简体   繁体   中英

Serial port with jSSC in linux

I'm trying to work with serial port in java with jSSC. My code:

import jssc.SerialPortList;
....
String[] ports = SerialPortList.getPortNames();

but it always return empty array.

brut@brut-Z97-D3H:~$ dmesg | grep tty
[    0.000000] console [tty0] enabled
[    0.957537] 00:05: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A

Can anyone help me?

I've faced the same issue recently, here's what I've managed to find out.

The first thing you should check is whether you have enough rights to access tty* interface.

Firstly, make sure your user is in dialout group. If not, execute

sudo adduser phil dialout

and then give yourself rights to read-write to the exact port.

sudo chmod 666 /dev/ttyS0

After that SerialPortList.getPortNames() should return ttyS0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM