Commit dbd2d1f3 authored by qizhiqiang's avatar qizhiqiang

接收参数修改

parent 32a45670
...@@ -31,7 +31,7 @@ public class RxtxUtils extends Thread implements SerialPortEventListener { ...@@ -31,7 +31,7 @@ public class RxtxUtils extends Thread implements SerialPortEventListener {
// 堵塞队列用来存放读到的数据 // 堵塞队列用来存放读到的数据
private BlockingQueue<String> msgQueue = new LinkedBlockingQueue<String>(); private BlockingQueue<String> msgQueue = new LinkedBlockingQueue<String>();
//当前接收到的重量信息 //当前接收到的重量信息
public static Double weightings; public static String weightings;
/** /**
* SerialPort EventListene 的方法,持续监听端口上是否有数据流 * SerialPort EventListene 的方法,持续监听端口上是否有数据流
*/ */
...@@ -140,10 +140,10 @@ public class RxtxUtils extends Thread implements SerialPortEventListener { ...@@ -140,10 +140,10 @@ public class RxtxUtils extends Thread implements SerialPortEventListener {
while (true) { while (true) {
// 如果堵塞队列中存在数据就将其输出 // 如果堵塞队列中存在数据就将其输出
if (msgQueue.size() > 0) { if (msgQueue.size() > 0) {
weightings = Double.parseDouble(msgQueue.take()); weightings = replaceStr(msgQueue.take());
System.out.println("Received messages:"+weightings); System.out.println("Received messages:"+weightings);
WebSocket webSocket = new WebSocket(); WebSocket webSocket = new WebSocket();
webSocket.sendAllToUserMessage(String.valueOf(weightings)); webSocket.sendAllToUserMessage(weightings);
// sendDate(weightings); // sendDate(weightings);
} }
} }
...@@ -151,6 +151,24 @@ public class RxtxUtils extends Thread implements SerialPortEventListener { ...@@ -151,6 +151,24 @@ public class RxtxUtils extends Thread implements SerialPortEventListener {
e.printStackTrace(); e.printStackTrace();
} }
} }
// public static void main(String[] args) {
// String str = "Received messages?ASNG/W+ 0.21 kg\n"; ;
// System.out.println(str);
// String s = replaceStr(str);
// System.out.println(s);
// }
/**
* 去除空格和回车
* @param str
* @return
*/
public static String replaceStr(String str){
//去除空格,回车
String s = str.replaceAll("\\s*|\r|\n|\t", "");
//去除nul值
String kg = s.substring(s.lastIndexOf("W+")+2, s.lastIndexOf("kg")+2);
return kg;
}
public static void sendToPort(String data) { public static void sendToPort(String data) {
OutputStream out = null; OutputStream out = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment