def main(): """ Send/receive data from the Papilio FPGA using the high speed mode of the FT232H. """ # Create the device list. num_devices = ft.createDeviceInfoList() if (num_devices == 0): print "No devices found." sys.exit(); print "Found {0} devices.".format(num_devices) # Get the device information for the device with sync FIFO mode. device_info = None device_index = 0 for index in range(0, num_devices): device_info = ft.getDeviceInfoDetail(devnum = index, update = False) if (device_info['description'] == 'UM232H_245FIFO'): device_index = index break if (device_info == None): print "Device not found." sys.exit() # Open the device and configure for sync FIFO mode. ft.setVIDPID(0x0403, 0x6014) device = ft.open(dev = device_index) device.setBitMode(0xFF, 0x00) # Reset mode sleep(.01) device.setBitMode(0xFF, 0x40) # Sync FIFO mode device.setLatencyTimer(2) # Receive buffer timeout in msec device.setUSBParameters(4096, 4096) # Set transfer in/out size to 4096 device.setFlowControl(FLOW_RTS_CTS, 0, 0) # Flow control method
def open( self ): # This method must return a string showing whether the open succeeded or failed. enum = d2xx.createDeviceInfoList() # quantity of FTDI devices if (enum == 0): return 'Device was not found' for i in range(enum): # Searching and openinq needed device a = d2xx.getDeviceInfoDetail(i) if (a['description'] == 'SDR-Micron'): try: self.usb = d2xx.openEx(a['serial']) except: return 'Device was not found' Mode = 64 # Configure FT2232H into 0x40 Sync FIFO Mode self.usb.setBitMode(255, 0) # reset time.sleep(0.1) self.usb.setBitMode( 255, Mode) #configure FT2232H into Sync FIFO mode self.usb.setTimeouts(100, 100) # read, write self.usb.setLatencyTimer(2) self.usb.setUSBParameters(64, 64) # in_tx_size, out_tx_size=0 time.sleep(1.5) # waiting for initialisation device data = self.usb.read( self.usb.getQueueStatus()) # clean the usb data buffer self.device = 'Opened' self.frame_msg = a['description'] + ' S/N - ' + a['serial'] return self.frame_msg return 'Device was not found'
def __init__(self, param_dict): param_dict = self._translate_dict_values(param_dict, self.ftd2xx_dict) [setattr(self, key, val) for key, val in param_dict.items()] self.n_bytes = param_dict["n_bytes"] # auto-find UM232H serial number num_devs = ftd2xx.createDeviceInfoList() for idx in range(num_devs): info_dict = ftd2xx.getDeviceInfoDetail(devnum=idx) if info_dict["description"] == b"UM232H": self.serial = info_dict["serial"]
def _print_ftdi_devices(self): """ :return: """ import ftd2xx as ft ftdi_devices = ft.listDevices() print("[*] Found the following FTDI device(s)") devnum = 0 for ftdi_device in ftdi_devices: print("FTDI device:\t {} \t {}".format( ftdi_device, ft.getDeviceInfoDetail(devnum=devnum))) devnum += 1
def ft_init(self): #Get the device list and save the index of logic analyzer into deviceIndex self.deviceList = ftd2xx.listDevices(0) # returns the list of ftdi devices S/Ns self.deviceIndex = -1; self.status = -1; if self.deviceList : print(len(self.deviceList), 'ftdi devices found') for x in range(0,len(self.deviceList)): if ( "LogicAnalyzer" in str(ftd2xx.getDeviceInfoDetail(x)['description'])) : print("Device %d details: "%x) print('-------------------------------------------------') print("Serial : " + str(ftd2xx.getDeviceInfoDetail(x)['serial'])) print("Type : " + str(ftd2xx.getDeviceInfoDetail(x)['type'])) print("ID : " + str(ftd2xx.getDeviceInfoDetail(x)['id'])) print("Description : " + str(ftd2xx.getDeviceInfoDetail(x)['description'])) print('-------------------------------------------------') if self.deviceIndex < 0: self.deviceIndex = x break else: print("no ftdi devices connected")
def _find_some_simps(self): # Determine the number of devices. This is a slow call. number_of_devices = ftd2xx.createDeviceInfoList() # For each FTDI device using the D2XX drivers, get and check the device description for a simp. devices = [] for index in range(number_of_devices): try: # Update is false to prevent another slow createDeviceInfoList call. device_details = ftd2xx.getDeviceInfoDetail(index, update=False) if (device_details['description'] == b'SIMPS Device'): devices.append(device_details) elif (device_details['description'] == b'SIMPS ATE'): devices.append(device_details) except ftd2xx.ftd2xx.DeviceError: pass return devices
def __init__(self, device=None, initbaud=38400, progbaud=1000000): vid, pid, iserial = usbutils.query_usb_id(device) devserials= ftd2xx.listDevices(); dev = None for i, sn in enumerate(devserials): if sn == iserial.encode(): dev = ftd2xx.getDeviceInfoDetail(i) break if dev == None: raise Exception(device + " not found") self.INITBAUD, self.PROGBAUD = int(initbaud), int(progbaud) self.SERIAL = iserial JennicProtocol.__init__(self)
def ftdi_open(board_id, channel, desc=None): """opens FTDI device function depending of the current OS""" if OS == 'Linux': return pylibftdi.Device(device_index=board_id, interface_select=channel + 1) elif OS == 'Windows': add = desc.get('location') dev_list = ftdi.listDevices() dev_channel = None for i, d in enumerate(dev_list): if d != b'': if chr(d[-1]) == chr(ord('A') + channel): tmp_dev = ftdi.getDeviceInfoDetail(i) if tmp_dev.get('location') == add + channel: dev_channel = tmp_dev.get('index') else: pass return ftdi.open(dev_channel)
def testgetDeviceInfoDetail(self): self.assert_(isinstance(ftd2xx.getDeviceInfoDetail(), dict))
def __init__(self,hwser=None): # Find out how many ftd2xx devices are connected to the USB bus numDevices=ftd2xx.createDeviceInfoList() # Check each device to see if either the serial number matches (if given) or the description string is recognized as valid for the class type numMatchingDevices=0 for dev in range(numDevices): detail=ftd2xx.getDeviceInfoDetail(dev) if hwser!=None and detail["serial"]!="" and int(detail["serial"])==hwser: # Get the first device which matches the serial number if given numMatchingDevices+=1 self.device=device=ftd2xx.open(dev) break elif hwser==None and (detail["description"] in self.deviceDescriptionStrings()): # Get the first device which is valid for the given class if no hwser numMatchingDevices+=1 if numMatchingDevices==1: self.device=device=ftd2xx.open(dev) elif dev==numDevices-1 and numMatchingDevices==0: # Raise an exception if no devices were found if hwser!=None: errorStr="Hardware serial number " + str(hwser) + " was not found" else: errorStr="No devices found matching class name " + type(self).__name__ + ". Expand the definition of CLASS_STRING_MAPPING if necessary" raise DeviceNotFoundError, errorStr # Print a warning message if no serial given and multiple devices were found which matched the class type if numMatchingDevices>1 and hwser==None: print(str(numMatchingDevices)+" devices found matching " + type(self).__name__ + "; the first device was opened") # Inititalize the device according to FTD2xx and APT requirements device.setBaudRate(ftd2xx.defines.BAUD_115200) device.setDataCharacteristics(ftd2xx.defines.BITS_8,ftd2xx.defines.STOP_BITS_1,ftd2xx.defines.PARITY_NONE) self.delay() device.purge() self.delay() device.resetDevice() device.setFlowControl(ftd2xx.defines.FLOW_RTS_CTS) device.setTimeouts(c.WRITE_TIMEOUT,c.READ_TIMEOUT) # Check first 2 digits of serial number to see if it's normal type or card/slot type, and build self.channelAddresses as list of (chanID,destAddress) tuples self.channelAddresses=[] if device.serial[0:2] in c.BAY_TYPE_SERIAL_PREFIXES: # Get the device info serNum,model,hwtype,firmwareVer,notes,hwVer,modState,numCh=self.query(c.MGMSG_HW_REQ_INFO,c.MGMSG_HW_GET_INFO,destID=c.RACK_CONTROLLER_ID)[-1] # Check each bay to see if it's enabled and also request hardware info for bay in range(numCh): bayId=c.ALL_BAYS[bay] self.writeMessage(c.MGMSG_HW_NO_FLASH_PROGRAMMING,destID=bayId) if self.BayUsed(bay): bayInfo=self.query(c.MGMSG_HW_REQ_INFO,c.MGMSG_HW_GET_INFO,destID=bayId)[-1] self.channelAddresses.append((c.CHANNEL_1,bayId)) else: # Otherwise just build a list of the channel numbers self.writeMessage(c.MGMSG_HW_NO_FLASH_PROGRAMMING,destID=c.GENERIC_USB_ID) serNum,model,hwtype,firmwareVer,notes,hwVer,modState,numCh=self.query(c.MGMSG_HW_REQ_INFO,c.MGMSG_HW_GET_INFO)[-1] for channel in range(numCh): self.channelAddresses.append((c.ALL_CHANNELS[channel],c.GENERIC_USB_ID)) for channel in range(len(self.channelAddresses)): self.writeMessage(c.MGMSG_MOD_SET_CHANENABLESTATE,1,c.CHAN_ENABLE_STATE_ENABLED,c.RACK_CONTROLLER_ID) self.EnableHWChannel(channel) # Set the controller type self.controllerType=model.replace("\x00","").strip() # Print a message saying we've connected to the device successfuly print("Connected to %s device with serial number %d. Notes about device: %s"%(model.replace('\x00', ''),serNum,notes.replace('\x00', '')))
import ftd2xx import pprint devNum = ftd2xx.createDeviceInfoList() getDeviceInfoDetail = [ ftd2xx.getDeviceInfoDetail(devnum=i, update=False) for i in range(devNum) ] dev = ftd2xx.open(0) dev.setChars(False, 0, False, 0) dev.setTimeouts(5000, 5000) dev.setLatencyTimer(2) dev.setBaudRate(300) AsynchronousBitBang = 0x01 dev.setBitMode(0x00, AsynchronousBitBang) value = None while True: rxBytes = dev.getQueueStatus() if rxBytes: rxbuffer = dev.read(rxBytes) newValue = rxbuffer[-1] if value != newValue: print(hex(newValue)) value = newValue
def __init__(self, hwser=None): # Find out how many ftd2xx devices are connected to the USB bus numDevices = ftd2xx.createDeviceInfoList() # Check each device to see if either the serial number matches (if given) or the description string is recognized as valid for the class type numMatchingDevices = 0 for dev in range(numDevices): detail = ftd2xx.getDeviceInfoDetail(dev) if hwser != None and detail["serial"] != "" and int( detail["serial"]) == hwser: # Get the first device which matches the serial number if given numMatchingDevices += 1 self.device = device = ftd2xx.open(dev) break elif hwser == None and (detail["description"] in self.deviceDescriptionStrings()): # Get the first device which is valid for the given class if no hwser numMatchingDevices += 1 if numMatchingDevices == 1: self.device = device = ftd2xx.open(dev) elif dev == numDevices - 1 and numMatchingDevices == 0: # Raise an exception if no devices were found if hwser != None: errorStr = "Hardware serial number " + str( hwser) + " was not found" else: errorStr = "No devices found matching class name " + type( self ).__name__ + ". Expand the definition of CLASS_STRING_MAPPING if necessary" raise DeviceNotFoundError, errorStr # Print a warning message if no serial given and multiple devices were found which matched the class type if numMatchingDevices > 1 and hwser == None: print( str(numMatchingDevices) + " devices found matching " + type(self).__name__ + "; the first device was opened") # Inititalize the device according to FTD2xx and APT requirements device.setBaudRate(ftd2xx.defines.BAUD_115200) device.setDataCharacteristics(ftd2xx.defines.BITS_8, ftd2xx.defines.STOP_BITS_1, ftd2xx.defines.PARITY_NONE) self.delay() device.purge() self.delay() device.resetDevice() device.setFlowControl(ftd2xx.defines.FLOW_RTS_CTS) device.setTimeouts(c.WRITE_TIMEOUT, c.READ_TIMEOUT) # Check first 2 digits of serial number to see if it's normal type or card/slot type, and build self.channelAddresses as list of (chanID,destAddress) tuples self.channelAddresses = [] if device.serial[0:2] in c.BAY_TYPE_SERIAL_PREFIXES: # Get the device info serNum, model, hwtype, firmwareVer, notes, hwVer, modState, numCh = self.query( c.MGMSG_HW_REQ_INFO, c.MGMSG_HW_GET_INFO, destID=c.RACK_CONTROLLER_ID)[-1] # Check each bay to see if it's enabled and also request hardware info for bay in range(numCh): bayId = c.ALL_BAYS[bay] self.writeMessage(c.MGMSG_HW_NO_FLASH_PROGRAMMING, destID=bayId) if self.BayUsed(bay): bayInfo = self.query(c.MGMSG_HW_REQ_INFO, c.MGMSG_HW_GET_INFO, destID=bayId)[-1] self.channelAddresses.append((c.CHANNEL_1, bayId)) else: # Otherwise just build a list of the channel numbers self.writeMessage(c.MGMSG_HW_NO_FLASH_PROGRAMMING, destID=c.GENERIC_USB_ID) serNum, model, hwtype, firmwareVer, notes, hwVer, modState, numCh = self.query( c.MGMSG_HW_REQ_INFO, c.MGMSG_HW_GET_INFO)[-1] for channel in range(numCh): self.channelAddresses.append( (c.ALL_CHANNELS[channel], c.GENERIC_USB_ID)) for channel in range(len(self.channelAddresses)): self.writeMessage(c.MGMSG_MOD_SET_CHANENABLESTATE, 1, c.CHAN_ENABLE_STATE_ENABLED, c.RACK_CONTROLLER_ID) self.EnableHWChannel(channel) # Set the controller type self.controllerType = model.replace("\x00", "").strip() # Print a message saying we've connected to the device successfuly print( "Connected to %s device with serial number %d. Notes about device: %s" % (model.replace('\x00', ''), serNum, notes.replace('\x00', '')))