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.