<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://rxtx.qbang.org/wiki/skins/common/feed.css?207"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Rxtx - User contributions [en]</title>
		<link>http://rxtx.qbang.org/wiki/index.php/Special:Contributions/Nigelbee</link>
		<description>From Rxtx</description>
		<language>en</language>
		<generator>MediaWiki 1.15.4</generator>
		<lastBuildDate>Tue, 09 Jun 2026 11:03:24 GMT</lastBuildDate>
		<item>
			<title>Writing &quot;Hello World&quot; to a USB to serial converter</title>
			<link>http://rxtx.qbang.org/wiki/index.php/Writing_%22Hello_World%22_to_a_USB_to_serial_converter</link>
			<description>&lt;p&gt;Nigelbee:&amp;#32;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This example shows how write a Java program to write out &amp;quot;Hello World&amp;quot; to a serial port or to a USB to serial converter.&lt;br /&gt;
&lt;br /&gt;
== Windows XP Computer ==&lt;br /&gt;
&lt;br /&gt;
If the machine doesn't have a serial port, install a USB to serial converter following the manufacturer's instructions. Select My Computer-&amp;gt;Properties-&amp;gt;Hardware-&amp;gt;Device Manager-&amp;gt;Ports(COM&amp;amp;LPT)-&amp;gt;USB - Serial Comm Port (COM4).  This shows a COM port to which the device was installed - in this case COM4.&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;path&amp;quot; (held in My Computer-&amp;gt;properties-&amp;gt;Advanced-&amp;gt;Environment Varables-&amp;gt;System Variables) includes &amp;quot;;C:\Program Files\Java\jdk1.6.0_03\bin&amp;quot; at the end.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Copy the SimpleWrite java program from here: [http://java.sun.com/developer/releases/javacomm/SimpleWrite.java]. Edit the file as follows:&lt;br /&gt;
&lt;br /&gt;
*Change the third import statement &amp;quot;import javax.comm.*;&amp;quot; to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; import gnu.io.*; &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Change the line &amp;quot;String  defaultPort = &amp;quot;/dev/term/a&amp;quot;;&amp;quot; to read:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; String  defaultPort = &amp;quot;COM4&amp;quot;; &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(or to whichever port the USB to serial converter is installed)&lt;br /&gt;
&lt;br /&gt;
This Java program can be compiled and run by typing the following at the Command Prompt:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
javac SimpleWrite.java&lt;br /&gt;
java SimpleWrite&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Hello World&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
== UBUNTU computer ==&lt;br /&gt;
&lt;br /&gt;
On Unix machines the serial port ID can be found by typing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo dmesg | grep tty&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is likely to show the port to be &amp;quot;/dev/ttyS0&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Sun Java RTE is installed at /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre and RXTXcomm.jar must be placed at /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/ext and the librxtxSerial.so and librxtxParallel.so files are placed at /usr/lib/jvm/java-1.5.0-sun-1.5.0.06/jre/lib/i386.&lt;br /&gt;
&lt;br /&gt;
The defaultPort line in the SimpleWrite Java file (see above) must now be changed to:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
String  defaultPort = &amp;quot;/dev/ttyS0&amp;quot;;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This Java program can be compiled and run by typing the following in the Terminal window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
javac SimpleWrite.java&lt;br /&gt;
java SimpleWrite&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Hello World&amp;quot; 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.&lt;/div&gt;</description>
			<pubDate>Mon, 29 Oct 2007 20:54:12 GMT</pubDate>			<dc:creator>Nigelbee</dc:creator>			<comments>http://rxtx.qbang.org/wiki/index.php/Talk:Writing_%22Hello_World%22_to_a_USB_to_serial_converter</comments>		</item>
		<item>
			<title>Writing &quot;Hello World&quot; to a USB to serial converter</title>
			<link>http://rxtx.qbang.org/wiki/index.php/Writing_%22Hello_World%22_to_a_USB_to_serial_converter</link>
			<description>&lt;p&gt;Nigelbee:&amp;#32;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This example shows how write a Java program to write out &amp;quot;Hello World&amp;quot; to a USB to serial converter connected to a Windows XP computer.&lt;br /&gt;
&lt;br /&gt;
Firstly the USB to serial converter in installed using the manufacturer's instructions. Select My Computer-&amp;gt;Properties-&amp;gt;Hardware-&amp;gt;Device Manager-&amp;gt;Ports(COM&amp;amp;LPT)-&amp;gt;USB - Serial Comm Port (COM4).  This shows a COM port to which the device was installed - in this case COM4.&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;path&amp;quot; (held in My Computer-&amp;gt;properties-&amp;gt;Advanced-&amp;gt;Environment Varables-&amp;gt;System Variables) includes &amp;quot;;C:\Program Files\Java\jdk1.6.0_03\bin&amp;quot; at the end.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Copy the SimpleWrite java program from here: [http://java.sun.com/developer/releases/javacomm/SimpleWrite.java]. Edit the file as follows:&lt;br /&gt;
&lt;br /&gt;
*Change the third import statement &amp;quot;import javax.comm.*;&amp;quot; to read &amp;quot;import gnu.io.*;&amp;quot;&lt;br /&gt;
*Change the line &amp;quot;String  defaultPort = &amp;quot;/dev/term/a&amp;quot;;&amp;quot; to read &amp;quot;String  defaultPort = &amp;quot;COM4&amp;quot;;&amp;quot; (or to whichever port the USB to serial converter is installed)&lt;br /&gt;
&lt;br /&gt;
This Java program can be compiled and run by typing the following at the Command Prompt:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
javac SimpleWrite.java&lt;br /&gt;
java SimpleWrite&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Hello World&amp;quot; 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.&lt;/div&gt;</description>
			<pubDate>Mon, 29 Oct 2007 20:15:56 GMT</pubDate>			<dc:creator>Nigelbee</dc:creator>			<comments>http://rxtx.qbang.org/wiki/index.php/Talk:Writing_%22Hello_World%22_to_a_USB_to_serial_converter</comments>		</item>
		<item>
			<title>Writing &quot;Hello World&quot; to a USB to serial converter</title>
			<link>http://rxtx.qbang.org/wiki/index.php/Writing_%22Hello_World%22_to_a_USB_to_serial_converter</link>
			<description>&lt;p&gt;Nigelbee:&amp;#32;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This example shows how write a Java program to write out &amp;quot;Hello World&amp;quot; to a USB to serial converter connected to a Windows XP computer.&lt;br /&gt;
&lt;br /&gt;
Firstly the USB to serial converter in installed using the manufacturer's instructions. Select My Computer-&amp;gt;Properties-&amp;gt;Hardware-&amp;gt;Device Manager-&amp;gt;Ports(COM&amp;amp;LPT)-&amp;gt;USB - Serial Comm Port (COM4).  This shows that the device was installed as a COM4 port.&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;path&amp;quot; (held in My Computer-&amp;gt;properties-&amp;gt;Advanced-&amp;gt;Environment Varables-&amp;gt;System Variables) includes &amp;quot;;C:\Program Files\Java\jdk1.6.0_03\bin&amp;quot; at the end.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Copy the SimpleWrite java program from here: [http://java.sun.com/developer/releases/javacomm/SimpleWrite.java]. Edit the file as follows:&lt;br /&gt;
&lt;br /&gt;
Change the third import statement &amp;quot;import javax.comm.*;&amp;quot; to read &amp;quot;import gnu.io.*;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Note also that the defaultPort has been set to be COM4.&lt;br /&gt;
Change the line &amp;quot;String  defaultPort = &amp;quot;/dev/term/a&amp;quot;;&amp;quot; to read &amp;quot;String  defaultPort = &amp;quot;COM4&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
This Java program can be compiled and run by typing the following at the Command Prompt:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
javac SimpleWrite.java&lt;br /&gt;
java SimpleWrite&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Hello World&amp;quot; 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.&lt;/div&gt;</description>
			<pubDate>Mon, 29 Oct 2007 20:05:50 GMT</pubDate>			<dc:creator>Nigelbee</dc:creator>			<comments>http://rxtx.qbang.org/wiki/index.php/Talk:Writing_%22Hello_World%22_to_a_USB_to_serial_converter</comments>		</item>
		<item>
			<title>Writing &quot;Hello World&quot; to a USB to serial converter</title>
			<link>http://rxtx.qbang.org/wiki/index.php/Writing_%22Hello_World%22_to_a_USB_to_serial_converter</link>
			<description>&lt;p&gt;Nigelbee:&amp;#32;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This example shows how write a Java program to write out &amp;quot;Hello World&amp;quot; to a USB to serial converter connected to a Windows XP computer.&lt;br /&gt;
&lt;br /&gt;
Firstly the USB to serial converter in installed using the manufacturer's instructions. Select My Computer-&amp;gt;Properties-&amp;gt;Hardware-&amp;gt;Device Manager-&amp;gt;Ports(COM&amp;amp;LPT)-&amp;gt;USB - Serial Comm Port (COM4).  This shows that the device was installed as a COM4 port.&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;path&amp;quot; (held in My Computer-&amp;gt;properties-&amp;gt;Advanced-&amp;gt;Environment Varables-&amp;gt;System Variables) includes &amp;quot;;C:\Program Files\Java\jdk1.6.0_03\bin&amp;quot; at the end.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Put the following file in a folder:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * @(#)SimpleWrite.java	1.12 98/06/25 SMI&lt;br /&gt;
 * &lt;br /&gt;
 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.&lt;br /&gt;
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.&lt;br /&gt;
 * &lt;br /&gt;
 * Sun grants you (&amp;quot;Licensee&amp;quot;) a non-exclusive, royalty free, license&lt;br /&gt;
 * to use, modify and redistribute this software in source and binary&lt;br /&gt;
 * code form, provided that i) this copyright notice and license appear&lt;br /&gt;
 * on all copies of the software; and ii) Licensee does not utilize the&lt;br /&gt;
 * software in a manner which is disparaging to Sun.&lt;br /&gt;
 * &lt;br /&gt;
 * This software is provided &amp;quot;AS IS,&amp;quot; without a warranty of any kind.&lt;br /&gt;
 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,&lt;br /&gt;
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A&lt;br /&gt;
 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND&lt;br /&gt;
 * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY&lt;br /&gt;
 * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE&lt;br /&gt;
 * SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS&lt;br /&gt;
 * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,&lt;br /&gt;
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,&lt;br /&gt;
 * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING&lt;br /&gt;
 * OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN&lt;br /&gt;
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.&lt;br /&gt;
 * &lt;br /&gt;
 * This software is not designed or intended for use in on-line control&lt;br /&gt;
 * of aircraft, air traffic, aircraft navigation or aircraft&lt;br /&gt;
 * communications; or in the design, construction, operation or&lt;br /&gt;
 * maintenance of any nuclear facility. Licensee represents and&lt;br /&gt;
 * warrants that it will not use or redistribute the Software for such&lt;br /&gt;
 * purposes.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.*;&lt;br /&gt;
