How to read a usb serial port in JAVA? - java

I add some detail to my question.
I receive on my Xbee device a flow of GPS coordinates but I'm unable to read and stock these data on a buffer.
My Xbee device is connected to my laptop on a usb serial port, that's why I want to create a program java to read and use my data flow sending by the serial port.
I'm searching on internet some code example or tutorials , without enought advices for my understanding, or I just find some dead projects.
I found that it's possible to use jssc library or javax.comm (but I can't download the javax.zip on sun). Do you know an other better USB API ? Could you help me to understand how I can manage to read and stock my Flow of GPS cordinate ?

Forget abut USB, it acts as transparent bridge. What you need is a way to read from the serial port. javax.comm is not (officially) available any more. I have been successfull dealing with the arduino serial port with the RXTX library.
First make sure you see the serial port on your dev machine. This might require to install a driver. Then use a terminal program to connect to the serial port.
Once this is working go on and get RXTX working.
Just in case: You can have only one connection at a time. Make sure that only one of IDE, terminal programm and RXTX is connecting to the serial port at the same time.

Related

Java Bluetooth Com Windows NRJavaSerial/RXTX

I am using Java with RXTX library and I have a problem. I want to read data from a Serial Port that is the bluetooth. If I use a normal COM port (usb arduino for example)and JAVA with RXTX, it works. If I use PUTTY, i can read the data from the bluetooth port.
If I use Java + RXTX and the bluetooth port, it doesn't work. If I use putty, and after that I want to display all ports, it works but only for one time, after that I cannot find the port anymore, like it break it. (not even in putty it doesn't work).
If I do not start PUTTY beforehand, It cannot even see the port. After the port is "broken" I have to turn off/on multiple times my bluetooth device. What seem to be the problem?
I did try the things listed here and it did not work : \
http://neophob.com/2011/05/serial-library-rxtx-v2-2pre5/
https://github.com/processing/processing/issues/1374.html
Any other thoughts?
Something is strange. Do you know what do I need to do so that the right rxtxSerial.dll is used? I have deleted every instance of rxtxSerial.dll from my PC and it still works???

RXTX issue with Bluetooth COM Port

I have an application made of a device I made to connect through USB emulating a Serial port. Now, I need to connect the same device via bluetooth so I'm using a RN-42 (Bluetooth to serial port) in my device to send the data over RF.
Then I pair my device in Windows with the laptop's internal BT module which creates to COM ports a Outgoing and a Incoming one. Then if I connect using Br#ay's terminal I receive the expected data when I connect to the Outgoing COM port.
The problem is that when I use my Java app where I am using the last RXTX libraries, I can discover the COM port (which is the problem that everyone has, at least thats all what i found in forums) and it seems to connect but then I don't receive no data. Using the same exact program but connecting using a cable it works just fine as the terminal does.
I also tried to use the BlueCove libraries, I can find the bluetooth devices but I don't really know how to discover it services and then connect to it using RFComm. I can't find a complete example of how to do that.
Any help will be appreciated!
I'm getting similar problem with default Windows Bluetooth stack.
With Toshiba stack communication is ok.

Is it possible to write to a serial port without device connected to it?

I have installed java rxtx library to communicate to the serial port. I have connected EFTPOS terminal to the serial port now. I want to check if my writing is happening onto the port. Even if i use the test program given by the rxtx i couldn get it right. Is it possible to write to the serial port without connecting any devices to the port ? And how can i watch the packets written on the serial port ? Please help me to solve this isssue!!
It depends on your software as to whether it will transmit without anything being connected to the serial port.
Some software will check if a signal line (DTR? I can't remember which one) is being driven high, other software will transmit in a dumb fashion and it will not matter if anything is connected, but there may be a protocol that does error checking to ensure that what is being received is the same as that sent. Basic transmission integrity checking can also be carried out by the receiver echoing back the transmitted character.
It is possible to buy intelligent breakout boxes for serial ports, they will display whatever is sent out. The alternative is to use a null modem cable and connect up a PC running a terminal program. Both methods will display characters, any 'packets' sent out are likely to be a proprietory protocol as mentioned above.

Java and USB-to-COM

I want to develop a Java application to communicate with the device based on Xilinx Spartan 3E Starter Kit.
The board is connected to my PC with USB-to-COM cable (COM is on the board).
What I need is to send some sequences of bytes to the device and than receive the response from it. It is the same way the serial terminals (hyperterminal, minicom, etc) do.
I'm kinda new to Java, so what classes do i need to implement this?
I'm not exactly sure what you mean by "USB-to-COM". Do you mean that the USB connection is accessible as an RS232 serial port on the PC (aka COM port on windows) ?
If so, you should look at the RXTX library here: http://rxtx.qbang.org . It provides support for Java serial port communications on a number of platforms. If you are new to Java, you might not find serial port programming the easiest way to learn Java, but the examples included with RXTX should be clear otherwise.

How to Communicating between a J2ME Midlet and PC?

How do I make a J2ME Midlet to communicate with a java program or some application on the pc through the cable connected?
Incredible_Honk is almost right. The key is to use the (standard) system property "microedition.commports". This provides a comma delimited list of the com ports which are available to your application. To open a connection use CommConnection as follows:
CommConnection con = (CommConnection) Connector.open("com:<commport name>");
Usually this will provide access to a USB serial connection, possibly also infrared if available. Iterate through each one to see which one corresponds to the connection you're looking for.
On Windows at least, you will need to install the correct drivers for your handset first. This will then allow you to open a serial connection and communicate with the application.
There is no general way of doing this. It hardly depends on the capabilities of the mobil. Might be that there is some vendor API giving you special access to USB, but I'm not aware of any.
Some phones support communication via serial port connections.
Take a look at the javax.microedition.io.CommConnection interface for more information.
Sonyericsson phones offer a way to debug your midlet on the device and get the console messages back through the cable.

Categories

Resources