-
I've got a USB based GPS device which I'd like to read from. I've been following the documentation here to get me started. I've proven my GPS device can be listened to by using Putty so I know its broadcasting on /dev/ttyUSB0 at 4800baud, 8 data bits, one stop bit. Of course I'm closing putty before running my Java app! My code so far looks like this:
So when I run the code, it waits for the serial port to open, but it never return true when I call serial.isOpen() The example in the documentation worked using a serial connection connected to the GPIO port, but I'm wondering if the API works for a USB based device? Maybe I'm just doing something silly. Any thoughts would be much appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
You need that .provider line. Without, the default '.build' operation has not created a usable device. With that line included your code gets into the SerialReader thread and fails for a bad handle, I do not have a /dev/ttyUSB0 in my tree. Hopefully this lets you debug further. |
Beta Was this translation helpful? Give feedback.
-
@taartspi thanks for your reply. I've had a dig into what the provider is and understand why its needed - basically in the background you are using the When I added the provider back into the code, the
I was looking around some other discussions on this forum and found that running my app with So as a gradle app I run it as: So although I've got it working, is there a way of reading the serial port without running my java app from sudo? I can run Putty via my own user and that works, so I'm wondering of there is some config I can do to make this work? Thanks again - this is much appreciated! |
Beta Was this translation helpful? Give feedback.
-
@taartspi thanks again for your replies, I thought you'd be interested in the project I've applied this to which is in this Blog Having used the pi4j API which is an great project backed up by good documentation, I feel that I could make some improvements and additions myself so I might pop in a ticket with my ideas. |
Beta Was this translation helpful? Give feedback.
-
Wow @mbcoder that's a really nice post where you combine two of my "darlings": Pi4J and JavaFX ;-) Will also include it in the next JFX-Central LinksOfTheWeek! Looking forward to your feedback for the Pi4J! |
Beta Was this translation helpful? Give feedback.
You need that .provider line. Without, the default '.build' operation has not created a usable device. With that line included your code gets into the SerialReader thread and fails for a bad handle, I do not have a /dev/ttyUSB0 in my tree. Hopefully this lets you debug further.