pylibftdi calling convension error

Issue #29 open
PerChr
created an issue

Hi

First, sorry for issue #28, something went wrong!

My setup is a 64 bit WIN 10 PC, with Anaconda 32 bit version or a 64 bit WIN 7 PC, with Anaconda 64 bit.

I have a relay board, which is based on the FtdiBitBangDUT.

On WIN 10 I get get an error when I try to open the device:

(sophiasystest) D:\Projects\Sophiadevtest\Test\SysTest\Sophia>python test.py -v run setechocancelleron -N Running on: IT-02509 13:54:18.505 Using testprofile 'default' Test cases to be executed: ['sophia_tests.SophiaTests.testSetEchoCancellerOn'] ================================================================================ tests.sophia_tests.SophiaTests.testSetEchoCancellerOn 13:54:18.513 ---== Setting up ==--- 13:54:18.513 ---== Setting up ==--- 13:54:18.513 Initializing DUT power_relay ERROR Traceback (most recent call last): File "C:\Anaconda3\envs\sophiasystest\lib\site-packages\devtest\core\case.py", line 394, in run self.setUp() File "D:\Projects\Sophiadevtest\Test\SysTest\Sophia\tests\sophia_tests.py", line 29, in setUp super().setUp() File "D:\Projects\Sophiadevtest\Test\SysTest\Sophia\tests\sophia_base.py", line 29, in setUp self.relay = DUTFactory.getDut('power_relay') File "C:\Anaconda3\envs\sophiasystest\lib\site-packages\devtest\dutfactory.py", line 66, in getDut DUTFactory._initDUT(dutId) File "C:\Anaconda3\envs\sophiasystest\lib\site-packages\devtest\dutfactory.py", line 179, in _initDUT dutInstance.open(device) File "D:\Projects\Sophiadevtest\Test\SysTest\Sophia\dut\powerrelaydut.py", line 47, in open super().open(device) File "C:\Anaconda3\envs\sophiasystest\lib\site-packages\devtestdut\ftdidut\ftdibitbangdut.py", line 32, in open self._dev = ftdi.BitBangDevice(self._id) File "C:\Anaconda3\envs\sophiasystest\lib\site-packages\pylibftdi\bitbang.py", line 60, in init self.open() File "C:\Anaconda3\envs\sophiasystest\lib\site-packages\pylibftdi\bitbang.py", line 66, in open super(BitBangDevice, self).open() File "C:\Anaconda3\envs\sophiasystest\lib\site-packages\pylibftdi\device.py", line 163, in open self.driver._libusb.libusb_set_auto_detach_kernel_driver(dev, 1) ValueError: Procedure called with not enough arguments (8 bytes missing) or wrong calling convention


Ran 1 test in 0.150s

I have goggled the problem, and I got an solution which I have tried.

https://stackoverflow.com/questions/30343107/python-32bit-on-windows-64bit-ctypes-module-error

In the file "pylibftdi.driver" I have made 2 changes:

In line 15: Inserted windll

line 15: from ctypes import (windll, cdll, byref, c_int, c_char_p, c_void_p, c_uint16, cast, create_string_buffer, Structure, pointer, POINTER)

In line 121: cdll changed to windll

line 121: lib = getattr(windll, lib_path)

I don't know if this is the right way to do it. It works for me for now.

I'm looking forward to hear from you.

Regards PerChr

Comments (5)

  1. Ben Bass repo owner
    • changed status to open

    Thanks PerChr; I'd sort-of assumed that mixed 32/64 bit OS and library/application might be a lost cause (and clearly isn't handled well), but that use of windll sounds promising - I'll aim to get this sorted by the weekend.

  2. Ben Bass repo owner

    I've started looking at this issue, but I can't reproduce the problem (if I switch from cdll to windll it gives me similar errors to the ones you're seeing).

    Since your error occurs when accessing a libusb (rather than libftdi) library function, how did you install libusb? There are several different versions of this around, for my testing I've always used Zadig (from http://zadig.akeo.ie/) to install libusbx (though note I don't have much access to Windows machines for testing).

    The output of python -m pylibftdi.examples.info would be useful, assuming that works OK.

    e.g.:

    C:\...>python -m pylibftdi.examples.info
    pylibftdi version     : 0.16.1.2
    libftdi version       : libftdi_version(major=1, minor=0, micro=0, version_str=b'1.0', snapshot_str=b'unknown')
    libftdi library name  : libftdi1
    libusb version        : libusb_version(major=1, minor=0, micro=14, nano=10576, rc=b'', describe=b'http://libusbx.org')
    libusb library name   : libusb-1.0.dll
    Python version        : 3.6.3
    OS platform           : Windows-10-10.0.16299-SP0
    

    In regards to the 'right way' of fixing this, I think passing auto_detach=False to the Device / BitBangDevice constructor might be a better approach, and since this has been causing a few issues, I'm tempted to disable it by default (i.e. change the default argument value).

    Ideally I'd be able to detect the calling convention of the libusb library and use the appropriate library loader (cdll / windll), but it seems there isn't a clean way of determining this just using ctypes, other than possibly trying some calls and seeing if they succeed...

  3. PerChr reporter
    - run zadig_2.3.exe
    - select Driver "FT232R USB UART" and => "libuskK(v3.0.7.0)" 
    - press "Reinstall driver"
    - In device manager COM port changes to "libusbK USB devices"
    
    - copy bin32\libusb-1.0.dll c:\Anaconda3\
    - copy bin32\libftdi1.dll c:\Anaconda3\
    - copy lib32\site-packages\* c:\Anaconda3\Lib\site-packages\
    

    or - copy bin64\libusb-1.0.dll c:\Anaconda3\ - copy bin64\libftdi1.dll c:\Anaconda3\ - copy lib64\site-packages\ftdi1.py c:\Anaconda3\Lib\site-packages\

    if you are using 64 bit python

  4. Christoph Klees

    Hi, I just started with python and have the same problem if I try to start any example.

    For example ,if I use the led_flash.py I got the following error : File "build\dist.win32\egg\pylibftdi\device.py" line180, in open ValueError: Procedure called with not enough arguments (8 bytes missing) or wrong calling convention

    I use the modul from FTDI called FT4232H-56Q

    The output, of "examples.info" is : pylibftdi version : 0.17.0 libftdi version : libftdi_version(major = 1, minor = 1 ,micro = 0, version_str = '1.1', snapshot_str= 'unknown' libftdi libary name : libftdi1 libusb version : libusb_version(major=1, minor=0, micro=18, nano=10866, rc='', describe = 'http://libusb.info' libusb library name : libusb-1.0.dll Python version : 2.7.14 OS platform : Windows-7-6.1.7601-8P1

    Maybe someone can help me, regards

  5. Log in to comment