Home > other >  Linux serial communication system
Linux serial communication system

Time:09-25

All bosses know that mistake how to solve? Serial port devices connected to success. But will run at the wrong
Stable Library
=========================================
Native lib Version=RXTX 2.1-7
Java lib Version=RXTX 2.1-7
RXTX Warning: o stale lock file./var/lock/LCK.. TtyUSB0
#
# A fatal error has had been detected by the Java Runtime Environment:
#
# SIGSEGV=0 (0 xb) at PC x00007fca7be34733, pid=2860, tid=0 x00007fca9a6a9700
#
SE # JRE version: the Java (TM) Runtime Environment (8.0 _131 - b11) (build 1.8.0 comes with _131 - b11)
# Java VM: Java HotSpot (TM) 64 - Bit Server VM (25.131 - bl1 mixed mode Linux - amd64 compressed oops)
# Problematic frame:
[librxtxSerial. So + 0 # C x7733] Java_gnu_io_RXTXPort_nativeDrain + 0 xc3
#
# Failed to write the core dump. Core dumps have had been disabled. To enable the core dumping, the try "ulimit -c unlimited" before starting the Java again
#
# An error report file with more information is saved as:
#/home/xian/JAVAHOME/account/hs_err_pid2860 log
#
# If you order a like to submit a bug report, both please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside The Java Virtual Machine in native code.
# See problematic frame for the where to report the bug.
#
Experimental: JNI_OnLoad called.

CodePudding user response:

I have solved, search on the Internet for a long time has been can't find the answer, and then use the debug debugging finally find out why
Question 1: RXTX Warning: o stale lock file./var/lock/LCK.. TtyUSB0
Solution: direct delete/var/lock/LCK.. TtyUSB0 file (rm/var/lock/LCK.. TtyUSB0)
Question 2: Experimental: JNI_OnLoad called.
Solution: the I in the code directly to the outputStream. Flush (); Comments with respect to ok
My whole serial communication code:
Package com. Lang. Business. The Test;

import java.io.IOException;
Import the Java. IO. OutputStream;
Import the Java. Util. Enumeration;

The import com. Lang. Business. Util. PropertiesUtil;

The import gnu.io.Com mPortIdentifier;
Import the gnu. IO. NoSuchPortException;
Import the gnu. IO. PortInUseException;
Import the gnu. IO. SerialPort;
Import the gnu. IO. UnsupportedCommOperationException;

Public class RxtxTest6 {

Public static final byte [] init=new byte [] {0 x1b, 0 x40};
Public static final byte [] the clean=new byte [] x0c {0};
Public static final byte [] pre_display=new byte [] {0 x1b, 0 x51, 0 x41};
Public static final byte [] post_display=new byte [] x0d {0};

The static CommPortIdentifier portId;
The static Enumeration portList.
Static int bauds []={9600, 19200, 57600, 115200};
Public static void displayCustomerScreen (String data, byte [] mode) {
Try {
CommPortIdentifier portIdentifier=CommPortIdentifier. GetPortIdentifier (PropertiesUtil getComport ());//serial number
//the user and the maximum response time (ms) says that if a serial port being used when the program is the longest waiting time, in milliseconds,
SerialPort SerialPort=(SerialPort) portIdentifier. Open (PropertiesUtil. GetComport (), 2000);
SerialPort. SetSerialPortParams (9600,//baud rate
SerialPort DATABITS_8,//check digit
SerialPort STOPBITS_1,//
the data bitsSerialPort. PARITY_NONE);//stop bit
SerialPort. SetFlowControlMode (serialPort. FLOWCONTROL_NONE);
Try {
OutputStream OutputStream=serialPort. GetOutputStream ();
If (mode!=null) {
OutputStream. Write (mode);
}
if (data !=null) {
OutputStream. Write (pre_display);
OutputStream. Write (data. GetBytes ());
OutputStream. Write (post_display);
}
//outputStream. Flush ();
outputStream.close();
} the catch (IOException e) {
e.printStackTrace();
} the finally {
SerialPort. Close ();
}
} the catch (NoSuchPortException e) {
e.printStackTrace();
} the catch (PortInUseException e) {
e.printStackTrace();
} the catch (UnsupportedCommOperationException e) {
e.printStackTrace();
}
}

Public static void main (String [] args) {
A String of bytes="" TEST \ "1% " 45345 \ "2%";
//displayCustomerScreen (null bytes. GetBytes ());
DisplayCustomerScreen (null bytes. GetBytes ());//TEST \ '\' \ "1%" 35345 \ "2%", "300 h4tj
"PortList.=CommPortIdentifier getPortIdentifiers ();
While (portList. HasMoreElements ()) {
PortId=(CommPortIdentifier) portList. NextElement ();
If (portId getPortType ()==CommPortIdentifier. PORT_SERIAL) {
System. The out. Println (" Find CommPort: "+ portId. GetName ());
}
}
}

}

CodePudding user response:

Started the first step to use Linux connection is can't find the serial port and equipment, the back after installed drive in the usb to rs232 serial port, the Linux system containing a serial port tools, and then set the serial port number and baud rate and parity stop bits, can run normally,
  • Related