Exemple #1
0
class NiceNI(NiceLib):
    _info = info
    _prefix = ('DAQmx_', 'DAQmx')
    _buflen = 512

    def _ret_wrap(code):
        if code != 0:
            raise DAQError(code)

    GetErrorString = ('in', 'buf', 'len')
    GetSysDevNames = ('buf', 'len')
    CreateTask = ('in', 'out')

    Task = NiceObjectDef(
        doc="A Nice-wrapped NI Task",
        attrs={
            'StartTask': ('in'),
            'StopTask': ('in'),
            'ClearTask': ('in'),
            'WaitUntilTaskDone': ('in', 'in'),
            'IsTaskDone': ('in', 'out'),
            'CreateAIVoltageChan':
            ('in', 'in', 'in', 'in', 'in', 'in', 'in', 'in'),
            'CreateAOVoltageChan': ('in', 'in', 'in', 'in', 'in', 'in', 'in'),
            'CreateDIChan': ('in', 'in', 'in', 'in'),
            'CreateDOChan': ('in', 'in', 'in', 'in'),
            'ReadAnalogF64':
            ('in', 'in', 'in', 'in', 'arr', 'len=in', 'out', 'ignore'),
            'ReadAnalogScalarF64': ('in', 'in', 'out', 'ignore'),
            'ReadDigitalScalarU32': ('in', 'in', 'out', 'ignore'),
            'WriteAnalogF64':
            ('in', 'in', 'in', 'in', 'in', 'in', 'out', 'ignore'),
            'WriteAnalogScalarF64': ('in', 'in', 'in', 'in', 'ignore'),
            'WriteDigitalScalarU32': ('in', 'in', 'in', 'in', 'ignore'),
            'GetBufInputBufSize': ('in', 'out'),
            'CfgSampClkTiming': ('in', 'in', 'in', 'in', 'in', 'in'),
            'CfgDigEdgeStartTrig': ('in', 'in', 'in'),
        })

    Device = NiceObjectDef({
        'GetDevProductType': ('in', 'buf', 'len'),
        'GetDevAIPhysicalChans': ('in', 'buf', 'len'),
        'GetDevAOPhysicalChans': ('in', 'buf', 'len'),
        'GetDevCIPhysicalChans': ('in', 'buf', 'len'),
        'GetDevCOPhysicalChans': ('in', 'buf', 'len'),
        'GetDevAIVoltageRngs': ('in', 'arr', 'len=20'),
        'GetDevAOVoltageRngs': ('in', 'arr', 'len=20'),
        'GetDevDILines': ('in', 'buf', 'len'),
        'GetDevDOLines': ('in', 'buf', 'len'),
        'GetDevProductCategory': ('in', 'out'),
        'GetDevSerialNum': ('in', 'out'),
    })
Exemple #2
0
class NicePixelfly(NiceLib):
    _info = info

    def _ret(code):
        if code != 0:
            pbuf = errortext.ffi.new('char[]', 1024)
            errortext.lib.PCO_GetErrorText(
                errortext.ffi.cast('unsigned int', code), pbuf, len(pbuf))
            err_message = errortext.ffi.string(pbuf)
            e = Error('({}) {}'.format(code, err_message))
            e.err_code = code
            raise e

    INITBOARD = ('in', 'out')  # Second arg should really be 'inout'
    CHECK_BOARD_AVAILABILITY = ('in')

    Board = NiceObjectDef(
        init='INITBOARD',
        attrs=dict(
            CLOSEBOARD=('inout'),
            START_CAMERA=('in'),
            STOP_CAMERA=('in'),
            TRIGGER_CAMERA=('in'),
            SETMODE=('in', 'in', 'in', 'in', 'in', 'in', 'in', 'in', 'in',
                     'in'),
            SET_EXPOSURE=('in', 'in'),
            GETMODE=('in', 'out', 'out', 'out', 'out', 'out', 'out', 'out',
                     'out', 'out'),
            GETSIZES=('in', 'out', 'out', 'out', 'out', 'out'),
            GETBOARDVAL=('in', 'in',
                         'inout'),  # TODO: deal with void pointer properly
            READVERSION=('in', 'in', 'buf', 'len=64'),
            READTEMPERATURE=('in', 'out'),
            WRRDORION=('in', 'in', 'out'),
            SETORIONINT=('in', 'in', 'in', 'in',
                         'in'),  # TODO: NiceLib needs something like bufin
            GETORIONINT=('in', 'in', 'in', 'buf', 'len'),
            READEEPROM=('in', 'in', 'in', 'out'),
            WRITEEEPROM=('in', 'in', 'in', 'in'),
            SETTIMEOUTS=('in', 'in', 'in', 'in'),
            #SET_TIMEOUT_VALUES = ('in', 'arr', 'len'),  # TODO: len is in bytes
            SETDRIVER_EVENT=('in', 'in', 'inout'),
            PCC_GET_VERSION=('in', 'out', 'out'),
            READ_IMAGE=('in', 'in', 'len', 'arr', 'in'),  # TODO: Check this
            ALLOCATE_BUFFER_EX=('in', 'inout', 'in', 'inout', 'inout'),
            FREE_BUFFER=('in', 'in'),
            SETBUFFER_EVENT=('in', 'in', 'inout'),
            CLEARBUFFER_EVENT=('in', 'in', 'inout'),
            PCC_RESETEVENT=('in', 'in'),
            ADD_BUFFER_TO_LIST=('in', 'in', 'in', 'in', 'in'),
            REMOVE_BUFFER_FROM_LIST=('in', 'in'),
            ADD_BUFFER=('in', 'in', 'in', 'in', 'in'),
            REMOVE_BUFFER=('in', 'in'),
            REMOVE_ALL_BUFFERS_FROM_LIST=('in'),
            PCC_WAITFORBUFFER=('in', 'in', 'inout', 'in'),
            GETBUFFER_STATUS=('in', 'in', 'in', 'arr', 'len=4:byte'),
        ))
