Reputation: 3890
I am trying to communicate with a microcontroller using java. In windows i simply use "COM4" and my code workes perfectly. In linux i am trying to use "/dev/ttyUSB0". But gives me an error "Could not find serial port".
I used dmesg | grep tty
to see active serial port. is this a right method?
how can i solve this issue? I am really new to linux so please explain in simple language
here is my code
Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier portId = null;
while (portIdentifiers.hasMoreElements())
{
CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();
if(pid.getPortType() == CommPortIdentifier.PORT_SERIAL &&
pid.getName().equals("/dev/ttyUSB0"))
{
portId = pid;
break;
}
}
if(portId == null)
{
System.err.println("Could not find serial port "); // + wantedPortName);
System.exit(1);
}
Upvotes: 0
Views: 1607
Reputation: 3890
Apparently java communication API do not have linux implementation http://www.oracle.com/technetwork/java/index-139971.html thats why my code wasn't working.
I installed RXTX library for serial communication and code is working fine now. Thanks nos and Olaf Dietsche for the help and support.
Upvotes: 0
Reputation: 74008
lsusb
should show you the serial to USB converter
lsusb | grep -i serial
gives on my system
Bus 001 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
and
ls -l /dev/ttyUSB*
crw-rw---- 1 root dialout 188, 0 Feb 18 10:30 /dev/ttyUSB0
I can then access it with
cat /dev/ttyUSB0
The user, who needs access to the port, must be in the group dialout
or whatever group it is in your system. You can add the user with
adduser <user-name> dialout
Upvotes: 1