Alarm.json
@@ -497,11 +497,132 @@ "type": "3", "page": "1" } ,{ "name": "B02.SR right in pos error", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "A01 servo turn homed", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "A02 servo turn homed", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "A01 servo travel homed", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "A02 servo travel homed", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "B01 servo travel homed", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "B02 servo travel homed", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "resetDelay", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "A01 travel Negative limit", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "A01 travel Positive limit", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "A01 turn up limit", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "A01 turn down limit", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "A02 travel Negative limit", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "A02 travel Positive limit", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "A02 turn up limit", "value": "1", "state": "1", "type": "3", "page": "1" } ,{ "name": "A02 turn down limit", "value": "1", "state": "1", "type": "3", "page": "1" },{ "name": "B01 travel Negative limit", "value": "1", "state": "1", "type": "3", "page": "1" },{ "name": "B01 travel Positive limit", "value": "1", "state": "1", "type": "3", "page": "1" },{ "name": "B02 travel Negative limit", "value": "1", "state": "1", "type": "3", "page": "1" },{ "name": "B02 travel Positive limit", "value": "1", "state": "1", "type": "3", "page": "1" } ], "address": [ { "name": "DB104.0.0", "count": 71 "count": 91 } ] } CanadaMes-ui/src/views/Electrical/Action.vue
@@ -4,8 +4,8 @@ <el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb"> <router-link to="/Electrical/ServoManualone" tag="el-button" type="text" active-class="blue-button">{{ $t('Alarm') }}</router-link> <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> <!-- <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> --> <!-- <router-link to="/Electrical/Action" tag="el-button" type="text" active-class="blue-button">{{ $t('Action') }}</router-link> --> <!-- <router-link to="/Electrical/Parameter" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter') CanadaMes-ui/src/views/Electrical/AutomaticParameterSetting.vue
@@ -3,8 +3,8 @@ <el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb"> <router-link to="/Electrical/alarm" tag="el-button" type="text" active-class="blue-button">{{ $t('Alarm') }}</router-link> <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> <!-- <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> --> <!-- <router-link to="/Electrical/Action" tag="el-button" type="text" active-class="blue-button">{{ $t('Action') }}</router-link> --> <!-- <router-link to="/Electrical/Parameter" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter') CanadaMes-ui/src/views/Electrical/InteractionState.vue
@@ -8,13 +8,13 @@ active-class="blue-button" >{{ $t("Alarm") }}</router-link > <router-link <!-- <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button" >{{ $t("State") }}</router-link > > --> <!-- <router-link to="/Electrical/Action" tag="el-button" CanadaMes-ui/src/views/Electrical/ManualonePosition.vue
@@ -3,8 +3,8 @@ <el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb"> <router-link to="/Electrical/alarm" tag="el-button" type="text" active-class="blue-button">{{ $t('Alarm') }}</router-link> <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> <!-- <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> --> <!-- <router-link to="/Electrical/Action" tag="el-button" type="text" active-class="blue-button">{{ $t('Action') }}</router-link> --> <!-- <router-link to="/Electrical/Parameter" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter') CanadaMes-ui/src/views/Electrical/Parameter2.vue
@@ -8,13 +8,13 @@ active-class="blue-button" >{{ $t("Alarm") }}</router-link > <router-link <!-- <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button" >{{ $t("State") }}</router-link > > --> <!-- <router-link to="/Electrical/Action" tag="el-button" CanadaMes-ui/src/views/Electrical/Positioning1.vue
@@ -8,13 +8,13 @@ active-class="blue-button" >{{ $t("Alarm") }}</router-link > <router-link <!-- <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button" >{{ $t("State") }}</router-link > > --> <!-- <router-link to="/Electrical/Action" tag="el-button" CanadaMes-ui/src/views/Electrical/ServoManualone.vue
@@ -8,13 +8,13 @@ active-class="blue-button" >{{ $t("Alarm") }}</router-link > <router-link <!-- <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button" >{{ $t("State") }}</router-link > > --> <!-- <router-link to="/Electrical/Action" tag="el-button" type="text" active-class="blue-button">{{ $t('Action') }}</router-link> --> <!-- <router-link to="/Electrical/Parameter" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter') CanadaMes-ui/src/views/Electrical/Servomanual.vue
@@ -3,8 +3,8 @@ <el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb"> <router-link to="/Electrical/alarm" tag="el-button" type="text" active-class="blue-button">{{ $t('Alarm') }}</router-link> <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> <!-- <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> --> <!-- <router-link to="/Electrical/Action" tag="el-button" type="text" active-class="blue-button">{{ $t('Action') }}</router-link> --> <!-- <router-link to="/Electrical/Parameter" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter') CanadaMes-ui/src/views/Electrical/Sign.vue
@@ -5,8 +5,8 @@ <router-link to="/Electrical/alarm" tag="el-button" type="text" active-class="blue-button">{{ $t('Alarm') }}</router-link> <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> <!-- <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> --> <!-- <router-link to="/Electrical/Action" tag="el-button" type="text" active-class="blue-button">{{ $t('Action') }}</router-link> --> <!-- <router-link to="/Electrical/Parameter" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter') CanadaMes-ui/src/views/Electrical/State.vue
@@ -5,8 +5,8 @@ <router-link to="/Electrical/alarm" tag="el-button" type="text" active-class="blue-button">{{ $t('Alarm') }}</router-link> <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> <!-- <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> --> <!-- <router-link to="/Electrical/Action" tag="el-button" type="text" active-class="blue-button">{{ $t('Action') }}</router-link> --> <!-- <router-link to="/Electrical/Parameter" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter') CanadaMes-ui/src/views/Electrical/alarm.vue
@@ -4,7 +4,7 @@ <el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb"> <router-link to="/Electrical/alarm" tag="el-button" type="text" active-class="blue-button">{{ $t('Alarm') }}</router-link> <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> <!-- <router-link to="/Electrical/State" tag="el-button" type="text" active-class="blue-button">{{ $t('State') }}</router-link> --> <!-- <router-link to="/Electrical/Action" tag="el-button" type="text" active-class="blue-button">{{ $t('Action') }}</router-link> --> <!-- <router-link to="/Electrical/Parameter" tag="el-button" type="text" active-class="blue-button">{{ $t('Parameter') }}</router-link> --> <router-link to="/Electrical/Sign" tag="el-button" type="text" active-class="blue-button">{{ $t('Sign') }}</router-link> CanadaMes-ui/src/views/home/index.vue
@@ -1011,7 +1011,7 @@ reset: false, isQueueWarning: false, CurrentFrame: [], DeviceList: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], DeviceList: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], GlassIdList: [], Scanningmethod: true, CurrrentGlassId: "" @@ -1045,12 +1045,14 @@ //console.log("收到数据====" + msg.data); let obj = JSON.parse(msg.data); if (obj.params != null) { this.car1 = 145 + 8.15 * Math.abs(obj.params[0][0] - this.carlist[0]['start']) / Math.abs(this.carlist[0]['end'] - this.carlist[0]['start']) * 100; this.car2 = 210 + 8.15 * Math.abs(obj.params[0][1] - this.carlist[1]['start']) / Math.abs(this.carlist[1]['end'] - this.carlist[1]['start']) * 100; var zhi1=obj.params[0][0]; var zhi2=obj.params[0][1]; this.car1 = 145 + 8.15 * Math.abs(zhi1 - this.carlist[0]['start']) / Math.abs(this.carlist[0]['end'] - this.carlist[0]['start']) * 100; this.car2 = 210 + 8.15 * Math.abs(zhi2 - this.carlist[1]['start']) / Math.abs(this.carlist[1]['end'] - this.carlist[1]['start']) * 100; // this.car1 = 210 + 11.25 * (obj.params[0][1]-this.carlist[1]['start'])/(this.carlist[1]['end']-this.carlist[1]['start'])*100; // this.car2 = 300 + 11.25 * (obj.params[0][1]-this.carlist[1]['start'])/(this.carlist[1]['end']-this.carlist[1]['start'])*100; } this.tableData = obj.tableData[0]; this.cagelist1 = obj.cagelist1[0]; this.cagelist2 = obj.cagelist2[0]; @@ -1072,10 +1074,11 @@ //查询当前铝框信息 this.CurrentFrame = obj.CurrentFrame; //获取设备状态 if (obj.DeviceList != null) { this.DeviceList = obj.DeviceList[0]; } // if (obj.DeviceList != null) { // this.DeviceList = obj.DeviceList[0]; // } //获取设备上的玻璃id if (obj.GlassIdList != null) { this.GlassIdList = obj.GlassIdList[0]; springboot-vue3/src/main/java/com/example/springboot/component/Plcalarm.java
@@ -28,7 +28,7 @@ FileInputStream fileInputStream; try { // 从文件中读取字节数据存入 fileInputStream fileInputStream = new FileInputStream("D:/canadames/Alarm.json"); fileInputStream = new FileInputStream("D:/code/canadames/Alarm.json"); // 读取 fileInputStream 中字节并将其解码为字符 InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "utf-8"); // 提高读取效率,在 BufferedReader 内包装 InputStreamReader springboot-vue3/src/main/java/com/example/springboot/component/Plchome.java
@@ -54,14 +54,9 @@ @Override public void run() { while (this != null) { JSONObject jsonObject = new JSONObject(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } JSONObject jsonObject = new JSONObject(); // 注入mapper homeMapper = WebSocketServer.applicationContext.getBean(HomeMapper.class); @@ -69,6 +64,9 @@ spianService = WebSocketServer.applicationContext.getBean(SpianService.class); outSliceServive = WebSocketServer.applicationContext.getBean(OutSliceServive.class); north_Glass_Buffer1Service = WebSocketServer.applicationContext.getBean(North_Glass_Buffer1Service.class); storageCageService = WebSocketServer.applicationContext.getBean(StorageCageService.class); dbserve = WebSocketServer.applicationContext.getBean(JdbcConnections.class); // 笼子使用情况 List<StorageCage> tableData = homeMapper.selectAll(); jsonObject.append("tableData", tableData); @@ -119,41 +117,46 @@ Out_slice CurrentFrame = outSliceServive.SelectCurrentFrame(); jsonObject.append("CurrentFrame", CurrentFrame); // List<Short> listd17 = S7control.getinstance().ReadWord("DB17.0",10); // String id=spianService.queGlassid("DB17.10", 14).toString(); // // String E01id = new String( S7controlLK.getinstance().ReadByte("DB17.0",16)); // String J01id = new String( S7controlLK.getinstance().ReadByte("DB17.22",14)); // 铝框线交互 try { if (CurrentFrame != null) { spianService.outmesid(CurrentFrame.getBarCode(), "DB17.0"); S7controlLK.getinstance().writeStrings(CurrentFrame.getBarCode(),"DB17.0"); } String E01id=S7controlLK.getinstance().readStrings("DB17.0"); String J01id=S7controlLK.getinstance().readStrings("DB17.22"); List<Short> framerequests = S7control.getinstance().ReadWord("铝框id请求字地址", 1); for (Short framerequest : framerequests) { List<Short> liststates=S7controlLK.getinstance().ReadWord("DB17.38", 1); List<Short> liststate=S7controlLK.getinstance().ReadWord("DB17.20", 1); Short framerequest = liststate.get(0); if (framerequest == 1) { // 铝框id String franmeno = spianService.queGlassid("DB17.10", 14).toString(); String position; try { position = dbserve.SelectPositionByFrameBarcode(franmeno); position = dbserve.SelectPositionByFrameBarcode(J01id); } catch (SQLException e) { // TODO Auto-generated catch block position = "0"; e.printStackTrace(); } Short send; if (position == "0") { if (position.equals("0")) { send = 0; } else { send = 1; } S7control.getinstance().WriteWord("铝框翻转发送地址", (short) send); S7controlLK.getinstance().WriteWord("DB17.38", (short) send); } } } catch (Exception e) { // TODO: handle exception } if (S7control.getinstance().CheckConnected() == true) { // 获取当前扫码方式 @@ -211,7 +214,6 @@ if (inglassInfo.size() > 0) { jsonObject.append("loadglassheight", inglassInfo.get(0) * 70); } } // // 获取铝框idDB106.DBW64,添加到出片队列 // String frameno="X21763329601FB"; @@ -268,8 +270,13 @@ } } storageCageService = WebSocketServer.applicationContext.getBean(StorageCageService.class); dbserve = WebSocketServer.applicationContext.getBean(JdbcConnections.class); } catch (InterruptedException e) { e.printStackTrace(); } boolean dbconnected = false; try { dbserve.getConn(); springboot-vue3/src/main/java/com/example/springboot/component/S7controlLK.java
New file @@ -0,0 +1,456 @@ package com.example.springboot.component; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.sql.Time; import java.util.ArrayList; import java.util.List; import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType; import com.github.xingshuangs.iot.protocol.s7.service.MultiAddressWrite; import com.github.xingshuangs.iot.protocol.s7.service.S7PLC; import com.google.common.primitives.Bytes; import org.apache.ibatis.jdbc.Null; public class S7controlLK { S7PLC s7PLC; // PLC通讯类实例 private EPlcType plcType = EPlcType.S1500; // 西门子PLC类型 private String ip = "192.168.10.101"; // plc ip地址 private int port = 102; // plc 端口号 private static volatile S7controlLK instance = null; private S7controlLK() { if (s7PLC == null) s7PLC = new S7PLC(plcType, ip, port, 0, 0); } // 单例模式 获取类的唯一实例 public static S7controlLK getinstance() { if (instance == null) { synchronized (S7controlLK.class) { if (instance == null) instance = new S7controlLK(); } } return instance; } /** * 关闭西门子s7通讯连接 */ public void CloseS7client() { if (s7PLC == null) s7PLC.close(); s7PLC.checkConnected(); } /** * s7通讯连接状态 */ public boolean CheckConnected() { return s7PLC.checkConnected(); } /** * 按指定的地址 写入一个word * * @param address 地址 * @param data word的值 */ public void WriteWord(String address, short data) { if (s7PLC == null) { return; } s7PLC.writeInt16(address, data); } /** * 从某地址连续 写入多个word * * @param address 地址 * @param datas word的值 */ public void WriteWord(String address, List<Short> datas) { if (s7PLC == null) return; // s7PLC.write(address, data); List<String> addresslist = GetAddressList(address, datas.size(), 16); MultiAddressWrite addressWrite = new MultiAddressWrite(); for (int i = 0; i < datas.size(); i++) { addressWrite.addInt16(addresslist.get(i), datas.get(i)); } s7PLC.writeMultiData(addressWrite); } /** * 按指定的地址 写入多个word * * @param address 地址 * @param datas word的值 */ /** * 按指定的地址 写入一个Bit * * @param address 地址 * @param data Bit的值 */ public void WriteBit(String address, Boolean data) { if (s7PLC == null) return; s7PLC.writeBoolean(address, data); } /** * 按指定的地址 写入多个bit * * @param address 地址 * @param datas bit的值 */ public void WriteBit(List<String> address, List<Boolean> datas) { if (s7PLC == null) return; // s7PLC.write(address, data); MultiAddressWrite addressWrite = new MultiAddressWrite(); for (int i = 0; i < address.size(); i++) { addressWrite.addBoolean(address.get(i), datas.get(i)); } s7PLC.writeMultiData(addressWrite); } /** * 从某地址连续 写入多个bit * * @param address 地址 * @param datas word的值 */ public void WriteBit(String address, List<Boolean> datas) { if (s7PLC == null) return; // s7PLC.write(address, data); List<String> addresslist = GetAddressList(address, datas.size(), 1); MultiAddressWrite addressWrite = new MultiAddressWrite(); for (int i = 0; i < datas.size(); i++) { addressWrite.addBoolean(addresslist.get(i), datas.get(i)); } s7PLC.writeMultiData(addressWrite); } /** * 按指定的地址 写入多个byte * * @param address 地址 * @param datas byte的值 */ public void WriteByte(String address, byte[] datas) { if (s7PLC == null) return; // s7PLC.write(address, data); s7PLC.writeByte(address, datas); } /** * 按指定的地址 读取word结果集 * * @param address 地址 * @return 结果 */ public List<Short> ReadWord(List<String> address) { if (s7PLC == null) return null; try { return s7PLC.readInt16(address); } catch (Exception e) { System.out.println("读取 " + address + " 失败:" + e.getMessage()); return null; } } private int getIndexFromAddress(String address) { // 可以解析出地址中的数字部分,并转换为整数 return 0; } private String getAddressFromIndex(int index) { // 整数转换为地址格式的字符串 return ""; } /** * 按指定的地址 读取word结果集 * * @param address 地址 * @param count 连续读多少个word * @return 结果 */ public List<Short> ReadWord(String address, int count) { if (s7PLC == null) return null; List<String> addresslist = GetAddressList(address, count, 16); try { return s7PLC.readInt16(addresslist); } catch (Exception e) { System.out.println("读取 " + address + " 失败:" + e.getMessage()); return null; } } /** * 按指定的地址 读取byte结果集 * * @param address 地址 * @param count 连续读多少个byte * @return 结果 */ public byte[] ReadByte(String address, int count) { if (s7PLC == null) return null; // List<String> addresslist = GetAddressList(address, count, 16); try { return s7PLC.readByte(address, count); } catch (Exception e) { // 处理异常 System.out.println("读取 " + address + " 失败:" + e.getMessage()); return null; } } /** * 按指定的地址 按bit位 0 flase 1 true 读取结果 * * @param addresslist 地址集 * @return Boolean结果 */ public List<Boolean> ReadBits(List<String> addresslist) { if (s7PLC == null) return null; return s7PLC.readBoolean(addresslist); } // 读取不连续地址bit public List<Boolean> readBits(List<String> addressList) { if (s7PLC == null || addressList.isEmpty()) { return null; } List<Boolean> values = new ArrayList<>(); for (String address : addressList) { try { boolean value = s7PLC.readBoolean(address); values.add(value); } catch (Exception e) { // 处理异常 System.out.println("读取 " + address + " 失败:" + e.getMessage()); } } return values; } // 读取String public List<String> readStrings(List<String> addressList) { if (s7PLC == null) { return null; } List<String> result = new ArrayList<>(); for (String address : addressList) { try { byte[] bytes = s7PLC.readByte(address, 14); if (bytes != null) { String str = new String(bytes, StandardCharsets.UTF_8); result.add(str); } } catch (Exception e) { System.out.println("读取 " + address + " 失败:" + e.getMessage()); result.add(null); } } return result; } public List<String> readStringsandword(List<String> addressList) { if (s7PLC == null) { return null; } List<String> result = new ArrayList<>(); for (String address : addressList) { try { if (address.contains("-")) { address = address.substring(0, address.indexOf("-")); byte[] bytes = s7PLC.readByte(address, 14); if (bytes != null) { String str = new String(bytes, StandardCharsets.UTF_8); result.add(str); } } else { Short value = s7PLC.readInt16(address); result.add(value.toString()); } } catch (Exception e) { System.out.println("读取 " + address + " 失败:" + e.getMessage()); result.add(null); } } return result; } // 不连续地址写入Word public void WriteWord(List<String> address, List<Short> datas) { if (s7PLC == null) return; for (int i = 0; i < address.size(); i++) { String addr = address.get(i); short data = datas.get(i); if (addr.contains("-")) { outmesid(String.valueOf(data), addr); // 单独处理带破折号的地址 } else { s7PLC.writeInt16(addr, data); // 将数据写入单个地址 } } } // 字符串写入 public void outmesid(String data, String addr) { // System.out.println("outmesid: " + data); List<Byte> glassidlist = new ArrayList<>(); String[] parts = addr.split("-"); if (parts.length == 2) { addr = parts[0]; // 只保留 "-" 前面的部分 } for (char iditem : data.toCharArray()) { glassidlist.add(Byte.valueOf(String.valueOf(iditem))); } byte[] bytes = Bytes.toArray(glassidlist); S7controlLK.getinstance().WriteByte(addr, bytes); } // 读取不连续word public List<Short> readWords(List<String> addresses) { if (s7PLC == null) { return null; } List<Short> data = new ArrayList<>(); for (String address : addresses) { try { // 单个地址 Short value = s7PLC.readInt16(address); data.add(value); } catch (Exception e) { System.out.println("读取 " + address + " 失败:" + e.getMessage()); } } return data; } // 读取时间 public Long readtime(String address) { if (s7PLC == null) return null; try { return s7PLC.readTime(address); } catch (Exception e) { System.out.println("读取 " + address + " 失败:" + e.getMessage()); return null; } } public void writetime(String address, long datas) { if (s7PLC == null) return; s7PLC.writeTime(address, datas); // 将数据写入单个地址 } private int extractAddressNumber(String address) { String numberStr = address.replaceAll("\\D+", ""); // 使用正则表达式提取数字部分 return Integer.parseInt(numberStr); } /** * 从指定的地址开始 连续按bit位读取 * * @param address 地址 * @param count 长度 * @return Boolean结果 */ public List<Boolean> ReadBits(String address, int count) { if (s7PLC == null) return null; List<String> addresslist = GetAddressList(address, count, 1); try { return s7PLC.readBoolean(addresslist); } catch (Exception e) { System.out.println("读取 " + address + " 失败:" + e.getMessage()); return null; } }; private List<String> GetAddressList(String address, int count, int addedbit) { List<String> addresslist = new ArrayList<String>(); String[] stringdatas = address.trim().split("\\."); if (stringdatas.length < 2 || !address.startsWith("DB")) return null; int dbwindex = 0; int bitindex = 0; if (stringdatas.length == 2) { dbwindex = Integer.parseInt(stringdatas[1]); } else if (stringdatas.length == 3) { dbwindex = Integer.parseInt(stringdatas[1]); bitindex = Integer.parseInt(stringdatas[2]); } else return null; addresslist.add(address); for (int i = 0; i < count - 1; i++) { int bitcurrent = bitindex + addedbit; if (bitcurrent > 7) { dbwindex += bitcurrent / 8; bitindex = 0; } else bitindex = bitcurrent; String endstr = stringdatas.length == 3 ? "." + bitindex : ""; addresslist.add(stringdatas[0] + "." + dbwindex + endstr); } return addresslist; } public void writeStrings(String data, String addr) { // List<Byte> glassidlist = new ArrayList<>(); String[] parts = addr.split("-"); if (parts.length == 2) { addr = parts[0]; } s7PLC.writeString(addr, data); } public String readStrings(String addr) { return s7PLC.readString(addr); } }