0

I have the issue while using the SainSmart 4 Relay USB with my Mac (10.8.5). I am trying to access over Java while using the d2xx/fdti driver.

This is my Java Code:

public class Demo {

  public static void main(String[] args) throws InterruptedException {
     try {
        List<FTDevice> fTDevices;
        fTDevices = FTDevice.getDevices();
        for (FTDevice fTDevice : fTDevices) {

           System.out.println("fTDevice:" + fTDevice);
           System.out.println("fTDevice.DevType:" + fTDevice.getDevType());
           System.out.println("fTDevice.DevID:" + fTDevice.getDevID());
           System.out.println("fTDevice.DevLocationID:" + fTDevice.getDevLocationID());

           fTDevice.open();
           fTDevice.setBaudRate(9600);
           [...]
           fTDevice.close();
        }

     } catch (FTD2XXException ex) {
        Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
     }
  }
}

And I just get this exception:

com.ftdi.FTD2XXException: D2XX error, ftStatus:INVALID_HANDLE
at com.ftdi.FTDevice.ensureFTStatus(FTDevice.java:139)
at com.ftdi.FTDevice.setBaudRate(FTDevice.java:324)
at de.relay.Demo.main(Demo.java:27)

What does "INVALID_HANDLE" mean?

I also tried to connect over the serial port, which works.

# kextload -b com.FTDI.driver.FTDIUSBSerialDriver 
# cu -l /dev/tty.usbserial-XXXXXXX --baud 9600
Connected.

Which "echo" would switch a relay? And how can i fix the exception? I really appreciate any help!

Cheers, Felix

debergalis
  • 11,870
  • 2
  • 49
  • 43
Felix
  • 1,097
  • 1
  • 10
  • 16

1 Answers1

1

I've encountered the same problem on Fedora 19.

The problem turned out to be an issue with JavaFTD2XX running on a 64-bit JVM. The handle appears to be a integer where it needs to be a long for 64-bit.

Switching to a 32-bit JRE got it working.

For a Mac, you might just be able to add the -d32 parameter to the JVM.

Matt C
  • 1,431
  • 2
  • 14
  • 18
Stav
  • 1,676
  • 1
  • 12
  • 16