Menu

#13 I2c support for FT4222

2.1
open
None
2020-08-19
2020-05-11
Peter
No

Hello, i was currenlty trying to use your library with the FT4222 for I2C commands. The first step of opening the communication ports interfaces did work, but after i tryed to send some read/write commands I got an error that my device doesnt support MPSSE. I checked it and yes it doesnt support it. So my question is is there a way to use your library without using the MPSSE?
- I am running this on windows 10
- using Intellij IDEA for IDE
- java 8
thanks a lot in advance.

Discussion

1 2 3 > >> (Page 1 of 3)
  • Stephen Davies

    Stephen Davies - 2020-05-11

    Hi Peter,
    thanks for your interest.

    I haven't encountered the FT4222 before. Whilst the datasheet explicitly mentions the D2XX driver it gives no indication of the commands that need to be issued. It looks like they put another library, LibFT4222, over the top of the D2XX driver.

    I had a quick look through the Windows version of the LibFT4222 code samples. None of them use D2XX api calls directly, they use the LibFT4222 api. Did a search but failed to find any source code for LibFT4222. I guess FTDI are keeping the chip details confidential.

    Hate to say it but I don't think yad2xx is right for you. I did see an Android .jar file mentioned, you could try that. There was also this: https://github.com/eclipse/mraa, it may be of use.

    The only other thing I could suggest is to write your own Java binding for LibFT4222. Start by looking at the code in src/main/native/FTDIInterface.c.

    Cheers,
    Stephen

     
  • Stephen Davies

    Stephen Davies - 2020-05-11

    BTW,
    the project has moved over to https://github.com/aushacker/yad2xx.

     
  • Peter

    Peter - 2020-05-12

    thank you for the information. yes this FT4222 uses the libFT4222 api. In the downlodable LibFT4222 file there is an header(.h) file, and also and lib and dll file. So I will try to make an java native interface for libFT4222 just like you did. And after im finished i can upload it to your existing project if somewho somewhere is going to need it :D Maybe if you could give me some tips it would be reallly helpful, because im not an java expert.

    • So if im right i can just use your FTDIInterface.c as a reference for making the FT4222 JNI right?
    • I still dont really understand why you have to paste the FTDIInterface.dll file into system32, will i have to generate an similar file and paste it there or what? In the existing libFT4222 there is an DLL file, but when i was using eclipse IDE (C) i just imported it into my project.
     

    Last edit: Peter 2020-05-12
  • Stephen Davies

    Stephen Davies - 2020-05-13

    Have you read through https://github.com/aushacker/yad2xx/wiki/Building-on-Windows yet?

    I suggest you follow the steps and see how it goes. I haven't tried building on Win 10 but the instructions should be pretty close. Would appreciate any feedback, please create an issue on github for documentation errors.

    Your contribution to the project is most welcome. I've created branch 'lib4222' in the repo for this development.

    To get the source tree:
    1. Install the git client
    2. Change to your working directory/workspace (whatever)
    3. git clone https://github.com/aushacker/yad2xx.git
    4. git checkout -b lib4222 origin/lib4222
    5. copy src/main/native/FTDIInterface.c src/main/native/LibFT4222.c

    Searching for "java native interface pdf" can be helpful.

    I'd then look at the Lib4222 I2C example code to work out which functions you're going to need to implement/wrap.

     
  • Stephen Davies

    Stephen Davies - 2020-05-14

    Peter,
    I've made a first pass at getting it working, code has been checked in to the lib4222 branch. Have only tested it on macOS so there may be a few hiccups on the windows build.

    FTDI's i2c_master.cpp program has been implemented as I2cMasterSample. It won't yet work as:
    1. native method FTDIInterface.getDevices needs to be changed to return FT4222Device instances
    2. I don't have a device to test it with
    3. i2cMasterRead and i2cMasterWrite are currently stubbed

     
  • Stephen Davies

    Stephen Davies - 2020-05-14
    • Milestone: 1.0 --> 2.1
     
  • Peter

    Peter - 2020-05-14

    Hey,
    Yes i did read through building on windows. yesterday I made my first JNI(HelloWorld) so I have some sort of understanding how calling c from java works (after spending hours on googling and reading). Yes i have determined the functions i will need.

    I tryed the 2cMasterSample, with the device and it just returns: No FT4222 device is found!
    But when i tryed calling ListDevices directly from samples it did return the information about the device.
    So i will try to change the getDevices so it will return the FT4222Device instances.

    Thanks a lot for this!

     
  • Stephen Davies

    Stephen Davies - 2020-05-14

    Excellent progress. What I had in mind for getDevices is for it to return a hetergeneous array of Device and FT4222Device instances. Right now it only returns an array of Devices, so when I2cMasterSample line #91 performs instanceof the test fails.

    To make getDevices work correctly you will need to add code to (refs to FTDIInterface.c):
    1. Also lookup class FT4222Device (lines 354-358)
    2. Lookup the constructor for FT4222Device (lines 374-378)
    3. Test the device info and conditionally construct either a Device or FT4222Device (lines 418-423) using the values from steps 1 & 2

    Methods open(), close(), i2cMasterInit(), unInitialize() should work.

     
  • Peter

    Peter - 2020-05-14

    i did look at the sections you mentioned. I hink that I dont have the knowledge to do it...But if you wont be able to do it then i will try tomorrow somehow. Also i have some quiestions.
    1. Where is the libft4222.h? It is included in FT4222Interface.c but i didnt find it in any folder :d
    2. Also dont we have to have somewhere the LibFT4222.dll?

     
  • Stephen Davies

    Stephen Davies - 2020-05-14

    It's late evening here, will implement it timorrow. You need to download the FT4222 support files from the FTDI website.

    I've updated the github wiki, added page FT4222 Function Index. You could try implementing one of the general functions, say one of the set functions that takes a boolean arg and returns nothing besides the status code.

     
  • Stephen Davies

    Stephen Davies - 2020-05-14

    Hi Peter, have changed getDevices(). Let me know how it turns out please. I have no FT4222 device, therefore no way to easily test.

     
  • Peter

    Peter - 2020-05-14

    Hi, i did try it. The same result as before. No FT4222 detected. I also debugger the last part so you can se what the devices returns. I am onlinne, currenlty i have some lectures, but I can debugg it for you if you need anything.

     
  • Stephen Davies

    Stephen Davies - 2020-05-15

    I assume that you have been able to build from source. Sounds like it is still using the old dll.

    Please run net.sf.yad2xx.samples.ListDevices and attach the output. This program dumps all device information. It shows all of the device fields, the type is what's important. It should indicate multiple devices of the FT4222 type.

    Then run DumpSystemProperties, samples package as well. Run it inside your IDE, not from the command line, so we can see what the IDE settings may be doing. What is java.library.path set to? The JVM searches these directories looking for the dll when System.loadLibrary("FTDIInterface") is called. The newly built dll needs to be in one of these directories. I must be because we aren't seeing any linkage exception. There may be an old copy in a directory earlier than the directory with the new version.

     
  • Peter

    Peter - 2020-05-15

    Here is the output of listdevices:
    java.library.path:
    java.library.path=C:\Program Files\Java\jdk1.8.0_241\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.8.0_241\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\PuTTY\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;D:\Programi\New Folder (2)\runtime\win64;D:\Programi\New Folder (2)\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Git\cmd;C:\Program Files\apache-maven-3.6.3\bin;C:\Program Files\Java\jre1.8.0_241\bin;C:\Program Files\SourceGear\Common\DiffMerge\;C:\minigw\mingw64\bin;C:\Users\Peter\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\Nmap;C:\Users\Peter\AppData\Local\Programs\Microsoft VS Code\bin;C:\minigw\mingw64\bin;;.

     
  • Peter

    Peter - 2020-05-15

    in think the problem is when i tryied follow the instructions for building on windows, on the n Native library section, i got an error :
    https://ibb.co/DzqDPRt
    And i didnt know how to solve it, so i just downloaded your FTDIInterface.dll library and pasted it in c/windows/system32

     
  • Stephen Davies

    Stephen Davies - 2020-05-15

    Ok, copying the old .dll will always fail. We are adding new native functions that do not exist in the old library. We need to get your build working.

    Please post an image of the error messages that occur further up the screen. They should be coming out of either the C compiler or the linker.

    You will also need to perform a "git pull" as I have made additional changes to the source code.

     
  • Stephen Davies

    Stephen Davies - 2020-05-15

    Forgot to mention, ListDevices looks good. The type is set to 0xA (10) and is being recognised as an FT4222 device. The new getDevices() method is likely to work.

     
  • Peter

    Peter - 2020-05-15

    https://ibb.co/DtnXmRn
    https://ibb.co/r0Nyg4Z
    git pull? i need to search what this is :D (sorry im new to the git community)

     
  • Stephen Davies

    Stephen Davies - 2020-05-15

    Ok, it's not finding the header file. What files have you put in C:\Users\Peter\d2xx?

    You'll need to have ftd2xx.h, libft4222.h, ftd2xx.lib (64 bit) and LibFt4222.lib (64 bit).

     
  • Stephen Davies

    Stephen Davies - 2020-05-15

    The FTDI library install instructions are rubbish on Windows. This seems to make more sense: https://github.com/dotnet/iot/blob/master/src/devices/Ft4222/README.md

    From LibFt4222.zip:
    1. copy imports\ftd2xx\ftd2xx.h c:\Users\Peter\d2xx\ftd2xx.h
    2. copy imports\ftd2xx\amd64\ftd2xx.lib c:\Users\Peter\d2xx\ftd2xx.lib
    3. copy imports\LibFT4222\inc\LibFT4222.h c:\Users\Peter\d2xx\LibFT4222.h
    4. copy imports\LibFT4222\inc\amd64\LibFT4222-64.dll c:\Users\Peter\d2xx\LibFT4222.dll
    5. copy imports\LibFT4222\inc\amd64\LibFT4222.lib c:\Users\Peter\d2xx\LibFT4222.lib

    NB. Rename in step 4.

     
  • Peter

    Peter - 2020-05-15

    okay i did it like you said it was successful. Then i copied the generated FTDIInterface.dll from yad2xx-lib4222/yad2xxDLL/target to C/windows/system32.
    Then i runned the i2cMasterSample and got this output:

     
  • Stephen Davies

    Stephen Davies - 2020-05-15

    All good, making progress. That looks like the FTDIInterface.dll is loading but then failing because it can't find LibFT4222.dll. https://github.com/dotnet/iot/blob/master/src/devices/Ft4222/README.md hints at what needs to be done.

    You can either:
    1. Open a Windows Command Prompt (Run as Administrator)
    2. regsvr32 c:\Users\Peter\d2xx\LibFT4222.dll
    or copy it to a directory on your PATH.

     
  • Stephen Davies

    Stephen Davies - 2020-05-15

    Which chip are you planning to attach to the I2C bus?

     
  • Peter

    Peter - 2020-05-15

    I tryied but got this error:

     
1 2 3 > >> (Page 1 of 3)

Log in to post a comment.