Egor Zindy wrote:
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
#!/usr/bin/env python
"""
A generic chipid library based on ctypes
This module handles most of the functions in FTChipID.dll
PROBLEM:
FTID_GetDeviceLocationID doesn't work...
FTID_GetDeviceChipID doesn't work...
Well, not exactly true.
Works with 2 devices plugged in and for device with id 1.
Does not work for device with id 0... What am I doing wrong?!?!?!?!?!?!
How does it work?
relies on ctypes and ftchipid.dll, was only tested in windows XP
the chipid dll (1.1.0) from here:
http://www.ftdichip.com/Projects/FTDIChip-ID.htm
for testing, need the the ftd2xx module http://pypi.python.org/pypi/ftd2xx/0.1
and the ftd2xx.dll, which comes with the driver install
The latest version of this file is stored in my google code repository:
http://code.google.com/p/ezwidgets/
Copyright (c) 2008 Egor Zindy <[EMAIL PROTECTED]>
Released under the MIT licence.
"""
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
__author__ = "Egor Zindy <[EMAIL PROTECTED]>"
__copyright__ = "Copyright (c) 2008 Egor Zindy"
__license__ = "MIT"
__version__ = "0.1"
__date= "2008-07-10"
__status__ = "Alpha"
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():
n = DWORD()
status = ftchipid.FTID_GetNumDevices(ctypes.byref(n))
if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)
return n.value
def FTID_GetDeviceSerialNumber(DeviceIndex):
s = ctypes.create_string_buffer(256)
status = ftchipid.FTID_GetDeviceSerialNumber(DeviceIndex, s, 256)
if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)
return s.value
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
def FTID_GetDeviceDescription(DeviceIndex):
s = ctypes.create_string_buffer(256)
status = ftchipid.FTID_GetDeviceDescription(DeviceIndex, s, 256)
if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)
return s.value
def FTID_GetDllVersion():
s = ctypes.create_string_buffer(256)
status = ftchipid.FTID_GetDllVersion(s, 256)
if status != FTID_SUCCESS:
raise DeviceError,FTID_GetErrorCodeString("EN",status)
return s.value
def FTID_GetErrorCodeString(lpLanguage, ErrorCode):
sl = STRING(lpLanguage)
s = ctypes.create_string_buffer(256)
status = ftchipid.FTID_GetErrorCodeString(sl,ErrorCode,s,256)
return s.value
#ChipID errors...
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
#testing...
if __name__ == '__main__':
import ftd2xx
device = ftd2xx.open()
if 1:
print "\nDll version",
v = FTID_GetDllVersion()
print v
n = FTID_GetNumDevices()
print "\nNumber of devices:",n
for i in range(n):
if 0:
print "\nChip ID:",
v = FTID_GetDeviceChipID(i)
print i,"0x%08lX" % v
if 1:
print "\nLocation ID:",
v = FTID_GetDeviceLocationID(i)
print i,"0x%08lX" % v
if 1:
print "\nSerial number:",
v = FTID_GetDeviceSerialNumber(i)
print i,v
if 1:
print "\nDescription:",
v = FTID_GetDeviceDescription(i)
print i,v
device.close()
--
http://mail.python.org/mailman/listinfo/python-list