Serialport write and read on windows not working


At first I tried using javax.comm to connect to the serial port (COM4). He did not even open the serial port.

Then I tried to use the rxtx libraries (rxtx-2.2pre2) to connect. It connects and writes data, but does not read data from the serial port.

Is there any JDK / platform dependency for using javax.comm or rxtx libraries?

I am using :
Windows XP SP3,
JDK 1.6.0_22,
rxtx-2.2pre2,
USB to serial adapter,
Portmon (from Microsoft) - for monitoring serial port activity
Hyperterminal - check if the COM port really works.
http://goo.gl/mNLNE - sample code used to verify read and write

Please let me know if you have the same problems as mine.

Any help is appreciated!

Thanks J

+7
source share
3 answers

After some digging, I was able to solve this myself, explicitly setting the flow control mode. Even if you do not need flow control, this clearly indicates FLOWCONTROL_NONE .

The same call is not required on Linux.

If you configure the flow control to โ€œHardwareโ€, I think it also requires setRTS explicitly to receive notifications in this mode. (Not verified).

+1
source

I tried this code and was successful. You need to have three files:

 comm.jar javax.comm.properties win32com.dll 

and you need to put these files in specific directories:

 comm.jar in /java/jre6/lib/ext , /java/jdk_1.6.0.20/jre6/lib/ext , java/jdk_1.6.0.20/lib win32com.dll in /java/jre6/bin, /java/jdk_1.6.0.20/bin, /windwos/System32 javax.comm.properties in /java/jdk_1.6.0.20/lib, java/jre/lib , /java/jdk_1.6.0.20/jre/lib 
+1
source

I would recommend trying purejavacomm: http://www.sparetimelabs.com/purejavacomm/index.html

This is the javax.comm implementation, written in pure java + JNA, which completely solved the portability problem between Windows and Linux for me. It should also work on OSX or FreeBSD (have not tried it) and should be easily ported to other OSs supported by JNA, such as Solaris.

Another advantage is that you do not need to install the DLL, as you do with rxtx, and that it does not seem to have a 100% CPU load error, which sometimes occurs with rxtx.

+1
source

All Articles