diff --git a/.idea/git_toolbox_blame.xml b/.idea/git_toolbox_blame.xml
new file mode 100644
index 00000000..7dc12496
--- /dev/null
+++ b/.idea/git_toolbox_blame.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ExceptionServer.java b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ExceptionServer.java
index ff88b851..32bf6b29 100644
--- a/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ExceptionServer.java
+++ b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ExceptionServer.java
@@ -32,6 +32,10 @@ public class ExceptionServer {
}
}
+ public ExceptionServer(){
+
+ }
+
public int GetAddress(String address) {
MessageLog.ShowInfo("GetAddress address="+address);
if (address == null) return -1;
diff --git a/app/src/main/java/com/bonait/bnframework/business/PlcReadHelper.java b/app/src/main/java/com/bonait/bnframework/business/PlcReadHelper.java
new file mode 100644
index 00000000..606842cc
--- /dev/null
+++ b/app/src/main/java/com/bonait/bnframework/business/PlcReadHelper.java
@@ -0,0 +1,114 @@
+package com.bonait.bnframework.business;
+
+import com.bonait.bnframework.HBL.Communication.Modbus.ExceptionServer;
+import com.bonait.bnframework.common.constant.ConfigName;
+import com.bonait.bnframework.common.db.mode.Res_PLCADDRESS;
+import com.bonait.bnframework.modbus.WokModbusTcpServer;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class PlcReadHelper {
+ public PlcReadHelper(){
+
+ }
+
+ public LinkedHashMap PlcStatus=new LinkedHashMap<>();
+ LinkedHashMap>> addGroup =new LinkedHashMap<>();
+ public void Init(){
+ List PlcAdd = ConfigName.getInstance().PlcAddress_Wok.stream().filter(p->p.isread==1).collect(Collectors.toList());
+ if(PlcAdd!=null && PlcAdd.size()>0){
+ //地址转换对象
+ ExceptionServer es = new ExceptionServer();
+
+ //Bool数据类型分组
+ List boolData = PlcAdd.stream().filter(p->p.address.toUpperCase().contains("M")).collect(Collectors.toList());
+ if(boolData!=null&&boolData.size()>0){
+ List boolReadModel = new ArrayList<>();
+ boolData.forEach(item->{ boolReadModel.add(new ReadModel(item.name,item.address,es.GetAddress(item.address)));});
+ addGroup.put("M",groupBy(boolReadModel));
+ }
+
+ //Short数据类型分组
+ List shortData = PlcAdd.stream().filter(p->p.address.toUpperCase().contains("VW")).collect(Collectors.toList());
+ if(shortData!=null&&shortData.size()>0){
+ List shortReadModel = new ArrayList<>();
+ shortData.forEach(item->{ shortReadModel.add(new ReadModel(item.name,item.address,es.GetAddress(item.address)));});
+ addGroup.put("VW",groupBy(shortReadModel));
+ }
+
+ //int 数据类型分组
+ List intData = PlcAdd.stream().filter(p->p.address.toUpperCase().contains("VD")).collect(Collectors.toList());
+ if(intData!=null&&intData.size()>0){
+ List intReadModel = new ArrayList<>();
+ intData.forEach(item->{ intReadModel.add(new ReadModel(item.name,item.address,es.GetAddress(item.address)));});
+ addGroup.put("VD",groupBy(intReadModel));
+ }
+
+ //float数据类型分组
+ List floatData = PlcAdd.stream().filter(p->p.address.toUpperCase().contains("VR")).collect(Collectors.toList());
+ if(floatData!=null&&floatData.size()>0){
+ List floatReadModel = new ArrayList<>();
+ floatData.forEach(item->{ floatReadModel.add(new ReadModel(item.name,item.address,es.GetAddress(item.address)));});
+ addGroup.put("VR",groupBy(floatReadModel));
+ }
+ }
+ }
+
+ public void read(){
+ for(Map.Entry>> item:addGroup.entrySet()){
+ for(Map.Entry> add:addGroup.get(item.getKey()).entrySet()){
+ if (item.getKey().startsWith("VD"))//int
+ {
+ WokModbusTcpServer.get().ReadInt(add.getValue().get(0).plcAddress, add.getValue().size(), ints -> {
+ for (int i = 0; i < ints.length; i++) {
+ PlcStatus.put(add.getValue().get(i).name,ints[i]);
+ }
+ });
+ } else if (item.getKey().startsWith("M"))//bool
+ {
+ WokModbusTcpServer.get().ReadBool(add.getValue().get(0).plcAddress, add.getValue().size(), val -> {
+ for (int i = 0; i < val.length; i++) {
+ PlcStatus.put(add.getValue().get(i).name,val[i]);
+ }
+ });
+ } else if (item.getKey().startsWith("VW"))//short
+ {
+ WokModbusTcpServer.get().ReadShort(add.getValue().get(0).plcAddress, add.getValue().size(), val -> {
+ for (int i = 0; i < val.length; i++) {
+ PlcStatus.put(add.getValue().get(i).name,val[i]);
+ }
+ });
+ } else if (item.getKey().startsWith("VR"))//float
+ {
+ WokModbusTcpServer.get().ReadFloat(add.getValue().get(0).plcAddress, add.getValue().size(), val -> {
+ for (int i = 0; i < val.length; i++) {
+ PlcStatus.put(add.getValue().get(i).name,val[i]);
+ }
+ });
+ }
+ }
+ }
+ }
+
+ public LinkedHashMap> groupBy(List data){
+ if(data==null) return new LinkedHashMap<>();
+ Collections.sort(data, Comparator.comparingInt(ReadModel::getModbusAddress));//进行排序
+ LinkedHashMap> result = new LinkedHashMap<>();
+ int groupNum=0;
+ for(ReadModel value:data){
+ if(!result.containsKey(groupNum) || result.get(groupNum).get(result.get(groupNum).size()-1).getModbusAddress()+1!=value.getModbusAddress()){
+ groupNum++;
+ }
+ if(!result.containsKey(groupNum))result.put(groupNum,new ArrayList<>());
+ result.get(groupNum).add(value);
+ }
+ return result;
+ }
+
+}
diff --git a/app/src/main/java/com/bonait/bnframework/business/ReadModel.java b/app/src/main/java/com/bonait/bnframework/business/ReadModel.java
new file mode 100644
index 00000000..f24c672a
--- /dev/null
+++ b/app/src/main/java/com/bonait/bnframework/business/ReadModel.java
@@ -0,0 +1,21 @@
+package com.bonait.bnframework.business;
+
+public class ReadModel {
+ public String name;
+ public String plcAddress;
+ private int modbusAddress;
+
+ public ReadModel(String name, String plcAddress, int modbusAddress) {
+ this.name = name;
+ this.plcAddress = plcAddress;
+ this.modbusAddress = modbusAddress;
+ }
+
+ public int getModbusAddress() {
+ return modbusAddress;
+ }
+
+ public void setModbusAddress(int modbusAddress) {
+ this.modbusAddress = modbusAddress;
+ }
+}
diff --git a/app/src/main/java/com/bonait/bnframework/newui/activity/MainHActivity.java b/app/src/main/java/com/bonait/bnframework/newui/activity/MainHActivity.java
index b116c4e5..dffd4068 100644
--- a/app/src/main/java/com/bonait/bnframework/newui/activity/MainHActivity.java
+++ b/app/src/main/java/com/bonait/bnframework/newui/activity/MainHActivity.java
@@ -22,6 +22,7 @@ import com.bonait.bnframework.MainApplication;
import com.bonait.bnframework.business.ConfigData;
import com.bonait.bnframework.business.ExecuteTheRecipe;
import com.bonait.bnframework.business.ExecuteTheRecipe2;
+import com.bonait.bnframework.business.PlcReadHelper;
import com.bonait.bnframework.common.base.BaseActivity;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.db.file.DBHelper;
@@ -141,6 +142,10 @@ public class MainHActivity extends BaseActivity {
}else {
PreferenceUtils.setInt("loginNum",loginNum+1);
}
+
+// PlcReadHelper plc = new PlcReadHelper();
+// plc.Init();
+// plc.read();
}
private void init(){