| xqd
@@ -127,7 +127,7 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
|
return 1;
|
|
|
}
|
|
|
// MainViewModel.reportDeviceEvent("queryMagDoor");
|
|
|
- return 0;
|
|
|
+ return 3;
|
|
|
|
|
|
}catch ( Exception e ){
|
|
|
e.printStackTrace();
|
| xqd
@@ -208,7 +208,7 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
|
|
|
|
public void setPower(){
|
|
|
try {
|
|
|
- byte[] setPower = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x0A, 0x02, 0x40, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
|
+ byte[] setPower = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x0A, 0x02, 0x25, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
|
|
|
port.write(setPower, 500);
|
|
|
byte[] response = new byte[12];
|
|
|
port.read(response,500);
|
| xqd
@@ -550,7 +550,7 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
|
|
|
|
/*
|
|
|
* 称重
|
|
|
- * */
|
|
|
+ * *//*
|
|
|
public Integer readWeight(){
|
|
|
try{
|
|
|
// 主机发送 : AA BB 0B 01 55 FF FF FF FF FF CC DD
|
| xqd
@@ -585,10 +585,10 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
- /*校准流程:1.设置分度值 2.去皮 3.零度校准 4.放砝码5.砝码校准*/
|
|
|
- /*
|
|
|
+ *//*校准流程:1.设置分度值 2.去皮 3.零度校准 4.放砝码5.砝码校准*//*
|
|
|
+ *//*
|
|
|
* 设置分度值(几克起跳 精度)
|
|
|
- * */
|
|
|
+ * *//*
|
|
|
public void setScale(){
|
|
|
// 主机发送 : AA BB 0B 01 66 01 61 XX FF FF CC DD XX是分度值 只能是10 20 50 A0 分别是1g 2g 5g 和10g (常规:100kg 误差10g ;200kg误差20g )
|
|
|
// 设备回复: AA BB 0B 01 66 01 61 00 60 FF CC DD
|
| xqd
@@ -608,9 +608,9 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
|
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
+ *//*
|
|
|
* 称重清零去皮
|
|
|
- * */
|
|
|
+ * *//*
|
|
|
public void clearWeight(){
|
|
|
// 主机发送 : AA BB 0B 01 66 01 62 63 FF FF CC DD
|
|
|
// 设备回复: AA BB 0B 01 66 01 62 00 63 FF CC DD
|
| xqd
@@ -629,9 +629,9 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
+ *//*
|
|
|
* 零度校准
|
|
|
- * */
|
|
|
+ * *//*
|
|
|
public void zeroCalibration(){
|
|
|
// 主机发送 : AA BB 0B 01 66 01 64 65 FF FF CC DD
|
|
|
// 设备回复: AA BB 0B 01 66 01 64 00 65 FF CC DD
|
| xqd
@@ -650,9 +650,9 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
+ *//*
|
|
|
* 砝码校准
|
|
|
- * */
|
|
|
+ * *//*
|
|
|
public void weightCalibration(){
|
|
|
try{
|
|
|
// 主机发送 : AA BB 0B 01 66 01 65 XX XX FF CC DD XX是校准的砝码 只能是单位g 防8kg 就是8000g 十六进制就是1F40
|
| xqd
@@ -671,5 +671,124 @@ public class OtherDevice extends BaseDeviceEntity {
|
|
|
Log.i(TAG,"砝码校准失败");
|
|
|
}
|
|
|
}
|
|
|
+*/
|
|
|
+ public synchronized Integer readWeight(){
|
|
|
+ try {
|
|
|
+// SPUtils.getInstance().put("RunningState","0");//1F 03 00 2A 00 01 A6 7C
|
|
|
+ port.write(new byte[]{0x1F, 0x03, 0x00, 0x2A,0x00, 0x01, (byte) 0xA6, 0x7C},150);//称重器读取数值的请求
|
|
|
+// port.write(new byte[]{(byte) 0xAA, (byte) 0xBB,0x0C ,0x01 ,0x55 , (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD},150);//称重器读取数值的请求
|
|
|
+// port.write(new byte[]{(byte) 0xAA, (byte) 0xBB,0x0C ,0x02 ,0x55 , (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD},150);//超声波读取数值的请求
|
|
|
+// Thread.sleep(100);
|
|
|
+ byte[] response = new byte[7];
|
|
|
+ port.read(response,200);
|
|
|
+ Log.i(TAG,"返回称重"+ByteUtil.bytesToString(response));
|
|
|
+
|
|
|
+ if(response[1]==3) {
|
|
|
+ long curTimeMiles = System.currentTimeMillis();
|
|
|
+ int num=0,a=0;
|
|
|
+ while (System.currentTimeMillis()-curTimeMiles<200){
|
|
|
+ port.read(response,10);
|
|
|
+ byte[] weightBytes = new byte[4];
|
|
|
+ weightBytes[2] = response[3];
|
|
|
+ weightBytes[3] = response[4];
|
|
|
+ int weightInt = ByteUtil.bytes2Int(weightBytes);
|
|
|
+// weightInt=weightInt*5*2;
|
|
|
+ num += (weightInt * 5 * 2);
|
|
|
+ a++;
|
|
|
+ Log.i("while","********"+a);
|
|
|
+ }
|
|
|
+ Log.i("num",num+"****"+a+"");
|
|
|
+ byte[] weightBytes = new byte[4];
|
|
|
+ weightBytes[2] = response[3];
|
|
|
+ weightBytes[3] = response[4];
|
|
|
+ int weightInt = ByteUtil.bytes2Int(weightBytes);
|
|
|
+ weightInt=weightInt*5*2;
|
|
|
+ System.out.println("称重读数:"+weightInt);
|
|
|
+ int weightNumber=num/a++;
|
|
|
+ if(weightInt>=327670){
|
|
|
+ weightNumber=0;
|
|
|
+ }
|
|
|
+ return (int) weightNumber;
|
|
|
+ }else {
|
|
|
+ Log.i("返回称重","错误");
|
|
|
+ SPUtils.getInstance().put("RunningState",1);
|
|
|
+ MainViewModel.SendSmsResponse("readWeight称重失灵");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+// int readLen = port.read(response,200);
|
|
|
+// System.out.println("readweight len:"+readLen+" bytes;"+ByteUtil.bytesToString(response));
|
|
|
+
|
|
|
+// return 1;
|
|
|
+//
|
|
|
+ }catch ( Exception e ){
|
|
|
+ e.printStackTrace();
|
|
|
+ SPUtils.getInstance().put("RunningState",1);
|
|
|
+ MainViewModel.SendSmsResponse("readWeight称重设备未检测到");
|
|
|
+
|
|
|
+ Log.e(TAG,"读取称重器读数错误",e);
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /* *
|
|
|
+ * 读数清零
|
|
|
+ */
|
|
|
+ public synchronized void weightClear(){
|
|
|
+ byte[] cleanOrderBytes = new byte[]{0x1F,0x06 ,0x00 ,0x24,0x00 ,0x00, (byte) 0xCA,0x7F};
|
|
|
+ System.out.println("称重器读数清零!!!!!");
|
|
|
+ try {
|
|
|
+ port.write(cleanOrderBytes,150);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 设置分度值
|
|
|
+ * */
|
|
|
+ public synchronized void setScale(){
|
|
|
+ byte[] cleanOrderBytes = new byte[]{0x1F, 0x06 ,0x00 ,0x04 ,0x00 ,0x01 ,0x0A ,0x75};
|
|
|
+ try {
|
|
|
+ port.write(cleanOrderBytes,150);
|
|
|
+ Log.i(TAG,"设置分度值");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* * 空载
|
|
|
+ * */
|
|
|
+ public synchronized void zeroCalibration(){
|
|
|
+ byte[] cleanOrderBytes = new byte[]{0x1F ,0x10 ,0x00 ,0x08 ,0x00 ,0x02 ,0x04 ,0x00 ,0x00 ,0x00 ,0x00 , (byte) 0x92,0x21 };
|
|
|
+ try {
|
|
|
+ port.write(cleanOrderBytes,150);
|
|
|
+ Log.i(TAG,"空载");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* * 量程设定
|
|
|
+ * */
|
|
|
+ public synchronized void weightSet(){
|
|
|
+ byte[] cleanOrderBytes = new byte[]{0x1F ,0x10 ,0x00 ,0x00 ,0x00 ,0x02 ,0x04 , 0x27, 0x10,0x00 ,0x00 , (byte) 0x98, (byte) 0xF6};
|
|
|
+ try {
|
|
|
+ port.write(cleanOrderBytes,150);
|
|
|
|
|
|
+ Log.i(TAG,"l量程设定");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 砝码校准
|
|
|
+ * */
|
|
|
+ public synchronized void weightCalibration(){
|
|
|
+ byte[] cleanOrderBytes = new byte[]{0x1F ,0x10 ,0x00 ,0x10 ,0x00 ,0x02 ,0x04 ,0x27 ,0x10 ,0x00 ,0x00, (byte) 0x96, (byte) 0xE4};
|
|
|
+ try {
|
|
|
+ port.write(cleanOrderBytes,150);
|
|
|
+ Log.i(TAG,"砝码校准kg");
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|