简体   繁体   English

在linux中使用jSSC的串口

[英]Serial port with jSSC in linux

I'm trying to work with serial port in java with jSSC. 我正在尝试使用jSSC在java中使用串口。 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. 您应该检查的第一件事是您是否有足够的权限访问tty *接口。

Firstly, make sure your user is in dialout group. 首先,确保您的用户处于dialout组。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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