Commit 98598a2e authored by pengguangpu's avatar pengguangpu

完善创捷的重量获取逻辑,release方法

parent baed0766
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
</value> </value>
</option> </option>
</component> </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" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
......
...@@ -20,6 +20,8 @@ public class WeighingActivity extends Activity implements View.OnClickListener { ...@@ -20,6 +20,8 @@ public class WeighingActivity extends Activity implements View.OnClickListener {
TextView tvResult; TextView tvResult;
TextView tvResultNow;
Handler handler = new Handler() { Handler handler = new Handler() {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
...@@ -38,6 +40,7 @@ public class WeighingActivity extends Activity implements View.OnClickListener { ...@@ -38,6 +40,7 @@ public class WeighingActivity extends Activity implements View.OnClickListener {
setContentView(R.layout.activity_weighing); setContentView(R.layout.activity_weighing);
tvResult = findViewById(R.id.tvResult); tvResult = findViewById(R.id.tvResult);
tvResultNow = findViewById(R.id.tvResultNow);
etGravity = findViewById(R.id.etGravity); etGravity = findViewById(R.id.etGravity);
etTare = findViewById(R.id.etTare); etTare = findViewById(R.id.etTare);
...@@ -48,6 +51,7 @@ public class WeighingActivity extends Activity implements View.OnClickListener { ...@@ -48,6 +51,7 @@ public class WeighingActivity extends Activity implements View.OnClickListener {
findViewById(R.id.btnTare).setOnClickListener(this); findViewById(R.id.btnTare).setOnClickListener(this);
findViewById(R.id.btnGravity).setOnClickListener(this); findViewById(R.id.btnGravity).setOnClickListener(this);
findViewById(R.id.btnRelease).setOnClickListener(this); findViewById(R.id.btnRelease).setOnClickListener(this);
findViewById(R.id.btnReadNow).setOnClickListener(this);
} }
@Override @Override
...@@ -106,6 +110,11 @@ public class WeighingActivity extends Activity implements View.OnClickListener { ...@@ -106,6 +110,11 @@ public class WeighingActivity extends Activity implements View.OnClickListener {
WeighingManager.getInstance().getWeighing().release(); WeighingManager.getInstance().getWeighing().release();
} }
break; break;
case R.id.btnReadNow:
if (WeighingManager.getInstance().isConnected()) {
tvResultNow.setText(WeighingManager.getInstance().getWeighing().getWeight()+"");
}
break;
} }
if (WeighingManager.getInstance().isConnected() == false) { if (WeighingManager.getInstance().isConnected() == false) {
tvResult.setText("当前没有称重设备,试试初始化!"); tvResult.setText("当前没有称重设备,试试初始化!");
......
...@@ -23,13 +23,15 @@ ...@@ -23,13 +23,15 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1"
android:text="称重demo" /> android:text="称重demo"
android:textSize="48sp" />
<Button <Button
android:id="@+id/btnPrint" android:id="@+id/btnPrint"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1"
android:text="打印demo" /> android:text="打印demo"
android:textSize="48sp" />
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -18,6 +18,14 @@ ...@@ -18,6 +18,14 @@
android:textSize="36sp" /> android:textSize="36sp" />
</android.support.v7.widget.ActionMenuView> </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 <TextView
android:id="@+id/tvResult" android:id="@+id/tvResult"
android:layout_width="wrap_content" android:layout_width="wrap_content"
...@@ -47,7 +55,7 @@ ...@@ -47,7 +55,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="读取重量" /> android:text="读取实时重量" />
</TableRow> </TableRow>
<TableRow> <TableRow>
...@@ -60,6 +68,16 @@ ...@@ -60,6 +68,16 @@
android:text="重置零点" /> android:text="重置零点" />
</TableRow> </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> <TableRow>
<EditText <EditText
......
...@@ -36,11 +36,11 @@ public class ChuangjieWeighing extends BaseWeighing { ...@@ -36,11 +36,11 @@ public class ChuangjieWeighing extends BaseWeighing {
serialPortFunction.getWeighingSerialPort("/dev/ttyS4", 9600); serialPortFunction.getWeighingSerialPort("/dev/ttyS4", 9600);
serialPortFunction.startReadWeight(new ReadSerialPort.DataWeight() { serialPortFunction.startReadWeight(new ReadSerialPort.DataWeight() {
@Override @Override
public void weight(String s) { public void weight(String s, boolean isStable) {
Log.i(TAG, "当前重量为:" + s); Log.i(TAG, "当前重量为:" + s);
curWeight = parseKg2g(s.trim()); curWeight = parseKg2g(s.trim());
if (weighingCallback != null && curWeight >= 0) { if (weighingCallback != null && curWeight >= 0) {
weighingCallback.returnWeight(curWeight, true); weighingCallback.returnWeight(curWeight, isStable);
} }
if (curWeight < 0) { if (curWeight < 0) {
//发送置零指令 //发送置零指令
...@@ -59,7 +59,7 @@ public class ChuangjieWeighing extends BaseWeighing { ...@@ -59,7 +59,7 @@ public class ChuangjieWeighing extends BaseWeighing {
@Override @Override
public boolean resetZero() { public boolean resetZero() {
if (serialPortFunction != null) { if (serialPortFunction != null && isResetZeroing == false) {
isResetZeroing = true; isResetZeroing = true;
//发送置零指令,有2s的耗时,内部为线程池异步操作 //发送置零指令,有2s的耗时,内部为线程池异步操作
serialPortFunction.sendEle("410D0A"); serialPortFunction.sendEle("410D0A");
...@@ -79,4 +79,14 @@ public class ChuangjieWeighing extends BaseWeighing { ...@@ -79,4 +79,14 @@ public class ChuangjieWeighing extends BaseWeighing {
} }
return false; return false;
} }
@Override
public boolean release() {
super.release();
weighingCallback = null;
if (serialPortFunction != null) {
serialPortFunction.closeEle();
}
return true;
}
} }
...@@ -165,4 +165,16 @@ public class WeighingManager { ...@@ -165,4 +165,16 @@ public class WeighingManager {
} }
return false; return false;
} }
/**
* 断开与称重台的连接
*
* @return 断开操作的结果
*/
public boolean disConnect() {
if (isConnected()) {
return weighing.release();
}
return true;
}
} }
...@@ -152,14 +152,14 @@ public class ReadSerialPort implements Runnable { ...@@ -152,14 +152,14 @@ public class ReadSerialPort implements Runnable {
System.out.println("在误差范围内" + weightMaxCount); System.out.println("在误差范围内" + weightMaxCount);
weightMaxCount--; weightMaxCount--;
if (weightMaxCount <= 0 && isStabilize) { if (weightMaxCount <= 0) {
nowWeight = tempWeight; nowWeight = tempWeight;
weightMaxCount = 3; weightMaxCount = 3;
if (dataWeight == null) { if (dataWeight == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
System.out.println("要发送的重量 " + MoneyUtil.formatMoney(nowWeight)); System.out.println("要发送的重量 " + MoneyUtil.formatMoney(nowWeight));
dataWeight.weight(MoneyUtil.formatMoney(nowWeight)); dataWeight.weight(MoneyUtil.formatMoney(nowWeight), isStabilize);
} }
} else { } else {
System.out.println("超出误差范围 次数归3"); System.out.println("超出误差范围 次数归3");
...@@ -194,6 +194,6 @@ public class ReadSerialPort implements Runnable { ...@@ -194,6 +194,6 @@ public class ReadSerialPort implements Runnable {
public interface DataWeight { public interface DataWeight {
void weight(String weight); void weight(String weight, boolean isStable);
} }
} }
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