publicvoidserialEvent(SerialPortEventevent){try{serialPort.setSerialPortParams(4800,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);}catch(Unsupported...
public void serialEvent(SerialPortEvent event) {
try {
serialPort.setSerialPortParams(4800, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
byte[] readBuffer = new byte[15];
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
while (inputStream.available() > 0) {//从线路上读取数据流
int numBytes = inputStream.read(readBuffer);
}
str = new String(readBuffer);
in_message.setText(str);
System.out.println(str);
String br = in_message.getText();
Transfer pt = new Transfer();
String[] a = new String[15];
for (int i = 0; i < 15;i++) {
a[i] = str.substring(i, i + 1);
}
System.out.println(str);这句输出的是乱码,求助啊,谢谢了
pt.transfer(a);( 这是写到数据库)
}catch (IOException e){}
}
}
展开