From 894c3212a1fadfbe1738ce969f98faa3f540fad3 Mon Sep 17 00:00:00 2001
From: Nah <15196688790@163.com>
Date: Fri, 10 Nov 2023 11:57:39 +0800
Subject: [PATCH 1/4] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E4=B8=8B=E4=BD=8D?=
=?UTF-8?q?=E6=8E=A7=E5=88=B6=E9=80=BB=E8=BE=91=E3=80=822.=20=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9=E5=AE=9E=E6=97=B6=E7=9B=91=E6=8E=A7=E6=98=BE=E7=A4=BA?=
=?UTF-8?q?=E3=80=823.=20=E4=BF=AE=E6=94=B9=E7=B3=BB=E7=BB=9F=E5=8F=82?=
=?UTF-8?q?=E6=95=B0=E9=85=8D=E7=BD=AE=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/.gitignore | 3 -
.idea/compiler.xml | 6 -
.idea/gradle.xml | 20 ---
.idea/jarRepositories.xml | 15 +-
.idea/misc.xml | 4 -
.../business/ExecuteTheRecipe.java | 43 +++--
.../common/constant/ConfigName.java | 161 ++++++++++++------
.../common/db/mode/BPA_SYSTEMSET.java | 5 +
.../BottomNavigationMainActivity.java | 22 +--
.../home/fragment/from/RealTimeActivity.java | 128 +++-----------
.../from/SystemParameterActivity.java | 107 +++++++++++-
.../res/layout/activity_systemparameter.xml | 62 ++++++-
app/src/main/res/values/strings.xml | 33 +++-
13 files changed, 362 insertions(+), 247 deletions(-)
delete mode 100644 .idea/.gitignore
delete mode 100644 .idea/compiler.xml
delete mode 100644 .idea/gradle.xml
delete mode 100644 .idea/misc.xml
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 26d33521..00000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
deleted file mode 100644
index fb7f4a8a..00000000
--- a/.idea/compiler.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
deleted file mode 100644
index 6e5389ed..00000000
--- a/.idea/gradle.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 9ce8da6d..bbe9e7b3 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -11,6 +11,11 @@
+
+
+
+
+
@@ -26,15 +31,5 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 2e691a23..00000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java
index ab9ca5e7..e390c1a8 100644
--- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java
+++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java
@@ -3,6 +3,7 @@ package com.bonait.bnframework.business;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
+import android.graphics.Bitmap;
import android.media.MediaPlayer;
import android.os.Handler;
import android.os.Looper;
@@ -11,6 +12,7 @@ import android.util.Log;
import androidx.annotation.NonNull;
import com.bonait.bnframework.R;
+import com.bonait.bnframework.business.devicesControl.PLCControl;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.constant.DataBus;
import com.bonait.bnframework.common.db.QueryDB;
@@ -34,6 +36,7 @@ import com.bonait.bnframework.common.helper.MediaPlayerHelper;
import com.bonait.bnframework.common.helper.MessageLog;
import com.bonait.bnframework.common.helper.RTrig;
import com.bonait.bnframework.common.helper.ThreadManager;
+import com.bonait.bnframework.common.modbus.ModbusRTUServer;
import com.bonait.bnframework.common.modbus.ModbusTcpServer;
import com.bonait.bnframework.common.utils.AlertDialogUtils;
import com.bonait.bnframework.common.utils.ToastUtils;
@@ -656,24 +659,30 @@ public class ExecuteTheRecipe {
*/
public static void ReadPLCStatus() {
try {
- if (ConfigName.getInstance().PLC_Address.containsKey("实时状态")) {
- BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get("实时状态");
- if (!plcaddress.address.isEmpty() && ConfigName.getInstance().PlcIsConnect) {
- ModbusTcpServer.get().ReadStatus(plcaddress.address, 4, (data) -> {
- for (int i = 0; i < data.length; i++) {
- byte status=data[i];//0x92
- IoStatus.put(i*8+0, ByteHelper.getBit(status,0)==1);
- IoStatus.put(i*8+1, ByteHelper.getBit(status,1)==1);
- IoStatus.put(i*8+2, ByteHelper.getBit(status,2)==1);
- IoStatus.put(i*8+3, ByteHelper.getBit(status,3)==1);
- IoStatus.put(i*8+4, ByteHelper.getBit(status,4)==1);
- IoStatus.put(i*8+5, ByteHelper.getBit(status,5)==1);
- IoStatus.put(i*8+6, ByteHelper.getBit(status,6)==1);
- IoStatus.put(i*8+7, ByteHelper.getBit(status,7)==1);
- }
- });
- }
+// if (ConfigName.getInstance().PLC_Address.containsKey("实时状态")) {
+// BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get("实时状态");
+// if (!plcaddress.address.isEmpty() && ConfigName.getInstance().PlcIsConnect) {
+// ModbusTcpServer.get().ReadStatus(plcaddress.address, 4, (data) -> {
+// for (int i = 0; i < data.length; i++) {
+// byte status=data[i];//0x92
+// IoStatus.put(i*8+0, ByteHelper.getBit(status,0)==1);
+// IoStatus.put(i*8+1, ByteHelper.getBit(status,1)==1);
+// IoStatus.put(i*8+2, ByteHelper.getBit(status,2)==1);
+// IoStatus.put(i*8+3, ByteHelper.getBit(status,3)==1);
+// IoStatus.put(i*8+4, ByteHelper.getBit(status,4)==1);
+// IoStatus.put(i*8+5, ByteHelper.getBit(status,5)==1);
+// IoStatus.put(i*8+6, ByteHelper.getBit(status,6)==1);
+// IoStatus.put(i*8+7, ByteHelper.getBit(status,7)==1);
+// }
+// });
+// }
+// }
+ //TODO:修改实时状态更新
+ boolean[] result= PLCControl.get().getAllMotorStatus();
+ for (int i=0;i< result.length;i++){
+ IoStatus.put(i,result[i]);
}
+
} catch (Exception ex) {
ToastUtils.error("异常信息:" + ex.getMessage());
} finally {
diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java
index 8561c1e5..d0bd0f71 100644
--- a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java
+++ b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java
@@ -3,41 +3,20 @@ package com.bonait.bnframework.common.constant;
import android.app.Application;
import android.content.Context;
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentManager;
-
-import com.bonait.bnframework.R;
import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS;
-import com.bonait.bnframework.common.db.mode.BPA_SILOS;
import com.bonait.bnframework.common.db.mode.BPA_USER;
import com.bonait.bnframework.common.db.mode.Res_PLCADDRESS;
import com.bonait.bnframework.common.db.res.Res_PLCADDRESS1;
import com.bonait.bnframework.common.db.res.Res_ZDSF;
-import com.bonait.bnframework.common.db.res.StatusMode;
-import com.bonait.bnframework.common.model.AddrType;
import com.bonait.bnframework.common.model.mode.CloudGood;
import com.bonait.bnframework.common.model.mode.DeviceInformation;
import com.bonait.bnframework.common.model.mode.OrganizeMode;
-import com.bonait.bnframework.common.model.mode.ProcessT;
import com.bonait.bnframework.common.model.mode.ResALLData;
import com.bonait.bnframework.common.model.mode.ResSilosModel;
-import com.bonait.bnframework.common.model.mode.VersionSelectionEnum;
-import com.bonait.bnframework.common.utils.ScreenUtils;
import com.bonait.bnframework.modules.home.adapter.FragmentAdapter;
-import com.bonait.bnframework.modules.home.fragment.DingDanfragment;
-import com.bonait.bnframework.modules.home.fragment.GongnengFragment;
-import com.bonait.bnframework.modules.home.fragment.GuanLifragment;
-import com.bonait.bnframework.modules.home.fragment.JiaoYanFragment;
-import com.bonait.bnframework.modules.home.fragment.MakeGoodFragment;
-import com.bonait.bnframework.modules.home.fragment.SheZhifragment;
-import com.bonait.bnframework.modules.mine.fragment.MyFragment;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -178,6 +157,32 @@ public class ConfigName {
public int Post = 502;
//endregion
+//region 串口PLC连接参数
+ /**
+ * 串口是否连接。
+ * */
+ public boolean SerialIsConnect =false;
+
+ /**
+ * 串口波特率
+ */
+ public int SerialBaudRate = 9600;
+ /**
+ * 串口数据位
+ */
+ public int SerialDataBits = 8;
+
+ /**
+ * 串口校验位
+ * */
+ public int SerialParity=0;
+ /**
+ * 串口停止位
+ * */
+ public int SerialStopBits=1;
+
+ //endregion
+
//region URL
//Sass地址
public String SaasAddress = "http://order.test1.com";
@@ -205,50 +210,91 @@ public class ConfigName {
*/
public static ConcurrentHashMap PLC_Address = new ConcurrentHashMap();
+
+ //region 味魔方
/**
- * 奶茶机基础PLC模型
+ * 味魔方基础PLC模型
*/
public List PlcAddress_味魔方 = new ArrayList() {{
- //通道校准
- add(new Res_PLCADDRESS("基础控制", "-------------", 0, 0));
- add(new Res_PLCADDRESS("料仓1", "M5.0", 1, 1));
- add(new Res_PLCADDRESS("料仓2", "M5.0", 1, 1));
- add(new Res_PLCADDRESS("料仓3", "M5.0", 1, 1));
- add(new Res_PLCADDRESS("料仓4", "M5.0", 1, 1));
- add(new Res_PLCADDRESS("料仓5", "M5.0", 1, 1));
- add(new Res_PLCADDRESS("料仓6", "M5.0", 1, 1));
- add(new Res_PLCADDRESS("料仓7", "M5.0", 1, 1));
- add(new Res_PLCADDRESS("料仓8", "M5.0", 1, 1));
- add(new Res_PLCADDRESS("料仓9", "M5.0", 1, 1));
- add(new Res_PLCADDRESS("料仓10", "M5.0", 1, 1));
- add(new Res_PLCADDRESS("料仓11", "M5.0", 1, 1));
- add(new Res_PLCADDRESS("料仓12", "M5.0", 1, 1));
- add(new Res_PLCADDRESS("料仓13", "M5.0", 1, 1));
- add(new Res_PLCADDRESS("料仓14", "M5.0", 1, 1));
+ //region 料仓通道开关
+ add(new Res_PLCADDRESS("通道1开关", "D10", 1, 1));
+ add(new Res_PLCADDRESS("通道2开关", "D11", 1, 1));
+ add(new Res_PLCADDRESS("通道3开关", "D12", 1, 1));
+ add(new Res_PLCADDRESS("通道4开关", "D13", 1, 1));
+ add(new Res_PLCADDRESS("通道5开关", "D14", 1, 1));
+ add(new Res_PLCADDRESS("通道6开关", "D15", 1, 1));
+ add(new Res_PLCADDRESS("通道7开关", "D16", 1, 1));
+ add(new Res_PLCADDRESS("通道8开关", "D17", 1, 1));
+ add(new Res_PLCADDRESS("通道9开关", "D18", 1, 1));
+ add(new Res_PLCADDRESS("通道10开关", "D19", 1, 1));
+ add(new Res_PLCADDRESS("通道11开关", "D20", 1, 1));
+ add(new Res_PLCADDRESS("通道12开关", "D21", 1, 1));
+ add(new Res_PLCADDRESS("通道13开关", "D22", 1, 1));
+ add(new Res_PLCADDRESS("通道14开关", "D23", 1, 1));
+ //endregion
+
+ //region 心跳变量
+ add(new Res_PLCADDRESS("心跳时间", "D0", 0, 1));
+ add(new Res_PLCADDRESS("超时标志", "M0", 1, 1));
+
+ //endregion
+
}};
/**
- * 奶茶机料仓模型
+ * 味魔方料仓模型
*/
public List Silos_味魔方 = new ArrayList() {{
- add(new ResSilosModel("粉料仓",1 , 1 ));
- add(new ResSilosModel("粉料仓",2 , 2 ));
- add(new ResSilosModel("粉料仓",3 , 3 ));
- add(new ResSilosModel("粉料仓",4 , 4 ));
- add(new ResSilosModel("粉料仓",5 , 5 ));
- add(new ResSilosModel("粉料仓",6 , 6 ));
- add(new ResSilosModel("外置仓",7 , 7 ));
- add(new ResSilosModel("外置仓",8 , 8 ));
- add(new ResSilosModel("外置仓",9 , 9 ));
- add(new ResSilosModel("外置仓",10, 10));
- add(new ResSilosModel("外置仓",11, 11));
- add(new ResSilosModel("外置仓",12, 12));
- add(new ResSilosModel("外置仓",13, 13));
- add(new ResSilosModel("外置仓",14, 14));
+ add(new ResSilosModel("外置仓", 1,1));
+ add(new ResSilosModel("液体仓", 2,2));
+ add(new ResSilosModel("液体仓", 3,3));
+ add(new ResSilosModel("外置仓", 4,4));
+
+ add(new ResSilosModel("外置仓", 5,5));
+ add(new ResSilosModel("液体仓", 6,6));
+ add(new ResSilosModel("液体仓", 7,7));
+ add(new ResSilosModel("外置仓", 8,8));
+
+ add(new ResSilosModel("粉料仓", 9,9));
+ add(new ResSilosModel("粉料仓", 10,10));
+ add(new ResSilosModel("粉料仓", 11,11));
+ add(new ResSilosModel("粉料仓", 12,12));
+ add(new ResSilosModel("粉料仓", 13,13));
+ add(new ResSilosModel("粉料仓", 14,14));
}};
+ /**
+ * 单机味魔方料仓手动控制
+ */
+// public List PlcAddress_味魔方_手动=new ArrayList(){{
+//
+// add(new Res_PLCADDRESS1("-------------","","外置仓",0,0));
+// add(new Res_PLCADDRESS1("Y0", "Y0", "通道1开关", 1, 1));
+// add(new Res_PLCADDRESS1("Y3", "Y3", "通道4开关", 1, 1));
+// add(new Res_PLCADDRESS1("Y4", "Y4", "通道5开关", 1, 1));
+// add(new Res_PLCADDRESS1("Y7", "Y7", "通道8开关", 1, 1));
+//
+// add(new Res_PLCADDRESS1("-------------","","液体仓",0,0));
+// add(new Res_PLCADDRESS1("Y1", "Y1", "通道2开关", 1, 1));
+// add(new Res_PLCADDRESS1("Y2", "Y2", "通道3开关", 1, 1));
+// add(new Res_PLCADDRESS1("Y5", "Y5", "通道6开关", 1, 1));
+// add(new Res_PLCADDRESS1("Y6", "Y6", "通道7开关", 1, 1));
+//
+// add(new Res_PLCADDRESS1("-------------","","粉料仓",0,0));
+// add(new Res_PLCADDRESS1("Y10", "Y10", "通道9开关", 1, 1));
+// add(new Res_PLCADDRESS1( "Y11", "Y11","通道10开关", 1, 1));
+// add(new Res_PLCADDRESS1( "Y12", "Y12","通道11开关", 1, 1));
+// add(new Res_PLCADDRESS1( "Y13", "Y13","通道12开关", 1, 1));
+// add(new Res_PLCADDRESS1( "Y14", "Y14","通道13开关", 1, 1));
+// add(new Res_PLCADDRESS1( "Y15", "Y15","通道14开关", 1, 1));
+//
+// }};
+
+ //endregion
+
+ //region 奶茶机
/**
* 奶茶机基础PLC模型
*/
@@ -546,9 +592,9 @@ public class ConfigName {
}};
+//endregion
-
-
+ //region 配料吧台
/**
* 配料吧台基础PLC模型
*/
@@ -851,6 +897,9 @@ public class ConfigName {
}};
+ //endregion
+
+
/**
* 出料算法
*/
@@ -942,7 +991,7 @@ public class ConfigName {
/**
* 选配版本信息
*/
- public String versionSelectionEnum = "奶茶机";
+ public String versionSelectionEnum = "味魔方";
//endregion
//region 主页
diff --git a/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_SYSTEMSET.java b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_SYSTEMSET.java
index 78ed5d73..13b2fa22 100644
--- a/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_SYSTEMSET.java
+++ b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_SYSTEMSET.java
@@ -12,6 +12,11 @@ public class BPA_SYSTEMSET extends ModeBase{
* 2 PLC端口
* 3 门店id
* 4 设备id
+ * 20 串口波特率
+ * 21 串口数据位
+ * 22 串口校验位
+ * 23 串口停止位
+ *
*/
public int type;
//值
diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java
index fe3686c0..d46c574d 100644
--- a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java
+++ b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java
@@ -20,6 +20,7 @@ import com.bonait.bnframework.common.helper.MQTT;
import com.bonait.bnframework.common.helper.MediaPlayerHelper;
import com.bonait.bnframework.common.helper.MessageLog;
import com.bonait.bnframework.common.helper.ThreadManager;
+import com.bonait.bnframework.common.modbus.ModbusRTUServer;
import com.bonait.bnframework.common.modbus.ModbusTcpServer;
import com.bonait.bnframework.common.tabbar.MainNavigateTabBar;
import com.bonait.bnframework.common.utils.NetworkUtils;
@@ -126,27 +127,12 @@ public class BottomNavigationMainActivity extends BaseActivity {
@Override
public void Run() throws InterruptedException {
try {
- if (ConfigName.getInstance().PlcIsConnect) {
- //ping 不通
- boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1);
- if (!status) //ping 不通 连接
- {
- MessageLog.ShowInfo("PLC状态断开,尝试连接...");
- ConfigName.getInstance().PlcIsConnect = false;
- }
- } else {
- boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1);
- if (status) {
- MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!");
- ModbusTcpServer.ConnectPLC();
- } else {
- MessageLog.ShowInfo("PLC状态断开,尝试连接...");
- ConfigName.getInstance().PlcIsConnect = false;
- }
+ if (!ConfigName.getInstance().SerialIsConnect) {
+ ModbusRTUServer.get().ConnectPLC();
}
Thread.sleep(10000);
} catch (Exception e) {
- Log.i("PLC", "PLC重连接失败!" + e.getMessage());
+ Log.i("PLC", "串口重连失败!" + e.getMessage());
}
}
diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/RealTimeActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/RealTimeActivity.java
index 7394d397..9b091d2b 100644
--- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/RealTimeActivity.java
+++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/RealTimeActivity.java
@@ -84,77 +84,27 @@ public class RealTimeActivity extends BaseActivity {
public void Initdata()
{
try{
-
- if (!ConfigName.getInstance().versionSelectionEnum.equals("配料吧台"))
- {
+ if (ConfigName.getInstance().versionSelectionEnum.equals("味魔方")){
DataBus.getInstance().statusModes=new ArrayList<>();
- DataBus.getInstance().statusModes.add(new StatusMode("出料口光电",R.mipmap.gd1,R.mipmap.gd2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("果糖电机(左)",R.mipmap.djcgq1,R.mipmap.djcgq2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("清洗池浮球",R.mipmap.fq1,R.mipmap.fq2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("果糖电机(右)",R.mipmap.djcgq1,R.mipmap.djcgq2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("果糖液位检测(左)",R.mipmap.fq1,R.mipmap.fq2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("果糖液位检测(右)",R.mipmap.fq1,R.mipmap.fq2,false));
-
- //16
- DataBus.getInstance().statusModes.add(new StatusMode("果糖加热(左)",R.mipmap.lcjr1,R.mipmap.lcjr2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("果糖加热(右)",R.mipmap.lcjr1,R.mipmap.lcjr2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("清洗池加热",R.mipmap.lcjr1,R.mipmap.lcjr2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("三色灯(红)",R.mipmap.ssd1,R.mipmap.ssd2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("三色灯(黄)",R.mipmap.ssd1,R.mipmap.ssd2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("三色灯(绿)",R.mipmap.ssd1,R.mipmap.ssd2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道一开关",R.mipmap.rdl1,R.mipmap.rdl2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道二开关",R.mipmap.csf1,R.mipmap.csf2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道三开关",R.mipmap.csf1,R.mipmap.csf2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道四开关",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(一)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(二)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(三)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(四)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("蠕动泵(五)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("隔膜泵(一)",R.mipmap.lxl1,R.mipmap.lxl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("隔膜泵(二)",R.mipmap.lxl1,R.mipmap.lxl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("隔膜泵(三)",R.mipmap.lxl1,R.mipmap.lxl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("隔膜泵(四)",R.mipmap.lxl1,R.mipmap.lxl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("隔膜泵(五)",R.mipmap.lxl1,R.mipmap.lxl2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道五开关",R.mipmap.rdl1,R.mipmap.rdl2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道六开关",R.mipmap.csf1,R.mipmap.csf2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道七开关",R.mipmap.csf1,R.mipmap.csf2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道八开关",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("果糖泵(左)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("果糖泵(右)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("清洗剂泵",R.mipmap.lxl1,R.mipmap.lxl2,false));
-
- DataBus.getInstance().statusModes.add(new StatusMode("排水阀开",R.mipmap.csf1,R.mipmap.csf2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("排水阀关",R.mipmap.csf1,R.mipmap.csf2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("进水阀",R.mipmap.jsf1,R.mipmap.jsf2,false));
- }else
- {
- DataBus.getInstance().statusModes=new ArrayList<>();
- DataBus.getInstance().statusModes.add(new StatusMode("出料口按钮",R.mipmap.gd1,R.mipmap.gd2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("清洗池浮球",R.mipmap.fq1,R.mipmap.fq2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道九开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道十开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道十一开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道十二开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道十三开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false));
+ DataBus.getInstance().statusModes.add(new StatusMode("通道十四开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵正转(一)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵正转(二)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵正转(三)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵正转(四)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵正转(五)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵正转(六)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵反转(一)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵反转(二)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵反转(三)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵反转(四)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵反转(五)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("外置仓泵反转(六)",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("粉料电机(一)",R.mipmap.djcgq1,R.mipmap.djcgq2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("粉料电机(二)",R.mipmap.djcgq1,R.mipmap.djcgq2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("粉料电机(三)",R.mipmap.djcgq1,R.mipmap.djcgq2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("酱油泵",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("醋泵",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("猪油泵",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("牛油泵",R.mipmap.rdl1,R.mipmap.rdl2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("水池进水阀",R.mipmap.jsf1,R.mipmap.jsf2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("水池排水阀",R.mipmap.csf1,R.mipmap.csf2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("猪油管道保温",R.mipmap.lcjr1,R.mipmap.lcjr2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("牛油管道保温",R.mipmap.lcjr1,R.mipmap.lcjr2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("水池加热",R.mipmap.lcjr1,R.mipmap.lcjr2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("三色灯(绿)",R.mipmap.ssd1,R.mipmap.ssd2,false));
- DataBus.getInstance().statusModes.add(new StatusMode("三色灯(红)",R.mipmap.ssd1,R.mipmap.ssd2,false));
}
Run();
@@ -192,47 +142,15 @@ public class RealTimeActivity extends BaseActivity {
@Override
public void run() {
try {
- if (!ConfigName.getInstance().versionSelectionEnum.equals("配料吧台"))
- {
- //64位
- //1.出口 0-15
- SetStatus(0,ExecuteTheRecipe.getConcurrentHash(0));
- SetStatus(1,ExecuteTheRecipe.getConcurrentHash(1));
- SetStatus(2,ExecuteTheRecipe.getConcurrentHash(2));
- SetStatus(3,ExecuteTheRecipe.getConcurrentHash(3));
- SetStatus(4,ExecuteTheRecipe.getConcurrentHash(4));
- SetStatus(5,ExecuteTheRecipe.getConcurrentHash(5));
-
- //3.
- for(int i=0;i<6;i++)//25
- {
- SetStatus(6+i,ExecuteTheRecipe.getConcurrentHash(16+i));
- }
-
- for(int i=0;i<16;i++)//25
- {
- SetStatus(12+i,ExecuteTheRecipe.getConcurrentHash(32+i));
- }
- adapter.refresh();
-
- }else
- {
- //64位
- //1.出口 0-15
- SetStatus(0,ExecuteTheRecipe.getConcurrentHash(0));
- SetStatus(1,ExecuteTheRecipe.getConcurrentHash(1));
- //3.
- for(int i=0;i<10;i++)//25
- {
- SetStatus(2+i,ExecuteTheRecipe.getConcurrentHash(16+i));
- }
-
- for(int i=0;i<16;i++)//25
- {
- SetStatus(12+i,ExecuteTheRecipe.getConcurrentHash(32+i));
- }
- adapter.refresh();
+ String sysName=ConfigName.getInstance().versionSelectionEnum;
+ switch (sysName){
+ case "味魔方":
+ for (int i=0;i<14;i++){
+ SetStatus(i,ExecuteTheRecipe.getConcurrentHash(i));
+ }
+ break;
}
+ adapter.refresh();
} catch (Exception e) {
}
}
diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java
index 6f629363..6d351878 100644
--- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java
+++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java
@@ -51,6 +51,17 @@ public class SystemParameterActivity extends BaseActivity {
EditText edittext3;
@BindView(R.id.edittext4)
EditText edittext4;
+
+ @BindView(R.id.serialBaudRate)
+ Spinner serialBaudRate;
+
+ @BindView(R.id.serialDataBits)
+ Spinner serialDataBits;
+ @BindView(R.id.serialParity)
+ Spinner serialParity;
+ @BindView(R.id.serialStopBits)
+ Spinner serialStopBits;
+
@BindView(R.id.environment)
Spinner environment;
@@ -63,6 +74,11 @@ public class SystemParameterActivity extends BaseActivity {
Map material_map = new LinkedHashMap<>();
Map material_map_vis = new LinkedHashMap<>();
+ Map baudRate_map = new LinkedHashMap<>();
+ Map dataBits_map = new LinkedHashMap<>();
+ Map parity_map = new LinkedHashMap<>();
+ Map stop_Bits = new LinkedHashMap<>();
+
/**
* 系统设置参数
*/
@@ -75,8 +91,13 @@ public class SystemParameterActivity extends BaseActivity {
context=getContext();
initTopBar();
initFragment();
- initData();
- initSelect();
+ try {
+ initData();
+ initSelect();
+ }catch (Exception e){
+
+ }
+
}
private void initTopBar() {
@@ -104,6 +125,20 @@ public class SystemParameterActivity extends BaseActivity {
material_map.put("测试环境", 1);
material_map.put("正式环境", 2);
+ baudRate_map.put("9600",0);
+ baudRate_map.put("19200",1);
+ baudRate_map.put("115200",2);
+
+ dataBits_map.put("7",0);
+ dataBits_map.put("8",1);
+
+ parity_map.put("0",0);
+ parity_map.put("1",1);
+ parity_map.put("2",2);
+
+ stop_Bits.put("1",0);
+ stop_Bits.put("2",1);
+
for (int i = 0; i < ConfigName.getInstance().versionSelectionValues.length; i++) {
material_map_vis.put(ConfigName.getInstance().versionSelectionValues[i], i);
}
@@ -117,6 +152,23 @@ public class SystemParameterActivity extends BaseActivity {
adapter1.setDropDownViewResource(R.layout.spinner_dropdown_item);
versionselection.setAdapter(adapter1);
+ ArrayAdapter adapter2 = new ArrayAdapter<>(context, R.layout.spinner_text_item, new ArrayList<>(baudRate_map.keySet()));
+ adapter2.setDropDownViewResource(R.layout.spinner_dropdown_item);
+ serialBaudRate.setAdapter(adapter2);
+
+ ArrayAdapter adapter3 = new ArrayAdapter<>(context, R.layout.spinner_text_item, new ArrayList<>(dataBits_map.keySet()));
+ adapter3.setDropDownViewResource(R.layout.spinner_dropdown_item);
+ serialDataBits.setAdapter(adapter3);
+
+ ArrayAdapter adapter4 = new ArrayAdapter<>(context, R.layout.spinner_text_item, new ArrayList<>(parity_map.keySet()));
+ adapter4.setDropDownViewResource(R.layout.spinner_dropdown_item);
+ serialParity.setAdapter(adapter4);
+
+ ArrayAdapter adapter5 = new ArrayAdapter<>(context, R.layout.spinner_text_item, new ArrayList<>(stop_Bits.keySet()));
+ adapter5.setDropDownViewResource(R.layout.spinner_dropdown_item);
+ serialStopBits.setAdapter(adapter5);
+
+
bpa_systemsets = QueryDB.GetSystemsetALL();
for (BPA_SYSTEMSET item : bpa_systemsets) {
@@ -145,7 +197,22 @@ public class SystemParameterActivity extends BaseActivity {
ConfigName.getInstance().DeviceAutoKey = item.value;
edittext4.setText(item.value);
break;
-
+ case 20:
+ ConfigName.getInstance().SerialBaudRate = Integer.parseInt(item.value);
+ serialBaudRate.setSelection(baudRate_map.get(item.value));
+ break;
+ case 21:
+ ConfigName.getInstance().SerialDataBits = Integer.parseInt(item.value);
+ serialDataBits.setSelection(dataBits_map.get(item.value));
+ break;
+ case 22:
+ ConfigName.getInstance().SerialParity = Integer.parseInt(item.value);
+ serialParity.setSelection(parity_map.get(item.value));
+ break;
+ case 23:
+ ConfigName.getInstance().SerialStopBits = Integer.parseInt(item.value);
+ serialStopBits.setSelection(stop_Bits.get(item.value));
+ break;
}
}
}
@@ -200,6 +267,9 @@ public class SystemParameterActivity extends BaseActivity {
set_vis.deviceID = ConfigName.getInstance().DeviceId;
set_vis.userID = ConfigName.getInstance().user.userID;
QueryDB.AddSystemset(set_vis);
+
+ saveSerialParam();
+
if (isgb) {
ConfigData.getInstance().RevertPLCProcess();
}
@@ -210,6 +280,37 @@ public class SystemParameterActivity extends BaseActivity {
}
//-------------------------配置viewPager与fragment关联----------------------------//
+ /**保存串口设置参数*/
+ private void saveSerialParam(){
+ BPA_SYSTEMSET set_baudrate = new BPA_SYSTEMSET();
+ set_baudrate.type = 20;
+ set_baudrate.value =serialBaudRate.getSelectedItem().toString();
+ set_baudrate.deviceID = ConfigName.getInstance().DeviceId;
+ set_baudrate.userID = ConfigName.getInstance().user.userID;
+ QueryDB.AddSystemset(set_baudrate);
+
+ BPA_SYSTEMSET set_dataBits = new BPA_SYSTEMSET();
+ set_dataBits.type = 21;
+ set_dataBits.value = serialDataBits.getSelectedItem().toString();
+ set_dataBits.deviceID = ConfigName.getInstance().DeviceId;
+ set_dataBits.userID = ConfigName.getInstance().user.userID;
+ QueryDB.AddSystemset(set_dataBits);
+
+ BPA_SYSTEMSET set_parity = new BPA_SYSTEMSET();
+ set_parity.type = 22;
+ set_parity.value =serialParity.getSelectedItem().toString();
+ set_parity.deviceID = ConfigName.getInstance().DeviceId;
+ set_parity.userID = ConfigName.getInstance().user.userID;
+ QueryDB.AddSystemset(set_parity);
+
+ BPA_SYSTEMSET set_stopBits = new BPA_SYSTEMSET();
+ set_stopBits.type = 23;
+ set_stopBits.value = serialStopBits.getSelectedItem().toString();
+ set_stopBits.deviceID = ConfigName.getInstance().DeviceId;
+ set_stopBits.userID = ConfigName.getInstance().user.userID;
+ QueryDB.AddSystemset(set_stopBits);
+ }
+
@Override
public void onDestroy() {
super.onDestroy();
diff --git a/app/src/main/res/layout/activity_systemparameter.xml b/app/src/main/res/layout/activity_systemparameter.xml
index 1ddd2cb2..7332631f 100644
--- a/app/src/main/res/layout/activity_systemparameter.xml
+++ b/app/src/main/res/layout/activity_systemparameter.xml
@@ -32,7 +32,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
- android:layout_margin="5dp">
+ android:layout_margin="5dp" android:visibility="gone">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
最多选择%d个文件
保存本地%s
-
-
+ 欢迎使用
请输入用户名
+ 请输入密码
+ 记住密码
+ 忘记密码?
+ 登录
+
+
+
+ 功能
+ 料仓管理(绑定物料)
+ 配方管理
+ 日志管理
+ 基础数据管理
+ 实时监控管理
+
+
+
-
-
+
+ 串口波特率:
+ 串口数据位:
+ 串口校验位:
+ 串口停止位:
+ 软件初始化加载中,请稍候...
+ 一键满管
+ 一键加满
+ 一键清洗
+ 一键设置
+ 点击料仓图形设置或控制料仓
+ 料仓物料低于最低值会警示
From 5643a69a8518642b06d2fc7b25409959deab9483 Mon Sep 17 00:00:00 2001
From: Nah <15196688790@163.com>
Date: Wed, 29 Nov 2023 11:35:14 +0800
Subject: [PATCH 2/4] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E4=BB=93=E4=BD=8D?=
=?UTF-8?q?=E7=89=A9=E6=96=99=E6=A0=A1=E5=87=86=E3=80=81=E6=BB=A1=E7=AE=A1?=
=?UTF-8?q?=E6=A0=A1=E5=87=86=E3=80=81=E9=85=B1=E6=96=99=E6=A0=A1=E5=87=86?=
=?UTF-8?q?=E5=8F=8A=E7=9B=B8=E5=BA=94=E6=A8=A1=E6=8B=9F=E5=87=BA=E6=96=99?=
=?UTF-8?q?=E9=80=BB=E8=BE=91=E3=80=822.=20=E4=BF=AE=E6=94=B9=E9=85=8D?=
=?UTF-8?q?=E6=96=B9=E5=87=BA=E6=96=99=E5=8F=8A=E4=BD=99=E9=87=8F=E9=80=BB?=
=?UTF-8?q?=E8=BE=91=E3=80=823.=20=E4=B8=8B=E5=8F=91=E9=85=8D=E6=96=B9?=
=?UTF-8?q?=E6=97=B6=E6=B7=BB=E5=8A=A0=E4=BD=99=E9=87=8F=E6=A3=80=E9=AA=8C?=
=?UTF-8?q?=E9=80=BB=E8=BE=91=E3=80=824.=E4=B8=B2=E5=8F=A3=E6=96=AD?=
=?UTF-8?q?=E7=BA=BF=E9=87=8D=E8=BF=9E=E4=BF=AE=E6=94=B9=E3=80=825.=20?=
=?UTF-8?q?=E7=94=B5=E5=AD=90=E7=A7=A4=E8=AF=BB=E5=8F=96=E9=87=8D=E9=87=8F?=
=?UTF-8?q?=E7=A8=8B=E5=BA=8F=E4=BF=AE=E6=94=B9=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/build.gradle | 3 +
.../business/ExecuteTheRecipe.java | 659 +++++++++---------
.../common/constant/ConfigName.java | 3 +-
.../bnframework/common/db/mode/BPA_SILOS.java | 3 +-
.../BottomNavigationMainActivity.java | 14 +-
.../home/fragment/MakeGoodFragment.java | 91 ++-
.../home/fragment/from/DzcjyActivity.java | 19 +-
.../home/fragment/from/RealTimeActivity.java | 19 +-
.../mode/Silos_item_jiaoyan_fragment.java | 16 +-
.../home/fragment/mode/add_silos_ck.java | 54 +-
.../fragment/mode/fragment_plc_control.java | 31 +-
.../home/fragment/mode/silos_jiaoyan.java | 429 +++++++++---
.../main/res/layout/fragment_make_good.xml | 16 -
app/src/main/res/layout/fragment_she_zhi.xml | 2 +-
.../item/layout/dialog_add_silos_ck.xml | 3 +
.../layout/fragment_silos_item_jiaoyan.xml | 4 +-
.../layout/item/layout/silos_jiaoyan_item.xml | 34 +-
17 files changed, 824 insertions(+), 576 deletions(-)
diff --git a/app/build.gradle b/app/build.gradle
index 7eb01605..5835a8b6 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -157,4 +157,7 @@ dependencies {
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
implementation 'com.contrarywind:Android-PickerView:3.2.6'
+
+ //曲线拟合方程式。
+ implementation 'org.apache.commons:commons-math3:3.6.1'
}
diff --git a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java
index e390c1a8..88bfb4fc 100644
--- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java
+++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java
@@ -1,64 +1,53 @@
package com.bonait.bnframework.business;
-import android.app.Activity;
-import android.content.Context;
-import android.content.ContextWrapper;
-import android.graphics.Bitmap;
-import android.media.MediaPlayer;
import android.os.Handler;
import android.os.Looper;
-import android.util.Log;
import androidx.annotation.NonNull;
-import com.bonait.bnframework.R;
import com.bonait.bnframework.business.devicesControl.PLCControl;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.constant.DataBus;
import com.bonait.bnframework.common.db.QueryDB;
-import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE;
-import com.bonait.bnframework.common.db.mode.BPA_MATERIAL;
import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS;
import com.bonait.bnframework.common.db.mode.BPA_SILOS;
-import com.bonait.bnframework.common.db.res.AlertLogEnum;
import com.bonait.bnframework.common.db.res.ResGoodsMake;
import com.bonait.bnframework.common.db.res.ResGoodsRecipe;
-import com.bonait.bnframework.common.db.res.SilosLsjyMode;
import com.bonait.bnframework.common.db.res.UserLogEnum;
import com.bonait.bnframework.common.helper.ByteHelper;
-import com.bonait.bnframework.common.helper.DataFormat;
import com.bonait.bnframework.common.helper.I.IReadCallBack;
import com.bonait.bnframework.common.helper.I.IRun;
import com.bonait.bnframework.common.helper.I.IRunT;
import com.bonait.bnframework.common.helper.I.IThread;
import com.bonait.bnframework.common.helper.I.IWriteCallBack;
-import com.bonait.bnframework.common.helper.MediaPlayerHelper;
import com.bonait.bnframework.common.helper.MessageLog;
import com.bonait.bnframework.common.helper.RTrig;
import com.bonait.bnframework.common.helper.ThreadManager;
import com.bonait.bnframework.common.modbus.ModbusRTUServer;
import com.bonait.bnframework.common.modbus.ModbusTcpServer;
-import com.bonait.bnframework.common.utils.AlertDialogUtils;
import com.bonait.bnframework.common.utils.ToastUtils;
-import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
-import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import kotlin.UShort;
-
/**
* 执行配方
*/
public class ExecuteTheRecipe {
//region 变量
+
+ /**是否处于自动模式*/
+ public static boolean isAutoMode=true;
+
+ /**是否处于称重模式*/
+ public static boolean isGravimetricMode=false;
+
+ /**PLC连接是否超时,默认超时。*/
+ public static boolean isTimeOut=true;
/**
* 等待超时时间
*/
@@ -207,7 +196,6 @@ public class ExecuteTheRecipe {
//endregion
//region PLC监听线程
- static List names=new ArrayList<>();
public static void Listening() {
ConfigName.getInstance().PLC_Address.clear();
@@ -218,35 +206,25 @@ public class ExecuteTheRecipe {
}
}
- names.clear();
- if (ConfigName.getInstance().versionSelectionEnum.equals("配料吧台")) {
- names.add("水池温度");
- }else if (ConfigName.getInstance().versionSelectionEnum.equals("奶茶机"))
- {
- names.add("水池温度");
- names.add("果糖左温度");
- names.add("果糖右温度");
- }
-
ThreadManager.Get().StartLong("PLC设备数据监听", true, new IThread() {
@Override
public void Run() throws InterruptedException {
try {
- //region 临时屏蔽实时数据
-// for (String item : ConfigName.getInstance().PLC_Address.keySet()) {
-// String key = item;
-// BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(item);
-// if (plcaddress.isread == 1) {
-// Object val = ReadPLC(key);
-// ListeningValue.put(key, val);
-// }
-// }
- //endregion
+
+ isTimeOut=PLCControl.get().isTimeOut("超时标志");
+
+ if (isTimeOut /*&& ConfigName.getInstance().SerialIsConnect*/){
+ ConfigName.getInstance().SerialIsConnect=false;
+ Thread.sleep(5000);
+ if (!PLCControl.get().isTimeOut("超时标志")){
+ timeOutHandler();
+ }
+ }
if(!IsMakeGood)
{
//1.读取扫码数据
- ReadCode();
+ //ReadCode();
//2.读取实时状态
ReadPLCStatus();
}
@@ -266,27 +244,10 @@ public class ExecuteTheRecipe {
@Override
public void Run() throws InterruptedException {
try {
- if(!IsMakeGood)
- {
- Object zl= ExecuteTheRecipe.ReadPLC("称当前重量");
- OutletWeigh=zl==null?0:(int)zl;
- Object bz= ExecuteTheRecipe.ReadPLC("出料口检测");
- IsCup=bz==null?false:(boolean) bz;
- Object obj1= ExecuteTheRecipe.ReadPLC("水池温度");
- WaterTemp=obj1==null?0:(int)obj1;
-
- if (ConfigName.getInstance().versionSelectionEnum.equals("奶茶机"))
- {
- Object obj2= ExecuteTheRecipe.ReadPLC("果糖左温度");
- Object obj3= ExecuteTheRecipe.ReadPLC("果糖右温度");
- SugarTempLeft=obj2==null?0:(int)obj2;
- SugarTempRight=obj3==null?0:(int)obj3;
-
- Object obj21= ExecuteTheRecipe.ReadPLC("果糖左温度设置");
- Object obj31= ExecuteTheRecipe.ReadPLC("果糖右温度设置");
- SugarTempLeft_SZ=obj21==null?0:(int)obj21;
- SugarTempRight_SZ=obj31==null?0:(int)obj31;
- }
+// if(!IsMakeGood)
+// {
+ OutletWeigh=PLCControl.get().getCurrentWeight();
+ PLCControl.get().clrHeartbeat("心跳时间",null);
if (WeighComplete!=null)
{
@@ -296,53 +257,33 @@ public class ExecuteTheRecipe {
{
TempComplete.Run();
}
- }
- } catch (Exception ex) {
- ToastUtils.error("异常信息:" + ex.getMessage());
- }
- Thread.sleep(200);
- }
- @Override
- public void RunComplete() throws InterruptedException {
-
- }
- });
-
- ThreadManager.Get().StartLong("PLC设备-自动加热补水", true, new IThread() {
- @Override
- public void Run() throws InterruptedException {
- try {
- if(!IsMakeGood)
- {
- AutoJR();
- }
+// }
} catch (Exception ex) {
ToastUtils.error("异常信息:" + ex.getMessage());
}
- Thread.sleep(5000);
+ Thread.sleep(300);
}
-
@Override
public void RunComplete() throws InterruptedException {
}
});
- ThreadManager.Get().StartLong("PLC设备数据监听-信号检测", true, new IThread() {
- @Override
- public void Run() throws InterruptedException {
- try {
- ChargeSignal();
- } catch (Exception ex) {
- ToastUtils.error("异常信息:" + ex.getMessage());
- }
- Thread.sleep(100);
- }
- @Override
- public void RunComplete() throws InterruptedException {
-
- }
- });
+// ThreadManager.Get().StartLong("PLC设备数据监听-信号检测", true, new IThread() {
+// @Override
+// public void Run() throws InterruptedException {
+// try {
+// ChargeSignal();
+// } catch (Exception ex) {
+// ToastUtils.error("异常信息:" + ex.getMessage());
+// }
+// Thread.sleep(100);
+// }
+// @Override
+// public void RunComplete() throws InterruptedException {
+//
+// }
+// });
ThreadManager.Get().StartLong("商品制作线程", true, new IThread() {
@Override
@@ -350,7 +291,6 @@ public class ExecuteTheRecipe {
try {
if(IsMakeGood && GoodMake!=null)
{
-
ArrayList recipes= GoodMake.recipes;
//region 根据物料配方排序Sort步骤分组
@@ -362,9 +302,13 @@ public class ExecuteTheRecipe {
}
//endregion
+ //计算系数,称重模式下配方默认是按1kg配料的,所以需要计算系数。
+ double ratio=OutletWeigh/10.0/1000;
+
+ PLCControl.get().Speak("配料开始",null);
int count = 0;
for (LinkedHashMap.Entry> entry : rgrs.entrySet()) {
- WritePLC("配料完成", false,null);
+ //WritePLC("配料完成", false,null);
final Integer key = entry.getKey();
@@ -377,7 +321,11 @@ public class ExecuteTheRecipe {
}
count=2;
DataBus.getInstance().UpdateGoodsMake(GoodMake.subOrder.id, "步骤【" + key + "】准备下发物料:" + RecipesNames, count, key, false);
+ final boolean[] stepCompleted = {false};
+
+ final boolean[] siloComplted=new boolean[goodsRecipes.size()];
+ //region 给每个料仓下发指令
for (int m = 0; m < goodsRecipes.size(); m++) {
ResGoodsRecipe recipe = goodsRecipes.get(m);
final String message = "[" + GoodMake.good.name + "]步骤【" + key + "】下发【" + recipe.materialName + "】";
@@ -390,54 +338,109 @@ public class ExecuteTheRecipe {
silos = item;
}
if (silos == null) {
- MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "下发失败!物料没有管理料仓!");
+ MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "下发失败!物料没有关联料仓!");
} else {
- //MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "准备下发【" + silos.num + "】号料仓PLC控制命令,需求量:=" + recipe.value);
- int _val = (int)Math.round((Double.parseDouble(recipe.value) * 10));
- WritePLC("需求值" + silos.num, (short) _val, null);
+ MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, message + "准备下发【" + silos.num + "】号料仓PLC控制命令,需求量:=" + recipe.value);
+
+ double silo_adjustTime=Double.parseDouble(silos.jTime);
+ double silo_adjustValue=Double.parseDouble(silos.jValue);
+ double demand_value=Double.parseDouble(recipe.value);
+
+ int delayTime=0;
+ if (silos.name.equals("外置仓")){
+ delayTime=(int)(getDelayTimeByLCID(silos.id,demand_value)*1000);
+ }else{
+ //打开时间= 校准时间/校准重量*需求量 .方法单位是ms,需要*1000.
+ delayTime=(int)(silo_adjustTime/silo_adjustValue*demand_value*1000);
+ }
+ //如果在称重模式下,要计算比例,否则直接出料。
+ if (isGravimetricMode){
+ delayTime=(int)(delayTime*ratio);
+ }
+ //保存当前值,传入OnSuccess里。
+ final int[] index={0};
+ index[0]=m;
+ final String siloId= silos.id;
+ //出完料后的余量。
+ final int afterMargin=silos.silosmargin-(int)demand_value;
+ PLCControl.get().openMotorAndClose(silos.num, delayTime, new IWriteCallBack() {
+ @Override
+ public void onSuccess() {
+ ToastUtils.success("[" + GoodMake.good.name + "] 配料完成!");
+
+ QueryDB.UpdateYL(siloId, afterMargin );
+ siloComplted[index[0]]=true;
+ }
+
+ @Override
+ public void onFailure(String ErrorMsg) {
+ ToastUtils.error("[" + GoodMake.good.name + "] 配料失败!");
+ }
+ });
+ MessageLog.ShowInfo("[" + GoodMake.good.name + "]步骤【" + key + "】开始配料成功!");
}
}
+ //endregion
+
MessageLog.ShowInfo(RecipesNames + "下发成功!");
//endregion
+ //region 旧代码
//等待配料完成,一直等待
- final boolean[] IsComplete = {false};
- OnChargeMixtureCompleteNotify = new IRun() {
- @Override
- public void Run() {
- IsComplete[0] = true;
- MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + GoodMake.good.name + "]步骤【" + key + "】配料完成!");
- }
- };
+//
+// OnChargeMixtureCompleteNotify = new IRun() {
+// @Override
+// public void Run() {
+// IsComplete[0] = true;
+// MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "[" + GoodMake.good.name + "]步骤【" + key + "】配料完成!");
+// }
+// };
//启动配料
- WritePLC("配料启动",true,new IWriteCallBack() {
- @Override
- public void onSuccess() {
- MessageLog.ShowInfo("[" + GoodMake.good.name + "]步骤【" + key + "】启动配料成功!");
- }
-
- @Override
- public void onFailure(String ErrorMsg) {
- MessageLog.ShowInfo("[" + GoodMake.good.name + "]步骤【" + key + "】启动配料失败!");
- MessageLog.ShowAlertMessage(AlertLogEnum.异常订单未制作日志, "[" + GoodMake.good.name + "]步骤【" + key + "】启动配料失败!");
- }
- });
-
+// WritePLC("配料启动",true,new IWriteCallBack() {
+// @Override
+// public void onSuccess() {
+// MessageLog.ShowInfo("[" + GoodMake.good.name + "]步骤【" + key + "】启动配料成功!");
+// }
+//
+// @Override
+// public void onFailure(String ErrorMsg) {
+// MessageLog.ShowInfo("[" + GoodMake.good.name + "]步骤【" + key + "】启动配料失败!");
+// MessageLog.ShowAlertMessage(AlertLogEnum.异常订单未制作日志, "[" + GoodMake.good.name + "]步骤【" + key + "】启动配料失败!");
+// }
+// });
+//endregion
+
+ //一分钟未完成 强制认为完成了。
long a = System.currentTimeMillis();
- while (!IsComplete[0]) {
+ while (!stepCompleted[0]) {
if ((System.currentTimeMillis() - a) > 1000 * 60) {
break;
}
- Thread.sleep(100);//10 *6
+
+ stepCompleted[0]=true;
+ for (int i=0;i {
- for (int i = 0; i < length; i++) {
- ReturnsVariable[i] = val[i];
- }
- });
- } else if (plcaddress.address.toUpperCase().startsWith("M"))//bool
- {
- ModbusTcpServer.get().ReadBool(plcaddress.address, length, val -> {
- for (int i = 0; i < length; i++) {
- ReturnsVariable[i] = val[i];
- }
- });
- } else if (plcaddress.address.toUpperCase().startsWith("VW"))//short
- {
- ModbusTcpServer.get().ReadShort(plcaddress.address, length, val -> {
- for (int i = 0; i < length; i++) {
- ReturnsVariable[i] = val[i];
- }
- });
- } else if (plcaddress.address.toUpperCase().startsWith("VR"))//float
- {
- ModbusTcpServer.get().ReadFloat(plcaddress.address, length, val -> {
- for (int i = 0; i < length; i++) {
- ReturnsVariable[i] = val[i];
- }
- });
- }
- }
- }
- } catch (Exception ex) {
- ToastUtils.error("异常信息:" + ex.getMessage());
- } finally {
- return ReturnsVariable;
- }
- }
-
/**
* 根据地址写 PLC数据 bool
*
@@ -659,25 +676,6 @@ public class ExecuteTheRecipe {
*/
public static void ReadPLCStatus() {
try {
-// if (ConfigName.getInstance().PLC_Address.containsKey("实时状态")) {
-// BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get("实时状态");
-// if (!plcaddress.address.isEmpty() && ConfigName.getInstance().PlcIsConnect) {
-// ModbusTcpServer.get().ReadStatus(plcaddress.address, 4, (data) -> {
-// for (int i = 0; i < data.length; i++) {
-// byte status=data[i];//0x92
-// IoStatus.put(i*8+0, ByteHelper.getBit(status,0)==1);
-// IoStatus.put(i*8+1, ByteHelper.getBit(status,1)==1);
-// IoStatus.put(i*8+2, ByteHelper.getBit(status,2)==1);
-// IoStatus.put(i*8+3, ByteHelper.getBit(status,3)==1);
-// IoStatus.put(i*8+4, ByteHelper.getBit(status,4)==1);
-// IoStatus.put(i*8+5, ByteHelper.getBit(status,5)==1);
-// IoStatus.put(i*8+6, ByteHelper.getBit(status,6)==1);
-// IoStatus.put(i*8+7, ByteHelper.getBit(status,7)==1);
-// }
-// });
-// }
-// }
- //TODO:修改实时状态更新
boolean[] result= PLCControl.get().getAllMotorStatus();
for (int i=0;i< result.length;i++){
IoStatus.put(i,result[i]);
@@ -689,43 +687,6 @@ public class ExecuteTheRecipe {
}
}
- /**
- * 读取扫码信息
- */
- public static void ReadCode() {
- try {
- if (ConfigName.getInstance().PLC_Address.containsKey("扫码数据")) {
- BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get("扫码数据");
- if (!plcaddress.address.isEmpty() && ConfigName.getInstance().PlcIsConnect) {
- ModbusTcpServer.get().ReadString(plcaddress.address, 40, (data) -> {
-
- if(!data.isEmpty() && !Code.equals(data) && OnScanTheCodeInformationT != null)
- {
- Log.d("信息", "扫码数据: "+data);
- OnScanTheCodeInformationT.Run(data);
- ModbusTcpServer.get().WriteString(plcaddress.address, 40, null);
- }
-
- //记录上一次读取PLC 扫码数据
- Code = data;
- });
- }
- }
-
-// if (ConfigName.getInstance().PLC_Address.containsKey("配料次数")) {
-// BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get("配料次数");
-// if (!plcaddress.address.isEmpty() && ConfigName.getInstance().PlcIsConnect) {
-// ModbusTcpServer.get().ReadInt(plcaddress.address, 1, (data) -> {
-// MakeGoodCount=data[0] ;
-// });
-// }
-// }
- } catch (Exception ex) {
- ToastUtils.error("异常信息:" + ex.getMessage());
- } finally {
- }
- }
-
/**
* 信号检测
*/
@@ -753,80 +714,6 @@ public class ExecuteTheRecipe {
}
}
- /**
- * 自动加热
- */
- public static void AutoJR() {
- try {
-
- if(ConfigName.getInstance().PlcIsConnect)
- {
-
- for (String item:names)
- {
- boolean isopen=false;
- if(item.equals("水池温度"))
- {
- isopen=ConfigName.getInstance().AutomaticHeating;
- }else if(item.equals("果糖左温度"))
- {
- isopen=ConfigName.getInstance().GT1_AutomaticHeating;
- }else if(item.equals("果糖右温度"))
- {
- isopen=ConfigName.getInstance().GT2_AutomaticHeating;
- }
-
- if(isopen)
- {
- Object sc= ReadPLC(item);
- Object scsz= ReadPLC(item+"设置");
-
- int sx_temp=sc==null?0:(int)sc;//水箱温度
- int sx_temp_sz=scsz==null?0:(int)scsz;//水箱温度设置值
- if(sx_temp_sz>0)
- {
- if(sx_temp>=sx_temp_sz)
- {
- WritePLC(item+"加热",false,null);
- }else
- {
- WritePLC(item+"加热",true,null);
- }
- }
- }
- }
-
- //自动补水
- if(ConfigName.getInstance().AutomaticWaterRefill)
- {
- Object yw= ReadPLC("水池液位检测");
- boolean isopen=yw==null?false:(boolean) yw;
- if(!isopen)
- {
- WritePLC("水池进水阀",true,null);
- }else
- {
- if(yw!=null )
- {
- Object jsf= ReadPLC("水池进水阀");
- if(jsf!=null && (boolean)jsf)
- {
- new Handler().postDelayed(new Runnable() {
- @Override
- public void run() {
- WritePLC("水池进水阀",false,null);
- }
- }, (int)Math.round((Double.parseDouble(ConfigName.getInstance().AutomaticWaterRefillTime) * 1000)));
- }
- }
- }
- }
- }
- } catch (Exception ex) {
- ToastUtils.error("异常信息:" + ex.getMessage());
- } finally {
- }
- }
/**
* 完成信号监听
@@ -856,26 +743,15 @@ public class ExecuteTheRecipe {
*/
public static boolean StartJiaoYanMode()
{
+
final boolean[] issucess1 = {false};
final boolean[] issucess2 = {false};
final boolean[] issucess3 = {false};
-
- //写校准模式
- WritePLC("砝码校准模式", true, new IWriteCallBack() {
- @Override
- public void onSuccess() {
- issucess1[0] =true;
- }
-
- @Override
- public void onFailure(String ErrorMsg) {
-
- }
- });
- WritePLC("关闭写保护", true, new IWriteCallBack() {
+ // 1. 关闭写保护。
+ PLCControl.get().closeWriteProtect(new IWriteCallBack() {
@Override
public void onSuccess() {
- issucess2[0] =true;
+ issucess1[0]=true;
}
@Override
public void onFailure(String ErrorMsg) {
@@ -883,17 +759,59 @@ public class ExecuteTheRecipe {
}
});
- WritePLC("零点校准", true, new IWriteCallBack() {
+ // 2.称台清零。
+ PLCControl.get().zeroScale(new IWriteCallBack() {
@Override
public void onSuccess() {
- issucess3[0] =true;
+ issucess2[0]=true;
}
+
@Override
public void onFailure(String ErrorMsg) {
}
});
- return issucess1[0] && issucess2[0]&& issucess3[0];
+ return issucess1[0] && issucess2[0];
+//region 旧代码。
+// final boolean[] issucess1 = {false};
+// final boolean[] issucess2 = {false};
+// final boolean[] issucess3 = {false};
+//
+// //写校准模式
+// WritePLC("砝码校准模式", true, new IWriteCallBack() {
+// @Override
+// public void onSuccess() {
+// issucess1[0] =true;
+// }
+//
+// @Override
+// public void onFailure(String ErrorMsg) {
+//
+// }
+// });
+// WritePLC("关闭写保护", true, new IWriteCallBack() {
+// @Override
+// public void onSuccess() {
+// issucess2[0] =true;
+// }
+// @Override
+// public void onFailure(String ErrorMsg) {
+//
+// }
+// });
+//
+// WritePLC("零点校准", true, new IWriteCallBack() {
+// @Override
+// public void onSuccess() {
+// issucess3[0] =true;
+// }
+// @Override
+// public void onFailure(String ErrorMsg) {
+//
+// }
+// });
+// return issucess1[0] && issucess2[0]&& issucess3[0];
+ // endregion
}
/**
@@ -901,14 +819,42 @@ public class ExecuteTheRecipe {
*/
public static boolean StopJiaoYanMode()
{
- final boolean[] issucess1 = {false};
- final boolean[] issucess2 = {false};
+ //region 旧代码
+// final boolean[] issucess1 = {false};
+// final boolean[] issucess2 = {false};
+//
+// //写校准模式
+// WritePLC("砝码校准模式", false, new IWriteCallBack() {
+// @Override
+// public void onSuccess() {
+// issucess1[0] =true;
+// }
+//
+// @Override
+// public void onFailure(String ErrorMsg) {
+//
+// }
+// });
+// WritePLC("打开写保护", true, new IWriteCallBack() {
+// @Override
+// public void onSuccess() {
+// issucess2[0] =true;
+// }
+// @Override
+// public void onFailure(String ErrorMsg) {
+//
+// }
+// });
+
+ //return issucess1[0] && issucess2[0];
+//endregion
- //写校准模式
- WritePLC("砝码校准模式", false, new IWriteCallBack() {
+ final boolean[] issucess1 = {false};
+ // 1. 打开写保护
+ PLCControl.get().openWriteProtect(new IWriteCallBack() {
@Override
public void onSuccess() {
- issucess1[0] =true;
+ issucess1[0]=true;
}
@Override
@@ -916,17 +862,46 @@ public class ExecuteTheRecipe {
}
});
- WritePLC("打开写保护", true, new IWriteCallBack() {
- @Override
- public void onSuccess() {
- issucess2[0] =true;
- }
- @Override
- public void onFailure(String ErrorMsg) {
+ return issucess1[0];
+ }
+ //endregion
- }
- });
- return issucess1[0] && issucess2[0];
+ //region 外置仓相关
+
+ /**根据外置仓的仓位ID获取对应克重的延时时间*/
+ public static double getDelayTimeByLCID(String lcID,double weight){
+
+ if (lcID.isEmpty() || weight<=0){
+ return 0;
+ }
+ BPA_SILOS silo= QueryDB.GetSilosID(lcID);
+ if (silo ==null || silo.maxweight==null || silo.minweight==null || silo.bcsfValue==null){
+ return 0;
+ }
+ final double maxWeight=Double.parseDouble(silo.maxweight);
+ final double minWeight=Double.parseDouble(silo.minweight);
+ final double[] coefficients=stringToDoubleArray(silo.bcsfValue);
+ if (weight<=minWeight || weight>=maxWeight){
+ return 0;
+ }
+
+ double delayTime=0.0;
+ final int degree=coefficients.length-1;
+ for (int i=0;i demandMap=new HashMap<>();
+ //物料ID和物料名称对照表。
+ HashMap materialNameMap=new HashMap<>();
+ for (ResGoodsRecipe material:makegood.recipes) {
+ //获取每个物料对应的料仓余量。
+ double demand_value=Double.parseDouble(material.value);
+ String materialName=material.materialName;
+ String materialID=material.materialID;
+ if (!demandMap.containsKey(materialID)){
+ demandMap.put(materialID,0.0);
+ }
+ double currentValue=demandMap.get(materialID);
+ demandMap.put(materialID,currentValue+demand_value);
+ materialNameMap.put(materialID,materialName);
+ }
+ for (Map.Entry entry :demandMap.entrySet()){
+ BPA_SILOS silos = null;
+ List siloslist = QueryDB.GetSolisByMaterialID(entry.getKey());
+ String materialName=materialNameMap.get(entry.getKey());
+ for (BPA_SILOS item : siloslist) {
+ if(silos==null)
+ silos = item;
+ }
+ if (silos == null) {
+ MessageLog.ShowUserMessage(UserLogEnum.订单处理日志, "下发失败!物料["+materialName+"]没有关联料仓!");
+ return;
+ }else{
+ if (silos.silosmargin materials = new ArrayList<>();
@@ -165,6 +158,7 @@ public class add_silos_ck extends LinearLayout {
boolean ismanguan = false;
+ @SuppressLint("ClickableViewAccessibility")
private void initEvent() {
buchongyuanliao.setOnClickListener(new OnClickListener() {
@Override
@@ -223,13 +217,16 @@ public class add_silos_ck extends LinearLayout {
if (ismanguan == false) {
ismanguan = true;
StartTime();
- ExecuteTheRecipe.WritePLC("手自切换", false, null);
+ //ExecuteTheRecipe.WritePLC("手自切换", false, null);
int time = lcMode.bValue <= 0 ? 10 : lcMode.bValue;//默认10秒
- ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, true, null);
+ //ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, true, null);
+ PLCControl.get().openMotor(lcMode.num,null);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
- ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, false, null);
+ //ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, false, null);
+
+ PLCControl.get().closeMotor(lcMode.num,null);
ToastUtils.info("满管成功!!!");
ismanguan = false;
StopTime();
@@ -345,19 +342,22 @@ public class add_silos_ck extends LinearLayout {
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Log.e("鼠标", "按下: ");
- ExecuteTheRecipe.WritePLC("手自切换", false, new IWriteCallBack() {
- @Override
- public void onSuccess() {
- ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, true, null);
- }
-
- @Override
- public void onFailure(String ErrorMsg) {
- }
- });
+// ExecuteTheRecipe.WritePLC("手自切换", false, new IWriteCallBack() {
+// @Override
+// public void onSuccess() {
+// ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, true, null);
+// }
+//
+// @Override
+// public void onFailure(String ErrorMsg) {
+// }
+// });
+ ExecuteTheRecipe.isAutoMode=false;
+ PLCControl.get().openMotor(lcMode.num,null);
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
Log.e("鼠标", "松开: ");
- ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, false, null);
+ //ExecuteTheRecipe.WritePLC("手动控制" + lcMode.num, false, null);
+ PLCControl.get().closeMotor(lcMode.num,null);
}
return false;
}
@@ -437,6 +437,7 @@ public class add_silos_ck extends LinearLayout {
*/
public void StartTime() {
jishiqi.setVisibility(View.VISIBLE);
+ menu_silo.setVisibility(View.GONE);
runtime.setBase(SystemClock.elapsedRealtime());
runtime.start();
@@ -447,6 +448,9 @@ public class add_silos_ck extends LinearLayout {
*/
public int StopTime() {
jishiqi.setVisibility(View.GONE);
+ menu_silo.setVisibility(View.VISIBLE);
+
+
long elapsedMillis = SystemClock.elapsedRealtime() - runtime.getBase();
runtime.stop();
diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc_control.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc_control.java
index ae530db0..8dc8ae6b 100644
--- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc_control.java
+++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc_control.java
@@ -188,7 +188,7 @@ public class fragment_plc_control extends LinearLayout {
@Override
public void onCheckedChanged(SwitchButton view, boolean isChecked) {
boolean ischick= control_switch.isChecked();
- ExecuteTheRecipe.WritePLC(model.name,ischick,null);
+ ExecuteTheRecipe.WritePLCForRTU(model.name,ischick,null);
ToastUtils.info("写入地址:"+model.address+"成功!状态:"+(ischick?"打开":"关闭"));
}
});
@@ -223,19 +223,22 @@ public class fragment_plc_control extends LinearLayout {
return;
}
- if(model.address.startsWith("VW"))
- {
- Short val=Short.parseShort(text);
- ExecuteTheRecipe.WritePLC(model.name,val,null);
- }else if(model.address.startsWith("VD"))
- {
- int val=Integer.parseInt(text);
- ExecuteTheRecipe.WritePLC(model.name,val,null);
- }else
- {
- Short val=Short.parseShort(text);
- ExecuteTheRecipe.WritePLC(model.name,val,null);
- }
+// if(model.address.startsWith("VW"))
+// {
+// Short val=Short.parseShort(text);
+// ExecuteTheRecipe.WritePLC(model.name,val,null);
+// }else if(model.address.startsWith("VD"))
+// {
+// int val=Integer.parseInt(text);
+// ExecuteTheRecipe.WritePLC(model.name,val,null);
+// }else
+// {
+// Short val=Short.parseShort(text);
+// ExecuteTheRecipe.WritePLC(model.name,val,null);
+// }
+
+ ExecuteTheRecipe.WritePLCForRTU(model.name,text,null);
+ //TODO:修改手动写入操作代码。
ToastUtils.info("写入地址:"+model.address+"成功!");
break;
diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java
index 54e36bf1..e352f263 100644
--- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java
+++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java
@@ -2,55 +2,48 @@ package com.bonait.bnframework.modules.home.fragment.mode;
import android.app.Activity;
import android.content.Context;
-import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Handler;
+import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
-import android.view.MotionEvent;
import android.view.View;
-import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.EditText;
-import android.widget.ImageView;
import android.widget.LinearLayout;
-import android.widget.RelativeLayout;
-import android.widget.Spinner;
import android.widget.TextView;
-import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import com.bonait.bnframework.R;
import com.bonait.bnframework.business.ExecuteTheRecipe;
+import com.bonait.bnframework.business.devicesControl.PLCControl;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.db.QueryDB;
-import com.bonait.bnframework.common.db.mode.BPA_MATERIAL;
import com.bonait.bnframework.common.db.mode.BPA_SILOS;
-import com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL;
+import com.bonait.bnframework.common.db.res.UserLogEnum;
import com.bonait.bnframework.common.db.res.lcMode;
import com.bonait.bnframework.common.helper.I.IRun;
import com.bonait.bnframework.common.helper.I.IWriteCallBack;
import com.bonait.bnframework.common.helper.I.MyClickListener;
-import com.bonait.bnframework.common.model.mode.ResMenuLeft;
+import com.bonait.bnframework.common.helper.MessageLog;
+import com.bonait.bnframework.common.utils.AlertDialogUtils;
import com.bonait.bnframework.common.utils.ToastUtils;
-import com.qmuiteam.qmui.arch.QMUIFragment;
-import com.qmuiteam.qmui.arch.QMUIFragmentPagerAdapter;
-import com.qmuiteam.qmui.widget.QMUIViewPager;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
-import com.qmuiteam.qmui.widget.tab.QMUIBasicTabSegment;
-import com.qmuiteam.qmui.widget.tab.QMUITabSegment;
+import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;
import com.suke.widget.SwitchButton;
-import java.math.BigDecimal;
-import java.text.DecimalFormat;
+import org.apache.commons.math3.fitting.PolynomialCurveFitter;
+import org.apache.commons.math3.fitting.WeightedObservedPoints;
+
import java.util.ArrayList;
-import java.util.List;
+import java.util.Arrays;
+import java.util.Map;
import butterknife.BindView;
import butterknife.ButterKnife;
@@ -119,12 +112,15 @@ public class silos_jiaoyan extends LinearLayout {
//endregion
//region 物料校准变量
+ /**物料校准--校准时间*/
@BindView(R.id.wljz1)
EditText wljz1;
+ /**物料校准--反转时间*/
@BindView(R.id.wljz2)
EditText wljz2;
+ /**物料校准--校准重量*/
@BindView(R.id.wljz3)
EditText wljz3;
@@ -146,6 +142,26 @@ public class silos_jiaoyan extends LinearLayout {
EditText bcjz_clsj;
//endregion
+ //region 酱料校准的控件
+ /**酱料校准下限*/
+ @BindView(R.id.txt_jljz_lowLimit)
+ EditText txt_jljz_lowLimit;
+
+
+ /**酱料校准上限*/
+ @BindView(R.id.txt_jljz_highLimit)
+ EditText txt_jljz_highLimit;
+
+
+ /**酱料校准频率*/
+ @BindView(R.id.txt_jljz_adjFreq)
+ EditText txt_jljz_adjFreq;
+
+ /**开始酱料校准*/
+ @BindView(R.id.btn_jljz_startAdj)
+ Button btn_jljz_startAdj;
+ //endregion
+
public silos_jiaoyan(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
root= LayoutInflater.from(context).inflate(R.layout.silos_jiaoyan_item, this);
@@ -159,6 +175,9 @@ public class silos_jiaoyan extends LinearLayout {
TextView text_wlkz;
@BindView(R.id.text_mgkz)
TextView text_mgkz;
+
+ @BindView(R.id.text_mgkz1)
+ TextView text_mgkz1;
@BindView(R.id.text_jlkz)
TextView text_jlkz;
@BindView(R.id.text_bckz)
@@ -176,12 +195,19 @@ public class silos_jiaoyan extends LinearLayout {
title_bc.setText(lcMode.num+" "+lcMode.materialName);
if(lcMode.name.equals("外置仓"))
{
+ text_wlkz.setVisibility(View.GONE);
+ text_mgkz1.setVisibility(View.GONE);
+
text_jlkz.setVisibility(View.VISIBLE);
- text_bckz.setVisibility(View.VISIBLE);
+ text_bckz.setVisibility(View.GONE);
text_jlkz1.setVisibility(View.VISIBLE);
- text_bckz1.setVisibility(View.VISIBLE);
+ text_bckz1.setVisibility(View.GONE);
+
}else
{
+ text_wlkz.setVisibility(View.VISIBLE);
+ text_mgkz1.setVisibility(View.VISIBLE);
+
text_jlkz.setVisibility(View.GONE);
text_bckz.setVisibility(View.GONE);
text_jlkz1.setVisibility(View.GONE);
@@ -264,7 +290,13 @@ public class silos_jiaoyan extends LinearLayout {
activity=ac;
this.lcMode=_lcMode;
initData();
- InitView("物料校准");
+ //InitView("物料校准");
+ if (lcMode.name.equals("外置仓")){
+ InitView("酱料校准");
+ }else{
+ InitView("物料校准");
+ }
+
Run();
}
@@ -460,7 +492,7 @@ public class silos_jiaoyan extends LinearLayout {
R.id.chuliao1, R.id.chuliao2, R.id.chuliao3,
R.id.click_mgjz, R.id.click_mgjz_save,
R.id.click_wljz, R.id.click_wljz_save,
- R.id.click_bcjz_save,
+ R.id.click_bcjz_save,R.id.btn_jljz_startAdj,
})
public void onViewClicked(View view) {
switch (view.getId()) {
@@ -499,6 +531,9 @@ public class silos_jiaoyan extends LinearLayout {
case R.id.click_bcjz_save://补偿校准 保存参数
SaveBCJZ();
break;
+ case R.id.btn_jljz_startAdj:
+ JLJZ();
+ break;
}
}
//endregion
@@ -509,8 +544,9 @@ public class silos_jiaoyan extends LinearLayout {
* 电子秤清零
*/
public void dzcql() {
- ExecuteTheRecipe.WritePLC("重量清零", true, new IWriteCallBack() {
- @Override
+ //ExecuteTheRecipe.WritePLC("重量清零", true, new IWriteCallBack() {
+ PLCControl.get().tare(new IWriteCallBack() {
+ @Override
public void onSuccess() {
ToastUtils.info("清零成功!");
}
@@ -542,7 +578,7 @@ public class silos_jiaoyan extends LinearLayout {
ToastUtils.warning("出料重量不能为空!");
return;
}
- double zl = 0;
+ double zl = 0;//需求重量。
try {
zl = Double.parseDouble(zltext);
} catch (Exception e) {
@@ -554,39 +590,225 @@ public class silos_jiaoyan extends LinearLayout {
return;
}
- if (ConfigName.getInstance().versionSelectionEnum.equals("奶茶机"))
- {
- if (!ExecuteTheRecipe.IsCup) {
- ToastUtils.warning("出料口没有检测到器皿!");
- return;
- }
- }
+// if (ConfigName.getInstance().versionSelectionEnum.equals("奶茶机"))
+// {
+// if (!ExecuteTheRecipe.IsCup) {
+// ToastUtils.warning("出料口没有检测到器皿!");
+// return;
+// }
+// }
+
+ //short kkk = (short) ((int) (zl * 10));
- short kkk = (short) ((int) (zl * 10));
+ final int[] delayTime=new int[]{0};
+ if (TypeName.equals("酱料校准")){
+ delayTime[0]=(int)(ExecuteTheRecipe.getDelayTimeByLCID(lcMode.id,zl)*1000);
+ }else{
+ delayTime[0] =(int)(Double.parseDouble(lcMode.jTime)/Double.parseDouble(lcMode.jValue)*zl*1000);
+ }
+ if (delayTime[0]<=0){
+ ToastUtils.error("Simulation Fail,the open motor time must greater than 0");
+ return;
+ }
new Thread(new Runnable() {
@Override
public void run() {
try {
- ExecuteTheRecipe.WritePLC("配料完成", false, null);
- ExecuteTheRecipe.WritePLC("手自切换", true, null);
- ExecuteTheRecipe.WritePLC("需求值" + lcMode.num, kkk, new IWriteCallBack() {
+// ExecuteTheRecipe.WritePLC("配料完成", false, null);
+// ExecuteTheRecipe.WritePLC("手自切换", true, null);
+ ExecuteTheRecipe.isAutoMode=false;
+
+ PLCControl.get().openMotorAndClose(lcMode.num, delayTime[0], new IWriteCallBack() {
@Override
public void onSuccess() {
- ExecuteTheRecipe.WritePLC("配料启动", true, null);
- ToastUtils.warning("启动成功......");
-
+ ToastUtils.success("Start Simulation Success......");
}
-
@Override
public void onFailure(String ErrorMsg) {
+ ToastUtils.error("Start Simulation Failure:"+ ErrorMsg);
}
});
} catch (Exception e) {
+ ToastUtils.error("Simulation Open:"+ e.getMessage());
}
}
}).start();
- ToastUtils.info("需求值下发成功!开始配料......");
+ ToastUtils.info("Start Simulation......");
+ }
+ //endregion
+
+ //region 酱料校准
+ /**酱料校准--校准成功自动保存*/
+ private void JLJZ(){
+
+ //region 校验及转换数据
+ String highLimit=txt_jljz_highLimit.getText().toString().trim();
+ String lowLimit=txt_jljz_lowLimit.getText().toString().trim();
+ String text_adjFreq=txt_jljz_adjFreq.getText().toString().trim();
+
+ if (lowLimit.isEmpty() || lowLimit.equals("")){
+ ToastUtils.warning("校准范围下限不能为空!");
+ return;
+ }
+ if (highLimit.isEmpty() || highLimit.equals("")){
+ ToastUtils.warning("校准范围上限不能为空!");
+ return;
+ }
+ if (text_adjFreq.isEmpty() || text_adjFreq.equals("")){
+ ToastUtils.warning("校准频率不能为空!");
+ return;
+ }
+
+ final double weightLowLimit;
+ final double weightHighLimit;
+ final int adjFreq;
+
+ try {
+ weightLowLimit=Double.parseDouble(lowLimit);
+ }catch (Exception e){
+ ToastUtils.error("校准下限异常!" + e.getMessage());
+ return;
+ }
+ try {
+ weightHighLimit=Double.parseDouble(highLimit);
+ }catch (Exception e){
+ ToastUtils.error("校准上限异常!" + e.getMessage());
+ return;
+ }
+ try {
+ adjFreq=Integer.parseInt(text_adjFreq);
+ }catch (Exception e){
+ ToastUtils.error("校准频率异常!" + e.getMessage());
+ return;
+ }
+ if (weightLowLimit<0 || (weightLowLimit>=weightHighLimit)){
+ ToastUtils.error("校准范围值异常,下限应大于0,且小于上限值!");
+ return;
+ }
+ //endregion
+
+ btn_jljz_startAdj.setEnabled(false);
+ btn_jljz_startAdj.setText("正在校准...");
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ ExecuteTheRecipe.isAutoMode=false;
+ final double[] currentWeight=new double[]{0};
+ currentWeight[0]=ExecuteTheRecipe.OutletWeigh/10;
+ //出料时间及出料重量对比表。
+ //HashMap outMaterialMap=new HashMap();
+
+ WeightedObservedPoints points=new WeightedObservedPoints();
+ long startTime=System.currentTimeMillis();
+ ToastUtils.info("开始酱料校准,时间较长,请耐心等待。");
+ while (currentWeight[0]<=weightHighLimit){
+// PLCControl.get().openMotorAndClose(lcMode.num, adjFreq * 1000, new IWriteCallBack() {
+// @Override
+// public void onSuccess() {
+// currentWeight[0]=ExecuteTheRecipe.OutletWeigh/10;
+// if (currentWeight[0]>=weightLowLimit){
+// //出料时间
+// long outTime=System.currentTimeMillis()-startTime;
+// double time=((double)outTime)/1000;
+// outMaterialMap.put(time,currentWeight[0]);
+// }
+// }
+// @Override
+// public void onFailure(String ErrorMsg) {
+// //ToastUtils.error("酱料校准开关电机错误,校准失败");
+// }
+// });
+ PLCControl.get().openMotor(lcMode.num, new IWriteCallBack() {
+ @Override
+ public void onSuccess() {
+ try {
+ Thread.sleep(adjFreq*1000);
+ PLCControl.get().closeMotor(lcMode.num, new IWriteCallBack() {
+ @Override
+ public void onSuccess() {
+ currentWeight[0]=ExecuteTheRecipe.OutletWeigh/10.0;
+ if (currentWeight[0]>=weightLowLimit){
+ //出料时间
+ long outTime=System.currentTimeMillis()-startTime;
+ double time=((double)outTime)/1000;
+ //outMaterialMap.put(time,currentWeight[0]);
+ //方程式里,x是重量,Y才是时间
+ points.add(currentWeight[0],time);
+ }
+ }
+ @Override
+ public void onFailure(String ErrorMsg) {
+
+ }
+ });
+ } catch (Exception e) {
+ ToastUtils.error("酱料校准错误 :"+e.getMessage());
+ }
+ }
+ @Override
+ public void onFailure(String ErrorMsg) {
+
+ }
+ });
+
+ }
+ //没出错就保存。
+ //String result= jzDataToString(outMaterialMap);
+ activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ new QMUIDialog.MessageDialogBuilder(activity).setTitle("确定要保存该酱料校准结果吗?")
+ .setCanceledOnTouchOutside(false)
+ .addAction("确认", new QMUIDialogAction.ActionListener() {
+ @Override
+ public void onClick(QMUIDialog dialog, int index) {
+ //Toast.makeText(activity.getApplicationContext(), "确认", Toast.LENGTH_SHORT).show();
+
+ //region 生成公式
+ //公式多项式阶数
+ int degree=3;
+
+ // 创建 PolynomialCurveFitter 对象,并进行多项式回归拟合
+ PolynomialCurveFitter fitter = PolynomialCurveFitter.create(degree);
+ double[] coefficients = fitter.fit(points.toList());
+
+ // 打印回归方程的系数
+// for (int i = 0; i < coefficients.length; i++) {
+// System.out.print(coefficients[i] + " ");
+// }
+ //endregion
+
+ dialog.dismiss();
+ //lcMode.bcsfValue=result;
+ QueryDB.UpdateSilosBcsfValue(lcMode.id,String.valueOf(weightLowLimit),String.valueOf(weightHighLimit),String.valueOf(adjFreq));
+ //QueryDB.UpdateSilosBcsfValue(lcMode.id, result);
+ QueryDB.UpdateSilosBcsfValue(lcMode.id, Arrays.toString(coefficients));
+ //ToastUtils.success("酱料校准结果保存成功!");
+ MessageLog.ShowUserMessage(UserLogEnum.角色操作日志,lcMode.num+"仓位酱料校准结果保存成功。");
+ }
+ }).addAction("取消", new QMUIDialogAction.ActionListener() {
+ @Override
+ public void onClick(QMUIDialog dialog, int index) {
+ //Toast.makeText(activity.getApplicationContext(), "取消", Toast.LENGTH_SHORT).show();
+ dialog.dismiss();
+ }
+ }).create(AlertDialogUtils.mCurrentDialogStyle).show();
+ }
+ });
+ //ToastUtils.success("酱料校准结束,数据已保存。");
+ }catch (Exception ex){
+ ToastUtils.error("酱料校准失败:"+ex.getMessage());
+ }finally {
+ activity.runOnUiThread(()->{
+ btn_jljz_startAdj.setEnabled(true);
+ btn_jljz_startAdj.setText("开始校准");
+ });
+ }
+
+ }
+ }).start();
}
//endregion
@@ -633,17 +855,17 @@ public class silos_jiaoyan extends LinearLayout {
ToastUtils.error("时间异常!" + e.getMessage());
return;
}
- ExecuteTheRecipe.WritePLC("反转时间", (short) ftime_1, new IWriteCallBack() {
- @Override
- public void onSuccess() {
- ToastUtils.info("反转时间保存成功!");
- }
-
- @Override
- public void onFailure(String ErrorMsg) {
- ToastUtils.error("反转时间保存失败!");
- }
- });
+// ExecuteTheRecipe.WritePLC("反转时间", (short) ftime_1, new IWriteCallBack() {
+// @Override
+// public void onSuccess() {
+// ToastUtils.info("反转时间保存成功!");
+// }
+//
+// @Override
+// public void onFailure(String ErrorMsg) {
+// ToastUtils.error("反转时间保存失败!");
+// }
+// });
}
lcMode.fTime=ftime;
lcMode.jTime=stime;
@@ -655,53 +877,70 @@ public class silos_jiaoyan extends LinearLayout {
QueryDB.UpdateSilosJZTime(item.id, stime, ftime);
}
QueryDB.UpdateJYZ(lcMode.id, zl);
- ExecuteTheRecipe.WritePLC("基准时间", (short) stime_1, new IWriteCallBack() {
- @Override
- public void onSuccess() {
- ToastUtils.info("校准基准时间保存成功!");
- }
-
- @Override
- public void onFailure(String ErrorMsg) {
- ToastUtils.error("校准基准时间保存失败!");
- }
- });
+ ToastUtils.success("物料校准时间保存成功!");
+
+// ExecuteTheRecipe.WritePLC("基准时间", (short) stime_1, new IWriteCallBack() {
+// @Override
+// public void onSuccess() {
+// ToastUtils.info("校准基准时间保存成功!");
+// }
+//
+// @Override
+// public void onFailure(String ErrorMsg) {
+// ToastUtils.error("校准基准时间保存失败!");
+// }
+// });
}
//endregion
//region 物料校准
public void WLJZ() {
- //判断是否为果糖->判断温度
- if (ConfigName.getInstance().versionSelectionEnum.equals("奶茶机")) {
- if (lcMode.num == 11) {
- if (ExecuteTheRecipe.SugarTempLeft < ExecuteTheRecipe.SugarTempLeft_SZ) {
- ToastUtils.warning("果糖左仓温度未达到设置值,不允许校准...");
- return;
- }
- } else if (lcMode.num == 12) {
- if (ExecuteTheRecipe.SugarTempRight < ExecuteTheRecipe.SugarTempRight_SZ) {
- ToastUtils.warning("果糖右仓温度未达到设置值,不允许校准...");
- return;
- }
- }
+ //TODO:重写物料校准。
+
+ //region 物料校准--可提取为内部方法
+ String stime = wljz1.getText().toString();
+ String ftime = wljz2.getText().toString();
+
+ if (stime.equals("")) {
+ ToastUtils.warning("校准基准时间不能为空!");
+ return;
+ }
+ final int[] stime_1 = {0};
+
+ try {
+ stime_1[0] = (int) Math.round((Double.parseDouble(stime)));
+ } catch (Exception e) {
+ ToastUtils.error("时间异常!" + e.getMessage());
+ return;
}
+ //endregion
new Thread(new Runnable() {
@Override
public void run() {
try {
- ExecuteTheRecipe.WritePLC("校准完成", false, null);
- ExecuteTheRecipe.WritePLC("手自切换", false, null);
- ExecuteTheRecipe.WritePLC("通道校准", true, new IWriteCallBack() {
+
+ ExecuteTheRecipe.isAutoMode=false;
+ PLCControl.get().openMotor(lcMode.num, new IWriteCallBack() {
@Override
public void onSuccess() {
- ToastUtils.info("启动通道校准成功!");
+ new Handler(Looper.getMainLooper()).postDelayed(()->{
+ PLCControl.get().closeMotor(lcMode.num, new IWriteCallBack() {
+ @Override
+ public void onSuccess() {
+ ToastUtils.info("通道校准完成--请确认重量!");
+ }
+ @Override
+ public void onFailure(String ErrorMsg) {
+ ToastUtils.error("通道校准---关闭通道失败!");
+ }
+ });
+ },stime_1[0]*1000);
}
-
@Override
public void onFailure(String ErrorMsg) {
- ToastUtils.error("启动通道校准失败!");
+ ToastUtils.error("通道校准---开启通道失败!");
}
});
} catch (Exception e) {
@@ -807,4 +1046,30 @@ public class silos_jiaoyan extends LinearLayout {
}
//endregion
+
+ //region 数据校验
+ /**物料校准参数校验*/
+ private void validateForWLJZ(){
+
+ }
+ //endregion
+
+
+ /**键值都为Double的HashMap转换为字符串,提供给酱料校准使用。*/
+ private String jzDataToString(Map hashMap){
+ String result="";
+ if (hashMap.isEmpty()){
+ result= "";
+ }
+ StringBuilder stringBuilder=new StringBuilder();
+ for (Map.Entry entry:hashMap.entrySet()){
+ stringBuilder.append(entry.getKey()).append(",").append(entry.getValue()).append("|");
+ }
+ if (stringBuilder.length()>0){
+ stringBuilder.setLength(stringBuilder.length()-1);
+ result=stringBuilder.toString();
+ }
+ return result;
+ }
+
}
diff --git a/app/src/main/res/layout/fragment_make_good.xml b/app/src/main/res/layout/fragment_make_good.xml
index 58b04666..0c96e8f5 100644
--- a/app/src/main/res/layout/fragment_make_good.xml
+++ b/app/src/main/res/layout/fragment_make_good.xml
@@ -136,22 +136,6 @@
android:textColor="@color/green_primary"
android:textSize="@dimen/TitleSize" />
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From 1e67707b12981e019b49f3fb3f1b772d4a8d1662 Mon Sep 17 00:00:00 2001
From: Nah <15196688790@163.com>
Date: Wed, 29 Nov 2023 11:45:55 +0800
Subject: [PATCH 3/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8B=E4=BD=8D?=
=?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=93=8D=E4=BD=9C=E7=9A=84=E7=B1=BB=EF=BC=8C?=
=?UTF-8?q?=E4=BB=A5=E5=8F=8A=E4=B8=AD=E8=8B=B1=E6=96=87=E5=AD=97=E7=AC=A6?=
=?UTF-8?q?=E4=B8=B2=E6=96=87=E4=BB=B6=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../business/devicesControl/PLCControl.java | 340 ++++++++++
.../common/modbus/ModbusRTUServer.java | 632 ++++++++++++++++++
app/src/main/res/values-en/strings.xml | 44 ++
3 files changed, 1016 insertions(+)
create mode 100644 app/src/main/java/com/bonait/bnframework/business/devicesControl/PLCControl.java
create mode 100644 app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java
create mode 100644 app/src/main/res/values-en/strings.xml
diff --git a/app/src/main/java/com/bonait/bnframework/business/devicesControl/PLCControl.java b/app/src/main/java/com/bonait/bnframework/business/devicesControl/PLCControl.java
new file mode 100644
index 00000000..6b71941a
--- /dev/null
+++ b/app/src/main/java/com/bonait/bnframework/business/devicesControl/PLCControl.java
@@ -0,0 +1,340 @@
+package com.bonait.bnframework.business.devicesControl;
+
+import android.os.Handler;
+import android.os.Looper;
+
+import com.bonait.bnframework.business.ExecuteTheRecipe;
+import com.bonait.bnframework.common.constant.ConfigName;
+import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS;
+import com.bonait.bnframework.common.helper.DataFormat;
+import com.bonait.bnframework.common.helper.I.IWriteCallBack;
+import com.bonait.bnframework.common.modbus.ModbusRTUServer;
+import com.bonait.bnframework.common.utils.ToastUtils;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+public class PLCControl {
+ //region 单例模式
+ private static volatile PLCControl instance = null;
+
+ public static PLCControl get() {
+ PLCControl manager = instance;
+ if (manager == null) {
+ synchronized (PLCControl.class) {
+ manager = instance;
+ if (manager == null) {
+ manager = new PLCControl();
+ instance = manager;
+ }
+ }
+ }
+ return manager;
+ }
+ private PLCControl() {
+ }
+ //endregion
+
+ /**语音模块的从站地址,这个最好不改,设备端不好修改默认地址*/
+ private final int voiceAddress=1;
+ /**电子秤的从站地址*/
+ private final int scaleAddress=2;
+ /**PLC的从站地址*/
+ private final int PLCAddress=3;
+
+ //region 语音模块控制 , 从站地址:1
+
+ public void Speak(String content,IWriteCallBack callBack){
+ try {
+ if (!content.isEmpty() /*&& !ExecuteTheRecipe.isTimeOut*/) {
+ int address = 0;
+ short[] values=getGB2312(content);
+ ModbusRTUServer.get().WriteString(voiceAddress, address, values, callBack);
+ }
+ }
+ catch (Exception ex) {
+ ToastUtils.error("Exception message:" + ex.getMessage());
+ }
+ }
+
+ //endregion
+
+ //region 电子秤控制, 从站地址:2
+
+ /**获取称当前重量、当前AD值、当前零位,文档建议150ms以上轮询一次*/
+ public int getCurrentWeight(){
+ //int readLength=3;
+ int[] result=new int[]{0};
+ try {
+ ModbusRTUServer.get().ReadInts(scaleAddress, 0, 1, DataFormat.BADC, val-> {
+ result[0]=val[0];
+ });
+ }catch (Exception ex){
+ ToastUtils.error("Exception message:" + ex.getMessage());
+ }finally {
+ return result[0];
+ }
+ }
+
+ /**写入砝码重量*/
+ public void writeCounterWeight(short counterWeight,IWriteCallBack callBack){
+ try {
+ ModbusRTUServer.get().WriteShort(scaleAddress, 6,counterWeight,callBack);
+ }catch (Exception ex){
+ ToastUtils.error("Exception message:" + ex.getMessage());
+ }
+ }
+
+ /**去皮*/
+ public void tare(IWriteCallBack callBack){
+ try {
+ ModbusRTUServer.get().WriteShort(scaleAddress, 21,(short) 1,callBack);
+ }catch (Exception ex){
+ ToastUtils.error("Exception message:" + ex.getMessage());
+ }
+ }
+
+ /**恢复去皮*/
+ public void cancelTare(IWriteCallBack callBack){
+ try {
+ ModbusRTUServer.get().WriteShort(scaleAddress, 21,(short) 2,callBack);
+ }catch (Exception ex){
+ ToastUtils.error("Exception message:" + ex.getMessage());
+ }
+ }
+
+ /**零点校准,写入前需要先关闭写保护*/
+ public void zeroScale(IWriteCallBack callBack){
+ try {
+ ModbusRTUServer.get().WriteShort(scaleAddress, 22,(short) 1,callBack);
+ }catch (Exception ex){
+ ToastUtils.error("Exception message:" + ex.getMessage());
+ }
+ }
+
+ /**恢复出厂设置,写入前需要先关闭写保护*/
+ public void factoryReset(IWriteCallBack callBack){
+ try {
+ ModbusRTUServer.get().WriteShort(scaleAddress, 22,(short) 9,callBack);
+ }catch (Exception ex){
+ ToastUtils.error("Exception message:" + ex.getMessage());
+ }
+ }
+
+ /**打开写保护*/
+ public void openWriteProtect(IWriteCallBack callBack){
+ try {
+ ModbusRTUServer.get().WriteShort(scaleAddress, 23,(short) 0,callBack);
+ }catch (Exception ex){
+ ToastUtils.error("Exception message:" + ex.getMessage());
+ }
+ }
+
+ /**关闭写保护,零点校准、写入砝码重量、恢复出厂设置都需要先执行此操作*/
+ public void closeWriteProtect(IWriteCallBack callBack){
+ try {
+ ModbusRTUServer.get().WriteShort(scaleAddress, 23,(short) 1,callBack);
+ }catch (Exception ex){
+ ToastUtils.error("Exception message:" + ex.getMessage());
+ }
+ }
+
+ //endregion
+
+ //region PLC控制 设备从站地址:3
+
+
+
+ /**复位PLC所有输出以及心跳,[如果输出更换了点位的话,无法复位所有电机]*/
+ public void initalPLC(IWriteCallBack callBack){
+ try {
+ short[] values = new short[14];
+
+ final boolean[] isSuccess={false,false,false};
+
+ int startAddress = ModbusRTUServer.GetAddress("D10");
+ ModbusRTUServer.get().WriteShorts(PLCAddress, startAddress, values, new IWriteCallBack() {
+ @Override
+ public void onSuccess() {
+ isSuccess[0]=true;
+ }
+
+ @Override
+ public void onFailure(String ErrorMsg) {
+
+ }
+ });
+
+ int timeoutFlag = ModbusRTUServer.GetAddress("M0");
+ ModbusRTUServer.get().WriteBool(PLCAddress, timeoutFlag, false, new IWriteCallBack() {
+ @Override
+ public void onSuccess() {
+ isSuccess[1]=true;
+ }
+
+ @Override
+ public void onFailure(String ErrorMsg) {
+
+ }
+ });
+
+ clrHeartbeat("心跳时间", new IWriteCallBack() {
+ @Override
+ public void onSuccess() {
+ isSuccess[2]=true;
+ }
+
+ @Override
+ public void onFailure(String ErrorMsg) {
+
+ }
+ });
+ if (callBack != null) {
+ if (isSuccess[0] && isSuccess[1] && isSuccess[2]){
+ callBack.onSuccess();
+ }else{
+ callBack.onFailure("Initial Failure");
+ }
+ }
+ } catch (Exception ex) {
+ if (callBack != null) {
+ callBack.onFailure(ex.getMessage());
+ }
+ }
+
+ }
+
+ /**打开电机,指定时间后关闭
+ * @param delayTime 关闭延迟时间,单位:ms
+ * */
+ public void openMotorAndClose(int index,int delayTime,IWriteCallBack callBack){
+ try {
+ openMotor(index, new IWriteCallBack() {
+ @Override
+ public void onSuccess() {
+ new Handler(Looper.getMainLooper()).postDelayed(()->{
+ closeMotor(index, new IWriteCallBack() {
+ @Override
+ public void onSuccess() {
+ callBack.onSuccess();
+ }
+
+ @Override
+ public void onFailure(String ErrorMsg) {
+ callBack.onFailure(ErrorMsg);
+ }
+ });
+ },delayTime);
+ }
+ @Override
+ public void onFailure(String ErrorMsg) {
+ callBack.onFailure(ErrorMsg);
+ }
+ });
+ } catch (Exception ex) {
+ ToastUtils.error("OpenMotorAndClose Exception:" + ex.getMessage());
+ }
+ }
+
+ /**打开电机*/
+ public void openMotor(int index, IWriteCallBack callBack) {
+ String name="通道"+index+"开关";
+ try {
+ if (ConfigName.getInstance().PLC_Address.containsKey(name)) {
+ BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name);
+ if (!plcaddress.address.isEmpty() && !ExecuteTheRecipe.isTimeOut) {
+ int address = ModbusRTUServer.GetAddress(plcaddress.address);
+ ModbusRTUServer.get().WriteShort(PLCAddress, address, (short)1, callBack);
+ }
+ }
+ } catch (Exception ex) {
+ ToastUtils.error("OpenMotor Exception:" + ex.getMessage());
+ }
+ }
+
+ /**关闭电机*/
+ public void closeMotor(int index, IWriteCallBack callBack) {
+ String name="通道"+index+"开关";
+ try {
+ if (ConfigName.getInstance().PLC_Address.containsKey(name)) {
+ BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name);
+ if (!plcaddress.address.isEmpty() && !ExecuteTheRecipe.isTimeOut) {
+ int address = ModbusRTUServer.GetAddress(plcaddress.address);
+ ModbusRTUServer.get().WriteShort(PLCAddress, address, (short)0, callBack);
+ }
+ }
+ } catch (Exception ex) {
+ ToastUtils.error("CloseMotor Exception:" + ex.getMessage());}
+ }
+
+ /**获取所有电机的状态,为true表示正在转,反之,为false。*/
+ public boolean[] getAllMotorStatus(){
+ //一共有14个电机
+ int length = 14;
+ boolean[] result = new boolean[length];
+ try {
+ BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get("通道1开关");
+ if (!plcaddress.address.isEmpty() && !ExecuteTheRecipe.isTimeOut) {
+ int startAddress = ModbusRTUServer.GetAddress(plcaddress.address);
+ ModbusRTUServer.get().ReadShorts(PLCAddress, startAddress, length, val -> {
+ for (int i = 0; i < length; i++) {
+ result[i] = val[i] > 0 ? true : false;
+ }
+ });
+ }
+ }catch (Exception ex){
+ ToastUtils.error("GetAllMotorStatus Exception:" + ex.getMessage());
+ }finally {
+ return result;
+ }
+ }
+
+ /**复位心跳*/
+ public void clrHeartbeat(String name,IWriteCallBack callBack){
+ try {
+ if (ConfigName.getInstance().PLC_Address.containsKey(name)) {
+ BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name);
+ if (!plcaddress.address.isEmpty()/* && !ExecuteTheRecipe.isTimeOut*/) {
+ int address = ModbusRTUServer.GetAddress(plcaddress.address);
+ ModbusRTUServer.get().WriteShort(PLCAddress , address ,(short) 0 , callBack);
+ }
+ }
+ } catch (Exception ex) {
+ ToastUtils.error("ClrHeartbeat Exception:" + ex.getMessage());
+ }
+ }
+
+ /**读取是否超时*/
+ public boolean isTimeOut(String name){
+ final boolean[] result = {true};
+ try{
+ if (ConfigName.getInstance().PLC_Address.containsKey(name)) {
+ BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name);
+ if (!plcaddress.address.isEmpty() /*&& ConfigName.getInstance().SerialIsConnect*/) {
+ ModbusRTUServer.get().ReadBools(PLCAddress, plcaddress.address, 1, val-> {
+ result[0] =val[0];
+ });
+ }
+ }
+ }catch (Exception ex){
+ ToastUtils.error("Exception message:" + ex.getMessage());
+ }finally {
+ return result[0];
+ }
+ }
+ //endregion
+
+
+
+ /**字符串转换为GB2312编码,需要测试,可能不对*/
+ public short[] getGB2312(String str){
+ try{
+ byte[] bytes=str.getBytes("gb2312");
+ short[] result=new short[bytes.length/2];
+ ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN).asShortBuffer().get(result);
+ return result;
+ }catch (Exception e){
+ return null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java
new file mode 100644
index 00000000..bd32c37c
--- /dev/null
+++ b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java
@@ -0,0 +1,632 @@
+package com.bonait.bnframework.common.modbus;
+
+import com.bonait.bnframework.business.ConfigData;
+import com.bonait.bnframework.common.constant.ConfigName;
+import com.bonait.bnframework.common.helper.DataFormat;
+import com.bonait.bnframework.common.helper.I.IReadCallBack;
+import com.bonait.bnframework.common.helper.I.IWriteCallBack;
+import com.bonait.bnframework.common.helper.MessageLog;
+import com.licheedev.modbus4android.ModbusCallback;
+import com.licheedev.modbus4android.ModbusParam;
+import com.licheedev.modbus4android.ModbusRespException;
+import com.licheedev.modbus4android.param.SerialParam;
+import com.serotonin.modbus4j.ModbusMaster;
+import com.serotonin.modbus4j.exception.ModbusInitException;
+import com.serotonin.modbus4j.exception.ModbusTransportException;
+import com.serotonin.modbus4j.msg.ReadCoilsResponse;
+import com.serotonin.modbus4j.msg.ReadHoldingRegistersResponse;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.concurrent.ExecutionException;
+
+public class ModbusRTUServer {
+ //region 单例模式
+ private static volatile ModbusRTUServer instance = null;
+
+ public static ModbusRTUServer get() {
+ ModbusRTUServer manager = instance;
+ if (manager == null) {
+ synchronized (ModbusRTUServer.class) {
+ manager = instance;
+ if (manager == null) {
+ manager = new ModbusRTUServer();
+ instance = manager;
+ }
+ }
+ }
+ return manager;
+ }
+ private ModbusRTUServer() {
+ }
+ //endregion
+
+
+ static ModbusParam param;
+
+ /**适用于三菱PLC,只有X,Y,M,D区*/
+ public static int GetAddress(String address){
+ if (address == null) return -1;
+ address = address.toUpperCase().trim();
+
+ try {
+ if (address.length() < 2) return Integer.parseInt(address);
+
+ String res = address.substring(1);
+ if (res == null) return -1;
+
+ int startAddress=Integer.parseInt(res) ;
+ //如果是M区地址。
+ if (address.contains("M")) {
+ return startAddress + 4000;
+ } else if (address.contains("D")) {
+ return startAddress;
+ }else if(address.contains("X")){
+ return Integer.parseInt(res,8);
+ }else if(address.contains("Y")){
+ return Integer.parseInt(res,8)+300;
+ }else{
+ return Integer.parseInt(address);
+ }
+ } catch (Exception e) {
+ return -1;
+ }
+ }
+
+
+ /** 连接PLC*/
+ public void ConnectPLC()
+ {
+ int baudRate=ConfigName.getInstance().SerialBaudRate;
+ int dataBits=ConfigName.getInstance().SerialDataBits;
+ int parity=ConfigName.getInstance().SerialParity;
+ int stopBits=ConfigName.getInstance().SerialStopBits;
+ //String com="COM0";
+
+ param = SerialParam.create("/dev/ttyCOM1", baudRate) // 串口地址和波特率
+ .setDataBits(dataBits) // 数据位
+ .setParity(parity) // 校验位
+ .setStopBits(stopBits) // 停止位
+ .setTimeout(3000).setRetries(0); // 不重试
+
+ ModbusTcpHelper.get().init(param, new ModbusCallback() {
+ @Override
+ public void onSuccess(ModbusMaster modbusMaster) {
+ //ToastUtils.info("串口 ["+com+"] 连接成功");
+
+ //MessageLog.ShowInfo("串口 ["+com+"] 连接成功");
+ ConfigName.getInstance().SerialIsConnect = true;
+ ConfigData.getInstance().PLC_Init();
+ }
+
+ @Override
+ public void onFailure(Throwable tr) {
+ ConfigName.getInstance().SerialIsConnect = false;
+ //ToastUtils.info("串口 ["+com+"] 连接失败:" + tr.getMessage());
+ //MessageLog.ShowError("串口 ["+com+"] 连接失败:" + tr.getMessage());
+ }
+ @Override
+ public void onFinally() {
+ }
+ });
+ }
+
+
+ //region 数据类型转换
+ private Float BytesToFloat(byte[] buffers, DataFormat df) {
+ if (buffers.length == 4) {
+ byte[] bytes = new byte[4];
+ if (df == DataFormat.ABCD) {
+ bytes[0] = buffers[3];
+ bytes[1] = buffers[2];
+ bytes[2] = buffers[1];
+ bytes[3] = buffers[0];
+ } else if (df == DataFormat.CDAB) {
+ bytes[0] = buffers[1];
+ bytes[1] = buffers[0];
+ bytes[2] = buffers[3];
+ bytes[3] = buffers[2];
+ } else if (df == DataFormat.BADC) {
+ bytes[0] = buffers[2];
+ bytes[1] = buffers[3];
+ bytes[2] = buffers[0];
+ bytes[3] = buffers[1];
+ } else if (df == DataFormat.DCBA) {
+ bytes[0] = buffers[0];
+ bytes[1] = buffers[1];
+ bytes[2] = buffers[2];
+ bytes[3] = buffers[3];
+ }
+ return ByteBuffer.wrap(bytes).getFloat();
+ }
+ return 0.0f;
+ }
+
+ private Integer BytesToInt(byte[] buffers, DataFormat df) {
+ if (buffers.length == 4) {
+ byte[] bytes = new byte[4];
+ if (df == DataFormat.ABCD) {
+ bytes[0] = buffers[3];
+ bytes[1] = buffers[2];
+ bytes[2] = buffers[1];
+ bytes[3] = buffers[0];
+ } else if (df == DataFormat.CDAB) {
+ bytes[0] = buffers[1];
+ bytes[1] = buffers[0];
+ bytes[2] = buffers[3];
+ bytes[3] = buffers[2];
+ } else if (df == DataFormat.BADC) {
+ bytes[0] = buffers[2];
+ bytes[1] = buffers[3];
+ bytes[2] = buffers[0];
+ bytes[3] = buffers[1];
+ } else if (df == DataFormat.DCBA) {
+ bytes[0] = buffers[0];
+ bytes[1] = buffers[1];
+ bytes[2] = buffers[2];
+ bytes[3] = buffers[3];
+ }
+ return ByteBuffer.wrap(bytes).getInt();
+ }
+ return 0;
+ }
+
+ private byte[] IntToByte(int number) {
+ int temp = number;
+ byte[] b = new byte[4];
+ for (int i = 0; i < b.length; i++) {
+ b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位
+ temp = temp >> 8; // 向右移8位
+ }
+ return b;
+ }
+
+ private short[] IntToShorts(int value) {
+ short[] res = new short[2];
+ int temp = value;
+ byte[] b = new byte[4];
+ for (int i = 0; i < b.length; i++) {
+ b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位
+ temp = temp >> 8; // 向右移8位
+ }
+ for (int i = 0; i < res.length; i++) {
+ short s0 = (short) (b[i * 2] & 0xff);// 最低位
+ short s1 = (short) (b[i * 2 + 1] & 0xff);
+ s1 <<= 8;
+ res[i] = (short) (s0 | s1);
+ }
+ return res;
+ }
+
+ public static String GetString(short[] src, int start, int len) throws UnsupportedEncodingException {
+ short[] temp = new short[len];
+ for (int i = 0; i < len; i++) {
+ temp[i] = src[i + start];
+ }
+ byte[] bytesTemp = shorts2Bytes(temp);
+ for (int i = 0; i < bytesTemp.length; i++) {
+ byte b = bytesTemp[i];
+ }
+ String str = new String(bytesTemp, "UTF-8");
+ return str;
+ }
+
+ public static byte[] shorts2Bytes(short[] data) {
+ byte[] byteValue = new byte[data.length * 2];
+ for (int i = 0; i < data.length; i++) {
+ byteValue[i * 2] = (byte) (data[i] & 0xff);
+ byteValue[i * 2 + 1] = (byte) ((data[i] & 0xff00) >> 8);
+ }
+ return byteValue;
+ }
+ //endregion
+
+ //region 读取及写入方法
+
+ /**写入字符串*/
+ public void WriteString(int slaveAddress,String Address, int length, IWriteCallBack callback) {
+ int add = GetAddress(Address);
+ if (add < 0) return;
+ short[] send = new short[length];
+ for (short item : send) {
+ item = 0;
+ }
+ try {
+ ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, add, send);
+ if (callback != null)
+ callback.onSuccess();
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ }
+ }
+
+ /**写入字符串*/
+ public void WriteString(int slaveAddress,int Address, short[] values, IWriteCallBack callback) {
+ if (slaveAddress<0) return;
+ if (Address < 0) return;
+ if (values ==null || values.length==0) return;
+ try {
+ ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, values);
+ if (callback != null)
+ callback.onSuccess();
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ }
+ }
+
+
+ /**根据地址批量读取16位寄存器*/
+ public void ReadShorts(int slaveAddress,int Address, int length, IReadCallBack callback) {
+ //int add = GetAddress(Address);
+ if (Address < 0) return;
+ try {
+ ReadHoldingRegistersResponse res = ModbusTcpHelper.get()
+ .syncReadHoldingRegisters(slaveAddress, Address, length);
+ short[] data = res.getShortData();
+ if (data.length == length) {
+ if (callback != null) callback.onSuccess(data);
+ }
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ }
+ }
+
+ public void ReadBools(int slaveAddress,String Address, int length, IReadCallBack callback) {
+ int add = GetAddress(Address);
+ if (add < 0) return;
+ try {
+ ReadCoilsResponse res = ModbusTcpHelper.get()
+ .syncReadCoil(slaveAddress, add, length);
+ boolean[] data = res.getBooleanData();
+ boolean[] result = Arrays.copyOfRange(data, 0, length);
+ if (result.length == length) {
+ if (callback != null) callback.onSuccess(result);
+ }
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ }catch (Exception e){
+ MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ }
+ }
+
+ public void ReadFloats(int slaveAddress,int Address, int length, IReadCallBack callback) {
+ //int add = GetAddress(Address);
+ if (Address < 0) return;
+ try {
+ ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(slaveAddress, Address, length*2);
+ byte[] data = res.getData();
+ float[] tempValues = new float[length];
+ for (int i = 0; i < length; i++) {
+ byte[] tempData = new byte[4];
+ for (int m = 0; m < 4; m++) {
+ tempData[m] = data[i * 4 + m];
+ }
+ tempValues[i] = BytesToFloat(tempData, DataFormat.BADC);
+ }
+ if (tempValues.length == length) {
+ if (callback != null) callback.onSuccess(tempValues);
+ }
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ }
+ }
+
+ public void ReadInts(int slaveAddress,int Address, int length,DataFormat dataFormat, IReadCallBack callback) {
+ //int add = GetAddress(Address);
+ if (Address < 0) return;
+ try {
+ ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(slaveAddress, Address, length * 2);
+ byte[] data = res.getData();
+ int[] tempValues = new int[length];
+ if(data.length>=4)
+ {
+ for (int i = 0; i < length; i++) {
+ byte[] tempData = new byte[4];
+ for (int m = 0; m < 4; m++) {
+ tempData[m] = data[i * 4 + m];
+ }
+ tempValues[i] = BytesToInt(tempData, dataFormat);
+ }
+ }else
+ {
+ MessageLog.ShowError("ReadInt onFailure,Address=" );
+
+ }
+ if (callback != null) callback.onSuccess(tempValues);
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString());
+ }
+ }
+
+ public void WriteShort(int slaveAddress,int Address, short Value, IWriteCallBack callback) {
+ //int add = GetAddress(Address);
+ if (Address < 0) return;
+ short[] send = new short[1];
+ send[0] = Value;
+ try {
+ ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send);
+ if (callback != null)
+ callback.onSuccess();
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ }
+ }
+
+ public void WriteShorts(int slaveAddress,int Address, short[] Value, IWriteCallBack callback) {
+ //int add = GetAddress(Address);
+ if (Address < 0) return;
+ try {
+ ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, Value);
+ if (callback != null)
+ callback.onSuccess();
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ }
+ }
+
+ public void WriteBool(int slaveAddress,int Address, boolean Value, IWriteCallBack callback) {
+ //int add = GetAddress(Address);
+ if (Address < 0) return;
+ try {
+ ModbusTcpHelper.get().syncWriteCoil(slaveAddress, Address, Value);
+ if (callback != null)
+ callback.onSuccess();
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ }
+ }
+
+ public void WriteBools(int slaveAddress,int Address, boolean[] Value, IWriteCallBack callback) {
+ //int add = GetAddress(Address);
+ if (Address < 0) return;
+ try {
+ ModbusTcpHelper.get().syncWriteCoils(slaveAddress, Address, Value);
+ if (callback != null)
+ callback.onSuccess();
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ }
+ }
+ public void WriteFloat(int slaveAddress,int Address, float Value, IWriteCallBack callback) {
+ //int add = GetAddress(Address);
+ if (Address < 0) return;
+ int intBits = Float.floatToRawIntBits(Value);
+ short[] send = IntToShorts(intBits);
+ try {
+ ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send);
+
+ if (callback != null) callback.onSuccess();
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ }
+ }
+
+ public void WriteInt(int slaveAddress,int Address, int Value, IWriteCallBack callback) {
+ //int add = GetAddress(Address);
+ if (Address < 0) return;
+ short[] send = IntToShorts(Value);
+ try {
+ ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send);
+ if (callback != null) callback.onSuccess();
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ if (callback != null) callback.onFailure(e.toString());
+ }
+ }
+
+ public void WriteShort(int slaveAddress,int Address, short Value) {
+ //int add = GetAddress(Address);
+ if (Address < 0) return;
+ short[] send = new short[1];
+ send[0] = Value;
+ try {
+ ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send);
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ }
+ }
+
+ public void WriteBool(int slaveAddress,int Address, boolean Value) {
+ //int add = GetAddress(Address);
+ if (Address < 0) return;
+
+ try {
+ ModbusTcpHelper.get().syncWriteCoil(slaveAddress, Address, Value);
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ }
+ }
+
+ public void WriteFloat(int slaveAddress,int Address, float Value) {
+ //int add = GetAddress(Address);
+ if (Address < 0) return;
+ int intBits = Float.floatToRawIntBits(Value);
+ short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)};
+ try {
+ ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send);
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ }
+ }
+
+ public void WriteInt(int slaveAddress,int Address, int Value) {
+ //int add = GetAddress(Address);
+ if (Address < 0) return;
+ short[] send = IntToShorts(Value);
+ try {
+ ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send);
+ } catch (InterruptedException e) {
+ MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ExecutionException e) {
+ MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ModbusTransportException e) {
+ MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ModbusInitException e) {
+ MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ } catch (ModbusRespException e) {
+ MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString());
+ }
+ }
+
+ //endregion
+}
diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml
new file mode 100644
index 00000000..e54fa58a
--- /dev/null
+++ b/app/src/main/res/values-en/strings.xml
@@ -0,0 +1,44 @@
+
+ 菠萝智慧吧
+ normal
+ all files
+ empty data
+ sd card not avaliable
+ selected:%s
+ 确定%s
+ 最多选择%d个文件
+ Save locally%s
+
+
+ Welcome!
+ Please enter username
+ Please enter password
+ Remember you
+ Forget password?
+ Login
+
+
+ Function
+ SilosManage
+ RecipeManage
+ LogManage
+ BaseDataManage
+ RealTimeMonitorManage
+
+
+ Software initialization in progress, please wait...
+ Full Pipe
+ Set Full Tank
+ Clean Pipe
+ Set Silo Info
+ Click on the silo icon to configure or control the silo
+ A warning will be triggered when the material in the silo falls below the minimum level.
+
+
+ SerialBaudRate:
+ SerialDataBits:
+ SerialParity:
+ SerialStopBits:
+
+
+
From 949b58ebbae96cae3d57fe15f8b679167789e4c4 Mon Sep 17 00:00:00 2001
From: Nah <15196688790@163.com>
Date: Mon, 4 Dec 2023 14:14:42 +0800
Subject: [PATCH 4/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8B=E4=BD=8D?=
=?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=93=8D=E4=BD=9C=E7=9A=84=E7=B1=BB=EF=BC=8C?=
=?UTF-8?q?=E4=BB=A5=E5=8F=8A=E4=B8=AD=E8=8B=B1=E6=96=87=E5=AD=97=E7=AC=A6?=
=?UTF-8?q?=E4=B8=B2=E6=96=87=E4=BB=B6=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/compiler.xml | 6 ++
.idea/gradle.xml | 20 ++++++
.idea/misc.xml | 4 ++
.../shelved.patch | 71 +++++++++++++++++++
..._Checkout_at_2023_12_4_14_14__Changes_.xml | 4 ++
.../bonait/bnframework/business/MainInit.java | 13 +---
.../common/modbus/ModbusRTUServer.java | 2 +-
7 files changed, 108 insertions(+), 12 deletions(-)
create mode 100644 .idea/compiler.xml
create mode 100644 .idea/gradle.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/shelf/Uncommitted_changes_before_Checkout_at_2023_12_4_14_14_[Changes]/shelved.patch
create mode 100644 .idea/shelf/Uncommitted_changes_before_Checkout_at_2023_12_4_14_14__Changes_.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 00000000..fb7f4a8a
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 00000000..ce86a83a
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 00000000..e9a58ca7
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/shelf/Uncommitted_changes_before_Checkout_at_2023_12_4_14_14_[Changes]/shelved.patch b/.idea/shelf/Uncommitted_changes_before_Checkout_at_2023_12_4_14_14_[Changes]/shelved.patch
new file mode 100644
index 00000000..d21148e1
--- /dev/null
+++ b/.idea/shelf/Uncommitted_changes_before_Checkout_at_2023_12_4_14_14_[Changes]/shelved.patch
@@ -0,0 +1,71 @@
+Index: app/src/main/java/com/bonait/bnframework/business/MainInit.java
+IDEA additional info:
+Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
+<+>package com.bonait.bnframework.business;\r\n\r\nimport android.app.Activity;\r\nimport android.app.Application;\r\nimport android.util.Log;\r\n\r\nimport com.bonait.bnframework.BuildConfig;\r\nimport com.bonait.bnframework.common.constant.ConfigName;\r\nimport com.bonait.bnframework.common.constant.Constants;\r\nimport com.bonait.bnframework.common.constant.DataBus;\r\nimport com.bonait.bnframework.common.db.QueryDB;\r\nimport com.bonait.bnframework.common.db.file.DBHelper;\r\nimport com.bonait.bnframework.common.db.mode.BPA_ALERTLOG;\r\nimport com.bonait.bnframework.common.db.mode.BPA_CLOUDDATA;\r\nimport com.bonait.bnframework.common.db.mode.BPA_GOODS;\r\nimport com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE;\r\nimport com.bonait.bnframework.common.db.mode.BPA_LOG;\r\nimport com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS;\r\nimport com.bonait.bnframework.common.db.mode.BPA_SILOS;\r\nimport com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL;\r\nimport com.bonait.bnframework.common.db.mode.BPA_USER;\r\nimport com.bonait.bnframework.common.db.res.AlertLogEnum;\r\nimport com.bonait.bnframework.common.db.res.ResGoodsRecipe;\r\nimport com.bonait.bnframework.common.db.res.UserLogEnum;\r\nimport com.bonait.bnframework.common.helper.CrashHandler;\r\nimport com.bonait.bnframework.common.helper.I.IMessageLogNotify;\r\nimport com.bonait.bnframework.common.helper.MessageLog;\r\nimport com.bonait.bnframework.common.helper.SdCart;\r\nimport com.bonait.bnframework.common.modbus.ModbusTcpHelper;\r\nimport com.bonait.bnframework.common.notification.MainNotification;\r\nimport com.bonait.bnframework.common.utils.AppUtils;\r\nimport com.bonait.bnframework.common.utils.NetworkUtils;\r\nimport com.bonait.bnframework.common.utils.PreferenceUtils;\r\nimport com.bonait.bnframework.common.utils.ToastUtils;\r\nimport com.bonait.bnframework.common.utils.WifiInterceptor;\r\nimport com.bonait.bnframework.manager.ActivityLifecycleManager;\r\nimport com.lzy.okgo.OkGo;\r\nimport com.lzy.okgo.cache.CacheEntity;\r\nimport com.lzy.okgo.cache.CacheMode;\r\nimport com.lzy.okgo.interceptor.HttpLoggingInterceptor;\r\nimport com.orhanobut.logger.AndroidLogAdapter;\r\nimport com.orhanobut.logger.FormatStrategy;\r\nimport com.orhanobut.logger.Logger;\r\nimport com.orhanobut.logger.PrettyFormatStrategy;\r\nimport com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager;\r\n\r\nimport org.litepal.LitePal;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.concurrent.TimeUnit;\r\nimport java.util.logging.Level;\r\n\r\nimport okhttp3.OkHttpClient;\r\n\r\npublic class MainInit {\r\n /**\r\n * 初始化\r\n * @param app\r\n */\r\n public static void Init(Application app)\r\n {\r\n //0.全局异常捕获,保存为SD卡本级目录 crash\r\n CrashHandler.getInstance().init(app);\r\n\r\n //1.设置程序active,初始化Main函数进程,初始化消息日志\r\n InitMsgLog();\r\n\r\n //2.初始化SD卡,数据库DB\r\n SdCart.getInstance().initSD();\r\n\r\n //4.初始化Main,并且增加本地图片库\r\n ConfigData.getInstance().AddImage(app);\r\n\r\n // activity生命周期管理\r\n ActivityLifecycleManager.get().init(app);\r\n\r\n // QMUI 框架初始化\r\n QMUISwipeBackActivityManager.init(app);\r\n\r\n // LitePal 数据库初始化\r\n LitePal.initialize(app);\r\n\r\n // 全局配置OkGo\r\n initOkGo(app);\r\n\r\n // 配置sharedPreferences\r\n PreferenceUtils.initPreference(app, AppUtils.getAppName(app), Activity.MODE_PRIVATE);\r\n\r\n // 初始化通知栏消息渠道\r\n MainNotification.initNotificationChannel(app);\r\n\r\n // 内存泄漏检测\r\n initLeakCanary(false);\r\n\r\n // Log日志打印框架\r\n initLogCat();\r\n\r\n // SmartShow Toast框架,暂时不用,先使用ToastUtils工具类的\r\n //SmartShow.init(this);\r\n\r\n //初始化DB数据\r\n InitDBdata();\r\n //ConfigData.getInstance().LoadingCloud();//加载云端数据\r\n\r\n DataBus.getInstance().GetTodayNoMake();\r\n\r\n //设置连接到有线网络\r\n // NetworkUtils.connetEnternet(app);\r\n }\r\n\r\n\r\n //========================================================================//\r\n public static void text()\r\n {\r\n String id=\"38f0a737-2476-40d8-a7d8-28ff7796e9d2\";\r\n BPA_GOODS gd=QueryDB.GetGoodsId(id);\r\n ArrayList PF=QueryDB.GetGoodsSrecipeID(id);\r\n ArrayList goods= QueryDB.GetGoodsALL();\r\n for (BPA_GOODS good:goods)\r\n {\r\n if(!good.id.equals(id))\r\n {\r\n for (BPA_GOODSRECIPE m:PF)\r\n {\r\n m.id=java.util.UUID.randomUUID().toString();\r\n m.goodsID=good.id;\r\n QueryDB.AddGoodsSrecipe(m);\r\n }\r\n }\r\n }\r\n\r\n\r\n\r\n\r\n\r\n }\r\n\r\n /**\r\n * 根据第一个配方重新写配方\r\n */\r\n public static void cx_cp()\r\n {\r\n ArrayList goods= QueryDB.GetGoodsALL();\r\n //38f0a737-2476-40d8-a7d8-28ff7796e9d2 鱼香肉丝\r\n //b414cef3-a315-4841-954a-abee17af02d6 重游发财\r\n\r\n\r\n String ydrs=\"dc2136ad-ee32-48c1-8077-afbdb80af9a3\";\r\n ArrayList ydrs_pf=QueryDB.GetGoodsSrecipeID(ydrs);\r\n\r\n\r\n String hc=\"b414cef3-a315-4841-954a-abee17af02d6\";\r\n ArrayList hc_pf=QueryDB.GetGoodsSrecipeID(hc);\r\n\r\n ArrayList rec= QueryDB.GetGoodsSrecipeALL();\r\n for (BPA_GOODSRECIPE pf:rec)\r\n {\r\n QueryDB.DeleteGoodsSrecipe(pf);\r\n }\r\n for (BPA_GOODS good:goods)\r\n {\r\n if(good.sort<=30)\r\n {\r\n for (BPA_GOODSRECIPE m:ydrs_pf)\r\n {\r\n m.id=java.util.UUID.randomUUID().toString();\r\n m.goodsID=good.id;\r\n QueryDB.AddGoodsSrecipe(m);\r\n }\r\n }else\r\n {\r\n for (BPA_GOODSRECIPE m:hc_pf)\r\n {\r\n m.id=java.util.UUID.randomUUID().toString();\r\n m.goodsID=good.id;\r\n QueryDB.AddGoodsSrecipe(m);\r\n }\r\n }\r\n }\r\n }\r\n /**\r\n * 初始化数据库数据(默认数据)\r\n */\r\n public static void InitDBdata() {\r\n //1.没有用户数据 默认写一个admin\r\n if (QueryDB.GetUserALL().size() <= 0) {\r\n BPA_USER user = new BPA_USER();\r\n user.id = \"20230415-fyf\";\r\n user.name = \"管理员\";\r\n user.account = \"admin\";\r\n user.pass = \"123456\";\r\n user.deviceID = ConfigName.getInstance().DeviceId;\r\n user.userID = \"20230415-fyf\";\r\n user.exp = \"管理员\";\r\n QueryDB.AddUser(user);\r\n\r\n ConfigData.getInstance().RevertPLCProcess();\r\n }\r\n }\r\n /**\r\n * 删除表-重新生成新表\r\n */\r\n public static void DBdelete()\r\n {\r\n// DBHelper.getInstance(this).DeleteCreateTables(BPA_CLOUDDATA.class,null);\r\n// DBHelper.getInstance(this).DeleteCreateTables(BPA_PLCADDRESS.class,null);\r\n }\r\n\r\n /**\r\n * 初始化消息日志接收打印\r\n */\r\n public static void InitMsgLog(){\r\n MessageLog.MsgNotify = new IMessageLogNotify() {\r\n @Override\r\n public void ErrorMsg(String msg) {\r\n if(msg.contains(\"msg:com.serotonin.modbus4j.exception\"))\r\n {\r\n ModbusTcpHelper.get().release();//释放modbus\r\n ConfigName.getInstance().PlcIsConnect=false;\r\n\r\n BPA_ALERTLOG log = new BPA_ALERTLOG();\r\n log.userID = ConfigName.getInstance().user.userID;\r\n log.type=4;\r\n log.text = msg+\"程序断开PLC,准备重连机制...\";\r\n QueryDB.AddAlertlog(log);\r\n }\r\n }\r\n @Override\r\n public void InfoMsg(String msg) {\r\n Log.i(\"Info\", msg);\r\n\r\n }\r\n @Override\r\n public void WarnMsg(String msg) {\r\n Log.w(\"Warn\", msg);\r\n }\r\n @Override\r\n public void UserMsg(UserLogEnum type, String msg) {\r\n BPA_LOG log = new BPA_LOG();\r\n log.userID = ConfigName.getInstance().user.userID;\r\n ToastUtils.info(msg);\r\n switch (type.toString())\r\n {\r\n case \"登录日志\":log.type=1;\r\n break;\r\n case \"角色操作日志\":log.type=2;\r\n break;\r\n case \"数据接收\":log.type=3;\r\n break;\r\n case \"上传日志\":log.type=4;\r\n break;\r\n case \"订单处理日志\":log.type=5;\r\n break;\r\n }\r\n log.text = msg;\r\n QueryDB.Addlog(log);\r\n }\r\n\r\n @Override\r\n public void AlertMsg(AlertLogEnum type, String msg) {\r\n BPA_ALERTLOG log = new BPA_ALERTLOG();\r\n log.userID = ConfigName.getInstance().user.userID;\r\n switch (type.toString())\r\n {\r\n case \"异常订单未制作日志\":log.type=1;\r\n break;\r\n case \"料仓缺料日志\":log.type=2;\r\n break;\r\n case \"传感器异常日志\":log.type=3;\r\n break;\r\n case \"其他\":log.type=4;\r\n break;\r\n }\r\n log.text = msg;\r\n\r\n QueryDB.AddAlertlog(log);\r\n }\r\n };\r\n }\r\n /**\r\n * 内存泄漏检测,根据flag来判断要不要初始化\r\n */\r\n private static void initLeakCanary(boolean flag) {\r\n if (flag) {\r\n // leak 内存检测注册\r\n// if (LeakCanary.isInAnalyzerProcess(this)) {\r\n// return;\r\n// }\r\n// LeakCanary.install(this);\r\n }\r\n }\r\n\r\n /**\r\n * 初始化log日志框架\r\n */\r\n private static void initLogCat() {\r\n FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()\r\n .showThreadInfo(false) // (可选)是否显示线程信息。 默认值为true\r\n .methodCount(2) // (可选)要显示的方法行数。 默认2\r\n .build();\r\n Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy) {\r\n @Override\r\n public boolean isLoggable(int priority, String tag) {\r\n return BuildConfig.DEBUG;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * 配置OkGo\r\n */\r\n private static void initOkGo(Application app) {\r\n\r\n //---------这里给出的是示例代码,告诉你可以这么传,实际使用的时候,根据需要传,不需要就不传-------------//\r\n /*HttpHeaders headers = new HttpHeaders();\r\n headers.put(\"commonHeaderKey1\", \"commonHeaderValue1\"); //header不支持中文,不允许有特殊字符\r\n headers.put(\"commonHeaderKey2\", \"commonHeaderValue2\");\r\n HttpParams params = new HttpParams();\r\n params.put(\"commonParamsKey1\", \"commonParamsValue1\"); //param支持中文,直接传,不要自己编码\r\n params.put(\"commonParamsKey2\", \"这里支持中文参数\");*/\r\n //----------------------------------------------------------------------------------------//\r\n\r\n OkHttpClient.Builder builder = new OkHttpClient.Builder();\r\n\r\n //log相关\r\n HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(\"OkGo\");\r\n //log打印级别,决定了log显示的详细程度\r\n loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY);\r\n //log颜色级别,决定了log在控制台显示的颜色\r\n loggingInterceptor.setColorLevel(Level.INFO);\r\n //添加OkGo默认debug日志\r\n builder.addInterceptor(loggingInterceptor);\r\n //builder.addInterceptor(new WifiInterceptor(app));\r\n //-------------------------配置超时时间,默认60000ms,60s------------------------------//\r\n //OkGo.DEFAULT_MILLISECONDS\r\n //全局的连接超时时间\r\n builder.connectTimeout(Constants.CONNECT_TIME_OUT, TimeUnit.MILLISECONDS);\r\n //全局的读取超时时间\r\n builder.readTimeout(Constants.CONNECT_TIME_OUT, TimeUnit.MILLISECONDS);\r\n //全局的写入超时时间\r\n builder.writeTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);\r\n OkGo.getInstance().init(app) //必须调用初始化\r\n .setOkHttpClient(builder.build()) //建议设置OkHttpClient,不设置将使用默认的\r\n .setCacheMode(CacheMode.NO_CACHE) //全局统一缓存模式,默认不使用缓存,可以不传\r\n .setCacheTime(CacheEntity.CACHE_NEVER_EXPIRE) //全局统一缓存时间,默认永不过期,可以不传\r\n .setRetryCount(0); //全局统一超时重连次数,默认为三次,那么最差的情况会请求4次(一次原始请求,三次重连请求),不需要可以设置为0\r\n //.addCommonParams(params); //全局公共参数\r\n\r\n }\r\n}\r\n
+Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
+<+>UTF-8
+===================================================================
+diff --git a/app/src/main/java/com/bonait/bnframework/business/MainInit.java b/app/src/main/java/com/bonait/bnframework/business/MainInit.java
+--- a/app/src/main/java/com/bonait/bnframework/business/MainInit.java (revision 1e67707b12981e019b49f3fb3f1b772d4a8d1662)
++++ b/app/src/main/java/com/bonait/bnframework/business/MainInit.java (date 1701246282625)
+@@ -9,30 +9,21 @@
+ import com.bonait.bnframework.common.constant.Constants;
+ import com.bonait.bnframework.common.constant.DataBus;
+ import com.bonait.bnframework.common.db.QueryDB;
+-import com.bonait.bnframework.common.db.file.DBHelper;
+ import com.bonait.bnframework.common.db.mode.BPA_ALERTLOG;
+-import com.bonait.bnframework.common.db.mode.BPA_CLOUDDATA;
+ import com.bonait.bnframework.common.db.mode.BPA_GOODS;
+ import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE;
+ import com.bonait.bnframework.common.db.mode.BPA_LOG;
+-import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS;
+-import com.bonait.bnframework.common.db.mode.BPA_SILOS;
+-import com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL;
+ import com.bonait.bnframework.common.db.mode.BPA_USER;
+ import com.bonait.bnframework.common.db.res.AlertLogEnum;
+-import com.bonait.bnframework.common.db.res.ResGoodsRecipe;
+ import com.bonait.bnframework.common.db.res.UserLogEnum;
+ import com.bonait.bnframework.common.helper.CrashHandler;
+ import com.bonait.bnframework.common.helper.I.IMessageLogNotify;
+ import com.bonait.bnframework.common.helper.MessageLog;
+ import com.bonait.bnframework.common.helper.SdCart;
+-import com.bonait.bnframework.common.modbus.ModbusTcpHelper;
+ import com.bonait.bnframework.common.notification.MainNotification;
+ import com.bonait.bnframework.common.utils.AppUtils;
+-import com.bonait.bnframework.common.utils.NetworkUtils;
+ import com.bonait.bnframework.common.utils.PreferenceUtils;
+ import com.bonait.bnframework.common.utils.ToastUtils;
+-import com.bonait.bnframework.common.utils.WifiInterceptor;
+ import com.bonait.bnframework.manager.ActivityLifecycleManager;
+ import com.lzy.okgo.OkGo;
+ import com.lzy.okgo.cache.CacheEntity;
+@@ -215,8 +206,8 @@
+ public void ErrorMsg(String msg) {
+ if(msg.contains("msg:com.serotonin.modbus4j.exception"))
+ {
+- ModbusTcpHelper.get().release();//释放modbus
+- ConfigName.getInstance().PlcIsConnect=false;
++ //ModbusTcpHelper.get().release();//释放modbus
++ //ConfigName.getInstance().PlcIsConnect=false;
+
+ BPA_ALERTLOG log = new BPA_ALERTLOG();
+ log.userID = ConfigName.getInstance().user.userID;
+Index: app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java
+IDEA additional info:
+Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
+<+>package com.bonait.bnframework.common.modbus;\r\n\r\nimport com.bonait.bnframework.business.ConfigData;\r\nimport com.bonait.bnframework.common.constant.ConfigName;\r\nimport com.bonait.bnframework.common.helper.DataFormat;\r\nimport com.bonait.bnframework.common.helper.I.IReadCallBack;\r\nimport com.bonait.bnframework.common.helper.I.IWriteCallBack;\r\nimport com.bonait.bnframework.common.helper.MessageLog;\r\nimport com.licheedev.modbus4android.ModbusCallback;\r\nimport com.licheedev.modbus4android.ModbusParam;\r\nimport com.licheedev.modbus4android.ModbusRespException;\r\nimport com.licheedev.modbus4android.param.SerialParam;\r\nimport com.serotonin.modbus4j.ModbusMaster;\r\nimport com.serotonin.modbus4j.exception.ModbusInitException;\r\nimport com.serotonin.modbus4j.exception.ModbusTransportException;\r\nimport com.serotonin.modbus4j.msg.ReadCoilsResponse;\r\nimport com.serotonin.modbus4j.msg.ReadHoldingRegistersResponse;\r\n\r\nimport java.io.UnsupportedEncodingException;\r\nimport java.nio.ByteBuffer;\r\nimport java.util.Arrays;\r\nimport java.util.concurrent.ExecutionException;\r\n\r\npublic class ModbusRTUServer {\r\n //region 单例模式\r\n private static volatile ModbusRTUServer instance = null;\r\n\r\n public static ModbusRTUServer get() {\r\n ModbusRTUServer manager = instance;\r\n if (manager == null) {\r\n synchronized (ModbusRTUServer.class) {\r\n manager = instance;\r\n if (manager == null) {\r\n manager = new ModbusRTUServer();\r\n instance = manager;\r\n }\r\n }\r\n }\r\n return manager;\r\n }\r\n private ModbusRTUServer() {\r\n }\r\n //endregion\r\n\r\n\r\n static ModbusParam param;\r\n\r\n /**适用于三菱PLC,只有X,Y,M,D区*/\r\n public static int GetAddress(String address){\r\n if (address == null) return -1;\r\n address = address.toUpperCase().trim();\r\n\r\n try {\r\n if (address.length() < 2) return Integer.parseInt(address);\r\n\r\n String res = address.substring(1);\r\n if (res == null) return -1;\r\n\r\n int startAddress=Integer.parseInt(res) ;\r\n //如果是M区地址。\r\n if (address.contains(\"M\")) {\r\n return startAddress + 4000;\r\n } else if (address.contains(\"D\")) {\r\n return startAddress;\r\n }else if(address.contains(\"X\")){\r\n return Integer.parseInt(res,8);\r\n }else if(address.contains(\"Y\")){\r\n return Integer.parseInt(res,8)+300;\r\n }else{\r\n return Integer.parseInt(address);\r\n }\r\n } catch (Exception e) {\r\n return -1;\r\n }\r\n }\r\n\r\n\r\n /** 连接PLC*/\r\n public void ConnectPLC()\r\n {\r\n int baudRate=ConfigName.getInstance().SerialBaudRate;\r\n int dataBits=ConfigName.getInstance().SerialDataBits;\r\n int parity=ConfigName.getInstance().SerialParity;\r\n int stopBits=ConfigName.getInstance().SerialStopBits;\r\n //String com=\"COM0\";\r\n\r\n param = SerialParam.create(\"/dev/ttyCOM1\", baudRate) // 串口地址和波特率\r\n .setDataBits(dataBits) // 数据位\r\n .setParity(parity) // 校验位\r\n .setStopBits(stopBits) // 停止位\r\n .setTimeout(3000).setRetries(0); // 不重试\r\n\r\n ModbusTcpHelper.get().init(param, new ModbusCallback() {\r\n @Override\r\n public void onSuccess(ModbusMaster modbusMaster) {\r\n //ToastUtils.info(\"串口 [\"+com+\"] 连接成功\");\r\n\r\n //MessageLog.ShowInfo(\"串口 [\"+com+\"] 连接成功\");\r\n ConfigName.getInstance().SerialIsConnect = true;\r\n ConfigData.getInstance().PLC_Init();\r\n }\r\n\r\n @Override\r\n public void onFailure(Throwable tr) {\r\n ConfigName.getInstance().SerialIsConnect = false;\r\n //ToastUtils.info(\"串口 [\"+com+\"] 连接失败:\" + tr.getMessage());\r\n //MessageLog.ShowError(\"串口 [\"+com+\"] 连接失败:\" + tr.getMessage());\r\n }\r\n @Override\r\n public void onFinally() {\r\n }\r\n });\r\n }\r\n\r\n\r\n //region 数据类型转换\r\n private Float BytesToFloat(byte[] buffers, DataFormat df) {\r\n if (buffers.length == 4) {\r\n byte[] bytes = new byte[4];\r\n if (df == DataFormat.ABCD) {\r\n bytes[0] = buffers[3];\r\n bytes[1] = buffers[2];\r\n bytes[2] = buffers[1];\r\n bytes[3] = buffers[0];\r\n } else if (df == DataFormat.CDAB) {\r\n bytes[0] = buffers[1];\r\n bytes[1] = buffers[0];\r\n bytes[2] = buffers[3];\r\n bytes[3] = buffers[2];\r\n } else if (df == DataFormat.BADC) {\r\n bytes[0] = buffers[2];\r\n bytes[1] = buffers[3];\r\n bytes[2] = buffers[0];\r\n bytes[3] = buffers[1];\r\n } else if (df == DataFormat.DCBA) {\r\n bytes[0] = buffers[0];\r\n bytes[1] = buffers[1];\r\n bytes[2] = buffers[2];\r\n bytes[3] = buffers[3];\r\n }\r\n return ByteBuffer.wrap(bytes).getFloat();\r\n }\r\n return 0.0f;\r\n }\r\n\r\n private Integer BytesToInt(byte[] buffers, DataFormat df) {\r\n if (buffers.length == 4) {\r\n byte[] bytes = new byte[4];\r\n if (df == DataFormat.ABCD) {\r\n bytes[0] = buffers[3];\r\n bytes[1] = buffers[2];\r\n bytes[2] = buffers[1];\r\n bytes[3] = buffers[0];\r\n } else if (df == DataFormat.CDAB) {\r\n bytes[0] = buffers[1];\r\n bytes[1] = buffers[0];\r\n bytes[2] = buffers[3];\r\n bytes[3] = buffers[2];\r\n } else if (df == DataFormat.BADC) {\r\n bytes[0] = buffers[2];\r\n bytes[1] = buffers[3];\r\n bytes[2] = buffers[0];\r\n bytes[3] = buffers[1];\r\n } else if (df == DataFormat.DCBA) {\r\n bytes[0] = buffers[0];\r\n bytes[1] = buffers[1];\r\n bytes[2] = buffers[2];\r\n bytes[3] = buffers[3];\r\n }\r\n return ByteBuffer.wrap(bytes).getInt();\r\n }\r\n return 0;\r\n }\r\n\r\n private byte[] IntToByte(int number) {\r\n int temp = number;\r\n byte[] b = new byte[4];\r\n for (int i = 0; i < b.length; i++) {\r\n b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位\r\n temp = temp >> 8; // 向右移8位\r\n }\r\n return b;\r\n }\r\n\r\n private short[] IntToShorts(int value) {\r\n short[] res = new short[2];\r\n int temp = value;\r\n byte[] b = new byte[4];\r\n for (int i = 0; i < b.length; i++) {\r\n b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位\r\n temp = temp >> 8; // 向右移8位\r\n }\r\n for (int i = 0; i < res.length; i++) {\r\n short s0 = (short) (b[i * 2] & 0xff);// 最低位\r\n short s1 = (short) (b[i * 2 + 1] & 0xff);\r\n s1 <<= 8;\r\n res[i] = (short) (s0 | s1);\r\n }\r\n return res;\r\n }\r\n\r\n public static String GetString(short[] src, int start, int len) throws UnsupportedEncodingException {\r\n short[] temp = new short[len];\r\n for (int i = 0; i < len; i++) {\r\n temp[i] = src[i + start];\r\n }\r\n byte[] bytesTemp = shorts2Bytes(temp);\r\n for (int i = 0; i < bytesTemp.length; i++) {\r\n byte b = bytesTemp[i];\r\n }\r\n String str = new String(bytesTemp, \"UTF-8\");\r\n return str;\r\n }\r\n\r\n public static byte[] shorts2Bytes(short[] data) {\r\n byte[] byteValue = new byte[data.length * 2];\r\n for (int i = 0; i < data.length; i++) {\r\n byteValue[i * 2] = (byte) (data[i] & 0xff);\r\n byteValue[i * 2 + 1] = (byte) ((data[i] & 0xff00) >> 8);\r\n }\r\n return byteValue;\r\n }\r\n //endregion\r\n\r\n //region 读取及写入方法\r\n\r\n /**写入字符串*/\r\n public void WriteString(int slaveAddress,String Address, int length, IWriteCallBack callback) {\r\n int add = GetAddress(Address);\r\n if (add < 0) return;\r\n short[] send = new short[length];\r\n for (short item : send) {\r\n item = 0;\r\n }\r\n try {\r\n ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, add, send);\r\n if (callback != null)\r\n callback.onSuccess();\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n }\r\n }\r\n\r\n /**写入字符串*/\r\n public void WriteString(int slaveAddress,int Address, short[] values, IWriteCallBack callback) {\r\n if (slaveAddress<0) return;\r\n if (Address < 0) return;\r\n if (values ==null || values.length==0) return;\r\n try {\r\n ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, values);\r\n if (callback != null)\r\n callback.onSuccess();\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"WriteString onFailure,Address=\" + Address + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"WriteString onFailure,Address=\" + Address + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"WriteString onFailure,Address=\" + Address + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"WriteString onFailure,Address=\" + Address + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"WriteString onFailure,Address=\" + Address + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n }\r\n }\r\n\r\n\r\n /**根据地址批量读取16位寄存器*/\r\n public void ReadShorts(int slaveAddress,int Address, int length, IReadCallBack callback) {\r\n //int add = GetAddress(Address);\r\n if (Address < 0) return;\r\n try {\r\n ReadHoldingRegistersResponse res = ModbusTcpHelper.get()\r\n .syncReadHoldingRegisters(slaveAddress, Address, length);\r\n short[] data = res.getShortData();\r\n if (data.length == length) {\r\n if (callback != null) callback.onSuccess(data);\r\n }\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"ReadShort onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"ReadShort onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"ReadShort onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"ReadShort onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"ReadShort onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n }\r\n }\r\n\r\n public void ReadBools(int slaveAddress,String Address, int length, IReadCallBack callback) {\r\n int add = GetAddress(Address);\r\n if (add < 0) return;\r\n try {\r\n ReadCoilsResponse res = ModbusTcpHelper.get()\r\n .syncReadCoil(slaveAddress, add, length);\r\n boolean[] data = res.getBooleanData();\r\n boolean[] result = Arrays.copyOfRange(data, 0, length);\r\n if (result.length == length) {\r\n if (callback != null) callback.onSuccess(result);\r\n }\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"ReadBool onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"ReadBool onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"ReadBool onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"ReadBool onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"ReadBool onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n }catch (Exception e){\r\n MessageLog.ShowError(\"ReadBool onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n }\r\n }\r\n\r\n public void ReadFloats(int slaveAddress,int Address, int length, IReadCallBack callback) {\r\n //int add = GetAddress(Address);\r\n if (Address < 0) return;\r\n try {\r\n ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(slaveAddress, Address, length*2);\r\n byte[] data = res.getData();\r\n float[] tempValues = new float[length];\r\n for (int i = 0; i < length; i++) {\r\n byte[] tempData = new byte[4];\r\n for (int m = 0; m < 4; m++) {\r\n tempData[m] = data[i * 4 + m];\r\n }\r\n tempValues[i] = BytesToFloat(tempData, DataFormat.BADC);\r\n }\r\n if (tempValues.length == length) {\r\n if (callback != null) callback.onSuccess(tempValues);\r\n }\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"ReadFloat onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"ReadFloat onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"ReadFloat onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"ReadFloat onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"ReadFloat onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n }\r\n }\r\n\r\n public void ReadInts(int slaveAddress,int Address, int length,DataFormat dataFormat, IReadCallBack callback) {\r\n //int add = GetAddress(Address);\r\n if (Address < 0) return;\r\n try {\r\n ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(slaveAddress, Address, length * 2);\r\n byte[] data = res.getData();\r\n int[] tempValues = new int[length];\r\n if(data.length>=4)\r\n {\r\n for (int i = 0; i < length; i++) {\r\n byte[] tempData = new byte[4];\r\n for (int m = 0; m < 4; m++) {\r\n tempData[m] = data[i * 4 + m];\r\n }\r\n tempValues[i] = BytesToInt(tempData, dataFormat);\r\n }\r\n }else\r\n {\r\n MessageLog.ShowError(\"ReadInt onFailure,Address=\" );\r\n\r\n }\r\n if (callback != null) callback.onSuccess(tempValues);\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"ReadInt onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"ReadInt onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"ReadInt onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"ReadInt onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"ReadInt onFailure,Address=\" + Address + \",length=\" + length + \",msg:\" + e.toString());\r\n }\r\n }\r\n\r\n public void WriteShort(int slaveAddress,int Address, short Value, IWriteCallBack callback) {\r\n //int add = GetAddress(Address);\r\n if (Address < 0) return;\r\n short[] send = new short[1];\r\n send[0] = Value;\r\n try {\r\n ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send);\r\n if (callback != null)\r\n callback.onSuccess();\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n }\r\n }\r\n\r\n public void WriteShorts(int slaveAddress,int Address, short[] Value, IWriteCallBack callback) {\r\n //int add = GetAddress(Address);\r\n if (Address < 0) return;\r\n try {\r\n ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, Value);\r\n if (callback != null)\r\n callback.onSuccess();\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n }\r\n }\r\n\r\n public void WriteBool(int slaveAddress,int Address, boolean Value, IWriteCallBack callback) {\r\n //int add = GetAddress(Address);\r\n if (Address < 0) return;\r\n try {\r\n ModbusTcpHelper.get().syncWriteCoil(slaveAddress, Address, Value);\r\n if (callback != null)\r\n callback.onSuccess();\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n }\r\n }\r\n\r\n public void WriteBools(int slaveAddress,int Address, boolean[] Value, IWriteCallBack callback) {\r\n //int add = GetAddress(Address);\r\n if (Address < 0) return;\r\n try {\r\n ModbusTcpHelper.get().syncWriteCoils(slaveAddress, Address, Value);\r\n if (callback != null)\r\n callback.onSuccess();\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n }\r\n }\r\n public void WriteFloat(int slaveAddress,int Address, float Value, IWriteCallBack callback) {\r\n //int add = GetAddress(Address);\r\n if (Address < 0) return;\r\n int intBits = Float.floatToRawIntBits(Value);\r\n short[] send = IntToShorts(intBits);\r\n try {\r\n ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send);\r\n\r\n if (callback != null) callback.onSuccess();\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"WriteFloat onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"WriteFloat onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"WriteFloat onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"WriteFloat onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"WriteFloat onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n }\r\n }\r\n\r\n public void WriteInt(int slaveAddress,int Address, int Value, IWriteCallBack callback) {\r\n //int add = GetAddress(Address);\r\n if (Address < 0) return;\r\n short[] send = IntToShorts(Value);\r\n try {\r\n ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send);\r\n if (callback != null) callback.onSuccess();\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"WriteInt onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"WriteInt onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"WriteInt onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"WriteInt onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"WriteInt onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n if (callback != null) callback.onFailure(e.toString());\r\n }\r\n }\r\n\r\n public void WriteShort(int slaveAddress,int Address, short Value) {\r\n //int add = GetAddress(Address);\r\n if (Address < 0) return;\r\n short[] send = new short[1];\r\n send[0] = Value;\r\n try {\r\n ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send);\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"WriteShort onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n }\r\n }\r\n\r\n public void WriteBool(int slaveAddress,int Address, boolean Value) {\r\n //int add = GetAddress(Address);\r\n if (Address < 0) return;\r\n\r\n try {\r\n ModbusTcpHelper.get().syncWriteCoil(slaveAddress, Address, Value);\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"WriteBool onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n }\r\n }\r\n\r\n public void WriteFloat(int slaveAddress,int Address, float Value) {\r\n //int add = GetAddress(Address);\r\n if (Address < 0) return;\r\n int intBits = Float.floatToRawIntBits(Value);\r\n short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)};\r\n try {\r\n ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send);\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"WriteFloat onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"WriteFloat onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"WriteFloat onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"WriteFloat onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"WriteFloat onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n }\r\n }\r\n\r\n public void WriteInt(int slaveAddress,int Address, int Value) {\r\n //int add = GetAddress(Address);\r\n if (Address < 0) return;\r\n short[] send = IntToShorts(Value);\r\n try {\r\n ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send);\r\n } catch (InterruptedException e) {\r\n MessageLog.ShowError(\"WriteInt onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ExecutionException e) {\r\n MessageLog.ShowError(\"WriteInt onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ModbusTransportException e) {\r\n MessageLog.ShowError(\"WriteInt onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ModbusInitException e) {\r\n MessageLog.ShowError(\"WriteInt onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n } catch (ModbusRespException e) {\r\n MessageLog.ShowError(\"WriteInt onFailure,Address=\" + Address + \",length=\" + Value + \",msg:\" + e.toString());\r\n }\r\n }\r\n\r\n //endregion\r\n}\r\n
+Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
+<+>UTF-8
+===================================================================
+diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java
+--- a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java (revision 1e67707b12981e019b49f3fb3f1b772d4a8d1662)
++++ b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java (date 1701245142553)
+@@ -84,7 +84,7 @@
+ int stopBits=ConfigName.getInstance().SerialStopBits;
+ //String com="COM0";
+
+- param = SerialParam.create("/dev/ttyCOM1", baudRate) // 串口地址和波特率
++ param = SerialParam.create("/dev/ttyCOM0", baudRate) // 串口地址和波特率
+ .setDataBits(dataBits) // 数据位
+ .setParity(parity) // 校验位
+ .setStopBits(stopBits) // 停止位
diff --git a/.idea/shelf/Uncommitted_changes_before_Checkout_at_2023_12_4_14_14__Changes_.xml b/.idea/shelf/Uncommitted_changes_before_Checkout_at_2023_12_4_14_14__Changes_.xml
new file mode 100644
index 00000000..4dc181f3
--- /dev/null
+++ b/.idea/shelf/Uncommitted_changes_before_Checkout_at_2023_12_4_14_14__Changes_.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/bonait/bnframework/business/MainInit.java b/app/src/main/java/com/bonait/bnframework/business/MainInit.java
index 8bc6e4af..56800c03 100644
--- a/app/src/main/java/com/bonait/bnframework/business/MainInit.java
+++ b/app/src/main/java/com/bonait/bnframework/business/MainInit.java
@@ -9,30 +9,21 @@ import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.constant.Constants;
import com.bonait.bnframework.common.constant.DataBus;
import com.bonait.bnframework.common.db.QueryDB;
-import com.bonait.bnframework.common.db.file.DBHelper;
import com.bonait.bnframework.common.db.mode.BPA_ALERTLOG;
-import com.bonait.bnframework.common.db.mode.BPA_CLOUDDATA;
import com.bonait.bnframework.common.db.mode.BPA_GOODS;
import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE;
import com.bonait.bnframework.common.db.mode.BPA_LOG;
-import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS;
-import com.bonait.bnframework.common.db.mode.BPA_SILOS;
-import com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL;
import com.bonait.bnframework.common.db.mode.BPA_USER;
import com.bonait.bnframework.common.db.res.AlertLogEnum;
-import com.bonait.bnframework.common.db.res.ResGoodsRecipe;
import com.bonait.bnframework.common.db.res.UserLogEnum;
import com.bonait.bnframework.common.helper.CrashHandler;
import com.bonait.bnframework.common.helper.I.IMessageLogNotify;
import com.bonait.bnframework.common.helper.MessageLog;
import com.bonait.bnframework.common.helper.SdCart;
-import com.bonait.bnframework.common.modbus.ModbusTcpHelper;
import com.bonait.bnframework.common.notification.MainNotification;
import com.bonait.bnframework.common.utils.AppUtils;
-import com.bonait.bnframework.common.utils.NetworkUtils;
import com.bonait.bnframework.common.utils.PreferenceUtils;
import com.bonait.bnframework.common.utils.ToastUtils;
-import com.bonait.bnframework.common.utils.WifiInterceptor;
import com.bonait.bnframework.manager.ActivityLifecycleManager;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;
@@ -215,8 +206,8 @@ public class MainInit {
public void ErrorMsg(String msg) {
if(msg.contains("msg:com.serotonin.modbus4j.exception"))
{
- ModbusTcpHelper.get().release();//释放modbus
- ConfigName.getInstance().PlcIsConnect=false;
+ //ModbusTcpHelper.get().release();//释放modbus
+ //ConfigName.getInstance().PlcIsConnect=false;
BPA_ALERTLOG log = new BPA_ALERTLOG();
log.userID = ConfigName.getInstance().user.userID;
diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java
index bd32c37c..377688a5 100644
--- a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java
+++ b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java
@@ -84,7 +84,7 @@ public class ModbusRTUServer {
int stopBits=ConfigName.getInstance().SerialStopBits;
//String com="COM0";
- param = SerialParam.create("/dev/ttyCOM1", baudRate) // 串口地址和波特率
+ param = SerialParam.create("/dev/ttyCOM0", baudRate) // 串口地址和波特率
.setDataBits(dataBits) // 数据位
.setParity(parity) // 校验位
.setStopBits(stopBits) // 停止位