| New file |
| | |
| | | package com.example.springboot.component; |
| | | |
| | | import com.example.springboot.entity.device.PlcBitObject; |
| | | import com.example.springboot.entity.device.PlcParameterObject; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import static com.example.springboot.component.InitUtil.readAndUpdateBitValues; |
| | | import static com.example.springboot.component.InitUtil.readAndUpdateWordValues; |
| | | |
| | | public class PLCAutomaticParameterSettingReview2 extends Thread { |
| | | |
| | | // 用于存储应用程序的配置信息 |
| | | private Configuration config; |
| | | private static InitUtil initUtil; |
| | | // 创建一个自定义的 S7 控制器消息处理器对象 |
| | | MessageHandler customS7Control = new MessageHandler(); |
| | | |
| | | // 单例实例 |
| | | private static PLCAutomaticParameterSettingReview2 instance; |
| | | |
| | | // 私有构造函数 |
| | | public PLCAutomaticParameterSettingReview2() throws IOException { |
| | | config = new Configuration("config.properties"); |
| | | initUtil = new InitUtil(); |
| | | } |
| | | |
| | | // 获取单例实例 |
| | | public static synchronized PLCAutomaticParameterSettingReview2 getInstance() throws IOException { |
| | | if (instance == null) { |
| | | instance = new PLCAutomaticParameterSettingReview2(); |
| | | } |
| | | return instance; |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | while (this != null) { |
| | | try { |
| | | Thread.sleep(1000); |
| | | |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | String jsonFilePath = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcParameter.json").getPath(); |
| | | String jsonFilePath2 = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcSign.json").getPath(); |
| | | String jsonFilePath4 = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcState.json").getPath(); |
| | | //System.out.println(jsonFilePath4); |
| | | |
| | | |
| | | // 调用initword方法 |
| | | PlcParameterObject plcParameterObject = initUtil.initword(jsonFilePath); |
| | | PlcParameterObject plcStateObject = initUtil.initword(jsonFilePath4); |
| | | |
| | | // 调用initbit方法 |
| | | PlcBitObject plcBitObject = initUtil.initbit(jsonFilePath2); |
| | | readAndUpdateBitValues(plcBitObject); |
| | | readAndUpdateWordValues(plcParameterObject); |
| | | readAndUpdateWordValues(plcStateObject); |
| | | // List<Boolean> getplcvlues = S7control.getinstance().ReadBits(plcBitObject.getPlcAddressBegin(), plcBitObject.getPlcAddressLength()); |
| | | // plcBitObject.setPlcBitList(getplcvlues); |
| | | |
| | | // int index = plcParameterObject.getPlcParameter("A01A02conveyorVelocity(Max)").getAddressIndex(); |
| | | // System.out.println(index); |
| | | // plcParameterObject.getPlcParameter("A01A02conveyorVelocity(Max)").getAddress(index); |
| | | // System.out.println(plcParameterObject.getPlcParameter("A01A02conveyorVelocity(Max)").getAddress(index)); |
| | | // S7control.getinstance().WriteWord(plcParameterObject.getPlcParameter("conveyorVelocity(AutoFAST)").getAddress(index), (short) 100); |
| | | // List<String> addresses = new ArrayList<>(); |
| | | // addresses.add("conveyorVelocity(AutoFAST)"); |
| | | // addresses.add("A02ID"); |
| | | //System.out.println(plcParameterObject.getPlcParameterValues(addresses)); |
| | | List<String> addresses2 = new ArrayList<>(); |
| | | addresses2.add("D01.SRdec"); |
| | | addresses2.add("D01.SRinpos"); |
| | | addresses2.add("D05.SRinpos"); |
| | | |
| | | |
| | | |
| | | |
| | | System.out.println(plcBitObject.getPlcBitValues(addresses2)); |
| | | |
| | | int index2 = plcBitObject.getPlcBit("D05.SRinpos").getAddressIndex(); |
| | | System.out.println(index2); |
| | | |
| | | plcBitObject.getPlcBit("D05.SRinpos").getAddress(index2); |
| | | System.out.println(plcBitObject.getPlcBit("D05.SRinpos").getAddress(index2)); |
| | | // |
| | | // |
| | | // List<String> addresses3 = new ArrayList<>(); |
| | | // addresses3.add("A02ID1"); |
| | | // addresses3.add("A01CurrentGrid"); |
| | | // System.out.println(plcStateObject.getPlcParameterValues(addresses3)); |
| | | } |
| | | } |
| | | } |