DukeUSB

jd2xx is a Java native interface port of Future Technology Devices International (FTDI) D2XX direct USB driver. FTDI chips are used in a variety of USB products such as serial converters and dongles.

FTDI provides D2XX drivers for Windows and Linux. Currently, jd2xx has been tested mainly in Windows; however there should be no major issues with Linux since the API is mostly the same. Stay tuned for updates about jd2xx in Linux.

jd2xx development is hosted at the jd2xx Java.net site. Check the files area for precompiled downloads and the CVS repository for the latest sources.

Looking for a Python D2XX interface module? Try PyUSB instead.

Usage examples

  1. Import the classes.
    import jd2xx.JD2XX;
    import jd2xx.JD2XXInputStream;
    import jd2xx.JD2XXOutputStream;
    
  2. Create a JD2XX object. It will attempt to load FTDI's ftd2xx DLL so it must be in your PATH.
    JD2XX jd = new JD2XX();
    
  3. List devices by serial number.
    Object[] devs = jd.listDevicesBySerialNumber();
    for (int i=0; i<devs.length; ++i)
      System.out.println(devs[i]);
    
  4. List devices by description.
    devs = jd.listDevicesByDescription();
    for (int i=0; i<devs.length; ++i)
      System.out.println(devs[i]);
    
  5. List devices by port location.
    devs = jd.listDevicesByLocation();
    for (int i=0; i<devs.length; ++i)
      System.out.println(
        Integer.toHexString((Integer)devs[i])
      );
    
  6. Open a device using its index.
    jd.open(0);
    
  7. Configure thy device.
    jd.setBaudRate(38400);
    jd.setDataCharacteristics(
      8, JD2XX.STOP_BITS_1, JD2XX.PARITY_NONE
    );
    jd.setFlowControl(
      JD2XX.FLOW_NONE, 0, 0
    );
    jd.setTimeouts(1000, 1000);
    
  8. Send a message.
    String msg = "Hello Duke.";
    msg += "The message is 'Fiat experimentum in corpore vili'";
    int ret = jd.write(msg.getBytes());
    System.out.println(ret + " bytes sent.");
    
  9. Receive data.
    byte[] rd = jd.read(10);
    System.out.println(new String(rd));
    
  10. Read device configuration EEPROM.
    ProgramData pd = jd.eeRead();
    System.out.println(pd.toString());
    
  11. Java dudes do it with streams.
    JD2XXInputStream ins = new JD2XXInputStream(jd);
    JD2XXOutputStream outs = new JD2XXOutputStream(jd);
    ...
    byte[] data = new byte[DATA_SIZE];
    int ret = ins.read(data);
    data = processData(data);
    outs.write(data);
    
  12. Finally, be polite.
    ins.close();
    outs.jd2xx.close();
    outs.close();
    

Copyright ©2005 Pablo Bleyer Kocik