示例#1
0
 def getDeviceInfo(self):
     """Returns a dictionary describing the device. """
     deviceType = _ft.DWORD()
     deviceId = _ft.DWORD()
     desc = c.c_buffer(FT_MAX_DESCRIPTION_SIZE)
     serial = c.c_buffer(FT_MAX_DESCRIPTION_SIZE)
     self.status = call_ft(_ft.FT_GetDeviceInfo, self.handle,
                           c.byref(deviceType), c.byref(deviceId), serial,
                           desc, None)
     return {
         'Type': deviceType.value,
         'ID': deviceId.value,
         'Description': desc.value,
         'Serial': serial.value
     }
示例#2
0
def create(id_str, flags=FT_OPEN_BY_INDEX):
    """Open a handle to a usb device by serial number, description or
    index depending on value of flags and return an FTD3XX instance for it"""
    h = _ft.FT_HANDLE()
    status = call_ft(_ft.FT_Create, id_str, _ft.DWORD(flags), c.byref(h))
    if (status != _ft.FT_OK):
        return None
    return FTD3XX(h)
示例#3
0
 def getStringDescriptor(self, index):
     """Returns a string descriptor. """
     strDesc = _ft.FT_STRING_DESCRIPTOR()
     lenTransferred = _ft.DWORD()
     self.status = call_ft(_ft.FT_GetDescriptor, self.handle,
                           _ft.UCHAR(FT_STRING_DESCRIPTOR_TYPE),
                           _ft.UCHAR(index), c.pointer(strDesc),
                           c.sizeof(strDesc), c.byref(lenTransferred))
     return strDesc
示例#4
0
def getDeviceInfoList():
    """Get device info list and return number of entries"""
    numDevices = _ft.DWORD()
    call_ft(_ft.FT_ListDevices, c.byref(numDevices), None,
            _ft.DWORD(FT_LIST_NUMBER_ONLY))
    numDevices = numDevices.value
    if numDevices == 0:
        return None
    """Use getDeviceInfoDetail instead"""
    deviceList = []
    for i in range(numDevices):
        device = _ft.FT_DEVICE_LIST_INFO_NODE()
        deviceInfo = getDeviceInfoDetail(i)
        device.Flags = deviceInfo['Flags']
        device.ID = deviceInfo['ID']
        device.LocId = deviceInfo['LocId']
        device.SerialNumber = deviceInfo['SerialNumber']
        device.Description = deviceInfo['Description']
        deviceList.append(device)
    return deviceList
示例#5
0
def listDevices(flags=_ft.FT_OPEN_BY_DESCRIPTION):
    """Return a list of serial numbers(default), descriptions or
    locations (Windows only) of the connected FTDI devices depending on value of flags"""
    n = _ft.DWORD()
    call_ft(_ft.FT_ListDevices, c.byref(n), None,
            _ft.DWORD(FT_LIST_NUMBER_ONLY))
    devcount = n.value
    if devcount:
        if flags == _ft.FT_OPEN_BY_INDEX:
            flags = _ft.FT_OPEN_BY_DESCRIPTION
        # since ctypes has no pointer arithmetic.
        bd = [c.c_buffer(FT_MAX_DESCRIPTION_SIZE)
              for i in range(devcount)] + [None]
        # array of pointers to those strings, initially all NULL
        ba = (c.c_char_p * (devcount + 1))()
        for i in range(devcount):
            ba[i] = c.cast(bd[i], c.c_char_p)
        call_ft(_ft.FT_ListDevices, ba, c.byref(n),
                _ft.DWORD(FT_LIST_ALL | flags))
        return [res for res in ba[:devcount]]
    else:
        return None
示例#6
0
def getDeviceInfoDetail(devnum=0):
    """Get an entry from the internal device info list."""
    f = _ft.DWORD()
    t = _ft.DWORD()
    i = _ft.DWORD()
    l = _ft.DWORD()
    h = _ft.FT_HANDLE()
    n = c.c_buffer(FT_MAX_DESCRIPTION_SIZE)
    d = c.c_buffer(FT_MAX_DESCRIPTION_SIZE)
    call_ft(_ft.FT_GetDeviceInfoDetail, _ft.DWORD(devnum), c.byref(f),
            c.byref(t), c.byref(i), c.byref(l), n, d, c.byref(h))
    if sys.platform == 'linux2':
        """Linux creates a handle to the device so close it. D3XX Linux driver issue."""
        call_ft(_ft.FT_Close, h)
    return {
        'Flags': f.value,
        'Type': t.value,
        'ID': i.value,
        'LocId': l.value,
        'SerialNumber': n.value,
        'Description': d.value
    }
示例#7
0
def createDeviceInfoList():
    """Create the internal device info list and return number of entries"""
    numDevices = _ft.DWORD()
    call_ft(_ft.FT_CreateDeviceInfoList, c.byref(numDevices))
    return numDevices.value
示例#8
0
 def getFirmwareVersion(self):
     """Get the version of the firmware"""
     firmwareVer = _ft.DWORD()
     self.status = call_ft(_ft.FT_GetFirmwareVersion, self.handle,
                           c.byref(firmwareVer))
     return firmwareVer.value
示例#9
0
 def getDriverVersion(self):
     """Get the version of the kernel driver"""
     driverVer = _ft.DWORD()
     self.status = call_ft(_ft.FT_GetDriverVersion, self.handle,
                           c.byref(driverVer))
     return driverVer.value
示例#10
0
 def getLibraryVersion(self):
     """Get the version of the user driver library"""
     libraryVer = _ft.DWORD()
     self.status = call_ft(_ft.FT_GetLibraryVersion, c.byref(libraryVer))
     return libraryVer.value