def SetAO(NoDev, NoSubDev, NoChannel): #Get maximalaceppted value #Using range 0 (iUnit, dMin, dMax, iMaxData) = meDriver.meQueryRangeInfo(NoDev, NoSubDev, 0) STEPS = 9 step = (dMax-dMin)/(STEPS-1) #Configure sub-device for output meDriver.meIOSingleConfig(NoDev, NoSubDev, NoChannel, 0, meDriver.ME_REF_AO_GROUND, meDriver.ME_TRIG_CHAN_DEFAULT, meDriver.ME_TRIG_TYPE_SW, meDriver.ME_TRIG_EDGE_NONE, meDriver.ME_IO_SINGLE_NO_FLAGS) for i in range(STEPS): #Write to sub-device SingleDict = { 'Device': NoDev, 'Subdevice': NoSubDev, 'Channel': NoChannel, 'Dir': meDriver.ME_DIR_OUTPUT, 'Value': meDriver.meUtilityPhysicalToDigital(dMin, dMax, iMaxData, dMin + (step * i)), 'TimeOut': meDriver.ME_VALUE_NOT_USED, 'Flags': meDriver.ME_IO_SINGLE_TYPE_NO_FLAGS, 'Errno': 0 } SingleList = [SingleDict] meDriver.meIOSingle(SingleList, meDriver.ME_IO_SINGLE_NO_FLAGS) print "Device [%d:%d/%d] SET:%f(0x%x)" % (NoDev, NoSubDev, NoChannel, dMin + (step * i), SingleList[0]['Value']) #Read back GetAO(NoDev, NoSubDev, NoChannel) time.sleep(1)
def GetAO(NoDev, NoSubDev, NoChannel): #Using range 0 (iUnit, dMin, dMax, iMaxData) = meDriver.meQueryRangeInfo(NoDev, NoSubDev, 0) #Read from sub-device SingleDict = { 'Device': NoDev, 'Subdevice': NoSubDev, 'Channel': NoChannel, 'Dir': meDriver.ME_DIR_INPUT, 'Value': 0, 'TimeOut': meDriver.ME_VALUE_NOT_USED, 'Flags': meDriver.ME_IO_SINGLE_TYPE_NO_FLAGS, 'Errno': 0 } SingleList = [SingleDict] meDriver.meIOSingle(SingleList, meDriver.ME_IO_SINGLE_NO_FLAGS) print "Device [%d:%d/%d] GET:%f(0x%x)" % (NoDev, NoSubDev, NoChannel, meDriver.meUtilityDigitalToPhysical(dMin, dMax, iMaxData, SingleList[0]['Value'], meDriver.ME_MODULE_TYPE_MULTISIG_NONE, 0), SingleList[0]['Value'])
def main(): try: #Initialization of ME-iDS meDriver.meOpen(meDriver.ME_OPEN_NO_FLAGS) #Get library version LibVer = meDriver.meQueryVersionLibrary() LibVer_Special = LibVer / 0x1000000 LibVer_API = LibVer / 0x10000 LibVer_Relase = LibVer / 0x100 LibVer_Compilation = LibVer print "Library version is %02x.%02x.%02x.%02x" % (LibVer_Special%0xFF, LibVer_API&0xFF, LibVer_Relase&0xFF, LibVer_Compilation&0xFF) #Get number of registered devices meNumberDevices = meDriver.meQueryNumberDevices() if meNumberDevices > 0: #Get main driver version DrvVer = meDriver.meQueryVersionMainDriver() DrvVer_Special = DrvVer / 0x1000000 DrvVer_API = DrvVer / 0x10000 DrvVer_Relase = DrvVer / 0x100 DrvVer_Compilation = DrvVer print "Main driver version is %02x.%02x.%02x.%02x" % (DrvVer_Special&0xFF, DrvVer_API&0xFF, DrvVer_Relase&0xFF, DrvVer_Compilation&0xFF) print "%i devices detected by driver system" % (meNumberDevices) for meNoDevices in range(meNumberDevices): #For each device get: # - device name # - device description # - driver name # - driver version # - number sub-devices print print "Device %i:" % (meNoDevices) print "=========" print "Device name is %s" % (meDriver.meQueryNameDevice(meNoDevices)) print "Driver name is %s" % (meDriver.meQueryNameDeviceDriver(meNoDevices)) print "Device description: %s" % (meDriver.meQueryDescriptionDevice(meNoDevices)) DrvVer = meDriver.meQueryVersionDeviceDriver(meNoDevices) DrvVer_Special = DrvVer / 0x1000000 DrvVer_API = DrvVer / 0x10000 DrvVer_Relase = DrvVer / 0x100 DrvVer_Compilation = DrvVer print "Device driver version is %02x.%02x.%02x.%02x" % (DrvVer_Special&0xFF, DrvVer_API&0xFF, DrvVer_Relase&0xFF, DrvVer_Compilation&0xFF) meNumberSubdevices = meDriver.meQueryNumberSubdevices(meNoDevices) for meNoSubdevices in range(meNumberSubdevices): #For each sub-device get: # - type # - sub-type (meType, meSubType) = meDriver.meQuerySubdeviceType(meNoDevices, meNoSubdevices) print "\tSubdevice %d is of type %s (0x%X) and subtype %s (0x%X)" % (meNoSubdevices, typeDevice[meType], meType , typeSubdevice[meSubType], meSubType); print "\t\tSubdevice %d has %d channels" % (meNoSubdevices, meDriver.meQueryNumberChannels(meNoDevices, meNoSubdevices)); if (meType == meDriver.ME_TYPE_AI) or (meType == meDriver.ME_TYPE_AO): #For AI and AO sub-device get number ranges meNumberRanges = meDriver.meQueryNumberRanges(meNoDevices, meNoSubdevices, meDriver.ME_UNIT_ANY); print "\t\tSubdevice %d has %d ranges:" % (meNoSubdevices, meNumberRanges); for meNoRanges in range(meNumberRanges): (meUnit, meMin, meMax, meMax_data) = meDriver.meQueryRangeInfo(meNoDevices, meNoSubdevices, meNoRanges) print "\t\t\tRange %d: Unit = 0x%X, Min = %lf, Max = %lf, Max Data = %d" %(meNoRanges, meUnit, meMin, meMax, meMax_data); except meDriver.error, Val: print sys.exc_info() print Val
def GetStreamAI(NoDev, NoSubDev): DataBlockSize = 0x10000 DataReadSize = 0x1000 AIBufSize = 0x400 #Preaparing trigger list TrigList = {'AcqStartTrigType' : meDriver.ME_TRIG_TYPE_SW, 'AcqStartTrigEdge' : meDriver.ME_TRIG_EDGE_NONE, 'AcqStartTrigChan' : meDriver.ME_TRIG_CHAN_DEFAULT, 'AcqStartTicks' : long(66), 'ScanStartTrigType' : meDriver.ME_TRIG_TYPE_TIMER, 'ScanStartTicks' : long(66), 'ConvStartTrigType' : meDriver.ME_TRIG_TYPE_TIMER, 'ConvStartTicks' : long(33000), #1kHz 'ScanStopTrigType' : meDriver.ME_TRIG_TYPE_NONE, 'ScanStopCount' : 0, 'AcqStopTrigType' : meDriver.ME_TRIG_TYPE_COUNT, 'AcqStopCount' : DataBlockSize, 'Flags' : meDriver.ME_IO_STREAM_TRIGGER_TYPE_NO_FLAGS} #Preaparing config list ConfList = [] ConfEntry = {'Channel': 0, 'StreamConfig': 0, 'Ref': meDriver.ME_REF_AI_GROUND, 'Flags': meDriver.ME_IO_STREAM_CONFIG_TYPE_NO_FLAGS} ConfList.append(ConfEntry) #Preaparing start list StartList = [] StartEntry = {'Device': NoDev, 'Subdevice': NoSubDev, 'StartMode': meDriver.ME_START_MODE_BLOCKING, #This is returning when stream STARTS! 'TimeOut': 0, 'Flags': meDriver.ME_IO_STREAM_START_TYPE_NO_FLAGS, 'Errno': 0} StartList.append(StartEntry) #Preaparing stop list StopList = [] StopEntry = {'Device': NoDev, 'Subdevice': NoSubDev, 'StopMode': meDriver.ME_STOP_MODE_IMMEDIATE, 'Flags': meDriver.ME_IO_STREAM_STOP_TYPE_NO_FLAGS, 'Errno': 0} StopList.append(StopEntry) #Using range 0 (iUnit, dMin, dMax, iMaxData) = meDriver.meQueryRangeInfo(NoDev, NoSubDev, 0) meDriver.meIOResetSubdevice(NoDev, NoSubDev, meDriver.ME_VALUE_NOT_USED) #Configure print "Configure AI" meDriver.meIOStreamConfig(NoDev, NoSubDev, ConfList, TrigList, AIBufSize, meDriver.ME_IO_STREAM_CONFIG_NO_FLAGS) print "Start AI" meDriver.meIOStreamStart(StartList, meDriver.ME_IO_STREAM_START_NO_FLAGS) print "Work" totalCount = 0 while (totalCount<DataBlockSize): #Read data (blocking mode) AIBufferCount=AIBufSize AIBuffer = meDriver.meIOStreamRead(NoDev, NoSubDev, meDriver.ME_READ_MODE_BLOCKING, AIBufferCount, meDriver.ME_IO_STREAM_READ_NO_FLAGS) #Show some samples print "\tSample 0x%x => %f" % (totalCount, meDriver.meUtilityDigitalToPhysical( dMin, dMax, iMaxData, AIBuffer[0], meDriver.ME_MODULE_TYPE_MULTISIG_NONE, 0)) totalCount = totalCount + len(AIBuffer) print "Stop AI" meDriver.meIOStreamStop(StopList, meDriver.ME_IO_STREAM_STOP_NO_FLAGS) print "AI stopped."