472,789 Members | 1,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 software developers and data experts.

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 2454

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
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.