Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
metage
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guoyu
metage
Commits
dbd2d1f3
Commit
dbd2d1f3
authored
Apr 14, 2023
by
qizhiqiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接收参数修改
parent
32a45670
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
3 deletions
+21
-3
RxtxUtils.java
src/main/java/com/mushiny/metage/util/RxtxUtils.java
+21
-3
No files found.
src/main/java/com/mushiny/metage/util/RxtxUtils.java
View file @
dbd2d1f3
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment