Merge remote-tracking branch 'origin/master'
| | |
| | | if (addressLength < 2) { |
| | | return null; |
| | | } |
| | | int wordindex = index; |
| | | return stringdatas[0] + "." + wordindex; |
| | | /* if (addressLength == 2) { |
| | | |
| | | if (addressLength == 2) { |
| | | int wordindex = index; |
| | | |
| | | return stringdatas[0] + "." + wordindex; |
| | | } |
| | |
| | | int wordindex = index; |
| | | int newIndex = wordindex + 13; |
| | | return stringdatas[0] + "." + wordindex + "-" + newIndex; |
| | | } |
| | | return null; |
| | | }*/ |
| | | // return null; |
| | | } |
| | | |
| | | public int getPlcAddress() { |
| | |
| | | } |
| | | if (plcParameterInfo.getAddressLength() == 2) { |
| | | plcParameterInfo.setValue(String.valueOf(byte2short(valueList))); |
| | | } else if (plcParameterInfo.getAddressLength() == 14) { |
| | | } else if (plcParameterInfo.getAddressLength() == 4) { |
| | | plcParameterInfo.setValue(String.valueOf(byte2int(valueList))); |
| | | } |
| | | else if (plcParameterInfo.getAddressLength() >10) { |
| | | plcParameterInfo.setValue((byteToHexString(valueList))); |
| | | } else { |
| | | String valuestr = new String(valueList); |
| | |
| | | return l; |
| | | } |
| | | |
| | | /** |
| | | * byte[]类型转short |
| | | * |
| | | * @param b byte[]类型值 |
| | | */ |
| | | public static short byte2int(byte[] b) { |
| | | short l = 0; |
| | | for (int i = 0; i < 4; i++) { |
| | | l <<= 8; //<<=和我们的 +=是一样的,意思就是 l = l << 8 |
| | | l |= (b[3-i] & 0xff); //和上面也是一样的 l = l | (b[i]&0xff) |
| | | } |
| | | return l; |
| | | } |
| | | public static String byteToHexString(byte[] bytes) { |
| | | |
| | | String str = new String(bytes, StandardCharsets.UTF_8); |
| | | String str = new String(bytes, StandardCharsets.UTF_8).trim(); |
| | | return str; |
| | | } |
| | | |
| | |
| | | } |
| | | mapValue.put(key, value); |
| | | } |
| | | |
| | | S7object.getinstance().plccontrol.WriteWord(S7object.getinstance().PlcMesObject.getPlcParameter("A06_request_word").getAddress(), (short)1); |
| | | try { |
| | | Thread.sleep(1000); |
| | | taskCacheService = WebSocketServer.applicationContext.getBean(TaskCacheService.class); |
| | | glassInfoService = WebSocketServer.applicationContext.getBean(GlassInfoService.class); |
| | | edgStorageCageService = WebSocketServer.applicationContext.getBean(EdgStorageCageService.class); |
| | | edgStorageCageDetailsMapper = WebSocketServer.applicationContext.getBean(EdgStorageCageDetailsMapper.class); |
| | | // initialize();//初始化数据 |
| | | if ("0".equals(mapValue.get("A06_request_word"))) { |
| | | if ("0".equals(S7object.getinstance().PlcMesObject.getPlcParameter("A06_request_word"))) { |
| | | //清除 |
| | | S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"), (short) 0); |
| | | } else if ("1".equals(mapValue.get("A06_request_word")) && |
| | | "0".equals(mapValue.get("MES_confirmation_word"))) { |
| | | } else if ("1".equals(S7object.getinstance().PlcMesObject.getPlcParameter("A06_request_word")) && |
| | | "0".equals(S7object.getinstance().PlcMesObject.getPlcParameter("MES_confirmation_word"))) { |
| | | |
| | | inTo(); |
| | | } else if ("2".equals(mapValue.get("A06_request_word")) && |
| | |
| | | package com.mes.common; |
| | | |
| | | import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType; |
| | | import com.mes.device.PlcParameterObject; |
| | | import com.mes.tools.InitUtil; |
| | | import com.mes.tools.S7control; |
| | | |
| | | |
| | | |
| | | /** |
| | | * @Author : zhoush |
| | | * @Date: 2024/4/9 15:13 |
| | | * @Description: |
| | | */ |
| | | public class S7object { |
| | | public class S7object extends Thread { |
| | | public S7control plccontrol; // PLC通讯类实例 |
| | | private EPlcType plcType = EPlcType.S1200; // 西门子PLC类型 |
| | | private String ip = "192.168.10.1"; // plc ip地址 |
| | | private int port = 102; // plc 端口号 |
| | | |
| | | |
| | | public PlcParameterObject PlcMesObject; |
| | | private static volatile S7object instance = null; |
| | | |
| | | private S7object() { |
| | | if (plccontrol == null) { |
| | | plccontrol = new S7control(plcType, ip, port, 0, 0); |
| | | |
| | | String PlcCacheGlass=S7object.class.getResource("/JsonFile/PlcCacheGlass.json").getPath(); |
| | | //log.info(PLCAutoMes.class.getResource("").getPath()); |
| | | PlcMesObject = InitUtil.initword(PlcCacheGlass); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | return instance; |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | while (this != null) { |
| | | try { |
| | | Thread.sleep(100); |
| | | |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | byte[] getplcvlues= plccontrol.ReadByte(PlcMesObject.getPlcAddressBegin(),PlcMesObject.getPlcAddressLength()); |
| | | PlcMesObject.setPlcParameterList(getplcvlues); |
| | | |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | { |
| | | "plcAddressBegin":"DB14.0", |
| | | "plcAddressLenght":"80", |
| | | "dataType":"word", |
| | | "parameteInfor":[ |
| | | { |
| | | "codeId": "A06_request_word", |
| | | "addressIndex":"0", |
| | | "addressLenght":"2", |
| | | "ratio":"1", |
| | | "unit":"m/min" |
| | | }, |
| | | { |
| | | "codeId": "A05_scanning_ID", |
| | | "addressIndex":"2", |
| | | "addressLenght":"30", |
| | | "ratio":"1", |
| | | "unit":"" |
| | | }, |
| | | { |
| | | "codeId": "MES_confirmation_word", |
| | | "addressIndex":"40", |
| | | "addressLenght":"2", |
| | | "ratio":"1", |
| | | "unit":"" |
| | | }, |
| | | { |
| | | "codeId": "A09_glass_status", |
| | | "addressIndex":"70", |
| | | "addressLenght":"2", |
| | | "ratio":"1", |
| | | "unit":"" |
| | | }, |
| | | { |
| | | "codeId": "A10_glass_status", |
| | | "addressIndex":"72", |
| | | "addressLenght":"2", |
| | | "ratio":"1", |
| | | "unit":"" |
| | | }, |
| | | { |
| | | "codeId": "A09_prohibit_film_production", |
| | | "addressIndex":"74", |
| | | "addressLenght":"2", |
| | | "ratio":"1", |
| | | "unit":"" |
| | | } |
| | | , |
| | | { |
| | | "codeId": "A10_prohibit_film_production", |
| | | "addressIndex":"76", |
| | | "addressLenght":"2", |
| | | "ratio":"1", |
| | | "unit":"" |
| | | } |
| | | ] |
| | | } |