I'm trying to work with serial port in java with jSSC. My code:
我正在尝试使用jSSC在java中使用串口。我的代码:
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?
谁能帮我?
1 个解决方案
#1
3
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.
您应该检查的第一件事是您是否有足够的权限访问tty *接口。
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
之后,SerialPortList.getPortNames()应该返回ttyS0
#1
3
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.
您应该检查的第一件事是您是否有足够的权限访问tty *接口。
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
之后,SerialPortList.getPortNames()应该返回ttyS0