A
Arash Nikkar
I am trying to port some Java code which was written specifically for
linux over to windows, and I have run into a bit of a problem.
The linux code uses a USB->Ir dongle, but uses the RXTX comm package. I
am a bit confused by this, because I though the comm package does not
support USB. Is the Comm package being "fooling" (sorry couldn't think
of a better term), into thinking that the USB is a serial port. The
code is as follows:
String port = "/dev/ttyUSB0"; //also seems to use: /dev/ttyS0 for
testing
RXTXCommDriver gnuDriver = new RXTXCommDriver();
CommPortIdentifier.addPortName(port,
CommPortIdentifier.PORT_SERIAL, gnuDriver);
portId = CommPortIdentifier.getPortIdentifier(port);
if (portId.getPortType() != CommPortIdentifier.PORT_SERIAL) {
System.out.println("Port " + port + " is not a serial port");
return;
};
serialPort = (SerialPort)portId.open("Test", 2000);
outputStream = serialPort.getOutputStream();
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
Seems straighforward to me, except for the PORT part. Is it possible to
mimick this code in windows?
The traditional way I have used serial ports with java is by asking the
system for all the available comm ports, and iterating through them:
List<SerialPort> serialPortList = new ArrayList<SerialPort>();
while (portList.hasMoreElements()) {
CommPortIdentifier portId =
(CommPortIdentifier)portList.nextElement();
if(portId.getPortType() == CommPortIdentifier.PORT_SERIAL &&
!portId.isCurrentlyOwned()) {
try {
SerialPort tempPort = (SerialPort)
portId.open("Test", 2000);
tempPort.setSerialPortParams(9600,
SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
....
}
thanks in advance...
linux over to windows, and I have run into a bit of a problem.
The linux code uses a USB->Ir dongle, but uses the RXTX comm package. I
am a bit confused by this, because I though the comm package does not
support USB. Is the Comm package being "fooling" (sorry couldn't think
of a better term), into thinking that the USB is a serial port. The
code is as follows:
String port = "/dev/ttyUSB0"; //also seems to use: /dev/ttyS0 for
testing
RXTXCommDriver gnuDriver = new RXTXCommDriver();
CommPortIdentifier.addPortName(port,
CommPortIdentifier.PORT_SERIAL, gnuDriver);
portId = CommPortIdentifier.getPortIdentifier(port);
if (portId.getPortType() != CommPortIdentifier.PORT_SERIAL) {
System.out.println("Port " + port + " is not a serial port");
return;
};
serialPort = (SerialPort)portId.open("Test", 2000);
outputStream = serialPort.getOutputStream();
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
Seems straighforward to me, except for the PORT part. Is it possible to
mimick this code in windows?
The traditional way I have used serial ports with java is by asking the
system for all the available comm ports, and iterating through them:
List<SerialPort> serialPortList = new ArrayList<SerialPort>();
while (portList.hasMoreElements()) {
CommPortIdentifier portId =
(CommPortIdentifier)portList.nextElement();
if(portId.getPortType() == CommPortIdentifier.PORT_SERIAL &&
!portId.isCurrentlyOwned()) {
try {
SerialPort tempPort = (SerialPort)
portId.open("Test", 2000);
tempPort.setSerialPortParams(9600,
SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
....
}
thanks in advance...