| | |
| | | /** |
| | | * 读取状态 ====> 整块plc |
| | | */ |
| | | private void read(){ |
| | | private void read() throws InterruptedException { |
| | | OperateResultExOne<byte[]> result = melsecMcNet.Read("D101", (short) 30); |
| | | if (result.IsSuccess) { |
| | | for (int i = 1; i <= 8; i++) { |
| | |
| | | staProtocol.setStaNo(melsecMcNet.getByteTransform().TransInt16(result.Content, (i-1)*2+40)); // 目标站 |
| | | } |
| | | } |
| | | Thread.sleep(100); |
| | | OperateResultExOne<boolean[]> result1 = melsecMcNet.ReadBool("M800", (short) 64); |
| | | if (result1.IsSuccess) { |
| | | for (int i = 1; i <= 8; i++) { |
| | |
| | | melsecMcNet.ConnectClose(); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | public static void main(String[] args) throws Exception { |
| | | DevpSlave slave = new DevpSlave(); |
| | | slave.setIp("192.168.3.65"); |
| | | slave.setPort(6000); |
| | | DevpThread devpThread = new DevpThread(slave); |
| | | devpThread.connect(); |
| | | devpThread.read(); |
| | | System.out.println("第一次读"); |
| | | // 写 |
| | | StaProtocol staProtocol = devpThread.getStation().get(1); |
| | | staProtocol.setWorkNo((short) 232); |
| | | staProtocol.setStaNo((short) 6); |
| | | staProtocol.setAutoing(true); |
| | | staProtocol.setEmptyMk(true); |
| | | staProtocol.setInEnable(true); |
| | | devpThread.write(staProtocol); |
| | | System.out.println("----------------------------------------"); |
| | | // StaProtocol staProtocol = devpThread.getStation().get(1); |
| | | // staProtocol.setWorkNo((short) 232); |
| | | // staProtocol.setStaNo((short) 6); |
| | | // staProtocol.setAutoing(true); |
| | | // staProtocol.setEmptyMk(true); |
| | | // staProtocol.setInEnable(true); |
| | | // devpThread.write(staProtocol); |
| | | // System.out.println("----------------------------------------"); |
| | | Thread.sleep(400); |
| | | // 读 |
| | | devpThread.read(); |
| | | System.out.println("第二次读"); |
| | | System.out.println(JSON.toJSONString(devpThread.station)); |
| | | |
| | | } |