Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
miya-hardware
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pengguangpu
miya-hardware
Commits
98598a2e
Commit
98598a2e
authored
Dec 20, 2018
by
pengguangpu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善创捷的重量获取逻辑,release方法
parent
baed0766
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
10 deletions
+61
-10
misc.xml
.idea/misc.xml
+1
-1
WeighingActivity.java
app/src/main/java/com/miya/hardware/WeighingActivity.java
+9
-0
activity_hardware.xml
app/src/main/res/layout/activity_hardware.xml
+4
-2
activity_weighing.xml
app/src/main/res/layout/activity_weighing.xml
+19
-1
ChuangjieWeighing.java
...ng/src/main/java/com/miya/weighing/ChuangjieWeighing.java
+13
-3
WeighingManager.java
...hing/src/main/java/com/miya/weighing/WeighingManager.java
+12
-0
ReadSerialPort.java
.../src/main/java/pupu/chuangjieweighing/ReadSerialPort.java
+3
-3
No files found.
.idea/misc.xml
View file @
98598a2e
...
...
@@ -29,7 +29,7 @@
</value>
</option>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
8
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
7
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/build/classes"
/>
</component>
<component
name=
"ProjectType"
>
...
...
app/src/main/java/com/miya/hardware/WeighingActivity.java
View file @
98598a2e
...
...
@@ -20,6 +20,8 @@ public class WeighingActivity extends Activity implements View.OnClickListener {
TextView
tvResult
;
TextView
tvResultNow
;
Handler
handler
=
new
Handler
()
{
@Override
public
void
handleMessage
(
Message
msg
)
{
...
...
@@ -38,6 +40,7 @@ public class WeighingActivity extends Activity implements View.OnClickListener {
setContentView
(
R
.
layout
.
activity_weighing
);
tvResult
=
findViewById
(
R
.
id
.
tvResult
);
tvResultNow
=
findViewById
(
R
.
id
.
tvResultNow
);
etGravity
=
findViewById
(
R
.
id
.
etGravity
);
etTare
=
findViewById
(
R
.
id
.
etTare
);
...
...
@@ -48,6 +51,7 @@ public class WeighingActivity extends Activity implements View.OnClickListener {
findViewById
(
R
.
id
.
btnTare
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
btnGravity
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
btnRelease
).
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
btnReadNow
).
setOnClickListener
(
this
);
}
@Override
...
...
@@ -106,6 +110,11 @@ public class WeighingActivity extends Activity implements View.OnClickListener {
WeighingManager
.
getInstance
().
getWeighing
().
release
();
}
break
;
case
R
.
id
.
btnReadNow
:
if
(
WeighingManager
.
getInstance
().
isConnected
())
{
tvResultNow
.
setText
(
WeighingManager
.
getInstance
().
getWeighing
().
getWeight
()+
""
);
}
break
;
}
if
(
WeighingManager
.
getInstance
().
isConnected
()
==
false
)
{
tvResult
.
setText
(
"当前没有称重设备,试试初始化!"
);
...
...
app/src/main/res/layout/activity_hardware.xml
View file @
98598a2e
...
...
@@ -23,13 +23,15 @@
android:layout_width=
"match_parent"
android:layout_height=
"0dp"
android:layout_weight=
"1"
android:text=
"称重demo"
/>
android:text=
"称重demo"
android:textSize=
"48sp"
/>
<Button
android:id=
"@+id/btnPrint"
android:layout_width=
"match_parent"
android:layout_height=
"0dp"
android:layout_weight=
"1"
android:text=
"打印demo"
/>
android:text=
"打印demo"
android:textSize=
"48sp"
/>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/activity_weighing.xml
View file @
98598a2e
...
...
@@ -18,6 +18,14 @@
android:textSize=
"36sp"
/>
</android.support.v7.widget.ActionMenuView>
<TextView
android:id=
"@+id/tvResultNow"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
android:text=
"显示当前称台重量"
android:textSize=
"36sp"
/>
<TextView
android:id=
"@+id/tvResult"
android:layout_width=
"wrap_content"
...
...
@@ -47,7 +55,7 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:text=
"读取重量"
/>
android:text=
"读取
实时
重量"
/>
</TableRow>
<TableRow>
...
...
@@ -60,6 +68,16 @@
android:text=
"重置零点"
/>
</TableRow>
<TableRow>
<Button
android:id=
"@+id/btnReadNow"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:text=
"获取当前称台重量"
/>
</TableRow>
<TableRow>
<EditText
...
...
weighing/src/main/java/com/miya/weighing/ChuangjieWeighing.java
View file @
98598a2e
...
...
@@ -36,11 +36,11 @@ public class ChuangjieWeighing extends BaseWeighing {
serialPortFunction
.
getWeighingSerialPort
(
"/dev/ttyS4"
,
9600
);
serialPortFunction
.
startReadWeight
(
new
ReadSerialPort
.
DataWeight
()
{
@Override
public
void
weight
(
String
s
)
{
public
void
weight
(
String
s
,
boolean
isStable
)
{
Log
.
i
(
TAG
,
"当前重量为:"
+
s
);
curWeight
=
parseKg2g
(
s
.
trim
());
if
(
weighingCallback
!=
null
&&
curWeight
>=
0
)
{
weighingCallback
.
returnWeight
(
curWeight
,
tru
e
);
weighingCallback
.
returnWeight
(
curWeight
,
isStabl
e
);
}
if
(
curWeight
<
0
)
{
//发送置零指令
...
...
@@ -59,7 +59,7 @@ public class ChuangjieWeighing extends BaseWeighing {
@Override
public
boolean
resetZero
()
{
if
(
serialPortFunction
!=
null
)
{
if
(
serialPortFunction
!=
null
&&
isResetZeroing
==
false
)
{
isResetZeroing
=
true
;
//发送置零指令,有2s的耗时,内部为线程池异步操作
serialPortFunction
.
sendEle
(
"410D0A"
);
...
...
@@ -79,4 +79,14 @@ public class ChuangjieWeighing extends BaseWeighing {
}
return
false
;
}
@Override
public
boolean
release
()
{
super
.
release
();
weighingCallback
=
null
;
if
(
serialPortFunction
!=
null
)
{
serialPortFunction
.
closeEle
();
}
return
true
;
}
}
weighing/src/main/java/com/miya/weighing/WeighingManager.java
View file @
98598a2e
...
...
@@ -165,4 +165,16 @@ public class WeighingManager {
}
return
false
;
}
/**
* 断开与称重台的连接
*
* @return 断开操作的结果
*/
public
boolean
disConnect
()
{
if
(
isConnected
())
{
return
weighing
.
release
();
}
return
true
;
}
}
weighing/src/main/java/pupu/chuangjieweighing/ReadSerialPort.java
View file @
98598a2e
...
...
@@ -152,14 +152,14 @@ public class ReadSerialPort implements Runnable {
System
.
out
.
println
(
"在误差范围内"
+
weightMaxCount
);
weightMaxCount
--;
if
(
weightMaxCount
<=
0
&&
isStabilize
)
{
if
(
weightMaxCount
<=
0
)
{
nowWeight
=
tempWeight
;
weightMaxCount
=
3
;
if
(
dataWeight
==
null
)
{
throw
new
NullPointerException
();
}
System
.
out
.
println
(
"要发送的重量 "
+
MoneyUtil
.
formatMoney
(
nowWeight
));
dataWeight
.
weight
(
MoneyUtil
.
formatMoney
(
nowWeight
));
dataWeight
.
weight
(
MoneyUtil
.
formatMoney
(
nowWeight
)
,
isStabilize
);
}
}
else
{
System
.
out
.
println
(
"超出误差范围 次数归3"
);
...
...
@@ -194,6 +194,6 @@ public class ReadSerialPort implements Runnable {
public
interface
DataWeight
{
void
weight
(
String
weight
);
void
weight
(
String
weight
,
boolean
isStable
);
}
}
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