class NiceCCSLib(NiceLib):
    """ Provides a convenient low-level wrapper for the library
    Thorlabs.MotionControl.TCube.DCServo.dll"""
    _info = load_lib('tlccs', __package__)
    _struct_maker = None
    _prefix = ('tlccs_')
    _buflen = 256
    _ret_wrap = 'error_code'

    def _ret_error_code(error_code, niceobj):
        if error_code != 0:
            if niceobj is None:
                raise ThorlabsCCSError(
                    NiceCCSLib.error_message(0, error_code)[0])
            else:
                raise ThorlabsCCSError(niceobj.error_message(error_code)[0])

    init = ('in', 'in', 'in', 'out')
    error_message = ('in', 'in', 'buf[512]')

    NiceCCS = NiceObjectDef({
        'close': ('in'),
        'setIntegrationTime': ('in', 'in'),
        'getIntegrationTime': ('in', 'out'),
        'startScan': ('in'),
        'startScanCont': ('in'),
        'startScanExtTrg': ('in'),
        'startScanContExtTrg': ('in'),
        'getDeviceStatus': ('in', 'out'),
        'getScanData': ('in', 'arr[{}]'.format(NUM_RAW_PIXELS)),
        'getRawScanData': ('in', 'out'),
        'setWavelengthData': ('in', 'in', 'in', 'in'),
        'getWavelengthData':
        ('in', 'in', 'arr[{}]'.format(NUM_RAW_PIXELS), 'out', 'out'),
        'getUserCalibrationPoints': ('in', 'out', 'out', 'out'),
        'setAmplitudeData': ('in', 'in', 'in', 'in', 'in'),
        'getAmplitudeData':
        ('in', 'arr[{}]'.format(NUM_RAW_PIXELS), 'in', 'in', 'in'),
        'identificationQuery':
        ('in', 'buf[256]', 'buf[256]', 'buf[256]', 'buf[256]', 'buf[256]'),
        'revision_query': ('in', 'out', 'out'),
        'reset': ('in'),
        'self_test': ('in', 'out', 'out'),
        'setUserText': ('in', 'in'),
        'getUserText': ('in', 'out'),
        'setAttribute': ('in', 'in', 'in'),
        'getAttribute': ('in', 'in', 'out'),
        'error_query': ('in', 'out', 'out'),
        'error_message': ('in', 'in', 'buf[512]', {
            'ret': 'ignore'
        })
    })
Exemple #4
0
class NicePicamLib(NiceLib):
    """Wrapper for Picam.dll"""
    _info = lib
    _buflen = 256
    _prefix = 'Picam_'
    _ret_wrap = 'error'

    def _ret_error(error):
        if error != 0:
            if bool(NicePicamLib.IsLibraryInitialized()):
                NicePicamLib.GetEnumerationString(
                    lib.PicamEnumeratedType_Error, error)
            else:
                NicePicamLib._ret_enum_string_error(error)

    def _ret_enum_string_error(error):
        if error != 0:
            if error == lib.PicamError_LibraryNotInitialized:
                raise PicamError('Library not initialized')
            if error == lib.PicamError_InvalidEnumeratedType:
                raise PicamError('Invalid enumerated Type')
            if error == lib.PicamError_EnumerationValueNotDefined:
                raise PicamError('Enumeration value not defined.')
            else:
                raise PicamError(
                    'Error when getting enumeration string.  Error code {}'.
                    format(error))

    GetVersion = ('out', 'out', 'out', 'out')
    IsLibraryInitialized = ('out', {'ret': 'ignore'})
    InitializeLibrary = ()
    UninitializeLibrary = ()
    DestroyString = ('in')
    GetEnumerationString = ('in', 'in', 'bufout', {'ret': 'enum_string_error'})
    DestroyCameraIDs = ('in')
    GetAvailableCameraIDs = ('out', 'out')
    GetUnavailableCameraIDs = ('out', 'out')
    IsCameraIDConnected = ('in', 'out')
    IsCameraIDOpenElsewhere = ('in', 'out')
    DestroyHandles = ('in')
    OpenFirstCamera = ('out')
    OpenCamera = ('in', 'out')
    # DestroyFirmwareDetails = (firmware_array)
    DestroyFirmwareDetails = ('in')
    # DestroyModels = (model_array)
    DestroyModels = ('in')
    GetAvailableDemoCameraModels = ('out', 'out')
    ConnectDemoCamera = ('in', 'in', 'out')
    DisconnectDemoCamera = ('in')
    GetOpenCameras = ('out', 'out')
    IsDemoCamera = ('in', 'out')
    # GetFirmwareDetails = (id, firmware_array, firmware_count)
    GetFirmwareDetails = ('in', 'out', 'out')
    # DestroyRois = (rois)
    DestroyRois = ('in')
    # DestroyModulations = (modulations)
    DestroyModulations = ('in')
    # DestroyPulses = (pulses)
    DestroyPulses = ('in')
    # DestroyParameters = (parameter_array)
    DestroyParameters = ('in')
    # DestroyCollectionConstraints = (constraint_array)
    DestroyCollectionConstraints = ('in')
    # DestroyRangeConstraints = (constraint_array)
    DestroyRangeConstraints = ('in')
    # DestroyRoisConstraints = (constraint_array)
    DestroyRoisConstraints = ('in')
    # DestroyModulationsConstraints = (constraint_array)
    DestroyModulationsConstraints = ('in')
    # DestroyPulseConstraints = (constraint_array)
    DestroyPulseConstraints = ('in')

    NicePicam = NiceObjectDef({
        'CloseCamera': ('in'),
        'IsCameraConnected': ('in', 'out'),
        'GetCameraID': ('in', 'out'),
        # GetParameterIntegerValue': (camera, parameter, value),
        'GetParameterIntegerValue': ('in', 'in', 'out'),
        # SetParameterIntegerValue': (camera, parameter, value),
        'SetParameterIntegerValue': ('in', 'in', 'in'),
        # CanSetParameterIntegerValue': (camera, parameter, value, settable),
        'CanSetParameterIntegerValue': ('in', 'in', 'in', 'out'),
        # GetParameterLargeIntegerValue': (camera, parameter, value),
        'GetParameterLargeIntegerValue': ('in', 'in', 'out'),
        # SetParameterLargeIntegerValue': (camera, parameter, value),
        'SetParameterLargeIntegerValue': ('in', 'in', 'in'),
        # CanSetParameterLargeIntegerValue': (camera, parameter, value, settable),
        'CanSetParameterLargeIntegerValue': ('in', 'in', 'in', 'out'),
        # GetParameterFloatingPointValue': (camera, parameter, value),
        'GetParameterFloatingPointValue': ('in', 'in', 'out'),
        # SetParameterFloatingPointValue': (camera, parameter, value),
        'SetParameterFloatingPointValue': ('in', 'in', 'in'),
        # CanSetParameterFloatingPointValue': (camera, parameter, value, settable),
        'CanSetParameterFloatingPointValue': ('in', 'in', 'in', 'out'),
        # GetParameterRoisValue': (camera, parameter, value),
        'GetParameterRoisValue': ('in', 'in', 'out'),
        # SetParameterRoisValue': (camera, parameter, value),
        'SetParameterRoisValue': ('in', 'in', 'in'),
        # CanSetParameterRoisValue': (camera, parameter, value, settable),
        'CanSetParameterRoisValue': ('in', 'in', 'in', 'out'),
        # GetParameterPulseValue': (camera, parameter, value),
        'GetParameterPulseValue': ('in', 'in', 'out'),
        # SetParameterPulseValue': (camera, parameter, value),
        'SetParameterPulseValue': ('in', 'in', 'in'),
        # CanSetParameterPulseValue': (camera, parameter, value, settable),
        'CanSetParameterPulseValue': ('in', 'in', 'in', 'out'),
        # GetParameterModulationsValue': (camera, parameter, value),
        'GetParameterModulationsValue': ('in', 'in', 'out'),
        # SetParameterModulationsValue': (camera, parameter, value),
        'SetParameterModulationsValue': ('in', 'in', 'in'),
        # CanSetParameterModulationsValue': (camera, parameter, value, settable),
        'CanSetParameterModulationsValue': ('in', 'in', 'in', 'out'),
        # GetParameterIntegerDefaultValue': (camera, parameter, value),
        'GetParameterIntegerDefaultValue': ('in', 'in', 'out'),
        # GetParameterLargeIntegerDefaultValue': (camera, parameter, value),
        'GetParameterLargeIntegerDefaultValue': ('in', 'in', 'out'),
        # GetParameterFloatingPointDefaultValue': (camera, parameter, value),
        'GetParameterFloatingPointDefaultValue': ('in', 'in', 'out'),
        # GetParameterRoisDefaultValue': (camera, parameter, value),
        'GetParameterRoisDefaultValue': ('in', 'in', 'out'),
        # GetParameterPulseDefaultValue': (camera, parameter, value),
        'GetParameterPulseDefaultValue': ('in', 'in', 'out'),
        # GetParameterModulationsDefaultValue': (camera, parameter, value),
        'GetParameterModulationsDefaultValue': ('in', 'in', 'out'),
        # CanSetParameterOnline': (camera, parameter, onlineable),
        'CanSetParameterOnline': ('in', 'in', 'out'),
        # SetParameterIntegerValueOnline': (camera, parameter, value),
        'SetParameterIntegerValueOnline': ('in', 'in', 'in'),
        # SetParameterFloatingPointValueOnline': (camera, parameter, value),
        'SetParameterFloatingPointValueOnline': ('in', 'in', 'in'),
        # SetParameterPulseValueOnline': (camera, parameter, value),
        'SetParameterPulseValueOnline': ('in', 'in', 'in'),
        # CanReadParameter': (camera, parameter, readable),
        'CanReadParameter': ('in', 'in', 'out'),
        # ReadParameterIntegerValue': (camera, parameter, value),
        'ReadParameterIntegerValue': ('in', 'in', 'out'),
        # ReadParameterFloatingPointValue': (camera, parameter, value),
        'ReadParameterFloatingPointValue': ('in', 'in', 'out'),
        # GetParameters': (camera, parameter_array, parameter_count),
        'GetParameters': ('in', 'out', 'out'),
        # DoesParameterExist': (camera, parameter, exists),
        'DoesParameterExist': ('in', 'in', 'out'),
        # IsParameterRelevant': (camera, parameter, relevant),
        'IsParameterRelevant': ('in', 'in', 'out'),
        # GetParameterValueType': (camera, parameter, type),
        'GetParameterValueType': ('in', 'in', 'out'),
        # GetParameterEnumeratedType': (camera, parameter, type),
        'GetParameterEnumeratedType': ('in', 'in', 'out'),
        # GetParameterValueAccess': (camera, parameter, access),
        'GetParameterValueAccess': ('in', 'in', 'out'),
        # GetParameterConstraintType': (camera, parameter, type),
        'GetParameterConstraintType': ('in', 'in', 'out'),
        # GetParameterCollectionConstraint': (camera, parameter, category, constraint),
        'GetParameterCollectionConstraint': ('in', 'in', 'in', 'out'),
        # GetParameterRangeConstraint': (camera, parameter, category, constraint),
        'GetParameterRangeConstraint': ('in', 'in', 'in', 'out'),
        # GetParameterRoisConstraint': (camera, parameter, category, constraint),
        'GetParameterRoisConstraint': ('in', 'in', 'in', 'out'),
        # GetParameterPulseConstraint': (camera, parameter, category, constraint),
        'GetParameterPulseConstraint': ('in', 'in', 'in', 'out'),
        # GetParameterModulationsConstraint': (camera, parameter, category, constraint),
        'GetParameterModulationsConstraint': ('in', 'in', 'in', 'out'),
        # AreParametersCommitted': (camera, committed),
        'AreParametersCommitted': ('in', 'out'),
        # CommitParameters': (camera, failed_parameter_array, failed_parameter_count),
        'CommitParameters': ('in', 'out', 'out'),
        # Acquire': (camera, readout_count, readout_time_out, available, errors),
        'Acquire': ('in', 'in', 'in', 'out', 'out'),
        # StartAcquisition': (camera),
        'StartAcquisition': ('in'),
        # StopAcquisition': (camera),
        'StopAcquisition': ('in'),
        # IsAcquisitionRunning': (camera, running),
        'IsAcquisitionRunning': ('in', 'out'),
        # WaitForAcquisitionUpdate': (camera, readout_time_out, available, status),
        'WaitForAcquisitionUpdate': ('in', 'in', 'out', 'out')
    })
Exemple #5
0
class NiceKinesisISC(NiceLib):
    """ This class provides a convenient low-level wrapper for the library
    Thorlabs.MotionControl.FilterFlipper.dll"""
    _info = load_lib('kinesis', __package__)

    #
    # Error wrapping functions
    #
    def _ret(ret):
        if ret != 0:
            raise KinesisError(ret)

    def _ret_success(ret, funcname):
        if not ret:
            raise KinesisError(
                msg="Call to function '{}' failed".format(funcname))

    #
    # Function signatures
    #
    _prefix = 'TLI_'

    BuildDeviceList = ()
    GetDeviceListSize = ({'ret': 'return'}, )
    GetDeviceListExt = ('buf', 'len')
    GetDeviceListByTypeExt = ('buf', 'len', 'in')
    GetDeviceListByTypesExt = ('buf', 'len', 'in', 'in')
    GetDeviceInfo = ('in', 'out')

    # GetDeviceList = ('out')
    # GetDeviceListByType = ('out', 'in', dict(first_arg=False))
    # GetDeviceListByTypes = ('out', 'in', 'in', dict(first_arg=False))

    Device = NiceObjectDef(prefix='ISC_',
                           attrs=dict(
                               Open=('in'),
                               Close=('in', {
                                   'ret': 'return'
                               }),
                               Identify=('in', {
                                   'ret': 'ignore'
                               }),
                               GetHardwareInfo=('in', 'buf', 'len', 'out',
                                                'out', 'buf', 'len', 'out',
                                                'out', 'out'),
                               GetFirmwareVersion=('in', {
                                   'ret': 'return'
                               }),
                               GetSoftwareVersion=('in', {
                                   'ret': 'return'
                               }),
                               LoadSettings=('in', {
                                   'ret': 'success'
                               }),
                               PersistSettings=('in', {
                                   'ret': 'success'
                               }),
                               GetNumberPositions=('in', {
                                   'ret': 'return'
                               }),
                               Home=('in'),
                               NeedsHoming=('in', {
                                   'ret': 'return'
                               }),
                               MoveToPosition=('in', 'in'),
                               GetPosition=('in', {
                                   'ret': 'return'
                               }),
                               RequestStatus=('in'),
                               RequestStatusBits=('in'),
                               GetStatusBits=('in', {
                                   'ret': 'return'
                               }),
                               StartPolling=(
                                   'in',
                                   'in',
                                   {
                                       'ret': 'success'
                                   },
                               ),
                               PollingDuration=('in', {
                                   'ret': 'return'
                               }),
                               StopPolling=('in', {
                                   'ret': 'ignore'
                               }),
                               RequestSettings=('in'),
                               ClearMessageQueue=('in', {
                                   'ret': 'ignore'
                               }),
                               RegisterMessageCallback=('in', 'in', {
                                   'ret': 'ignore'
                               }),
                               MessageQueueSize=('in', {
                                   'ret': 'return'
                               }),
                               GetNextMessage=('in', 'out', 'out', 'out', {
                                   'ret': 'success'
                               }),
                               WaitForMessage=('in', 'out', 'out', 'out', {
                                   'ret': 'success'
                               }),
                               GetMotorParamsExt=('in', 'out', 'out', 'out'),
                               SetJogStepSize=('in', 'in'),
                               GetJogVelParams=('in', 'out', 'out'),
                               GetBacklash=('in', {
                                   'ret': 'return'
                               }),
                               SetBacklash=('in', 'in'),
                           ))
Exemple #6
0
class NiceUC480(NiceLib):
    _info = info
    _prefix = ('is_', 'IS_')

    # Error wrapping
    #
    def _ret(result):
        if result != NiceUC480.SUCCESS:
            raise UC480Error('({})'.format(result))

    def _ret_cam(result, niceobj):
        if result != NiceUC480.SUCCESS:
            err_code, err_msg = niceobj.GetError()
            raise UC480Error('({}): {}'.format(result, err_msg))

    # Classmethods
    #
    GetNumberOfCameras = ('out')
    GetCameraList = ('inout')
    InitCamera = ('inout', 'in')

    # Hand-wrapped methods
    #
    def _AOI(command, param=None):
        """AOI(command, param=None)"""
        if command & lib.AOI_MULTI_GET_AOI:
            if command == lib.AOI_MULTI_GET_AOI:
                raise Error(
                    "command AOI_MULTI_GET_AOI must be or'd together with another flag"
                )
            param_type = 'UINT[8]'
            getting = True
        elif command in AOI_GET_PARAM_TYPES:
            param_type = AOI_GET_PARAM_TYPES[command]
            getting = True
        elif command in AOI_SET_PARAM_TYPES:
            param_type = AOI_SET_PARAM_TYPES[command]
            getting = False
        else:
            raise Error("Unsupported command given")

        if getting and param is not None:
            raise ValueError(
                "Cannot give a param value when using a GET command")
        elif not getting and param is None:
            raise ValueError(
                "Must give a param value when using a SET command")

        param_type = ffi.typeof(param_type)
        deref = (param_type.kind == 'pointer')  # Don't dereference arrays

        param_data = ffi.new(param_type, param)
        size = ffi.sizeof(ffi.typeof(param_data).item if deref else param_data)
        param_ptr = ffi.cast('void*', param_data)
        NiceUC480._AOI.orig(command, param_ptr, size)

        if getting:
            return param_data[0] if deref else param_data

    _AOI.sig = ('in', 'in', 'inout', 'in')

    def _Exposure(command, param=None):
        if command in EXPOSURE_GET_PARAM_TYPES:
            param_type = EXPOSURE_GET_PARAM_TYPES[command]
            getting = True
        elif command in EXPOSURE_SET_PARAM_TYPES:
            param_type = EXPOSURE_SET_PARAM_TYPES[command]
            getting = False
        else:
            raise Error("Unsupported command given")

        if getting and param is not None:
            raise ValueError(
                "Cannot give a param value when using a GET command")
        elif not getting and param is None:
            raise ValueError(
                "Must give a param value when using a SET command")

        param_type = ffi.typeof(param_type)
        deref = (param_type.kind == 'pointer')  # Don't dereference arrays

        param_data = ffi.new(param_type, param)
        size = ffi.sizeof(ffi.typeof(param_data).item if deref else param_data)
        param_ptr = ffi.cast('void*', param_data)
        NiceUC480._Exposure.orig(command, param_ptr, size)

        if getting:
            return param_data[0] if deref else param_data

    _Exposure.sig = ('in', 'in', 'inout', 'in')

    # Camera methods
    #
    Camera = NiceObjectDef(
        init='InitCamera',
        ret='cam',
        attrs=dict(
            AddToSequence=('in', 'in', 'in'),
            AllocImageMem=('in', 'in', 'in', 'in', 'out', 'out'),
            AOI=_AOI,
            CaptureVideo=('in', 'in', {
                'ret': ret_handler('IS_GET_LIVE')
            }),
            ClearSequence=('in'),
            DisableEvent=('in', 'in'),
            EnableEvent=('in', 'in'),
            ExitCamera=('in'),
            ExitEvent=('in', 'in'),
            ExitImageQueue=('in'),
            Exposure=_Exposure,
            FreeImageMem=('in', 'in', 'in'),
            GetActSeqBuf=('in', 'out', 'out', 'out'),
            GetError=('in', 'out', 'bufout'),
            GetImageMemPitch=('in', 'out'),
            GetSensorInfo=('in', 'out'),
            InitEvent=('in', 'in', 'in'),
            InitImageQueue=('in', 'in'),
            ParameterSet=('in', 'in', 'inout', 'in'),
            SetAutoParameter=('in', 'in', 'inout', 'inout'),
            SetBinning=('in', 'in', {
                'ret': ret_handler('IS_GET_*BINNING*')
            }),
            SetCameraID=('in', 'in', {
                'ret': ret_handler('IS_GET_CAMERA_ID')
            }),
            SetColorMode=('in', 'in', {
                'ret': ret_handler('IS_GET_COLOR_MODE')
            }),
            SetDisplayMode=('in', 'in', {
                'ret': ret_handler('IS_GET_DISPLAY_MODE')
            }),
            SetExternalTrigger=('in', 'in', {
                'ret': ret_handler('IS_GET_*TRIGGER*')
            }),
            SetFrameRate=('in', 'in', 'out'),

            # TODO: Replace this deprecated function
            SetImageSize=('in', 'in', 'in', {
                'ret': ret_handler('IS_GET_IMAGE_SIZE_*')
            }),
            SetSubSampling=('in', 'in', {
                'ret': ret_handler('IS_GET_*SUBSAMPLING*')
            }),
            SetTriggerDelay=('in', 'in', {
                'ret': ret_handler('IS_GET_*TRIGGER*')
            }),
            StopLiveVideo=('in', 'in'),
            SetHardwareGain=('in', 'in', 'in', 'in', 'in', {
                'ret':
                ret_handler(('IS_GET_MASTER_GAIN', 'IS_GET_RED_GAIN',
                             'IS_GET_GREEN_GAIN', 'IS_GET_BLUE_GAIN',
                             'IS_GET_DEFAULT_MASTER', 'IS_GET_DEFAULT_RED',
                             'IS_GET_DEFAULT_GREEN', 'IS_GET_DEFAULT_BLUE'))
            }),
        ))
Exemple #7
0
class NiceTDC001(NiceLib):
    """ Provides a convenient low-level wrapper for the library
    Thorlabs.MotionControl.TCube.DCServo.dll"""
    _ret = 'error_code'
    _struct_maker = None
    _ffi = ffi
    _ffilib = lib
    _prefix = ('CC_', 'TLI_')
    _buflen = 512

    def _ret_bool_error_code(success):
        if not success:
            raise TDC001Error('The function did not execute successfully')

    def _ret_error_code(retval):
        if not (retval == 0 or retval is None):
            raise TDC001Error(error_dict[retval])

    BuildDeviceList = ()
    GetDeviceListSize = ({'ret': 'return'}, )
    GetDeviceInfo = ('in', 'out', {'ret': 'bool_error_code'})
    GetDeviceList = ('out')
    GetDeviceListByType = ('out', 'in')
    GetDeviceListByTypes = ('out', 'in', 'in')
    GetDeviceListExt = ('buf', 'len')
    GetDeviceListByTypeExt = ('buf', 'len', 'in')
    GetDeviceListByTypesExt = ('buf', 'len', 'in', 'in')

    TDC001 = NiceObjectDef({
        'Open': ('in'),
        'Close': ('in', {
            'ret': 'return'
        }),
        'Identify': ('in', {
            'ret': 'return'
        }),
        'GetLEDswitches': ('in', {
            'ret': 'return'
        }),
        'SetLEDswitches': ('in', 'in'),
        'GetHardwareInfo':
        ('in', 'buf', 'len', 'out', 'out', 'buf', 'len', 'out', 'out', 'out'),
        'GetHardwareInfoBlock': ('in', 'out'),
        'GetHubBay': ('in', {
            'ret': 'return'
        }),
        'GetSoftwareVersion': ('in', {
            'ret': 'return'
        }),
        'LoadSettings': ('in', {
            'ret': 'bool_error_code'
        }),
        'PersistSettings': ('in', {
            'ret': 'bool_error_code'
        }),
        'DisableChannel': ('in'),
        'EnableChannel': ('in'),
        'GetNumberPositions': ('in', {
            'ret': 'return'
        }),
        'CanHome': ('in', {
            'ret': 'bool_error_code'
        }),
        'NeedsHoming': ('in', {
            'ret': 'return'
        }),
        'Home': ('in'),
        'MoveToPosition': ('in', 'in'),
        'GetPosition': ('in', {
            'ret': 'return'
        }),
        'GetHomingVelocity': ('in', {
            'ret': 'return'
        }),
        'SetHomingVelocity': ('in', 'in'),
        'MoveRelative': ('in', 'in'),
        'GetJogMode': ('in', 'out', 'out'),
        'SetJogMode': ('in', 'in', 'in'),
        'SetJogStepSize': ('in', 'in'),
        'GetJogStepSize': ('in', {
            'ret': 'return'
        }),
        'GetJogVelParams': ('in', 'out', 'out'),
        'SetJogVelParams': ('in', 'in', 'in'),
        'MoveJog': ('in', 'in'),
        'SetVelParams': ('in', 'in', 'in'),
        'GetVelParams': ('in', 'out', 'out'),
        'MoveAtVelocity': ('in', 'in'),
        'SetDirection': ('in', 'in', {
            'ret': 'return'
        }),
        'StopImmediate': ('in'),
        'StopProfiled': ('in'),
        'GetBacklash': ('in', {
            'ret': 'return'
        }),
        'SetBacklash': ('in', 'in'),
        'GetPositionCounter': ('in', {
            'ret': 'return'
        }),
        'SetPositionCounter': ('in', 'in'),
        'GetEncoderCounter': ('in', {
            'ret': 'return'
        }),
        'SetEncoderCounter': ('in', 'in'),
        'GetLimitSwitchParams': ('in', 'out', 'out', 'out', 'out', 'out'),
        'SetLimitSwitchParams': ('in', 'in', 'in', 'in', 'in', 'in'),
        'GetSoftLimitMode': ('in', {
            'ret': 'return'
        }),
        'SetLimitsSoftwareApproachPolicy': ('in', 'in', {
            'ret': 'return'
        }),
        'GetButtonParams': ('in', 'out', 'out', 'out', 'out'),
        'SetButtonParams': ('in', 'in', 'in', 'in'),
        'SetPotentiometerParams': ('in', 'in', 'in', 'in'),
        'GetPotentiometerParams': ('in', 'in', 'out', 'out'),
        'GetVelParamsBlock': ('in', 'out'),
        'SetVelParamsBlock': ('in', 'in'),
        'SetMoveAbsolutePosition': ('in', 'in'),
        'GetMoveAbsolutePosition': ('in', {
            'ret': 'return'
        }),
        'MoveAbsolute': ('in'),
        'SetMoveRelativeDistance': ('in', 'in'),
        'GetMoveRelativeDistance': ('in', {
            'ret': 'return'
        }),
        'MoveRelativeDistance': ('in'),
        'GetHomingParamsBlock': ('in', 'out'),
        'SetHomingParamsBlock': ('in', 'in'),
        'GetJogParamsBlock': ('in', 'out'),
        'SetJogParamsBlock': ('in', 'in'),
        'GetButtonParamsBlock': ('in', 'out'),
        'SetButtonParamsBlock': ('in', 'in'),
        'GetPotentiometerParamsBlock': ('in', 'out'),
        'SetPotentiometerParamsBlock': ('in', 'in'),
        'GetLimitSwitchParamsBlock': ('in', 'out'),
        'SetLimitSwitchParamsBlock': ('in', 'in'),
        'GetDCPIDParams': ('in', 'out'),
        'SetDCPIDParams': ('in', 'in'),
        'SuspendMoveMessages': ('in'),
        'ResumeMoveMessages': ('in'),
        'RequestPosition': ('in'),
        'RequestStatusBits': ('in', {
            'ret': 'return'
        }),
        'GetStatusBits': ('in', {
            'ret': 'return'
        }),
        'StartPolling': ('in', 'in', {
            'ret': 'bool_error_code'
        }),
        'PollingDuration': ('in', {
            'ret': 'return'
        }),
        'StopPolling': ('in', {
            'ret': 'return'
        }),
        'RequestSettings': ('in'),
        'GetStageAxisMinPos': ('in', {
            'ret': 'return'
        }),
        'GetStageAxisMaxPos': ('in', {
            'ret': 'return'
        }),
        'SetStageAxisLimits': ('in', 'in', 'in'),
        'SetMotorTravelMode': ('in', 'in'),
        'GetMotorTravelMode': ('in', {
            'ret': 'return'
        }),
        'SetMotorParams': ('in', 'in', 'in', 'in'),
        'GetMotorParams': ('in', 'out', 'out', 'out'),
        'SetMotorParamsExt': ('in', 'in', 'in', 'in'),
        'GetMotorParamsExt': ('in', 'out', 'out', 'out'),
        'ClearMessageQueue': ('in', {
            'ret': 'return'
        }),
        'RegisterMessageCallback': ('in', 'in', {
            'ret': 'return'
        }),
        'MessageQueueSize': ('in', {
            'ret': 'return'
        }),
        'GetNextMessage': ('in', 'out', 'out', 'out', {
            'ret': 'bool_error_code'
        }),
        'WaitForMessage': ('in', 'in', 'in', 'in', {
            'ret': 'bool_error_code'
        }),
    })
Exemple #8
0
class NicePCO(NiceLib):
    def _ret(code):
        if code != 0:
            e = Error(get_error_text(code))
            e.code = code & 0xFFFFFFFF
            raise e

    def _struct_maker(*args):
        """PCO makes you fill in the wSize field of every struct"""
        struct_p = ffi.new(*args)
        struct_p[0].wSize = ffi.sizeof(struct_p[0])
        for name, field in ffi.typeof(struct_p[0]).fields:
            # Only goes one level deep for now
            if field.type.kind == 'struct':
                s = getattr(struct_p[0], name)
                s.wSize = ffi.sizeof(s)
        return struct_p

    _ffi = ffi
    _ffilib = lib
    _prefix = 'PCO_'

    OpenCamera = ('inout', 'ignore')
    OpenCameraEx = ('inout', 'inout')

    # Special cases
    def _GetTransferParameter(hcam, niceobj=None):
        params_p = ffi.new('PCO_SC2_CL_TRANSFER_PARAM *')
        void_p = ffi.cast('void *', params_p)
        lib.PCO_GetTransferParameter(hcam, void_p, ffi.sizeof(params_p[0]))
        # Should do error checking...
        return params_p[0]

    def _SetTransferParametersAuto(hcam, niceobj=None):
        lib.PCO_SetTransferParametersAuto(hcam, ffi.NULL, 0)
        # Should do error checking...

    Camera = NiceObjectDef({
        'CloseCamera': ('in'),
        'GetSizes': ('in', 'out', 'out', 'out', 'out'),
        'SetROI': ('in', 'in', 'in', 'in', 'in'),
        'GetROI': ('in', 'out', 'out', 'out', 'out'),
        'GetInfoString': ('in', 'in', 'buf', 'len'),
        'GetCameraName': ('in', 'buf40', 'len'),
        'GetRecordingState': ('in', 'out'),
        'SetRecordingState': ('in', 'in'),
        'SetDelayExposureTime': ('in', 'in', 'in', 'in', 'in'),
        'GetDelayExposureTime': ('in', 'out', 'out', 'out', 'out'),
        'SetFrameRate': ('in', 'out', 'in', 'inout', 'inout'),
        'GetFrameRate': ('in', 'out', 'out', 'out'),
        'ArmCamera': ('in'),
        'SetBinning': ('in', 'in', 'in'),
        'GetBinning': ('in', 'out', 'out'),
        'GetActiveLookupTable': ('in', 'out', 'out'),
        'SetActiveLookupTable': ('in', 'inout', 'inout'),
        'GetPixelRate': ('in', 'out'),
        # GetTransferParameter = ('in', 'buf', 'len')
        'GetTriggerMode': ('in', 'out'),
        'SetTriggerMode': ('in', 'in'),
        'ForceTrigger': ('in', 'out'),
        'AllocateBuffer': ('in', 'inout', 'in', 'inout', 'inout'),
        'CamLinkSetImageParameters': ('in', 'in', 'in'),
        'FreeBuffer': ('in', 'in'),
        'CancelImages': ('in'),
        'AddBufferEx': ('in', 'in', 'in', 'in', 'in', 'in', 'in'),
        'GetBufferStatus': ('in', 'in', 'out', 'out'),
        'GetLookupTableInfo':
        ('in', 'in', 'out', 'buf20', 'len', 'out', 'out', 'out', 'out'),
        'GetCameraDescription': ('in', 'out'),
        'EnableSoftROI': ('in', 'in', 'in', 'in'),
        'GetHWIOSignalDescriptor': ('in', 'in', 'out'),
        'GetHWIOSignal': ('in', 'in', 'out'),
        'SetHWIOSignal': ('in', 'in', 'in'),
        'GetIRSensitivity': ('in', 'out'),
        'SetIRSensitivity': ('in', 'in'),
        'GetTransferParameter':
        _GetTransferParameter,
        'SetTransferParametersAuto':
        _SetTransferParametersAuto,
    })
Exemple #9
0
class NiceNI(NiceLib):
    _info = info
    _prefix = ('DAQmx_', 'DAQmx')
    _buflen = 512
    _use_numpy = True

    def _ret(code):
        if code != 0:
            raise DAQError(code)

    GetErrorString = ('in', 'buf', 'len')
    GetSysDevNames = ('buf', 'len')
    CreateTask = ('in', 'out')

    Task = NiceObjectDef(
        doc="A Nice-wrapped NI Task",
        attrs={
            'StartTask': ('in'),
            'StopTask': ('in'),
            'ClearTask': ('in'),
            'WaitUntilTaskDone': ('in', 'in'),
            'IsTaskDone': ('in', 'out'),
            'TaskControl': ('in', 'in'),
            'CreateAIVoltageChan':
            ('in', 'in', 'in', 'in', 'in', 'in', 'in', 'in'),
            'CreateAOVoltageChan': ('in', 'in', 'in', 'in', 'in', 'in', 'in'),
            'CreateDIChan': ('in', 'in', 'in', 'in'),
            'CreateDOChan': ('in', 'in', 'in', 'in'),
            'ReadAnalogF64':
            ('in', 'in', 'in', 'in', 'arr', 'len=in', 'out', 'ignore'),
            'ReadAnalogScalarF64': ('in', 'in', 'out', 'ignore'),
            'ReadDigitalScalarU32': ('in', 'in', 'out', 'ignore'),
            'WriteAnalogF64':
            ('in', 'in', 'in', 'in', 'in', 'in', 'out', 'ignore'),
            'WriteAnalogScalarF64': ('in', 'in', 'in', 'in', 'ignore'),
            'WriteDigitalScalarU32': ('in', 'in', 'in', 'in', 'ignore'),
            'GetBufInputBufSize': ('in', 'out'),
            'GetBufInputOnbrdBufSize': ('in', 'out'),
            'CfgSampClkTiming': ('in', 'in', 'in', 'in', 'in', 'in'),
            'CfgDigEdgeStartTrig': ('in', 'in', 'in'),
            'SetReadOffset': ('in', 'in'),
            'GetReadOffset': ('in', 'out'),
            'SetReadRelativeTo': ('in', 'in'),
            'GetReadRelativeTo': ('in', 'out'),
            'SetReadOverWrite': ('in', 'in'),
            'GetReadOverWrite': ('in', 'out'),
        })

    Device = NiceObjectDef({
        # Device properties
        'GetDevIsSimulated': ('in', 'out'),
        'GetDevProductCategory': ('in', 'out'),
        'GetDevProductType': ('in', 'buf', 'len'),
        'GetDevProductNum': ('in', 'out'),
        'GetDevSerialNum': ('in', 'out'),
        'GetDevAccessoryProductTypes': ('in', 'buf', 'len=20'),
        'GetDevAccessoryProductNums': ('in', 'arr', 'len=20'),
        'GetDevAccessorySerialNums': ('in', 'arr', 'len=20'),
        'GetCarrierSerialNum': ('in', 'out'),
        'GetDevChassisModuleDevNames': ('in', 'buf', 'len'),
        'GetDevAnlgTrigSupported': ('in', 'out'),
        'GetDevDigTrigSupported': ('in', 'out'),

        # AI Properties
        'GetDevAIPhysicalChans': ('in', 'buf', 'len'),
        'GetDevAISupportedMeasTypes': ('in', 'arr', 'len=32'),
        'GetDevAIMaxSingleChanRate': ('in', 'out'),
        'GetDevAIMaxMultiChanRate': ('in', 'out'),
        'GetDevAIMinRate': ('in', 'out'),
        'GetDevAISimultaneousSamplingSupported': ('in', 'out'),
        'GetDevAISampModes': ('in', 'arr', 'len=3'),
        'GetDevAITrigUsage': ('in', 'out'),
        'GetDevAIVoltageRngs': ('in', 'arr', 'len=32'),
        'GetDevAIVoltageIntExcitDiscreteVals': ('in', 'arr', 'len=32'),
        'GetDevAIVoltageIntExcitRangeVals': ('in', 'arr', 'len=32'),
        'GetDevAICurrentRngs': ('in', 'arr', 'len=32'),
        'GetDevAICurrentIntExcitDiscreteVals': ('in', 'arr', 'len=32'),
        'GetDevAIBridgeRngs': ('in', 'arr', 'len=32'),
        'GetDevAIResistanceRngs': ('in', 'arr', 'len=32'),
        'GetDevAIFreqRngs': ('in', 'arr', 'len=32'),
        'GetDevAIGains': ('in', 'arr', 'len=32'),
        'GetDevAICouplings': ('in', 'out'),
        'GetDevAILowpassCutoffFreqDiscreteVals': ('in', 'arr', 'len=32'),
        'GetDevAILowpassCutoffFreqRangeVals': ('in', 'arr', 'len=32'),
        'GetAIDigFltrTypes': ('in', 'arr', 'len=5'),
        'GetDevAIDigFltrLowpassCutoffFreqDiscreteVals':
        ('in', 'arr', 'len=32'),
        'GetDevAIDigFltrLowpassCutoffFreqRangeVals': ('in', 'arr', 'len=32'),

        # AO Properties
        'GetDevAOPhysicalChans': ('in', 'buf', 'len'),
        'GetDevAOSupportedOutputTypes': ('in', 'arr', 'len=3'),
        'GetDevAOSampClkSupported': ('in', 'out'),
        'GetDevAOSampModes': ('in', 'arr', 'len=3'),
        'GetDevAOMaxRate': ('in', 'out'),
        'GetDevAOMinRate': ('in', 'out'),
        'GetDevAOTrigUsage': ('in', 'out'),
        'GetDevAOVoltageRngs': ('in', 'arr', 'len=32'),
        'GetDevAOCurrentRngs': ('in', 'arr', 'len=32'),
        'GetDevAOGains': ('in', 'arr', 'len=32'),

        # DI Properties
        'GetDevDILines': ('in', 'buf', 'len'),
        'GetDevDIPorts': ('in', 'buf', 'len'),
        'GetDevDIMaxRate': ('in', 'out'),
        'GetDevDITrigUsage': ('in', 'out'),

        # DO Properties
        'GetDevDOLines': ('in', 'buf', 'len'),
        'GetDevDOPorts': ('in', 'buf', 'len'),
        'GetDevDOMaxRate': ('in', 'out'),
        'GetDevDOTrigUsage': ('in', 'out'),

        # CI Properties
        'GetDevCIPhysicalChans': ('in', 'buf', 'len'),
        'GetDevCISupportedMeasTypes': ('in', 'arr', 'len=15'),
        'GetDevCITrigUsage': ('in', 'out'),
        'GetDevCISampClkSupported': ('in', 'out'),
        'GetDevCISampModes': ('in', 'arr', 'len=3'),
        'GetDevCIMaxSize': ('in', 'out'),
        'GetDevCIMaxTimebase': ('in', 'out'),

        # CO Properties
        'GetDevCOPhysicalChans': ('in', 'buf', 'len'),
        'GetDevCOSupportedOutputTypes': ('in', 'arr', 'len=3'),
        'GetDevCOSampClkSupported': ('in', 'out'),
        'GetDevCOSampModes': ('in', 'arr', 'len=3'),
        'GetDevCOTrigUsage': ('in', 'out'),
        'GetDevCOMaxSize': ('in', 'out'),
        'GetDevCOMaxTimebase': ('in', 'out'),

        # Other Device Properties
        'GetDevTEDSHWTEDSSupported': ('in', 'out'),
        'GetDevNumDMAChans': ('in', 'out'),
        'GetDevBusType': ('in', 'out'),
        'GetDevPCIBusNum': ('in', 'out'),
        'GetDevPCIDevNum': ('in', 'out'),
        'GetDevPXIChassisNum': ('in', 'out'),
        'GetDevPXISlotNum': ('in', 'out'),
        'GetDevCompactDAQChassisDevName': ('in', 'buf', 'len'),
        'GetDevCompactDAQSlotNum': ('in', 'out'),
        'GetDevTCPIPHostname': ('in', 'buf', 'len'),
        'GetDevTCPIPEthernetIP': ('in', 'buf', 'len'),
        'GetDevTCPIPWirelessIP': ('in', 'buf', 'len'),
        'GetDevTerminals': ('in', 'buf', 'len=2048'),
    })
