Skip to content

Allow for std::shared_ptr default holders for ADC/DACDevice python bindings

Daniel Joseph Antrim requested to merge dantrim_fix_adc_pybindings into devel

What

This MR updates the Python bindings for the ADCDevice and DACDevice classes to specify that their default holders be std::shared_ptr. The default in pybind11 is for std::unique_ptr. Basically, we follow the recommendations here.

This addresses the errors reported by @beringer in #77 (closed). I have tried a MWE:

from labRemote import com, devcom
def main() :
    serial = com.TextSerialCom("/dev/ttyAMC0", 9600)
    dev = devcom.ADCDevComuino(5, serial)
    try :
        sensor = devcom.NTCSensor(0, dev, True, 4, 4, 4, False, 5, 5)
    except Exception as e :
        print(f"Failed to initialize NTCSensor: {e}")

if __name__ == "__main__" :
    main()

Prior to the changes introduced in this MR, calling this script would result in the error messages reported in #77 (closed). With the changes introduced in this MR, no error is reported.

Note that I have not tested these changes with actual devices.

Related Issues

Relates to #77 (closed).

Edited by Daniel Joseph Antrim

Merge request reports

Loading