473,473 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: ftdi chip + ctypes + ftd2xx... need help with reading chipid!(now with the right source code!)

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/Eva...Kits/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 <ez****@gmail.com>

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 <ez****@gmail.com>"
__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,25 6)

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()
Jul 19 '08 #1
0 2522

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gandu | last post by:
I apologize if this is not the appropriate newsgroup to post this message. Could someone please tell me a good place to get an an Aloha protocol simulator source code(C++) that is well-documented...
17
by: wana | last post by:
I was reading through original source code of ping for some insight and was confused by unusual code. Entire listing available at: http://www.ping127001.com/pingpage/ping.html #include...
3
by: Stefan Behnel | last post by:
Hi! I need to generate source code (mainly Java) from a domain specific XML language, preferably from within a Python environment (since that's where the XML is generated). I tried using...
6
by: KG21 | last post by:
Need help i have the source code but don't know how to make it into a program. Any kind hearted people can make the source code and become a run able program? the file is too big... any kind...
1
by: TC | last post by:
I'm using Visual Studio 2005 with SourceGear Vault. I'm having trouble with the integrated source code control features. I think the problem is entirely with Visual Studio, not Vault. First, let...
8
by: teddarr | last post by:
I'm having trouble getting a mathmatical formula to work in my code. I am supposed to write a program in java that calculates the ending balance each month. The user is supposed to input the...
66
by: Jon Skeet [C# MVP] | last post by:
I'm sure the net will be buzzing with this news fairly soon, but just in case anyone hasn't seen it yet: Microsoft are going to make the source code for the .NET framework (parts of it,...
3
by: ddailey | last post by:
The code which follows is something I cobbled together quite hastily to display to students a way of illustrating HTML source code (including CSS and JavaScript) alongside a page as rendered. I've...
3
by: Jens-Oliver Murer | last post by:
Hello, I have a problem with an ASP.Net-application which generates very large source codes which have to be sent to the clients through 'thin' lines. The main problem seems to be a Datagrid...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.