Talk:Serial Programming/Serial Java
From Wikibooks, the open-content textbooks collection
Hello,
I'm currently learning basics of using Java for serial communication on Linux. I couldn't get JavaComm to find /dev/ttyS0, so I've downloaded Sun's SimpleRead.java (http://java.sun.com/developer/releases/javacomm/SimpleRead.java) and modified in the following way:
...
portId = (CommPortIdentifier) portList.nextElement();
System.out.println("Found a port named " + portId.getName());
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
...
It turned out, that on my machine serial ports are named COMx with x being a number 1-8.
This naming convention seems consistent with the contents of javax.comm.properties which reads on my machine:
... # Port numbers are sequentially allocated to all devices found that correspond # to these devices. # For example if you specify the prefix /dev/ttyS=PORT_SERIAL # and the following devices exist # /dev/ttyS0 # /dev/ttyS1 # then they will be allocated COM1 and COM2 respectively ...
Therefore I'd propose adding a warning to other newbies in "Finding the desired serial Port" paragraph, that they should not neccessarily expect JavaComm port names to correspond to the OS level port names.
My observations may or may not relate to the software that I'm using, so for reference I tested this on IBM Java Runtime Environment 1.4.2, JavaComm is provided by java-1.4.2-ibm-javacomm rpm package and I'm running them on Red Hat Enterprise Linux Workstation 4 update 3.
Regards,
Paweł Brodacki
Hello
I will also add that in order to properly compile this code is necesary to add this line at the begin. import java.io.*;
Also, I think variable motoPort is not previously defined.
Best Regards, Javier Sanchez.