import java.util.*;&lt;br /&gt;
import gnu.io.*;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Class declaration&lt;br /&gt;
 *&lt;br /&gt;
 *&lt;br /&gt;
 * @author&lt;br /&gt;
 * @version 1.10, 08/04/00&lt;br /&gt;
 */&lt;br /&gt;
public class SimpleWrite {&lt;br /&gt;
    static Enumeration	      portList;&lt;br /&gt;
    static CommPortIdentifier portId;&lt;br /&gt;
    static String	      messageString = &amp;quot;Hello, world!&amp;quot;;&lt;br /&gt;
    static SerialPort	      serialPort;&lt;br /&gt;
    static OutputStream       outputStream;&lt;br /&gt;
    static boolean	      outputBufferEmptyFlag = false;&lt;br /&gt;
    /**&lt;br /&gt;
     * Method declaration&lt;br /&gt;
     *&lt;br /&gt;
     *&lt;br /&gt;
     * @param args&lt;br /&gt;
     *&lt;br /&gt;
     * @see&lt;br /&gt;
     */&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
	boolean portFound = false;&lt;br /&gt;
	String  defaultPort = &amp;quot;COM4&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
	if (args.length &amp;gt; 0) {&lt;br /&gt;
	    defaultPort = args[0];&lt;br /&gt;
	} &lt;br /&gt;
&lt;br /&gt;
	portList = CommPortIdentifier.getPortIdentifiers();&lt;br /&gt;
&lt;br /&gt;
	while (portList.hasMoreElements()) {&lt;br /&gt;
	    portId = (CommPortIdentifier) portList.nextElement();&lt;br /&gt;
&lt;br /&gt;
	    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {&lt;br /&gt;
&lt;br /&gt;
		if (portId.getName().equals(defaultPort)) {&lt;br /&gt;
		    System.out.println(&amp;quot;Found port &amp;quot; + defaultPort);&lt;br /&gt;
&lt;br /&gt;
		    portFound = true;&lt;br /&gt;
&lt;br /&gt;
		    try {&lt;br /&gt;
			serialPort = &lt;br /&gt;
			    (SerialPort) portId.open(&amp;quot;SimpleWrite&amp;quot;, 2000);&lt;br /&gt;
		    } catch (PortInUseException e) {&lt;br /&gt;
			System.out.println(&amp;quot;Port in use.&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
			continue;&lt;br /&gt;
		    } &lt;br /&gt;
&lt;br /&gt;
		    try {&lt;br /&gt;
			outputStream = serialPort.getOutputStream();&lt;br /&gt;
		    } catch (IOException e) {}&lt;br /&gt;
&lt;br /&gt;
		    try {&lt;br /&gt;
			serialPort.setSerialPortParams(9600, &lt;br /&gt;
						       SerialPort.DATABITS_8, &lt;br /&gt;
						       SerialPort.STOPBITS_1, &lt;br /&gt;
						       SerialPort.PARITY_NONE);&lt;br /&gt;
		    } catch (UnsupportedCommOperationException e) {}&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
		    try {&lt;br /&gt;
		    	serialPort.notifyOnOutputEmpty(true);&lt;br /&gt;
		    } catch (Exception e) {&lt;br /&gt;
			System.out.println(&amp;quot;Error setting event notification&amp;quot;);&lt;br /&gt;
			System.out.println(e.toString());&lt;br /&gt;
			System.exit(-1);&lt;br /&gt;
		    }&lt;br /&gt;
		    &lt;br /&gt;
		    &lt;br /&gt;
		    System.out.println(&lt;br /&gt;
		    	&amp;quot;Writing \&amp;quot;&amp;quot;+messageString+&amp;quot;\&amp;quot; to &amp;quot;&lt;br /&gt;
			+serialPort.getName());&lt;br /&gt;
&lt;br /&gt;
		    try {&lt;br /&gt;
			outputStream.write(messageString.getBytes());&lt;br /&gt;
		    } catch (IOException e) {}&lt;br /&gt;
&lt;br /&gt;
		    try {&lt;br /&gt;
		       Thread.sleep(2000);  // Be sure data is xferred before closing&lt;br /&gt;
		    } catch (Exception e) {}&lt;br /&gt;
		    serialPort.close();&lt;br /&gt;
		    System.exit(1);&lt;br /&gt;
		} &lt;br /&gt;
	    } &lt;br /&gt;
	} &lt;br /&gt;
&lt;br /&gt;
	if (!portFound) {&lt;br /&gt;
	    System.out.println(&amp;quot;port &amp;quot; + defaultPort + &amp;quot; not found.&amp;quot;);&lt;br /&gt;
	} &lt;br /&gt;
    } &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the third import statement has been changed to be &amp;quot;import gnu.io.*;&amp;quot;&lt;br /&gt;
rather than the &amp;quot;import javax.comm.*;&amp;quot; that appears in Sun's original version.&lt;br /&gt;
&lt;br /&gt;
Note also that the defaultPort has been set to be COM4.&lt;br /&gt;
&lt;br /&gt;
This Java program can be compiled and run by typing the following at the Command Prompt:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
javac SimpleWrite.java&lt;br /&gt;
java SimpleWrite&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Hello World&amp;quot; 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.&lt;/div&gt;</description>
			<pubDate>Sun, 28 Oct 2007 21:05:46 GMT</pubDate>			<dc:creator>Nigelbee</dc:creator>			<comments>http://rxtx.qbang.org/wiki/index.php/Talk:Writing_%22Hello_World%22_to_a_USB_to_serial_converter</comments>		</item>
		<item>
			<title>Writing &quot;Hello World&quot; to a USB to serial converter</title>
			<link>http://rxtx.qbang.org/wiki/index.php/Writing_%22Hello_World%22_to_a_USB_to_serial_converter</link>
			<description>&lt;p&gt;Nigelbee:&amp;#32;New page: This example shows how write a Java program to write out &amp;quot;Hello World&amp;quot; to a USB to serial converter connected to a Windwos XP computer.  Firstly the USB to serial converter in installed us...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This example shows how write a Java program to write out &amp;quot;Hello World&amp;quot; to a USB to serial converter connected to a Windwos XP computer.&lt;br /&gt;
&lt;br /&gt;
Firstly the USB to serial converter in installed using the manufacturer's instructions. Select My Computer-&amp;gt;Properties-&amp;gt;Hardware-&amp;gt;Device Manager-&amp;gt;Ports(COM&amp;amp;LPT)-&amp;gt;USB - Serial Comm Port (COM4).  This shows that the device was installed as a COM4 port.&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;path&amp;quot; (held in My Computer-&amp;gt;properties-&amp;gt;Advanced-&amp;gt;Environment Varables-&amp;gt;System Variables) includes &amp;quot;;C:\Program Files\Java\jdk1.6.0_03\bin&amp;quot; at the end.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Put the following file in a folder:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
 * @(#)SimpleWrite.java	1.12 98/06/25 SMI&lt;br /&gt;
 * &lt;br /&gt;
 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.&lt;br /&gt;
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.&lt;br /&gt;
 * &lt;br /&gt;
 * Sun grants you (&amp;quot;Licensee&amp;quot;) a non-exclusive, royalty free, license&lt;br /&gt;
 * to use, modify and redistribute this software in source and binary&lt;br /&gt;
 * code form, provided that i) this copyright notice and license appear&lt;br /&gt;
 * on all copies of the software; and ii) Licensee does not utilize the&lt;br /&gt;
 * software in a manner which is disparaging to Sun.&lt;br /&gt;
 * &lt;br /&gt;
 * This software is provided &amp;quot;AS IS,&amp;quot; without a warranty of any kind.&lt;br /&gt;
 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,&lt;br /&gt;
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A&lt;br /&gt;
 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND&lt;br /&gt;
 * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY&lt;br /&gt;
 * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE&lt;br /&gt;
 * SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS&lt;br /&gt;
 * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,&lt;br /&gt;
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,&lt;br /&gt;
 * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING&lt;br /&gt;
 * OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN&lt;br /&gt;
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.&lt;br /&gt;
 * &lt;br /&gt;
 * This software is not designed or intended for use in on-line control&lt;br /&gt;
 * of aircraft, air traffic, aircraft navigation or aircraft&lt;br /&gt;
 * communications; or in the design, construction, operation or&lt;br /&gt;
 * maintenance of any nuclear facility. Licensee represents and&lt;br /&gt;
 * warrants that it will not use or redistribute the Software for such&lt;br /&gt;
 * purposes.&lt;br /&gt;
 */&lt;br /&gt;
import java.io.*;&lt;br /&gt;
import java.util.*;&lt;br /&gt;
import gnu.io.*;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Class declaration&lt;br /&gt;
 *&lt;br /&gt;
 *&lt;br /&gt;
 * @author&lt;br /&gt;
 * @version 1.10, 08/04/00&lt;br /&gt;
 */&lt;br /&gt;
public class SimpleWrite {&lt;br /&gt;
    static Enumeration	      portList;&lt;br /&gt;
    static CommPortIdentifier portId;&lt;br /&gt;
    static String	      messageString = &amp;quot;Hello, world!&amp;quot;;&lt;br /&gt;
    static SerialPort	      serialPort;&lt;br /&gt;
    static OutputStream       outputStream;&lt;br /&gt;
    static boolean	      outputBufferEmptyFlag = false;&lt;br /&gt;
    /**&lt;br /&gt;
     * Method declaration&lt;br /&gt;
     *&lt;br /&gt;
     *&lt;br /&gt;
     * @param args&lt;br /&gt;
     *&lt;br /&gt;
     * @see&lt;br /&gt;
     */&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
	boolean portFound = false;&lt;br /&gt;
	String  defaultPort = &amp;quot;COM4&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
	if (args.length &amp;gt; 0) {&lt;br /&gt;
	    defaultPort = args[0];&lt;br /&gt;
	} &lt;br /&gt;
&lt;br /&gt;
	portList = CommPortIdentifier.getPortIdentifiers();&lt;br /&gt;
&lt;br /&gt;
	while (portList.hasMoreElements()) {&lt;br /&gt;
	    portId = (CommPortIdentifier) portList.nextElement();&lt;br /&gt;
&lt;br /&gt;
	    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {&lt;br /&gt;
&lt;br /&gt;
		if (portId.getName().equals(defaultPort)) {&lt;br /&gt;
		    System.out.println(&amp;quot;Found port &amp;quot; + defaultPort);&lt;br /&gt;
&lt;br /&gt;
		    portFound = true;&lt;br /&gt;
&lt;br /&gt;
		    try {&lt;br /&gt;
			serialPort = &lt;br /&gt;
			    (SerialPort) portId.open(&amp;quot;SimpleWrite&amp;quot;, 2000);&lt;br /&gt;
		    } catch (PortInUseException e) {&lt;br /&gt;
			System.out.println(&amp;quot;Port in use.&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
			continue;&lt;br /&gt;
		    } &lt;br /&gt;
&lt;br /&gt;
		    try {&lt;br /&gt;
			outputStream = serialPort.getOutputStream();&lt;br /&gt;
		    } catch (IOException e) {}&lt;br /&gt;
&lt;br /&gt;
		    try {&lt;br /&gt;
			serialPort.setSerialPortParams(9600, &lt;br /&gt;
						       SerialPort.DATABITS_8, &lt;br /&gt;
						       SerialPort.STOPBITS_1, &lt;br /&gt;
						       SerialPort.PARITY_NONE);&lt;br /&gt;
		    } catch (UnsupportedCommOperationException e) {}&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
		    try {&lt;br /&gt;
		    	serialPort.notifyOnOutputEmpty(true);&lt;br /&gt;
		    } catch (Exception e) {&lt;br /&gt;
			System.out.println(&amp;quot;Error setting event notification&amp;quot;);&lt;br /&gt;
			System.out.println(e.toString());&lt;br /&gt;
			System.exit(-1);&lt;br /&gt;
		    }&lt;br /&gt;
		    &lt;br /&gt;
		    &lt;br /&gt;
		    System.out.println(&lt;br /&gt;
		    	&amp;quot;Writing \&amp;quot;&amp;quot;+messageString+&amp;quot;\&amp;quot; to &amp;quot;&lt;br /&gt;
			+serialPort.getName());&lt;br /&gt;
&lt;br /&gt;
		    try {&lt;br /&gt;
			outputStream.write(messageString.getBytes());&lt;br /&gt;
		    } catch (IOException e) {}&lt;br /&gt;
&lt;br /&gt;
		    try {&lt;br /&gt;
		       Thread.sleep(2000);  // Be sure data is xferred before closing&lt;br /&gt;
		    } catch (Exception e) {}&lt;br /&gt;
		    serialPort.close();&lt;br /&gt;
		    System.exit(1);&lt;br /&gt;
		} &lt;br /&gt;
	    } &lt;br /&gt;
	} &lt;br /&gt;
&lt;br /&gt;
	if (!portFound) {&lt;br /&gt;
	    System.out.println(&amp;quot;port &amp;quot; + defaultPort + &amp;quot; not found.&amp;quot;);&lt;br /&gt;
	} &lt;br /&gt;
    } &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the third import statement has been changed to be &amp;quot;import gnu.io.*;&amp;quot;&lt;br /&gt;
rather than the &amp;quot;import javax.comm.*;&amp;quot; that appears in Sun's original version.&lt;br /&gt;
&lt;br /&gt;
Note also that the defaultPort has been set to be COM4.&lt;br /&gt;
&lt;br /&gt;
This Java program can be compiled and run by typing the following at the Command Prompt:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
javac SimpleWrite.java&lt;br /&gt;
java SimpleWrite&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Hello World&amp;quot; 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.&lt;/div&gt;</description>
			<pubDate>Sun, 28 Oct 2007 21:04:52 GMT</pubDate>			<dc:creator>Nigelbee</dc:creator>			<comments>http://rxtx.qbang.org/wiki/index.php/Talk:Writing_%22Hello_World%22_to_a_USB_to_serial_converter</comments>		</item>
		<item>
			<title>Examples</title>
			<link>http://rxtx.qbang.org/wiki/index.php/Examples</link>
			<description>&lt;p&gt;Nigelbee:&amp;#32;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Note that all the examples below require that you import the gnu.io package.&lt;br /&gt;
&lt;br /&gt;
*[[Two way communcation with the serial port]]&lt;br /&gt;
*[[Parallel Communications]]&lt;br /&gt;
*[[Discovering comm ports]]&lt;br /&gt;
*[[Discovering available comm ports]]&lt;br /&gt;
*[[Writing &amp;quot;Hello World&amp;quot; to a USB to serial converter]]&lt;/div&gt;</description>
			<pubDate>Sun, 28 Oct 2007 20:22:39 GMT</pubDate>			<dc:creator>Nigelbee</dc:creator>			<comments>http://rxtx.qbang.org/wiki/index.php/Talk:Examples</comments>		</item>
	</channel>
</rss>