• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Communicating over a virtual COM port

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have the following setup:

PC <-----> USB-to-RS232 adaptor <-----> RS232 port on custom hardware

I found this Java code for communicating over COM ports (uses javax.comm): http://www.java-samples.com/showtutorial.php?tutorialid=11

Since I'm using a usb-serial port adaptor, I will have to install a virtual COM port.

Does this code support virtual COM ports?

Thanks.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried it?
 
Mikpo Siru
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I haven't tried it.

I'm choosing between this and a physical port. If the virtual port has it's own Java intricacies, then I'm going to stick with a physical port.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then try it. Using COM ports is a very uncommon thing to do in Java (and in any language given that COM ports are rapidly disappearing from the hardware), so you aren't likely to find experts here or anywhere else. Once you get the answer you're going to be one of the world experts on the topic.
 
Mikpo Siru
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I may be giving it a go soon.

If you want to communicate with hardware devices in Java, what do you typically use?

I would have thought USB, but I don't think Java has alot of support for it.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Me? I haven't done that since 2001. The device we were using then became obsolete and was replaced by a device which spoke TCP/IP. Which Java handles easily.
 
Mikpo Siru
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I managed to do this using a physical COM port.

Initially I was looking into using the javax.comm package, but I found that support for this is limited. Instead I used gnu.io, which is an opensource package provided by rxtx (wiki is at http://rxtx.qbang.org/wiki/index.php/Main_Page, whilst their original main page is at http://users.frii.com/jarvi/rxtx/index.html). If you use rxtx v2.1 or above, you don't need to download or use javax.comm at all.

1. Download rxtx v2.1 or greater from: http://rxtx.qbang.org/wiki/index.php/Main_Page

2. Extract the file. Put "RXTXcomm.jar" into C:\Program Files\Java\jdkXXXX\jre\lib\ext (in my case "jdkXXXX" was "jdk1.7.0").

3. Put "rxtxSerial.dll" and "rxtxParallel.dll" into C:\Program Files\Java\jdkXXXX\jre\bin

4. Make a new project in NetBeans. Right click the project to add a library, and add the RXTXcomm.jar file at C:\Program Files\Java\jdkXXXX\jre\lib\ext

5. Serial comms should now work.

To see what serial ports your PC has, you can use the code below. But you must make one change to this code - replace "import javax.comm.*;" with "import gnu.io.*;".


Code courtesy of http://pradnyanaik.wordpress.com/2009/04/07/communicating-with-ports-using-javaxcomm-package-for-windows/


If you want to read data from the serial port, you can use the code below. But you must make one change to this code - replace "import javax.comm.*;" with "import gnu.io.*;".


Code courtesy of http://www.java-samples.com/showtutorial.php?tutorialid=11

Both pieces of code worked without a hitch on Windows XP 32bit in NetBeans IDE.
 
Mikpo Siru
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just thought that I'd update everyone on how I got along with using a virtual COM port.

As per my post above, I have been able to easily communicate over a physical COM port using the RXTXcomm java library.

This is fine as long as I am on a 32bit XP machine as it boasts a physical COM port.

I recently moved over to a 64bit Windows 7 machine with, of course, no physical COM port in sight. However, I am able to use the aforementioned library without any modification at all to talk over a virtual COM port.

To do this I used a serial-USB bridge made by Prolific, and the driver installer is available on their website (google 'profilic serial to usb') ("PL2303_Prolific_DriverInstaller_v1.5.0.zip" at http://www.prolific.com.tw/eng/downloads.asp?id=31).

Once the installer completes, any software you wrote for use with physical ports, will work without modification on this virtual port (e.g. when I did a search of available ports using the code in the post above, it showed up as COM3).

If you're on a 64bit machine, you must point your compiler (I'm using NetBeans) to a 32bit JDK, in my case it was Program Files (x86)/Java/jdk.
 
reply
    Bookmark Topic Watch Topic
  • New Topic