PT-104 Problem with handling multiple units

Having problems ? let us know the details here
Post Reply
sruizr
Newbie
Posts: 1
Joined: Tue Apr 28, 2020 8:56 am

PT-104 Problem with handling multiple units

Post by sruizr »

Environment:
  • Hardware: Rasbperry pi 3 B+
  • Operating system: Raspbian Buster(and same results with Jessei)
  • Language: Python 3.7
  • Driver version: 'UsbPT104 Linux Driver, 2.0.17.1441'
  • Usb version: '1.1'
  • Hardware_version: '1'
  • Kernel Driver version: '1.0'
When several PT-104 are connected with usb to the same rasbperry pi board, the driver assign same handle for different units.
Code which reproduce bug:

Code: Select all

import ctypes as c                                                                                                                                                                                                                            
from ctypes.util import find_library                                                                                                                                                                                                          
                                                                                                                                                                                                                                              
lib_path = find_library('usbpt104')                                                                                                                                                                                                           
libusbpt104 = c.cdll.LoadLibrary(lib_path)                                                                                                                                                                                                    
libusbpt104.UsbPt104Enumerate.argtypes = [c.POINTER(c.c_char),                                                                                                                                                                                
                                          c.POINTER(c.c_ulong),                                                                                                                                                                               
                                          c.c_short]                                                                                                                                                                                          
                                                                                                                                                                                                                                              
libusbpt104.UsbPt104OpenUnit.argtypes = [c.POINTER(c.c_short),                                                                                                                                                                                
                                         c.POINTER(c.c_char)]                                                                                                                                                                                 
                                                                                                                                                                                                                                              
libusbpt104.UsbPt104CloseUnit.argtypes = [c.c_short]                                                                                                                                                                                          
                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                              
def open_unit(batch_and_serial):                                                                                                                                                                                                              
    handle = c.c_short()                                                                                                                                                                                                                      
    batch_and_serial = batch_and_serial.encode()                                                                                                                                                                                              
    status = libusbpt104.UsbPt104OpenUnit(c.byref(handle), batch_and_serial)                                                                                                                                                                  
    if status != 0:                                                                                                                                                                                                                           
        raise Exception(f'PICO ERROR WITH CODE {status}')                                                                                                                                                                                     
                                                                                                                                                                                                                                              
    print(f'Handle for {batch_and_serial.decode()} is {handle}')                                                                                                                                                                              
                                                                                                                                                                                                                                              
    return handle                                                                                                                                                                                                                             
                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                              
def discover_devices():                                                                                                                                                                                                                       
    enum_len = c.c_ulong(256)                                                                                                                                                                                                                 
    enum_string = c.create_string_buffer(256)                                                                                                                                                                                                 
    communication_type = c.c_short()                                                                                                                                                                                                          
    communication_type.value = 3                                                                                                                                                                                                              
    libusbpt104.UsbPt104Enumerate(enum_string, enum_len,                                                                                                                                                                                      
                                  communication_type)                                                                                                                                                                                         
                                                                                                                                                                                                                                              
    devices = enum_string.value.decode().split(',')                                                                                                                                                                                           
    print(devices)                                                                                                                                                                                                                            
                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                              
discover_devices()                                                                                                                                                                                                                            
SN_3 = 'EY477/080'                                                                                                                                                                                                                            
SN_2 = 'FO527/106'                                                                                                                                                                                                                            
SN_1 = 'EY477/119'                                                                                                                                                                                                                            
                                                                                                                                                                                                                                              
handle_1 = open_unit(SN_1)                                                                                                                                                                                                                    
handle_2 = open_unit(SN_2)                                                                                                                                                                                                                    
handle_3 = open_unit(SN_3)                                                                                                                                                                                                                    
                                                                                                                                                                                                                                              
libusbpt104.UsbPt104CloseUnit(handle_1)                                                                                                                                                                                                       
print(f'Closing {SN_1}')                                                                                                                                                                                                                      
                                                                                                                                                                                                                                              
handle_1 = open_unit(SN_1)                           
Output after running the script:

Code: Select all

['USB:EY477/080', 'USB:FO527/106', 'USB:EY477/119']
Handle for EY477/119 is c_short(3)
Handle for FO527/106 is c_short(2)
Handle for EY477/080 is c_short(1)
Closing EY477/119
Handle for EY477/119 is c_short(1)
Af you can see EY477/119 device is mixed with EY477/080. The result is that I can not access again to EY477/119. Unless you open the devices in the inverse order they are listed when enumerated, the handle are mixed and it's not possible to access them.

Post Reply