Exemple #10
0
class NiceFilterFlipper(NiceLib):
    """ Provides a convenient low-level wrapper for the library
    Thorlabs.MotionControl.FilterFlipper.dll"""
    _ret = 'error_code'
    _struct_maker = None
    _ffi = ffi
    _ffilib = lib
    _prefix = ('FF_', 'TLI_')
    _buflen = 512

    def _ret_bool_error_code(success):
        if not success:
            raise FilterFlipperError(
                'The function did not execute successfully')

    def _ret_error_code(retval):
        if not (retval == 0 or retval is None):
            raise FilterFlipperError(error_dict[retval])

    BuildDeviceList = ()
    GetDeviceListSize = ({'ret': 'return'}, )
    GetDeviceList = ('out')
    GetDeviceListByType = ('out', 'in')
    GetDeviceInfo = ('in', 'out', {'ret': 'bool_error_code'})

    # GetDeviceListByTypes seemed not to be properly implemented in the .dll
    #    GetDeviceListByTypes = ('out', 'in', 'in')
    GetDeviceListExt = ('buf', 'len')
    GetDeviceListByTypeExt = ('buf', 'len', 'in')
    GetDeviceListByTypesExt = ('buf', 'len', 'in', 'in')

    Flipper = NiceObjectDef({
        'Open': ('in'),
        'Close': ('in'),
        'Identify': ('in'),
        'GetHardwareInfo':
        ('in', 'buf', 'len', 'out', 'out', 'buf', 'len', 'out', 'out', 'out'),
        'GetFirmwareVersion': ('in', {
            'ret': 'return'
        }),
        'GetSoftwareVersion': ('in', {
            'ret': 'return'
        }),
        'LoadSettings': ('in', {
            'ret': 'bool_error_code'
        }),
        'PersistSettings': ('in', {
            'ret': 'bool_error_code'
        }),
        'GetNumberPositions': ('in', {
            'ret': 'return'
        }),
        'Home': ('in'),
        'MoveToPosition': ('in', 'in'),
        'GetPosition': ('in', {
            'ret': 'return'
        }),
        'GetIOSettings': ('in', 'out'),
        'GetTransitTime': ('in', {
            'ret': 'return'
        }),
        'SetTransitTime': ('in', 'in'),
        'RequestStatus': ('in'),
        'GetStatusBits': ('in', {
            'ret': 'return'
        }),
        'StartPolling': ('in', 'in', {
            'ret': 'bool_error_code'
        }),
        'PollingDuration': ('in', {
            'ret': 'return'
        }),
        'StopPolling': ('in'),
        'RequestSettings': ('in'),
        'ClearMessageQueue': ('in'),
        'RegisterMessageCallback': ('in', 'in'),
        'MessageQueueSize': ('in', {
            'ret': 'return'
        }),
        'GetNextMessage': ('in', 'in', 'in', 'in', {
            'ret': 'bool_error_code'
        }),
        'WaitForMessage': ('in', 'in', 'in', 'in', {
            'ret': 'bool_error_code'
        }),
    })