Writing "Hello World" to a USB to serial converter

From Rxtx

(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
This example shows how write a Java program to write out "Hello World" to a USB to serial converter connected to a Windows XP computer.
This example shows how write a Java program to write out "Hello World" to a USB to serial converter connected to a Windows XP computer.
-
Firstly the USB to serial converter in installed using the manufacturer's instructions. Select My Computer->Properties->Hardware->Device Manager->Ports(COM&LPT)->USB - Serial Comm Port (COM4).  This shows that the device was installed as a COM4 port.
+
Firstly the USB to serial converter in installed using the manufacturer's instructions. Select My Computer->Properties->Hardware->Device Manager->Ports(COM&LPT)->USB - Serial Comm Port (COM4).  This shows a COM port to which the device was installed - in this case COM4.
Then install Sun's Java software (JDK6 Update 3).  The JDK files are placed at C:\Program Files\Java\jdk1.6.0_03\ and the runtime files are placed at C:\Program Files\Java\jre1.6.0_03\. Ensure the System Variable "path" (held in My Computer->properties->Advanced->Environment Varables->System Variables) includes ";C:\Program Files\Java\jdk1.6.0_03\bin" at the end.
Then install Sun's Java software (JDK6 Update 3).  The JDK files are placed at C:\Program Files\Java\jdk1.6.0_03\ and the runtime files are placed at C:\Program Files\Java\jre1.6.0_03\. Ensure the System Variable "path" (held in My Computer->properties->Advanced->Environment Varables->System Variables) includes ";C:\Program Files\Java\jdk1.6.0_03\bin" at the end.
Line 9: Line 9:
Copy the SimpleWrite java program from here: [http://java.sun.com/developer/releases/javacomm/SimpleWrite.java]. Edit the file as follows:
Copy the SimpleWrite java program from here: [http://java.sun.com/developer/releases/javacomm/SimpleWrite.java]. Edit the file as follows:
-
Change the third import statement "import javax.comm.*;" to read "import gnu.io.*;".
+
*Change the third import statement "import javax.comm.*;" to read "import gnu.io.*;"
-
 
+
*Change the line "String  defaultPort = "/dev/term/a";" to read "String  defaultPort = "COM4";" (or to whichever port the USB to serial converter is installed)
-
Note also that the defaultPort has been set to be COM4.
+
-
Change the line "String  defaultPort = "/dev/term/a";" to read "String  defaultPort = "COM4".
+
This Java program can be compiled and run by typing the following at the Command Prompt:
This Java program can be compiled and run by typing the following at the Command Prompt:

Revision as of 20:15, 29 October 2007

This example shows how write a Java program to write out "Hello World" to a USB to serial converter connected to a Windows XP computer.

Firstly the USB to serial converter in installed using the manufacturer's instructions. Select My Computer->Properties->Hardware->Device Manager->Ports(COM&LPT)->USB - Serial Comm Port (COM4). This shows a COM port to which the device was installed - in this case COM4.

Then install Sun's Java software (JDK6 Update 3). The JDK files are placed at C:\Program Files\Java\jdk1.6.0_03\ and the runtime files are placed at C:\Program Files\Java\jre1.6.0_03\. Ensure the System Variable "path" (held in My Computer->properties->Advanced->Environment Varables->System Variables) includes ";C:\Program Files\Java\jdk1.6.0_03\bin" at the end.

Install RxTx. This involves placing rxtxSerial.dll and rxtxParallell.dll in both C:\Program Files\Java\jdk1.6.0_03\jre\bin and C:\Program Files\Java\jre1.6.0_03\bin. It also involves placing RXTXcomm.jar in both C:\Program Files\Java\jdk1.6.0_03\jre\lib\ext and C:\Program Files\Java\jre1.6.0_03\lib\ext.

Copy the SimpleWrite java program from here: [1]. Edit the file as follows:

  • Change the third import statement "import javax.comm.*;" to read "import gnu.io.*;"
  • Change the line "String defaultPort = "/dev/term/a";" to read "String defaultPort = "COM4";" (or to whichever port the USB to serial converter is installed)

This Java program can be compiled and run by typing the following at the Command Prompt:

javac SimpleWrite.java
java SimpleWrite

"Hello World" should then appear on the device connected to the serial port, assuming that it has been set up to receive a 9600 baud rate, 8 data bits, 1 stop bit, no parity and no handshaking.

Personal tools