def list_devices(): print "Vendor\t\tProduct\t\t\tSerial" dev_list = [] for device in Driver().list_devices(): device = map(lambda x: x.decode('latin1'), device) vendor, product, serial = device print "%s\t\t%s\t\t%s" % (vendor, product, serial)
def load_hardware(self): self.__device_type = None for device in Driver().list_devices(): vendor, product, self.__device = [x.decode('latin1') for x in device] self.__device_type = 'Serial' if product.endswith('UART') else 'BitBang' logger.debug('Found switch board {}, {}, {}, of type {}'.format(vendor,product,self.__device,self.__device_type)) break # For now, we only support 1 switch board!
def get_ftdi_device_list(): dev_list = [] for device in Driver().list_devices(): dev_info = device vendor, product, serial = dev_info # device must always be this triple dev_list.append(serial) return dev_list
def run(self): while self.parent.run: time.sleep(.5) new_devices = {} try: for device in Driver().list_devices(): # vendor, product, serial = map(lambda x: x.decode('latin1'), device) vendor, product, serial = map(lambda x: x, device) new_devices[serial] = (vendor, product) if not serial in self.ftdi_devices: wx.CallAfter(dispatcher.send, signal="USBMonitor", sender=self, action="add", vendor=vendor, product=product, serial=serial) for serial in self.ftdi_devices: if not serial in new_devices: wx.CallAfter(dispatcher.send, signal="USBMonitor", sender=self, action="remove", vendor=self.ftdi_devices[serial][0], product=self.ftdi_devices[serial][1], serial=serial) except FtdiError as e: if sys.exc_info()[0] == LibraryMissingError: wx.LogError(str(e)) break except LibraryMissingError as e: wx.LogError(str(e)) break self.ftdi_devices = new_devices
def GetFtdiDevices(): dev_list = {} for device in Driver().list_devices(): dev_info = map(lambda x: x.decode('latin1'), device) vendor, product, serial = dev_info dev_list[serial] = (vendor, product) return dev_list
def GetFtdiDevices(): dev_list = {} for device in Driver().list_devices(): dev_info = device vendor, product, serial = dev_info dev_list[serial] = (vendor, product) return dev_list
def return_device_serial_number(): # print "Vendor\t\tProduct\t\t\tSerial" serial = None for device in Driver().list_devices(): device = map(lambda x: x.decode("latin1"), device) vendor, product, serial = device # print "%s\t\t%s\t\t%s" % (vendor, product, serial) return serial
def __load_ftdi_device(self): for device in Driver().list_devices(): vendor, product, self.device = map(lambda x: x.decode('latin1'), device) self.device_type = 'Serial' if product.endswith( 'UART') else 'BitBang' logger.debug('Found switch board %s, %s, %s, of type %s' % (vendor, product, self.device, self.device_type)) break # For now, we only support 1 switch board!
def list_devices(): print('%-12s' % 'Vendor', '%-35s' % 'Product', '%-25s' % 'Serial', sep='\t') print( '--------------------------------------------------------------------') dev_list = [] for vendor, product, serial in Driver().list_devices(): print('%-12s' % vendor, '%-35s' % product, '%-25s' % serial, sep='\t')
def get_ftdi_device_list(): """ return a list of lines, each a colon-separated vendor:product:serial summary of detected devices """ dev_list = [] for device in Driver().list_devices(): # device must always be this triple vendor, product, serial = device dev_list.append("%s:%s:%s" % (vendor, product, serial)) return dev_list
class FTD2XXLinux(object): def __init__(self): self.driver = Driver() self.bb = None self.comport = None def initialise(self, deviceID, baudRate, mask, bitMode): try: indexed = deviceID.split("#", 2) if len(indexed) == 2: deviceID = indexed[0] which = int(indexed[1]) else: which = 0 index = 0 found = False for dev in self.driver.list_devices(): if re.search(deviceID + '.+', dev[2].decode()): if which == index: found = True print('Found device %s#%d => %s' % (deviceID, index, dev[2].decode())) deviceID = dev[2].decode() break index += 1 if found: self.bb = BitBangDevice(deviceID) self.bb.direction = mask self.bb.open() except Exception as e: raise dae_RelayBoard_Common.Denkovi_Exception( 'Could not connect to relay board: %s: %s' % (e.__class__, e)) if not found: raise dae_RelayBoard_Common.Denkovi_Exception( 'Relay board: %s#%d not found' % (deviceID, index)) def close(self): if self.bb is not None: self.bb.close() self.bb = None def writeByte(self, byte): if self.bb is None: raise dae_RelayBoard_Common.Denkovi_Exception( 'Board non initialized') self.bb.port = byte def readByte(self): if self.bb is None: raise dae_RelayBoard_Common.Denkovi_Exception( 'Board non initialized') return self.bb.port
def get_ftdi_device_list(): """ return a list of lines, each a colon-separated vendor:product:serial summary of detected devices """ dev_list = [] for device in Driver().list_devices(): # list_devices returns bytes rather than strings dev_info = map(lambda x: x.decode('latin1'), device) # device must always be this triple vendor, product, serial = dev_info dev_list.append("%s:%s:%s" % (vendor, product, serial)) return dev_list
def _scan_relays(callback = None, **kwargs): device_nr = 0 for (_, _, serial) in Driver().list_devices(): device_nr += 1 # We have by default 4 switches..... not sure... amount_sockets = 4 for x in range(amount_sockets): # Explicit None value for ID. This will force to generate a new ID based on the address yield terrariumRelay(None, terrariumRelayFTDI.HARDWARE, f'{x+1},{serial}', f'{terrariumRelayFTDI.NAME} device nr: {device_nr}({serial}) socket: {x+1}', callback=callback)
def reset_device(): print "locating device..." found = False while not found: for device in Driver().list_devices(): device = map(lambda x: x.decode('latin1'), device) vendor, product, serial = device print product if product == PRODUCT: found = True break else: retry() print "...done"
def load_hardware(self): address = self.__get_address() self.__device_type = None counter = 1 for device in Driver().list_devices(): if counter != address[1]: counter += 1 continue vendor, product, self.__device = [x for x in device] self.__device_type = 'Serial' if product.endswith('UART') else 'BitBang' logger.debug('Found switch board {}, {}, {}, of type {}'.format(vendor,product,self.__device,self.__device_type)) break # For now, we only support 1 switch board!
def getFTDIDevicesFromSystem(): global vendor global product global serial dev_list = [] for device in Driver().list_devices(): # list_devices returns bytes rather than strings dev_info = map(lambda x: x.decode('latin1'), device) # device must always be this triple vendor, product, serial = dev_info if vendor == "FTDI": dev_list.append("%s:%s:%s" % (vendor, product, serial)) return dev_list
def _load_hardware(self): # Address value = Switch_number,board_serial (optional). When board_serial is missing, use the first found device and update the address.... address = self._address number_mode = terrariumUtils.is_float(address[1]) counter = 1 for (_, device_type, serial) in Driver().list_devices(): # Loop until we reatch the number (amount) or serial that is entered if (number_mode and counter != address[1]) or (not number_mode and address[1] != serial): counter += 1 continue device = serial device_type = terrariumRelayFTDI.SERIAL if device_type.lower().endswith('uart') else terrariumRelayFTDI.BITBANG self.address = f'{address[0]},{device}' return (serial,device_type)
def GetFtdiDevices(): # devices = ftd.listDevices() # dev_list = {} # i = 0 # ftd.createDeviceInfoList() # for device in devices: # dev_info_detail = ftd.getDeviceInfoDetail(i, False) # i = i + 1 # serial = dev_info_detail.get("serial") # vendor = dev_info_detail.get("id") # product = dev_info_detail.get("description") # dev_list[serial] = (vendor, product) # return dev_list dev_list = {} for device in Driver().list_devices(): dev_info = map(lambda x: x.decode('latin1'), device) # dev_info = map(lambda x: x, device) vendor, product, serial = dev_info dev_list[serial] = (vendor, product) return dev_list
class FTD2XXLinux(object): def __init__(self): self.driver = Driver() self.bb = None self.comport = None def initialise(self, deviceID, baudRate, mask, bitMode): try: for dev in self.driver.list_devices(): if re.search(deviceID + '.+', dev[2]): deviceID = dev[2] print('Found device ' + deviceID) break if deviceID is None: raise dae_RelayBoard_Common.Denkovi_Exception( 'No board connected') self.bb = BitBangDevice(deviceID) self.bb.direction = mask self.bb.open() except Exception as e: raise dae_RelayBoard_Common.Denkovi_Exception( 'Could not connect to relay board: %s: %s' % (e.__class__, e)) def close(self): pass def writeByte(self, byte): if self.bb is None: raise dae_RelayBoard_Common.Denkovi_Exception( 'Board non initialized') self.bb.port = byte def readByte(self): if self.bb is None: raise dae_RelayBoard_Common.Denkovi_Exception( 'Board non initialized') return self.bb.port
from pylibftdi import Driver for dev in Driver().list_devices(): print(dev)
def devlist( self ): # should really be done outside of this script; but I'll just put it here too. SUDO PRIVILEGES NEEDED TO WORK, OTHERWISE LIST COMES BACK EMPTY. return Driver().list_devices()
def __init__(self): self.driver = Driver() self.bb = None self.comport = None
#! /usr/bin/python import sys, os #import pylibftdi from pylibftdi import Driver, Device try: dev_list = Driver().list_devices() if len(dev_list) != 0: print "\n\nFollowing devices found: \n" for device_ in dev_list: print device_ dev = Device(device_id="FTZ17IRO", mode='b', interface_select=2) dev.open() tx_data = bytearray(range(0, 256)) dev.write(tx_data) rx_data = bytearray(dev.read(257))#, timeout = 0)) if len(rx_data) == 256 : print "\n\n[Test] Test 1 Passed: Sent 256 bytes of data, received 256 bytes of data" failed = False for i in range(256): if ((tx_data[i]+1)%256) != rx_data[i]: print "[Test] Test 2: Data verification failed! , tx_data : ", tx_data[i], " =/= rx_data : ", rx_data[i] failed = True
def list_serial_only(): # print("Vendor\t\tProduct\t\t\tSerial") for device in Driver().list_devices(): device = map(lambda x: x, device) vendor, product, serial = device print("%s" % serial)