Jump to content
  • 0

wrong device opened after selecting from device enumeration list, python analog discovery


mikeyc

Question

Hi there,

I have an unrelated applications that work with different analog discovery units (2 and a pro) from the same host (win10), using python. DWF Version: b'3.20.1'

I enumerate the connected devices, then search the enumerated list for the serial number of the dev I want to open, then open that device. This always results in the wrong device opened, instead the last device enumerated is always opened. Any way to specifically open a device by serial number? Many thanks!

 

#declare ctype variables

hdwf = c_int()

cDevice = c_int()

cConfig = c_int()

cInfo = c_int()

iDevId = c_int()

iDevRev = c_int()

 

#declare string variables

devicename = create_string_buffer(64)

serialnum = create_string_buffer(16)

 

#enumerate and print device information

dwf.FDwfEnum(enumfilterAll, byref(cDevice))

#dwf.FDwfEnum(devidDiscovery2, byref(cDevice)) only Analog Discovery 2 devices

#dwf.FDwfEnum(c_int(enumfilterType.value|enumfilterUSB.value), byref(cDevice)) # only USB devices

print("Number of Devices: "+str(cDevice.value))

 

# create list of device dictionaries

devices = []

for iDev in range(0, cDevice.value):

   

    dwf.FDwfEnumDeviceName (c_int(iDev), devicename)

    dwf.FDwfEnumSN (c_int(iDev), serialnum)

    dwf.FDwfEnumDeviceType (c_int(iDev), byref(iDevId), byref(iDevRev))

    others = create_string_buffer(128)

    print("------------------------------")

    print("Device "+str(iDev)+" : ")

    print("\tName: " + str(devicename.value.decode()) + " " + str(serialnum.value.decode()))

    print("\tID: "+str(iDevId.value)+" rev: "+chr(0x40+(iDevRev.value&0xF))+" "+hex(iDevRev.value)) # LSbits of rev represent 1=A, 2=B

 

    print("\tConfigurations:")

    dwf.FDwfEnumConfig(c_int(iDev), byref(cConfig))

    for iCfg in range (0, cConfig.value):

        sz = "\t"+str(iCfg)+"."

        dwf.FDwfEnumConfigInfo(c_int(iCfg), c_int(1), byref(cInfo)) # DECIAnalogInChannelCount

        sz += " AnalogIn: "+str(cInfo.value)

        dwf.FDwfEnumConfigInfo(c_int(iCfg), c_int(7), byref(cInfo)) # DECIAnalogInBufferSize

        sz += " x "+str(cInfo.value)

        dwf.FDwfEnumConfigInfo(c_int(iCfg), c_int(2), byref(cInfo)) # DECIAnalogOutChannelCount

        sz += " \tAnalogOut: "+str(cInfo.value)

        dwf.FDwfEnumConfigInfo(c_int(iCfg), c_int(8), byref(cInfo)) # DECIAnalogOutBufferSize

        sz += " x "+str(cInfo.value)

        dwf.FDwfEnumConfigInfo(c_int(iCfg), c_int(4), byref(cInfo)) # DECIDigitalInChannelCount

        sz += " \tDigitalIn: "+str(cInfo.value)

        dwf.FDwfEnumConfigInfo(c_int(iCfg), c_int(9), byref(cInfo)) # DECIDigitalInBufferSize

        sz += " x "+str(cInfo.value)

        dwf.FDwfEnumConfigInfo(c_int(iCfg), c_int(5), byref(cInfo)) # DECIDigitalOutChannelCount

        sz += " \tDigitalOut: "+str(cInfo.value)

        dwf.FDwfEnumConfigInfo(c_int(iCfg), c_int(10), byref(cInfo)) # DECIDigitalOutBufferSize

        sz += " x "+str(cInfo.value)

        dwf.FDwfEnumConfigInfo(c_int(iCfg), c_int(-2), byref(others)) # other text info

        szothers = str(others.value.decode())

        if len(szothers) > 1 : sz += " \t"+szothers

        print(sz)

 

    devices.append({

        'dev'       : iDev,

        'devName'   : str(devicename.value.decode()),

        'snum'      : serialnum.value.decode(),

        'devID'     : iDevId.value,

        'devRev'    : chr(0x40+(iDevRev.value&0xF))+" "+hex(iDevRev.value),

        })

targetDevSN = 'SN:210018B23D22'

for dev in devices:

    if targetDevSN == dev['snum']:

        devID = dev['dev']

        print('Found target device: ' + targetDevSN + ' device ID: ' + str(devID))

        break

 

# #open device

print("Opening device... " + str(devID))

dwf.FDwfParamSet(DwfParamOnClose, c_int(0)) # 0 = continue running, 1 = stop, 2 = shutdown

#declare ctype variables

hdwf = c_int()

#devID = 1

dwf.FDwfDeviceOpen(c_int(devID), byref(hdwf))

 

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...