Dear List,
This one is way beyond my comprehension skills, I just don't understand
what I'm doing wrong.
I am trying to read the chipid from an FTDI chip based USB key (DLP-D,
http://www.ftdichip.com/Products/EvaluationKits/DLP-D.htm ), using:
- the ftd2xx module http://pypi.python.org/pypi/ftd2xx/0.1
- the ftd2xx.dll which comes with the driver install
- the chipid dll (1.1.0) from here:
http://www.ftdichip.com/Projects/FTDIChip-ID.htm
- a ctypes interface I wrote by hand (only 7 functions to wrap, I
thought it'd be easy!)
The ftd2xx is used for testing, to open / close the device.
My Problem is that neither of the following two wrapped functions (with
the exact same arguments) return the right result (full chipid.py
library attached):
def FTID_GetDeviceLocationID(DeviceIndex):
n = DWORD()
status = ftchipid.FTID_GetDeviceLocationID(DeviceIndex,
ctypes.byref(n))
if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)
return n.value
def FTID_GetDeviceChipID(DeviceIndex):
n = DWORD()
status = ftchipid.FTID_GetDeviceChipID(DeviceIndex, ctypes.byref(n))
if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)
return n.value
* On my machine (XP, 32 bits), if I plug two keys in, I can get the
device chip id from the device with index=1. The one with index=0 always
gives the message "Invalid device handle."
* I get the wrong location id as well, 0 instead of 0x21...
* the FTID_GetNumDevices function also uses a byref, c_ulong and works.
* FTDI's win32 console example returns the right results (and uses c
unsigned longs) - available from
http://www.ftdichip.com/Projects/FTDIChip-ID.htm
Any help appreciated!
Regards,
Egor
#-----------------------------------------------------------------------------
#
# Encoder card device driver module
#
#-----------------------------------------------------------------------------
#
# Revision History.
#
# V1.0 20031023 first module (translated from the VB header file)
#
#-----------------------------------------------------------------------------
# XXX Make use of python exceptions?
import ctypes
import ctypes.wintypes
import sys
STRING = ctypes.c_char_p
if sys.platform == 'win32':
DWORD = ctypes.wintypes.DWORD
else:
DWORD = ctypes.c_ulong
#calling the dll
ftchipid=ctypes.windll.ftchipid
class DeviceError(Exception):
"""Exception class for status messages"""
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
def FTID_GetNumDevices():
arg1 = DWORD()
status = ftchipid.FTID_GetNumDevices(ctypes.byref(arg1))
if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)
return arg1.value
def FTID_GetDeviceSerialNumber(DeviceIndex):
arg1 = DWORD(DeviceIndex)
arg2 = ctypes.create_string_buffer(256)
arg3 = DWORD(256)
status = ftchipid.FTID_GetDeviceSerialNumber(arg1, arg2, arg3)
if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)
return arg2.value
def FTID_GetDeviceLocationID(DeviceIndex):
arg1 = DWORD(DeviceIndex)
arg2 = DWORD()
status = ftchipid.FTID_GetDeviceLocationID(arg1, ctypes.byref(arg2))
if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)
return arg2.value
def FTID_GetDeviceChipID(DeviceIndex):
arg1 = DWORD(DeviceIndex)
arg2 = DWORD()
status = ftchipid.FTID_GetDeviceChipID(ctypes.c_long(0), ctypes.byref(arg2))
if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)
return arg2.value
def FTID_GetDeviceDescription(DeviceIndex):
arg1 = DWORD(DeviceIndex)
arg2 = ctypes.create_string_buffer(256)
arg3 = DWORD(256)
status = ftchipid.FTID_GetDeviceDescription(arg1, arg2, arg3)
if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)
return arg2.value
def FTID_GetDllVersion():
arg1 = ctypes.create_string_buffer(256)
arg2 = DWORD(256)
status = ftchipid.FTID_GetDllVersion(arg1, arg2)
if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)
return arg1.value
def FTID_GetErrorCodeString(lpLanguage, ErrorCode):
arg1 = STRING(lpLanguage)
arg2 = DWORD(ErrorCode)
arg3 = ctypes.create_string_buffer(256)
arg4 = DWORD(256)
status = ftchipid.FTID_GetErrorCodeString(arg1,arg2,arg3,arg4)
return arg3.value
#ChipID returns...
FTID_SUCCESS = 0
FTID_INVALID_HANDLE = 1
FTID_DEVICE_NOT_FOUND = 2
FTID_DEVICE_NOT_OPENED = 3
FTID_IO_ERROR = 4
FTID_INSUFFICIENT_RESOURCES = 5
FTID_BUFER_SIZE_TOO_SMALL = 20
FTID_PASSED_NULL_POINTER = 21
FTID_INVALID_LANGUAGE_CODE = 22
FTID_INVALID_STATUS_CODE = 0xFFFFFFFF
if __name__ == '__main__':
import ftd2xx
#test things...
device = ftd2xx.open()
if 1:
print "\nNumber of devices:"
print FTID_GetNumDevices()
if 1:
print "\nChip ID"
v = FTID_GetDeviceChipID(1L)
print hex(v)
if 0:
print "\nSerial number:"
v = FTID_GetDeviceSerialNumber(0)
print v
if 0:
print "\nLocation ID:"
v = FTID_GetDeviceLocationID(0)
print v
if 0:
print "\nDll version"
v = FTID_GetDllVersion()
print v
if 0:
print "\nDescription:"
v = FTID_GetDeviceDescription(0)
print v
if 0:
print "\nError 0"
v = FTID_GetErrorCodeString("EN",0)
print v
device.close()
--
http://mail.python.org/mailman/listinfo/python-list