| | |
| | | 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.Arrays; |
| | | 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 static PlcParameterObject plcParameterObject; |
| | | // 用于存储应用程序的配置信息 |
| | | private Configuration config; |
| | | private static InitUtil initUtil; |
| | | // 创建一个自定义的 S7 控制器消息处理器对象 |
| | | MessageHandler customS7Control = new MessageHandler(); |
| | | |
| | | // public static PlcParameterObject plcStateObject; |
| | | |
| | | // 单例实例 |
| | | private static PLCAutomaticParameterSettingReview2 instance; |
| | |
| | | // 私有构造函数 |
| | | public PLCAutomaticParameterSettingReview2() throws IOException { |
| | | config = new Configuration("config.properties"); |
| | | initUtil = new InitUtil(); |
| | | // initUtil = new InitUtil(); |
| | | } |
| | | |
| | | // 获取单例实例 |
| | |
| | | } |
| | | return instance; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void run() { |
| | |
| | | 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); |
| | | |
| | | |
| | | // 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); |
| | | // plcParameterObject = initUtil.initword(jsonFilePath); |
| | | // plcStateObject = initUtil.initword(jsonFilePath4); |
| | | |
| | | // 调用initbit方法 |
| | | PlcBitObject plcBitObject = initUtil.initbit(jsonFilePath2); |
| | | readAndUpdateBitValues(plcBitObject); |
| | | readAndUpdateWordValues(plcParameterObject); |
| | | readAndUpdateWordValues(plcStateObject); |
| | | // 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)); |
| | | // PlcBitObject plcBitObject = initUtil.initbit(jsonFilePath2); |
| | | |
| | | // int index3 = plcParameterObject.getPlcParameter("A01A02conveyorVelocity(Max)").getAddressIndex(); |
| | | // System.out.println(index3); |
| | | // System.out.println(plcParameterObject.getPlcParameter("A01A02conveyorVelocity(Max)").getAddress(index3)); |
| | | |
| | | |
| | | // readAndUpdateBitValues(plcBitObject); |
| | | // readAndUpdateWordValues(plcParameterObject); |
| | | // readAndUpdateWordValues(plcStateObject); |
| | | |
| | | // List<String> addresses = new ArrayList<>(); |
| | | // addresses.add("conveyorVelocity(AutoFAST)"); |
| | | // addresses.add("A02ID"); |
| | | // addresses.add("conveyorVelocity(Manual)"); |
| | | List<String> addresses = new ArrayList<>(); |
| | | addresses.add("conveyorVelocity(AutoFAST)"); |
| | | addresses.add("A02ID"); |
| | | addresses.add("conveyorVelocity(Manual)"); |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | List<String> address = PLCAutomaticParameterSettingReview2.plcParameterObject.getAddressListByCodeId(addresses); |
| | | System.out.println(address); |
| | | |
| | | // List<String> address = plcParameterObject.getAddressListByCodeId(addresses); |
| | | // System.out.println(address); |
| | | |
| | | // int index = plcParameterObject.getPlcParameter("A01turnAngle1").getAddressIndex(); |
| | | // List<Short> arraylist = S7control.getinstance().ReadWord(plcParameterObject.getPlcParameter("A01turnAngle1").getAddress(index), 8); |
| | | |
| | | |
| | | // List<Boolean> getplcvlues = S7control.getinstance().ReadBits(plcBitObject.getPlcAddressBegin(), plcBitObject.getPlcAddressLength()); |
| | | // plcBitObject.setPlcBitList(getplcvlues); |
| | | |
| | | |
| | | // 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("conveyorVelocity(AutoSLOW)"); |
| | | addresses2.add("D01.SRdec"); |
| | | |
| | | |
| | | |
| | | System.out.println(plcBitObject.getPlcBitValues(addresses2)); |
| | | |
| | | int index2 = plcBitObject.getPlcBit("DO1id").getAddressIndex(); |
| | | System.out.println(index2); |
| | | |
| | | plcBitObject.getPlcBit("DO1id").getAddress(index2); |
| | | System.out.println(plcBitObject.getPlcBit("DO1id").getAddress(index2)); |
| | | |
| | | |
| | | List<String> addresses3 = new ArrayList<>(); |
| | | addresses3.add("A02ID1"); |
| | | addresses3.add("A01CurrentGrid"); |
| | | System.out.println(plcStateObject.getPlcParameterValues(addresses3)); |
| | | // 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)); |
| | | } |
| | | } |
| | | } |