I want to create communication between serial port and java, since my real device is not arrived yet, so I use socat as people suggested on internet mostly.
I start with running socat first for virtual serial port with this command
socat -d -d pty,raw,echo=0 pty,raw,echo=0
then I get this
2018/12/05 05:05:04 socat[2687] N PTY is /dev/pts/4
2018/12/05 05:05:04 socat[2687] N PTY is /dev/pts/5
that's mean I could use /dev/pts/4 and /dev/pts/5 for port (NB: this is randomly given by socat, i don't know why)
and then I tried with python for communication with /dev/pts/4, and its work perfectly, then I use java with jSerialComm library I couldn't connect to /dev/pts/4, even cannot listed any ports.
SerialPort sp=SerialPort.getCommPort("/dev/pts/4");
System.out.println(sp.isOpen());
my java code keeps returning false. any response for this I'd appreciate it.
thanks
When you do SerialPort sp=SerialPort.getCommPort("/dev/pts/4");
you are getting the object that controls that port. The port however is still closed until you open it. This is done by doing sp.openPort();
. Then you will see that when you run sp.isOpen();
it should return true.
If you need further help the documentation can be found here .
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.