Java Open a TTY device file

Hey all;

I’m trying to do a simple slider-dimmer interface written in Java, and I don’t want to screw around with a separate library. My firmware reads in a single byte and sends it right to the PWM output.

In any case, on UNIXen (all I care about) I should just be able to open the serial port device file, and read/write to it with no trouble.

My problem is with opening the device file in Java. The code hangs on the FileOutputStream - but it doesn’t crash.

Here’s the relevant code:

System.out.println("Opening tty");
final FileOutputStream f=new FileOutputStream("/dev/tty.usbserial-A9007Ndt");
System.out.println("tty opened");

The second println is never reached, but there are no exceptions either.

Anyone know what gives?

Hi, if it where that easy, this page http://www.arduino.cc/playground/Interfacing/Java would never have been written. Or in other words, you can't do this without some native-code library.

Eberhard

Fair enough - still finding where to look around here.

Then I suppose my question isn't so much an Arduino question, more a Java question. Why can't I treat device files like regular files? That's their entire raison d'etre, as it were.

I guess my question is - what's the problem with Java? Trying some similar code in Python (f=open("/dev/tty.usbserial-XXX", "wb"); f.write(var)) and even shell redirection (echo hi > /dev/tty.usbserial-XXX) works fine.

Maybe I'll just use Python.

Maybe I’ll just use Python.

Good choice if you are not bound to using java.
I also don’t like the application interface of librxtx-java that much.

But you probably will end up using this
http://pyserial.sourceforge.net/
when it comes to resetting your arduino-board from your python code; configure a different port speed etc…
Recommended, will save you a lot of work.
Eberhard