Home Engidea Home Circle

New Agust 20145: Support Linux 32 & 64 bit plus Win 64 bity

Download the latest version of Winjcom dated august 2015

Added support for Linux, seems to work fine on my test. The issue here is that Linux has support for timeout on RX but the support for TX timeout should use select

NOTE: Have a look at the tester program PortTester.java on how to differentiate the various drivers. You can find the deploy under java/deploy

NOTE: You need to put the linux library under the appropriate path eg: /usr/lib/...

New updated licence and Vista win 7 compatibility

Download the latest version of Winjcom dated 19 november 2011

The winjcom is now updated with a new licence, apache 2 and it is also compatible with Win Vista -> win 7, let me tell you what is different win Vista

The problem lies with the CancelIo function that behaves differently in Vista than in XP, it is really incredible since Microsoft actually makes a new function that behaves likes the old one, CancelIoEx I really cannot understand the reasonning for such bad choice.

To support both platforms winjcomport needs to load different dll, it tries to do its best to find out wich one but if you have particular issues you can "force" the choice, look at the code, it is really simple !

Windows Java Serial Com Port Driver

with proper handling of Timeouts

I had to interface a machine using Java and the serial port. It is not the first time that I need this and as usual I headed to Sun Java homepage to download the COM driver for Windows (XP)

Not anymore... Windows COM ports are not directly supported by Sun. It is not so bad since there is another package called rxtx that is mostly suited. I did try it, amazing stuff, but it does not handle (at the time I checked and as far as I understand) serial port timeouts on TX and timeout on RX is done in some sort of polling mode.

For all of you wondering, proper timeout handling is essential if you want to avoid getting stuck when your machine (connected to the serial port) is not talking to you anymore and you want to recover nicely from this (without shutting down ports or applications)

Well, Java is open, and you can add pieces if you want, so I have written a Serial Driver for Windows XP that makes full use of all Windows features, and especially of the OVERLAPPED mode in COM handling. Using overlapped mode makes the whole driver quite simple and hopefully bug free :-)

Thanks to Aleksandar Kanchev for pointing out that the event value does NOT come from a getOverlapped BUT from the previously called and possibly no more in scope GetEvent parameter. The new api does not have the bug and events should be returned correctly. At first I could not believe it, basically what Microsoft has done is a nice way to corrupt stack if one is not extra careful, but what could you expect from them ?

Simpler API more functions

If you want simpler API and more functions keep reading here, otherwise go on the "old API" section.

The new API provides the following:

There is a patched version

It solves a memory leak when opening the port and it explains the port enumeration better. You may not know but the name of a com port under windows is not as easy as it seems, the first nine ports are named COM1 ... COM9 from then onward the name changes into \\.\com10 \\.\com11 and so on. To keep things simple the autodiscovery code stops at the port number 9, if you know that your system has more ports just use the correct name. (this did work even with the previous version)

The new version is released the 13jan2009 and you can download it from here (as usual source, jar, dll, javadoc). Everything is the same as the so called "new api", this is just bug fix.

I leave the previous version online, just in case, if you want to try it out just download new API, source, jar, dll, javadoc, (a single 7z file) unpack it, find the dll that is in the win32/jcomport directory and put it into the C:\WINDOWS, then you can just try it out by typing

java -jar jcomport.jar

To understand how to use it look at PortTester and use as a skeleton. If you are familiar with the old javx.comm API you will find many similarities, less code and more possibilities. Let me know what you think. Of course I wish to know about bugs and enhancements and if there is someone wishing for it I can write the Linux/UNIX version.

Download the package (OLD API)

Everything (click here to download) is in a single 7z file, the source, a ready made jar and a ready made dll and documentation on JNI and javacom

How do you use it ?

There are two pieces, really, the jar and the dll

You can test it typing

java -jar jcomport.jar

The test should list the ports in your system and allow you to read/write. The initial parameters are 9600, 8bit, no parity

How do you change it ?

I suggest you give a look at the java code, it is simple and there are no tricks around. You will see that some parts like the management of ownership is not done, simply because I did not need it :-) You are free to add it if you feel like.

Bear in mind that declaring a port "free" in Java does not guarantee at all that some Windows processes did not grab it first..

I have also found out that the reliability of "signals" generated by various USB adapters/modems is not optimal. What surely works is reading/writing with timeout. All the rest.... well... it is Windows :-)
Note that since I am using what Windows suggest to talk to COM ports, if some signals are not generated, well, it is not Java fault !

To compile the library you just need minGW, great stuff, I must say. Just download minGW (you do not really need MSYS, and download the 'C' development part (not c++). Set the PATH so you can have gcc anywhere you wish and then head for win32/jcomport In there you will find make-dll.bat that compiles the only source file that there is and even put it into the C:\WINDOWS directory

If you change the Java code, especially the native interface, you need to recreate the header file. Go into the java part of the winjcom and you will find a file called make-jni-header.bat. Note that most likely you have to change it to suit your needs (basically where java is and where winjcom is).

To compile the Java code you can use any decent IDE, for historical reasons I am used to Jdeveloper but there is nothing wrong with Eclipse and really, if you are also changing the 'c' source code that is probably the best option.

I hope you find it useful !

If you find some parts of the code that you do not like, feel free to change them as you please, you do not need to tell me or send changes back. Just one thing, if you find it useful, post a Blog entry on winjcom. I quite often have my own hard time to find stuff on Internet and it is really not fun to spend a couple of days working on something if there is the same solution already prepared somewhere around !

If you want to contact me, just write your message below and press the side button.
Leave an Email address if you want to be called back

Last Updated August 2015 Damiano Bolla