From af63c05a971e41d56ab656f93f3249a68d845ea8 Mon Sep 17 00:00:00 2001 From: liuhanqing Date: Wed, 10 Dec 2025 10:01:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 29 + images/0.jpg | Bin 0 -> 15249 bytes images/1.gif | Bin 0 -> 1634 bytes images/11.gif | Bin 0 -> 1706 bytes images/12.gif | Bin 0 -> 361 bytes images/a.gif | Bin 0 -> 1227 bytes images/calendar.jpg | Bin 0 -> 1644 bytes images/excel.gif | Bin 0 -> 142 bytes images/his.gif | Bin 0 -> 370 bytes images/login.gif | Bin 0 -> 7688 bytes images/mar.gif | Bin 0 -> 180 bytes images/now.gif | Bin 0 -> 202 bytes images/tr.gif | Bin 0 -> 3485 bytes images/任务查询.gif | Bin 0 -> 1270 bytes images/作业查询.gif | Bin 0 -> 1272 bytes images/堆垛机.gif | Bin 0 -> 1272 bytes images/�车.gif | Bin 0 -> 1049 bytes images/红.gif | Bin 0 -> 499 bytes images/红22.gif | Bin 0 -> 390 bytes images/红22.jpg | Bin 0 -> 32436 bytes images/红23.gif | Bin 0 -> 403 bytes images/红25.gif | Bin 0 -> 431 bytes images/绿.gif | Bin 0 -> 515 bytes images/绿23.gif | Bin 0 -> 404 bytes images/绿23.jpg | Bin 0 -> 30728 bytes images/绿24.gif | Bin 0 -> 417 bytes images/绿25.gif | Bin 0 -> 434 bytes images/设备监控.gif | Bin 0 -> 1240 bytes images/调度�作.gif | Bin 0 -> 1271 bytes images/调度日志.gif | Bin 0 -> 1261 bytes images/黄.gif | Bin 0 -> 529 bytes images/黄25.gif | Bin 0 -> 445 bytes images/黄25.jpg | Bin 0 -> 25692 bytes out/production/ft503-wcs/META-INF/MANIFEST.MF | 3 + .../dss/ats/customs/abb/model/BasZxlx.hbm.xml | 32 + .../abb/model/CarDeviceExecutionQueue.hbm.xml | 46 + .../ats/customs/abb/model/KzxcSsjMsg.hbm.xml | 17 + .../ats/customs/abb/model/LineStatus.hbm.xml | 18 + .../abb/model/RgvDeviceExecutionQueue.hbm.xml | 71 + .../RgvDeviceExecutionQueueFinish.hbm.xml | 71 + .../dss/ats/customs/abb/model/RgvMsg.hbm.xml | 20 + .../dss/ats/customs/abb/model/SsjMsg.hbm.xml | 14 + .../wms/dss/ats/customs/abb/model/end.hbm.xml | 15 + .../com/wms/dss/ats/customs/abb/plc/备注.txt | 1 + out/production/ft503-wcs/log4j.properties | 41 + src/META-INF/MANIFEST.MF | 3 + .../intelligt/modbus/jlibmodbus/Modbus.java | 338 + .../intelligt/modbus/jlibmodbus/Version.java | 42 + .../modbus/jlibmodbus/data/CommStatus.java | 304 + .../modbus/jlibmodbus/data/DataHolder.java | 215 + .../jlibmodbus/data/DataHolderBuilder.java | 67 + .../jlibmodbus/data/ExceptionStatus.java | 28 + .../modbus/jlibmodbus/data/FifoQueue.java | 58 + .../modbus/jlibmodbus/data/ModbusCoils.java | 124 + .../modbus/jlibmodbus/data/ModbusFile.java | 65 + .../data/ModbusHoldingRegisters.java | 199 + .../modbus/jlibmodbus/data/ModbusValues.java | 62 + .../data/SimpleDataHolderBuilder.java | 95 + .../data/SimpleExceptionStatus.java | 45 + .../jlibmodbus/data/SimpleFifoQueue.java | 65 + .../jlibmodbus/data/SimpleModbusFile.java | 59 + .../modbus/jlibmodbus/data/SimpleSlaveId.java | 43 + .../modbus/jlibmodbus/data/SlaveId.java | 28 + .../jlibmodbus/data/comm/ModbusCommEvent.java | 80 + .../ModbusCommEventEnterListenOnlyMode.java | 32 + ...ommEventInitiatedCommunicationRestart.java | 33 + .../data/comm/ModbusCommEventReceive.java | 65 + .../data/comm/ModbusCommEventSend.java | 83 + .../ReadDeviceIdentificationInterface.java | 186 + .../exception/AcknowledgeException.java | 44 + .../GatewayPathUnavailableException.java | 41 + ...yTargetDeviceFailedToRespondException.java | 39 + .../IllegalDataAddressException.java | 58 + .../exception/IllegalDataValueException.java | 46 + .../exception/IllegalFunctionException.java | 52 + .../exception/MemoryParityErrorException.java | 44 + .../exception/ModbusChecksumException.java | 35 + .../exception/ModbusIOException.java | 37 + .../exception/ModbusMasterException.java | 33 + .../exception/ModbusNumberException.java | 32 + .../exception/ModbusProtocolException.java | 39 + .../exception/ModbusSlaveException.java | 33 + .../exception/SlaveDeviceBusyException.java | 41 + .../SlaveDeviceFailureException.java | 38 + .../jlibmodbus/master/ModbusMaster.java | 777 ++ .../jlibmodbus/master/ModbusMasterASCII.java | 44 + .../master/ModbusMasterFactory.java | 77 + .../jlibmodbus/master/ModbusMasterRTU.java | 40 + .../jlibmodbus/master/ModbusMasterSerial.java | 172 + .../jlibmodbus/master/ModbusMasterTCP.java | 185 + .../jlibmodbus/msg/ModbusMessageFactory.java | 41 + .../jlibmodbus/msg/ModbusRequestBuilder.java | 406 + .../jlibmodbus/msg/ModbusRequestFactory.java | 119 + .../jlibmodbus/msg/ModbusResponseFactory.java | 123 + .../msg/base/AbstractDataRequest.java | 72 + .../msg/base/AbstractMultipleRequest.java | 63 + .../msg/base/AbstractReadResponse.java | 69 + .../base/AbstractWriteMultipleRequest.java | 82 + .../msg/base/AbstractWriteResponse.java | 73 + .../jlibmodbus/msg/base/ModbusFileRecord.java | 78 + .../jlibmodbus/msg/base/ModbusMessage.java | 102 + .../jlibmodbus/msg/base/ModbusRequest.java | 115 + .../jlibmodbus/msg/base/ModbusResponse.java | 87 + .../msg/base/mei/ConformityLevel.java | 50 + .../jlibmodbus/msg/base/mei/MEIFactory.java | 37 + .../base/mei/MEIReadDeviceIdentification.java | 237 + .../base/mei/ModbusEncapsulatedInterface.java | 48 + .../mei/ReadDeviceIdentificationCode.java | 48 + .../msg/request/DiagnosticsRequest.java | 218 + ...EncapsulatedInterfaceTransportRequest.java | 101 + .../request/GetCommEventCounterRequest.java | 79 + .../msg/request/GetCommEventLogRequest.java | 83 + .../msg/request/IllegalFunctionRequest.java | 80 + .../msg/request/MaskWriteRegisterRequest.java | 116 + .../msg/request/ReadCoilsRequest.java | 81 + .../ReadDeviceIdentificationRequest.java | 42 + .../request/ReadDiscreteInputsRequest.java | 70 + .../request/ReadExceptionStatusRequest.java | 84 + .../msg/request/ReadFifoQueueRequest.java | 85 + .../msg/request/ReadFileRecordRequest.java | 132 + .../request/ReadHoldingRegistersRequest.java | 79 + .../request/ReadInputRegistersRequest.java | 70 + .../ReadWriteMultipleRegistersRequest.java | 132 + .../msg/request/ReportSlaveIdRequest.java | 84 + .../msg/request/WriteFileRecordRequest.java | 122 + .../request/WriteMultipleCoilsRequest.java | 103 + .../WriteMultipleRegistersRequest.java | 123 + .../msg/request/WriteSingleCoilRequest.java | 78 + .../request/WriteSingleRegisterRequest.java | 107 + .../msg/response/BroadcastResponse.java | 59 + .../msg/response/DiagnosticsResponse.java | 79 + ...ncapsulatedInterfaceTransportResponse.java | 74 + .../response/GetCommEventCounterResponse.java | 77 + .../msg/response/GetCommEventLogResponse.java | 116 + .../msg/response/IllegalFunctionResponse.java | 63 + .../response/MaskWriteRegisterResponse.java | 74 + .../msg/response/ReadCoilsResponse.java | 92 + .../response/ReadDiscreteInputsResponse.java | 36 + .../response/ReadExceptionStatusResponse.java | 66 + .../msg/response/ReadFifoQueueResponse.java | 86 + .../msg/response/ReadFileRecordResponse.java | 97 + .../ReadHoldingRegistersResponse.java | 87 + .../response/ReadInputRegistersResponse.java | 36 + .../ReadWriteMultipleRegistersResponse.java | 36 + .../msg/response/ReportSlaveIdResponse.java | 73 + .../msg/response/WriteFileRecordResponse.java | 87 + .../response/WriteMultipleCoilsResponse.java | 51 + .../WriteMultipleRegistersResponse.java | 51 + .../msg/response/WriteSingleCoilResponse.java | 51 + .../response/WriteSingleRegisterResponse.java | 73 + .../jlibmodbus/net/ModbusConnection.java | 92 + .../jlibmodbus/net/ModbusConnectionASCII.java | 32 + .../net/ModbusConnectionFactory.java | 47 + .../jlibmodbus/net/ModbusConnectionRTU.java | 32 + .../net/ModbusConnectionSerial.java | 86 + .../net/ModbusMasterConnectionTCP.java | 97 + .../net/ModbusSlaveConnectionTCP.java | 94 + .../net/stream/InputStreamASCII.java | 91 + .../jlibmodbus/net/stream/InputStreamRTU.java | 70 + .../net/stream/InputStreamSerial.java | 50 + .../jlibmodbus/net/stream/InputStreamTCP.java | 77 + .../net/stream/OutputStreamASCII.java | 88 + .../net/stream/OutputStreamRTU.java | 40 + .../net/stream/OutputStreamSerial.java | 32 + .../net/stream/OutputStreamTCP.java | 57 + .../net/stream/base/LoggingInputStream.java | 85 + .../net/stream/base/LoggingOutputStream.java | 98 + .../net/stream/base/ModbusInputStream.java | 89 + .../net/stream/base/ModbusOutputStream.java | 75 + .../net/transport/ModbusTransport.java | 96 + .../net/transport/ModbusTransportASCII.java | 34 + .../net/transport/ModbusTransportFactory.java | 42 + .../net/transport/ModbusTransportRTU.java | 33 + .../net/transport/ModbusTransportSerial.java | 60 + .../net/transport/ModbusTransportTCP.java | 78 + .../jlibmodbus/serial/SerialParameters.java | 92 + .../modbus/jlibmodbus/serial/SerialPort.java | 175 + .../jlibmodbus/serial/SerialPortAT.java | 142 + .../serial/SerialPortAbstractFactory.java | 51 + .../serial/SerialPortException.java | 32 + .../serial/SerialPortFactoryAT.java | 54 + .../serial/SerialPortFactoryJSSC.java | 42 + .../serial/SerialPortFactoryJSerialComm.java | 47 + .../serial/SerialPortFactoryLoopback.java | 49 + .../serial/SerialPortFactoryPJC.java | 64 + .../serial/SerialPortFactoryRXTX.java | 63 + .../serial/SerialPortFactoryTcpClient.java | 169 + .../serial/SerialPortFactoryTcpServer.java | 209 + .../jlibmodbus/serial/SerialPortJSSC.java | 105 + .../serial/SerialPortJSerialComm.java | 142 + .../jlibmodbus/serial/SerialPortLoopback.java | 123 + .../jlibmodbus/serial/SerialPortPJC.java | 187 + .../jlibmodbus/serial/SerialPortRXTX.java | 187 + .../modbus/jlibmodbus/serial/SerialUtils.java | 95 + .../serial/ValidatorSerialPortFactory.java | 50 + .../modbus/jlibmodbus/slave/ModbusSlave.java | 211 + .../jlibmodbus/slave/ModbusSlaveASCII.java | 44 + .../jlibmodbus/slave/ModbusSlaveFactory.java | 87 + .../jlibmodbus/slave/ModbusSlaveRTU.java | 39 + .../jlibmodbus/slave/ModbusSlaveSerial.java | 116 + .../jlibmodbus/slave/ModbusSlaveTCP.java | 147 + .../jlibmodbus/slave/RequestHandler.java | 54 + .../slave/RequestHandlerSerial.java | 118 + .../jlibmodbus/slave/RequestHandlerTCP.java | 98 + .../modbus/jlibmodbus/tcp/TcpAduHeader.java | 106 + .../modbus/jlibmodbus/tcp/TcpParameters.java | 97 + .../modbus/jlibmodbus/utils/ByteFifo.java | 102 + .../modbus/jlibmodbus/utils/CRC16.java | 106 + .../modbus/jlibmodbus/utils/DataUtils.java | 183 + .../utils/DiagnosticsSubFunctionCode.java | 89 + .../modbus/jlibmodbus/utils/FrameEvent.java | 40 + .../jlibmodbus/utils/FrameEventListener.java | 34 + .../utils/FrameEventListenerList.java | 40 + .../utils/FrameEventListenerListImpl.java | 71 + .../modbus/jlibmodbus/utils/LRC.java | 37 + .../modbus/jlibmodbus/utils/MEITypeCode.java | 52 + .../jlibmodbus/utils/ModbusExceptionCode.java | 61 + .../jlibmodbus/utils/ModbusFunctionCode.java | 151 + .../utils/ModbusSlaveSerialObserver.java | 22 + .../utils/ModbusSlaveTcpObserver.java | 22 + .../jlibmodbus/utils/SerialPortInfo.java | 28 + .../jlibmodbus/utils/TcpClientInfo.java | 30 + .../ats/customs/abb/entity/BasDevice.hbm.xml | 20 + .../dss/ats/customs/abb/entity/BasDevice.java | 41 + .../customs/abb/entity/BasFaultRecord.hbm.xml | 43 + .../customs/abb/entity/BasFaultRecord.java | 121 + .../ats/customs/abb/entity/CMP_Device.java | 45 + .../ats/customs/abb/entity/DDJ_Device.java | 54 + .../ats/customs/abb/entity/JXS_Device.java | 39 + .../customs/abb/entity/JxsFinishCpj.hbm.xml | 27 + .../ats/customs/abb/entity/JxsFinishCpj.java | 59 + .../ats/customs/abb/entity/JxsJobMsg.hbm.xml | 41 + .../dss/ats/customs/abb/entity/JxsJobMsg.java | 104 + .../dss/ats/customs/abb/entity/JxsMsg.hbm.xml | 23 + .../dss/ats/customs/abb/entity/JxsMsg.java | 50 + .../dss/ats/customs/abb/entity/MsgCmp.hbm.xml | 32 + .../dss/ats/customs/abb/entity/MsgCmp.java | 113 + .../dss/ats/customs/abb/entity/MsgDdj.hbm.xml | 47 + .../dss/ats/customs/abb/entity/MsgDdj.java | 122 + .../dss/ats/customs/abb/entity/MsgJxs.hbm.xml | 35 + .../dss/ats/customs/abb/entity/MsgJxs.java | 86 + .../ats/customs/abb/entity/MsgRkkSsj.hbm.xml | 41 + .../dss/ats/customs/abb/entity/MsgRkkSsj.java | 104 + .../ats/customs/abb/entity/MsgXdkSsj.hbm.xml | 32 + .../dss/ats/customs/abb/entity/MsgXdkSsj.java | 77 + .../ats/customs/abb/entity/MydoJob.hbm.xml | 105 + .../dss/ats/customs/abb/entity/MydoJob.java | 303 + .../ats/customs/abb/entity/OpenLed.hbm.xml | 39 + .../dss/ats/customs/abb/entity/OpenLed.java | 94 + .../dss/ats/customs/abb/entity/RKK_SSJ.java | 58 + .../dss/ats/customs/abb/entity/SendData.java | 39 + .../customs/abb/entity/StoredParameters.java | 37 + .../customs/abb/entity/SysDictData.hbm.xml | 29 + .../ats/customs/abb/entity/SysDictData.java | 51 + .../ats/customs/abb/entity/WcsCmpIn.hbm.xml | 30 + .../dss/ats/customs/abb/entity/WcsCmpIn.java | 50 + .../entity/WmsDeviceExecutionQueue.hbm.xml | 73 + .../abb/entity/WmsDeviceExecutionQueue.java | 176 + .../dss/ats/customs/abb/entity/XDK_SSJ.java | 36 + .../ats/customs/abb/form/ABBMainFrame.java | 25 + .../ats/customs/abb/form/StartCorrespond.java | 156 + .../ats/customs/abb/form/StopCorrespond.java | 148 + src/com/wms/dss/ats/customs/abb/led/LED1.java | 187 + src/com/wms/dss/ats/customs/abb/led/LED2.java | 185 + src/com/wms/dss/ats/customs/abb/led/LED3.java | 183 + .../ats/customs/abb/modbus/Modbus4jUtils.java | 335 + .../ats/customs/abb/modbus/ModbusService.java | 156 + .../dss/ats/customs/abb/modbus/ValueType.java | 17 + .../wms/dss/ats/customs/abb/plc/HslRead.java | 105 + .../ats/customs/abb/plc/IsoTcpClientDDJ1.java | 304 + .../ats/customs/abb/plc/IsoTcpClientDDJ2.java | 293 + .../ats/customs/abb/plc/IsoTcpClientDDJ3.java | 294 + .../ats/customs/abb/plc/IsoTcpClientSSJ.java | 863 ++ .../customs/abb/plc/PLCCorrespondService.java | 45 + .../dss/ats/customs/abb/plc/ReadPLCDDJ1.java | 36 + .../dss/ats/customs/abb/plc/ReadPLCDDJ2.java | 37 + .../dss/ats/customs/abb/plc/ReadPLCDDJ3.java | 37 + .../dss/ats/customs/abb/plc/ReadPLCSSJ.java | 152 + .../dss/ats/customs/abb/plc/Readdd_PLC.java | 23 + src/com/wms/dss/ats/customs/abb/plc/备注.txt | 1 + .../abb/schedule/ABBThreadSchedule.java | 68 + .../ats/customs/abb/schedule/DDJ1Thread.java | 434 + .../ats/customs/abb/schedule/DDJ2Thread.java | 423 + .../ats/customs/abb/schedule/DDJ3Thread.java | 426 + .../ats/customs/abb/schedule/DDJService.java | 330 + .../dss/ats/customs/abb/schedule/DbGet.java | 383 + .../customs/abb/schedule/SSJ_CMP_Thread.java | 929 ++ .../customs/abb/schedule/SSJ_JXS_Thread.java | 447 + .../customs/abb/schedule/SSJ_ONE_Thread.java | 309 + .../abb/schedule/ThreadCK_SSJ_LED.java | 112 + .../wms/dss/ats/customs/abb/test/Test.java | 26 + .../customs/abb/utils/AllocatePropUtils.java | 526 + .../ats/customs/abb/utils/CheckWeight.java | 106 + .../ats/customs/abb/utils/ConstantUtils.java | 242 + .../dss/ats/customs/abb/utils/HTTPREST.java | 34 + .../customs/abb/utils/HttpClientUtility.java | 196 + .../ats/customs/abb/utils/HttpConnection.java | 109 + .../ats/customs/abb/utils/LEDSender2010.java | 3230 ++++++ .../wms/dss/ats/customs/abb/utils/LZSS.java | 164 + .../ats/customs/abb/utils/MyUdpSocket.java | 94 + .../dss/ats/customs/abb/utils/ParseUtil.java | 538 + .../ats/customs/abb/utils/ProtocolDemo.java | 949 ++ .../customs/abb/utils/QueryDbDataUtils.java | 527 + .../wms/dss/ats/customs/abb/utils/Tools.java | 502 + .../wms/dss/ats/customs/abb/utils/UtilId.java | 13 + .../wms/dss/ats/customs/abb/utils/ZsGet.java | 100 + src/log4j.properties | 41 + src/org/libnodave/Nodave.java | 589 ++ src/org/libnodave/PDU.java | 520 + src/org/libnodave/PLCinterface.java | 108 + src/org/libnodave/Result.java | 35 + src/org/libnodave/ResultSet.java | 47 + src/org/libnodave/S7Connection.java | 590 ++ src/org/libnodave/TCPConnection.java | 108 + src/org/libnodave/tests/PlcTcpClient.java | 83 + src/org/libnodave/tests/TestISOTCP2.java | 269 + src/org/s7/standard/ynuo/PlcBus.java | 39 + src/org/s7/standard/ynuo/PlcInterface.java | 9 + .../standard/ynuo/ReadAreaPlcInterface.java | 486 + .../s7/standard/ynuo/ReadDotPlcInterface.java | 49 + .../ynuo/ReadPlcDBAnalyServer101.java | 248 + .../ynuo/ReadPlcDBAnalyServer102.java | 247 + .../ynuo/ReadPlcDBAnalyServer103.java | 76 + .../ynuo/ReadPlcDBAnalyServer104.java | 425 + .../ynuo/ReadPlcDBAnalyServer171.java | 3054 ++++++ .../standard/ynuo/WriteDotPlcInterface.java | 155 + .../standard/ynuo/client/IsoTcpClient100.java | 800 ++ .../standard/ynuo/client/IsoTcpClient101.java | 804 ++ .../standard/ynuo/client/IsoTcpClient102.java | 860 ++ .../standard/ynuo/client/IsoTcpClient103.java | 371 + .../standard/ynuo/client/IsoTcpClient104.java | 1371 +++ .../standard/ynuo/client/IsoTcpClient171.java | 9204 +++++++++++++++++ wcs.iml | 21 + wmsdssconfig/abb/actionRelation.xml | 9 + wmsdssconfig/abb/carcommand31.dat | Bin 0 -> 5 bytes wmsdssconfig/abb/cranecommand1.dat | Bin 0 -> 5 bytes wmsdssconfig/abb/cranecommand2.dat | Bin 0 -> 5 bytes wmsdssconfig/abb/exectask1.dat | Bin 0 -> 84 bytes wmsdssconfig/abb/exectask2.dat | Bin 0 -> 84 bytes wmsdssconfig/abb/hibernate.cfg.xml | 37 + wmsdssconfig/abb/opcItemconfig.xml | 442 + wmsdssconfig/abb/ssxcommand1.dat | Bin 0 -> 5 bytes wmsdssconfig/abb/ssxcommand2.dat | Bin 0 -> 84 bytes wmsdssconfig/abb/ssxcommandLC1.dat | Bin 0 -> 5 bytes wmsdssconfig/abb/wmsdssconfig.xml | 255 + wmsdssconfig/dssconfig.properties | 4 + 346 files changed, 54556 insertions(+) create mode 100644 .gitignore create mode 100644 images/0.jpg create mode 100644 images/1.gif create mode 100644 images/11.gif create mode 100644 images/12.gif create mode 100644 images/a.gif create mode 100644 images/calendar.jpg create mode 100644 images/excel.gif create mode 100644 images/his.gif create mode 100644 images/login.gif create mode 100644 images/mar.gif create mode 100644 images/now.gif create mode 100644 images/tr.gif create mode 100644 images/任务查询.gif create mode 100644 images/作业查询.gif create mode 100644 images/堆垛机.gif create mode 100644 images/�车.gif create mode 100644 images/红.gif create mode 100644 images/红22.gif create mode 100644 images/红22.jpg create mode 100644 images/红23.gif create mode 100644 images/红25.gif create mode 100644 images/绿.gif create mode 100644 images/绿23.gif create mode 100644 images/绿23.jpg create mode 100644 images/绿24.gif create mode 100644 images/绿25.gif create mode 100644 images/设备监控.gif create mode 100644 images/调度�作.gif create mode 100644 images/调度日志.gif create mode 100644 images/黄.gif create mode 100644 images/黄25.gif create mode 100644 images/黄25.jpg create mode 100644 out/production/ft503-wcs/META-INF/MANIFEST.MF create mode 100644 out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/BasZxlx.hbm.xml create mode 100644 out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/CarDeviceExecutionQueue.hbm.xml create mode 100644 out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/KzxcSsjMsg.hbm.xml create mode 100644 out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/LineStatus.hbm.xml create mode 100644 out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/RgvDeviceExecutionQueue.hbm.xml create mode 100644 out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/RgvDeviceExecutionQueueFinish.hbm.xml create mode 100644 out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/RgvMsg.hbm.xml create mode 100644 out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/SsjMsg.hbm.xml create mode 100644 out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/end.hbm.xml create mode 100644 out/production/ft503-wcs/com/wms/dss/ats/customs/abb/plc/备注.txt create mode 100644 out/production/ft503-wcs/log4j.properties create mode 100644 src/META-INF/MANIFEST.MF create mode 100644 src/com/intelligt/modbus/jlibmodbus/Modbus.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/Version.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/CommStatus.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/DataHolder.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/DataHolderBuilder.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/ExceptionStatus.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/FifoQueue.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/ModbusCoils.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/ModbusFile.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/ModbusHoldingRegisters.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/ModbusValues.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/SimpleDataHolderBuilder.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/SimpleExceptionStatus.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/SimpleFifoQueue.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/SimpleModbusFile.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/SimpleSlaveId.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/SlaveId.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEvent.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventEnterListenOnlyMode.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventInitiatedCommunicationRestart.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventReceive.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventSend.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/data/mei/ReadDeviceIdentificationInterface.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/AcknowledgeException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/GatewayPathUnavailableException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/GatewayTargetDeviceFailedToRespondException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/IllegalDataAddressException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/IllegalDataValueException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/IllegalFunctionException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/MemoryParityErrorException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/ModbusChecksumException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/ModbusIOException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/ModbusMasterException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/ModbusNumberException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/ModbusProtocolException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/ModbusSlaveException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/SlaveDeviceBusyException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/exception/SlaveDeviceFailureException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/master/ModbusMaster.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterASCII.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterFactory.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterRTU.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterSerial.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterTCP.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/ModbusMessageFactory.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/ModbusRequestBuilder.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/ModbusRequestFactory.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/ModbusResponseFactory.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractDataRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractMultipleRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractReadResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractWriteMultipleRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractWriteResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusFileRecord.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusMessage.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/mei/ConformityLevel.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/mei/MEIFactory.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/mei/MEIReadDeviceIdentification.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/mei/ModbusEncapsulatedInterface.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/base/mei/ReadDeviceIdentificationCode.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/DiagnosticsRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/EncapsulatedInterfaceTransportRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/GetCommEventCounterRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/GetCommEventLogRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/IllegalFunctionRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/MaskWriteRegisterRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/ReadCoilsRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/ReadDeviceIdentificationRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/ReadDiscreteInputsRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/ReadExceptionStatusRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/ReadFifoQueueRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/ReadFileRecordRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/ReadHoldingRegistersRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/ReadInputRegistersRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/ReadWriteMultipleRegistersRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/ReportSlaveIdRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/WriteFileRecordRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/WriteMultipleCoilsRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/WriteMultipleRegistersRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/WriteSingleCoilRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/request/WriteSingleRegisterRequest.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/BroadcastResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/DiagnosticsResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/EncapsulatedInterfaceTransportResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/GetCommEventCounterResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/GetCommEventLogResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/IllegalFunctionResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/MaskWriteRegisterResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/ReadCoilsResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/ReadDiscreteInputsResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/ReadExceptionStatusResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/ReadFifoQueueResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/ReadFileRecordResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/ReadHoldingRegistersResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/ReadInputRegistersResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/ReadWriteMultipleRegistersResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/ReportSlaveIdResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/WriteFileRecordResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/WriteMultipleCoilsResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/WriteMultipleRegistersResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/WriteSingleCoilResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/msg/response/WriteSingleRegisterResponse.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/ModbusConnection.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionASCII.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionFactory.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionRTU.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionSerial.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/ModbusMasterConnectionTCP.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/ModbusSlaveConnectionTCP.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamASCII.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamRTU.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamSerial.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamTCP.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamASCII.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamRTU.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamSerial.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamTCP.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/stream/base/LoggingInputStream.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/stream/base/LoggingOutputStream.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/stream/base/ModbusInputStream.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/stream/base/ModbusOutputStream.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransport.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportASCII.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportFactory.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportRTU.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportSerial.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportTCP.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialParameters.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPort.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortAT.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortAbstractFactory.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortException.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryAT.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryJSSC.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryJSerialComm.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryLoopback.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryPJC.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryRXTX.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryTcpClient.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryTcpServer.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortJSSC.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortJSerialComm.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortLoopback.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortPJC.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialPortRXTX.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/SerialUtils.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/serial/ValidatorSerialPortFactory.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlave.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveASCII.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveFactory.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveRTU.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveSerial.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveTCP.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/slave/RequestHandler.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/slave/RequestHandlerSerial.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/slave/RequestHandlerTCP.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/tcp/TcpAduHeader.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/tcp/TcpParameters.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/ByteFifo.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/CRC16.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/DataUtils.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/DiagnosticsSubFunctionCode.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/FrameEvent.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/FrameEventListener.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/FrameEventListenerList.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/FrameEventListenerListImpl.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/LRC.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/MEITypeCode.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/ModbusExceptionCode.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/ModbusFunctionCode.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/ModbusSlaveSerialObserver.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/ModbusSlaveTcpObserver.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/SerialPortInfo.java create mode 100644 src/com/intelligt/modbus/jlibmodbus/utils/TcpClientInfo.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/BasDevice.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/BasDevice.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/BasFaultRecord.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/BasFaultRecord.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/CMP_Device.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/DDJ_Device.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/JXS_Device.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/JxsFinishCpj.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/JxsFinishCpj.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/JxsJobMsg.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/JxsJobMsg.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/JxsMsg.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/JxsMsg.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/MsgCmp.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/MsgCmp.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/MsgDdj.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/MsgDdj.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/MsgJxs.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/MsgJxs.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/MsgRkkSsj.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/MsgRkkSsj.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/MsgXdkSsj.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/MsgXdkSsj.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/MydoJob.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/MydoJob.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/OpenLed.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/OpenLed.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/RKK_SSJ.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/SendData.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/StoredParameters.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/SysDictData.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/SysDictData.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/WcsCmpIn.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/WcsCmpIn.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/WmsDeviceExecutionQueue.hbm.xml create mode 100644 src/com/wms/dss/ats/customs/abb/entity/WmsDeviceExecutionQueue.java create mode 100644 src/com/wms/dss/ats/customs/abb/entity/XDK_SSJ.java create mode 100644 src/com/wms/dss/ats/customs/abb/form/ABBMainFrame.java create mode 100644 src/com/wms/dss/ats/customs/abb/form/StartCorrespond.java create mode 100644 src/com/wms/dss/ats/customs/abb/form/StopCorrespond.java create mode 100644 src/com/wms/dss/ats/customs/abb/led/LED1.java create mode 100644 src/com/wms/dss/ats/customs/abb/led/LED2.java create mode 100644 src/com/wms/dss/ats/customs/abb/led/LED3.java create mode 100644 src/com/wms/dss/ats/customs/abb/modbus/Modbus4jUtils.java create mode 100644 src/com/wms/dss/ats/customs/abb/modbus/ModbusService.java create mode 100644 src/com/wms/dss/ats/customs/abb/modbus/ValueType.java create mode 100644 src/com/wms/dss/ats/customs/abb/plc/HslRead.java create mode 100644 src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientDDJ1.java create mode 100644 src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientDDJ2.java create mode 100644 src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientDDJ3.java create mode 100644 src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientSSJ.java create mode 100644 src/com/wms/dss/ats/customs/abb/plc/PLCCorrespondService.java create mode 100644 src/com/wms/dss/ats/customs/abb/plc/ReadPLCDDJ1.java create mode 100644 src/com/wms/dss/ats/customs/abb/plc/ReadPLCDDJ2.java create mode 100644 src/com/wms/dss/ats/customs/abb/plc/ReadPLCDDJ3.java create mode 100644 src/com/wms/dss/ats/customs/abb/plc/ReadPLCSSJ.java create mode 100644 src/com/wms/dss/ats/customs/abb/plc/Readdd_PLC.java create mode 100644 src/com/wms/dss/ats/customs/abb/plc/备注.txt create mode 100644 src/com/wms/dss/ats/customs/abb/schedule/ABBThreadSchedule.java create mode 100644 src/com/wms/dss/ats/customs/abb/schedule/DDJ1Thread.java create mode 100644 src/com/wms/dss/ats/customs/abb/schedule/DDJ2Thread.java create mode 100644 src/com/wms/dss/ats/customs/abb/schedule/DDJ3Thread.java create mode 100644 src/com/wms/dss/ats/customs/abb/schedule/DDJService.java create mode 100644 src/com/wms/dss/ats/customs/abb/schedule/DbGet.java create mode 100644 src/com/wms/dss/ats/customs/abb/schedule/SSJ_CMP_Thread.java create mode 100644 src/com/wms/dss/ats/customs/abb/schedule/SSJ_JXS_Thread.java create mode 100644 src/com/wms/dss/ats/customs/abb/schedule/SSJ_ONE_Thread.java create mode 100644 src/com/wms/dss/ats/customs/abb/schedule/ThreadCK_SSJ_LED.java create mode 100644 src/com/wms/dss/ats/customs/abb/test/Test.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/AllocatePropUtils.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/CheckWeight.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/ConstantUtils.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/HTTPREST.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/HttpClientUtility.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/HttpConnection.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/LEDSender2010.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/LZSS.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/MyUdpSocket.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/ParseUtil.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/ProtocolDemo.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/QueryDbDataUtils.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/Tools.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/UtilId.java create mode 100644 src/com/wms/dss/ats/customs/abb/utils/ZsGet.java create mode 100644 src/log4j.properties create mode 100644 src/org/libnodave/Nodave.java create mode 100644 src/org/libnodave/PDU.java create mode 100644 src/org/libnodave/PLCinterface.java create mode 100644 src/org/libnodave/Result.java create mode 100644 src/org/libnodave/ResultSet.java create mode 100644 src/org/libnodave/S7Connection.java create mode 100644 src/org/libnodave/TCPConnection.java create mode 100644 src/org/libnodave/tests/PlcTcpClient.java create mode 100644 src/org/libnodave/tests/TestISOTCP2.java create mode 100644 src/org/s7/standard/ynuo/PlcBus.java create mode 100644 src/org/s7/standard/ynuo/PlcInterface.java create mode 100644 src/org/s7/standard/ynuo/ReadAreaPlcInterface.java create mode 100644 src/org/s7/standard/ynuo/ReadDotPlcInterface.java create mode 100644 src/org/s7/standard/ynuo/ReadPlcDBAnalyServer101.java create mode 100644 src/org/s7/standard/ynuo/ReadPlcDBAnalyServer102.java create mode 100644 src/org/s7/standard/ynuo/ReadPlcDBAnalyServer103.java create mode 100644 src/org/s7/standard/ynuo/ReadPlcDBAnalyServer104.java create mode 100644 src/org/s7/standard/ynuo/ReadPlcDBAnalyServer171.java create mode 100644 src/org/s7/standard/ynuo/WriteDotPlcInterface.java create mode 100644 src/org/s7/standard/ynuo/client/IsoTcpClient100.java create mode 100644 src/org/s7/standard/ynuo/client/IsoTcpClient101.java create mode 100644 src/org/s7/standard/ynuo/client/IsoTcpClient102.java create mode 100644 src/org/s7/standard/ynuo/client/IsoTcpClient103.java create mode 100644 src/org/s7/standard/ynuo/client/IsoTcpClient104.java create mode 100644 src/org/s7/standard/ynuo/client/IsoTcpClient171.java create mode 100644 wcs.iml create mode 100644 wmsdssconfig/abb/actionRelation.xml create mode 100644 wmsdssconfig/abb/carcommand31.dat create mode 100644 wmsdssconfig/abb/cranecommand1.dat create mode 100644 wmsdssconfig/abb/cranecommand2.dat create mode 100644 wmsdssconfig/abb/exectask1.dat create mode 100644 wmsdssconfig/abb/exectask2.dat create mode 100644 wmsdssconfig/abb/hibernate.cfg.xml create mode 100644 wmsdssconfig/abb/opcItemconfig.xml create mode 100644 wmsdssconfig/abb/ssxcommand1.dat create mode 100644 wmsdssconfig/abb/ssxcommand2.dat create mode 100644 wmsdssconfig/abb/ssxcommandLC1.dat create mode 100644 wmsdssconfig/abb/wmsdssconfig.xml create mode 100644 wmsdssconfig/dssconfig.properties diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..024ffd5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# idea +/.idea/ +**/target/ + +/log/ diff --git a/images/0.jpg b/images/0.jpg new file mode 100644 index 0000000000000000000000000000000000000000..da49dc92bcd45aad6b412dbb7a86f84e0766646c GIT binary patch literal 15249 zcmeG@2UJtbwsTSmy$dK9qzXdlO=;2vq!%lMBtR$$q)1Wps)&MxYeT_;B3JBP1ni<> zMMV(=3#fpgAc%m1nm;F0@AJNYeSf{X)?drXI_K=!WoFNweP$+S&j@M-4M2K^tA{H< zFbHsmKOktt^}8f9BLVRC26_Mh5kN#_0Tx0C`~gG-;Ds;%5y3V*u}9 zJiIuFi4c~D@Y<9+gH=503bEDY_WTyaf2$Mx;Cvky^ zk+HFjk%f(k3E9}f#?;Kl%p6JqfZc_R>b46rQoh?kbc1b~2Ghj_ey0VIVvK>rPvfC%bAIuI8T5h00) zlStw+VxnR)3R2?YQVL3Patd;CN;2ZYH1rtE{P~VZh>1x^N=QpeO3O=1O3I@*N%=t$ znZHwj;1ZA#0ct=Ei%bF-83ZeX2%f=aV+2TD`pacc9`N3TEr zar#KeTEqN3Okr{h+3t^fFE6d_H%jeMHI+GUzt2DB=D|9HOj?~4ckX%pw;DE6`?>Yi&-Hh8ejt$rKqs8LB_}QX zQUyy!fo~sBw9&k*?vSLK*Rzm)yBjssjmeoZ9j@O32JX&!m0jY#$&2n*DrYFCytq>U zh#&oRzK=4`%<(jJiOo6FX2G^qaMj4oo+tY8OhaWudQ2X{8RwG$Z=Tt z%U5;euCqDgFW!21ZN`Da$w~9Z(`8Atesp;aCR~GKATkn>T_n5#ndV`!EkWrXs*#6eDco zCzuBy0nQCSOxQOl`G+LI|Ai*B3|cg78$g6PbXEbvF?rA;BEmds31}6J!{9Y!V>O5! z%d3KBv6k>Q*jh9T?LTxOz!*a4O!Vh87B|fO9nV;XVZx9~XqLr~i-QkTbwUK2&!TgE zB4TJTHzemz~ z&Wj6k$anSNg*1qkg%?qn@o*kfHZh9B<|llIBCt8kC?<=+;>SZ7ahCwJbRQuO<|U|n z9@~wV1#=8%r zp(K&ch@|r4cn~BlU~qUpU=JQff6p!!5#_{=V{^tBS7xyM>24zgC<11(S*Wc^Ja&Q) zpT}hkI|fP(kLU`~!L|1o%E-WtO zLpcDp0p3uv4Zk&Wp&~aR{wh#{tDj%%rC;l%=H6fHrT@q4CE>fS4&QJ90^o(9FS`_Q z1a!a#5r6^6z!yYAmR$hXL%l_a z4E1Ml*>QX!qooODn0G9Cgm>1DdB>thct=@-SWKRs$&e0zLjNnoT5|6Hn#YG2^LG3`$G_BWfCD6#HX+2ZwGrPr@0KGBO9Fe*E80zbg4D8~-xb zFLV8r1%8V8mv{X#*H2mCrdDky<{gefMiusp! z{W8~2S>UIb|5NW09sP>WV8KuKN$?xJ;H7w|hm%v7ufLD0hnI^m+#v4m#bmKDFx(!` z;&J@lrjtWw%_b8oVYrLR|7+msH!!9zG5!f{Ew1Qd@(N#!GAQ5b`U_~kiJK?p0MaMU0?MaVM< zJD@N08pwM#cA$>k*jn7itmkSk0RZbAzI&v?a0o9TL#FeQE6}s0G~tVqHz|o!JnP@KNcLL z))+me_%k9I90m(k6%4(M$%=yA&7w1fu_Y$!uX^}D6dR)h3J&@;1mp_80r@aPAbn3B zVB7BioSYcI&fN(q$Vk6=k%D1}5rB}1ErWg!VMrI=zq?_wVHU$>3b&yEC;vb)jn7#y z$bv&3cpwTxm-0Xv?pDwMx^NGa39tlHfdg;>Gk^~W1hc?=K!ZWdc)$TkU=dgfGQeu^ zJJ<~JKt3o0`@s=#0-OQoz-4e9+=jbbt3f?z08QX6=mfoB0PdqCA`*xkqKr&Lv=Dv7 z1hGQw5EsM?@keGM;Ybw1LiorcWI3`L*?{CByOI6KaikQvjNC*XAWx7+q!syq^kc9X zag01h6{C%zV5~5X7*9+fW*#OAlZZ*hq+`}$wqgn}hcLyM%b44kYD@#>Ev5%fXu=rz%&qTOO*Vw1$I#r(vWV!w%P6+0$&L#$Ekv$(9dp170v zTyehmI`Ja$OX5$&yCozfv?UxQW=rrS)=BJ_D3^FH@kvrn(ooVvk}kPKa+_qaWR+xx z6iG@;%28^*RH{^t)Jds(QtzZm(%RBa(p2fi(%YmnWaMOwWqf4fW!A_Xkhv-I zMwTe6E$bpnmra-5BU>)}N)9WhA?GAVlUpuVD0fY+NuD6DBkv&}BfnbyuzaO_r-H14 znL@Bavcfin^9l`$SVe6`55+jeY{e6bj}`mJsg83T#~7D6?#Q^RaeYeTl^m29N?A%r zm8zBcmC4F3%CXApmCq(s$FH( zR$9?oTeK>)`m}YlL$p_FpV5A!qom`Zld5x2=c%rQuDx!eZh`Kj$%M&PlVd0En0#Lk zqi3!ct+!3@o<2t3LZ7L>L;t}P{1odctSJRkY7E2;91Rv295iS&R5bK5TxNL2u!EvW znN3+wsi1r_GB=7dDm1D$mNlMXyv(@F_=Aa_3C(1i$s(A66EEPOA zczkcLo7XjF@3Q+^^SC8EdAOLm!`J1n;5RO?Td-}xr=;MdlgTp4tmHc> zdMTMHEvc@le=Ni;q%FL%NPW@LMU82WX}cFAiz60aS)#EdeM!@AZolnYD!Mdw>D^^U z%Qh_gxIAQeS-NWaZ|SdAxUD#tA(_F+s98C6W&SGMD(0%nOw-KV%x_urtXr#%R_Cn# zvWB+i)>`AWTh|KKMXsyNw#eT3JK=ZM?~m8puiv*pW<%TT1v9o;@*d*=4O9rPVlI~{f&$yd!^o!`HU zxvO@!+wS55?Sh;=ggp!PG#3UJR{UZ0$Ns%4dspxMTEr@9*yq3R>VC`p`wvVwkbMwy zkbkiC(A-1!4?7<&Ibv{R_ff^8tB-+W{9|p$!;e2c;d$c9Nvo4bPHCOmep>EyRxwhX zQrvka`bcyT*376hoj=KEn zO4yb9^3d`}SN*P5Uh}+mKEbo=vx4vKYVA_KVRrXbvA38t0{>bCe?dqA;4;}|SuC19{(@;yVee)#lNmt#1 zx`F!Np5mWoJ(GTx^L)bdf)|rt9Br^@IN#{pc;{un%lcQeS8rc)Uw>&zZ*TLx-#ouP6~x1x%cCbV9N=1D@MOl| zxre`X$BZWINE#!FotLK2pU5kW{mR7@IR5G*{KfkidK5J-Fkp4yPX%M#Rya+83FvAm;+h62fN zx*}E6bew*8wZM$-)n4pBLArRwDe z`f}dJbjF^Osi~ld(41~wWw%j%z~ukl++a&D_3P^ZQ7i(WovF;;U9a8 z_U%7#>U8m$lG3uP*REIGxOwYQ_2Zh_Cv~rznp@tqwtejB?fdk(A2uI7OM=7VaX1`- zfRBeN%fPcFcw+*XBA2?Q2Tq*MagEE&;E@s~nsZmd z32k%bKnoYTjwpBeMpquHZxDkYY?;17sBrgWl}&}G&_gAg2Tzsgx`jkqjT|f)Jyqf! z8lAjq>%Nj3wQoLId(2{{WajQKz4@f|v!2b2*)geEc?ZgF)wT71fB571wo?O3=sl8p z%QeoKe5~!e6QWI#@R+i1$c2S#Tgz=F|GxL zA4AWu?_4-mU+pRR=GmvY`X;1^U2@j~X0H-}=DN^VQ|@2b8JBYU{ECgavwL3j&D*r$ z`eE<6<0eG=s4acay^tmAZV_MR(HP*pM0A7I{hf9@9Ik)4T=zN7(9N{Q`jBDg?)s11 z*Cw?GtaoRtE2vIm`;>8JQ!-Y~47%XZ-$NmNDZgOHnz(l1z1PM1ysE%=?aS@-$Cq9)RX$$2=JD%m z@zeOY2XiX5_uY*QUuAImZJNc!$xNkGD^5KQE zQz;+978yQm-yV7QNxod~bvb@udtS@7_HOGL-JUJ_ex#s3_HPY*^XPK!T)lOajtMOn zIn7P;W1AL-%v;g%^64L)H`N@vDs~Wk$Cb|SxOem1+neWdtf}u0_hqJgU0QeF)qC0- z(_VhqteH)#UrXu}OUedhO7<~d)}OK#|2F-6TU!k0N#2d}z{=AmVK=>wCaSJI_09Iy zA@$QP#lya5vPX)QkX`3^-9eec5;@!BN5mQIfC zv(wjd^C_%;#mL##(XjsL?b~@6|T6Q8p#7`Ep7tYR~O> zwVK+m<#QapU1t@ft{iW^D^ig?VNJ!yr5)<^X)m`VG)YD@hdn)D7-wnKK20^$PV13H z_0cDWM{n;s^5Ff|furi(Ar_KhL1*hNlMhK;IApncA%5rKFm=0&w{|QMJg^L_?0zLb zC+u|*twZ%iXtd47X0=P-UIulLCJBI6-NL$^dAY|*_1exmR5+WQl8Kc_6X_^l%1-|J ze(}vR*A(tf3s0_LwSIS?`#fiE)3?rLQCH_?fplvaUCb|64O_=8Ihm zW7oBkBMUokEH+E7bR;%a5icxu3b#vXpDnqg)vlnjJ#9yc{^af*`(JD;PN(+Hl!~Cn zI6paXV8UA0tkkRn=|v3Z0FIAZ`Inv!H_8Xs`Vs-iuCO=0e@)_0RN!ILEL}YlLQJae zi@y2udsigs5487=uVlIy&zUv7Zf|TRURptcjB)Xi+%nI!_>JYx%FmhIp61!NeZNGs zsqT0bre?wNYn}7;ZrqOY+Oy;Lap&w+AnVjUbUfE|NE7qiiqs&L82O^TLjV}>SOd|= zrQR}LXD$k<3M|Wdqw_VO$iw1d%;$X8Knd4;*);*sSbHVry;y1CVCgEOn|wCKeIv<0iA zkklSNOQS5+dCcrjjS3N6)bF|QW4@syC9#p zXx@QaZULu0%*%afTeJFU=(P{ex2P63+~YH}KkTc>cy-fze3im$BejO-A;rB*z9!!J zvcHtlbBs_kLCj+Lm-!lc$qGeXMz*vi+Oq~EzMVBlygBuR0L;f+%v3lrH#zFlx!}-m z`MwIDwp%($RdlRrJC}XkZs+P|%H2DWFFtKtC%>`%bN`E?sa0iL>{l?&zvgtuAAh_# zS5)c#vNfNrs2Q&}T%9{GrEbdk&DqaX+g?gEYPPs;dYeVx6uqIevo7>1T>uJcy&v6< zw+lehzO?3M{ex-!)@hehvR8|DRhoIu{p3BxQ`x@TqyF%@1go&7RQsIBPvzlfvct|? zv8dgem)3r^^>}IH%4}JaPkvc9=*AV2mU2O=mvnED_n3ap>Sr%W8K0HHENYs0qUNLz N()jR0QJCP#{{S0^!ae{1 literal 0 HcmV?d00001 diff --git a/images/1.gif b/images/1.gif new file mode 100644 index 0000000000000000000000000000000000000000..5dda50808c09e71dc83b231b3f34dda88e095722 GIT binary patch literal 1634 zcmb7@`&-h70*Aj-R0u&pLqs$b6G5jScI4toE?z**`{r_Hn3q|rCWfWS8iJrEc)!Fk zpJQT~*O8L$nXM8v(~BGuHluectDJe|vxYL<%D4j0|_c9oPkc z-QC@nKW*>4-dXzplF?!`o6XN(Z*Bc=Yx$?;5zC0lY#O!W`q}ka!{(^z@rr5Lq)cuj_6MC`URZx3yJYR`vAt z&=-P>zG&^e)~g&W6A!m&uXc#^&C<_XPTy#v8EM)!ZE;UiUSC6vwpM;kR{ig4jYjiv zXVt}j)n{L=C}^#uj!+fNRaNzB;T1(mqby*^zq-1%L0x~QS*cd354T*9s3lUBoYYTB zX_jO(eD+a|R4rF470NtyNq%KMsgsmccTS=xNvoEKOD`m-&&VVtXFn@CDJ{&9pGzzg z5ib)9iVLDEP8Syz@7L@nHWA}WPo6J0Pi)%n)kF};PnmIFV~=N^0tRso@{I@1E<9`N%mTJ_(!c5+9x5k?yfK z(}@!o&xnuaM+pu_$2z5=(1-U5cmf`m=N#+o5#k~~PB zo_+`toPZ}le86@D@IIG)hGO(~vDDbAb`%o@T1G4wP$)uC?LCEx+%&JW{E!J{nHZC#W z0)`=Fg}oyVk&E<2qb^&=U3#?NF3j4V)h%{;tWZ565wL!nx*uA|4xoLd$oHSC?46U> z^|ie3XWR}-K#-`!b`UalNngvLP?Y4Hn^@5=a}g>GvmD`;zka_4NBcxJXt*}B2r03< zPyfwZ-H5013xyp0^m#r^d3F}H85N+uc7Sa!#M#hO@Nf*j-tgK~g;oYgp`FpY6 zAKpHFfUvvdR(E9d?kkY@op>u7XO$m{k6#E!K?veEqZetdA^#CDr$7mS>m5nEH6%`- z80}q`oXB_k)G4uCUh89+qOJ-JR#+21Gx8l--u%~&w5Oi-e(i;Gkyz1AMwTaER%g%b zU(zWKEM&cA6P~A8E8$(zOruYuS7HP@y(1w4ThIW3P@d1Wk2!uLOu7i1Ezi6P>(|j@ z@abuzV&=dT z(?ntLfLn+O-wk8C967Gf+++9BX;#U2_B%(`{X~jVAP(hHmFO4!qA2>Jlw;-bOp-Z~ z67*s&mKxW_<_E8BqAq%a%21X5^KJ7F@IE04F{~Rn;;i+5hw7so{zx60Va&Z4hz?qc zPpUc~@0jJ0wLY} zc4}#BF)uYYHaSH^NGmHZ85tWRBP1jxE)*3SCOc<9TaP0xK{`iZLs4!sJWmK&)CpJJ3R&L?QOpZm=L=in2}`>ST;mN} z;SO5e4q4d{U*!;8;0;Nv3qX_;QoIsPvKV6B8D-=eVAc{mei+~Y1gJ%g*TZ-$0CLPF2v z)VbB}{mTUbSQU`=vilhn6#fqM-x zA7FQCgOrNSQSVV+IK`@KA;;&MyZi?rDe{v7DKv8B}PX zs4mnjQ%x;)^pS}stS;iJrH3T{(uW(iRI>~F5K^Gr34m0TTkGkOL8A03(ez+n_^09H9u} zaVUGl@jxEIZ1asY%E%&b5)jegCLZ{JgRwTT6!1U;4LlHmF2ZQD%{buTqs{{rbkKu9 zGE7{CFxHSGPB!?IvrYsA6p&6e+hpSnIMyIj00vPcv4TJ<;J||tYUF~CG~#%p&pEFQ zP^&lGh@($F$HY5A2RMv}Es$PASb;__%7haQHsP!zcR1pRGmSF6Kybm{K=?h-3qTm5 zL>98-qD?-^)G`1o%2e|VFtI#!3Q8n5rPOJfB-@i(+j}@@c{tSl0*8hyf|CP)AAaKtVY}2&a|6{NAA^8LW2LL|+EC2ui01yBU000Jtz@KpV^N>iycDXX!=s>F&Y9I31ks892^rIEHW}9f;=mRJtY(a zHy1hv4m>Xm7(*5kGcyO493ciBp-Mj@6%`i>C=gn%B0eQK7a3Y_LjXHCCn`~{KM17- HNkITRSSPOg literal 0 HcmV?d00001 diff --git a/images/a.gif b/images/a.gif new file mode 100644 index 0000000000000000000000000000000000000000..a6e3b775777d3dc949508425be5c904647887ab4 GIT binary patch literal 1227 zcmdUuc~9C006>3bh&YdU&QZ;r*DAVhX3-2=H^HMtwm90fY2D_5Q-aPJjjXe-YZW|b zHBRs(u?h+zcp(*Qqj-VRDk^mboP^n_DUu0!f3TF2d3Pt|l36ID7L#+8W zzM*fy0Q-JU*wJY)7(U0bf8reKbUOdLx`NixY_TEwj#!~LIbST#qDg+pmY7cdy+y2+ zNF)nKMkbS~TH0-sYamf$*DCfKl>5m=G7f)qSUN!++HtwkEFYWe*MU_dJA3*Q3}q)O zMi5LLZ(jsS^Z{i0+N46&-1+jicI~~ky-UQWvA?kGccjS0N;VEUO%wV=^S z2cO&E`!w3!hYueYj~pP=R4%A$+1jb$#AtDIy1Z|3X8TQ4@y4-!e^#|b7xYt_U*W1Z zYis#W=8Y{aEf0F%%p9K;^=@KgSVX2Gwon|++#MR%W;Uzx#5&7>8f-d`J7E|cQTI=7 z|5;Y&d}H`AcVKnTNbUvGx=!UIGpp;n*UB~Sq{XIg&5+7qe_KH$GQT6XgceUIl?!WU zpgmp*f}mcnH=Uj^6=1R4G`M4|eXgHh+CBi!vcww-5bRn3#p>fYawnJDO5zLrgoa%`T+l1+)ttB0ALXK^j*Qb zCjdAIP%T`s!ez84%)!@+X#PQ=nWc5YYkMm*XrL1rA+pV2aoo>$qecUB6*XQ6N5Y1W z1+4&^;IXPaNBS^$8#E!RwPbShrDDeQ0>3H~y|X^_l-8sOMEDq#9)hL~zhweUZ_qg-p|tmlGp4 z09ln)t{>X*t-Ff(&6iE-0&RT>#GxaNo+2VpFGMg6O7f&KvDv>KG*9WDhF_Z z*^*&Mvy%*SE8KF%9F6WcHR>BvN{PYvG!;l){Ym>%G+OEMIXH~P!WT6z3&ZU`{Bc%p zSyU~el-RL_6r_i85aaRnG#)U+-htL2)7CLLaK{<~7vl#7AZC8|la&aDGCm0nT>cNa Cr!{o| literal 0 HcmV?d00001 diff --git a/images/calendar.jpg b/images/calendar.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4baf8c5156d0fa18bfa65538e3cbfb8524d1fdcc GIT binary patch literal 1644 zcmbu+c`(~)7zglQB#uxe>S~rM>Pj0&qlhbmmWtI~SA-TDN*#k0S5||mZBfT+mFm)^ zO2j!DSIf8)v{70OO4*Xw)-g(=jOk8jY$;E+q9 zVd1fH@d=5fpOSvQdM!O8^LkePt%AbaMR$HJzF$#EsiIcb)HXG@w6;Bb)ZWogXABGu zJ$}M`!5W{Kd^t7!ip^R0L&l%oC3a#|l$8|BVb3M7t6D<3mu>+n9&{*wJS zSla)ReS!VsdIcN+gG8SPh5;C056Q3LR_sf+^Ik4wFw_IKllJa+8LFzeMLa({^ELy#*t;kv{G6j8RvZzf;?V+v^pzR2h zKU_4QhMO=hg3rnr)IYsg{{`|9T+ zlG$2;~76obI(Us~Y6<7>1AxnLYbX0*5SNBuBTl>FqueA}8ylQoy2S zvGqC4YQbu!um!c}sN&J(Hn6gt|WcQ4jtx8dYCMrSfNR!h6BWYX%qjhNhm2dY?< zr;^#ELaybH6~0ux7RG>`Q8Xe~f1uiFod}Ogm%t|?Ht=MeZh^n9=SmRkDV3pegN)dt2GBL+gaF%!hxx^{QD%;>-RqrbX1SOx zu#4yX_HB1v^1OO9zI1dB*V83GH5*~BY<_#gX?qwmOIP%l$@K0IIb06Z$aao z(LH{%T`^~=C;dGA2t3avYhcYN#0>XwqKxi}VtnrstHTO#sdcdSZ767ZMw#*(s)WfX zdM~m#Pj_cHDAfgmi*f%#2|XzE2cp0hk&7kGo-X%SS|S)s;H$B@=pmJntwM|UwVk7` zueFi=Y;NK28uhGgJfdJ(KZwROT~KA#+uTiQ9){XS@5E+#Tt%K!$Thv6wAi0FmB$%M z>o$%kgQsWOO{ZKs1)5N$WSf#wgtxw8#k#i10EP%PF+ literal 0 HcmV?d00001 diff --git a/images/his.gif b/images/his.gif new file mode 100644 index 0000000000000000000000000000000000000000..5499d98b4fa324ed06fbfd6cd7ec4a008bce98bf GIT binary patch literal 370 zcmZ?wbhEHb#9{ay{>;J85 z?;X?pzIN&Jy_(ndYW`n3=l{%^->3B4TdH_&sl>5468BoFk4+KS+QM2X$*6sg60HyO$qYq0U?GKFQ*nSh88D=VoS?3W8)xAO)o`7Cq>2o z|Nk?P1r&d>u!=C~GU$MGgZ#w6)_)*O`-z}bzjO%8B2G?cjb!%;Yiwq9b*NpP#UvNX zp>n8WfejPWL+QGZ00mRVi3y9fBzD}IVDLd$R8v}0DNBrljfayfU#W$KO@>plo2OBs zrA|gjU52MeQ&Ce{R6tBdTuol3S4(%XjIcbTi1_q%PU76GjLf`^iaXp`*%|q!YrDH? Ss7h!moIK^GsdLhi!5RQAOLi{+ literal 0 HcmV?d00001 diff --git a/images/login.gif b/images/login.gif new file mode 100644 index 0000000000000000000000000000000000000000..7cf798ce0432b44e070b2d3fcd1a880506625b4d GIT binary patch literal 7688 zcmb7k`8U+>|Ne8v%oqkqLZQYQSt}Ju4G9@BNo1XolKnLmWlLiV$&#f=GWMN8*_W|K zwy|Yr?6QopGnV=E{{9Ew$GOkrhwDDqeXhrK9@njXPfJtL4##r1qT>2mDX#d~)2gl75J1vttt<;^~`Teow{mE6v{Q5sG<7?|` zW;Z>*ZzI2#UNO8?F|=7bx>Y~E-9p{zoZao3-R+#&q0H^}%P=yL+r#eD!}+e~q;D^eUoWqJA74P9 zU{L?L;C^JtfXIgd(GLUSp?}0f2QGyDkq#e}i5QfP7?g_~RE!$B5^X3?)^;eFj=FnKYwe(_WDQgqAm z=ho%;ww3s{ zw%cd6y5_cf=C}J7cLtYshnIIpmUpSNy&3xc-1`3CO~(4}!7k&FwsWwsvA4}Qnp)dg z-94P&`iJiy9v}bP;s3YG|KCky9|8h^RY3NC%>QKqfHMIWxR4HssO}4f2wAjJa2kP} zV)A-YMNjI3_^!Z+Sw*5P;mDI39Bp*5wm=rG@2*)dCDg;^6&gOCc_G;uCTIV(I^@c8 zy@VUAbf@y@3zQ^{AQ!#tAJ6+z4dO4x-uPjMNs`Y#8)$Yq7oB_Q=LAIX&+@$j%hYRb zIYy}70$YO*ma4lK%%WUo-iufDuA0@}07d6HnkeWrU?`hb}%qdo2f4*b>qFH$Et(!H9MR?>*Ylph(~J=>Bl3#i1ZUO47TbFxwXAU_~C5lbKu+OL?i*&3E?L~lRPHy^? zmhSmdwTz2}rS_%m*6H&+x_Q+sN+_4O&6MTO_b@Lb1=Nu1S6e|)BirQFIzZEz0RY6%QF8oS(`AyQK`cj9iK}T^bQ3j&LCbaM(1_fdGNmQveb={_IC9;_u-D0`HoiC7*yI;7wdI|^ zdN}uIjNW+f3}2cZFP(|jb}1Q5#NJY#+p?sTO-7^n8=>6&naCMVN&WRgmRMHaG;6^JL?ebbFy+gQ8ulLdyow*cQIYk%efj6p1)LBhVm$DjAp&0GD>Xu9|g<98^ zUy8MREvoN)w)%4Gj)N6R$3FgZ-D}kJi9arN{;O*WPngH4*h4dZ6g0o5dgh zK|p*_5rGgV5ia}S281`Dt{{#=Fx~7LdC%DeY6zvAaExo>-MJ8W)q4t>zNjf;MfRH& zi)4?M(v*+t4#`&)1ql&+`FvgkYXtb#H^A?T^hO4$J{3U>WFg-T_k@2hF)O1j7K-qk z47&3)ndKJgjwquikYHpjDr2Y4zeN8Oa#I{>L#?_4+xR3iYc2UNn*utQKXGDgq=ZfH zsF?A99gIYT)isliD>q_E0TLYg!@pgKPe2G#z$GjDQ0P!f>@;~!UP>tldNU=qh&%`O zQ%|;(rJl-{od-94>agZR#vw>rvY#pd$A-%S5oC#rl~cc;PDjNTaI{=$&+d5b5UsHk zFfTI@(*8I&HFnE;UKN|c)be30KTGD7kan{U^*g&oEJeWr;U6#oqGB<>1T;~1?uop3 z`~;Mxn5krOrpv~d_scoC4DJ8y*`CXn0Ds7HS_pawv?&D`IJCP~b}u>3=hT-{yKD)X zDG>FQH<51fTqdk2)H2`--`zQT&~zKxhL)1P;W{t&-J!$lxFqQ@R0=f%4}0zTD863` zWm2~^K>Cj2F{M9e`6}K2G$kdr7c;M0^tMcrd(lNbICnKS$F*{|k&|&C`VT{RKrt$NT2BXrLyx&I9K>g4W zXjUoE@E9cu>FNH-CIo=?aIAoT5}G|jbyAbFF{DDpfC)f`2Mxkolku4pS?KW zWBT&RshrosYu99!4PA`g8P#RA{<*KC3FZAH*Dr6aohwg&n^$!QN)-L9G7QMPStYCRA{}wOLd>yfZXr2hCYJ~)g5!$O&zwpUYI#LTxOP9CII)Qw&}P}z8!%$9nUF?Cu2RjQ)*w@&1HnOJsxv# z&&1R&ejk;lOP58B{C3?*sXIIDVqp|N!J(w{C4ci(=)`8z*2Noj9e=?%Doc5H4NYC` zW5&Bwpr)`;)Tb~^v)|;@Y_P4Ne|-mT#jmpIs$$`r`aTt%I`X1Kj$!_bw{Q7l8BPiS z^FbZ+?V{@K=7JcvoqB^|TIS|HY4#Sz*VM=4!^}a~pPJ*_cvn_lzs_trpgE$Ljx@=u`^C;K00bUh`D^d4jH* zt22@SM-o7CaB$TEe(V%B*~tHTtJ--0EQtq~F97GLASLC1qzo@%3W$#klB6p+XxhqO zd$2BMt8L7NYt;8UnfK1o&im@!`Q9+<6dNBp>ztD&@ko3*Ec zgQ@Kzq-iG861- zjIF@{Q>3u`fiNf%np6(hVZyWpLjJnDnml#g7yxQFFE=gvDK38aGX%QJYQrdxP-_M8 z5yFGX@1DlECZ<{GEQA*81al!n_(&jL42X|tmAv&N<#gb)4FB^K&_HnbC-;xLLm)+h z7nJB_NyJ8AxS(W*ZMUc=kHTB}!RPJ6AojlZ_;C&apmpXeTc^eMRnNo9%Wf#l2k>V{ zoWpSNb4XQGA4AR&AJA3Y)l4vJdjyide7 zV1Q}c&%D!Y@)f`ndaS-Z$ae3E0N(bIRAix)KNlfDnBe83<9`YVNaDcSAptK<1J405 z-;HgT0-Zm^tGt&EzCiwXzf~L9I31w#jDk>7raep=1 zkL4%Fmv}@V@d-%oZ!Q#2m&ZrR$dA7T0^ON?AH%Z!f3&?nhX+fNK#~}EARgRp3feFQ zX$!y~nP8hRfKeuP{~lL7^(%q`-Bcm6c!FU!lK7BGa^wW9ZG~iGoorbNC{|YjL=dkpNJ-@-z~AE8GwBGz*(|@a zSsg*_SQK$1I|ZIYRAn*%UNVT6I~&Ue7F1+$%D{}`ytmUae82wv*oaSOb5e9cG}D|< zj8t9}93G4gM?oaD*!|C#wDUUhJ^`mVfL~FuC1?HIxw9qlDe?2VR(|fkI3kXJYK4u{sL4<4L^5;E?r}1DxQo#ul zhP~;mW1PU{Oz4!%htiqQAA+>7gq%!uP(AsfzFBs z@;oA0F9w3#mkKzCIiXcWTbd-nQA7;|mU=cjed&AVQfh<)@dO4;V@o=Xgs?pZhKbqv z>4Z5Z*?sy3VoSikEGS&N{L9<@*uNeD?{MreJ`Vo5BHz!f3Pi3`-!I_rC(+@H zX?F76id3=#OcQ|o#e>r@Y`(Uvyj8$BA+Mee-q;5usigf%F0v=P>j8Md zp&+EPz~e*Fl08_0l6u<=${1j4`^6rV;9Vq9P<$G4g1aJ0wIb#K5GAk(l4C6@xc2+? zx5QabaaZ~aR(x#-nd*uNDVD=V1Qf$W#ZwL7YmFr z74w1>;z%$r(x-^d!TW^6@#_yzDB2)0BaH$(p;!fNW-T!X$f}^ec5s1URZ&7UPbrXw zyziS)RUQ*mCs^4i1Iksc&qL(3qsao_>We~amn#Ye9EjOO?1uRJZ3zQ`#q#o5mId<) zX%tw9Vk&=Ezr+ijrdZXr^yq11U6(HV2&7sRAcOO&TU47);mEL1H2)l2h=As(1}yfg za%I4`h2nUf$ozTrk2$Jf+!bPqasJuGZe&{u2Kb(ZwK)uv%F{Datdx)%@YMqB>7S#KfDRZ4~HBDq==TLqe%_&Qn)yzawbol&Y_6>=-DH;{JFnxCuZ4dl5| zI+qz$>;$kF0g&fT78yb~-=y>jR=O~6)=Z5xC*O$63pC3>i4cicwYQc)zTOM!zfr4L zBWuMmV2gXEsx^QCHwWToPw!}dmP{oK2^P$+mY}q;QmXqL$>VU(|C*b|51ZatfG@rU zN*p3{HH=(ik$mFAEuZ~Fo7!LEchabn5|Hdd$C*!^_uZZjwIX8*Uy=2JvK?y#L# zlvD3LIz_SSp2tT`C;zDaM4Mqlh@4Q;eEz`vMEi`@RW@-qo&M{sT^Acd+N`>T3AOf5aAZSro5dNs7%Er|345Xl zv!SqTZ9ytkVI6}jxLdHqkCdT)79rwtb`4nO?W%C+AHM2^77DvAIrh5~U{zE3*J?Sn zfaY(`asL-56uH)*z4nY_`S&bjSa_BlKjujr5F%P4$kdKZJv~VlxiGXLiN;EV91nOW zDZ>VQR)r`mHY9sBJRnb5_rmK>OsroR`>aZ&StZh}gu6tE3osJsI-w*#-CdCxVYb1? z&Y(TAjvQ}D7>DCGlwN-!MCJe;Q3r6o+sG&C?e&Cw^~u)+0(h6D99m; z1j(&#&6TrUU~VUN42cqfL~n2{)r%ao(~aM>nu9A*+C&N9r)!(XS7E}1`Vbi|bRA&z zZtLFKfF-xSDGH=a1}jt6gOm0?tbv72D>?4=eB-qXA+w!Ob zFBJIV_-1m_pLvw`yAuo- zuO#XeO*MUh3LB=8MVmDOAqaMk><6hjAyC#^H?uMI!MtKhFWU_J=3`|_U3sqHaP6mM z)dRUK{ZSwxCHt7~(*7CQhFQANT8Up_odanm$;RUh7Lj`)GWG9crAV@EzRymjaiT@< zvhzG|OR>!ToIhOUxXtCQs!?EB>@g6oCbL6?^LU<@wbJv|Flc4v5W-L~^>ghqr*H)v zCj*1yz6n~rZyo;ew=+>)QrYR+idB&pw!I+tiwl#T_l3RVyrtmke?y)UM4gjk_lQpKxAf}B_A(+A-Em z$2%vjRl^!;wD#6CIME#|HT>6C6z`7dP-V%@ISCyo$O+zjrMRarNhlWKYQ5T1(MB)t zbZJVd=YvjK&YP}Z} z^W!1w`X-`Zy+|%K>+Jx%RI;>Q_uS>m!L1hA<+%u%c6cG9GfD(1u~(^f&D92 zA7Amfx~UM;adD9tz*kJ`_++Sy9=5u#i}o!;{flH&-7H10M5{UC#TPHs#AO&P{XF((-e}B@ozSbz-Cg#SJ4CIVX*mur87XJ$HTLpj zH(wz&`5VS5E^$8Spx>=d_fcqIvwnK^YMr$BfwM~u;)NE+i3o;f{v*v+jn)$pMJ{Kw z`wh zXm|Ko=J?L2ipc}NQO8U*_u*L9TkiA8Nnaof$-Co>$&$jv{XtG{b;x93w~zN~^V%(U z9xZyPcUQ=-qqlog+Bo%znKGu&o_gcEcgLJabx7To0byga3*gidj+3Gi5CI%MS-;4j z96Jd2Men0K{r zqzfgu1=&`C%Q%xtwXytL xvF%-t8H0zX_{HkSd0$-v3mKW1WFA)k)J=^=+9#(+35O zTN%^uPRNj{Fgc`A7*KM`#4CN=bOPQ4n~8? zQr+$*;#K4YhfCj_>kF#q& m1TnlhFh^XlMbNJ)VM1E_sy9EEW@}291WGtQFg?J+U=09X%Rwms literal 0 HcmV?d00001 diff --git a/images/tr.gif b/images/tr.gif new file mode 100644 index 0000000000000000000000000000000000000000..3fd6c20a8ba2db3c4a0fcadf9c1d8a5986d01b5b GIT binary patch literal 3485 zcma)-`#;nF`^V?F4Vxu2D$&W_r9uZP)#mM#)LTVKDO4lx4&og}YI81;cZ$hrIW;*n zry9y}X3SyEL>gnxOwQY0uh(bq?_cn}ZrAO8d;ajaez>mZ#tnx;4ObV5_kI z0)n8C-_Y;^G%SR8Lg?2#^m7hMsuLwKMagxd6s9P(UX;cXQ5!_*4WbOTD6>(N)g;Pp z66Z9FX&lj~7I9vSxS&n^nJX@Amy~o$Q(W0E`M?%sb3`ATML8|v+*Wa3n>e2<{@gC1 zcSz{%;=&GbahIf6DweWKT-+)C(k&_N5`XQHeCd`_T-GaL^oYxQB^7;=@?P<`e#y5! z@%JB+ssTyOAW%IZsrv~qe**PG0P7dfGz>KJLCy%k9Rtgx`aW^hprmdHsOJIfVX%P* zG>(AmVJQI)A8Z)~oB2S?D9|a^;E!pLHxETKM&4BLIZ}ZDY#oyl z=$rsM#-#+hC&BJXpmz%Fn+6AGp_sCf*X1MsR`BD#@!x*uQ>sQ2t4H70NXbvE;-}P( zrq+#SumqV6f+Ftpx8C`xeqm+beD@UCKLhqmiU#MPfmv{99vYklMi!v>Dt?l*ggHvB zA1nMJNoS2^u?5+Uf{#t(Ih^s_=7~?7@%)yFg4W4G?liq^irzL^+%a9+IaAUx{k3cM zOXm!ud$zo1?pxn{)em9q-~#jKZ#HkK;n!l*@Nx@(rFmqzZEUq&u+}lY)-|!-Jt-QP zlQtsmoe~YqN`48Y{|@jLprLty{~Id#34CfEZyJ}5T3A2yyMIPJ{2MABl9c|Ee32$k z!Wag=@qw}tpn?y48wD!IfGPn{GY-^F0IW%{eiCS$1{LlkD|jZsy^;}LDJu8U>ZgE) zX|Q1$Xq*Ar(?Ihq*fa}r=D?PDuyr2f&Vy}2uzdmSTmah^fcD>D=WnoU5$s+9dzYb} zC9rQ9`mq8vFM@q5P|Fh7whXl{fvrmbcNOYbg?iVZ&NZlOU213O|9t)bg5J8k3=Fma zGx$&a-%h{~5R8+hg`n}OLlib<8_~Rn3Bi~Rvf8w%*Y#1@gG4iLo@&Eu-BXI%r{84e z#^ElO@3Du)a}o?)(3I1~*=Li=e30y%gC9w0cyg1rZ3(SC!zOOeyZXFqX&>z~Y~Q^k zesaupR`dEpDd7JYif3Ww_ zO-|}rfBdY;nA0$3d1#xrkV>@yy4g(eaO_ zd+B$gpoIKQ{`afDcfx_7EI`9(ZXil)$Ejz5qLt6DwB&BQl8zU=9R8e5SjFDzx|40` zc>ZBe?4Q~xjvb+U92p(g_|YaL7n78Pq=4{!f1)*ay1Q9!uyj3dsjAhR+q+pZ3 z0J;*EXI8nY6U#cPul2~;Ou;!_ZePu*q;2pvKH>I*?Z@cH(p*V-59d5%jjroG8i0a`?x`;OXHTNAAe-VWuI zhRHNt%F)Y8Bz}5jia(TRQHQZsS*XLyyDijX;WbRwmIpHy4V#tq^1u8d4uoRPVq_H5 zC(-ALiF2#~{>v4lY4Z09?N17H)rTLQ3uT^PHoW$RB&R0OP%)OSPQia z)<2h2oy5YB9w&bwgo(PLQnc~R-6&(m**q164HK0r2Q}vBPA}#kQP%f#PdrSy<@Z7a zz0&3qJ}X?dGdg@cF5(%I{*UVMnd-;<*j3#!ew_9G^)bq7b)6vDU#GO!H40UPxgDZB z)ihQ4lbB~DFqw~qkF?}^ROw{4TN2M=88VHU207Og_Q=Jcm;LF{(8P2_pf8?Spryf)t_e~@8Y!1Br1_C4fTe-LR z&W;s>qv@O8*_^yZOZu7ad!Y3Y!s%&l8sPWQKvtdVdFVXLaO-Vk*NTa<^JJ%|hJ&mr^}m zaagElA8mBugL!dgS`7NXQCJozd!vSGyfnT_fjDU}xF17}IWnz-V`CI|8%N4kvHF(0|tTika+aLW;b zVL(p?RrBlG;a6dQUCl7KopkN(cC|8n{8IVVq0FMM$8?w;t5?r}Bk7Rdb$3^JY&8sN zqst|0FHzwrnz`J2a`>?&c`Z`{GW138Ml;{{SQnWiyC#Eej}#_hN`@80i z*Z+7SEBjHoXV7mwZp$e0lpjyY_=IMS?2Nr?Tr!I{^2 zIh(LG7md8h&-cImpt^Op(jjW|sUoVv7Q|jS2`i^X(I8ptUPs61pHL#U!_64ZebuJM z_wpSaZ@6#NI4A%4aeWuDJmA-sK!x}1x=r!x>ezS043)cfFnJ9sUSW?RxzTE+D89u& z;RxqStI}b4i>-u<2_lD_{aqhW-Cmck3cKknUa9q4!bT(we-^rL9Jp&XoplUnYagBK zLJZzKIJ$CK7MOfjC^YXS{1vKF7E~k38k)fCFRJ{W8UQzmF~Rv{V1X7`=cm*jTAWH@h9JXrVIy0r}X?E(`-6d z`%mVsi~#2>)NvliRk0YZ!z01XT$^>gt0~=2iK_l

Y^b;mdsG>snXiWi@FF7aqPM zuQ{tLoKT!rWZ7Dr33doh?n*yh!wwxvoheX$7ANvlY}2s9a;`kF4@(KH65{^UMj;N% znV+4ykaVo;hSeiV=b*qSu&-t3Nh7~gu`VrBPufg-jHnPz7LD(SG++5_l7n?sj$aC_ zK^4`diwcU5p-X1Uw(1WT!o&t7<2Qw*`v*ueJhX{i<-R$ewD(YDQ zCcAs3;L+hTWDItBXl@to(wNu|<+Ru<3L1HyXmX(m<>aNH$XBC~TzwB8XE1?jyZk(= z!M2{-7cFVV)PG6$^?Celt1GhRbF(o~k^vlK^0mCqj(9MN!Q7i_fH2J+%C*f9{S`D7 zSQFK=IpZJzy(u8{~f%V}|6 zpEOP-03H@Qw7C>3>cQB3;EFhtG(}MS}1sh^RcAJJ6IE5U+1#f1MC+Q((Z1hYl`Xn~g z+%$C7KGf=Q=&TTJ%LuhasGeI3wa12?n?SeV5!bxKoG4+=jIe7o#p`Qfu88oz>55*4 z;Y82yyRqS3Y(*DtxC>X&8xe8eFycNQ;rBS=fl$%M5bgtmKNLoU*(3fjjC>?5dyI&T zjC|n=_vc2w44@*S=!jR~d2AB&`rkngF;Bs%g* zEIgSG58xudxGJaGN2LjoUolD_U`pR`O6ho|OhctwCnct*Qnt4eJ5q@jtCYio=Luis dVxk!&<$U|-d|gBz4)Iy2RESY-#b98^{|86bSrz~Q literal 0 HcmV?d00001 diff --git a/images/任务查询.gif b/images/任务查询.gif new file mode 100644 index 0000000000000000000000000000000000000000..7650c710a8d995c3958281948b3ecea3e414d735 GIT binary patch literal 1270 zcmWlYjZ>3#0LO=MYJ`M|ui+V9rIyGvK#(H99Ri|GO;5=b>?*<2H1G{OP7nzZ9grfO zsb_GCMkoSD@+JZr?--21=9q&qwrA^k#-3-}^YVLszhC(I3%=jG&u3F?bVz8DkHkm9 zO5T8{VR;whuv4}vD=AP83?O5tEoK660%9R!p?M1r7=T5r8POns8OjNHED8{C&|Arwi}`BrN2VonZy6)s2m4 zM*Gz!gVAKPP)>j;J7aKQ7C?%20Eiqs7&RDq5wZek?(7i|<{`2RqEi4YL>$Hfgd700 z(+M%=cz)bqATgp5WHI6~WFc^3FlIKg7>EdxHp+oGg0gaepZ>#R!RDMITvn6AObHY% z(j4Zjv{f~t0wQp+E+aD`V4h^Gy0KB^Sf7cQw9%y5skL%Chym%Cm^2$)*kpHD$0u|m z6hu7zz((1u0=7&~b^#?sEXUJ8WLVI9>-IH{rvOx8Jb|$ZV*+FAlP47z+Yn+9;t9fp z5QI>KqD3>1f`mRSsxdTRIBC?LA81+IUB6M?mknL*nD5TcN^_2;z2T`&9jc%0L4bEu<4u)Tl|rGp&AykW5N zGiB{A=d1JVe;wnE+sTdu*UJM_y+;_e;#FJbU}Hwj1BHF^`SZpPuVdioPM0mG+T3%owhm*ge+#>z_X?(%wJb zclT`l{p%b#jzmEexZ4R!9;V0sw&&v;Uw=|{G_)>r_pAHarlyTGRR z$fZc&NWx^d67_{Sf`b|A>SCv*Lhk86hG!to{#N;t+8y*zqe%NNj2W{a=q4jp6l~W zPOHA`w@j|z7SNzS=n=x3qoNly`5v3?2~W3e325#}%6UIs{$5wO@3G7mi#h2Bk?$tQ zZ@jYdRL!#sK3hDK6mPG~eVMaFz9>=Rl{68xHQ>6u(A_&sDQ)rI^ttyluZWStIdf$( ztMa}K5+&Jlq7w(7ztiELDf3AvJEvIF?kkOSUz(OUW2Sfhqbxr&SKa2dK0jhxsL|bB G681lQ98^gF literal 0 HcmV?d00001 diff --git a/images/作业查询.gif b/images/作业查询.gif new file mode 100644 index 0000000000000000000000000000000000000000..b05180324001ae4567d7c30800aa1addd02551dc GIT binary patch literal 1272 zcmV&MO9N%UneIi+1cZEc6;~t`H+#Fr>n@eyw-Ytj?U26>Fe@} zmb-w5oh>s#&DP{;Z+BdNsceR&n5n&QcY$q>wMJWVLuigdV1HYLtck48Zj!Njp1rKk z>N!YKb9sHW$I?1jX=#$GhmVp~Y;l04tjgQn!q?d+I5?rXx#a%-?*IRsq@?uz{&976 z`Tzg@|Ns8~|2kGxK37)8+1S|V=RR6kvA(@KR8U)ecRNf;;QRJPc5FLPOp?mGmb|f` z$-3(I@o}Dr#_HK%X=J?F$hEq+*xlOE)Y3*%O1iPxjxw);`+06Uzd-!c3M_8^XsqGy)3+{Ka7Dz|NQE>s%gr!RlT*9 zp__v8>c*Ipe*XLJ{rmHIYBJu$VDZ&$Bw2lvuOJ2z1Y^!vzJiW zy?FK4jm))up@2Qu!kpmKywk01X;wIncToG;q50ml-^r+LX=8tMWx}Y3{`2O_v6k}V z(#*xZn1O2c@$7I+F43un>d39sxTpU1@n=^~%EiKcWm)_6^0tF)@YKh|hHduAxA*Jj z;-`|@qma0jiQUl5Qcq5&XjiIuYSo;J&v|6il!UROo}5K8y>(@lYGXh+H~R7Lz>CUC2 zcaJ~-CR~;*VZw=*6cnk}#iLg$7qx5h3T&WZWQYzQPRs>J@oJqrcB5`(yHzfMgb+n$ z$gtr=oToI<;<(Fq4V*f3`~+}t5u^u>9ZXD^uwrP_xP0->of9B0oR1+sc;vY8!Jh#! z3gB&b1Xms2rsB%$P)^r!blw>z+=iRvmkSgGlYavLJT#OVMqoTKv01QDr{m( zC9e#_3^L6$(ZnH#d~(PEn2=-710J|=LLa8+5=}J7V4Lj1r;Kma?hy1r%r literal 0 HcmV?d00001 diff --git a/images/堆垛机.gif b/images/堆垛机.gif new file mode 100644 index 0000000000000000000000000000000000000000..b57fad21319a02149758568b35c1b3f447b7021b GIT binary patch literal 1272 zcmVrO+Za8DK0ZHG;wBsDkd;LK0+iTEHN=Z9wagxAuAUjEhj23ASW>+ zD>fS-Cm=9HFgZjNF;OW$R~;%j8z(g#DK{oBIS(yN6ERN_A~PpUawbG#8ZJT}Ge{yf zOFUnLE<{>UaF9!7e<3O}CM`4~C@w5BIw>tN4@P(lH(eA$Z5K;?6+B-NFijamZ51+1 z5hpwqE=CtHND?A36(uw&M`R~MT{Bj98Y($1NMR^BNe3D#C0>vcE=3tPQ5P{r6e&9r zB{dc%Gc8MG8Ywm?JWU-aF(xfD8a!1UKwBU_RV`L^6C^PxNn;WqD=tV}8YnXp9VIG2 zQLM4G6(}_?Ph}P)E+RBR8740sCM+f~IWRm#H$FoVBQ7C0M;$RfIaOvOF*-0*Xel~G z8zn1ETVoO>FDpDnA}=;9IY1&TF+@m80Tv)MMNB0zHZVLv9Vjd%H999ZJVaJoB`q&S zPEavDKO-wEBP}eYtg2&XUu9=uXK7)Vn1-^jqPVoA(Z{H|wWM2FQ?jk0y0W3Vv7dW- zc+JJO!Md%EiGa4OoWr@P$-b_>w57MRt+}k6(8agQz_Z1+rOv{&y|Sjy!?u2RZ`{?* zv7wRD#kj?}t<1o*z_h8&!M3`urQFcP+tSLcn~kobnAgg`=GxHG%EPmync&pRn~8kR z#J+%SV~%rYuz6>DP(*H8ReDoPR!BvUWL(BOD8xZ8LLwb>KR1$CPn20vh*L{-P)dh% zalAe*nK34>IxUqlCPOhVIx;b!G%A)hEqW{_i#9K7DHZ^P~C7@$rRW~+$W@U0bJ54DmLM0_M zD=S7qLjV8&A^8LW00930EC2ui02BZe000R806Pf;_{lUuiCS4-R$kF@JNpxF;A4JS<@rTihd>@gkZOA+<^m@64k&0C5<2* zcfzy)M?!!Fa@)K$n|DSM95Pb;c(EdfP7Mww7(gI5t=lT2@BupC i7y&~ei#Xs91r&5pk24cYkk17pd;kImB8X5zKma?@xzSbt literal 0 HcmV?d00001 diff --git a/images/å°�车.gif b/images/å°�车.gif new file mode 100644 index 0000000000000000000000000000000000000000..f14f92b85171a231e1f493c40189567e0abb2784 GIT binary patch literal 1049 zcmZ?wbhEHb6k!ly_|5#$_wTO|ncu&@{`vX&_t*E+I_tlG zdiV3|r|+LX{QLd$&84H?UqAi%@$IjVZJLYDzdO9^&7qyI4(&>gium#5 z!3kTni$S*MV?6I>hTg8vd(vC;bmNK-2Y0^Nx9#=*?Qak7etu~8hs)=#x#+fQ$)2*; zIq#@<#ntexr|DHU<8z)SC*6%Ndz)SKHb3TOa@O1OYPj>w#K33Sk$2O>ALmA&ObB|E z8+#!&>~U$z!?M)d&E@ynsvb;eezkhxhhqm`pE&&f+{t@~_I-N%@Pe)OWqZAA4*J(! z46isDU3WJ*>0ofv)9jM7$t4$)lTOCBJuI$yS={ijyzX!ND8%Vju+x=5hl_zucOpEl zM|wWaj6M(_aN8z%S?r}@KLpFv7 z989-5n%>MzIGY;tWYfBrdv?4&xcB9;!yj(lcz5f@%ah07T|9qfLhtKM8{VBh{q4=0 zA3uHoV-_64qXfb&LXt-=>nm9-L z)R!|8gPXaV_(Gm+VPHOVfL%YuDMR29<3R}x<2gGF)jHc7wV8ajay@kJmP*`{ar4o0 zehEY8OD_a&H?sCB*uOAnQf56Zt`nQ`CEyB&kffu-B7@9FX?=67%YLQoe6;wKvcn{! zvlk|}cTLqSyyuX)Iql*+k68w9Jq{ko>{Ruea;5T+8}EFFW<5m#i-rS?jod;D1e=Zv ePWPNEBT&LA*rduRqw+*W!qJh@--wxs!5RSW0;in- literal 0 HcmV?d00001 diff --git a/images/红.gif b/images/红.gif new file mode 100644 index 0000000000000000000000000000000000000000..1a992ae23774278d2608c3898e9c05c916660acd GIT binary patch literal 499 zcmZ?wbhEHblw*)%xXJ(m|AByk=|3a$e=FFM@Xa4{H`~QDh8iTPh z!_1k+X=%nYXQuuCfAjzUXFwTCBgU*`<2h4P{{J|ZlWdfoY&>^z%G^oGyJl<83*_8a zps_Vy_y4A>xk*Or1GqK>a2-oiJDH+(JXP&`jphFi&vRZ}mt6SX8}Wa)lK803_d$d2 zyS~_eGudB?LjRRTe~Iw?XJ7z2<^SKmK&Jp5lm=u2orwVyf3h$#Fjz9^fMh^^Vqp7! zU`~Mtk3_%QqN0;IR`b1O`q2c73E-bRxIih5}GYAH&d6N z(@DHo(1THE<*FiPZZjvPVn!}^we6+6Yzr3~>wBmlF4bjUs8J;5ekSv5xyi!f<%~D# zm_^Nmi?5j8uanu$bm!XHn$-E0GR5*QYIRu`e#vY*Tz3B3&)wz=4)ZEnuq`Tn*ucTs z`rbig<3WDe1I=C;M;bZa@rbHPMjfzr(YQ02T_$YGn-dEUuTwXZ$=FFM@Xa4{H`~QDh8iTPh z!_1k+X=%nYXQuuCfAjzUXFwTCBgU*`<2h4P{{J|ZlWdfoY&>^z%G^oGyJl<83*_8a zps_Vy_y4A>xk*Or1GqK>a2-oiJDH+(JXP&`jphFi&vRZ}mt6SX8}Wa)lK803_d$d2 zyS~_eGudB?LjRRTe~Iw?XJ7z2<^SKmK&Jp5lm=u2orwVyf3h$#Fjz9^fMh^^VqjZ* zU`~Msk3{d0B}FGw9!V^|#?hRuX1L*C!Zz6iu4^&bZhFP(x?Gnx>ux`5JV{7dTiB1q zqO!nq*(pN-x2kGUMknzUL3bg6mTEI6r4)C@{yet!6rpL;3q;L?Q^e-ZOO=_(G<#Vt zvnYq9Op5%nG}iV_Tho}$oh){x>AB=@Wma%8NnXQj;w5>iDqqxxU;9X&@d{rKa}k+j RW?dQnL{Cu>$uLI-YXDFaltKUi literal 0 HcmV?d00001 diff --git a/images/红22.jpg b/images/红22.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5b476940f0f7c7689775dee2162be942c9408e45 GIT binary patch literal 32436 zcmeGEcU%-pvp5dVlA{C(ibMekl94E|A{oV%90g&?IV?G>0YN|{C?F!Bh9|5>YncE+Qxjsd6;%`g2o?lT z27dtN3(0E*FB?k$P*VfA0RSKX@FA1{HV8q$9{`~PaF1aCFoT@=3EM(AztdoWG=c#5 z1kQlBD@5oRrUK#cU>gAEd)hSc{Smyu5|48I_LenwGP7X5Zta9{agrue!uaK`8!!I0VKzDGLcgQAed#~#Bm5PzXj$1 z!3+a|00{vB0U-eiAt4C`F%dBZH5myB8TF}?C#g@KJVilre0_g?3;gR7LP|_bdV-Yv z#0he$6DLkk9X(D^eM>^|-^l<|4^R*Q&w=OIkh1_51q7P{f*A#?O@wKHKtV2XA;;JE zDr19+f`f~PPe4dS464KLkq`h2`$r@>0KtJ^W8q-o;^PtEVv`7ikrdcCER=${vg)QM z&$`?e!lR0MQFNJ=jauW4neYYIJ6&@4?9rO5U)JDmA~Y$*chAW`(lS?gn~D&n?biNk zv0f7RuE%|1Ly_Zg+PzmX4ZV|_>7|W*Q(HQg9zn4gW$*i^x5bontvrL{GRvC=W_Bn5 zEG&>)oMWEw@o+_sSzr;Q!~r>QIeQXU=ynv<5eIKHx>kkR%)YqZiI&r(hPz!@W5+vU z0RNoG+isAFR9bTdZBc~9*Pkr>XAU_2VgWM*kYFE|NdZ8CEv;x3b}qKZ#@mAFoh;8? zRaMR7JM82uZsEJ7OjnH$*fS=Pdab#SzGin$)Lnq;&O4qRe)geSrw4oWy7}}AQv9r4 z$&tAF$^y%D{@w{_I`jz!@E}W@IkcPAqa1cMn2Bh!sz4LtpFglPd-eX@`SF9yNc_*Q zQI9|5Rkj7&hSl6f^SNGU%A06I=6SKAc^GR~)*kgG9`sS`$XKoCV1V7vTZ7U1jKJk- zN_F}@*j(&nz{zI$>r-F0=uI}0YLnN(dJ`CP=~k$-L(l^A-dNL0p&Jcz@8Ul|RS!O` z`<;w@g0_}JRmoHbZ)IjqHdSExs`lpcg~=Dye^`?&cFejnKtXJkacJK1qWy$7vv>BF zj(}Cy%EH|;fCDEY%HK@0z%bq4+Tu;VZ|M!{)9xc54ZL+yqlM^bv7uaXknD!QIksru z8!Bwksz}U7P@3ApCAp1R6^WNFJ?$+BB)R`UA-Yvq=7DPKqBF&yGm{>={6^%Ard*i* z`}FN>7PSA$NB5X^Cim!NGYn#i}(NThz2sx*nR6%j5r$&pX;rOFie^ zhl)n68VrCJUC_5>S1_6@kjL6^{~#wT@L_#2^D<0^1Sz8|hw6Sn-w?Zn)Tn(~_sqYp z-&x72_e6#F=I~+K+Fh?gKg>FB0nQ>B%uP zR_{=J4lKF`7057>TH#OF%e%|5V-Uh|^~omd`QimgzYu)qSLpUGL5^3T*j=bU%2k+2kpe+1>MPVlVIV0JUrlc=Fzl3 z(^f?XbVbuBLxo*?R0C9^$BCeHOTv6}y@aY|ZugOurWKH%IooO$4FC<5gFIF31s4NX3pQ1= zZ=NW~c$KuqZqe5xnQ^0d=$#={Wt_VECSqVhz^4ogekk(I)+RWp-;aW_8!~I@E&fvydByY6|(XOs=>zNNXp;cGw z%xGQX*X=w-gzuX`$M9W!EPSoKmjZqu;U-gc8Q zA(Hg6>c^?f)aC=b*z8Yan4Sdz`Wc2Bk}+8_p{;Y{4QTD`z3eAwodJo1FD{Z@+Y-+4 z)Ar{p7OXx^y|Y4!Ys=VqrtK1JUg%a~SD&RiDwHi+h3hviIOsF3MJF;QnCsDccCUD* zh|}}Sym6r+xPiP@H1^1SRma;~Gi1%r=n@puyHvDRM8|=2FWaDG$Z;je6?M>rfKjX1CZ9hJU)!7Ly(IKyM}4A~9Kgvm@CjUFIxl zv~fb*snqCm6c3P9jE2mff7?aLOgn? z$t7?lS~It6p06~w%jen!jloqTWM7-m%&WJXJlq~y_|bJA-d*vAJ=|cdB{#wJ&+j*S zQ@?x~G%nKM&XadIDf5nzxL5KaXIU{V{(z4S{F$l7G_xm8jo6#YXXf`m2-Z$Yl|1`u z@m@=vH?OpTB?oqm`_+-QfM2}7X}I%x7pht>VOJHrk0ZyL4=6yy8EjXCpIoc|a7m=H z!%W;oResY4nwuz96z)P^6(nYNNqe;@LG2P`(7@oymv`ihWC_zJ?2F^VFauj+uf%2b z{7o`M`^AIur-;v!kzck?VdE^h+0LU$iM#%=u!l)=#3N7a<*PTw`F;E1l@EDszxWg? zmc>=P?Q9Qh_~c6#8a;dLagL<@^hjV2BQ~@W4a}8c)coDGgV66t(>wl2Jvxs|Qsw*!x#Mq`3cH}2Tp)FPucWj-sidt=j`FEHoW<}~DXY+P$r9iY zr@d(E_GG-$?XU;3^ti@s#noi(*4xx4ddqu+ zIIi)YiE{I-4<}UXKkTRWadFs*0XeOB%IFZ!mwvjBKj2#2mrhR&jIOp)o)Rf4 z_nA@b6A{S(B4J8Nnh{rcY){BKXS7bvT>Q?doZyNBnhd7inAiG#WTCn-aVuFy_7MBZvXQIYMTk>OzjZ)#5((lNZ*j z+ZYopYHdgq9S;~PIj$LpV?h~qM`w~lF)0e(wMFvcEy zf~ytqf_%rkh=2MMBXo>60G~f-M2<1Me_@Wf*#*M@;0&(r{`SJ2J&OL@D9ryaamSK5 z${MWOcex#{3;zlc9EXnN0LldG(zp9NB_oIhj@Mt`WJh-t#0Hln-|Ko51c2u6H?9@8 zHU5()052d2Vvbgn|9bt3`;qE5nqLWiM0{uMDCp>JZx6nXDu8F^DqWh!sG?%KAtAQ5et7-Ue>rrelBA z4GckkD+l*D4n$LeH~w)zMgEt(@vU5)+?{_z;W@e5SlKvQIJ!H4X-E__k8+0{dX)f8c24k7?8Z)c0|#6;hSk1$6uDh^i6;Ol?8{@CuW_F4*hT3}J%g?l9Y z-!W=#Ru;cu@J#IyTBcUN;ZDFUz;qT~2o*PFEw!s=PEPhm84~>hvY9@E=@>>hvY z9)Ii}f9xKA>>hvY9>=TxKX#9QFiJK|TR~Knm*RYznutKrowGfa_0bj+N><4rUv3X%1ZxH32ne zISXqWWgk}yO`mI8a34FkggFOPhDgdw(#yfw!2)5*?B!tZ=qBkU&2gN$BnTg&`8k-6 zNf36@9C~WknGxWs&dvtG3|f15g~WN7EnQ6=EIgfD?U)7mL^;3=UCk{eHRKh)X9tF) zIllAl>FLSmDa_~OYQ--oAtAvpAjB^u#0ygJx_LVyOucv=-B`iWj@hu$`e}cX z*A^^@i21lEc?&nVtBo_l#>tWSsAyBrT7Zz|aCf&cm$VQ!yI^4{EW&FlY-Y+UC}<(T zYbGplf!9<_%tBaPSU^bJRFH#+`FoKT;6D7{7kU))qgZBUsiUCe@hVail(>bApcMbV zqQFeQkzKd(var{aw{fs=bOTwG5fTviPW`VjzbDcEk4b)s0Y$)nROer0@V_7z=Uq_T}0!pYTJMvDL6asM~$BWx`HgMJ;w z{KE86P!hBlS%975NUx6+?B8%l>T-Xq|5!XMGz&|4Xqg{W*^^YX*kBI+h*B^2HBMJN?;y>E;M_m6%0{@8kf2v(X zf7$UZ96{r~CupU|d?nFSk&`pIt^re2xvFry;XtB%)yB~Y3v`)ta74IjC|zdO(>Gwo z?*Luq2tl7c&^gW&?&hqfsd(hq1*j;&(o5;s09@1>D&c z^vr@>2dRb4K`T562ZFG@C&Kv%f8^;zWoCB-V;#BaQMrN)g7B#$*y5JD4BA4Iq5q!~Muv4*Mzy2YJ|7c!F>*2(#I{JJ^8mk;f&KgM}&R zz=w0>Ma71&fLnvG00@(~YH7%UuoUQtMq>2~Z1xL`0KL{gT0qXp+56a!iwS^$izYKR_w^XaAxrUP<{^pP7VEqV|xzn zT?GO_S?4eHp*hl*Uv_P5EZ}@c0{waYKM8(P{%7Eq^7xL*`zbqS`EPE2%tu0ngKm88 zuFP&nJ1xw-|Ek3QuFSP+UCy4=Uqa-i}^0VEp66%1Pi~yj^H1kdGK^Tlb ze*X5riU5OHZZ^lRq=1};7Bk%4)#Dop&e01OAObfpsesb}Bftu9f9}63c1d9rb0qYzVKbAO_EY=k)Evy?@ zR#+}rK3IWR53!zLrC{Y@m0`WXYQ^fq`i!-JwFUkOl^B}_n+2N}TO3;s8-{IwZHeuQ z9e^E*9gCfUU4UJM-GtqP{TX`^dk+T>=Ohj@4lm9{9AzAB95{{(P5{mWoToThIAu5u zI6XLDa8_~9xTLuBxaV;taaC~jaIJ7Xaf5JUaWimBaT{^_aHnv$@$m3y@Hp_q@RafN z@oe#Y@gCqM;uYf6<8|Rp;BDdK6Q3oPAXX=~A-+ZYg!mFP9=SVM+8jvDLAChL1z9StY-92&g1m6jj6Xqw7ClXGSo#;NXOh!n?P9{rc zOy)xtOIAYGNw!E%NPdo7j@*{u%WW)5Bsg7x$nVMOa*`E0ca|81#3q6Z6 zi#y8;mJSxwS&p;XXYZUXJUhxt#465e$@-Y}E$b>96Pp^FA6qWl5IZ5eIJ-4_9D5V{ z&N+^Ay61w=m7kmCIK`pD;lq*3F~Uj83FUO*OyTV1!s8O>vg1nR`pAvNEy8Whoxt6B z9_zg5d7JZz=eu}tc_eroc~W==cu9C=c|CY@dB5<{@LlD*!&lC?%+JPez#qlm#E%vb z5wI6X6Brhx6jT+wBUmN4F2pSa7fKN76($u{6h;bH2(Mi@f5GBH(uGeVCq>jmf<@kn z9EysGx{4Nv&WW*!-4uH!HXu$VeqH>5c(Vkq#AOMj#A}H?Nl{6JWU=JRMc#{c7jrJo zN^wY8NTo?lNS~E9m3|@pS%z8Wrp$Ah&rlYqDKrK8^%CnP^Gg|*W@Nc!ZDsRhmoE!k zcD-DBc}GrC&R?!x9$Q{XK2*L#fl@(R;ihU{j*(8b&W^6UZnW-a zJ$^lZy;glXeH;A>1AGG=gA9W$Lj}Va!zm*XqadUH8yq*hZnPNF8QUAzn2?#6nv~qc zy{UUM=jMSa%rwPx%S^@Wnb|5_4juJvh9u?%r4UoW3Ovp=s@6b)1lIl($UVb!HLny%c;xxymOHAXBSDA z7?)MoE3O%C5Vsp{6$mPDGS%kJ>3+}si-(Lyg2%3>j%SG%g_omOn>V+2i1&<-qEEUn zjxXHztsjfuZND%6vi>guAOU6pZ;`CXK;+adrCV9IiEi87ZoeaNC;HCjUERA?feeAS z0w?Y%-OCL+5#$;)5PUH>`998loBJIh!Xfb?=uq>}4`Bjfv0(=f;15283x+=l$2_!r z*byNbkras+=@{7`1&zvzrik{5o_M78sO&NGK?QEh{pEbo&7%I|E5&b1#7hcZvA=p&da^XM3{vJ@wpwmo{<%WGqN`H1@@>_{s?ut{ z>de-)-yft|{{7&y(Z-aV6N8^>o=J$&4-!;iL z)ip~uziyFisr(@Rp}bYJwX98~t+ZXFy|hELqpVY`v*M$~$Eq%=uG(&B_nRL1p7*^f zy{&!M`nvkH`#%jB4SfD&{%Lm5esFEbV+b{TYXo;Bbd-EFc8q>3Wt?lg@U!UWnlJKS z+P-Rj9iD(sEKIsh9!v#JlTOFZFwJDo3eCQrQ=I!aZ#X}-;JkoZ3|gXCdbZ5D{A%UW zO53X5>eQO+8fN{$#_5gB%?q1vx2|uEZ98nEc0zYg?`G|Z?=|h~?$4k+5AYA39C962 zp|7AvFb?2b3|Wg1g9VOkBB+o#N;*yUan zt)9E!N_6^7mk7rfP0>4R(JAs;ZVHNGN^nkX9bLNOx7}aY&F>-}1zMz*yz80Z61UuN z=a!IER#62fYgX1awjQ2d-ahw&g71ffK8}fvdlLUNEj=SMD?8^^X<2ziWmQAt`=;iW z550Z;1D^(mCa0!nX6NQNx3+h7_x8c+AD!!fgN=)WgM){M>j1J$0iNrCD~Jc2Jt?b> zFJwyPLU8#uYZSG{3o{yF!XmaeU2?9gv|sLA0FQS#1(#n-DLyB1T1!;HoP)^i?juFS z5x?3N?mA+D_l_Cf;G%n+_Uh<>hnR0CJa8)MT8jTXci0d{_h7dj8BYL?HKPY*9_F43f)%%7Dj!4MNk&h z2Hg?nb$4K=QYF3+<4)f5K1YJb*a}?ZZq-#ug`CQ*P~W&Pr%;pLH++A|AuXmenhTBs zq^Scw?KQ0-)8V=Phr?&=7&lEHeAF=KT$rh{tICnpa2zi~vVJmgp9#<#yqj>?FT&bP z4qKOo(cj*=vC}%zRBo&}d1f$HRXs^8-0d2B+_Yp~M>__%2ly!t3HSCa&NQ!h1U6@F zuKB;x5b_2f2W_v5BRXeB>?(bCKIlAXwKQ;*7VLLeSK3kW{~{5@X*n$tY^Reh#~_al z<0dn{zr71)#`#_HhUT4e8b!*DWX!wKyOicFzR#C%` zzI@^?+^_Y&O2afVzI5-kHQ!!=z6HG+0X|x|r)(4~pTq-x1>4G_m&H-)1^i+C8Ivge z-I?Js4B*A^A$MY!Y%9Q@c7 zby?4)=*Am6i$o&oij*(615EQMpS#|fs8pxLzVu;FB|kbMrsPdYX=#Up$$cwNkqhoy zT8Qqel%G2ZidgtD09RdK%|p>~FAuw#vx-16c$5ZIucRY+^vyDiKP0J}kb$P|UM=$D z9>T|izuhr;Tu`$`F7dghOafVT#)M9o9$hSSXj`IaMlEHROJx8mhz=-%KdoIH`?~(> z5qp0h7vUk^9tKdF>U#8UWvTF)!Xu`~8P5c8te?^xUZU7HhYoytcm}0kFZh9MrkB5B zJ!!ABgncS38^0a4SEZ|TK_kn0)QG|*{Wb<*dIOEHeS?2{R%-3Fd9VhVzVu4Yzbowz zEjGb?{Co9Q4qx~*%wOo@HZA6XWC%{l44;h3vCW?F7fiiq^HAmbBXj7Ye@e}W{r2ut zyXt%LjA;mtsU)>&W2f3M$El?ZyRbNBAg4hqQv8;`PbxC5u2U|{$HjHnGmk4}6ctKw zK|m|5>r}TnH9;DW`z>-dg&l$o&)PGJonMESLeEuDzu23Z8BnhU8`ox;sp9=RubGep z$H8G03+CSJZoi(7Nu_yvrw@h$3=eMQX5UHmHy7;~ecTac<{}KcI!BVvsW)Vuqjsl} zx8eZRbi!;0o*=ekVK*H*GEizOxIIwN>nnCRj`SS2;r$%TryYdyy1~}Use^Ni+gi6* zH)ptQxu(4$Co{jpYU8x+(|AUe^k(y1?!m!NB_^F0p52IGg1Iyd=!%haN-Zz?t3ba< zTRt3qxtJhDVd&tiR{EL%{AX?#C;t9*Nf-*A>R7Wf>Raf$W4thSI8Zg2*ZQG^3!S69 zkIY}`V+}Uo&R+w3kd2Pd#u(+J!&tOWvQ)(+ncC?^q}|>3Rj2M6=W|$u9nPT|&Rw@z%&OC=tm7g!IjA;&0H^J2ne`oD^EU5PiSz z9gL~(wcLgltS_Rn>E;gQ*b+6eS&>b3p?3(}Rq2%T; zI;@8Cs`PQ^l$Kpc3N(*}NyYF`w^Fp#tGrs9dqVo=fH2DGwd+B5+IGi$C98 z+&k%V3TI!Q{TzgUIGb!mH2?Pb7JaJ|50Cc8yS>RCa}R%$_D-Gqavi4YcO56HW>E^y zjLs?Z`W(d0)5)3x06a)_>{;oqN#)*>mjEK8zx(U9`JJJ2-lskSg!3h}h8RFl?OxZZ z2Qe~YtV-%}L8tpK!XOq=8qNg7TEW2&e8VeCM$VIlo~Dt2Ji(rpLCTcaEu(fMr|aB3 ziMa~xC)H}=?S^{Ob@w@%x3Xy4BBo)(H7l_#*EN@o?wvcUpF_c%nUfVxqQ-t1g3^A# z`=aT!;tZL~j>EP-t6?m8v@_w}!T$bPRK;Pdf6aEz+YieQ(Wk|zwb|pfp5DrAmsZj? zyRoE4_wL|+lf|b^TJ)%&5+z#~PB{Cd(Tl6;N z7AJt@b|)K^RR8-g+mAuw=-bzmctWS(jx3u{a~ipEtbKf6tTs2Z?YBP- zt4&4>8>Uw$^*B;5f3BOWOYMI%O1j=kSe-Q+vo1&*br$DzS4dSO1`r#bHyptLMQ%p4 z*0-9EHL)4#et2tC!e@Faw*6H$G%&(sHsV?Y8XNJ^GJ7KSbktVXq)>7_`T?@AXpvUE z?fKn)w&h{cv0>q~s3^JaJn~Ddk=~4bo0nzrf+KFAb_|X?^fwjj{;6W!CJ4vZmIKd| z%4)qP^in-bstRXy9NmR5K=yX*{QP;n!AaBGUCT``jaSND42BvSN+7pjC;Q0!R?ucG zB}MTM&W*G*QO(Ct;02{)W6`9Gcj;s%%6#td*&)$yxfns=4es(&St2 z=-VD;9ikZn?UJ$SPaS8LQCQ*Y8xh&^=4muqYn5s^4-@8ns#1sNNmGJq06(fvoWu-6 z7*#@WlA+r^`=r|ugB^yGyeZvdt&ZUg>TYS?kVA^OE^SYnQzb=~=O&|7CdcQ!w`tg( zC1u8FU!qpPH}Xg2{^u{szfF{kVg?Dgm09QDEA>4&#X(f841^bl%|1+VI_+y=Q?F4TsV@)P|2kO+?Ftph)f+ulci#l98nKIkIni?>5%F@!RUi z7?Xg9%r$i`?QQiHRwa)HNq=2`zvEoS!<~5^{TKs~8AN-|xI2kGikWgG==3rTUEy<~biyo5@(#8EC|_)~Q!= zlA??A!C6lg*YvY!7~s_vvX3I=ac%Zhe{yhJTCI5W(_lVFRj3G4!-u*rtS@NoH>fc@5|Liig+sth5`fRg9@?_?Qr{wMVGJ3B@Nz&=igz^b)o)jScR|4}Quolqh}E`8Fwesp`yXax?!F zgXjIp1sAVIXOg%`<*q|<)~2nQPj|+bzqEI2zK=SY73_)LPp;07e6-`9-q?bFDjk`8 zS(@yCqr75F+M8idNmZxu?Ii;2JN9Z9jo%HXAwB$8Lt87d4(dM5;(H$M8u#Vh=J6KN zKR-XdDW+zayvNYHD5+xSNoLIxLP=}g|HLTfvYwC4?fnfWgZL65NP<>xBrY>OBKd|_Rk|JLPis1U zYJ>l2??btV(gmee)``l}xSmT7N#71>dA-S!HpFl2j1sA^T|{V1-k>%Q+RrrIw8qV| zV(J;mZKZ#^`ub+e0lG6;k8mZkq-;1Qe=@|9kQvSN2&t5x5Ww#jlGfe@pGe?Le=3gq z;KR7~U9=NZ%TDx2Q5%<}BAp3r-MsrD z&PNBIzQVI!d@HLd8aFQwnT1Xoij}2{lY#}}Ye3(vs=`s&Qj1dMo~5)v+V&1=4!uH!4! zT=s9Qs;>6v(-5^)=9;&igq_P~Qf-mSb;fxpPU+9PLR)U*xHJ4-PMWHG&u4k3ykDwr z3C7pxT7A=d;y&GVqR8j_WY@wmKx5rhd^hU7Uw~nWu-kOM9979geJuMUlRKC11(NW% zzdS%iNkE7E@9d={xK{{as}?9_w&sbTz}1wOShZg+>Gojr8A<)(d18J$3bo61S!1s&-LwNDMSHmn1$Yu-osu~wi9d={s-rjc;cg~c6{7xALC(s&5HJ1Tr(RGf*Wya=OI@Xc5wuwkxES#9%Q{%$@2|LQHoz%bQHS|5Y;2DgSLHv;nMz4FlLBy;3`@ zw%89aKAKi`zH|ZhN&s&HDwJE*GDxkgqP*DamzaAz_wfVh$&>`#zFA ztqfpz+ixL=r7UB@x<0=caMmv{nL#%^RJFgXf(ly@{c2)E?6dDvi7QX(OYZlENm zb;oFjP8IU5m|rn95c`4w)Yca)F~Gybcd*3w6HTM|R-xzj-|VL`Z8&3q9I%sCSLdxY zjZUE*D}q;;$~BgB%dP64llav-tk1u35t-A4o#DcpPje+*&fTj-*EX#wGbl(lsJ-pV zpLTxNwz;*m9Oi@R8`-I==H{&|w@afgdaIM9*%nHA;D&5(L?^v9+@9pkA6dwdY&Nm+ z=2n~WDure6>N1)Lt}kdhC5&$G<@H~S<;nICzII!_;qF2<%~v!0fiZ5kf&X(mucSpQU486Xf-@n-BLWgIJ_%QQC)Q$>CoDgN7 z$lS#6AmrW4@?qb0DL_m@mZG4sD%z+C9!WL z=F5PBN3Ko&(uDp!y1NWQzW=)LKANZh=m+!KJkx~Qx1s8rb*KQ|L+L?7mAR0wlrL}) zwpAuCxt%K|g-T+Gd5jiVXV;LW5p#>0B_^+g*w1uk(T)_T2fG$ml9ID!ukSI%88Z2a zthi24_zp{ zcZkMxyRcZN&ggC_FCC^H`cIzd^Enr;?8H}z-FZ-QZq!%ul@=r-uI->oV6~Y|;igl4 z9g4|}+*UF;?eYUz1|+7x)+Am!RbMwOFEzCwR-aKK^6bSE2rbBmmdzc&EogdOarU7K z1_)aygnIHRmACQk+A2~jCz-}Y9|aNX;f^4d1nzhv>aarqfpFTp9%SbHGVu(e*LB%rAqnj>S;UC{ygB;kT>b+=3_u{7VN7eSM$k3cK zkMR=$RKlW%L%BmZyfh4OS%@9!TQ-s0$e-LvINak|ycV@l*g5ktFeiuSIUxRW+v44G z74~qI&Ks!lZ>u$j=Drpc;@4)2IjYICi1PjMWC!Ibs;H*)ew`K#%lz*{ubGl}F=e(U*Itgec0brcJ|IgzkUN&JV=x6KD3Cuit0#%55L%Y3sajcjwhD ztyMOkgZ-7d(TPt;_|i6t3);WkH`!fj9$qp$pQxiVv3RY%t!?4y*u}fdSBjj@nJ{aI zaA^1C@V0P_Tyd{*^dwPe+{{N0)^!eCE@PCN^v|GjNR6?-2@q)zHKuqsZ_ygDn45mBAiGTmS_}Ov%rBQ{5+~IhR zl$?7pAEM6c-BDtR+cy{}FV$J6GL`GX+b}N|P(E$TiEQmF@`Ek5%nFG&h$vi&rf3U} z&|wqwi=K)9kzdsi@@qMqc=(g_QTJ()DwCSk4-m9zVsxsEh%w%%OWZP#g*K+pJR;qE#qD z8jBAkRIhzik*n^)7Bj@?do=11!4=HJ~Hche@J&e{M+fN6V zXuc+%6v`vyn=vbSDOu4|cI(Vr?9Sd+GEcoQz<_rb{=}i~ZnEdTcf=Q_^0X%JVciGq zdtB0%=oJg#buyfxwkmfncD#H4nZN(aT>3^2N=fT*=cY~Sdy&oXy7rzEPPkfJX?^-( z8tQo`R39KM>he;Dyq89}ax+mMXUA>Ec!v-@cFqdOaTwY$_vDl|mZn)Tsf-E5DT+>K zp~v#*5Db82hYIn2gC)n89eESYvaz@Iv9LP4E$&SCtzi2~Gku$V4W!b(v>pDsaS2_# zQ6REmF2jkZpF)i)1+B76^6=dl+lEmTVLBtHgbdQjL@ue`z>&1OJj7y2Q&n*J8GQHC6p*W0q=qRBDV~00Ah~ zx@xW$41$vQiukEkUBkup9tNS^kBNCqhD!6+Hui&yj9Wb5F~T$bP*mzmCGYYPbfStT z8oR%(j`$)=df1th+OasAt0s3b0Hki{a5D3pqX5r3Rf-m0=JE`~)u`Ty%lj-R1t6G7WR>^RuG8MG(8}9kKN$W`?p0zSZs5 zq^hP0YfXHg>RMDQ{R_0mcp6IAs+{ehuIepDeuzphe@_tVn*VcTzuh`zC->a+P zS5Fy8I@Db)Jj-{sVWMRp?mFn~Qa0WX~Gf%4S(%TYmfCd8g&bk)0hY|60Nw zyAXay0-VVRx#=1jqo$1~dxej6U1ScgWcF>ospvWXqUz?IDQ!ChZo| zZ0yc++nU2YY-XZ0V9@!ay*6`xo@mN$365!>Sl&GQyi~m<2Y5I>kb}RAfBmp0-T$}E z%>TL{+1ksZlfZR-7VC>EHz%jkntP}@4!)A}qkEGzT^76FUXJFK_QBe)cX<}Z_8H(I~|bdJ1*BXcd~X%{Y)XYNT(iH&K-vPPeo*0Z(#Ha#ls zz1W?&swJ62Tog*-;_F&uf->nvwJ@ZtT_qfyl>8c3;a4iO9H$j@R~-WoE?~N9$Fe?H zE-YlAa$eqD$%L?C$;f=h09nlA$u5jdybaL|PP=uj1M>d8MMDley~D#=yK)@R;F&HA zFih|^^z8B?0&o`;+vJzR03kb^gQ1GtKK0A+NRi2>S`f{8zx}J*!gGziBg6!0B}}{L zlaRx{SE}ePV*o3qgV2}}hx-#*$Ut}5I>8(SpYka1YWpSAW>4p9mzlVRy5v2dCH_%^ zk+`A>k^UKCPP5z=hdMHP|B^dXaz^@g&giR(PI<#N8Q#~oc-6>s zde+Xn$*Dy)MHuBz-kn{9mgA#zcYR|juTAnq?SV&Ia~Ppf^^4IkD=+7i@TqmjGT5BM zg7yI!9a#KKi&fCcExgl8wb#s&LCXt#4tvYnCJL6Sah} zM~rK^!VWJayD;%(^&@+jR=2wNz1iXR&u@BN!2k^Njo{Ai0ZtfNKVs*_vS#Tnz8+aE z2B?H>C$DbaTl`8(s|79jg50NpZOgRo*vo@WAV=n;nE!Ts;5r5%STN~)Qf#vOr1IrP zm}@|t+sYYV1Q`vjU~|9>+`&}$<91S`QQTvSaC#tm7WNgM{3uO zRqHpOM=yM4>SFrLfIT_#=ukzbdH-<`z~KJt2HroD{m&^?;u;?%0={{ojA>DKxQI?* zw$Ay6x&ULM-uV0c2F~0pDZ6wVp#G$#*cHZ8vv2&%Cd}=zw|9 zzW8!MlQdj;T=`s-*Te=;K95eCNz8S2A-Tx}&W>6f113>ABZd0?8K6M`>W=BDeHik* zt+)Rgyg{4$a7!WnYdmy{<1icAG@{lT)zM)?n2|c^?=uUnp{>>uojv3FpggdGBy;s3 zLI+y5Iw-6{?xi6_Zqma29_WVhJ9Sp-^b;b8@+Iq~F#zJ_ekK=}sR=VIx%D~f)moQq zNUlh{y&C75N<+LP8#B(M)eY>u?HjMJE9o#+CMYuT53|2`1@w+ge`7$Y-m}`v?2WR-;OeJ>oOL%?c?DV= z5aHSMzDzMJV#gf1DJ9b+Rd<-;9$LFXG&ph?e1M-jI&b()QTV_(B4Uq-th2Jy2K}DD z^&ru;aD<5T{mvqCRm=p_J4_kjrlbJVaNZ5ImF5@3We%jQuRP#9h%k4#LD2O;;NC&7 zMhv=9he#L^$*&n{ghwuzW)l}rBdNJE$4U6wmWPYx zKOG~euh;vixqaf1MSP{13Oel(dS{7)5p?h8#Ki|2%nF5qQRlI4_ddIig)Al8^<`LJe{}Y`dnn`D6?zX{_D>|>nh$x% zU+St|@c_;yq(>*We`fU~65Kclu3WJ!jr#iF_8j_JCC9SPp@l<*ajx?D@o8xK0H$wP z$45LiHcPYX$@|LtJY{t}FdVYZ;+uD6yAxG--B>Cgw7VJf%*^#!`DLeiG)-RN#8D8h zebE?;+&XML_;PwRttkpzr09?CxK^7K6hm@#OjZjGdi?I*SBfcQ+HiGh-x~mpl$qUQ zYq0ox=N^HB9Q4NFw#;Re`wR4aaE89AYzOTW+XwM-OfCn>6bt-I$Rgtu-%M4XeW|*<&iMtl;`bqkKr=V?GHgn( z^a=xQ8}d;e%?`?${L|P%(%mb_+f{=lFGQ0rU!}RI#^ao&>b9>n0>MYYUdMcLU=vVM z$Rq;|`6ljrciP1a+cjfFKoi-xOdY1b{B>qW$A=G{+A5?3w{=odn5hZASVjxLmeIP& zUI+e-qn4Hm5AS3iNV}tTlR zE7fgB4Cog74|~*(uvk7`V^ConNBMskc~L1#Gj=P+H2GyjoL0%W)+7Hdcxx-|<7lTn z8~^%)_u*e9Wa?%X@&a0K$nz{|$j~Vrpt{bqoC|q^RAN1xL`7Io!TZhhM6<3RR5@-B zT&ep1m-u6b4W6}|0NQoSycHEwafj1meM9-?#&=PRZ!fB-$SCC&?SdP}xy@gn4r!;| z!TE#%$2Wbm#}HX7Yjk(0-#QWQDXKfRv3J5b>n50@N2G_FAe51wz_ z_cibaeV=5uOuPfnU!RCd@5Dd!m>IDWPh~8*Yv=rtg)vds*DCee5BuMLR^$ISMK#tW z+5DxQ<=4)Hvz7}aY?bsi^rr6E7fdd}aKSkS_Tr5Ftrl(~@2xX#@26vZ{oloAf_4nZ zf<@i!M3d|y%GWp;px&bwUibBJ@{Y;tsL30}8I-y`2Z=69D~6qtx-JTFyTMGLT9@5i zV5mF+B~v*Sc;jXS3cBGah)zSoyxGeP?|+en@l_;rpxWXR!r#RU=wX1sgMG}$I>)a= zR8O+zbA+fVuD_+Tvg|s|F8g?VGa|p{jc;PHTz1;c+yNbLTEEJX0|K7UHtEj+t^E_Z zVy~(rvOUtMANTF0Wo64Um)_a}RisDAcO25IA~Z9{cs z6)KeA`g|&?x@uc-A}i;r?0S(6ZvFn9ZU|EU02N$*hyk3ctjMhjB2Y?89Ab;thim7C z0H(=3go;q3=1dv5Hr3Z19=fXm8T#5>nh9}63Tb^~m!{pmCyr3^({mNwfcMts^ z?pZkrcQQ&f?MXIZ06*^<(VBu)LO}BWtL#d{p={Xph?*oxgbb$ayR_KHl4VF4J6TdB zOQEr39n+&H8rh|k7)$oDB&H!IC1a^%-$x=E!_>o=X;$z3eDCo+$MGKT`+Udy{k{L) z$F-c-d0yvr-`+#ZKtw3NT*eQ6MS9|`wI2Cb>#K#Ia^3-X5^0PFPad^uI$1@p+~yP~ zZKGD=S-x+1ypv`jSGSnBq57(!O?d=1<)x$JxSVOk9 zQ8Vm6yPr+flekI%=N);)5+PGn+wb-+yELR+_n^dvLBKLba1^ZKJN)m3l>Y~31OgM? zJ{@;tb6Pz(?*!{xhUc#22J9DfW9x+DsTZpJL#2%;sKa4&7h{-eH3$4WB^jKAs_Aq4 zTKBCy@(#JM`FHGwGxmcDi;az!yc8m*qLu-O>NY3}Y(Di9iAOTdt;+!DM-_9sl?dNn zhD3nPQx0Y{Sx1%Xj2IARcH`wXE3V8=%cQ{}kZU*cZH{<#n*aA&*x!b5 zY(U+kzF6K`@qwcj*N*=W9-*WB;U%ygHOM>e(bQ+Y@l1}x_x6oh?EB`5SdS7Rtk~)9 zJitRiRQ^hw!weKb=7%J&sssA2G@DB;Zq(V(f8%qj8}cCmfRyeoX--1*%+&SkqmG(^ zm#ZVsnM3Z9vsVrSOIOslNtH;}%)2AHqx?V-QGm6{LJ?}NF(B)EljghZk6kFQF6~q! zY0on2eWK-s!zKPunzOb=P+ul}~VPe!%Uo_yjsW=9gb=Az;ou1oA z7!&2GY;E8V9xo#YRt|O_4K!@Dnth#c5AsTP{PFjmhT*e_QpkKD0E|MBY}bU zCOHJ{4lPD3qovnds){fafo1uTV=Pd$lWwm}?l^a9Vyf&wd-P<$`P{PP2Mqr3qNr{K zw;S?M-CnX3Hut>M*Iw&wN=*{6jJe(B_ogw`aZ&eIMu|<@#Gw+z zTy=BTV|V2Z2eaze&z2n=JQY$eh#73MO?_{GfA}%-^P@ZFG_O-TLf;AV3el1tjF)Y# z67xitQJ1%vC5+@9r$qVesse!3*4w+{GTq>OlS=s8C_G6=`EiI~y%=$oPHUpKl&=2M zRyDS;MA`n+oT%+BcHoSlLbS7#=)mo5cL0T%rqd6Ua%~kVV1yeFKDovO+#VMD@hPP@ zJPDO}THba9ehh~}C|x!C1L*Q~^gRo0QVjw5EwDfU;?_y)u{Uq|94yT?YgwImMbPR} zhV7pgBo8F4H(F!vNFTp+dIs*#pj*#B zoG^qDyxkiuHAC}k4Kc)hLlMscxQJI~k+Vv;*xh?&V|4QHBw}nUF0kF*A6&>xVu98| z0;_J?iQj|vnV`_`IIx@-1*a5h{f{gaTPk?ekSL?vzb)MV+^(mbdv*)t)A%Vr=7V!~ z+Yv2si0wV!)-}Hg%jrwHIIGm$3C|gLlbWad3y|`K*SCUav||N_74AO9I+PQTsGjL~ z%WLiU&MqtUw0nGSpoKI_DB%`*@a>BfO^2u({v36Q#}V@>MA`^}PPX7cu;YL^pD}G1p3zotCGLE2-rS!b!&FD z=EwscNk$G`PxOLSP5N=8rP$L^Hy1xlZq54)^caifp%5Qfv}1|KzaRVSRna@+|1@5* z*o=$h3KdLM-848-0tdqP^3quBP}>LQ7P3+o!o|F78zDJxYkqu}slR^UVNV`Z zsDr45N!44%n5_&#>l63>Fc#1c2CziK;f2C%L~N{_A0B7s-fbyza+A4jZl;ke+@Dl@ zUha4^m%hu$TZ9oW^IV6<*cIiW2pzw2Z*p*h88fkP*_0MyuNtmXV{GHi)uFYQ9r*f- zSv*rP{Fu9opY*40Ut>nR_kFep%Ce3#x;) z7E!ocUs^B{eC52R#aM>vlVo!i-@1~b&XJ>8FQkW%xQ@EMePEYK|3C}1Mi!XUiltRfO z4#2#0n$y(WiA;aLf{PIl@@gLaSe_8Py+`QWaspX=?y%|RP#&x$J3L*jVM+Rr9u!u) zD}hHtCu@+R2!vU~1oFpbP4#Ce&v-*-Oq_AlHGjSL0;i+~JWI2rMvez$9%3E#_?}*x zjExFxeda#=458oT6dpJZ36aj?js zgpY4?j(Pt!T=6pxmLB-#AftQkmgcTA2!6BCW7!!B?k?QI3V zt}zA!FGY=YIC~0(G=L!~OWmx6s!o{JelC042DxdrLNR69&&#G2YJG`|2vEAkv0p`y zqru}#^{QB_pJ&ss3$E)mGutb8?5X*b07vP!P1tqGpB+qbx*qu0`X7P0N*GeItm#ZYOdQuPnO`>3vU0;L3bwqH7oyj8RMiL9HKs)7Z;Fo{OFpS znfJmPKniTEkTw_ZTgD*6yUXvVn4$!{2^DP@f2P{j|MBvf;{F3Q$MnbKIE6)P-qYtv z{XsYP=IOGHa`3V9a)IBbMK^S=2%v2_U1;sQDiJ#%E$tRku6zIad*ya22P}TR(fpuj zwpoMLSqFEp!`et`8i&TX*cFNNYiAB?;#*+-bf8@~FNb+ss|%J}3ESPR8&3 z_|0MmWD&hTFyUlN)5j{@b@zIodvNi_K1C?Qkyp}RImIxzLH{^baGCm0fokd2#uSB~ z05cQ9%gManK3n<9nQ8qpal6`yxYaqrr1mP5}TvJu=vcG}QZOV#k=;1>gsm z(<$OD@+GMM6S1bMYSws{T}e$%W?j8}6~f6}NMb*n0?iI;Gr9Mnlo;;R{I>C-U(Q z;Ag2rjPAtRk7}_&8@%44Q^GaihPJXA@K>6`P<`E+NIFb#xNyxU!e@J8;T_RVnke%l zyS%oZ_AFFp40araZWDfwXPn%Ssc%|GK1;kgFAXyIEXEF*Jjv~0Y|Up!H>z~5Y9l-F z@ltu^aMzE>r>E8Ohtq6FP76va1{>@JYKixoD+qQM1ajOTBhu2+9OUoGeDXJ?^yj73 KpVAs(XZjzp!+y5_ literal 0 HcmV?d00001 diff --git a/images/红23.gif b/images/红23.gif new file mode 100644 index 0000000000000000000000000000000000000000..67e92d640a39366592de081dd2c3dada2646db42 GIT binary patch literal 403 zcmZ?wbhEHb6lV};xXJ(m|AByk=|3a$e=FFM@Xa4{H`~QDh8iTPh z!_1k+X=%nYXQuuCfAjzUXFwTCBgU*`<2h4P{{J|ZlWdfoY&>^z%G^oGyJl<83*_8a zps_Vy_y4A>xk*Or1GqK>a2-oiJDH+(JXP&`jphFi&vRZ}mt6SX8}Wa)lK803_d$d2 zyS~_eGudB?LjRRTe~Iw?XJ7z2<^SKmK&Jp5lm=u2orwVyf3h$#Fjz9^fMh^^Vqn{F zU`~Msk3|2GB}FH59!V&NX15$Poh)%9!C-bF`;0@T*I&&#dq=GG<-lf zFzvD4p%R>CDBvbkT_eiqBpxg1E+o*FVdkV1>&`eaotdpu(OBPIeP#xGXROeS#RZ~f z!m(m2SEb2JW?H@}k6Dz%QYKb@Q#xzszJs&Ooh*)}>$&6|V^(l6N!`J0;w5>t?YyWD gzxMg_amHJGIm|_5t}^S&@F#nU3X4dFJ2F@U0A~)I2mk;8 literal 0 HcmV?d00001 diff --git a/images/红25.gif b/images/红25.gif new file mode 100644 index 0000000000000000000000000000000000000000..0906e98efa144b4f8cb2dad01f1d8b1bf68df8ba GIT binary patch literal 431 zcmZ?wbhEHblw^=(xXJ(m|AByk=|3a$e=FFM@Xa4{H`~QDh8iTPh z!_1k+X=%nYXQuuCfAjzUXFwTCBgU*`<2h4P{{J|ZlWdfoY&>^z%G^oGyJl<83*_8a zps_Vy_y4A>xk*Or1GqK>a2-oiJDH+(JXP&`jphFi&vRZ}mt6SX8}Wa)lK803_d$d2 zyS~_eGudB?LjRRTe~Iw?XJ7z2<^SKmK&Jp5lm=u2orwVyf3h$#Fjz9^fMh^^VqiOS zU`~Msk3>J?qN0;IR_zw-$xE_&4J_^ib4pjFZ+5H*xbaLwcSDqJUf?{{k5znf8%%uq z=lF(Co~D^C;4V~K%Hiphz``QbBG8t^&*>zdAm|}9p)G;i%tSxARlg*r;#-UO0V1k+tH=o2Aos|ZSPHno5 H3=Gx)|AeIf literal 0 HcmV?d00001 diff --git a/images/绿.gif b/images/绿.gif new file mode 100644 index 0000000000000000000000000000000000000000..48d618bf2467d47d0b7177061783b580d49d6612 GIT binary patch literal 515 zcmZ?wbhEHblw*)%xXJ(m|Ns9#GxJQ^%$W>n#tbu!8O|6R|4(E1Z_MzYf#D1T!%PN- zGzR1U#>PPLnZ{}V(~Q%MXa1j=HZ$$a|1ByRfN|6o$rbh}+Mywqr1wRZLnVU9>C_X7oIqMwZ z?lfl?Q$`P~n#tbu!8O|6R|4(E1Z_MzYf#D1T!%PN- zGzR1U#>PPLnZ{}V(~Q%MXa1j=HZ$$a|1ND)TO|II|@6 zDV@`JbThza28*kiRIG^Fu@lpHavkzrKaaDpzfcRK zh(H@BpG=_)CvOj~|7Q-oTf6c5a8OBEMg@zgQqIw}+zO@v5ZDVLaU2e$TlT!>%X_3o3qk M>!BbQ=Ez_T0GW_<&j0`b literal 0 HcmV?d00001 diff --git a/images/绿23.jpg b/images/绿23.jpg new file mode 100644 index 0000000000000000000000000000000000000000..251bf554973c4dd44d21504c7bd13ba75d9a1821 GIT binary patch literal 30728 zcmeEvcU%<9vhXZ9DUt;wNtB!3`g%h_uYHm_ul*K48NJFuCDH`uCA`>>abwGU?zYQ8Y=2400ajDsDXa~ zW|H)&vY&%30BC6eyZ`_Y0fZ1r02hQH;2!{C0Pv4s0I-5E{)DeXc)ru%fHWci_yici z+XEtc1XF`>Ldl((e?fHE%1*|$T3pVW5Sc!>ygmozqa>nVcPi|Oyo~6ww3Fo>HuWzILHq%RjuG`=%Y_s%c zQ;+x5mJ0X7tXpLX?|P@VpO?Syo7pk6^|_sxUGbrRc2`o>$jrWQ`H3!^(uz(o?$Z(I!qyV76j((gv=NXQN=DV+4+=1gWoKz+y z7w67qn4ZI}HXc=4q7m2RVH}?t^c)P<78B@kzT>(YiPJe7a^?=r2WWnp{bA#jbkO(* z{~){%ECtx$m3nh+vxTb7W6xGuQaTL1$4wkr+COVQjz$PNa3;rpJ#23ASAO6+cDcFVB~vC5)yBqYx;4@@&fm~qyq6@U^<)d_ zFjBO1N$tQH-!y0GtV`F*t+uSJJMZ>$(P?yuWRXLQC%5;d8tV|$J5G*%!UZM$(D{Vd zM!^qcD9hYs>dRw@ja~(rZ?`Bs>zQegwIM4mIK0ZSfrk+mw$^GWVEPH}0(%#mus+$ek zy%kEGSNSb(Kid(^K&GCP;eV^nN0_#EvxJJwHgmtO^IgLkxtmiT{46IAG&tfpMcH|( zF@R!}?`w9k=W~q_r%E&L@S}}2EJp9eCy~+TY+66T0JZe$FX9@;?)8$-LN<897t!u> z_WOBv*gKeBbsiepAId&W9BI(raA;SzAM7g1)f^j-dk#~)&86=z9aMz@p4^Lm%xrEX zAvDKoIUC6lrz3nu?yXInZh!~NmCprr$FseTd(7!vFMAbf5M_~^dWJ+sV&B}w&xU6n zA#Nk_n)Rd1Y=DnH9*!YeesYDO@P5K9g9!|5FR{P4S55-L(pM}#7_5>uzo-(w%0O&szjYNjXSmO7e&R+_1zxlsi_ziiT2r;D+XoK!3u@?xnTtrzG-b`ZQWWM-iJ4kUcn(X{ z*CxrZS0xIuMw>PDv_vqw*;1#ny7u#PXtp$3^#Bge=}inkJ?l1;v^dL+>UH3V>+k^k z1;=v^u>Iv}6Qu;hvu7{j7>SbceKAU`x?Zs9|4BO1#U*X_XpWLoC82jw3nW?`n{h=x&ico$nwG8{yq$dn1A+|dM&^X>@3(fX zQ^p5Ep>5ZC1U2MuJRH55NO91dFjRq$yK_f;*WRG>{l4~CEC#@T5hC3Z-JQG{Uhq&p zM>#xEzFCRu+@TY0t!|+g6jP zbHwR_Qh1n!H4(HqN@0{fk9gj7nNg{XMQ2;QHtCbOO2^q#!1l(gszS}BE~bX%j%}4r zK=iG-ueazhJ*)N{q4_TfZ<#RO$WNs<4mtOx4FgEXJz1W5X6(!2ZsLDPbI-Ng7*3^7 z`E;*(Cqtbh(K_m=EKuwkzZEWZF;3lOQihpM{f^}>IUV`O>L4qnu(7x9<3>Bf`{#T2 zf|gY6CjI$TF}-WXA78lo@>a`Vd3e`Zd7Q@iD}Ba?PKE^4$8GV)p?$p}iF2OSo7dhS zWU%EpVt}l0?ia&8k8#gu%_Y&FkxiiaG}95!R^8G%uZ>$UKPqNU2sTla1c`k8SZgP&_Y&XVA8sDPJbH|fUFi0NBqN{T}f-_jIvr_`u- zHqpq5YdXbmI%12bmh4}L0YsYlZ7!*pyO`|j=)Jn0Ui`e;jeCoRBTh{~7c3ZSfR0oV zgf)&3Pq=ii#l@(NHufxWPI{kAP%_yxe##rBCS0SDT>i|9g{}cai)jK2oO5ae# zO#>`6=FeNh_IPAoEm`(GkMt5DGc}qKN_L z^rG<8$%)guat&-zIBb}K9Z7L1{*h(jbv05Q#pUB9a#gq0VvI{Cql{zB`NU}2-Me&I zZw<_Op(bMJD0x`(TpI9E;lHI~)>v$}c*Ywim{=QChC{H~-@lrfZL z0lu20Y!k67+V3N-aIjO@luS0sm7cg!V$kEp9BqYbjbw>M9O;642!NnddJxHT?nHneiYV&aijJ&%t^3JM3JBQ>w7M0>= zkvg>lVRiaP{)Q)Emv~oLi~^n(^V5WnHX|R#%xq~-H=psx-`jWEKc+-IGebFhrcbL< zO0*)0YNAHY;zfc4Q@n#es(+sLlf-dBKA$dQyEN}W!Z%x&qI5-?D?21L6ZhyuM2}mE zsDc5)Y?Nt8qRql#!e_l`1A$`&=|Du>;LQF-WBhZD$mZFA<3@2!Z6HtPB~TGi6Z0jo zW-#t>5l=jn4mBqbzWTykMn4JcH;Xe?dJ;{hr9AU?%Qw`=lhTw=O`W5QQYyL z2>|E~;9HKzj&RuFuip_R{m(G-QLbA@VdA4F_<(#%MRF7d2lQAP?r;2%91ZZX5l3a> z?i|sm0YbL6V2l&^1c&3`1^JG7mYnhvBYK3t3O;|(V2Aw>K;RF|5jT5a7y#Tr_vKG7 z+<9#DpGIN+f8vfLgUuSO8vr>9VI3df$Zhy05u&3oRuZ68aL#?Zzsr~z#QsXlfDPh; zqwepu#RdVO<@=3q$7@gc=n+`=Z&Epm{Oy5tq<&mKQvC=Yy?-V65%HZhY|zEq$q9U6 zt3Y7o>g{6Vscm)L8Vr3;r)%vc0*0_k0qBGNnUkx_4_^ql2($J2HGJO7)%klE%L<@t zXa6G}8z%5{a>ONR zF5b>y8Zu=)Z0_1eI52$7(%Z{b73Ko-u=Il2fCxa}-wpPinB*HV7K4pZceY~%U;o?n z$MyDb(pNUt2aEbHT&(ba$7p%l!G6OKSUP#>TiX4GJ8lgF)4}|_)IHVowJut@x;kMq zB>I8=jhNWp)gwUB$-(Z2q{zQjUhM}OOi5@1v$gbg@&Z9(ADD;NpO72=K>tooYGtS7 z>g4M2i*PBv<$qrFX9So8xa8`Bl{K-KtDCmBmnZCpVqoJ)oIpkTCoGwjs~4zH|AZ$6 zo7nyz$&dOW4>mJ^47?%G^&|LOf5c8id{bfEBRVVvKoSl*%g3EeGC157$4(z?W z++>7=Ts#FWu?uj5)~?P%ewJ=RB7(v~fE?7%&C=Qt=EZ6S13fHx?zP%RZdL~yd2XY# zTEbdxN-%o|wEz#8Uce=N>i|b$PeAS%VrYU^R?4D)sMaAXw`l;8$4^sup&(Y>JZ zJv%TY&;6ZmUteEAUok;f4?7_dX=!O8VNoGbQ2~%bz|-Hw%hFH4#giQ@?T8Hr}HZo%3;} z5fPZMfR&iExPYakBuq?7OjuOPQiPj?^?Q*pa544I3&qC#D3+B~4jYs?@{{yHiNh2` z z!JqE1_=WlJwEt&qpr!R+w}P|tku5lC2rVs{3$E7QpxyIQzo78#lVam)4O-|YlrYvlOZ^M`d{o`vGyA`(uZ{K3%DRDbfJdJ#8*3q$6AW7?Pq4p=e6OvIwT!K+ zhqI-Zf`hZA9ZcxD8_Z5l=nw3l^ZU(ogI`MUn<@13D~#3S|NZOlLjIDB{}$KZ;`&Px z_)ElpYuDf6`b!e{OT>R`*Wcp$OA`1?#D8no-{Sg968KBRe{0v@;`&Px_)ElpYuDf6 z`b!e{OT_1v-Fs+WX9@BN*0%OwN=zFDjzL4kf~jCaB;-}H-$O7 zczNimo@X__a+Q_v6Sygi7~GWxZvV2h_H@(IQ^D?B0@Rh2SUo`^Ed0l{+y8A(Q;&e! zWmeWd@c$7+VeRGt?mdEB2C2ntz*%?@z6rukzFuxvJa#V+wUr|l#=&kxqxJw91mTld z*zOyQ-MT|<^$k9Ug>9T&z-?bRSf1T%oNci1I}pC>Tx-eUq2h0U5$`I5t2NyfAxm|1= zj#if(T>e!H|2LEU!UGokrq>`qm4ybVEd+rRozwvCN;`l@MGD}Wrh+k$pY3*$*brP~ z1OOwJxo>(8!eIQ-^S1|1G#JG3bU4~92`K66vs!z5_&64jB$L4igR+ju4I% zjv|gGjy{eVjvbCWP5{nLoG6?}I2kzkI2AZ=aN2PCa3*k;aCX3xgrvB%xNNurxKg-E zxZ1c^acyxua6@n-a1(Jea0_v3aGP;^a3^q=arf~E@Tl-u@dWT>@zn4P@T~FN@j~z( z;HBW@;#J_i!|TDD#9PNh;~&F6h0ljCgRhQnjBkhUi+>wG5kDKh9REFjAN~yfE&%}n zEde)yB!L>i6@u#ofdmf-o)Q!hye8-(m?GFABqXFKY*htt- zI77HcL`uX$Bub=0bd|`3D2ynP=mk*&Q8&>X5t8@>F({Lor)>PqCSyb<-W~d3MxvABuuT$TrE};HI zy-q_(BTi#T<45zDrk-Yk7MGTbR-M*~Hk!7Cwx9NZj)_i@4n}v6u8^*q4snw4pWk_Xs&#=r$%_z%g%^1O0!Z>sa=M?WL z-BW?5GEcRi+F@d5Qe|>uN@i+eT4ttYKF55W`5|)y^8yPMivo)S%R`n%mPJ+?Rz+4P z)<>-GSl8K3v8l0nvpr+`#D+Z0ecIr3*y*CvqwFN?QtYrtfay4xa>{1K(4=E`EG|X?_>}4E_NDG66*aAAy$wlY+E@7X`xvD+O1D zIE1bW#R@eGp@q*1I|*kA4~tNWXo!S~)QD_~@`_rEJ{Ij2J0_+g1{bRm+Ysjyhl!_( ze>qEaR_pAYvv1F$BqSv~Bnl-KBsnCnNj{MrkfN5lEcHODMH*lFyfj?8PI_NPLdHv` zL}pD^K-N+Ah3vc>w;W6^OKwX3w7jMKGx-SxR)uQ{=?W82HmD^u1N!wG`#GC)+2`gI z&nRA3%vW4JFMQtPeEE5Vl8jQY((4Pj7gR4qT==9+scfK}qCBQ@TE$M~rOLYMS=B(* z*J}7`nrg9X1L{ob*6Mlc>l%_8!5Z&0$u#veQ#8L`W)|u56(GAjV)}zw1(0ie`tAAcUT7TGp$H3d*ts%Lg zsbQWW!svogoY91_ka4ha+ZBc@4p*wK5?(dDntgT0MA;<4WXANY>21?~Gj20KvsQBk zb0_n93vvrfi_&ZO*Nm>cxOQl%ZJA-YW2J8O#A@AI$vVk;$>yBRLz@MdJS+}2XDe?T zXFG2vZx?U3U=OuVv|n~ma!7I5xUP0R?K;9y+Yvlr33nOy1ow3hO^<9(h^Lunl@~QQm}>Xt@xJ9f>7(HD*k{kz(6`i&!q3I8 z-JjS0p8s5cO2G3#yg=)~w?S+{p+S?uiowr9AR$&EZ{h6loA8+%syA{&NkSb%JHmv+ z;=;DWjlyegGTpp!bLy7rt(Uit-}bmYa7Xq|+FiW64tGD@6T6pu4;^6>@$tU!{lxo+ z53C=2j1-A{6p4wljrtTV5uF-C5aSZl9}A7mjiZPQh?|Pnim!Oc`Y__*c7jDhYod5! zS`tZ;chbb8i;t?3Ig(?N4^!+@`W~NuT=eABlY37PPi>xdr=CkKOk+yBpLUS$kpAVF z>a&Uru8hP?f=r*x*(}4X=I2t+^RgMT?`NZOTyiFIb#ve4N#^CfIQ1g>CC*Flmkar( z`JW3e6jT)o6h14WExP{-c;)?SvG`hXe~D(v+fu30!ZOaXC*@S-5fzXM|BCfW`^t%` zD^*?98r5%WWNXT61#5Ha*ydkTl$Ez%&Ll?!0z;z5K@R&D2|qx5G`wO}+1Q z-hFzn`M%|Y%7>U|xavYuL+_MASPxjB1mHgS$+E^l6RzHUKf;q#)&;>?oU z5_0+W3dPEkRi4$dwR3Cj>&ELd8y*{&%?DfbTRGd}+i!O+?~Ls_?;;Tqd-Qv``%?SO z2Sx{TNZ&)k!$+tys2a2;dIaMPp0oMmsQWo^Eb#59`?rJS|IriYj|=zb^-D_Z!ET(N z5&tQGIXddz0<_>lz_a0h9CfD$kGg}yT7UotJg)uoA|xWf$0Noi0e=L56hsr?g602= z1fy^Xafl$q014>{00)8#9(KpYa)d)b>}7xqC0-VM1ckqvVvV=h->Ac`wS! zD=Mq1Yu>&8(A?7cvA3^(;LG69^vvws{KDe)&Msna{{XB$_HaHPE?!?(Z^!g`RE=zyK5>!_>yzpJM<44cDO0-xb*!l3D<3e6Uiv9Jp%aycICUE z{DriJ>XK2jpxA^CID0SEr!;>IV6#sQL%;GYFKMajeo*MRFWH%qRs&Bix@=``^Saw$ zuFT@Yq8!iMeGl_~Np!28uc!JZMBgdN;0#ectXHLj zjzzBWw+9JYL`f~Z1^MV4Rj`65H_U9FY55x0zjH<3vvaOaW!b3SvTQf#yx?v5>cfxj3C}4TZu116qr3ubPTQkcz5JyC?L!wpx!GZ) zkckdkw4Ui);~N&z;6z1m1*@V6yCQ}fC3gut&v)qHU22-Qc>uTAZ$vZC37R2?J#5#W z!;)#D+u@(hZ0vYZd(yZ;pG!?u3PY^XVe@Y%WE)|2{Sw(NJ?IHqX8T4-4DdMTAn>t- zt53C_zrL^qx9|3y{eu>>@G-Q;c)vu&i1jKu4g-8PBYx;V0`s_?^CIG0NTL^X?P75B zif?4YhLWONzCsr|Bx_h6;n;AwAEEL3uzCN$*U*qomk0ykkRu05S>Kc#3y?50q|qf> zY7AWbUH5)dM$G3w*HkrBU!z1}duCjv8*G6mBU1Ck)&-XP?$5IHP|ub{+D)h0>Rw() z1oqFJ(#b6}HrmzqBA+b`nlZmv8i#l!>38j(vPYZ67qy+m^1#~tSm%{8-VGCiNDuFg z#0&ZTx0C|-`>BTB&W+(C%Mq)C66ATq)e^m?<|H?ESojakJhjKx);MNXuh0b=u@2sU zxsyw&uUqwrab+ZR8yZCZpqD0H{K()cob8XCM)I22B zaKt~tc!e>HUG#Hs`eDsXbTvE>9uVAK{j}2jdMY2+>nI5uz`9+sEn`wIrl`OtuCSso zZzRz+H#f!B3eM58tX;(wINX+PS6v&YDyJzXxu?Fwxav!a9B>d4f+e)(2`;}wcL&^A zkyJZCG+kb=qt!Go%)Ju`f8- zV1T=p%bz;^M))6zO9~S0r)_P!TQ|A{1`<@(x~XnQ?;o7pP4agMA}gk8(O)<(CDyi0 z2kK4J0rH{0>q1vU62fTxZlQ#i$+C*u5kfT!Nfjt>_>#O3F^ya;-ctGxjwL zdh~9NJ(RoPL1}vZv_;X&gLZgM-RLwN?lU^dcBQblm^pI}C0N6@GB9T6Fs_T2x}!<4 zr~vPt@12yqEi1$zE_Pw)#Yw{UP-bI#9jD1?!O_eRB9xX?cK5|AJH7#pn%ZRl39_UR^QFt>got!82+*Fta2FjbLC$bWHy0ip2eg zj-RviDXva+H3aK&dj!Rdq2gnn=))HKV;>E1q{7U&6)UrSSOyWT+Ftd$vtvQ^kF=^= z1ny1H-^i9{EM!HtA!6s?9+kxJKdkYTaZi%H)?%;#J1KhJx zM?hrj9+-VeRIrn`=8se7D~pr1lT$wn?JQ(o>XZ3R;l@w{HNPRowR1p)JSCH+9+R7O zt*d2Gby@_}IQF47$H9U}qSA!VcOTz+pGgpPo_zRoUrDVV-^~<0Lyb^14B!LZ!vGy` zP{AJ$b5;eX$~2h-A3?UDbBm7CY2K1%QTAnH!aCUSJDKq5C--(g_YP2f41b~532Ini z$C^{{p7;9cs#;Xe3OdP*Vi&%4=5(;Qq-1m3{ouy##nxSN7wauICA9vnN5{|R&Glgb zN%Cz(s$B9aEOCX*VhSfKAUdtH@Zlz5ZEXkw4?3lp8?CdozYYC7ot__Qc8clzAq57Y zL5N?qX!43^c|DMSqj)5}4vb;go>_sbnEm#R#dQDFmu^S5)vKrQIm&57Gv?2aW$U1z zFUgmd?*xwL?>ahgr=H`HS5+*uoHbzz>o&QctnWb6$}+cDsGxTEG9`+k&WG!jilR-O z$9)V?g8_O!$#3M^{=iO5g+$XH)%U)Sv+JZ_iieTi`{ zWY*XGd_cs<*5{jIjN(zMGVqs`+laO(mpOr+M{BmJiwlo+wzy}umLlu6I)^*Yu2PMd zkI61_--8Mz&&zPcd$#Tpa8=8za>QNt+Zp)P(EL-o{}UpvmaQg^2m!OoPM>?pSHh6j zsTo;Yy(m(u^48akU*SR1L0S_i1(V_}yj{u8M#^r6PnK8SnVcUB*mwAG<_YdUF zpkrFmiK%C}tsQawwUHKbAE8BcuXmeA`%B_Zj#)>i4R0;U%BLYZD)ybf#(73BU|YJk zrnbsqb6xM{r6e}h{nswR7F%u@Ks%Uv7colYD|JmzcykLG66~!vwB}cUxGRv5L&NHi zYE*~}5fY$r()c(ro=OBAh%Ty&8AkA|P8k{!)WdEM)G7y3mQh zHyjyWOwUnMs|UZY%6nDj(aE06leKwn+T`FBx}gaxDSr;x&+@mT~=4c{-!*( z6-{G}hJ2=EWL(NnNd0u>BnBW6Gup-N&Y>GXc8Z>BUTLpG9Kd6GbD158DM}k?ehwflXO1) zFUt0e7Ze?tJW>hezI=e@R4X|m!;m{6FM5_WiHaV>i+kUf!hP(i&gT1!9bQT zFOi{|cB8LNHzzU%Hi;GTAr;JU6Lhj%3ac;S@VG;cVQb;7pJdp>@v`{o&e>fM4r zM+rarYBe7XYjhx9xK3X}M2xD&GJ#J3eOIE235APV<-lR^y$Z9hj?%G-=Vj+3LJ4Bt}bYbSQYg;+n90K7zsIigVYhJ-!@zJnhQha%WA?V5d`@ z*$D_U+_m$i?P5b~POIKI=6n%W_k5NeixsZ8(ljK%L0v7wHjue zfxuT+v4~8gs1{`-k{V&h==DPkP>hK6kt`m0mtSCBQtCW%y7rbCL;1q+V3Nww2-5=7 zJD$WH6BR}n`-Sw3Tr8Sp3a!w#wq{*=>*?Ls^F^K`?5`^QnQjvr>}--(J!Vli($v(a zxnbG#&8}wMK)x*sKz(-Pb9@{a7$G^l8+0(&IYu=mF}xzU;_Q+;xP?>*)>oO61{La& z_hZ(Lthiwv{t+f_lwR<8+E z?Ds^{AsBbVy(ADLb6x}QK0j<>hIb)lQNQCdl8QP{6I*s5i7-2XD#bC9;M zmM-^vIjJNlhngKWeUdci>$L*C{i4poR1fIr-0Dv2Ws@k2-A`X?AS!N!>KMSO5qjz7 zqF-^@b;>)$ky!>4cp2Gx+m(IndaGA&IQwW&Ie!sgRa~HkPm;(yF1X!M$r|l2^O(BJ+mzlV} z#F+Sa!&R*tI!0b|7PWP#hkkP@cQ|zd{HQiBQ!m{~@!UyK!T@ZQhepF({+;i|LVCJA zJw3*0nnHSdd0S6?aOFtbG=b}&6}rsS*&<)EgYl$;FcEoM7v`LdnL(R9UcpbnTm!by zMQHPwSYWPpx2Zui?reye6?xq>>R5;A6Be<}#Zp=E=;|ai8GJr1C=KD<_@Pi?e9QYi zdEoG&&(sQZdcM5xam)A;26#vAR}|pL=Y0zqn!nZywXYFc`q6WK>q@f^E{`wcK* z2@V-gGd$acN?)%RcfIV-D;>XZus^Hq-?_q4B|tTtsdWhUC$m$#vZI8zRx$&_-(kO0 z1-^xq5BzzJ1$eCVEqb9tjYHAfh^{e}*}H26Uzs_tLp!&YUZO`m9|R`kQzvFcTU5?{ zMrsKsKnT#Y_MDWg?0LIGmb^IRy1}^%Mi!X9(aeg<3@i6OJpC6ZZjZf!_QK1fmsUv- zd?`uJ#VPTjic4T`_^{@)-zD+1X5xNKc50(t=L_w%<8OkpHJ($xDjyAHXr(QIm&Yii z?n74xWE!Tbv>8SQY6q70cfc`aVEvom0k5h^!5v?>qQR|s;idTo1ly@NwH&=Lm1p~8 z@aBU+#g*WqzVWx8-qzHIjNO-iQc73*hGPH_=1)b@b_jP zMxFWDf+bm$(4KP`fYvP&H8OXWH(`ZD4IFL=ndZGQhgiyYp*2x zj4lx!q8Joc&TgMjA}#+k<$4nL(*>4EdG-^&IM*h0975-rb4{(I1NutNct_Ra@`%L}`gP!k$H}zn#FvAVG zBKO|lq2R-TA;cG5js@sBgJHsFh(ceRG8(s#$;&6<_R*l#Rysf?SJNePmR8@{;o)1_ zJv>MYu9|Ii5}Z)r#6QyI=C1mCGaAOzd51!~jWan&i-uUFawqd?lg!Q|Rkq!g9MPr` zu#TH+!K!k;tD~)MNs5F~pPO{!0S1^tGjC-kRVvq1KDb?=YQ{9BK2@B};s?$A* zBmV%Bn>+89C5-2d=^s*R^o42Jc)rn=ixUgOd3m-lD9CL*e(iDU#uk3xW}B$l~ui-C@qc@Tj*+D5{i)3bbe2B z$w+vRAx7~`dV1r_0~ILYSO`)FAve8haGSJXJV?^WTKu_uh?&>$AhhZZn}-c8qIOM$ zv8_u{4!+lA%!bNXp z%q&bcIHR4HXA1pnYhkSaAW(X;Yv)W;AqrWrgPmPDSCALrHyGmqsYEuHNmdHsU2NU( zGO03abtbKYpO`Q6xs4bV7vIc=vTmoJDZcF5s<>ylr?BBT8WKF)(a`Tb>`O(2+qSvC zb30@=FzFN0Ea9!QY~Bq>gwf2rszKhDr?r8VaoiL2 z3Bmhyb<$>b_(p;h*%YYZQ-pO2YsgCPV6T#``p*yIZ>)+$tIRhJ*ok>Zg>3OzNV6<1 zE}mrBCD8U8sPd%603mZrmG_g$KdC||<*if}I!rsN)yC_5m-4hfT_Hj{_bAC0b0$AZ z%d_Q3+i6v3r627uYlVuLhp%zOG1SI|*rZk=i}ZhX^54w#uWsss`pv@Y{!?ssiyM0} zKy>M7_DXs(k*mVZTFxz#PWodPw}S#yeOvLBMU(FqTdcs}V1S|eS)sDJPa9e;*%sQ+ z%DH|&B-zzx}G+tg4tuGd#g%FD+?m_m_Hc{28H&Gpj>Q~Kh~`_9@i`eJYybYb!+`3( z?fBcW2UL2O9)``$=fnGT;bV7-rO5o)ph-#qeFL@iE^fc~^B1mJ0FAs)L0!@~Deow%6Wt=GWSUnR zQvSWR9Z|$_8&Lo=Mz)W#D;!ID#ZnX=@v0F}3P6eQa`N_1RiB zytDs264oeRu*{ODXtA~9YDQB-_NwPh3I@oDv{;Al76qT(g+IC&doKIx`jIoc^(ECo zwCQ^G^`oG%3Qje5L|R{~4Q|?EKTDc_X{kAXm(pmQsu{@_p*X*S5BYJ>rUA_7#vr3h zt{pvkr%GFQFPk#CxOfdOSmnf8uEopcEUQ+@^>|YENQOePwR2`=zDjbShU-7i$>s`j zyJlB#*c^mdXF3$i_y|uqa@2>eY<3B!5twJF{1KY zr(~WMAqq+p3g~ajygklD8`89|{%EMUjhPOw=(KtJC;oFidx8oz(RD@$p*6dD4=<1A z;$@(vju>i}w?tMyf?VAqJgqEeTHD5!WsVoSx#OC40Ri1gs$#yP`?xtevXB}NFA6}v zOI^R846P#{Ypza_Jzvqa4*IaYz*%lW!)S``q~jo z%guOSDk{vI26^0VTt_guGEZ$49-1I>giST|QflF8xi5ne)+5X?LElunn#VdFW{sWQ z8tSlziE*m2(ULy4&@~Pufx38)hy%>ldQp8ISK!@Nv46H52!nYVqbhskf1C39ZEF9Y z7M?gIBoVLd1BOxnw#s#oWJ%= zk~HtR;bS%I%*GPhbK~Xsx%!l`FO1#}_9An;J3Zr;(zo7}8>T#wLyr}R+014JiWuSu8%Bo+q`yUaOU7!vXO=J-78514JMRJ@0pax)v-0@m%Wua4qQ0 zeof)nM3ScdNRi|Oqw@>|f?6 zMpQKQVIQqyw&0q5r_->)A7@?dZVN1K&W;$MARn44EJVWUI|QfNUM*yl_p)ya z5?Wxohm@>@mM{2owXK~Dt~_@-yg&S~-g2&N9`6K;4Eg4^TsOGxz_PBh#_7~p%mix~ zM}=+Q9m5OGuRIiDS-JCyPL|>7MY%k*OQyD4N}^{pFUzL4Y5i-L9k2rpL?0vuZ;_4- ztW|@p)jGf&vfg=+WRbQn!y%pNFpl!U0DkP_P{fvIvcg#P{r1@;-Qap|`P%_R|GZxM zUn}-MX*!7TT8eawdj?%>{MyjYf092!yGW(h`ep+0&iq$zT8ovroX^tWTy7V9YK_TYIX3G+T= zS(Kkrt*EH%R)ic#;Dq00AIMkPO>A>d9K+!^6(BsJT9i8v&wQ3Aa!lji!ko#?%EJU# ze-ZFUC?_H{2;^FrVEv<&W+<6OWmEqcXj3<7fFiYi-2PJT*QuulmvI!rW6Z&Ul>3^z zBDJ9>{n~^E?uQHeK?nEin=8T?8N)rRO`cP4Bq&%YyfmqLDRPhV{DWJvvAF@9_x4f6 zd)8}-A$#U4ngXvGpIq$Qgej!nDHIF->U%7Ks|MHiR!WxT!-D|kdlFXm=5`wuFH1e) z%`BghueCPqIjZBEg3s4`3O!mCn5liJ%=OItQShA_(*Kc0oK!-4!v~oAufpx?Pl98X z>-7vFFQGHw4{8@e$I`|wAidyMSt<`vFx7IqLn|zFCFha_aUdDlX#lGd#2E>YS0S0uqYLaxkLf-CcC*?;F zVyP8Njt_?`#ZDZJ-|sZ+2iC5t^f~&{_SK04WO|$1>@Oz9pN4-i*wG{DXuH~?6~SMc z&bok(qu4{VHM-ZgA^6;CADVCJ&x%dc-^tmonYvRmwu&sTG5=J1M|z}86_3Du0VR0j z;KjjWj(~xYjx3djO^Rx@90qWRt_!XmsU&TsFI>k<#_Dp~|9XGIU+Zr@x5)Rw#T?VXD-NiPZA)v^i*3h%RC;kum2w0RX4OAZ3$&7O$VdAScVQJCGDZ=y(kCgyC!_9OL z0JW+EG~tBF7g1x??pIL^*0~3Mbn}mt@nr+JpH>qK_fismemnv%3v5dBPglTiWp4qe zoAZw$4!)q|Cr>|uPA^tUmV_EW4;j&%@UIQ~&Yg?2tCm~P>7~e!*<6#QP!OEwf%ll z%nC8-qP=?dcMQG+s~)l(%FhgxRoJRe^w7Y213qcn@RL>29o(f4wlU?H-xd6A0s+n53)aCK`j$per$$f8PXna&7 zrhibQvd;HxfPlQOQb{)0rNU-pXmjy0dJde z7GX-wvutv>)(6m{cvQ}qU*MTixwzr@re$Qn0(5lkTHKWa;@3!p@g&2AfjyB+B5^0w zBQlcLtOT+zkM|tPZ#TzPgc7}qdGIn1b*Hcv8C-nddzj<&a~mZjLp>byGAp@nU6&=A zIB-Ak0@ufOWA_nl3Bw&PfkX@d>Rns;V=f)03e}lzLN{gUtXN~b?ea#b_Bv?4hMc!G zb}tcS%c!@9`AaO|lK5Bf+I#qa@RPgvMY)_5`YN zdY&>51z%%XGoRp#xp2GQTHwoRJqzy;|K2(>`L`RqKeCoUR^)N5e zY=rwBH_B*_#e;==rNi5wC?`!f?XNf)z;3^BVhHq!iDUXGQO!HXrQ`vV5(89!Gc%Na&= z!<>34r>?s4d3~MuCF&*2=b@xmZe_hBn+BgAwxp+ZS5B$!k^51!SNPQWamp)A(J)Bm>=f$dru^$CeXHD@&ac|2lR~pt z7I&5yqE+>zV(R4cf|AJ(GJ z{7PuV!p$GMZFX%?YnD9(Rx zF8)2mq5;2(I!VvFGHigsPX zZf0WS%uKaSZc)zg=8^#F;S5(}W4WzHM6^)lOyB5sRCiQZSn^FnHd=%UycyJ2RPfHr zA@i%6va%lRo7-UH_#g+Fb)w$B9lUu3oCyvwWBjOgQ-?RyMSi-k%u4EQXutW;h12)+ zk2hkvh6k!8ATP6Wtxg`OziMR31p5~)GPAY7-C34l9W=XX4VxZRW>-x`^4{$12i4?; z3=Kvq8C<^L{KgfW46+A5cq{|sqNtBEwq;eR5%9iC)r70#T=kKCZ$A5_StPY(B*$jk zb9wVBW0z+A4+B5c&Xb9jEG$tX7;VGsbn7Jo6}v3{r#^w*osO0>Mfvw=NUvX$!UL_^ zy25+8+Va*wZwB7}oM&mg%bVk47b0$gRxR!2)xF7nQR%EywPS_Zvtm1_&c)ON$z`L; z)!8AtJ14PX^Y&aFU%46OG#iI|(LcCRu%O588vBQ?^Pxa@_=f8e8h8AnzlE(PsoFzM z9+{;^ZYPSBip%L5m%UiYtuJLk1~A=Yo`EZ6MOn!j1ie`h*FAy8lHdZ{ zZKuYOJl)}ew&i_qquOz2O+^D?5#jD;Bpy5uYzyZ7wT@xDL|;mDa=Jp=vUgj9-%PTT zU^W4J_`+^b4KY__rq#)-rbKYEuGn-C%MA#G+7h;T1jXhf|k}E+B0Sl2yLNq@vT_> zOv#J2GFP50YgdS^G2Y6GbkXR=3cZLt`(X8ypbSp$BuP5@H6aq-N4SF+U~%+6E%4$4 z<>wpcuo~~nI9TK|Ip{M_YVr+1KW}B6sjuTm>b}Nm^*|*e-8+8$U9n1T=8YwxN*UiG zaI->oMFKB7%yNhJzyi&;!qiuD@uu(s{>lqem5)tr8B>FS1o50&(nz;u{cpV!J_PQQ z!QWcrGO-wL43$ZW?J&EE_4vfodD(tn-acx#NEBrI@=gboUldJW5|J@PL z6Zf(QG|H_C%XdG$(YJfq%%}#wo~^w&_*&~>8Uv4Yo5?F)1bZhstElSQbmaA$6FakW9gE9m4^8I6<(_x#go`ab1#Y5i=VjmjC+ zc3>MSaL!3#UOdjevhO|ISvyy}?o{EEBuP7EMo6)XT>#jKYHm`*QDwk?g?j_~HGB;A zWl-6UvY8=Nu|H^KI7s3IhkH6TlN8ddE9uB=fXm(3UA|hxmPS}y1u9Q+x#CfV zSlG4Yn;?{ihPC>~d=A{y_rWH9kyahxa#i|;IfLY@YFe;K%itYFK{E)=p+N!I)34>? zNQKTM(=0^NV4l-#wVzW5v>TPyHGgYWzSJl>RoR{iu--9b={d+nH>^(ue-U(oxqXh| zTR=A()3gVb{=Z7iKAh>jkK@0JlS(Zm-4VkP<*B2G6`F}k&dNNLmW71op>feDll{U$ ztysp%T}~(qq0v0-7&nSYj+W<#S*tvajM!{!Gv{}o>%P0Lb6x#$-~WEE-+#aN=ly+u z-rv_X7RRtsWxWh8A|_uS+IKeTmSi(A!00D|`dno|iTXklk5u@7+GBJvcJQc)0y(|9 zD6;OrXq)wwrULEHefr>Q z=szdSw3ua@3O16=>$w-}92htIpDYZ-xgCF)5bNG@K2tQ}p)6DqavP=VuCiEK*`@p4 zhqpN8K_M3_nt@ko;d-`q^+st3?0hXtbbhZ#wr@CtR@Kqj5@)5M%$GUN<|+lTCPpV> z4600~eJfFywbQv0Cw~rv2Nw^n(#TUlDmLiih`$7(bc|Y8!?czpaM3>rWUYhS_VC7PtFSi z<0)*7p71Ng?Ei6~e~YMNY&nR(j98yX!^mDu@Y3~8s8P^*Wjn*oeo1xqAGO)9duUD` zHLFNHoU+61W3K@W#2%M+I%L&lS5F$mtv|NqUNa`1S#{P<|@e1u&@}vP`v7I zXibeIx5>UMgIFBap`3ec+uA}8Wbq{aZvz0X^nDY_l)1S!KRww?WFO z4wb8W&UuM-X9)4B9rgn8Ty>C`xqY*~f^CnNwT4Z& z^%c;xdep`bbHs{8j##qcLtMjvG|3Oi)K)+hI8_QEM={sPPPpu22lWyaJS|<(94r*S z<#HiCen*?WfJ*I#auO6csKY#I;24h=_!C#(e;&S9uyA*$Na`@=J!c#md$Q@!n;Q-J zo#uRSjp^WchW3lSD$grn0@Mh#&SL^z^SUkA=j9m^gnj0bUe(`_CwW(N7!MR#rNPCp z<9mrW5d7=O(FvQU=<%1~LR9?rMS06RKl$^kX#;=wQHo(@a@|Yk4lH-Xh=TAz2I_gT ze_w1{-x3e``D@!R-j71h@2F4UccCH>BhwSMgs}x7Js!Hmvx_i9iOw+c1szs-|11R7 z6K|Ic;25_nF}I&>ToAViSAb(MKiizsNxG!XBjWUe= zbO6V!O7Qqp%)4Fw1HuO!ppsalGXd<2<-*9V5|8Iz^V<bw zP%?CNHl{0>a$l5We&$rF@rS~Di3XnAT#BQ7hFtG_g&>BLky*pA;kb#H8RU9Oi`IyX z2s7A+okvLn9_L& z+d5~4yn|mzkmkhL&@g|i&SQ@^w>rB70zUlO5f~X$_iBvcFsA2LjrLCQXC)le)I44$ zd`fz!beC|_m-M=9?Yzd?LxVD1-4FCC7YhDmX%AolK(?w8K8?H!0Iupp8(@{aRX=&T OPxjq{=C9pgW$;gAsXNO6 literal 0 HcmV?d00001 diff --git a/images/绿24.gif b/images/绿24.gif new file mode 100644 index 0000000000000000000000000000000000000000..4e1bd232aea9db746a9e67cae167180d60788323 GIT binary patch literal 417 zcmZ?wbhEHblwgoxxXJ(m|Ns9#GxJQ^%$W>n#tbu!8O|6R|4(E1Z_MzYf#D1T!%PN- zGzR1U#>PPLnZ{}V(~Q%MXa1j=HZ$$a|1k^(n6C0xTZ2Pi}AJ<%;V$|R957fAT$zWPJ7voU Z#kVesio*PYKfZo*lXs}tA;iL94FGKPct!vK literal 0 HcmV?d00001 diff --git a/images/绿25.gif b/images/绿25.gif new file mode 100644 index 0000000000000000000000000000000000000000..ddadb26eab225f1f635ce5c2aea2475ec4657d8a GIT binary patch literal 434 zcmZ?wbhEHblw^=(xXJ(m|Ns9#GxJQ^%$W>n#tbu!8O|6R|4(E1Z_MzYf#D1T!%PN- zGzR1U#>PPLnZ{}V(~Q%MXa1j=HZ$$a|1FOvG<~@4YGazUAizAB+4BhqxTSREdv9>KTZgKh;a4Cp8+=(ebLWHriv%Vpa z$5}W~sEbiVfVVf0Po_*JVKSq%(9B@2IgHF=yj?Svln5#-@NlwsuUoo7aWk(dcyH literal 0 HcmV?d00001 diff --git a/images/设备监控.gif b/images/设备监控.gif new file mode 100644 index 0000000000000000000000000000000000000000..9af5a6de0461199fdf1bbf48d1e7625d7811c7be GIT binary patch literal 1240 zcmb`G`&W|%7{{lKi>3(*I7AY{jKWMv3-ee4nhGdLRvb@xOuKlYo#xC#P`}+<7H@2}$Yg@Cwq34I^$Itnm@AG+f?fE2Y z%h$1#Sc;qSa)QAi0zg535C-93An33=>~nS)fFVw7 z>>+WBWLP>ZlyD#OApqg_4b791r(00xX80;3pg8CU7JPXoYSVjJTe7z0=N0Dd*|)#wv%-C!7UUOoclB}F zJI6-H6>^nCEFTg|gaYw1{t%xh-EjeIc8>FkmQs`qZ=Dj$z%$tR3;LM`}+DH zKJ035@3?T`qTe6z`Tp^Eye^m9>72J(Z8%OyBvP?h^5{`tYinC=?Nu&+XjG|zQ4%mi zTAdz%a5IdXV8ZS3!U(D!pD-i%z*8Q8;2=hrVFbi*5J5~JIPY=+C;}j`35FbQ*X*3l z>2=S!oJItko}HQX*sUIi9s?Y1Cjgu6Zimz5^auP#ldexQt-!9ku^z?HckIQENiiBi>LRXj|FcdWdHmlV_k|aS8IBql; zlw)I~3I(6X3j_jwzu#)L&d$zSLW*G+5{hav>GgWGTCG$nWinZBZ!d?#sjm<9S;Jzn z%FD|`#{OsS|FBZL)CCj@Nm>7r_3|euQ9()=Z8@#6ad4rQlW-ud$ke~;cSn_^OTHy`gAj*3auGUL{-jb4_W z8@72qrYT4M8%22H%mzkFG?}a6Bo#w~!iLQ|4^E9#rI);WXt1wK&p3LeF0J53+L;`Y zw&SZOm%Pg(W@yc44-3j*`?ryG?;nk4Jh~abH*wSVqR!1*4?`6TPb})*a_Nk%w1VH5xq0QUd@00030|NpI)m$0X(+RM%P-ske^?Cs|1`rz%#vcl@y z=kMe0`sMoW=I-t2?ds|3^xXLE=I-q0?d9O-(!|;6Feh5>E`YA^ZDuM>+9h%C5Y6Lf*CO~&gW|-F3*_E230XUBxMus>~b!va01T=eIfVAf5>j6!)0!5vGo4~@y z&IdbvGiahlCxumen$;O_k5=IQ`YmjPC!7F?SHXu$+!w+(*U zTB_@_(CGkk%LQ`9yvo&zl9=Z3_yBm$0A;8Fit96<=>wAN2$k&zfY1qi#0YV;6r=l| z+5Z52!UdM)C#dz|?eyj9?Es~6?^7J^9pw{c|;p*$j^7ZWR?_{#D z-|XvVnw948?cDL|+0g{=-lDo*6iWq>*wX^=Ui=L-tXk(>gK=3z~AWL-Rj=u z@#Xvc`|9iJ-SOMw?c(R`=H%?+vD>2O>gC+z*68cx=j-9>?B|7|Q{?N^vd&`W>e}k< z;qUX|(bu}}@9OI7=H}<(-|nF3>)ZSM^^lT!+T=>l)lJdWeC+Jyad1!8%`@%n+v@4q z_VnKR>Rq?1Nb2d|ud0gw*%9r?8sfq${>TIN#}d4pI?%_d|GohFz7Eiw5vrG7?djd? z>ErdV4F9qO-lZS&?&H|h%l4!I{Hz1VqFC?ignhHrU2-Y1?=hM|Cs~xnilAh z71fkB?12IAlPB7ZFTsU4{*Dgae;LA`dH3hl;B*Aah)3_`+v(`%+=ex^iemM862)d0 z)Sz|QdNJ+k=I`m{<>KJLR~Ou>iQ~z-;j*3i?&-w5y6flWv`#n3nUdk!+34Zm_vGU7 z<>c+_>;M1%A^8LW00930EC2ui02BZe000R80LwJsH)_L$S^DI4Q`e5(21S{6MUe2$ zRH;DF=cC25kANwtgr&F$0Kmdg6XOPMT;6er)~j4luVj5A02+!$VTi}AvJW^ zNC7e;Ri;KDn(2Yzfd`Xgz-kS8lSfV#BRP;%N@idHixMV;VDVE67Nif z<7|+4@#4srEPhDk^7JMR8!<|1M5#AUMTitMgfw{q=S~z(gXYA!vLi(gORi>|Ac2F2 zlP+V(gkcp+6p<-HJXEn{$=M7ME}VPR;R42utX{r=EEy6*MurR)2nc{d!^oE{XYl9( z7VHs@AU;^&&n1VTKtL5R41t9hXslrjF~!hQ2NnD51J5D_oa2ckRj3fd4X+3T4K&OQ zfXXcp^s@>e{G3CGCo)iw06X4fgN-)P5P(ZF3>Y9tAG;s|h&c-=kk2~gkW!f4PBA|Sb#3+-LDFFrtjAP3L6bQfzF9b|rha;V6;>aeT hd=iQ(_Z)yoB>U*I2qO-F5Q#MIXkbPn4>%AI06U;?(QyC( literal 0 HcmV?d00001 diff --git a/images/调度日志.gif b/images/调度日志.gif new file mode 100644 index 0000000000000000000000000000000000000000..55d1a76e09d662b1d05d3cbf1098ebac0da883db GIT binary patch literal 1261 zcmVV4@&Eh(`Stnp@$=Km)%^JV$Hd66 zt+Ds=`sCx~IygPv+~WQG|2{lN>gn?E@bc{J?##^1#mLe1_W5gXd7!7S@$~oj`uz6! z`&VCMY;JG-{{Qp!_U`iY)!W?h`1$nx{_FGfid=gZ{Jx9s87x_LI+l~3%eX4?@95<8id4RIQt;o{uc)Qeyt98|Sm976?~inFY-_ZoqTRy1 zt)igbIU&`hpVFnE;gycT9~IKW!o>#w+87eQ3kUq|?cUYZNJT~d_V)Pl^2)}>^6~MD zii-F5_y7O@A^8LW00930EC2ui02BZe000R80J~NDMG%)kO`lYO0tE~kwo}v2onr<` zk~2hk)`*E?DW4@mmi!P3hAtkxW|3NqKw(5l6eTB4F!>V3${%>~=C#A+2*?da`SS76 zN5X{@GdXxLSWvHBxL>-SOj$EQf&+Ugpmg!~LWhM0;-D4#wN3?=KnxPR`_raP09omN zXpu81nzvZlSYYu}K!LS6FG8eIb74l3Jfg0JizTUoiV!7K(4bNTf*LaTSio5%Dq1*B zlH`qG(hr7*08hwdz(7GCBQU~@-QBhii4r=ztPLRW?G2t0Ao$ryCY#flG(?P)a|aK> z0&{1)R5?Rgam5!M2;swmJ!G*(0N@<6%q}~yP{R^+1mQvnHgI4E9B>SRLJl4r zGmRoQ#GuC>mz-e2iyK5R2pc&NaYG-WKx4=aI5-i&k4p?u#w9;;fdv|U+|h_Jk?aCN zB85<*4JCL8qRo|kki(8Tj%-4WC%)v83M{bP@=7Y3pmGZ=sN~`cGLLvtOfRdHLdq<) XutG~Md9u<;DW;IpNhYHZ6A%D9)~^K3 literal 0 HcmV?d00001 diff --git a/images/黄.gif b/images/黄.gif new file mode 100644 index 0000000000000000000000000000000000000000..8ac7847f9a2498836a1c756702f12f3482e62b5a GIT binary patch literal 529 zcmZ?wbhEHblw*)%xXJ(m|NsA=nKm;mZRX6GXU?4Yf9C)HzyJR)x~RA74#S=Q%J2V2 zz5mbf8-$qt{{<>$`2CyV^Jj+l?-|aVVc4~cVdhMRh6aX`5{9%i24iEO0;d1}S^ocL z`~P3y|9^@5_Z9BkQU3qm^8bI=rAu{}EYV%GNN?s$Tw)S4ote~VI&817OrgE7i`Y0Hjs5J8AJhUT()oJ~0+b>?LqO5NJ zuaD98Q|D=@Xed+h)f5rnFOiqmnABOC>#Z$TrljkxKW(};E2FcxjNl}F{rS2JGXzAn z*_h!FX53ibrRps$H?x^y}yh{oq4HviL!^rnQ~EV=90@ZCx44zCp$0F&PWiw@l`{GHG#a92kj2pQoi;A+SNi9#CFj-Gj zLS({{!@?3QJZf#WD_{AKcsWbg$a+cXDBdO0|34= B-bw%f literal 0 HcmV?d00001 diff --git a/images/黄25.gif b/images/黄25.gif new file mode 100644 index 0000000000000000000000000000000000000000..eaa46ea8b7b5e8b368fb931569f98382d02e3dce GIT binary patch literal 445 zcmZ?wbhEHblw^=(xXJ(m|NsA=nKm;mZRX6GXU?4Yf9C)HzyJR)x~RA74#S=Q%J2V2 zz5mbf8-$qt{{<>$`2CyV^Jj+l?-|aVVc4~cVdhMRh6aX`5{9%i24iEO0;d1}S^ocL z`~P3y|9^@5_Z9BkQU3qm^8bI=rAu{}EYV%GNN?s$QhBOA6c>c zZK8^|SdOl{enUB{r<07Jyu5z9Zl{5OHk*^CfUKT}{*=x{NmD0r0X{}{H||9_>dc@9LHO zT^8nd%L<)qUzWQt-nv^a>Sdf&vTmBNvA4Ep{jt`SW@kKmeVJbyL~LK`z{MkRrDJ77 S=@7Bp$Ll1!9=KQKVJfW{X%G{sAyLvE|7b&}^%XkE_TprQX z?Kiq|l>b^@h$PUUp z>jIg`-Q%ETEQ>^pd}rbBIpF`n0{$aF4c#r10Z;+fjFRAdg1pzbTuo*4GIX9DG~|}x z(7loUA<-D6Qxt%x`zWV+FG*i0a{@KW4m*C>**kM3c~d#j>cGI0?Ul{gg#nTeCYf*J zFEAdXlY3q@+tQP9imN7m%^MG-RciV>xIb7P9c^=8*clzU!DsZjP489`Kep?bgx|%L z7#^Sd?AM5|Rc_8Zv8|40ek`KtMZDIP5_L^+D17pawNz+nyAy_3Be{Fv9WnFtb(5t- zuY^gE7NyM+PDHUR5eAycx_;i2aNZj6uTj+{3)<+Gf4%FY{CkjAo5iTK8Z za9S9_uD|r%#z?#!6MxRu#YdLD*U){`>V{$Sk%w@7 zo26qmr^&W0H^K+$<1uAg?6wzlwTdZX^52|0A||r^DHabHE%EL@!<%H(l?TdCl!Cm+ zoSfomq0``a~$8W!BaSl((mEoEK}2E3hnc_1zgOd>%2+2)66%x zZ8d9)YWq}PEsrd}j3;k?17oZ@CAf$ARpLgbN>p0vbi}=_rpR+zg1kv*j$KQF^WNc2 zf(!bmopyO>tXbS)Jg9v`zKrIiMox>4q46{_!mGx^M7;GXt0Wh`Yt`J6j|M)9HbPSI zCytkUzdERUxnZz;UCUc2FUKN8pmoV$1+{m4(~^%pS*3>oit{0c>m)H>%PS(oN!v`l zdcFBps8Z2@h3E!f;u75zTG#RCPbWlqFL!|wx>f}?ldb{y*=35~<#@u;gE8qwRpu_8 zCkv)a#3!rUBYgKz3h{E`yI19QxO4Ir@{Ekbtj9X}?6UHVOvILIFq9jGyh*06->daY zmV|opIT^de(HBWwN8A!=h#Z57h~eL@%H7sw^G&pFRTttJx#6S1K>yNqr>O}KXdz8o z;k>E)lYFj4U%MI~#CcE)%p>MIkAw_=F5#}*_!%4Vd%ZFyLLOHFKFL?6wBmbKkC5J> zzQ7=JojhMCadtJEUD;Z5n$Xw?a?snUG zmt8*hq^wRpi<~>CPw2ez@qNzpdVGZm341XC+eUwml^=dXmKFlgYSYk##&v+KRUie&nV)B1$0brVuE3*pGt1(yk>i zCJ-+cpSpVDj@j6zaP8}6+x;B66n6^l`bGK`pHDX1Cv9L^%JWhqQ>0!B*+x=z9d!7buM{Oq4u}6hlXw<-2YhA4y!$*ui+jqU)kI5J!G()S-i9CYq$+?NHK=&O=Jw43hWZXE6R1c1tU;7g7)yEwvvAGk}& z_C3tGo9oJMm}2(}ejr~`QSOF86^1~=|AimQU6qCqv0El|ZI?y|5OZ_{W8A6q`q!0_6Xn8ZpVGW5agF~ zNOt2uG$Z(u?FQhQKjls4v=O^JZe92#3`+EeK1UTX8L69{C z($h=d59y2e)-ecilx|>0`VTC%ohK6PQ2&9a0-MKmQ3xO&=s22X$6fi*J zOLkxK|FUx+15LNPCE!2p*>XlAy%fa6JbXoM2}V{?drx<{2~lw|Kv5;o%hui% zfrQy1K%G*Ff1##C5a{mZ zjzHSN0^Qv_d=&zf_;)i`0AT`Jj32g3f^=2lH`O}{LxP%`s|yka?%_lv<%MC6KDO?N z08bxRn1rY-KbWD9gQJ3h=FzX&fgvUSuY3mt1c(MmiF*1tiAfwjd{|6eQcO}(1f&r0 z4e~(R28ww2@_?o7vf*O-J=rhSburzoEm#mGY_}*)gs;7iix<+x(*s5*+7{daAeH$2 z{9GIqq@<-Cr6uI#MQo+)Y(*p_5aJ?sQir8QY~|z-Qu0#blJd3^{FJb-MIu0h`R@xQ z#C$6j22&&i6?Qd4Lr~%fWeG*GzoNiQzmT1D2}HP=YPz^1JbXbGl_kZ+zf%7-=GP== z{x-=^F`x*<2zCBR2LB6k@%pI=e`yOa0+foB7}yy9H;jBcQ}}%=d3}risj0r>6m(pC zk)A$5%8FwDiTl4{AL-)wH~otc^AppApaQrHM1X^W(60#{>_2dX?y`$CH9+`!y7}!A z%1MfSqx~8Eo%YP{X@5q4r~N@{?BRk`mi)@YU(o+Iq5~(n-?#a<*^kf#VTxc#LBj_D z?v^#d7aVI65+dSqBH|K8-;SGv#N`zTBk(Vj-xBM2I=DCn{gcE$QGQPh&Xx|gNZWsu z{Ab#48SJtS?nA*DR(bb~>9?n7KQaH6_W!I6^z{DgR&aOUoeOpwLQhXY)6?D$ocEA$ zP3133ii4*;I4l1ce_!Wkx&LZ@-mUJhnf>3?*TMdKWxYVF$L_M_U@wMnLlElZ3yxQb zueEisS8(+7akoV(ySUprA;ivlA)FM&eqevk@0Y0?Tq(gdQ|$XHOz6k|`_G?3{*{dX zi0hBI{*?s&74e_m^+#O)N&^3i_)qWpBd&iXfqzB(r+57k*T0g$zaswAyZ(slUrFF! z5&!93f5i2#B=E0@|EIl+@`oKC;Q<=&13)W1euUZ-uAyOl(m?+x{J7TcfdjS9aTgCy zBG3)S-2>@kpsfxwJ!1wVdkeb3P=J0opu>x;y|0&^;ZcIG1_0O6fcb(%1o+3Z-uuOi zqgzDhBn9|xF*r@NP}M-TvfsWTxJz(|lS3>31g z#9>)k5lK;kztOknzl{7w^xymv+V%^{%BkHpgRs8-f%}p82hKAG^wt7>)}RSLaCSEU zpdu0g_I~_<7N&8RrVI}mJpH6LD5cZ-3fqsAfTY~SDe-Hdro+zQb@3Mnw zesSf25rk?Fy5{)#zFZ~{b!T8@TCEyB>09*%d0+~P_PzaO&Wk3Z` z3p@p00I$F+Aw57pFbs?XGr%IS4q(B{2V@W$2or=2!Uf@j2tgzv@(^W+7UVd@0CEOm z195_QK>Q%*AQvH5AW4v$kZedH4bcMe1c3tmLXe2P$Fs~W+D!vgG6FP z@3L?TNjK!-%gE z-y|*|enQ+#+)ez6c##-KLPNq%B1ED<0w*ygaUuyIxkQpea+l;W$#aq(l5vuCQc_Y@ zQhri7QXSGWq-RM(NUxIKCM_jxB<&;}C0!#UBV!{IB2yyMC$l9(l3gOZL3W?4fvk&c zoNR-fikypFlKd#S8Mz1f1@aW~BJz6jF7gR-ECoFUAB6&iK7|8C5Jfyi9z``pJH!2K(x@I#y`=g?wMorLeTZ6v z+Jf4TI*vM@x{>+=^$HCQ%|RMf8Z#OsO&m=jO%u%^%?2$Kttc&=)`1p9n@;c{vf>uy)AtheL8&=eINZA0~3P;gFb^h!&QbNhE|42 zMl!~Oj9QEij1i2vj7^NAOi(5sCJiQgri)B@OwXCdnMs-Xnc>W5nXfPxGrwhCWMO2H zW;x9g$db-d$1=7tu}5tWVo&s*l098}Fnjm!Ro#o&8?(1` zZ_nN>HW-^0n=4x)TLs&|KH`0c_MO@nurFiZ^L?}XnfD*rZ@)igf7$+z>_qH`*bUf2 z*mK!mv#)V*a%gjSaopf&;+W-R93na- zbIAEn`k{6qA|Y8J7opoiox&u-hlM?abAx@p(}AgqFQ2E@{pvxWV+-#DH^GxQYfiPsU>M4X@qo!^m`d5 z89kXOnP)OPvU0LMvL&)pa=daja<}CAWh)IU!<225vy_Kb4yf3w!wcbyx^lXqy3NO^j~O1jd2HnPq2oTstM!QVboG+;&?op#c$}!v2lV0k z$@&8)`A>SEtT{z`>g1{PQ=bha49*#}7%~}J8x|R^8>t(`8}%Ct82cGNJ56`m;&kC@ zjESa6lF6{Cm}#i#t26t~xSXjpBQrZ~cGqmpT+95r`M8CQ#U+bgOMc5h%T}v>R&G{x z)^ygk*5x)NHYPSjHruxPwmG(Ic5u5}c8m5J_Nn$W4yq2<9HtOTh$O^>qmpBiPvx;+y^Q?=8%T1T1vpQ!p&thElUGrV>ZYFM}?&R(^?o}R)9{<6<0Q+OCLSNx8Cp)&6Q* ztVC>DEI!UL?rpqmd`1Fkf=5DcqDo>x5<^mO(rB_?@{?<@YcbbWuUlVlO_5H?Or=cq zOC3%-o>qB-_eR2v?VHXwd(zd@OK-8?ioS)p?Qpv*Lp7r$lOyv==2n(V*86Pj>?b(~ zb5e3ibNzEa=bg@Lxg&q4@b135SMKiQd*lxn7!))Y$`uwCu@}YPBf95zZ|c6q{f=VI z;>r?{lI&8}(kl;u2YwHxAKEsadI>nZCa>hTT14Qq{Fjk8ako{m1Ve%9Y)+VrmZRP)>C z$DY4@ar8w~i&{&=OQn~!tqQGGZSrjuuVi06c`ft$@f(>pkKf9^ebO%1UfFTDqquI-U_ltM%cdvR*^mO(b_rCA5=o^0T@P6`x+lQr({vWaZ=g}nSm;w5MltK2v zoFT!X(qY-*x=)&)UXK`#^pDz)&W!nvZI4HMrum#Q!8K7hDLGj?b#$s@+I)I^#%l&U zdufhg?$*4({G$cch1ZLwi{nc^OZerhD{L$ItJ15_)=sVsuDh>eF)k@g?vQ3IXr`{kYD^23}_b)mng*2)vT_{UIYKB_XDOQi2yfsX#O-6fFOHBp3xH zBO-@T0F+ep01*TVUTB08I3gmY@PmL?9T`X%Ne_@QaRcNM%xaQ6EEK2IS#5cx_854F z@3l+h)5w0fcu?AhlI>}y4F4xX*$YcaIhsbkT1Vxy?FEcao9rul)-|&1a1ogtfygay z>K+x8cU0z2;I**+CgLBUvp6 zeoEhq$w!d{evJ`+r{y9dcNtz0+;=VS5#c80^)FX31++~Z<-gy?{Badi$J9CSa#}&< z%lDHThv8>jf}(E}R<(YZ+B~G7Yj!p`=4MfK+sEmxUvEqfjSf{~tT6L+eRbGUzlE@w zfsn6=-otz`Ff%vz@ z)9T{%{D*RnWp3kd(ZW(0o&Bx^Kj0fE{&&(Rg>7PTN6xI;hT(#%y zw57NDnAl~O8{nakmvVTy$1SNLAtG5TUXkvddwZ?dkTPZ{FvG?RgZu2kWmg5g19x#e z9}Z+sA3(ERgk2jubYnHJ-{`)ENOAjvBiNPs*^&i0CF>fA!u!Rzu-l7S&ksO35K+F4 z*_vvWa&xU?)~6oG)z#P1*}30akei?Hxx?(GoIRy&b76|nBOC+%kR zUR`E-bF6A|m`Wc;!l!*Gb>MbhvuMBvw2+B#Fk%+wZe*n-?0x%=SuA`!Y3pbd@3OnM z?;0k>B5G%hy@&d8dh7=wwdU1JmPJzPWa^|+Wp+1Z87ql(8WKo~T>)(_{h&8z}*~CgqZRZ#ssFf31;XPG0q;0su!P@FL z8HmifRK|Awj0OFW+GZUd7|EF6s7YIY)5?-nWq4{VSf}&B^0X-ot7Kxra=KvpcEJ2V zNNEVhYG!b!uNu?fH($5#6@l;g&u(U$5}0LaP@RPb7|F_ZTKxLg(}P4SsPbZ1SomTk zdaj>&NqH!kIzR##?(I5!e($^ThxXfB zR^kHU3Zrvmzo{po;%hIr7)9(`);I^^TzFu)^uZW|?E4w}BYoRfW$POH&390X>w+H- z*Z6%LJ9=TR55A^koFER1yIxt>Zb%$+Jl0)72M?Nta4Wcm+Vu661(w(QnIDp&dArEB zweylb-V0-2J!BKmG#LSh)#uQ>RJ7hk!BBM}Q>gNWb8NSZZENbElQDH_y%-emp6IB! zicWZUiB$higW~(lMXpZ^cW?tCD~}fz)yyB5cDLua6zj4+ojOCJs|z{J$~`jFjpH9Y zHW#vXcXZz)AE;GA8N<6QwYmn*_NUZ`=!|9>LVipSyYmIU^GCy$ko65lQ&QNg^;O%o zO$a{h)SYiKaxMB;yraz%Cy!waxia4_wk+E3?H3SuL5nP!L-5kT9qGFYV&*ju9Iq!S z1d&@FTz55H+1v{Ggc;0SXsz;)oIi5nc@@j$o)Gix0gC%idMv45WrR~!e<;fHPkcY^ zgUdw~%5Lo_*Kdr!K~L4JSZ?=)ME1XY4R7VoZC1T-kwashYI^6}g!UgZ+^-1I7u$HC z9uHhzUo}*8qkOE;cS5?StMT+}RT^C5mH4GCEa&pX;lVkn7oD%)Z?2iBHeT!qk3^TL z&niYGkd(Go^tNoH29+l09$5#vH@T+t9u}j4aE9)&Fefe5I8Ele89}L60!+;Ku5Mvx zP~|FthynYGxMMNzX!&!5(pB@L)QwquUY|#!RK->s)`%t+Ro-JK_Xzn$>@Tj>A1To; z)sj4_<=tKOKxGy+YBgp$euh~x;|BL_pY;i|??bKu-?iH!7H2M8$(%yDw{mMnqC047 z72p%TOD7x6UuIpZSltTM#?l4O%wuZJ1Nhx5_@{d;1Xrfq>mDXtMVezgW>bpH3VIEU zZo{mvSnqg{Vd>71W8dsdh;3e)UVq!~ZO>*WK0xU%-0a7vttQ=F`^KL)GhcBrtij52 zAuav$ns<%mE5)u9;d5JZCjk!Ib&cMwUuJ_rOx`G&Qb?&O9?+P3ej%Xbvc=B%jK`;D z`utV8`|&_cX=7n|0^MqUsZsD+PhEasUOa6CXGLFK#b2hCp@jyOzHM^MW4pV#rG5t~ zJ{~0YZiMbc);IJ`%^oXXNPe#yyWfGcppA~9tDELl3fqC5XTqrBaBx1T=UiU+m>DF; zQS^C0?-QlqM3-RkQ+9=Y>+2)E;b!`C(DtrgTxvso6?XqZOE2FwU#leViB6WD$1?WW zju+|<0%)I#Dm-9{YNiVn8GGw}(eFugL}L6LKa7IC^D-TQ~wKS8u#V7^KM62$V^X;(_?*ctCkr%&+cc#duxW zTz&D$NM)30ig{D<`FyQc{_|2Y9miXGd&l0d*seB=E}_nGVc%jmm8blITxmyMOA64b zyB@KG?L#sc!TB`ryP3`EJg9rxuz`xNKU?4Q7QIfA31jnajCvK`Ydaf+_Zz$JdN|M08fC z)knrv3a_Ca@DDmJ2VnR@mZ}9)Z&syxKCrNn(Ql8QtlNxxe-7M&T&whQJ2NZNiU+vX zRc5fQ9%i`FdZY9G4KmogH*srmw_Lj9KEqXr*=EF>4e9QcbFFRQ0Xj^k?};}%ZyNkV zi^SzlIMr5NlX11;>5hk|r-|(y5m$IE@hEc?w=!?okE+JZM?O~0@8`>Wa{I$n%AjZe zl3|JZg;x;h=sJtnxJ~{fM>CBfwL~P;quh+JthX6Q~G*LrpdOhsHo8)cBS?553?Q~IsN{Z zZ7wqc#!wEfepVQ(UGSx$Ow3TS@W8WXRE08@W7etmSP;#9N9z;(IaFx^@JWN5LZ+jahFS5z z{`hR%laawKxwhID>9LRWMySI(6{AnwW=4CrSJAL5Tu^W-v0CV>#=jei;yL|5b1qC3 zb{+*L7CL8w5pPYdph zi&MODO60N4 z>>n}3vmakvL2}2X837Qig5Uw)xT^k-Rs1z+y{@hM=lF|8yGv%39)2nuHQZdAUYnr{ zBfoflre|hwPF1lQV>+~h!FoE>_cGELBscnS2M2mc?!YnRgt}X?cBvJINDGAlgdAMO>NWJbVM$#2N zcdCS(g)@`|-PDrZPm;u_y;oR;t8W_htPk@64>*Q49mBdByF4x63?(b!&OUfsY&g}F zRppbbHx9EPyYBwfBRlru>D-(N=4q#gbe!ok_@2RZ-|=4gaY#JbBC2sHLu?K6cBodY zs<+1SI{KKPh(>2!9$(?9PT%(Nh;kJgJDS**^-^EYsrGs%Y|Xsbg5}63GmX5e%~ie& zup$A)YMs2B?-Td$&n%osYR>ct7?^*%5`=cwi+kg%WZ`gtXTAHb=xTwCjbL|=!sEy; zbjU(L*{$3Lv$@_<-$%7VdFRw`lZsl(*jC>psT;4$qoLLyc>F-HBUuvjA88xfG1b(4&cvnj6CYiOk1eTwhh<)NuV2Ua%ICj%^XT zS0$R~6l|1nJ^V!VdTR07&-^Y1`LI04E*Q8VbVe|WTW9h}4gsGEr>jNef!+WV*Lo7d2Gr()9 zMZ;gR^yQW5Z7cMSThJ(|R8&+bz80GuKBzm4)R1)Hzq3!KQN?-&59}L7uXze2LOA%8 zz<-TnAk(kU@{XnI{`3`BNJt`>d2Hr6Rm?Nr*ZZ%($*ZuFkLH=^NJ2ZCg?DJ3OjL|` zC>&OsfXdq1QORE4w~m^hnB$zO>Gx24UXec4WOUDgsi#DAo<&FFL`^h3Cj>wx$ z%zM4X(qlY85_}-z%&pr#oOi6_8}WcSdSdiQ!K|^hs(=E# zudeUQ2Gnn%CCX}s2}`lU94CV48nam)S?x9;lT+Tz#axL+Jg#GGYd(qN>3nlTekwyX zcTs6Ec`$@ZqS8`4uGny~lCt`zrqwfgZRLlG|pT6BxLcSkgF)}2`tJL)B@f6#vx zGbK{%6sI6;tGkBpL%;GlO?uO~N{%-}r7=!q?IF+5+W;kBVH1mPX`jIuS7nrPWTFTY zRhNCnWxi`;HFhn3~Ng;#89kwLSM9aDAF8>N`IZ9hf=;YuLiQl%sW7A9Y+( zITsT3M15)rDrvvD=FR?Qu^HuLq4;ie?Rdi+9so78C+oDenD+U#3YI+?({lrZ$zq#Z zUgnmZ^qiG4miu-PWJ_zD&jK=ohpOjdbh@xNoS)Os@LI2|dD{mEss}gsJaWRK7L-So z&tj)`dPF{@sLZUMKr%&<pa*F8J(yKn{q?9hxlNPbIEVSQcU9ZvH|aWd$~R5p*Ibs zQn_yn&Xl_Q)qmfS{>K*eXGDpP4o@;T_eT>p10}tBw0G;ASM!_S+WT#r#^-PE9qilg zAJhu5txGrW_rL=ZU1yTARu$%AJ|R92>F28)1xHlKZ2rJR`bBNWyVfTzdvwHFQmq=p zUeso2cjMHyae$7^ z*3(vq(=Y9KVN8VAy2o2`Q|l@zi707r%rS;Vn8zt+E-Q;Hs8k6h2klQ0w!Mg1o5Wth@hsx84>etsAfpQIYi4WIWF2G zHC{uH)%^UC2X6mHA44J`qqSJ*x72SEzFkLs-!adZ7 z(_Wz3lpSQMVJzIJ-4aje40e{o13}%{Nu^*!!Go=kk@&&WpUbSmS0=R_<^6!&&8Pc9;;reArA}CV?T3pqdn$YCdAbKe z2LHxH_nS%Vx6@n*ySCLdLg-A(9yzYLhSG43E=^vaXetzFu3z+;$S?+5!H>f!2=Xik8r3y&yDz?Q{Vznd2byVU77Kq zEfn0vj)XR4Ojfe)IlRrEKRlvU0vJhN0rJ+rrPA`3D~nP^c~S1hc|&hp6-|K{6#abN9ZhYMm!;j2D?GUmu-X-3}RPsJ9M&t1&@QVv_1V#b$ad zBSN-UGHYLd!JWF{gV@((0hLL{S9Fs*bM7X#lqff8zU#a9_lnCeW9`4Tq-1ctQ@ZVL z-Ou0O?cOy*v6V8o!vFEm#yTEwo}%6+XAfqcM7=598j91ePh2)FzNKO_nR7x#xdHzU zeNQ~DN7Ay`Uu9Md^#%_#p~dPCj`A|?x!st(GNn7UI>lzf#fwf)4p{-GW&4eade_iV z|51^;g)7n#^eBeOj~!#kcJA;nvDGo`h*))vah@DTnCITv!@L<0UQBAeDuEMT*$y@& zB*7+qbr1h)kNB&(@}Kr0zxnc}P<1poC6*6lv*oKQ1?Ps=k?$pE8&DZ;3=?t9K*?>H z@5I-BS~qmem>>Cgk%eOqnjSJ~|DwZ6B7_#Q2h{5d@PHL=t8@;-cj;mH9q&dYT=<4O zsHmgcWm5`#UVNTI6*n|r3FOJ2ECNBh;QvR{nVxI=!ofleo;^d4ha)Xv0? z>&ikpDp0TA@#f&7`H;}9MVZNuoo2ZlQt&mEg$B-z+w&hx>Z$~v1ssZ;)qsrN4n^7X*+jcZscJvWXq`zT#idDkac z_WUis=(>@|8+pZXDYTVXwVq#1*#Epw{3^m4fkKXud|hVYX)@mARjyH7=~ZEY z6-T0iq+_+C)XCqw>}^-O?Evw#F`s$GU?UGR&rrqC`<_OBerxlv+&;gv+V+}@B0#sT zqr5pVKZss><7KAcu<8!=nwB8gvQ`#oD|A+mgSL@lEvXiv*Ze$wt?JJf|9>v78go{z zg@*i!xsICf-fE*yF11Oe8=N{^y+boYtJqdL7k_9-rCHaZo+!AJ4f8}U&0~o%UXlDo zmHe&b9kGS#O#k|0&Nk%)H5oW|;m2zKY5k#FMPT9Xy(6SZcBQ4rUTi1;{7=1VC2$4q{8QBFL_9a|F z$nBldaf*u2ww}|BXPaK-t>`ebui8FIp)aI1!BV=JtW0m?=s2@|tAl#NEIg&~w1fSa9vC8P7C~;^#ei_AeEJ18-VrO(nN@;Vwuq3xS zuoy0_Y{}lQf7~QXPUcGBSc1#LQ5^qH6=*4*Ra$Bvi1+Z6#ipmou0rBdwHIHKk9J9# zu5v9seu)PXaoV-V2V^H6UGIs4b~S1VSv|n=a9{d6W7R($vfeWT$MW(e+j3fxgxzsm z$)5Sj&$r9VUR7B>-@~4^9+&8KEk5!|c61u|@#ltExvem`Ets>7(sKGxDdJ9|CvV*QTbZKq z?jEEHBxPwW(cy`51TRWm8@sU1 zx%3S8;+PBD8J82+FZQY+ZYd1?3(e{0oldW5jtfmxU;J}i!va~RBldK^$Xc`ai@c=Z zLg~q4AN&2L&%%VS2J)gqwOWSvhobs09i=s?59RjntmSomkP^{O)v7RoXbE*D_g8A> zT~JXa-k%;niSAEFo8fTh>*Cjg+f)4eWo2zm1(r9FEY+2wI;F>us#&P#A{)@D1>w25 z(TZ4mtt@CBadMx^S%tpcdVoe@f}?tE(v04Ex9M2@ndh1O0A=6t& z84<}Hq9$9YQrysvrbV(fTo zeP+N+bnMuJkAT3r>LZVNgK4}I zZ3vy{GBZ6x!Mbf>1uEI4J4&ODqmT8Rc!UlxD;*-H7wqM77^8O%uCT)VtJ&5ehX4A7 zoFvot<{7BohH|~~vsLJMMsgm$=o!uPhk_YpUvw6hioT9T93lxHP7vE1X~s^P47AKw z)UJf?M80{G8%PrVY250H=mN3r`O(g_{(iem&V+~hC*xY;vxiqaR0czLh(b6pK_7y+ z+@H9J?0G?{SWRUy$VLO1a=TmroN`5h_Ks*w%9Hhuk1rmopBLcRlWf?h;<;AxeXYg! zd_QyTl~vWcucBgoXJcY&V?86pc|!euo!dU-E9XHTA(@t@NHcn)Is(F>> z^OM($ZSHIj)%CeXS5E-3!y^H zg`8?@W{L6#z-?GMbjN)b(Pk0f;2XLs8=@DHR4&d@q|f?6Wnm9*0qt%9C#=iR_6|ub zGMj#WKJ}q|W#(rob7;f2bUuOV{|nqw6PnJ(KhEyb#I`Zq=3KQoO{alW$EjQIBVNoV zT6KHdzT8*r>v^Yc<>J6lRbpB@UmO~qJ**&q(d#)Cat}f_5}}xE#=4q?>VCRoy`+Ec zJ%(w%{EfMADjjRj!AScJ{i7WNxm;KBkQ*P4Dxs}5CXhDpOgChP zimwY{@9lI?P(0b`%QSNDH#`;dWM7nYzSbV|o=0jaJSLNMo{J0<-Igb4lTpo74IGTe7w7`F=iU+J4LJVVsNy-eLetlJI^|I zXg%_3{BtRr?j5lWm+suKvb!36vopMw99755g|ACwPJDwQEWAE<}wM zVcNAF>oeFg++1y(h-2OOI@;47Hl6m4QCU0ZLq&hH+ZoJOJGqxIUgTd}gn| zPx3|fg{94kcm0EBm-8RvhI}-sJloKB?49; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/CarDeviceExecutionQueue.hbm.xml b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/CarDeviceExecutionQueue.hbm.xml new file mode 100644 index 0000000..ed3d44d --- /dev/null +++ b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/CarDeviceExecutionQueue.hbm.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/KzxcSsjMsg.hbm.xml b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/KzxcSsjMsg.hbm.xml new file mode 100644 index 0000000..2e9365d --- /dev/null +++ b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/KzxcSsjMsg.hbm.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + diff --git a/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/LineStatus.hbm.xml b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/LineStatus.hbm.xml new file mode 100644 index 0000000..b38f2a0 --- /dev/null +++ b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/LineStatus.hbm.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + diff --git a/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/RgvDeviceExecutionQueue.hbm.xml b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/RgvDeviceExecutionQueue.hbm.xml new file mode 100644 index 0000000..101d35a --- /dev/null +++ b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/RgvDeviceExecutionQueue.hbm.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/RgvDeviceExecutionQueueFinish.hbm.xml b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/RgvDeviceExecutionQueueFinish.hbm.xml new file mode 100644 index 0000000..ee20b4b --- /dev/null +++ b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/RgvDeviceExecutionQueueFinish.hbm.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/RgvMsg.hbm.xml b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/RgvMsg.hbm.xml new file mode 100644 index 0000000..423ecbd --- /dev/null +++ b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/RgvMsg.hbm.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + diff --git a/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/SsjMsg.hbm.xml b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/SsjMsg.hbm.xml new file mode 100644 index 0000000..776ea21 --- /dev/null +++ b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/SsjMsg.hbm.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/end.hbm.xml b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/end.hbm.xml new file mode 100644 index 0000000..c0509a1 --- /dev/null +++ b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/model/end.hbm.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/plc/备注.txt b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/plc/备注.txt new file mode 100644 index 0000000..fa6f9a1 --- /dev/null +++ b/out/production/ft503-wcs/com/wms/dss/ats/customs/abb/plc/备注.txt @@ -0,0 +1 @@ +ÓëPLCͨÐÅ,¶ÁÈ¡PLC±äÁ¿,±£´æÔÚÊý¾Ý¿âÖÐ \ No newline at end of file diff --git a/out/production/ft503-wcs/log4j.properties b/out/production/ft503-wcs/log4j.properties new file mode 100644 index 0000000..d14544e --- /dev/null +++ b/out/production/ft503-wcs/log4j.properties @@ -0,0 +1,41 @@ +# Configure logging for testing +# ???????INFO?debug Modbus.MAX_SERVER_ADDRESS); + } + } + + /** + * validates is the value in the range from min to max. + * + * @param value - the value for checkFrame + * @param min - minimum + * @param max - maximum + * @return "true" if value in the range from min to max, else "false". + */ + static private boolean checkRange(int value, int min, int max) { + return !(value < min || value > max); + } + + /** + * validates the value in the range from 1 to max. + * + * @param value - the value for checkFrame + * @param max - maximum + * @return "true" if value in the range from 1 to max, else "false". + */ + static private boolean checkQuantity(int value, int max) { + return checkRange(value, 1, max); + } + + /** + * validates data offset in the range from Modbus.MIN_START_ADDRESS to max. + * + * @param value - the offset for checkFrame + * @param max - maximum + * @return "true" if offset in the range from Modbus.MIN_START_ADDRESS to max, else "false". + */ + static private boolean checkStartAddress(int value, int max) { + return checkRange(value, MIN_START_ADDRESS, max); + } + + /** + * validates number of registers for read + * + * @param value - register count + * @return "true" if quantity is correct, else "false". + */ + static public boolean checkReadRegisterCount(int value) { + return checkQuantity(value, Modbus.MAX_READ_REGISTER_COUNT); + } + + /** + * validates number of registers for write + * + * @param value - register count + * @return "true" if quantity is correct, else "false". + */ + static public boolean checkWriteRegisterCount(int value) { + return checkQuantity(value, Modbus.MAX_WRITE_REGISTER_COUNT); + } + + /** + * validates number of coils for read + * + * @param value - coil count + * @return "true" if quantity is correct, else "false". + */ + static public boolean checkReadCoilCount(int value) { + return checkQuantity(value, Modbus.MAX_READ_COIL_COUNT); + } + + /** + * validates number of coils for write + * + * @param value - coil count + * @return "true" if quantity is correct, else "false". + */ + static public boolean checkWriteCoilCount(int value) { + return checkQuantity(value, Modbus.MAX_WRITE_COIL_COUNT); + } + + /** + * validates start address for read/write + * + * @param value - start address + * @return "true" if start address is correct, else "false". + */ + static public boolean checkStartAddress(int value) { + return checkStartAddress(value, Modbus.MAX_START_ADDRESS); + } + + /** + * validates end address for read/write + * end address = start address + quantity + * + * @param value - end address + * @return "true" if end address is correct, else "false". + */ + static public boolean checkEndAddress(int value) { + return checkStartAddress(value, Modbus.MAX_START_ADDRESS + 1); + } + + /** + * validates register value + * + * @param value - value of register + * @return "true" if register value is correct, else "false". + */ + static public boolean checkRegisterValue(int value) { + return checkRange((short)value, 0, Modbus.MAX_REGISTER_VALUE); + } + + /** + * returns autoIncrementTransactionId variable + * + * @return "true" if autoincrement of TransactionId field is enabled, else "false". + */ + public static boolean isAutoIncrementTransactionId() { + return Modbus.autoIncrementTransactionId; + } + + /** + * activates auto increment of TransactionId field. if you do not use ModbusTCP, invocation has no effect. + * + * @param autoIncrementTransactionId - new value of the autoIncrementTransactionId variable + */ + public static void setAutoIncrementTransactionId(boolean autoIncrementTransactionId) { + Modbus.autoIncrementTransactionId = autoIncrementTransactionId; + } + + /** + * logging.Level wrapper. + */ + public enum LogLevel { + LEVEL_RELEASE(Level.SEVERE), + LEVEL_WARNINGS(Level.WARNING), + LEVEL_VERBOSE(Level.INFO), + LEVEL_DEBUG(Level.ALL); + + final private Level value; + + LogLevel(Level value) { + this.value = value; + } + + /** + * getter + * + * @return logging.Level instance + */ + private Level value() { + return value; + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/Version.java b/src/com/intelligt/modbus/jlibmodbus/Version.java new file mode 100644 index 0000000..067be65 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/Version.java @@ -0,0 +1,42 @@ +package com.intelligt.modbus.jlibmodbus; +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +/** + * A class to keep the current version in. + * It's an auto generated class, which used by + * Modbus.getVersion(). + * + * @since 1.2.3 + */ +class Version { + + private static final String version = "1.2.9.7"; + /** + * returns the current version of the JLibModbus library + * + * @return a string representing the version + */ + public static String getVersion() { + return version; + } +} + \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/data/CommStatus.java b/src/com/intelligt/modbus/jlibmodbus/data/CommStatus.java new file mode 100644 index 0000000..016d400 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/CommStatus.java @@ -0,0 +1,304 @@ +package com.intelligt.modbus.jlibmodbus.data; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.comm.ModbusCommEvent; + +import java.util.LinkedList; +import java.util.List; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class CommStatus { + /** + * PDU length(254) - server_address - function_code - 3 x 2 Bytes + */ + public static final int EVENT_QUEUE_CAPACITY = Modbus.MAX_PDU_LENGTH - 8; + /** + * When the remote device enters its Listen Only Mode, all active communication controls are + * turned off. The Ready watchdog timer is allowed to expire, locking the controls off. While the + * device is in this mode, any MODBUS messages addressed to it or broadcast are monitored, + * but no actions will be taken and no responses will be sent. + */ + private boolean listenOnlyMode = false; + + volatile private boolean restartCommunicationsOption = false; + + volatile private boolean clearLog = false; + /** + * + */ + private int diagnosticRegister = 0; + /** + * the status word will be all ones (FF FF hex) if a previously–issued program command is still being + * processed by the remote device (a busy condition exists). Otherwise, the status word will be all zeros. + */ + private int commStatus = 0; + /** + * event counter is incremented once for each successful message completion. It + * is not incremented for exception responses, poll commands, or fetch event counter + * commands. + */ + private int eventCount = 0; + /** + * the quantity of messages that the remote device has detected + * on the communications system since its last restart + */ + private int busMessageCount = 0; + /** + * the quantity of messages addressed to the remote device, or + * broadcast, that the remote device has processed since its last restart + */ + private int slaveMessageCount = 0; + /** + * the quantity of CRC errors encountered by the remote device since its last restart + */ + private int communicationErrorCount = 0; + /** + * the quantity of MODBUS exception responses returned by the remote device since its last restart + */ + private int exceptionErrorCount = 0; + /** + * the quantity of messages addressed to the remote device for + * which it has returned no response (neither a normal response nor an exception response), + * since its last restart + */ + private int slaveNoResponseCount = 0; + /** + * the quantity of messages addressed to the remote device for + * which it returned a Negative Acknowledge (NAK) exception response, since its last restart + */ + private int slaveNAKCount = 0; + /** + * the quantity of messages addressed to the remote device for + * which it returned a Slave Device Busy exception response, since its last restart + */ + private int slaveBusyCount = 0; + /** + * the quantity of messages addressed to the remote device that + * it could not handle due to a character overrun condition, since its last restart + */ + private int characterOverrunCount = 0; + /** + * Comm event queue. Capacity = PDU length(254) - server_address - function_code - 3 x 2 Bytes, + * (Length of Status, Event Count and Message Count). + */ + final private LinkedList eventQueue = new LinkedList(); + + public CommStatus() { + } + + public void enter() { + commStatus = 0xffff; + } + + public void leave() { + commStatus = 0; + } + + public void incEventCounter() { + eventCount++; + } + + public void incBusMessageCounter() { + busMessageCount++; + } + + public void incSlaveMessageCounter() { + slaveMessageCount++; + } + + public void incCommErrorCounter() { + communicationErrorCount++; + } + + public void incExErrorCounter() { + exceptionErrorCount++; + } + + public void incNoResponseCounter() { + exceptionErrorCount++; + } + + public void incSlaveNAKCounter() { + exceptionErrorCount++; + } + + public void incSlaveBusyCounter() { + exceptionErrorCount++; + } + + public void incCharacterOverrunCounter() { + exceptionErrorCount++; + } + + public int getCommStatus() { + return commStatus; + } + + public void setCommStatus(int commStatus) { + this.commStatus = commStatus; + } + + public int getEventCount() { + return eventCount; + } + + public void setEventCount(int eventCount) { + this.eventCount = eventCount; + } + + public int getMessageCount() { + return busMessageCount; + } + + public void setBusMessageCount(int busMessageCount) { + this.busMessageCount = busMessageCount; + } + + public int getSlaveMessageCount() { + return slaveMessageCount; + } + + public void setSlaveMessageCount(int slaveMessageCount) { + this.slaveMessageCount = slaveMessageCount; + } + + public int getCommunicationErrorCount() { + return communicationErrorCount; + } + + public void setCommunicationErrorCount(int communicationErrorCount) { + this.communicationErrorCount = communicationErrorCount; + } + + public int getExceptionErrorCount() { + return exceptionErrorCount; + } + + public void setExceptionErrorCount(int exceptionErrorCount) { + this.exceptionErrorCount = exceptionErrorCount; + } + + public int getSlaveNoResponseCount() { + return slaveNoResponseCount; + } + + public void setSlaveNoResponseCount(int slaveNoResponseCount) { + this.slaveNoResponseCount = slaveNoResponseCount; + } + + public int getSlaveNAKCount() { + return slaveNAKCount; + } + + public void setSlaveNAKCount(int slaveNAKCount) { + this.slaveNAKCount = slaveNAKCount; + } + + public int getSlaveBusyCount() { + return slaveBusyCount; + } + + public void setSlaveBusyCount(int slaveBusyCount) { + this.slaveBusyCount = slaveBusyCount; + } + + public int getCharacterOverrunCount() { + return characterOverrunCount; + } + + public void setCharacterOverrunCount(int characterOverrunCount) { + this.characterOverrunCount = characterOverrunCount; + } + + public int getDiagnosticRegister() { + return diagnosticRegister; + } + + public void setDiagnosticRegister(int diagnosticRegister) { + this.diagnosticRegister = diagnosticRegister; + } + + public void setAsciiInputDelimiter(int asciiInputDelimiter) { + Modbus.setAsciiInputDelimiter(asciiInputDelimiter); + } + + public boolean isListenOnlyMode() { + return listenOnlyMode; + } + + public void setListenOnlyMode(boolean listenOnlyMode) { + this.listenOnlyMode = listenOnlyMode; + } + + public boolean isRestartCommunicationsOption() { + return restartCommunicationsOption; + } + + public void setRestartCommunicationsOption(boolean restartCommunications) { + this.restartCommunicationsOption = restartCommunications; + } + + public boolean isClearLog() { + return clearLog; + } + + public void setClearLog(boolean clearLog) { + this.clearLog = clearLog; + } + + public void clearCountersAndDiagnosticRegister() { + setBusMessageCount(0); + setEventCount(0); + setCharacterOverrunCount(0); + setCommunicationErrorCount(0); + setExceptionErrorCount(0); + setSlaveNoResponseCount(0); + setSlaveBusyCount(0); + setSlaveMessageCount(0); + setSlaveNAKCount(0); + } + + public void restartCommunicationsOption() { + clearCountersAndDiagnosticRegister(); + setListenOnlyMode(false); + if (isClearLog()) { + getEventLog().clear(); + setClearLog(false); + } + } + + public List getEventLog() { + return eventQueue; + } + + public void setEventQueue(List eventQueue) { + this.eventQueue.clear(); + this.eventQueue.addAll(eventQueue); + } + + public void addEvent(ModbusCommEvent event) { + if (eventQueue.size() >= EVENT_QUEUE_CAPACITY) + eventQueue.poll(); + eventQueue.add(event); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/DataHolder.java b/src/com/intelligt/modbus/jlibmodbus/data/DataHolder.java new file mode 100644 index 0000000..d73336a --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/DataHolder.java @@ -0,0 +1,215 @@ +package com.intelligt.modbus.jlibmodbus.data; + +import com.intelligt.modbus.jlibmodbus.data.mei.ReadDeviceIdentificationInterface; +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataAddressException; +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataValueException; +import com.intelligt.modbus.jlibmodbus.exception.IllegalFunctionException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusFileRecord; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.util.Map; +import java.util.TreeMap; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/* +facade + */ +public class DataHolder { + final private CommStatus commStatus = new CommStatus(); + final private Map fifoMap = new TreeMap(); + final private Map fileMap = new TreeMap(); + private ModbusCoils coils = null; + private ModbusCoils discreteInputs = null; + private ModbusHoldingRegisters holdingRegisters = null; + private ModbusHoldingRegisters inputRegisters = null; + private SlaveId slaveId = null; + private ExceptionStatus exceptionStatus = null; + private ReadDeviceIdentificationInterface readDeviceIdentificationInterface = null; + + private void checkPointer(Object o, int offset) throws IllegalDataAddressException { + if (o == null) + throw new IllegalDataAddressException(offset); + } + + public int readHoldingRegister(int offset) throws IllegalDataAddressException { + checkPointer(holdingRegisters, offset); + return holdingRegisters.get(offset); + } + + public int[] readHoldingRegisterRange(int offset, int quantity) throws IllegalDataAddressException { + checkPointer(holdingRegisters, offset); + return holdingRegisters.getRange(offset, quantity); + } + + public void writeHoldingRegister(int offset, int value) throws IllegalDataAddressException, IllegalDataValueException { + checkPointer(holdingRegisters, offset); + holdingRegisters.set(offset, value); + } + + public void writeHoldingRegisterRange(int offset, int[] range) throws IllegalDataAddressException, IllegalDataValueException { + checkPointer(holdingRegisters, offset); + holdingRegisters.setRange(offset, range); + } + + public int[] readInputRegisterRange(int offset, int quantity) throws IllegalDataAddressException { + checkPointer(inputRegisters, offset); + return inputRegisters.getRange(offset, quantity); + } + + public int[] readFifoQueue(int fifoPointerAddress) throws IllegalDataValueException, IllegalDataAddressException { + FifoQueue fifoQueue = fifoMap.get(fifoPointerAddress); + checkPointer(fifoQueue, fifoPointerAddress); + return fifoQueue.get(); + } + + public boolean[] readCoilRange(int offset, int quantity) throws IllegalDataAddressException, IllegalDataValueException { + checkPointer(coils, offset); + return coils.getRange(offset, quantity); + } + + public void writeCoil(int offset, boolean value) throws IllegalDataAddressException, IllegalDataValueException { + checkPointer(coils, offset); + coils.set(offset, value); + } + + public void writeCoilRange(int offset, boolean[] range) throws IllegalDataAddressException, IllegalDataValueException { + checkPointer(coils, offset); + coils.setRange(offset, range); + } + + public byte[] readSlaveId() throws IllegalFunctionException { + if (slaveId == null) + throw new IllegalFunctionException(ModbusFunctionCode.REPORT_SLAVE_ID.toInt()); + return slaveId.get(); + } + + public int readExceptionStatus() throws IllegalFunctionException { + if (exceptionStatus == null) + throw new IllegalFunctionException(ModbusFunctionCode.READ_EXCEPTION_STATUS.toInt()); + return exceptionStatus.get(); + } + + public boolean[] readDiscreteInputRange(int offset, int quantity) throws IllegalDataAddressException, IllegalDataValueException { + checkPointer(discreteInputs, offset); + return discreteInputs.getRange(offset, quantity); + } + + public void readFileRecord(ModbusFileRecord fileRecord) throws IllegalDataAddressException, IllegalDataValueException { + ModbusFile file = getFile(fileRecord.getFileNumber()); + checkPointer(file, fileRecord.getFileNumber()); + fileRecord.writeRegisters(file.read(fileRecord.getRecordNumber(), fileRecord.getRecordLength())); + } + + public void writeFileRecord(ModbusFileRecord fileRecord) throws IllegalDataAddressException, IllegalDataValueException { + ModbusFile file = getFile(fileRecord.getFileNumber()); + checkPointer(file, fileRecord.getFileNumber()); + file.write(fileRecord.getRecordNumber(), fileRecord.getRegisters()); + } + + public ModbusCoils getCoils() { + return coils; + } + + public void setCoils(ModbusCoils coils) { + this.coils = coils; + } + + public ModbusCoils getDiscreteInputs() { + return discreteInputs; + } + + public void setDiscreteInputs(ModbusCoils discreteInputs) { + this.discreteInputs = discreteInputs; + } + + public ModbusHoldingRegisters getHoldingRegisters() { + return holdingRegisters; + } + + public void setHoldingRegisters(ModbusHoldingRegisters holdingRegisters) { + this.holdingRegisters = holdingRegisters; + } + + public ModbusHoldingRegisters getInputRegisters() { + return inputRegisters; + } + + public void setInputRegisters(ModbusHoldingRegisters inputRegisters) { + this.inputRegisters = inputRegisters; + } + + public CommStatus getCommStatus() { + return commStatus; + } + + public SlaveId getSlaveId() { + return slaveId; + } + + public void setSlaveId(SlaveId slaveId) { + this.slaveId = slaveId; + } + + public ExceptionStatus getExceptionStatus() { + return exceptionStatus; + } + + public void setExceptionStatus(ExceptionStatus exceptionStatus) { + this.exceptionStatus = exceptionStatus; + } + + public FifoQueue getFifoQueue(int fifoPointerAddress) throws IllegalDataAddressException { + FifoQueue file = fifoMap.get(fifoPointerAddress); + if (file == null) + throw new IllegalDataAddressException(fifoPointerAddress); + return file; + } + + public void addFifoQueue(FifoQueue fifoQueue, int fifoPointerAddress) throws IllegalDataAddressException { + if (fifoMap.containsKey(fifoPointerAddress)) + throw new IllegalDataAddressException(fifoPointerAddress); + fifoMap.put(fifoPointerAddress, fifoQueue); + } + + public void addFile(ModbusFile file) throws IllegalDataAddressException { + if (fileMap.containsKey(file.getNumber())) + throw new IllegalDataAddressException(file.getNumber()); + fileMap.put(file.getNumber(), file); + } + + public ModbusFile getFile(int number) throws IllegalDataAddressException { + ModbusFile file = fileMap.get(number); + if (file == null) + throw new IllegalDataAddressException(number); + return file; + } + + public ReadDeviceIdentificationInterface getReadDeviceIdentificationInterface() { + return readDeviceIdentificationInterface; + } + + public void setReadDeviceIdentificationInterface(ReadDeviceIdentificationInterface readDeviceIdentificationInterface) { + this.readDeviceIdentificationInterface = readDeviceIdentificationInterface; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/DataHolderBuilder.java b/src/com/intelligt/modbus/jlibmodbus/data/DataHolderBuilder.java new file mode 100644 index 0000000..4c844dd --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/DataHolderBuilder.java @@ -0,0 +1,67 @@ +package com.intelligt.modbus.jlibmodbus.data; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +abstract public class DataHolderBuilder { + protected DataHolder dataHolder; + + protected DataHolderBuilder() { + createNewDataHolder(); + } + + public DataHolder getDataHolder() { + return dataHolder; + } + + final public void createNewDataHolder() { + dataHolder = new DataHolder(); + } + + public abstract void buildCoils(); + + public abstract void buildDiscreteInputs(); + + public abstract void buildHoldingRegisters(); + + public abstract void buildInputRegisters(); + + public abstract void buildSlaveId(); + + public abstract void buildExceptionStatus(); + + public abstract void buildFifoQueue(); + + public abstract void readDeviceIdentificationInterface(); + + final public DataHolder build() { + createNewDataHolder(); + buildCoils(); + buildDiscreteInputs(); + buildHoldingRegisters(); + buildInputRegisters(); + buildSlaveId(); + buildExceptionStatus(); + buildFifoQueue(); + readDeviceIdentificationInterface(); + return getDataHolder(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/ExceptionStatus.java b/src/com/intelligt/modbus/jlibmodbus/data/ExceptionStatus.java new file mode 100644 index 0000000..ac0a6eb --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/ExceptionStatus.java @@ -0,0 +1,28 @@ +package com.intelligt.modbus.jlibmodbus.data; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public interface ExceptionStatus { + int get(); + + void set(int exceptionStatus); +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/FifoQueue.java b/src/com/intelligt/modbus/jlibmodbus/data/FifoQueue.java new file mode 100644 index 0000000..f94907a --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/FifoQueue.java @@ -0,0 +1,58 @@ +package com.intelligt.modbus.jlibmodbus.data; + +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataValueException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +abstract public class FifoQueue { + + final private int capacity; + + public FifoQueue(int capacity) { + this.capacity = capacity; + } + + public abstract int size(); + + abstract protected int[] peekImpl(); + + abstract protected void addImpl(int register); + + abstract protected void pollImpl(); + + synchronized final public void poll() { + if (size() != 0) + pollImpl(); + } + + synchronized final public void add(int register) { + if (size() < capacity) + addImpl(register); + } + + synchronized final public int[] get() throws IllegalDataValueException { + if (size() > 31 || size() == 0) { + throw new IllegalDataValueException(); + } + return peekImpl(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/ModbusCoils.java b/src/com/intelligt/modbus/jlibmodbus/data/ModbusCoils.java new file mode 100644 index 0000000..b7fe32d --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/ModbusCoils.java @@ -0,0 +1,124 @@ +package com.intelligt.modbus.jlibmodbus.data; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataAddressException; +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataValueException; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; + +import java.util.Arrays; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * since 1.2.8.4 it extends Observable to notify observers if register values was changed. + * + * @see java.util.Observable + * @see java.util.Observer + */ +public class ModbusCoils extends ModbusValues { + private boolean[] coils = new boolean[0]; + + public ModbusCoils(int size) { + this.coils = new boolean[Modbus.checkEndAddress(size) ? size : Modbus.MAX_START_ADDRESS]; + } + + public ModbusCoils(byte[] bytes) { + coils = DataUtils.toBitsArray(bytes, bytes.length*8); + } + + @Override + public byte[] getBytes() { + return DataUtils.toByteArray(coils); + } + + @Override + public void setBytesBe(byte[] bytes) { + coils = DataUtils.toBitsArray(bytes, bytes.length*8); + } + + public void setBytes(byte[] bytes, int quantity) { + coils = DataUtils.toBitsArray(bytes, quantity); + } + + void setSize(int size) { + if (coils.length != size) { + coils = Arrays.copyOf(coils, size); + } + } + + @Override + public void setImpl(int offset, Boolean coil) throws IllegalDataAddressException, IllegalDataValueException { + checkAddress(offset); + synchronized (this) { + coils[offset] = coil; + } + } + + public void setRange(int offset, boolean[] range) throws IllegalDataAddressException, IllegalDataValueException { + checkRange(offset, range.length); + if (!Modbus.checkWriteCoilCount(range.length)) + throw new IllegalDataValueException(); + synchronized (this) { + for (int i = 0; i < range.length; i++) { + set(offset + i, range[i]); + } + } + } + + public boolean[] getRange(int offset, int quantity) throws IllegalDataAddressException, IllegalDataValueException { + checkRange(offset, quantity); + if (!Modbus.checkReadCoilCount(quantity)) + throw new IllegalDataValueException(); + synchronized (this) { + return Arrays.copyOfRange(coils, offset, offset + quantity); + } + } + + @Override + synchronized public int getQuantity() { + return coils.length; + } + + @Override + synchronized public int getByteCount() { + return (int)Math.ceil((double)coils.length/8); + } + + @Override + public Boolean get(int offset) throws IllegalDataAddressException { + checkAddress(offset); + synchronized (this) { + return coils[offset]; + } + } + + private void checkRange(int offset, int quantity) throws IllegalDataAddressException { + if (offset + quantity > getQuantity()) + throw new IllegalDataAddressException(offset); + } + + private void checkAddress(int offset) throws IllegalDataAddressException { + if (!Modbus.checkStartAddress(offset)) + throw new IllegalDataAddressException(offset); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/ModbusFile.java b/src/com/intelligt/modbus/jlibmodbus/data/ModbusFile.java new file mode 100644 index 0000000..a025576 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/ModbusFile.java @@ -0,0 +1,65 @@ +package com.intelligt.modbus.jlibmodbus.data; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataAddressException; +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataValueException; + +import java.util.Observable; + +/** + * quote from MODBUS Application Protocol Specification V1.1b + *

+ * "A file is an organization of records. Each file contains 10000 records, addressed 0000 to + * 9999 decimal or 0X0000 to 0X270F. For example, record 12 is addressed as 12. + * ... + * The quantity of registers to be read, combined with all other fields in the expected response, + * must not exceed the allowable length of the MODBUS PDU : 253 bytes." + *

+ * so the length of file record must not exceed 250 bytes(253 - function_code - resp_data_len - sub_req_resp_len). + */ +abstract public class ModbusFile extends Observable { + private final int number; + + public ModbusFile(int number) { + this.number = number; + } + + /** + * read modbus file record + * + * @param recordNumber number of a record + * @param recordLength read register count + * @return record data + * @throws IllegalDataAddressException record with number recordNumber not exist or recordLength bytes not allowable. + */ + abstract public int[] read(int recordNumber, int recordLength) throws IllegalDataAddressException; + + public void write(int recordNumber, int[] buffer) throws IllegalDataAddressException, IllegalDataValueException { + notifyObservers(new int[]{recordNumber, buffer.length}); + } + + public int getNumber() { + return number; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/ModbusHoldingRegisters.java b/src/com/intelligt/modbus/jlibmodbus/data/ModbusHoldingRegisters.java new file mode 100644 index 0000000..f3c3e7e --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/ModbusHoldingRegisters.java @@ -0,0 +1,199 @@ +package com.intelligt.modbus.jlibmodbus.data; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataAddressException; +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataValueException; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; + +import java.util.Arrays; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * since 1.2.8.4 it extends Observable to notify observers if register values was changed. + * + * @see java.util.Observable + * @see java.util.Observer + */ +public class ModbusHoldingRegisters extends ModbusValues { + + private int[] registers = new int[0]; + + public ModbusHoldingRegisters(int size) { + registers = new int[(Modbus.checkEndAddress(size) ? size : Modbus.MAX_START_ADDRESS)]; + } + + public ModbusHoldingRegisters() { + + } + + void setSize(int size) { + synchronized (this) { + if (registers.length != size) { + registers = Arrays.copyOf(registers, size); + } + } + } + + protected void checkOffsetAndValue(int offset, int value) throws IllegalDataValueException, IllegalDataAddressException { + checkAddress(offset); + checkValue(value); + } + + @Override + public void setImpl(int offset, Integer value) throws IllegalDataAddressException, IllegalDataValueException { + checkAddress(offset); + checkValue(value); + synchronized (this) { + registers[offset] = value; + } + } + + public void setRange(int offset, int[] range) throws IllegalDataAddressException, IllegalDataValueException { + checkRange(offset, range.length); + if (!Modbus.checkWriteRegisterCount(range.length)) + throw new IllegalDataAddressException(offset); + synchronized (this) { + for (int i = 0; i < range.length; i++) { + set(offset + i, range[i]); + } + } + } + + public void setInt8At(int offset, int i8) throws IllegalDataAddressException, IllegalDataValueException { + checkOffsetAndValue(offset, i8); + set(offset, (int) DataUtils.byteLow(i8)); + } + + public void setInt16At(int offset, int i16) throws IllegalDataAddressException, IllegalDataValueException { + checkOffsetAndValue(offset, i16); + set(offset, i16); + } + + public void setInt32At(int offset, int i32) throws IllegalDataAddressException, IllegalDataValueException { + setInt16At(offset, DataUtils.wordLow(i32)); + setInt16At(offset + 1, DataUtils.wordHigh(i32)); + } + + public void setInt64At(int offset, long i64) throws IllegalDataAddressException, IllegalDataValueException { + setInt32At(offset, (int) (i64 & 0xffffffff)); + setInt32At(offset + 2, (int) ((i64 >> 32) & 0xffffffff)); + } + + public void setFloat32At(int offset, float f32) throws IllegalDataAddressException, IllegalDataValueException { + setInt32At(offset, Float.floatToRawIntBits(f32)); + } + + public void setFloat64At(int offset, double f64) throws IllegalDataAddressException, IllegalDataValueException { + setInt64At(offset, Double.doubleToRawLongBits(f64)); + } + + public int getInt8At(int offset) throws IllegalDataAddressException { + checkAddress(offset); + return DataUtils.byteLow(get(offset)); + } + + public int getInt16At(int offset) throws IllegalDataAddressException { + return get(offset); + } + + public int getInt32At(int offset) throws IllegalDataAddressException { + return (getInt16At(offset)&0xffff) | ((getInt16At(offset + 1)&0xffff) << 16); + } + + public long getInt64At(int offset) throws IllegalDataAddressException { + return (getInt32At(offset)&0xffffffffL) | ((getInt32At(offset + 2)&0xffffffffL) << 32); + } + + public float getFloat32At(int offset) throws IllegalDataAddressException { + return Float.intBitsToFloat(getInt32At(offset)); + } + + public double getFloat64At(int offset) throws IllegalDataAddressException { + return Double.longBitsToDouble(getInt64At(offset)); + } + + public int[] getRegisters() { + return Arrays.copyOf(registers, getQuantity()); + } + + public void setRegisters(int[] registers) { + this.registers = Arrays.copyOf(registers, registers.length); + } + + @Override + synchronized public int getByteCount() { + return getQuantity() * 2; + } + + @Override + public byte[] getBytes() { + return DataUtils.toByteArray(registers); + } + + @Override + public void setBytesBe(byte[] bytes) { + registers = DataUtils.BeToIntArray(bytes); + } + + public void setBytesLe(byte[] bytes) { + this.registers = DataUtils.LeToIntArray(bytes); + } + + @Override + synchronized public int getQuantity() { + return registers.length; + } + + @Override + public Integer get(int offset) throws IllegalDataAddressException { + checkAddress(offset); + synchronized (this) { + return registers[offset]; + } + } + + public int[] getRange(int offset, int quantity) throws IllegalDataAddressException { + checkRange(offset, quantity); + if (!Modbus.checkReadRegisterCount(quantity)) + throw new IllegalDataAddressException(offset); + synchronized (this) { + return Arrays.copyOfRange(registers, offset, offset + quantity); + } + } + + private void checkRange(int offset, int quantity) throws IllegalDataAddressException { + if (offset + quantity > getQuantity()) + throw new IllegalDataAddressException(offset); + } + + private void checkAddress(int offset) throws IllegalDataAddressException { + if (DataUtils.wordLow(offset) > (getQuantity() - 1)) + throw new IllegalDataAddressException(offset); + } + + private void checkValue(int value) throws IllegalDataValueException { + if (!Modbus.checkRegisterValue(value)) + throw new IllegalDataValueException(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/ModbusValues.java b/src/com/intelligt/modbus/jlibmodbus/data/ModbusValues.java new file mode 100644 index 0000000..c14fe52 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/ModbusValues.java @@ -0,0 +1,62 @@ +package com.intelligt.modbus.jlibmodbus.data; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataAddressException; +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataValueException; + +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.Observable; + +abstract public class ModbusValues extends Observable implements Iterable { + + abstract public int getQuantity(); + + abstract public T get(int offset) throws IllegalDataAddressException; + + abstract public void setImpl(int offset, T value) throws IllegalDataAddressException, IllegalDataValueException; + + abstract public int getByteCount(); + + abstract public byte[] getBytes(); + + abstract public void setBytesBe(byte[] bytes); + + final public void set(int offset, T value) throws IllegalDataAddressException, IllegalDataValueException { + setImpl(offset, value); + setChanged(); + notifyObservers(new int[]{offset, 1}); + } + + @Override + public Iterator iterator() { + return new Iterator() { + + int index = 0; + + @Override + public boolean hasNext() { + return index < getQuantity(); + } + + @Override + public T next() { + if (hasNext()) { + try { + return get(index++); + } catch (IllegalDataAddressException e) { + Modbus.log().severe(this.getClass().getSimpleName() + " " + e.getLocalizedMessage() + ": quantity = " + getQuantity() + ", index = " + index); + throw new NoSuchElementException(); + } + } else { + throw new NoSuchElementException(); + } + } + + @Override + public void remove() { + + } + }; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/SimpleDataHolderBuilder.java b/src/com/intelligt/modbus/jlibmodbus/data/SimpleDataHolderBuilder.java new file mode 100644 index 0000000..650ae20 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/SimpleDataHolderBuilder.java @@ -0,0 +1,95 @@ +package com.intelligt.modbus.jlibmodbus.data; + +import com.intelligt.modbus.jlibmodbus.data.mei.ReadDeviceIdentificationInterface; +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataAddressException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class SimpleDataHolderBuilder extends DataHolderBuilder { + final private int coilCount; + final private int discreteInputCount; + final private int holdingRegisterCount; + final private int inputRegisterCount; + final private int slaveIdSize; + + public SimpleDataHolderBuilder(int size) { + coilCount = discreteInputCount = holdingRegisterCount = inputRegisterCount = slaveIdSize = size; + } + + public SimpleDataHolderBuilder(int slaveIdSize, int inputRegisterCount, int holdingRegisterCount, int discreteInputCount, int coilCount) { + this.slaveIdSize = slaveIdSize; + this.inputRegisterCount = inputRegisterCount; + this.holdingRegisterCount = holdingRegisterCount; + this.discreteInputCount = discreteInputCount; + this.coilCount = coilCount; + } + + public DataHolder getDataHolder() { + return dataHolder; + } + + @Override + public void buildCoils() { + dataHolder.setCoils(new ModbusCoils(coilCount)); + } + + @Override + public void buildDiscreteInputs() { + dataHolder.setDiscreteInputs(new ModbusCoils(discreteInputCount)); + + } + + @Override + public void buildHoldingRegisters() { + dataHolder.setHoldingRegisters(new ModbusHoldingRegisters(holdingRegisterCount)); + } + + @Override + public void buildInputRegisters() { + dataHolder.setInputRegisters(new ModbusHoldingRegisters(inputRegisterCount)); + } + + @Override + public void buildSlaveId() { + dataHolder.setSlaveId(new SimpleSlaveId(slaveIdSize)); + } + + @Override + public void buildExceptionStatus() { + dataHolder.setExceptionStatus(new SimpleExceptionStatus(0)); + } + + @Override + public void buildFifoQueue() { + try { + dataHolder.addFifoQueue(new SimpleFifoQueue(), 0); + } catch (IllegalDataAddressException e) { + //it newer be thrown + e.printStackTrace(); + } + } + + @Override + public void readDeviceIdentificationInterface() { + dataHolder.setReadDeviceIdentificationInterface(new ReadDeviceIdentificationInterface()); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/SimpleExceptionStatus.java b/src/com/intelligt/modbus/jlibmodbus/data/SimpleExceptionStatus.java new file mode 100644 index 0000000..8494616 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/SimpleExceptionStatus.java @@ -0,0 +1,45 @@ +package com.intelligt.modbus.jlibmodbus.data; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class SimpleExceptionStatus implements ExceptionStatus { + + int value; + + public SimpleExceptionStatus() { + this(0); + } + + public SimpleExceptionStatus(int value) { + set(value); + } + + @Override + synchronized public int get() { + return value; + } + + @Override + synchronized public void set(int value) { + this.value = value; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/SimpleFifoQueue.java b/src/com/intelligt/modbus/jlibmodbus/data/SimpleFifoQueue.java new file mode 100644 index 0000000..5518d11 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/SimpleFifoQueue.java @@ -0,0 +1,65 @@ +package com.intelligt.modbus.jlibmodbus.data; + +import com.intelligt.modbus.jlibmodbus.Modbus; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Queue; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class SimpleFifoQueue extends FifoQueue { + + final private Queue queue = new LinkedList(); + + public SimpleFifoQueue() { + super(Modbus.MAX_FIFO_COUNT); + } + + @Override + public int size() { + return queue.size(); + } + + @Override + protected int[] peekImpl() { + if (queue.size() > 0) { + int[] r = new int[queue.size()]; + Iterator iterator = queue.iterator(); + for (int i = 0; i < r.length && iterator.hasNext(); i++) { + r[i] = iterator.next(); + } + return r; + } + return new int[0]; + } + + @Override + protected void addImpl(int register) { + queue.add(register); + } + + @Override + protected void pollImpl() { + queue.poll(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/SimpleModbusFile.java b/src/com/intelligt/modbus/jlibmodbus/data/SimpleModbusFile.java new file mode 100644 index 0000000..77b893d --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/SimpleModbusFile.java @@ -0,0 +1,59 @@ +package com.intelligt.modbus.jlibmodbus.data; + +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataAddressException; +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataValueException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusFileRecord; + +import java.util.Arrays; +import java.util.Map; +import java.util.TreeMap; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class SimpleModbusFile extends ModbusFile { + + final private Map records = new TreeMap(); + + public SimpleModbusFile(int number) { + super(number); + } + + @Override + synchronized public int[] read(int recordNumber, int recordLength) throws IllegalDataAddressException { + if (!records.containsKey(recordNumber)) + throw new IllegalDataAddressException(recordNumber); + int[] buffer = records.get(recordNumber).getRegisters(); + if (buffer.length < recordLength) + throw new IllegalDataAddressException(recordLength); + return Arrays.copyOf(buffer, recordLength); + } + + @Override + synchronized public void write(int recordNumber, int[] buffer) throws IllegalDataAddressException, IllegalDataValueException { + if (records.containsKey(recordNumber)) { + records.get(recordNumber).writeRegisters(buffer); + } else { + records.put(recordNumber, new ModbusFileRecord(getNumber(), recordNumber, buffer)); + } + super.write(recordNumber, buffer); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/SimpleSlaveId.java b/src/com/intelligt/modbus/jlibmodbus/data/SimpleSlaveId.java new file mode 100644 index 0000000..d0d78fd --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/SimpleSlaveId.java @@ -0,0 +1,43 @@ +package com.intelligt.modbus.jlibmodbus.data; + +import java.util.Arrays; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class SimpleSlaveId implements SlaveId { + + private byte[] bytes = null; + + public SimpleSlaveId(int size) { + bytes = new byte[size]; + } + + @Override + synchronized public byte[] get() { + return Arrays.copyOf(bytes, bytes.length); + } + + @Override + synchronized public void set(byte[] data) { + bytes = Arrays.copyOf(data, data.length); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/SlaveId.java b/src/com/intelligt/modbus/jlibmodbus/data/SlaveId.java new file mode 100644 index 0000000..bfa5edc --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/SlaveId.java @@ -0,0 +1,28 @@ +package com.intelligt.modbus.jlibmodbus.data; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public interface SlaveId { + byte[] get(); + + void set(byte[] data); +} diff --git a/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEvent.java b/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEvent.java new file mode 100644 index 0000000..920f8b7 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEvent.java @@ -0,0 +1,80 @@ +package com.intelligt.modbus.jlibmodbus.data.comm; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +abstract public class ModbusCommEvent { + + final private Type type; + private int event = 0; + + public ModbusCommEvent(Type type, int event) { + this.type = type; + this.event = type.getCode() | event; + } + + static public ModbusCommEvent getEvent(int event) { + for (Type t : Type.values()) { + if ((t.getCode() & event) == t.getCode()) { + switch (t) { + case SEND: + return new ModbusCommEventSend(event); + case RECEIVE: + return new ModbusCommEventReceive(event); + case INITIATED_COMMUNICATION_RESTART: + return new ModbusCommEventInitiatedCommunicationRestart(event); + case ENTER_LISTEN_ONLY_MODE: + return new ModbusCommEventEnterListenOnlyMode(event); + } + } + } + throw new IllegalArgumentException(); + } + + public Type getType() { + return type; + } + + protected boolean isBitsSet(int bits) { + return (event & bits) == bits; + } + + public int getEvent() { + return event; + } + + public enum Type { + SEND(0x80), + RECEIVE(0x40), + INITIATED_COMMUNICATION_RESTART(0x0), + ENTER_LISTEN_ONLY_MODE(0x10); + + final private int code; + + Type(int code) { + this.code = code; + } + + public int getCode() { + return code; + } + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventEnterListenOnlyMode.java b/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventEnterListenOnlyMode.java new file mode 100644 index 0000000..db919c0 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventEnterListenOnlyMode.java @@ -0,0 +1,32 @@ +package com.intelligt.modbus.jlibmodbus.data.comm; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusCommEventEnterListenOnlyMode extends ModbusCommEvent { + public ModbusCommEventEnterListenOnlyMode() { + super(Type.ENTER_LISTEN_ONLY_MODE, 0); + } + + public ModbusCommEventEnterListenOnlyMode(int event) { + super(Type.ENTER_LISTEN_ONLY_MODE, event); + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventInitiatedCommunicationRestart.java b/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventInitiatedCommunicationRestart.java new file mode 100644 index 0000000..5be044d --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventInitiatedCommunicationRestart.java @@ -0,0 +1,33 @@ +package com.intelligt.modbus.jlibmodbus.data.comm; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusCommEventInitiatedCommunicationRestart extends ModbusCommEvent { + + public ModbusCommEventInitiatedCommunicationRestart() { + this(0); + } + + protected ModbusCommEventInitiatedCommunicationRestart(int event) { + super(Type.INITIATED_COMMUNICATION_RESTART, event); + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventReceive.java b/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventReceive.java new file mode 100644 index 0000000..143eee6 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventReceive.java @@ -0,0 +1,65 @@ +package com.intelligt.modbus.jlibmodbus.data.comm; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusCommEventReceive extends ModbusCommEvent { + final static private int BIT_COMMUNICATION_ERROR = 0x1; + final static private int BIT_CHARACTER_OVERRUN = 0x10; + final static private int BIT_CURRENTLY_IN_LISTEN_ONLY_MODE = 0x20; + final static private int BIT_BROADCAST_RECEIVED = 0x40; + + protected ModbusCommEventReceive(int event) { + super(Type.RECEIVE, event); + } + + static public ModbusCommEventReceive createCommunicationError() { + return new ModbusCommEventReceive(BIT_COMMUNICATION_ERROR); + } + + static public ModbusCommEventReceive createCharacterOverrun() { + return new ModbusCommEventReceive(BIT_CHARACTER_OVERRUN); + } + + static public ModbusCommEventReceive createCurrentlyInListenOnlyMode() { + return new ModbusCommEventReceive(BIT_CURRENTLY_IN_LISTEN_ONLY_MODE); + } + + static public ModbusCommEventReceive createBroadcastReceived() { + return new ModbusCommEventReceive(BIT_BROADCAST_RECEIVED); + } + + public boolean isCurrentlyInListenOnlyMode() { + return isBitsSet(BIT_CURRENTLY_IN_LISTEN_ONLY_MODE); + } + + public boolean isCharacterOverrun() { + return isBitsSet(BIT_CHARACTER_OVERRUN); + } + + public boolean isCommunicationError() { + return isBitsSet(BIT_COMMUNICATION_ERROR); + } + + public boolean isBroadcastReceived() { + return isBitsSet(BIT_BROADCAST_RECEIVED); + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventSend.java b/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventSend.java new file mode 100644 index 0000000..54b6e5b --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/comm/ModbusCommEventSend.java @@ -0,0 +1,83 @@ +package com.intelligt.modbus.jlibmodbus.data.comm; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusCommEventSend extends ModbusCommEvent { + final static private int BIT_READ_EXCEPTION_SENT = 0x1; + final static private int BIT_SLAVE_ABORT_EXCEPTION_SENT = 0x2; + final static private int BIT_SLAVE_BUSY_EXCEPTION_SENT = 0x4; + final static private int BIT_SLAVE_PROGRAM_NAK_EXCEPTION_SENT = 0x8; + final static private int BIT_WRITE_TIMEOUT_ERROR_OCCURRED = 0x10; + final static private int BIT_CURRENTLY_IN_LISTEN_ONLY_MODE = 0x20; + + protected ModbusCommEventSend(int event) { + super(Type.SEND, event); + } + + static public ModbusCommEventSend createExceptionSentRead() { + return new ModbusCommEventSend(BIT_READ_EXCEPTION_SENT); + } + + static public ModbusCommEventSend createExceptionSlaveSentAbort() { + return new ModbusCommEventSend(BIT_SLAVE_ABORT_EXCEPTION_SENT); + } + + static public ModbusCommEventSend createExceptionSlaveSentBusy() { + return new ModbusCommEventSend(BIT_SLAVE_BUSY_EXCEPTION_SENT); + } + + static public ModbusCommEventSend createExceptionSentSlaveProgramNAK() { + return new ModbusCommEventSend(BIT_SLAVE_PROGRAM_NAK_EXCEPTION_SENT); + } + + static public ModbusCommEventSend createWriteTimeoutErrorOccurred() { + return new ModbusCommEventSend(BIT_WRITE_TIMEOUT_ERROR_OCCURRED); + } + + static public ModbusCommEventSend createCurrentlyInListenOnlyMode() { + return new ModbusCommEventSend(BIT_CURRENTLY_IN_LISTEN_ONLY_MODE); + } + + public boolean isCurrentlyInListenOnlyMode() { + return isBitsSet(BIT_CURRENTLY_IN_LISTEN_ONLY_MODE); + } + + public boolean isExceptionSentRead() { + return isBitsSet(BIT_READ_EXCEPTION_SENT); + } + + public boolean isExceptionSlaveSentAbort() { + return isBitsSet(BIT_SLAVE_ABORT_EXCEPTION_SENT); + } + + public boolean isExceptionSlaveSentBusy() { + return isBitsSet(BIT_SLAVE_BUSY_EXCEPTION_SENT); + } + + public boolean isExceptionSentSlaveProgramNAK() { + return isBitsSet(BIT_SLAVE_PROGRAM_NAK_EXCEPTION_SENT); + } + + public boolean isWriteTimeoutErrorOccurred() { + return isBitsSet(BIT_WRITE_TIMEOUT_ERROR_OCCURRED); + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/data/mei/ReadDeviceIdentificationInterface.java b/src/com/intelligt/modbus/jlibmodbus/data/mei/ReadDeviceIdentificationInterface.java new file mode 100644 index 0000000..0c9a72f --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/data/mei/ReadDeviceIdentificationInterface.java @@ -0,0 +1,186 @@ +package com.intelligt.modbus.jlibmodbus.data.mei; + +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.TreeMap; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ReadDeviceIdentificationInterface { + + final static public int BASIC_OBJECT_COUNT = 3; + final static public int REGULAR_OBJECT_COUNT = 0x7D; + final static public int EXTENDED_OBJECT_COUNT = 0x7F; + final static public int OBJECT_ID_VENDOR_NAME = 0; + final static public int OBJECT_ID_PRODUCT_CODE = 1; + final static public int OBJECT_ID_MAJOR_MINOR_REVISION = 2; + final static public int OBJECT_ID_VENDOR_URL = 3; + final static public int OBJECT_ID_PRODUCT_NAME = 4; + final static public int OBJECT_ID_MODEL_NAME = 5; + final static public int OBJECT_ID_USER_APPLICATION_NAME = 6; + final private DataObjectsHolder dataObjectsBasic = new DataObjectsHolder(BASIC_OBJECT_COUNT); + final private DataObjectsHolder dataObjectsRegular = new DataObjectsHolder(REGULAR_OBJECT_COUNT); + final private DataObjectsHolder dataObjectsExtended = new DataObjectsHolder(EXTENDED_OBJECT_COUNT); + + public ReadDeviceIdentificationInterface() { + for (int i = 0; i < BASIC_OBJECT_COUNT; i++) + dataObjectsBasic.add(new DataObject(i, new byte[0])); + } + + DataObjectsHolder getDataObjectsHolder(int id) { + if (id < 0) + throw new IllegalArgumentException(); + if (id >= REGULAR_OBJECT_COUNT) + return dataObjectsExtended; + if (id >= BASIC_OBJECT_COUNT) + return dataObjectsRegular; + return dataObjectsBasic; + } + + public void setValue(int id, String value) { + setValue(new DataObject(id, value.getBytes(Charset.forName("UTF-8")))); + } + + public void setValue(DataObject dataObject) { + getDataObjectsHolder(dataObject.getId()).add(dataObject); + } + + public DataObject getValue(int id) { + return getDataObjectsHolder(id).get(id); + } + + public DataObject getVendorName() { + return getValue(OBJECT_ID_VENDOR_NAME); + } + + public void setVendorName(String value) { + setValue(OBJECT_ID_VENDOR_NAME, value); + } + + public DataObject getProductCode() { + return getValue(OBJECT_ID_PRODUCT_CODE); + } + + public void setProductCode(String value) { + setValue(OBJECT_ID_PRODUCT_CODE, value); + } + + public DataObject getMajorMinorRevision() { + return getValue(OBJECT_ID_MAJOR_MINOR_REVISION); + } + + public void setMajorMinorRevision(String value) { + setValue(OBJECT_ID_MAJOR_MINOR_REVISION, value); + } + + public DataObject getVendorUrl() { + return getValue(OBJECT_ID_VENDOR_URL); + } + + public void setVendorUrl(String value) { + setValue(OBJECT_ID_VENDOR_URL, value); + } + + public DataObject getProductName() { + return getValue(OBJECT_ID_PRODUCT_NAME); + } + + public void setProductName(String value) { + setValue(OBJECT_ID_PRODUCT_NAME, value); + } + + public DataObject getModelName() { + return getValue(OBJECT_ID_MODEL_NAME); + } + + public void setModelName(String value) { + setValue(OBJECT_ID_MODEL_NAME, value); + } + + public DataObject getUserApplicationName() { + return getValue(OBJECT_ID_USER_APPLICATION_NAME); + } + + public void setUserApplicationName(String value) { + setValue(OBJECT_ID_USER_APPLICATION_NAME, value); + } + + public DataObject[] getBasic() { + return dataObjectsBasic.toArray(); + } + + public DataObject[] getRegular() { + return dataObjectsRegular.toArray(); + } + + public DataObject[] getExtended() { + return dataObjectsExtended.toArray(); + } + + static public class DataObject { + final private int id; + private byte[] value; + + public DataObject(int id, byte[] value) { + this.id = id; + setValue(value); + } + + public int getId() { + return id; + } + + public byte[] getValue() { + return Arrays.copyOf(value, value.length); + } + + public void setValue(byte[] value) { + this.value = Arrays.copyOf(value, value.length); + } + } + + static private class DataObjectsHolder { + final private int capacity; + final TreeMap map; + + public DataObjectsHolder(int capacity) { + this.capacity = capacity; + map = new TreeMap(); + } + + public void add(DataObject dataObject) { + if (map.containsKey(dataObject.getId())) { + map.get(dataObject.getId()).setValue(dataObject.getValue()); + } else if (map.size() < capacity) { + map.put(dataObject.getId(), dataObject); + } + } + + public DataObject get(int id) { + return map.get(id); + } + + public DataObject[] toArray() { + return map.values().toArray(new DataObject[map.size()]); + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/AcknowledgeException.java b/src/com/intelligt/modbus/jlibmodbus/exception/AcknowledgeException.java new file mode 100644 index 0000000..faf2e88 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/AcknowledgeException.java @@ -0,0 +1,44 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +import com.intelligt.modbus.jlibmodbus.utils.ModbusExceptionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * quote from MODBUS Application Protocol Specification V1.1b + *

+ * "Specialized use in conjunction with programming + * commands. + * The server (or slave) has accepted the request + * and is processing it, but a long duration of time + * will be required to do so. This response is + * returned to prevent a timeout error from occurring + * in the client (or master). The client (or master) + * can next issue a Poll Program Complete message + * to determine if processing is completed." + */ +public class AcknowledgeException extends ModbusProtocolException { + public AcknowledgeException() { + super(ModbusExceptionCode.ACKNOWLEDGE); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/GatewayPathUnavailableException.java b/src/com/intelligt/modbus/jlibmodbus/exception/GatewayPathUnavailableException.java new file mode 100644 index 0000000..c538870 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/GatewayPathUnavailableException.java @@ -0,0 +1,41 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +import com.intelligt.modbus.jlibmodbus.utils.ModbusExceptionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * quote from MODBUS Application Protocol Specification V1.1b + *

+ * "Specialized use in conjunction with gateways, + * indicates that the gateway was unable to allocate + * an internal communication path from the input + * port to the output port for processing the request. + * Usually means that the gateway is misconfigured + * or overloaded." + */ +public class GatewayPathUnavailableException extends ModbusProtocolException { + public GatewayPathUnavailableException() { + super(ModbusExceptionCode.GATEWAY_PATH_UNAVAILABLE); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/GatewayTargetDeviceFailedToRespondException.java b/src/com/intelligt/modbus/jlibmodbus/exception/GatewayTargetDeviceFailedToRespondException.java new file mode 100644 index 0000000..93a3a44 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/GatewayTargetDeviceFailedToRespondException.java @@ -0,0 +1,39 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +import com.intelligt.modbus.jlibmodbus.utils.ModbusExceptionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * quote from MODBUS Application Protocol Specification V1.1b + *

+ * "Specialized use in conjunction with gateways, + * indicates that no response was obtained from the + * target device. Usually means that the device is + * not present on the network." + */ +public class GatewayTargetDeviceFailedToRespondException extends ModbusProtocolException { + public GatewayTargetDeviceFailedToRespondException() { + super(ModbusExceptionCode.GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/IllegalDataAddressException.java b/src/com/intelligt/modbus/jlibmodbus/exception/IllegalDataAddressException.java new file mode 100644 index 0000000..a1b1da8 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/IllegalDataAddressException.java @@ -0,0 +1,58 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +import com.intelligt.modbus.jlibmodbus.utils.ModbusExceptionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * quote from MODBUS Application Protocol Specification V1.1b + *

+ * "The data address received in the query is not an + * allowable address for the server (or slave). More + * specifically, the combination of reference number + * and transfer length is invalid. For a controller with + * 100 registers, the PDU addresses the first + * register as 0, and the last one as 99. If a request + * is submitted with a starting register address of 96 + * and a quantity of registers of 4, then this request + * will successfully operate (address-wise at least) + * on registers 96, 97, 98, 99. If a request is + * submitted with a starting register address of 96 + * and a quantity of registers of 5, then this request + * will fail with Exception Code 0x02 “Illegal Data + * Address� since it attempts to operate on registers + * 96, 97, 98, 99 and 100, and there is no register + * with address 100." + */ +public class IllegalDataAddressException extends ModbusProtocolException { + final private int dataAddress; + + public IllegalDataAddressException(int dataAddress) { + super(ModbusExceptionCode.ILLEGAL_DATA_ADDRESS); + this.dataAddress = dataAddress; + } + + public int getDataAddress() { + return dataAddress; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/IllegalDataValueException.java b/src/com/intelligt/modbus/jlibmodbus/exception/IllegalDataValueException.java new file mode 100644 index 0000000..7cd1378 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/IllegalDataValueException.java @@ -0,0 +1,46 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +import com.intelligt.modbus.jlibmodbus.utils.ModbusExceptionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * quote from MODBUS Application Protocol Specification V1.1b + *

+ * "A value contained in the query data field is not an + * allowable value for server (or slave). This + * indicates a fault in the structure of the remainder + * of a complex request, such as that the implied + * length is incorrect. It specifically does NOT mean + * that a data item submitted for storage in a register + * has a value outside the expectation of the + * application program, since the MODBUS protocol + * is unaware of the significance of any particular + * value of any particular register." + */ +public class IllegalDataValueException extends ModbusProtocolException { + + public IllegalDataValueException() { + super(ModbusExceptionCode.ILLEGAL_DATA_VALUE); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/IllegalFunctionException.java b/src/com/intelligt/modbus/jlibmodbus/exception/IllegalFunctionException.java new file mode 100644 index 0000000..e744e0e --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/IllegalFunctionException.java @@ -0,0 +1,52 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +import com.intelligt.modbus.jlibmodbus.utils.ModbusExceptionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * quote from MODBUS Application Protocol Specification V1.1b + *

+ * "The function code received in the query is not an + * allowable action for the server (or slave). This + * may be because the function code is only + * applicable to newer devices, and was not + * implemented in the unit selected. It could also + * indicate that the server (or slave) is in the wrong + * state to process a request of this type, for + * example because it is unconfigured and is being + * asked to return register values." + */ +public class IllegalFunctionException extends ModbusProtocolException { + + final private int functionCode; + + public IllegalFunctionException(int functionCode) { + super(ModbusExceptionCode.ILLEGAL_FUNCTION); + this.functionCode = functionCode; + } + + public int getFunctionCode() { + return functionCode; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/MemoryParityErrorException.java b/src/com/intelligt/modbus/jlibmodbus/exception/MemoryParityErrorException.java new file mode 100644 index 0000000..1817eaf --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/MemoryParityErrorException.java @@ -0,0 +1,44 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +import com.intelligt.modbus.jlibmodbus.utils.ModbusExceptionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * quote from MODBUS Application Protocol Specification V1.1b + *

+ * "Specialized use in conjunction with function codes + * 20 and 21 and reference type 6, to indicate that + * the extended file area failed to pass a consistency + * checkFrame. + * The server (or slave) attempted to read record + * file, but detected a parity error in the memory. + * The client (or master) can retry the request, but + * service may be required on the server (or slave) + * device." + */ +public class MemoryParityErrorException extends ModbusProtocolException { + public MemoryParityErrorException() { + super(ModbusExceptionCode.MEMORY_PARITY_ERROR); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/ModbusChecksumException.java b/src/com/intelligt/modbus/jlibmodbus/exception/ModbusChecksumException.java new file mode 100644 index 0000000..64c41cf --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/ModbusChecksumException.java @@ -0,0 +1,35 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusChecksumException extends ModbusIOException { + + public static final String CHECKSUM_ERROR_STRING = "checksum error: received %d, calculated %d"; + + public ModbusChecksumException(int recv, int calc) { + super(String.format(CHECKSUM_ERROR_STRING, recv, calc)); + } + + public ModbusChecksumException(int recv, int calc, Throwable cause) { + super(String.format(CHECKSUM_ERROR_STRING, recv, calc), cause); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/ModbusIOException.java b/src/com/intelligt/modbus/jlibmodbus/exception/ModbusIOException.java new file mode 100644 index 0000000..ccfcfbc --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/ModbusIOException.java @@ -0,0 +1,37 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusIOException extends Exception { + + public ModbusIOException(String message) { + super(message); + } + + public ModbusIOException(String message, Throwable cause) { + super(message, cause); + } + + public ModbusIOException(Throwable cause) { + super(cause); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/ModbusMasterException.java b/src/com/intelligt/modbus/jlibmodbus/exception/ModbusMasterException.java new file mode 100644 index 0000000..a65b6df --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/ModbusMasterException.java @@ -0,0 +1,33 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusMasterException extends Exception { + + public ModbusMasterException(String message) { + super(message); + } + + public ModbusMasterException(Throwable cause) { + super(cause); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/ModbusNumberException.java b/src/com/intelligt/modbus/jlibmodbus/exception/ModbusNumberException.java new file mode 100644 index 0000000..66a9304 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/ModbusNumberException.java @@ -0,0 +1,32 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusNumberException extends Exception { + public ModbusNumberException(String message, int number) { + super(message + " : " + number); + } + + public ModbusNumberException(String message) { + super(message); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/ModbusProtocolException.java b/src/com/intelligt/modbus/jlibmodbus/exception/ModbusProtocolException.java new file mode 100644 index 0000000..db74a2c --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/ModbusProtocolException.java @@ -0,0 +1,39 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +import com.intelligt.modbus.jlibmodbus.utils.ModbusExceptionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public class ModbusProtocolException extends Exception { + + private final ModbusExceptionCode exception; + + public ModbusProtocolException(ModbusExceptionCode exception) { + super(exception.toString()); + this.exception = exception; + } + + public ModbusExceptionCode getException() { + return exception; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/ModbusSlaveException.java b/src/com/intelligt/modbus/jlibmodbus/exception/ModbusSlaveException.java new file mode 100644 index 0000000..e187b9f --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/ModbusSlaveException.java @@ -0,0 +1,33 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusSlaveException extends Exception { + + public ModbusSlaveException(String message) { + super(message); + } + + public ModbusSlaveException(Throwable cause) { + super(cause); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/SlaveDeviceBusyException.java b/src/com/intelligt/modbus/jlibmodbus/exception/SlaveDeviceBusyException.java new file mode 100644 index 0000000..c60c669 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/SlaveDeviceBusyException.java @@ -0,0 +1,41 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +import com.intelligt.modbus.jlibmodbus.utils.ModbusExceptionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * quote from MODBUS Application Protocol Specification V1.1b + *

+ * "Specialized use in conjunction with programming + * commands. + * The server (or slave) is engaged in processing a + * long–duration program command. The client (or + * master) should retransmit the message later when + * the server (or slave) is free." + */ +public class SlaveDeviceBusyException extends ModbusProtocolException { + public SlaveDeviceBusyException() { + super(ModbusExceptionCode.SLAVE_DEVICE_BUSY); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/exception/SlaveDeviceFailureException.java b/src/com/intelligt/modbus/jlibmodbus/exception/SlaveDeviceFailureException.java new file mode 100644 index 0000000..229dba4 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/exception/SlaveDeviceFailureException.java @@ -0,0 +1,38 @@ +package com.intelligt.modbus.jlibmodbus.exception; + +import com.intelligt.modbus.jlibmodbus.utils.ModbusExceptionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * quote from MODBUS Application Protocol Specification V1.1b + *

+ * "An unrecoverable error occurred while the server + * (or slave) was attempting to perform the + * requested action." + */ +public class SlaveDeviceFailureException extends ModbusProtocolException { + public SlaveDeviceFailureException() { + super(ModbusExceptionCode.SLAVE_DEVICE_FAILURE); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/master/ModbusMaster.java b/src/com/intelligt/modbus/jlibmodbus/master/ModbusMaster.java new file mode 100644 index 0000000..4f6ae6a --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/master/ModbusMaster.java @@ -0,0 +1,777 @@ +package com.intelligt.modbus.jlibmodbus.master; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.CommStatus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.ModbusRequestBuilder; +import com.intelligt.modbus.jlibmodbus.msg.ModbusRequestFactory; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusFileRecord; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusMessage; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.base.mei.MEIReadDeviceIdentification; +import com.intelligt.modbus.jlibmodbus.msg.base.mei.ReadDeviceIdentificationCode; +import com.intelligt.modbus.jlibmodbus.msg.response.*; +import com.intelligt.modbus.jlibmodbus.net.ModbusConnection; +import com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransport; +import com.intelligt.modbus.jlibmodbus.utils.FrameEvent; +import com.intelligt.modbus.jlibmodbus.utils.FrameEventListener; +import com.intelligt.modbus.jlibmodbus.utils.FrameEventListenerList; +import com.intelligt.modbus.jlibmodbus.utils.ModbusExceptionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +abstract public class ModbusMaster implements FrameEventListenerList { + + final private ModbusConnection conn; + final private BroadcastResponse broadcastResponse = new BroadcastResponse(); + private int transactionId = 0; + private long requestTime = 0; + + public ModbusMaster(ModbusConnection conn) { + this.conn = conn; + } + + public int getTransactionId() { + return transactionId; + } + + public void setTransactionId(int transactionId) { + this.transactionId = Math.min(Math.abs(transactionId), Modbus.TRANSACTION_ID_MAX_VALUE); + } + + protected ModbusConnection getConnection() { + return conn; + } + + /** + * this method allows you to implement your own behavior of connect method. + * + * @throws ModbusIOException + */ + protected void connectImpl() throws ModbusIOException { + getConnection().open(); + } + + /** + * this method allows you to implement your own behavior of disconnect method. + * + * @throws ModbusIOException + */ + protected void disconnectImpl() throws ModbusIOException { + getConnection().close(); + } + + final public void connect() throws ModbusIOException { + if (!isConnected()) { + connectImpl(); + } + } + + final public void disconnect() throws ModbusIOException { + if (isConnected()) { + disconnectImpl(); + } + } + + public boolean isConnected() { + return getConnection().isOpened(); + } + + public void sendRequest(ModbusMessage msg) throws ModbusIOException { + ModbusTransport transport = getConnection().getTransport(); + if (transport == null) + throw new ModbusIOException("transport is null"); + transport.send(msg); + requestTime = System.currentTimeMillis(); + } + + protected ModbusMessage readResponse(ModbusRequest request) throws ModbusProtocolException, ModbusNumberException, ModbusIOException { + return getConnection().getTransport().readResponse(request); + } + + /** + * this function allows you to process your own ModbusRequest. + * Each request class has a compliant response class for instance ReadHoldingRegistersRequest and ReadHoldingRegistersResponse. + * If you process an instance of ReadHoldingRegistersRequest this function exactly either returns a ReadHoldingRegistersResponse instance or throws an exception. + * + * @param request an instance of ModbusRequest. + * @return an instance of ModbusResponse. + * @throws ModbusProtocolException + * @throws ModbusIOException + * @see ModbusRequestFactory + * @see ModbusRequest + * @see ModbusResponse + * @see com.intelligt.modbus.jlibmodbus.msg.request + * @see com.intelligt.modbus.jlibmodbus.msg.request + */ + synchronized public ModbusResponse processRequest(ModbusRequest request) throws ModbusProtocolException, ModbusIOException { + try { + sendRequest(request); + if (request.getServerAddress() != Modbus.BROADCAST_ID) { + do { + try { + ModbusResponse msg = (ModbusResponse) readResponse(request); + request.validateResponse(msg); + /* + * if you have received an ACKNOWLEDGE, + * it means that operation is in processing and you should be waiting for the answer + */ + if (msg.getModbusExceptionCode() != ModbusExceptionCode.ACKNOWLEDGE) { + if (msg.isException()) + throw new ModbusProtocolException(msg.getModbusExceptionCode()); + return msg; + } + } catch (ModbusNumberException mne) { + Modbus.log().warning(mne.getLocalizedMessage()); + } + } while (System.currentTimeMillis() - requestTime < getConnection().getReadTimeout()); + /* + * throw an exception if there is a response timeout + */ + throw new ModbusIOException("Response timeout."); + } else { + /* + return because slaves do not respond broadcast requests + */ + broadcastResponse.setFunction(request.getFunction()); + return broadcastResponse; + } + } catch (ModbusIOException mioe) { + disconnect(); + throw mioe; + } + } + + /** + * ModbusMaster will block for only this amount of time. + * If the timeout expires, a ModbusTransportException is raised, though the ModbusMaster is still valid. + * + * @param timeout the specified timeout, in milliseconds. + */ + public void setResponseTimeout(int timeout) { + try { + getConnection().setReadTimeout(timeout); + } catch (Exception e) { + Modbus.log().warning(e.getLocalizedMessage()); + } + } + + /** + * This function code is used to read the contents of a contiguous block of holding registers in a + * remote device. The Request PDU specifies the starting register address and the number of + * registers. In the PDU Registers are addressed starting at zero. Therefore registers numbered + * 1-16 are addressed as 0-15. + * + * @param serverAddress a slave address + * @param startAddress starting register address + * @param quantity the number of registers + * @return the register data + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + final public int[] readHoldingRegisters(int serverAddress, int startAddress, int quantity) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReadHoldingRegisters(serverAddress, startAddress, quantity); + ReadHoldingRegistersResponse response = (ReadHoldingRegistersResponse) processRequest(request); + return response.getRegisters(); + } + + /** + * This function code is used to read from 1 to 125 contiguous input registers in a remote + * device. The Request PDU specifies the starting register address and the number of registers. + * In the PDU Registers are addressed starting at zero. Therefore input registers numbered 1-16 + * are addressed as 0-15. + * + * @param serverAddress a slave address + * @param startAddress starting register address + * @param quantity the number of registers + * @return the register data + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + final public int[] readInputRegisters(int serverAddress, int startAddress, int quantity) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReadInputRegisters(serverAddress, startAddress, quantity); + ReadHoldingRegistersResponse response = (ReadInputRegistersResponse) processRequest(request); + return response.getRegisters(); + } + + /** + * This function code is used to read from 1 to 2000 contiguous status of coils in a remote + * device. The Request PDU specifies the starting address, i.e. the address of the first coil + * specified, and the number of coils. In the PDU Coils are addressed starting at zero. Therefore + * coils numbered 1-16 are addressed as 0-15. + * If the returned output quantity is not a multiple of eight, the remaining coils in the final boolean array + * will be padded with FALSE. + * + * @param serverAddress a slave address + * @param startAddress the address of the first coil + * @param quantity the number of coils + * @return the coils + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + final synchronized public boolean[] readCoils(int serverAddress, int startAddress, int quantity) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReadCoils(serverAddress, startAddress, quantity); + ReadCoilsResponse response = (ReadCoilsResponse) processRequest(request); + return response.getCoils(); + } + + /** + * This function code is used to read from 1 to 2000 contiguous status of discrete inputs in a + * remote device. The Request PDU specifies the starting address, i.e. the address of the first + * input specified, and the number of inputs. In the PDU Discrete Inputs are addressed starting + * at zero. Therefore Discrete inputs numbered 1-16 are addressed as 0-15. + * If the returned input quantity is not a multiple of eight, the remaining inputs in the final boolean array + * will be padded with FALSE. + * + * @param serverAddress a slave address + * @param startAddress the address of the first input + * @param quantity the number of inputs + * @return the discrete inputs + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + final public boolean[] readDiscreteInputs(int serverAddress, int startAddress, int quantity) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReadDiscreteInputs(serverAddress, startAddress, quantity); + ReadDiscreteInputsResponse response = (ReadDiscreteInputsResponse) processRequest(request); + return response.getCoils(); + } + + /** + * This function code is used to write a single output to either ON or OFF in a remote device. + * The requested ON/OFF state is specified by a constant in the request data field. A value of + * TRUE requests the output to be ON. A value of FALSE requests it to be OFF. + * The Request PDU specifies the address of the coil to be forced. Coils are addressed starting + * at zero. Therefore coil numbered 1 is addressed as 0. + * + * @param serverAddress a slave address + * @param startAddress the address of the coil to be forced + * @param flag the request data field + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + final public void writeSingleCoil(int serverAddress, int startAddress, boolean flag) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + processRequest(ModbusRequestBuilder.getInstance().buildWriteSingleCoil(serverAddress, startAddress, flag)); + } + + /** + * This function code is used to write a single holding register in a remote device. + * The Request PDU specifies the address of the register to be written. Registers are addressed + * starting at zero. Therefore register numbered 1 is addressed as 0. + * + * @param serverAddress a slave address + * @param startAddress the address of the register to be written + * @param register value + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + final public void writeSingleRegister(int serverAddress, int startAddress, int register) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + processRequest(ModbusRequestBuilder.getInstance().buildWriteSingleRegister(serverAddress, startAddress, register)); + } + + /** + * This function code is used to force each coil in a sequence of coils to either ON or OFF in a + * remote device. The Request PDU specifies the coil references to be forced. Coils are + * addressed starting at zero. Therefore coil numbered 1 is addressed as 0. + * The requested ON/OFF states are specified by contents of the request array of boolean. A logical 'true' + * in position of the array requests the corresponding output to be ON. A logical 'false' requests + * it to be OFF. + * + * @param serverAddress a slave address + * @param startAddress the address of the coils to be written + * @param coils the coils + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + final public void writeMultipleCoils(int serverAddress, int startAddress, boolean[] coils) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + processRequest(ModbusRequestBuilder.getInstance().buildWriteMultipleCoils(serverAddress, startAddress, coils)); + } + + /** + * This function code is used to write a block of contiguous registers (1 to 123 registers) in a + * remote device. + * The requested written values are specified in the request data field. Data is packed as two + * bytes per register. + * + * @param serverAddress a slave address + * @param startAddress the address of the registers to be written + * @param registers the register data + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + final public void writeMultipleRegisters(int serverAddress, int startAddress, int[] registers) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + processRequest(ModbusRequestBuilder.getInstance().buildWriteMultipleRegisters(serverAddress, startAddress, registers)); + } + + /** + * This function code performs a combination of one read operation and one write operation in a + * single MODBUS transaction. The write operation is performed before the read. + * Holding registers are addressed starting at zero. Therefore holding registers 1-16 are + * addressed in the PDU as 0-15. + * The request specifies the starting address and number of holding registers to be read as well + * as the starting address, number of holding registers, and the data to be written. + * + * @param serverAddress a slave address + * @param readAddress the address of the registers to be read + * @param readQuantity the number of registers to be read + * @param writeAddress the address of the registers to be written + * @param registers the number of registers to be written + * @return the register value + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + final public int[] readWriteMultipleRegisters(int serverAddress, int readAddress, int readQuantity, int writeAddress, int[] registers) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReadWriteMultipleRegisters(serverAddress, readAddress, readQuantity, writeAddress, registers); + ReadWriteMultipleRegistersResponse response = (ReadWriteMultipleRegistersResponse) processRequest(request); + return response.getRegisters(); + } + + /** + * This function code allows to read the contents of a First-In-First-Out (FIFO) queue of register + * in a remote device. The function returns the queued data. + * Up to 31 queue data registers can be read. + * The function reads the queue contents, but does not clear them. + * If the queue count exceeds 31, an exception response is returned with an error code of 03 + * (Illegal Data Value). + * + * @param serverAddress a slave address + * @param fifoPointerAddress address of a fifo pointer register + * @return the data register value + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + final public int[] readFifoQueue(int serverAddress, int fifoPointerAddress) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReadFifoQueue(serverAddress, fifoPointerAddress); + ReadFifoQueueResponse response = (ReadFifoQueueResponse) processRequest(request); + return response.getFifoValueRegister(); + } + + /** + * This function code is used to perform a file record read. + * A file is an organization of records. Each file contains 10000 records, addressed 0000 to + * 9999 decimal or 0X0000 to 0X270F. For example, record 12 is addressed as 12. + * The function can read multiple groups of references. + * + * @param serverAddress a slave address + * @param records array of ModbusFileRecord + * @return array of ModbusFileRecord has been read + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + final public ModbusFileRecord[] readFileRecord(int serverAddress, ModbusFileRecord[] records) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReadFileRecord(serverAddress, records); + ReadFileRecordResponse response = (ReadFileRecordResponse) processRequest(request); + return response.getFileRecords(); + } + + /** + * This function code is used to perform a file record write. All Request Data Lengths are + * provided in terms of number of bytes and all Record Lengths are provided in terms of the + * number of 16-bit words. + * A file is an organization of records. Each file contains 10000 records, addressed 0000 to + * 9999 decimal or 0X0000 to 0X270F. For example, record 12 is addressed as 12. + * The function can write multiple groups of references. + * + * @param serverAddress a server address + * @param record the ModbusFileRecord to be written + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + final public void writeFileRecord(int serverAddress, ModbusFileRecord record) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + processRequest(ModbusRequestBuilder.getInstance().buildWriteFileRecord(serverAddress, record)); + } + + /** + * This function code is used to modify the contents of a specified holding register using a + * combination of an AND mask, an OR mask, and the register's current contents. The function + * can be used to set or clear individual bits in the register. + * The request specifies the holding register to be written, the data to be used as the AND + * mask, and the data to be used as the OR mask. Registers are addressed starting at zero. + * Therefore registers 1-16 are addressed as 0-15. + * The function’s algorithm is: + * Result = (Current Contents AND And_Mask) OR (Or_Mask AND (NOT And_Mask)) + * For example: + * Hex Binary + * Current Contents= 12 0001 0010 + * And_Mask = F2 1111 0010 + * Or_Mask = 25 0010 0101 + *

+ * (NOT And_Mask)= 0D 0000 1101 + *

+ * Result = 17 0001 0111 + *

+ * Note: + * y If the Or_Mask value is zero, the result is simply the logical ANDing of the current contents and + * And_Mask. If the And_Mask value is zero, the result is equal to the Or_Mask value. + * y The contents of the register can be read with the Read Holding Registers function (function code 03). + * They could, however, be changed subsequently as the controller scans its user logic program. + * + * @param serverAddress slave id + * @param startAddress reference address + * @param and the AND mask + * @param or the OR mask + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + final public void maskWriteRegister(int serverAddress, int startAddress, int and, int or) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + processRequest(ModbusRequestBuilder.getInstance().buildMaskWriteRegister(serverAddress, startAddress, and, or)); + } + + /** + * This function code is used to read the contents of eight Exception Status outputs in a remote + * device. + * The function provides a simple method for accessing this information, because the Exception + * Output references are known (no output reference is needed in the function). + * The normal response contains the status of the eight Exception Status outputs. The outputs + * are packed into one data byte, with one bit per output. The status of the lowest output + * reference is contained in the least significant bit of the byte. + * The contents of the eight Exception Status outputs are device specific. + * + * @param serverAddress a slave address + * @return the eight Exception Status outputs + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + abstract public int readExceptionStatus(int serverAddress) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException; + + /** + * This function code is used to read the description of the type, the current status, and other + * information specific to a remote device. + * The data contents are specific to each type of device. + * + * @param serverAddress slave address + * @return a byte array of the device's specific data + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + */ + abstract public byte[] reportSlaveId(int serverAddress) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException; + + /** + * This function code is used to get a status word and an event count from the remote device's + * communication event counter. + * By fetching the current count before and after a series of messages, a client can determine + * whether the messages were handled normally by the remote device. + * The device’s event counter is incremented once for each successful message completion. It + * is not incremented for exception responses, poll commands, or fetch event counter + * commands. + * The event counter can be reset by means of the Diagnostics function (code 08), with a subfunction of Restart Communications Option (code 00 01) or Clear Counters and Diagnostic + * Register (code 00 0A). + * + * @param serverAddress a slave address + * @return the CommStatus instance + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + * @see CommStatus + */ + abstract public CommStatus getCommEventCounter(int serverAddress) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException; + + /** + * This function code is used to get a status word, event count, message count, and a field of + * event bytes from the remote device. + * The status word and event counts are identical to that returned by the Get Communications + * Event Counter function (11, 0B hex). + * The message counter contains the quantity of messages processed by the remote device + * since its last restart, clear counters operation, or power–up. This count is identical to that + * returned by the Diagnostic function (code 08), sub-function Return Bus Message Count (code + * 11, 0B hex). + * The event bytes field contains 0-64 bytes, with each byte corresponding to the status of one + * MODBUS send or receive operation for the remote device. The remote device enters the + * events into the field in chronological order. Byte 0 is the most recent event. Each new byte + * flushes the oldest byte from the field. + * + * @param serverAddress a slave address + * @return the CommStatus instance + * @throws ModbusProtocolException if modbus-exception is received + * @throws ModbusNumberException if response is invalid + * @throws ModbusIOException if remote slave is unavailable + * @see CommStatus + */ + abstract public CommStatus getCommEventLog(int serverAddress) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException; + + /** + * The data passed in the request data field is to be returned (looped back) in the response. The + * entire response message should be identical to the request. + * + * @param serverAddress a slave address + * @param queryData request data field + * @throws ModbusNumberException if server address is in-valid + */ + abstract public void diagnosticsReturnQueryData(int serverAddress, int queryData) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * The remote device serial line port must be initialized and restarted, and all of its + * communications event counters are cleared. If the port is currently in Listen Only Mode, no + * response is returned. This function is the only one that brings the port out of Listen Only + * Mode. If the port is not currently in Listen Only Mode, a normal response is returned. This + * occurs before the restart is executed. + * When the remote device receives the request, it attempts a restart and executes its power–up + * confidence tests. Successful completion of the tests will bring the port online. + * A request data field contents of FF 00 hex causes the port’s Communications Event Log to be + * cleared also. Contents of 00 00 leave the log as it was prior to the restart. + * + * @param serverAddress a slave address + * @param clearLog causes the port’s Communications Event Log to be cleared + * @throws ModbusNumberException if server address is in-valid + */ + abstract public void diagnosticsRestartCommunicationsOption(int serverAddress, boolean clearLog) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * Returns the contents of the remote device’s 16–bit diagnostic register are returned in the response. + * + * @param serverAddress a slave address + * @return 16–bit diagnostic register + * @throws ModbusNumberException if server address is in-valid + */ + abstract public int diagnosticsReturnDiagnosticRegister(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * The character passed in the request data field becomes the end of message delimiter + * for future messages (replacing the default LF character). This function is useful in cases of a + * Line Feed is not required at the end of ASCII messages. + * + * @param serverAddress a slave address + * @param delimiter request data field + * @throws ModbusNumberException if server address is in-valid + */ + abstract public void diagnosticsChangeAsciiInputDelimiter(int serverAddress, int delimiter) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * Forces the addressed remote device to its Listen Only Mode for MODBUS communications. + * This isolates it from the other devices on the network, allowing them to continue + * communicating without interruption from the addressed remote device. No response is + * returned. + * When the remote device enters its Listen Only Mode, all active communication controls are + * turned off. The Ready watchdog timer is allowed to expire, locking the controls off. While the + * device is in this mode, any MODBUS messages addressed to it or broadcast are monitored, + * but no actions will be taken and no responses will be sent. + * The only function that will be processed after the mode is entered will be the Restart + * Communications Option function (function code 8, sub-function 1). + * + * @param serverAddress a slave address + * @throws ModbusNumberException if server address is in-valid + */ + abstract public void diagnosticsForceListenOnlyMode(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * The goal is to clear all counters and the diagnostic register. Counters are also cleared upon power–up. + * + * @param serverAddress a slave address + * @throws ModbusNumberException if server address is in-valid + */ + abstract public void diagnosticsClearCountersAndDiagnosticRegister(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * The response data field returns the quantity of messages that the remote device has detected + * on the communications system since its last restart, clear counters operation, or power–up. + * + * @param serverAddress a slave address + * @return bus message count + * @throws ModbusNumberException if server address is in-valid + */ + abstract public int diagnosticsReturnBusMessageCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * The response data field returns the quantity of CRC errors encountered by the remote device + * since its last restart, clear counters operation, or power–up. + * + * @param serverAddress a slave address + * @return CRC error count + * @throws ModbusNumberException if server address is in-valid + */ + abstract public int diagnosticsReturnBusCommunicationErrorCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * The response data field returns the quantity of MODBUS exception responses returned by the + * remote device since its last restart, clear counters operation, or power–up. + * + * @param serverAddress a slave address + * @return MODBUS exception response count + * @throws ModbusNumberException if server address is in-valid + */ + abstract public int diagnosticsReturnBusExceptionErrorCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * The response data field returns the quantity of messages addressed to the remote device, or + * broadcast, that the remote device has processed since its last restart, clear counters + * operation, or power–up. + * + * @param serverAddress a slave address + * @return count of messages has been processed + * @throws ModbusNumberException if server address is in-valid + */ + abstract public int diagnosticsReturnSlaveMessageCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * The response data field returns the quantity of messages addressed to the remote device for + * which it has returned no response (neither a normal response nor an exception response), + * since its last restart, clear counters operation, or power–up. + * + * @param serverAddress a slave address + * @return no-response count + * @throws ModbusNumberException if server address is in-valid + */ + abstract public int diagnosticsReturnSlaveNoResponseCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * The response data field returns the quantity of messages addressed to the remote device for + * which it returned a Negative Acknowledge (NAK) exception response, since its last restart, + * clear counters operation, or power–up. + * + * @param serverAddress a slave address + * @return NAK count + * @throws ModbusNumberException if server address is in-valid + */ + abstract public int diagnosticsReturnSlaveNAKCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * The response data field returns the quantity of messages addressed to the remote device for + * which it returned a Slave Device Busy exception response, since its last restart, clear + * counters operation, or power–up. + * + * @param serverAddress a slave address + * @return Slave Device Busy exception response count + * @throws ModbusNumberException if server address is in-valid + */ + abstract public int diagnosticsReturnSlaveBusyCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * The response data field returns the quantity of messages addressed to the remote device that + * it could not handle due to a character overrun condition, since its last restart, clear counters + * operation, or power–up. A character overrun is caused by data characters arriving at the port + * faster than they can be stored, or by the loss of a character due to a hardware malfunction. + * + * @param serverAddress a slave address + * @return character overrun count + * @throws ModbusNumberException if server address is in-valid + */ + abstract public int diagnosticsReturnBusCharacterOverrunCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * Clears the overrun error counter and reset the error flag. + * + * @param serverAddress a slave address + * @throws ModbusNumberException if server address is in-valid + */ + abstract public void diagnosticsClearOverrunCounterAndFlag(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException; + + /** + * This function code allows reading the identification and additional information relative to the + * physical and functional description of a remote device, only. + * The Read Device Identification interface is modeled as an address space composed of a set + * of addressable data elements. The data elements are called objects and an object Id + * identifies them. + * The interface consists of 3 categories of objects : + * ƒ Basic Device Identification. All objects of this category are mandatory : VendorName, + * Product code, and revision number. + * ƒ Regular Device Identification. In addition to Basic data objects, the device provides + * additional and optional identification and description data objects. All of the objects of + * this category are defined in the standard but their implementation is optional . + * ƒ Extended Device Identification. In addition to regular data objects, the device provides + * additional and optional identification and description private data about the physical + * device itself. All of these data are device dependent. + * ObjectId ObjectName/Description Type M/O category + * 0x00 VendorName ASCII String Mandatory Basic + * 0x01 ProductCode ASCII String Mandatory Basic + * 0x02 MajorMinorRevision ASCII String Mandatory Basic + * 0x03 VendorUrl ASCII String Optional Regular + * 0x04 ProductName ASCII String Optional Regular + * 0x05 ModelName ASCII String Optional Regular + * 0x06 UserApplicationName ASCII String Optional Regular + * 0x07 Reserved Optional Optional Regular + * … + * 0x7F + * 0x80 Private objects may be optionally device Optional Extended + * … defined. The range [0x80 – 0xFF] dependant + * 0xFF is Product dependant. + */ + final public MEIReadDeviceIdentification readDeviceIdentification(int serverAddress, int objectId, ReadDeviceIdentificationCode readDeviceId) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + EncapsulatedInterfaceTransportResponse response = (EncapsulatedInterfaceTransportResponse) processRequest(ModbusRequestBuilder.getInstance().buildReadDeviceIdentification(serverAddress, objectId, readDeviceId)); + return (MEIReadDeviceIdentification) response.getMei(); + } + + /* facade */ + @Override + public void addListener(FrameEventListener listener) { + getConnection().addListener(listener); + } + + @Override + public void removeListener(FrameEventListener listener) { + getConnection().removeListener(listener); + } + + @Override + public void removeListeners() { + getConnection().removeListeners(); + } + + @Override + public void fireFrameReceivedEvent(FrameEvent event) { + getConnection().fireFrameReceivedEvent(event); + } + + @Override + public void fireFrameSentEvent(FrameEvent event) { + getConnection().fireFrameSentEvent(event); + } + + @Override + public int countListeners() { + return getConnection().countListeners(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterASCII.java b/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterASCII.java new file mode 100644 index 0000000..9f09b45 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterASCII.java @@ -0,0 +1,44 @@ +package com.intelligt.modbus.jlibmodbus.master; + +import com.intelligt.modbus.jlibmodbus.net.ModbusConnectionFactory; +import com.intelligt.modbus.jlibmodbus.serial.SerialParameters; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; +import com.intelligt.modbus.jlibmodbus.serial.SerialPortException; +import com.intelligt.modbus.jlibmodbus.serial.SerialUtils; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +final public class ModbusMasterASCII extends ModbusMasterSerial { + + public ModbusMasterASCII(SerialParameters parameters) throws SerialPortException { + super(ModbusConnectionFactory.getASCII(SerialUtils.createSerial(parameters))); + } + + public ModbusMasterASCII(String device, SerialPort.BaudRate baudRate, SerialPort.Parity parity) throws SerialPortException { + this(new SerialParameters(device, baudRate, 7, parity == SerialPort.Parity.NONE ? 2 : 1, parity)); + } + + public ModbusMasterASCII(String device, SerialPort.BaudRate baudRate) throws SerialPortException { + this(device, baudRate, SerialPort.Parity.EVEN); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterFactory.java b/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterFactory.java new file mode 100644 index 0000000..36de8a0 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterFactory.java @@ -0,0 +1,77 @@ +package com.intelligt.modbus.jlibmodbus.master; + +import com.intelligt.modbus.jlibmodbus.serial.SerialParameters; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; +import com.intelligt.modbus.jlibmodbus.serial.SerialPortException; +import com.intelligt.modbus.jlibmodbus.tcp.TcpParameters; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +final public class ModbusMasterFactory { + + private ModbusMasterFactory() { + + } + + /** + * Creates a ModbusMasterRTU instance. + * + * @param sp parameters of the serial port you would like to use. + * @return the newly created rtu-master + * @see SerialPort.Parity + * @see SerialPort.BaudRate + * @see ModbusMaster + * @see ModbusMasterRTU + * @see SerialParameters + */ + static public ModbusMaster createModbusMasterRTU(SerialParameters sp) throws SerialPortException { + return new ModbusMasterRTU(sp); + } + + /** + * Creates a ModbusMasterASCII instance. + * + * @param sp parameters of the serial port you would like to use. + * @return the newly created ascii-master + * @see SerialPort.Parity + * @see SerialPort.BaudRate + * @see ModbusMaster + * @see ModbusMasterASCII + */ + static public ModbusMaster createModbusMasterASCII(SerialParameters sp) throws SerialPortException { + return new ModbusMasterASCII(sp); + } + + /** + * Creates ModbusMasterTCP instance. + * + * @param tcpParameters - a TcpParameters instance + * @return the newly created tcp-master + * @see ModbusMaster + * @see ModbusMasterTCP + * @see TcpParameters + */ + static public ModbusMaster createModbusMasterTCP(TcpParameters tcpParameters) { + return new ModbusMasterTCP(tcpParameters); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterRTU.java b/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterRTU.java new file mode 100644 index 0000000..9853f9b --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterRTU.java @@ -0,0 +1,40 @@ +package com.intelligt.modbus.jlibmodbus.master; + +import com.intelligt.modbus.jlibmodbus.net.ModbusConnectionFactory; +import com.intelligt.modbus.jlibmodbus.serial.SerialParameters; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; +import com.intelligt.modbus.jlibmodbus.serial.SerialPortException; +import com.intelligt.modbus.jlibmodbus.serial.SerialUtils; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +final public class ModbusMasterRTU extends ModbusMasterSerial { + + public ModbusMasterRTU(SerialParameters parameters) throws SerialPortException { + super(ModbusConnectionFactory.getRTU(SerialUtils.createSerial(parameters))); + } + + public ModbusMasterRTU(String device, SerialPort.BaudRate baudRate, int dataBits, int stopBits, SerialPort.Parity parity) throws SerialPortException { + this(new SerialParameters(device, baudRate, dataBits, stopBits, parity)); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterSerial.java b/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterSerial.java new file mode 100644 index 0000000..dfc36c1 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterSerial.java @@ -0,0 +1,172 @@ +package com.intelligt.modbus.jlibmodbus.master; + +import com.intelligt.modbus.jlibmodbus.data.CommStatus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.ModbusRequestBuilder; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.response.*; +import com.intelligt.modbus.jlibmodbus.net.ModbusConnection; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +abstract public class ModbusMasterSerial extends ModbusMaster { + + final private CommStatus commStatus = new CommStatus(); + + public ModbusMasterSerial(ModbusConnection conn) { + super(conn); + } + + @Override + final public int readExceptionStatus(int serverAddress) throws + ModbusProtocolException, ModbusNumberException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReadExceptionStatus(serverAddress); + ReadExceptionStatusResponse response = (ReadExceptionStatusResponse) processRequest(request); + return response.getExceptionStatus(); + } + + @Override + final public byte[] reportSlaveId(int serverAddress) throws ModbusProtocolException, ModbusNumberException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReportSlaveId(serverAddress); + ReportSlaveIdResponse response = (ReportSlaveIdResponse) processRequest(request); + return response.getSlaveId(); + } + + @Override + final public CommStatus getCommEventCounter(int serverAddress) throws ModbusProtocolException, ModbusNumberException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildGetCommEventCounter(serverAddress); + GetCommEventCounterResponse response = (GetCommEventCounterResponse) processRequest(request); + synchronized (commStatus) { + commStatus.setCommStatus(response.getStatus()); + commStatus.setEventCount(response.getEventCount()); + } + return commStatus; + } + + @Override + final public CommStatus getCommEventLog(int serverAddress) throws ModbusProtocolException, ModbusNumberException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildGetCommEventLog(serverAddress); + GetCommEventLogResponse response = (GetCommEventLogResponse) processRequest(request); + synchronized (commStatus) { + commStatus.setCommStatus(response.getStatus()); + commStatus.setEventCount(response.getEventCount()); + commStatus.setBusMessageCount(response.getMessageCount()); + commStatus.setEventQueue(response.getEventQueue()); + } + return commStatus; + } + + @Override + final public void diagnosticsReturnQueryData(int serverAddress, int queryData) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + processRequest(ModbusRequestBuilder.getInstance().buildReturnQueryData(serverAddress, queryData)); + } + + @Override + final public void diagnosticsRestartCommunicationsOption(int serverAddress, boolean clearLog) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + processRequest(ModbusRequestBuilder.getInstance().buildRestartCommunicationsOption(serverAddress, clearLog)); + } + + @Override + final public int diagnosticsReturnDiagnosticRegister(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReturnDiagnosticRegister(serverAddress); + DiagnosticsResponse response = (DiagnosticsResponse) processRequest(request); + return response.getSubFunctionData(); + } + + @Override + final public void diagnosticsChangeAsciiInputDelimiter(int serverAddress, int delimiter) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + processRequest(ModbusRequestBuilder.getInstance().buildChangeAsciiInputDelimiter(serverAddress, delimiter)); + } + + @Override + final public void diagnosticsForceListenOnlyMode(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + processRequest(ModbusRequestBuilder.getInstance().buildForceListenOnlyMode(serverAddress)); + } + + @Override + final public void diagnosticsClearCountersAndDiagnosticRegister(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + processRequest(ModbusRequestBuilder.getInstance().buildClearCountersAndDiagnosticRegister(serverAddress)); + } + + @Override + final public int diagnosticsReturnBusMessageCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReturnBusMessageCount(serverAddress); + DiagnosticsResponse response = (DiagnosticsResponse) processRequest(request); + return response.getSubFunctionData(); + } + + @Override + final public int diagnosticsReturnBusCommunicationErrorCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReturnBusCommunicationErrorCount(serverAddress); + DiagnosticsResponse response = (DiagnosticsResponse) processRequest(request); + return response.getSubFunctionData(); + } + + @Override + final public int diagnosticsReturnBusExceptionErrorCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReturnBusExceptionErrorCount(serverAddress); + DiagnosticsResponse response = (DiagnosticsResponse) processRequest(request); + return response.getSubFunctionData(); + } + + @Override + final public int diagnosticsReturnSlaveMessageCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReturnSlaveMessageCount(serverAddress); + DiagnosticsResponse response = (DiagnosticsResponse) processRequest(request); + return response.getSubFunctionData(); + } + + @Override + final public int diagnosticsReturnSlaveNoResponseCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReturnSlaveNoResponseCount(serverAddress); + DiagnosticsResponse response = (DiagnosticsResponse) processRequest(request); + return response.getSubFunctionData(); + } + + @Override + final public int diagnosticsReturnSlaveNAKCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReturnSlaveNAKCount(serverAddress); + DiagnosticsResponse response = (DiagnosticsResponse) processRequest(request); + return response.getSubFunctionData(); + } + + @Override + final public int diagnosticsReturnSlaveBusyCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReturnSlaveBusyCount(serverAddress); + DiagnosticsResponse response = (DiagnosticsResponse) processRequest(request); + return response.getSubFunctionData(); + } + + @Override + final public int diagnosticsReturnBusCharacterOverrunCount(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + ModbusRequest request = ModbusRequestBuilder.getInstance().buildReturnBusCharacterOverrunCount(serverAddress); + DiagnosticsResponse response = (DiagnosticsResponse) processRequest(request); + return response.getSubFunctionData(); + } + + @Override + final public void diagnosticsClearOverrunCounterAndFlag(int serverAddress) throws ModbusNumberException, ModbusProtocolException, ModbusIOException { + processRequest(ModbusRequestBuilder.getInstance().buildClearOverrunCounterAndFlag(serverAddress)); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterTCP.java b/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterTCP.java new file mode 100644 index 0000000..df277cd --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/master/ModbusMasterTCP.java @@ -0,0 +1,185 @@ +package com.intelligt.modbus.jlibmodbus.master; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.CommStatus; +import com.intelligt.modbus.jlibmodbus.exception.IllegalFunctionException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusMessage; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.net.ModbusConnectionFactory; +import com.intelligt.modbus.jlibmodbus.tcp.TcpParameters; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +final public class ModbusMasterTCP extends ModbusMaster { + final private boolean keepAlive; + + public ModbusMasterTCP(TcpParameters parameters) { + super(ModbusConnectionFactory.getTcpMaster(parameters)); + keepAlive = parameters.isKeepAlive(); + try { + if (isKeepAlive()) { + connect(); + } + } catch (ModbusIOException e) { + Modbus.log().warning("keepAlive is set, connection failed at creation time."); + } + } + + private int nextTransactionId() { + int nextId = getTransactionId() + 1; + return nextId > Modbus.TRANSACTION_ID_MAX_VALUE ? 0 : nextId; + } + + public boolean isKeepAlive() { + return keepAlive; + } + + @Override + public void sendRequest(ModbusMessage msg) throws ModbusIOException { + if (!isKeepAlive()) + connect(); + try { + if (Modbus.isAutoIncrementTransactionId()) { + setTransactionId(nextTransactionId()); + } + msg.setTransactionId(getTransactionId()); + super.sendRequest(msg); + } catch (ModbusIOException e) { + if (isKeepAlive()) { + disconnect(); + connect(); + super.sendRequest(msg); + } else { + throw e; + } + } + } + + @Override + protected ModbusMessage readResponse(ModbusRequest request) throws ModbusNumberException, ModbusIOException, ModbusProtocolException { + ModbusMessage msg = super.readResponse(request); + if (!isKeepAlive()) { + disconnect(); + } + return msg; + } + + @Override + public int readExceptionStatus(int serverAddress) throws ModbusNumberException, ModbusIOException, ModbusProtocolException { + throw new IllegalFunctionException(ModbusFunctionCode.READ_EXCEPTION_STATUS.toInt()); + } + + @Override + public byte[] reportSlaveId(int serverAddress) throws ModbusProtocolException, ModbusNumberException, ModbusIOException { + throw new IllegalFunctionException(ModbusFunctionCode.REPORT_SLAVE_ID.toInt()); + } + + @Override + public CommStatus getCommEventCounter(int serverAddress) throws ModbusProtocolException, ModbusNumberException, ModbusIOException { + throw new IllegalFunctionException(ModbusFunctionCode.GET_COMM_EVENT_COUNTER.toInt()); + } + + @Override + public CommStatus getCommEventLog(int serverAddress) throws ModbusProtocolException, ModbusNumberException, ModbusIOException { + throw new IllegalFunctionException(ModbusFunctionCode.GET_COMM_EVENT_LOG.toInt()); + } + + @Override + public void diagnosticsReturnQueryData(int serverAddress, int queryData) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public void diagnosticsRestartCommunicationsOption(int serverAddress, boolean clearLog) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public int diagnosticsReturnDiagnosticRegister(int serverAddress) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public void diagnosticsChangeAsciiInputDelimiter(int serverAddress, int delimiter) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public void diagnosticsForceListenOnlyMode(int serverAddress) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public void diagnosticsClearCountersAndDiagnosticRegister(int serverAddress) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public int diagnosticsReturnBusMessageCount(int serverAddress) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public int diagnosticsReturnBusCommunicationErrorCount(int serverAddress) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public int diagnosticsReturnBusExceptionErrorCount(int serverAddress) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public int diagnosticsReturnSlaveMessageCount(int serverAddress) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public int diagnosticsReturnSlaveNoResponseCount(int serverAddress) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public int diagnosticsReturnSlaveNAKCount(int serverAddress) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public int diagnosticsReturnSlaveBusyCount(int serverAddress) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public int diagnosticsReturnBusCharacterOverrunCount(int serverAddress) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } + + @Override + public void diagnosticsClearOverrunCounterAndFlag(int serverAddress) throws ModbusNumberException, IllegalFunctionException { + throw new IllegalFunctionException(ModbusFunctionCode.DIAGNOSTICS.toInt()); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/ModbusMessageFactory.java b/src/com/intelligt/modbus/jlibmodbus/msg/ModbusMessageFactory.java new file mode 100644 index 0000000..a1d1e35 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/ModbusMessageFactory.java @@ -0,0 +1,41 @@ +package com.intelligt.modbus.jlibmodbus.msg; + +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusMessage; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public interface ModbusMessageFactory { + /** + * This method creates a #ModbusMessage instance from #functionCode. + * The returned value can be either an instance of ModbusRequest or ModbusResponse. + * + * @param functionCode a number representing a modbus function + * @return an instance of a specific ModbusMessage + * @see ModbusRequest + * @see ModbusResponse + * @see ModbusMessageFactory + * @see ModbusResponseFactory + */ + ModbusMessage createMessage(int functionCode); +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/ModbusRequestBuilder.java b/src/com/intelligt/modbus/jlibmodbus/msg/ModbusRequestBuilder.java new file mode 100644 index 0000000..ffe6328 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/ModbusRequestBuilder.java @@ -0,0 +1,406 @@ +package com.intelligt.modbus.jlibmodbus.msg; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractDataRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractMultipleRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusFileRecord; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.mei.ReadDeviceIdentificationCode; +import com.intelligt.modbus.jlibmodbus.msg.request.*; +import com.intelligt.modbus.jlibmodbus.utils.DiagnosticsSubFunctionCode; + +import java.util.Arrays; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * [https://github.com/kochedykov/jlibmodbus] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusRequestBuilder { + + static public ModbusRequestBuilder getInstance() { + return SingletonHolder.instance; + } + + private ModbusRequest setBaseParameter(ModbusRequest request, int serverAddress) throws ModbusNumberException { + request.setServerAddress(serverAddress); + return request; + } + + private void setSimpleDataRequestParameters(AbstractDataRequest request, int serverAddress, int startAddress) throws ModbusNumberException { + request.setServerAddress(serverAddress); + request.setStartAddress(startAddress); + } + + private void setMultipleDataRequestParameters(AbstractMultipleRequest request, int serverAddress, int startAddress, int quantity) throws ModbusNumberException { + setSimpleDataRequestParameters(request, serverAddress, startAddress); + request.setQuantity(quantity); + } + + public ModbusRequest buildReadCoils(int serverAddress, int startAddress, int quantity) throws ModbusNumberException { + ReadCoilsRequest request = new ReadCoilsRequest(); + setMultipleDataRequestParameters(request, serverAddress, startAddress, quantity); + return request; + } + + public ModbusRequest buildReadDiscreteInputs(int serverAddress, int startAddress, int quantity) throws ModbusNumberException { + ReadDiscreteInputsRequest request = new ReadDiscreteInputsRequest(); + setMultipleDataRequestParameters(request, serverAddress, startAddress, quantity); + return request; + } + + public ModbusRequest buildReadInputRegisters(int serverAddress, int startAddress, int quantity) throws ModbusNumberException { + ReadInputRegistersRequest request = new ReadInputRegistersRequest(); + setMultipleDataRequestParameters(request, serverAddress, startAddress, quantity); + return request; + } + + public ModbusRequest buildReadHoldingRegisters(int serverAddress, int startAddress, int quantity) throws ModbusNumberException { + ReadHoldingRegistersRequest request = new ReadHoldingRegistersRequest(); + setMultipleDataRequestParameters(request, serverAddress, startAddress, quantity); + return request; + } + + public ModbusRequest buildReadWriteMultipleRegisters(int serverAddress, int readAddress, int readQuantity, int writeAddress, int[] registers) throws ModbusNumberException { + ReadWriteMultipleRegistersRequest request = new ReadWriteMultipleRegistersRequest(); + request.setServerAddress(serverAddress); + request.setReadAddress(readAddress); + request.setReadQuantity(readQuantity); + request.setWriteAddress(writeAddress); + request.setWriteRegisters(registers); + return request; + } + + public ModbusRequest buildWriteSingleCoil(int serverAddress, int startAddress, boolean coil) throws ModbusNumberException { + WriteSingleCoilRequest request = new WriteSingleCoilRequest(); + setSimpleDataRequestParameters(request, serverAddress, startAddress); + request.setCoil(coil); + return request; + } + + public ModbusRequest buildWriteMultipleCoils(int serverAddress, int startAddress, boolean[] coils) throws ModbusNumberException { + WriteMultipleCoilsRequest request = new WriteMultipleCoilsRequest(); + setSimpleDataRequestParameters(request, serverAddress, startAddress); + request.setCoils(coils); + + return request; + } + + public ModbusRequest buildWriteMultipleRegisters(int serverAddress, int startAddress, int[] registers) throws ModbusNumberException { + WriteMultipleRegistersRequest request = new WriteMultipleRegistersRequest(); + setSimpleDataRequestParameters(request, serverAddress, startAddress); + request.setRegisters(registers); + return request; + } + + public ModbusRequest buildWriteMultipleRegisters(int serverAddress, int startAddress, byte[] bytes) throws ModbusNumberException { + WriteMultipleRegistersRequest request = new WriteMultipleRegistersRequest(); + setSimpleDataRequestParameters(request, serverAddress, startAddress); + request.setBytes(bytes); + return request; + } + + public ModbusRequest buildWriteSingleRegister(int serverAddress, int startAddress, int register) throws ModbusNumberException { + WriteSingleRegisterRequest request = new WriteSingleRegisterRequest(); + setSimpleDataRequestParameters(request, serverAddress, startAddress); + request.setValue(register); + return request; + } + + public ModbusRequest buildMaskWriteRegister(int serverAddress, int startAddress, int and, int or) throws ModbusNumberException { + MaskWriteRegisterRequest request = new MaskWriteRegisterRequest(); + setSimpleDataRequestParameters(request, serverAddress, startAddress); + request.setMaskAnd(and); + request.setMaskOr(or); + return request; + } + + public ModbusRequest buildReadExceptionStatus(int serverAddress) throws ModbusNumberException { + return setBaseParameter(new ReadExceptionStatusRequest(), serverAddress); + } + + public ModbusRequest buildReportSlaveId(int serverAddress) throws ModbusNumberException { + return setBaseParameter(new ReportSlaveIdRequest(), serverAddress); + } + + public ModbusRequest buildGetCommEventCounter(int serverAddress) throws ModbusNumberException { + return setBaseParameter(new GetCommEventCounterRequest(), serverAddress); + } + + public ModbusRequest buildGetCommEventLog(int serverAddress) throws ModbusNumberException { + return setBaseParameter(new GetCommEventLogRequest(), serverAddress); + } + + public ModbusRequest buildReadFifoQueue(int serverAddress, int fifoPointerAddress) throws ModbusNumberException { + ReadFifoQueueRequest request = new ReadFifoQueueRequest(); + request.setServerAddress(serverAddress); + request.setStartAddress(fifoPointerAddress); + return request; + } + + public ModbusRequest buildReadFileRecord(int serverAddress, ModbusFileRecord[] records) throws ModbusNumberException { + ReadFileRecordRequest request = new ReadFileRecordRequest(); + request.setServerAddress(serverAddress); + request.addFileRecords(Arrays.asList(records)); + return request; + } + + public ModbusRequest buildWriteFileRecord(int serverAddress, ModbusFileRecord record) throws ModbusNumberException { + WriteFileRecordRequest request = new WriteFileRecordRequest(); + request.setServerAddress(serverAddress); + request.setFileRecord(record); + return request; + } + + /** + * The function uses a sub-function code field in the query to define the type of test to + * be performed. The server echoes both the function code and sub-function code in a normal + * response. Some of the diagnostics cause data to be returned from the remote device in the + * data field of a normal response. + * + * @param subFunctionCode a sub-function code + * @param serverAddress a slave address + * @param data request data field + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + * @see DiagnosticsRequest + * @see DiagnosticsSubFunctionCode + */ + public ModbusRequest buildDiagnostics(DiagnosticsSubFunctionCode subFunctionCode, int serverAddress, int data) throws ModbusNumberException { + DiagnosticsRequest request = new DiagnosticsRequest(); + request.setServerAddress(serverAddress); + request.setSubFunctionCode(subFunctionCode); + request.setSubFunctionData(data); + return request; + } + + /** + * The data passed in the request data field is to be returned (looped back) in the response. The + * entire response message should be identical to the request. + * + * @param serverAddress a slave address + * @param queryData request data field + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildReturnQueryData(int serverAddress, int queryData) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.RETURN_QUERY_DATA, serverAddress, queryData); + } + + /** + * The remote device serial line port must be initialized and restarted, and all of its + * communications event counters are cleared. If the port is currently in Listen Only Mode, no + * response is returned. This function is the only one that brings the port out of Listen Only + * Mode. If the port is not currently in Listen Only Mode, a normal response is returned. This + * occurs before the restart is executed. + * When the remote device receives the request, it attempts a restart and executes its power–up + * confidence tests. Successful completion of the tests will bring the port online. + * A request data field contents of FF 00 hex causes the port’s Communications Event Log to be + * cleared also. Contents of 00 00 leave the log as it was prior to the restart. + * + * @param serverAddress a slave address + * @param clearLog causes the port’s Communications Event Log to be cleared + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildRestartCommunicationsOption(int serverAddress, boolean clearLog) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.RESTART_COMMUNICATIONS_OPTION, serverAddress, clearLog ? DiagnosticsRequest.CLEAR_LOG : 0); + } + + /** + * Returns the contents of the remote device’s 16–bit diagnostic register are returned in the response. + * + * @param serverAddress a slave address + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildReturnDiagnosticRegister(int serverAddress) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.RETURN_DIAGNOSTIC_REGISTER, serverAddress, 0); + } + + /** + * The character passed in the request data field becomes the end of message delimiter + * for future messages (replacing the default LF character). This function is useful in cases of a + * Line Feed is not required at the end of ASCII messages. + * + * @param serverAddress a slave address + * @param delimiter request data field + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildChangeAsciiInputDelimiter(int serverAddress, int delimiter) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.CHANGE_ASCII_INPUT_DELIMITER, serverAddress, delimiter); + } + + /** + * Forces the addressed remote device to its Listen Only Mode for MODBUS communications. + * This isolates it from the other devices on the network, allowing them to continue + * communicating without interruption from the addressed remote device. No response is + * returned. + * When the remote device enters its Listen Only Mode, all active communication controls are + * turned off. The Ready watchdog timer is allowed to expire, locking the controls off. While the + * device is in this mode, any MODBUS messages addressed to it or broadcast are monitored, + * but no actions will be taken and no responses will be sent. + * The only function that will be processed after the mode is entered will be the Restart + * Communications Option function (function code 8, sub-function 1). + * + * @param serverAddress a slave address + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildForceListenOnlyMode(int serverAddress) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.FORCE_LISTEN_ONLY_MODE, serverAddress, 0); + } + + /** + * The goal is to clear all counters and the diagnostic register. Counters are also cleared upon power–up. + * + * @param serverAddress a slave address + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildClearCountersAndDiagnosticRegister(int serverAddress) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.CLEAR_COUNTERS_AND_DIAGNOSTIC_REGISTER, serverAddress, 0); + } + + /** + * The response data field returns the quantity of messages that the remote device has detected + * on the communications system since its last restart, clear counters operation, or power–up. + * + * @param serverAddress a slave address + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildReturnBusMessageCount(int serverAddress) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.RETURN_BUS_MESSAGE_COUNT, serverAddress, 0); + } + + /** + * The response data field returns the quantity of CRC errors encountered by the remote device + * since its last restart, clear counters operation, or power–up. + * + * @param serverAddress a slave address + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildReturnBusCommunicationErrorCount(int serverAddress) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.RETURN_BUS_COMMUNICATION_ERROR_COUNT, serverAddress, 0); + } + + /** + * The response data field returns the quantity of MODBUS exception responses returned by the + * remote device since its last restart, clear counters operation, or power–up. + * + * @param serverAddress a slave address + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildReturnBusExceptionErrorCount(int serverAddress) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.RETURN_BUS_EXCEPTION_ERROR_COUNT, serverAddress, 0); + } + + /** + * The response data field returns the quantity of messages addressed to the remote device, or + * broadcast, that the remote device has processed since its last restart, clear counters + * operation, or power–up. + * + * @param serverAddress a slave address + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildReturnSlaveMessageCount(int serverAddress) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.RETURN_SLAVE_MESSAGE_COUNT, serverAddress, 0); + } + + /** + * The response data field returns the quantity of messages addressed to the remote device for + * which it has returned no response (neither a normal response nor an exception response), + * since its last restart, clear counters operation, or power–up. + * + * @param serverAddress a slave address + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildReturnSlaveNoResponseCount(int serverAddress) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.RETURN_SLAVE_NO_RESPONSE_COUNT, serverAddress, 0); + } + + /** + * The response data field returns the quantity of messages addressed to the remote device for + * which it returned a Negative Acknowledge (NAK) exception response, since its last restart, + * clear counters operation, or power–up. + * + * @param serverAddress a slave address + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildReturnSlaveNAKCount(int serverAddress) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.RETURN_SLAVE_NAK_COUNT, serverAddress, 0); + } + + /** + * The response data field returns the quantity of messages addressed to the remote device for + * which it returned a Slave Device Busy exception response, since its last restart, clear + * counters operation, or power–up. + * + * @param serverAddress a slave address + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildReturnSlaveBusyCount(int serverAddress) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.RETURN_SLAVE_BUSY_COUNT, serverAddress, 0); + } + + /** + * The response data field returns the quantity of messages addressed to the remote device that + * it could not handle due to a character overrun condition, since its last restart, clear counters + * operation, or power–up. A character overrun is caused by data characters arriving at the port + * faster than they can be stored, or by the loss of a character due to a hardware malfunction. + * + * @param serverAddress a slave address + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildReturnBusCharacterOverrunCount(int serverAddress) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.RETURN_BUS_CHARACTER_OVERRUN_COUNT, serverAddress, 0); + } + + /** + * Clears the overrun error counter and reset the error flag. + * + * @param serverAddress a slave address + * @return DiagnosticsRequest instance + * @throws ModbusNumberException if server address is in-valid + */ + public ModbusRequest buildClearOverrunCounterAndFlag(int serverAddress) throws ModbusNumberException { + return buildDiagnostics(DiagnosticsSubFunctionCode.CLEAR_OVERRUN_COUNTER_AND_FLAG, serverAddress, 0); + } + + public ModbusRequest buildReadDeviceIdentification(int serverAddress, int objectId, ReadDeviceIdentificationCode readDeviceId) throws ModbusNumberException { + ReadDeviceIdentificationRequest request = new ReadDeviceIdentificationRequest(); + request.setServerAddress(serverAddress); + request.setObjectId(objectId); + request.setReadDeviceId(readDeviceId); + return request; + } + + static private class SingletonHolder { + final static private ModbusRequestBuilder instance = new ModbusRequestBuilder(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/ModbusRequestFactory.java b/src/com/intelligt/modbus/jlibmodbus/msg/ModbusRequestFactory.java new file mode 100644 index 0000000..7707fab --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/ModbusRequestFactory.java @@ -0,0 +1,119 @@ +package com.intelligt.modbus.jlibmodbus.msg; + +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusMessage; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.request.*; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class ModbusRequestFactory implements ModbusMessageFactory { + + private ModbusRequestFactory() { + + } + + static public ModbusRequestFactory getInstance() { + return SingletonHolder.instance; + } + + /** + * This method creates a #ModbusRequest instance from #functionCode + * + * @param functionCode a number representing a modbus function + * @return an instance of a specific ModbusRequest + * @see ModbusRequest + * @see ModbusMessageFactory + * @see ModbusResponseFactory + */ + @Override + public ModbusMessage createMessage(int functionCode) { + ModbusMessage msg; + + switch (ModbusFunctionCode.get(functionCode)) { + case READ_COILS: + msg = new ReadCoilsRequest(); + break; + case READ_DISCRETE_INPUTS: + msg = new ReadDiscreteInputsRequest(); + break; + case READ_HOLDING_REGISTERS: + msg = new ReadHoldingRegistersRequest(); + break; + case READ_INPUT_REGISTERS: + msg = new ReadInputRegistersRequest(); + break; + case WRITE_SINGLE_COIL: + msg = new WriteSingleCoilRequest(); + break; + case WRITE_SINGLE_REGISTER: + msg = new WriteSingleRegisterRequest(); + break; + case WRITE_MULTIPLE_COILS: + msg = new WriteMultipleCoilsRequest(); + break; + case WRITE_MULTIPLE_REGISTERS: + msg = new WriteMultipleRegistersRequest(); + break; + case MASK_WRITE_REGISTER: + msg = new MaskWriteRegisterRequest(); + break; + case READ_WRITE_MULTIPLE_REGISTERS: + msg = new ReadWriteMultipleRegistersRequest(); + break; + case READ_FIFO_QUEUE: + msg = new ReadFifoQueueRequest(); + break; + case READ_FILE_RECORD: + msg = new ReadFileRecordRequest(); + break; + case WRITE_FILE_RECORD: + msg = new WriteFileRecordRequest(); + break; + case READ_EXCEPTION_STATUS: + msg = new ReadExceptionStatusRequest(); + break; + case REPORT_SLAVE_ID: + msg = new ReportSlaveIdRequest(); + break; + case GET_COMM_EVENT_COUNTER: + msg = new GetCommEventCounterRequest(); + break; + case GET_COMM_EVENT_LOG: + msg = new GetCommEventLogRequest(); + break; + case DIAGNOSTICS: + msg = new DiagnosticsRequest(); + break; + case ENCAPSULATED_INTERFACE_TRANSPORT: + msg = new EncapsulatedInterfaceTransportRequest(); + break; + default: + msg = new IllegalFunctionRequest(functionCode); + } + return msg; + } + + static private class SingletonHolder { + final static private ModbusRequestFactory instance = new ModbusRequestFactory(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/ModbusResponseFactory.java b/src/com/intelligt/modbus/jlibmodbus/msg/ModbusResponseFactory.java new file mode 100644 index 0000000..f1a1d9e --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/ModbusResponseFactory.java @@ -0,0 +1,123 @@ +package com.intelligt.modbus.jlibmodbus.msg; + +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusMessage; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.*; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class ModbusResponseFactory implements ModbusMessageFactory { + + private ModbusResponseFactory() { + + } + + static public ModbusResponseFactory getInstance() { + return SingletonHolder.instance; + } + + /** + * This method creates a #ModbusResponse instance from #functionCode + * + * @param functionCode a number representing a modbus function + * @return an instance of a specific ModbusRequest + * @see ModbusRequest + * @see ModbusMessageFactory + * @see ModbusResponseFactory + */ + @Override + public ModbusMessage createMessage(int functionCode) { + ModbusResponse msg; + + switch (ModbusFunctionCode.get(functionCode)) { + case READ_COILS: + msg = new ReadCoilsResponse(); + break; + case READ_DISCRETE_INPUTS: + msg = new ReadDiscreteInputsResponse(); + break; + case READ_HOLDING_REGISTERS: + msg = new ReadHoldingRegistersResponse(); + break; + case READ_INPUT_REGISTERS: + msg = new ReadInputRegistersResponse(); + break; + case WRITE_SINGLE_COIL: + msg = new WriteSingleCoilResponse(); + break; + case WRITE_SINGLE_REGISTER: + msg = new WriteSingleRegisterResponse(); + break; + case WRITE_MULTIPLE_COILS: + msg = new WriteMultipleCoilsResponse(); + break; + case WRITE_MULTIPLE_REGISTERS: + msg = new WriteMultipleRegistersResponse(); + break; + case MASK_WRITE_REGISTER: + msg = new MaskWriteRegisterResponse(); + break; + case READ_WRITE_MULTIPLE_REGISTERS: + msg = new ReadWriteMultipleRegistersResponse(); + break; + case READ_FIFO_QUEUE: + msg = new ReadFifoQueueResponse(); + break; + case READ_FILE_RECORD: + msg = new ReadFileRecordResponse(); + break; + case WRITE_FILE_RECORD: + msg = new WriteFileRecordResponse(); + break; + case READ_EXCEPTION_STATUS: + msg = new ReadExceptionStatusResponse(); + break; + case REPORT_SLAVE_ID: + msg = new ReportSlaveIdResponse(); + break; + case GET_COMM_EVENT_COUNTER: + msg = new GetCommEventCounterResponse(); + break; + case GET_COMM_EVENT_LOG: + msg = new GetCommEventLogResponse(); + break; + case DIAGNOSTICS: + msg = new DiagnosticsResponse(); + break; + case ENCAPSULATED_INTERFACE_TRANSPORT: + msg = new EncapsulatedInterfaceTransportResponse(); + break; + default: + msg = new IllegalFunctionResponse(functionCode); + } + if (ModbusFunctionCode.isException(functionCode)) { + msg.setException(); + } + return msg; + } + + static private class SingletonHolder { + final static private ModbusResponseFactory instance = new ModbusResponseFactory(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractDataRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractDataRequest.java new file mode 100644 index 0000000..c782f71 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractDataRequest.java @@ -0,0 +1,72 @@ +package com.intelligt.modbus.jlibmodbus.msg.base; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +abstract public class AbstractDataRequest extends ModbusRequest { + + private int startAddress; + + protected AbstractDataRequest() { + super(); + } + + abstract protected void writeData(ModbusOutputStream fifo) throws IOException; + + abstract protected void readData(ModbusInputStream fifo) throws IOException, ModbusNumberException; + + @Override + final public void readPDU(ModbusInputStream fifo) throws ModbusNumberException, IOException { + setStartAddress(fifo.readShortBE()); + readData(fifo); + } + + @Override + public void writeRequest(ModbusOutputStream fifo) throws IOException { + fifo.writeShortBE(getStartAddress()); + writeData(fifo); + } + + public int getStartAddress() { + return startAddress; + } + + public void setStartAddress(int startAddress) throws ModbusNumberException { + if (!Modbus.checkStartAddress(startAddress)) { + throw new ModbusNumberException("Error in start address", startAddress); + } + this.startAddress = startAddress; + } + + @Override + final public int requestSize() { + return 2 + dataSize(); + } + + abstract protected int dataSize(); +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractMultipleRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractMultipleRequest.java new file mode 100644 index 0000000..df94364 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractMultipleRequest.java @@ -0,0 +1,63 @@ +package com.intelligt.modbus.jlibmodbus.msg.base; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +abstract public class AbstractMultipleRequest extends AbstractDataRequest { + private int quantity; + + protected AbstractMultipleRequest() { + super(); + } + + @Override + protected void readData(ModbusInputStream fifo) throws IOException, ModbusNumberException { + setQuantity(fifo.readShortBE()); + } + + @Override + protected void writeData(ModbusOutputStream fifo) throws IOException { + fifo.writeShortBE(quantity); + } + + @Override + protected int dataSize() { + return 2; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) throws ModbusNumberException { + if (!checkAddressRange(getStartAddress(), quantity)) + throw new ModbusNumberException("End address out of bounds", getStartAddress() + quantity); + this.quantity = quantity; + } + + protected abstract boolean checkAddressRange(int startAddress, int quantity); +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractReadResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractReadResponse.java new file mode 100644 index 0000000..4899fc7 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractReadResponse.java @@ -0,0 +1,69 @@ +package com.intelligt.modbus.jlibmodbus.msg.base; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +abstract public class AbstractReadResponse extends ModbusResponse { + + private int byteCount = 0; + + protected AbstractReadResponse() { + super(); + } + + public int getByteCount() { + return byteCount; + } + + protected void setByteCount(int byteCount) throws ModbusNumberException { + if (byteCount > (Modbus.MAX_PDU_LENGTH - 2)) + throw new ModbusNumberException("Byte count greater than max allowable"); + this.byteCount = byteCount; + } + + @Override + final public void readResponse(ModbusInputStream fifo) throws IOException, ModbusNumberException { + setByteCount(fifo.read()); + readData(fifo); + } + + @Override + final public void writeResponse(ModbusOutputStream fifo) throws IOException { + fifo.write(getByteCount()); + writeData(fifo); + } + + abstract protected void readData(ModbusInputStream fifo) throws IOException, ModbusNumberException; + + abstract protected void writeData(ModbusOutputStream fifo) throws IOException; + + @Override + final protected int responseSize() { + return 1 + getByteCount(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractWriteMultipleRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractWriteMultipleRequest.java new file mode 100644 index 0000000..c08e61a --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractWriteMultipleRequest.java @@ -0,0 +1,82 @@ +package com.intelligt.modbus.jlibmodbus.msg.base; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +abstract public class AbstractWriteMultipleRequest extends AbstractMultipleRequest { + + private byte[] values; + private int byteCount; + + protected AbstractWriteMultipleRequest() { + super(); + } + + @Override + public void writeData(ModbusOutputStream fifo) throws IOException { + super.writeData(fifo); + fifo.write(getByteCount()); + fifo.write(getBytes()); + } + + @Override + protected void readData(ModbusInputStream fifo) throws IOException, ModbusNumberException { + super.readData(fifo); + setByteCount(fifo.read()); + values = new byte[byteCount]; + int size; + if ((size = fifo.read(values, 0, getByteCount())) < getByteCount()) + Modbus.log().warning(getByteCount() + " bytes expected, but " + size + " received."); + } + + public int getByteCount() { + return byteCount; + } + + public void setByteCount(int byteCount) throws ModbusNumberException { + if (byteCount > Modbus.MAX_WRITE_REGISTER_COUNT * 2) { + //TODO add a description + throw new ModbusNumberException("" + byteCount); + } + this.byteCount = byteCount; + } + + public byte[] getBytes() { + return values; + } + + public void setBytes(byte[] values) throws ModbusNumberException { + this.values = values; + setByteCount(values.length); + } + + @Override + protected int dataSize() { + return super.dataSize() + 1 + getByteCount(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractWriteResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractWriteResponse.java new file mode 100644 index 0000000..26bb8ad --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/AbstractWriteResponse.java @@ -0,0 +1,73 @@ +package com.intelligt.modbus.jlibmodbus.msg.base; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public abstract class AbstractWriteResponse extends ModbusResponse { + private int startAddress = 0; + + protected AbstractWriteResponse() { + super(); + } + + @Override + final protected void readResponse(ModbusInputStream fifo) throws IOException { + try { + setStartAddress(fifo.readShortBE()); + } catch (ModbusNumberException e) { + e.printStackTrace(); + } + readValue(fifo); + } + + @Override + final public void writeResponse(ModbusOutputStream fifo) throws IOException { + fifo.writeShortBE(getStartAddress()); + writeValue(fifo); + } + + abstract protected void readValue(ModbusInputStream fifo) throws IOException; + + abstract protected void writeValue(ModbusOutputStream fifo) throws IOException; + + final public int getStartAddress() { + return startAddress; + } + + public void setStartAddress(int startAddress) throws ModbusNumberException { + if (!(Modbus.checkStartAddress(startAddress))) + throw new ModbusNumberException("Error in start address", startAddress); + this.startAddress = startAddress; + } + + @Override + final protected int responseSize() { + return 4; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusFileRecord.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusFileRecord.java new file mode 100644 index 0000000..4c3ea3a --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusFileRecord.java @@ -0,0 +1,78 @@ +package com.intelligt.modbus.jlibmodbus.msg.base; + +import com.intelligt.modbus.jlibmodbus.exception.IllegalDataValueException; + +import java.util.Arrays; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusFileRecord { + final static public int REF_TYPE = 0x06; + final private int number; + final private int file; + private int length = 0; + private int[] registers; + + public ModbusFileRecord(int fileNumber, int recordNumber, int registerCount) { + this.file = fileNumber; + this.number = recordNumber; + this.length = registerCount; + } + + public ModbusFileRecord(int file, int number, int[] buffer) { + this.file = file; + this.number = number; + setRegisters(buffer); + } + + public int[] getRegisters() { + return Arrays.copyOf(registers, registers.length); + } + + /** + * setter + * + * @param registers modbus register values + */ + protected void setRegisters(int[] registers) { + this.registers = Arrays.copyOf(registers, registers.length); + this.length = registers.length; + } + + public void writeRegisters(int[] registers) throws IllegalDataValueException { + if (registers.length > getRegisters().length) + throw new IllegalDataValueException(); + this.length = registers.length; + } + + public int getFileNumber() { + return file; + } + + public int getRecordNumber() { + return number; + } + + public int getRecordLength() { + return length; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusMessage.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusMessage.java new file mode 100644 index 0000000..e7d95b8 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusMessage.java @@ -0,0 +1,102 @@ +package com.intelligt.modbus.jlibmodbus.msg.base; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +abstract public class ModbusMessage { + + private int serverAddress = Modbus.TCP_DEFAULT_ID; + private int protocolId = Modbus.PROTOCOL_ID; + private int transactionId = 0; + + public ModbusMessage() { + + } + + final public void write(ModbusOutputStream fifo) throws ModbusIOException { + try { + fifo.write(getServerAddress()); + writePDU(fifo); + } catch (IOException e) { + throw new ModbusIOException(e); + } + } + + final public void read(ModbusInputStream fifo) throws ModbusNumberException, ModbusIOException { + try { + readPDU(fifo); + } catch (IOException e) { + throw new ModbusIOException(e); + } + } + + abstract public void readPDU(ModbusInputStream fifo) throws ModbusNumberException, IOException; + + abstract protected void writePDU(ModbusOutputStream fifo) throws IOException; + + abstract public int getFunction(); + + public int size() { + return 1 + pduSize(); + } + + abstract protected int pduSize(); + + public int getServerAddress() { + return serverAddress; + } + + /* + protected ModbusMessage(int serverAddress) throws ModbusNumberException { + setServerAddress(serverAddress); + } + */ + public void setServerAddress(int serverAddress) throws ModbusNumberException { + if (!Modbus.checkServerAddress(serverAddress)) + throw new ModbusNumberException("Error in slave id", serverAddress); + this.serverAddress = serverAddress; + } + + public int getProtocolId() { + return protocolId; + } + + public void setProtocolId(int protocolId) { + this.protocolId = protocolId; + } + + public int getTransactionId() { + return transactionId; + } + + public void setTransactionId(int transactionId) { + this.transactionId = transactionId; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusRequest.java new file mode 100644 index 0000000..935c05f --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusRequest.java @@ -0,0 +1,115 @@ +package com.intelligt.modbus.jlibmodbus.msg.base; + +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.ModbusMessageFactory; +import com.intelligt.modbus.jlibmodbus.msg.ModbusResponseFactory; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +@SuppressWarnings("unchecked") +abstract public class ModbusRequest extends ModbusMessage implements ModbusMessageFactory { + + final private ModbusResponse response; + + public ModbusRequest() { + ModbusResponse response = null; + try { + final Constructor[] constructors = (Constructor[]) getResponseClass().getConstructors(); + for (Constructor c : constructors) { + if (c.getParameterTypes().length == 0) { + response = c.newInstance(); + break; + } + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } finally { + this.response = response; + } + } + + @Override + public void setServerAddress(int serverAddress) throws ModbusNumberException { + super.setServerAddress(serverAddress); + + getResponse().setServerAddress(serverAddress); + } + + public ModbusResponse getResponse() { + return response; + } + + protected abstract Class getResponseClass(); + + abstract public void writeRequest(ModbusOutputStream fifo) throws IOException; + + @Override + final public void writePDU(ModbusOutputStream fifo) throws IOException { + fifo.write(getFunction()); + writeRequest(fifo); + } + + @Override + final protected int pduSize() { + return 1 + requestSize(); + } + + abstract public int requestSize(); + + abstract public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException; + + abstract protected boolean validateResponseImpl(ModbusResponse response); + + public void validateResponse(ModbusResponse msg) throws ModbusNumberException { + if (getProtocolId() != msg.getProtocolId()) + throw new ModbusNumberException("Collision: does not matches the protocol id"); + if (getTransactionId() != msg.getTransactionId()) + throw new ModbusNumberException("Collision: does not matches the transaction id"); + if (getServerAddress() != msg.getServerAddress()) + throw new ModbusNumberException("Does not matches the slave address", msg.getServerAddress()); + if (getFunction() != msg.getFunction()) + throw new ModbusNumberException("Does not matches the function code", msg.getFunction()); + if (!msg.isException()) { + if (!validateResponseImpl(msg)) + throw new ModbusNumberException("Collision: response does not matches the request"); + } + } + + @Override + public ModbusMessage createMessage(int functionCode) { + if (functionCode != getFunction()) { + return ModbusResponseFactory.getInstance().createMessage(functionCode); + } else { + return getResponse(); + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusResponse.java new file mode 100644 index 0000000..71c9c35 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/ModbusResponse.java @@ -0,0 +1,87 @@ +package com.intelligt.modbus.jlibmodbus.msg.base; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusExceptionCode; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public abstract class ModbusResponse extends ModbusMessage { + + private volatile ModbusExceptionCode modbusExceptionCode = ModbusExceptionCode.NO_EXCEPTION; + + protected ModbusResponse() { + super(); + } + + final public boolean isException() { + return getModbusExceptionCode() != ModbusExceptionCode.NO_EXCEPTION; + } + + final public void setException() { + modbusExceptionCode = ModbusExceptionCode.UNKNOWN_EXCEPTION; + } + + @Override + final protected void writePDU(ModbusOutputStream fifo) throws IOException { + if (isException()) { + fifo.write(ModbusFunctionCode.getExceptionValue(getFunction())); + fifo.write(getModbusExceptionCode().getValue()); + } else { + fifo.write(getFunction()); + writeResponse(fifo); + } + } + + @Override + final public void readPDU(ModbusInputStream fifo) throws IOException, ModbusNumberException { + if (isException()) { + setModbusExceptionCode(fifo.read()); + } else { + readResponse(fifo); + } + } + + abstract protected void readResponse(ModbusInputStream fifo) throws IOException, ModbusNumberException; + + abstract protected void writeResponse(ModbusOutputStream fifo) throws IOException; + + final public ModbusExceptionCode getModbusExceptionCode() { + return modbusExceptionCode; + } + + final public void setModbusExceptionCode(int code) { + modbusExceptionCode = ModbusExceptionCode.get(code); + } + + @Override + final protected int pduSize() { + return 1 + responseSize(); + } + + abstract protected int responseSize(); +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/ConformityLevel.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/ConformityLevel.java new file mode 100644 index 0000000..82716bc --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/ConformityLevel.java @@ -0,0 +1,50 @@ +package com.intelligt.modbus.jlibmodbus.msg.base.mei; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public enum ConformityLevel { + BASIC_STREAM_ONLY(0x01), + REGULAR_STREAM_ONLY(0x02), + EXTENDED_STREAM_ONLY(0x03), + BASIC_STREAM_AND_INDIVIDUAL(0x81), + REGULAR_STREAM_AND_INDIVIDUAL(0x82), + EXTENDED_STREAM_AND_INDIVIDUAL(0x83); + + final private int code; + + ConformityLevel(int code) { + this.code = code; + } + + static public ConformityLevel get(int code) { + for (ConformityLevel c : values()) { + if (c.toInt() == code) { + return c; + } + } + return BASIC_STREAM_ONLY; + } + + public int toInt() { + return code; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/MEIFactory.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/MEIFactory.java new file mode 100644 index 0000000..b6cde2f --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/MEIFactory.java @@ -0,0 +1,37 @@ +package com.intelligt.modbus.jlibmodbus.msg.base.mei; + +import com.intelligt.modbus.jlibmodbus.utils.MEITypeCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class MEIFactory { + static public ModbusEncapsulatedInterface getMEI(MEITypeCode meiTypeCode) { + switch (meiTypeCode) { + case READ_DEVICE_IDENTIFICATION: + return new MEIReadDeviceIdentification(); + case CAN_OPEN_PDU: + case RESERVED: + default: + return null; + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/MEIReadDeviceIdentification.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/MEIReadDeviceIdentification.java new file mode 100644 index 0000000..9830e7f --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/MEIReadDeviceIdentification.java @@ -0,0 +1,237 @@ +package com.intelligt.modbus.jlibmodbus.msg.base.mei; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.data.mei.ReadDeviceIdentificationInterface; +import com.intelligt.modbus.jlibmodbus.data.mei.ReadDeviceIdentificationInterface.DataObject; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.MEITypeCode; + +import java.io.IOException; +import java.util.Arrays; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class MEIReadDeviceIdentification implements ModbusEncapsulatedInterface { + + public static final int SIZE_OF_HEADER = 8; + private int objectId = 0; + private ReadDeviceIdentificationCode readDeviceIdCode = ReadDeviceIdentificationCode.BASIC_STREAM_ACCESS; + private ConformityLevel conformityLevel = ConformityLevel.BASIC_STREAM_ONLY; + private boolean moreFollows = false; + private int nextObjectId = 0; + private int numberOfObjects = 0; + private DataObject[] objects = new DataObject[0]; + private int responseSize = 0; + + private int firstObjectIndex = 0; + + @Override + public MEITypeCode getTypeCode() { + return MEITypeCode.READ_DEVICE_IDENTIFICATION; + } + + @Override + public void writeRequest(ModbusOutputStream fifo) throws IOException { + fifo.write(getReadDeviceIdCode().toInt()); + fifo.write(getObjectId()); + } + + @Override + public void readRequest(ModbusInputStream fifo) throws IOException { + setReadDeviceId(ReadDeviceIdentificationCode.get(fifo.read())); + setObjectId(fifo.read()); + } + + @Override + public int getRequestSize() { + return 2; + } + + @Override + public void writeResponse(ModbusOutputStream fifo) throws IOException { + fifo.write(getReadDeviceIdCode().toInt()); + fifo.write(getConformityLevel().toInt()); + fifo.write(isMoreFollows() ? 0xFF : 0x00); + fifo.write(getNextObjectId()); + fifo.write(getNumberOfObjects()); + for (int i = getFirstObjectIndex(); i < getFirstObjectIndex() + getNumberOfObjects(); i++) { + DataObject o = objects[i]; + fifo.write(o.getId()); + fifo.write(o.getValue().length); + fifo.write(o.getValue()); + } + } + + @Override + public void readResponse(ModbusInputStream fifo) throws IOException, ModbusNumberException { + setReadDeviceId(ReadDeviceIdentificationCode.get(fifo.read())); + setConformityLevel(ConformityLevel.get(fifo.read())); + setMoreFollows(fifo.read() == 0xff); + setNextObjectId(fifo.read()); + setNumberOfObjects(fifo.read()); + if (getNumberOfObjects() > 0x7F) { + throw new ModbusNumberException("Illegal number of data objects", getNumberOfObjects()); + } + setObjects(new DataObject[getNumberOfObjects()]); + int size = SIZE_OF_HEADER; + for (int i = 0; i < getNumberOfObjects(); i++) { + int id = fifo.read(); + int length = fifo.read(); + size += 2 + length; + if (size > Modbus.MAX_PDU_LENGTH) + throw new ModbusNumberException("Exceeded max pdu length", size); + byte[] value = new byte[length]; + int read; + if ((read = fifo.read(value)) != length) + Modbus.log().warning(length + " bytes expected, but " + read + " received."); + objects[i] = new DataObject(id, value); + } + setResponseSize(size); + } + + @Override + public int getResponseSize() { + return responseSize; + } + + public void setResponseSize(int responseSize) { + this.responseSize = responseSize; + } + + @Override + public void process(DataHolder dataHolder) { + ReadDeviceIdentificationInterface deviceId = dataHolder.getReadDeviceIdentificationInterface(); + if (deviceId.getExtended().length != 0) { + setConformityLevel(ConformityLevel.EXTENDED_STREAM_AND_INDIVIDUAL); + } else if (deviceId.getRegular().length != 0) { + setConformityLevel(ConformityLevel.REGULAR_STREAM_AND_INDIVIDUAL); + } else { + setConformityLevel(ConformityLevel.BASIC_STREAM_AND_INDIVIDUAL); + } + switch (getReadDeviceIdCode()) { + case BASIC_STREAM_ACCESS: + setObjects(deviceId.getBasic()); + break; + case REGULAR_STREAM_ACCESS: + setObjects(deviceId.getRegular()); + break; + case EXTENDED_STREAM_ACCESS: + setObjects(deviceId.getExtended()); + break; + case ONE_SPECIFIC_INDIVIDUAL_ACCESS: + default: + setObjects(new DataObject[]{deviceId.getValue(getObjectId())}); + } + int size = SIZE_OF_HEADER; + int number_of_objects = 0; + + if (getObjectId() != 0) { + for (int i = 0; i < objects.length && getFirstObjectIndex() == 0; i++) { + if (objects[i].getId() == getObjectId()) { + setFirstObjectIndex(i); + } + } + } + + for (int i = getFirstObjectIndex(); i < objects.length; i++) { + size += objects[i].getValue().length + 2;//object id + object length = 2 + if (size >= Modbus.MAX_PDU_LENGTH) { + break; + } + number_of_objects++; + } + setResponseSize(size); + if ((objects.length - getFirstObjectIndex()) > number_of_objects) { + setNextObjectId(number_of_objects + 1); + } else { + setMoreFollows(false); + } + setNumberOfObjects(number_of_objects); + } + + public int getNumberOfObjects() { + return numberOfObjects; + } + + public void setNumberOfObjects(int numberOfObjects) { + this.numberOfObjects = numberOfObjects; + } + + public int getObjectId() { + return objectId; + } + + public void setObjectId(int objectId) { + this.objectId = objectId; + } + + public ReadDeviceIdentificationCode getReadDeviceIdCode() { + return readDeviceIdCode; + } + + public void setReadDeviceId(ReadDeviceIdentificationCode readDeviceIdCode) { + this.readDeviceIdCode = readDeviceIdCode; + } + + public ConformityLevel getConformityLevel() { + return conformityLevel; + } + + public void setConformityLevel(ConformityLevel conformityLevel) { + this.conformityLevel = conformityLevel; + } + + public boolean isMoreFollows() { + return moreFollows; + } + + public void setMoreFollows(boolean moreFollows) { + this.moreFollows = moreFollows; + } + + public int getNextObjectId() { + return nextObjectId; + } + + public void setNextObjectId(int nextObjectId) { + this.nextObjectId = nextObjectId; + } + + public DataObject[] getObjects() { + return Arrays.copyOf(objects, objects.length); + } + + public void setObjects(DataObject[] objects) { + this.objects = Arrays.copyOf(objects, objects.length); + } + + public int getFirstObjectIndex() { + return firstObjectIndex; + } + + public void setFirstObjectIndex(int firstObjectIndex) { + this.firstObjectIndex = firstObjectIndex; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/ModbusEncapsulatedInterface.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/ModbusEncapsulatedInterface.java new file mode 100644 index 0000000..3be0829 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/ModbusEncapsulatedInterface.java @@ -0,0 +1,48 @@ +package com.intelligt.modbus.jlibmodbus.msg.base.mei; + +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.MEITypeCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public interface ModbusEncapsulatedInterface { + MEITypeCode getTypeCode(); + + void writeRequest(ModbusOutputStream fifo) throws IOException; + + void readRequest(ModbusInputStream fifo) throws IOException; + + int getRequestSize(); + + void writeResponse(ModbusOutputStream fifo) throws IOException; + + void readResponse(ModbusInputStream fifo) throws IOException, ModbusNumberException; + + int getResponseSize(); + + void process(DataHolder dataHolder); +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/ReadDeviceIdentificationCode.java b/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/ReadDeviceIdentificationCode.java new file mode 100644 index 0000000..799b943 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/base/mei/ReadDeviceIdentificationCode.java @@ -0,0 +1,48 @@ +package com.intelligt.modbus.jlibmodbus.msg.base.mei; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public enum ReadDeviceIdentificationCode { + BASIC_STREAM_ACCESS(0x01), + REGULAR_STREAM_ACCESS(0x02), + EXTENDED_STREAM_ACCESS(0x03), + ONE_SPECIFIC_INDIVIDUAL_ACCESS(0x04); + + final private int code; + + ReadDeviceIdentificationCode(int code) { + this.code = code; + } + + static public ReadDeviceIdentificationCode get(int code) { + for (ReadDeviceIdentificationCode c : values()) { + if (c.toInt() == code) { + return c; + } + } + return BASIC_STREAM_ACCESS; + } + + public int toInt() { + return code; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/DiagnosticsRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/DiagnosticsRequest.java new file mode 100644 index 0000000..104955b --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/DiagnosticsRequest.java @@ -0,0 +1,218 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.data.CommStatus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.DiagnosticsResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.DiagnosticsSubFunctionCode; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * MODBUS function code 08 provides a series of tests for checking the communication system + * between a client ( Master) device and a server ( Slave), or for checking various internal error + * conditions within a server. + * The function uses a two–byte sub-function code field in the query to define the type of test to + * be performed. The server echoes both the function code and sub-function code in a normal + * response. Some of the diagnostics cause data to be returned from the remote device in the + * data field of a normal response. + * In general, issuing a diagnostic function to a remote device does not affect the running of the + * user program in the remote device. User logic, like discrete and registers, is not accessed by + * the diagnostics. Certain functions can optionally reset error counters in the remote device. + * A server device can, however, be forced into ‘Listen Only Mode’ in which it will monitor the + * messages on the communications system but not respond to them. This can affect the + * outcome of your application program if it depends upon any further exchange of data with the + * remote device. Generally, the mode is forced to remove a malfunctioning remote device from + * the communications system. + * The following diagnostic functions are dedicated to serial line devices. + * The normal response to the Return Query Data request is to loopback the same data. The + * function code and sub-function codes are also echoed. + */ +public class DiagnosticsRequest extends ModbusRequest { + /** + * Diagnostic uses a two–byte sub-function code field in the query to define the type of test to + * be performed. + */ + final static public int CLEAR_LOG = 0xff00; + private DiagnosticsSubFunctionCode subFunctionCode = DiagnosticsSubFunctionCode.RESERVED; + private int subFunctionData = 0; + + public DiagnosticsRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return DiagnosticsResponse.class; + } + + @Override + public void writeRequest(ModbusOutputStream fifo) throws IOException { + fifo.writeShortBE(getSubFunctionCode().toInt()); + fifo.writeShortBE(getSubFunctionData()); + } + + @Override + public int requestSize() { + return 4; + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + DiagnosticsResponse response = new DiagnosticsResponse(); + response.setServerAddress(getServerAddress()); + response.setSubFunctionCode(getSubFunctionCode()); + CommStatus commStatus = dataHolder.getCommStatus(); + switch (getSubFunctionCode()) { + case RETURN_QUERY_DATA: + response.setSubFunctionData(getSubFunctionData()); + break; + case RESTART_COMMUNICATIONS_OPTION: + if (getSubFunctionData() == 0xff00) { + commStatus.setClearLog(true); + } + commStatus.setRestartCommunicationsOption(true); + response.setSubFunctionData(getSubFunctionData()); + break; + case RETURN_DIAGNOSTIC_REGISTER: + response.setSubFunctionData(commStatus.getDiagnosticRegister()); + break; + case CHANGE_ASCII_INPUT_DELIMITER: + commStatus.setAsciiInputDelimiter((getSubFunctionData() >> 8) & 0xff); + response.setSubFunctionData(getSubFunctionData()); + break; + case FORCE_LISTEN_ONLY_MODE: + commStatus.setListenOnlyMode(true); + break; + case CLEAR_COUNTERS_AND_DIAGNOSTIC_REGISTER: + commStatus.clearCountersAndDiagnosticRegister(); + response.setSubFunctionData(getSubFunctionData()); + break; + case RETURN_BUS_MESSAGE_COUNT: + response.setSubFunctionData(commStatus.getMessageCount()); + break; + case RETURN_BUS_COMMUNICATION_ERROR_COUNT: + response.setSubFunctionData(commStatus.getCommunicationErrorCount()); + break; + case RETURN_BUS_EXCEPTION_ERROR_COUNT: + response.setSubFunctionData(commStatus.getExceptionErrorCount()); + break; + case RETURN_SLAVE_MESSAGE_COUNT: + response.setSubFunctionData(commStatus.getSlaveMessageCount()); + break; + case RETURN_SLAVE_NO_RESPONSE_COUNT: + response.setSubFunctionData(commStatus.getSlaveNoResponseCount()); + break; + case RETURN_SLAVE_NAK_COUNT: + response.setSubFunctionData(commStatus.getSlaveNAKCount()); + break; + case RETURN_SLAVE_BUSY_COUNT: + response.setSubFunctionData(commStatus.getSlaveBusyCount()); + break; + case RETURN_BUS_CHARACTER_OVERRUN_COUNT: + response.setSubFunctionData(commStatus.getCharacterOverrunCount()); + break; + case CLEAR_OVERRUN_COUNTER_AND_FLAG: + commStatus.setCharacterOverrunCount(0); + response.setSubFunctionData(getSubFunctionData()); + break; + case RESERVED: + break; + } + return response; + } + + @Override + protected boolean validateResponseImpl(ModbusResponse response) { + DiagnosticsResponse r = (DiagnosticsResponse) response; + + if (getSubFunctionCode() != r.getSubFunctionCode()) + return false; + + switch (subFunctionCode) { + case RETURN_QUERY_DATA: + case RESTART_COMMUNICATIONS_OPTION: + case CHANGE_ASCII_INPUT_DELIMITER: + case CLEAR_COUNTERS_AND_DIAGNOSTIC_REGISTER: + case CLEAR_OVERRUN_COUNTER_AND_FLAG: + return getSubFunctionData() == r.getSubFunctionData(); + case FORCE_LISTEN_ONLY_MODE: + break; + case RETURN_DIAGNOSTIC_REGISTER: + break; + case RETURN_BUS_MESSAGE_COUNT: + break; + case RETURN_BUS_COMMUNICATION_ERROR_COUNT: + break; + case RETURN_BUS_EXCEPTION_ERROR_COUNT: + break; + case RETURN_SLAVE_MESSAGE_COUNT: + break; + case RETURN_SLAVE_NO_RESPONSE_COUNT: + break; + case RETURN_SLAVE_NAK_COUNT: + break; + case RETURN_SLAVE_BUSY_COUNT: + break; + case RETURN_BUS_CHARACTER_OVERRUN_COUNT: + break; + case RESERVED: + break; + } + return true; + } + + @Override + public void readPDU(ModbusInputStream fifo) throws ModbusNumberException, IOException { + setSubFunctionCode(DiagnosticsSubFunctionCode.get(fifo.readShortBE())); + setSubFunctionData(fifo.readShortBE()); + } + + public int getSubFunctionData() { + return subFunctionData; + } + + public void setSubFunctionData(int subFunctionData) { + this.subFunctionData = subFunctionData; + } + + public DiagnosticsSubFunctionCode getSubFunctionCode() { + return subFunctionCode; + } + + public void setSubFunctionCode(DiagnosticsSubFunctionCode subFunctionCode) { + this.subFunctionCode = subFunctionCode; + } + + @Override + public int getFunction() { + return ModbusFunctionCode.DIAGNOSTICS.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/EncapsulatedInterfaceTransportRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/EncapsulatedInterfaceTransportRequest.java new file mode 100644 index 0000000..cdaaf9b --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/EncapsulatedInterfaceTransportRequest.java @@ -0,0 +1,101 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.base.mei.MEIFactory; +import com.intelligt.modbus.jlibmodbus.msg.base.mei.ModbusEncapsulatedInterface; +import com.intelligt.modbus.jlibmodbus.msg.response.EncapsulatedInterfaceTransportResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.MEITypeCode; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class EncapsulatedInterfaceTransportRequest extends ModbusRequest { + + private ModbusEncapsulatedInterface mei = null; + + public EncapsulatedInterfaceTransportRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return EncapsulatedInterfaceTransportResponse.class; + } + + public void setMEIType(MEITypeCode meiTypeCode) { + setMei(MEIFactory.getMEI(meiTypeCode)); + } + + @Override + public void writeRequest(ModbusOutputStream fifo) throws IOException { + fifo.write(mei.getTypeCode().toInt()); + mei.writeRequest(fifo); + } + + @Override + public void readPDU(ModbusInputStream fifo) throws ModbusNumberException, IOException { + int meiTypeCode = fifo.read(); + if ((mei = MEIFactory.getMEI(MEITypeCode.get(meiTypeCode))) == null) { + throw new ModbusNumberException("Unknown MEI type", meiTypeCode); + } + mei.readRequest(fifo); + } + + @Override + public int requestSize() { + return 1 + (mei == null ? 0 : mei.getRequestSize()); + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + EncapsulatedInterfaceTransportResponse response = new EncapsulatedInterfaceTransportResponse(); + response.setServerAddress(getServerAddress()); + mei.process(dataHolder); + response.setMei(mei); + return response; + } + + public ModbusEncapsulatedInterface getMei() { + return mei; + } + + public void setMei(ModbusEncapsulatedInterface mei) { + this.mei = mei; + } + + @Override + protected boolean validateResponseImpl(ModbusResponse response) { + return response instanceof EncapsulatedInterfaceTransportResponse && mei.getTypeCode() == ((EncapsulatedInterfaceTransportResponse) response).getMei().getTypeCode(); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.ENCAPSULATED_INTERFACE_TRANSPORT.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/GetCommEventCounterRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/GetCommEventCounterRequest.java new file mode 100644 index 0000000..ea0808a --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/GetCommEventCounterRequest.java @@ -0,0 +1,79 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.GetCommEventCounterResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class GetCommEventCounterRequest extends ModbusRequest { + + public GetCommEventCounterRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return GetCommEventCounterResponse.class; + } + + @Override + public void writeRequest(ModbusOutputStream fifo) throws IOException { + //no op + } + + @Override + public int requestSize() { + return 0; + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + GetCommEventCounterResponse response = new GetCommEventCounterResponse(); + response.setServerAddress(getServerAddress()); + response.setEventCount(dataHolder.getCommStatus().getEventCount()); + response.setStatus(dataHolder.getCommStatus().getCommStatus()); + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + return true; + } + + @Override + public void readPDU(ModbusInputStream fifo) throws ModbusNumberException, IOException { + //no op + } + + @Override + public int getFunction() { + return ModbusFunctionCode.GET_COMM_EVENT_COUNTER.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/GetCommEventLogRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/GetCommEventLogRequest.java new file mode 100644 index 0000000..31175d6 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/GetCommEventLogRequest.java @@ -0,0 +1,83 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.data.CommStatus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.GetCommEventLogResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class GetCommEventLogRequest extends ModbusRequest { + + public GetCommEventLogRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return GetCommEventLogResponse.class; + } + + @Override + public void writeRequest(ModbusOutputStream fifo) throws IOException { + //no op + } + + @Override + public int requestSize() { + return 0; + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + GetCommEventLogResponse response = new GetCommEventLogResponse(); + response.setServerAddress(getServerAddress()); + CommStatus commStatus = dataHolder.getCommStatus(); + response.setEventCount(commStatus.getEventCount()); + response.setStatus(commStatus.getCommStatus()); + response.setMessageCount(commStatus.getMessageCount()); + response.setEvents(commStatus.getEventLog()); + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + return true; + } + + @Override + public void readPDU(ModbusInputStream fifo) throws ModbusNumberException, IOException { + //no op + } + + @Override + public int getFunction() { + return ModbusFunctionCode.GET_COMM_EVENT_LOG.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/IllegalFunctionRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/IllegalFunctionRequest.java new file mode 100644 index 0000000..43ef796 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/IllegalFunctionRequest.java @@ -0,0 +1,80 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.IllegalFunctionResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class IllegalFunctionRequest extends ModbusRequest { + + final private int functionCode; + + public IllegalFunctionRequest(int functionCode) { + super(); + + this.functionCode = functionCode; + } + + @Override + protected Class getResponseClass() { + return IllegalFunctionResponse.class; + } + + @Override + public void writeRequest(ModbusOutputStream fifo) throws IOException { + throw new IOException("Can't send Illegal request"); + } + + @Override + public int requestSize() { + return 0; + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + IllegalFunctionResponse response = (IllegalFunctionResponse) getResponse(); + response.setFunctionCode(getFunction()); + return response; + } + + @Override + protected boolean validateResponseImpl(ModbusResponse response) { + return response.getFunction() == getFunction(); + } + + @Override + public void readPDU(ModbusInputStream fifo) throws ModbusNumberException, IOException { + //no op + } + + @Override + public int getFunction() { + return functionCode; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/MaskWriteRegisterRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/MaskWriteRegisterRequest.java new file mode 100644 index 0000000..44de915 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/MaskWriteRegisterRequest.java @@ -0,0 +1,116 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractDataRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.MaskWriteRegisterResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class MaskWriteRegisterRequest extends AbstractDataRequest { + + private int maskAnd; + private int maskOr; + + public MaskWriteRegisterRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return MaskWriteRegisterResponse.class; + } + + /*result = ((reg & and) | (or & !and))*/ + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + MaskWriteRegisterResponse response = (MaskWriteRegisterResponse) getResponse(); + response.setStartAddress(getStartAddress()); + response.setMaskAnd(getMaskAnd()); + response.setMaskOr(getMaskOr()); + + try { + int reg = dataHolder.readHoldingRegister(getStartAddress()); + dataHolder.writeHoldingRegister(getStartAddress(), (reg & getMaskAnd()) | (getMaskOr() & (~getMaskAnd()))); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + if (!(response instanceof MaskWriteRegisterResponse)) { + return false; + } + MaskWriteRegisterResponse r = (MaskWriteRegisterResponse) response; + return (r.getStartAddress() == getStartAddress()) && + (r.getMaskAnd() == getMaskAnd()) && + (r.getMaskOr() == getMaskOr()); + } + + @Override + protected void readData(ModbusInputStream fifo) throws IOException { + setMaskAnd(fifo.readShortBE()); + setMaskOr(fifo.readShortBE()); + } + + @Override + public void writeData(ModbusOutputStream fifo) throws IOException { + fifo.writeShortBE(getMaskAnd()); + fifo.writeShortBE(getMaskOr()); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.MASK_WRITE_REGISTER.toInt(); + } + + @Override + protected int dataSize() { + return 4; + } + + public int getMaskAnd() { + return maskAnd; + } + + public void setMaskAnd(int maskAnd) { + this.maskAnd = maskAnd; + } + + public int getMaskOr() { + return maskOr; + } + + public void setMaskOr(int maskOr) { + this.maskOr = maskOr; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadCoilsRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadCoilsRequest.java new file mode 100644 index 0000000..ba1b566 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadCoilsRequest.java @@ -0,0 +1,81 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractMultipleRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.ReadCoilsResponse; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public class ReadCoilsRequest extends AbstractMultipleRequest { + + public ReadCoilsRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return ReadCoilsResponse.class; + } + + @Override + final public boolean checkAddressRange(int startAddress, int quantity) { + return Modbus.checkReadCoilCount(quantity) && + Modbus.checkStartAddress(startAddress) && + /* + * registers quantity equals to rounded value of coils quantity/16 + */ + Modbus.checkEndAddress(startAddress + (int) Math.ceil((double) quantity / 16)); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_COILS.toInt(); + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + ReadCoilsResponse response = (ReadCoilsResponse) getResponse(); + try { + boolean[] range = dataHolder.readCoilRange(getStartAddress(), getQuantity()); + response.setCoils(range); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + if (!(response instanceof ReadCoilsResponse)) { + return false; + } + ReadCoilsResponse r = (ReadCoilsResponse) response; + return (r.getByteCount() == ReadCoilsResponse.calcByteCount(getQuantity())); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadDeviceIdentificationRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadDeviceIdentificationRequest.java new file mode 100644 index 0000000..3ee4bb1 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadDeviceIdentificationRequest.java @@ -0,0 +1,42 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.msg.base.mei.MEIReadDeviceIdentification; +import com.intelligt.modbus.jlibmodbus.msg.base.mei.ReadDeviceIdentificationCode; +import com.intelligt.modbus.jlibmodbus.utils.MEITypeCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ReadDeviceIdentificationRequest extends EncapsulatedInterfaceTransportRequest { + + public ReadDeviceIdentificationRequest() { + super(); + setMEIType(MEITypeCode.READ_DEVICE_IDENTIFICATION); + } + + public void setObjectId(int objectId) { + ((MEIReadDeviceIdentification) getMei()).setObjectId(objectId); + } + + public void setReadDeviceId(ReadDeviceIdentificationCode readDeviceId) { + ((MEIReadDeviceIdentification) getMei()).setReadDeviceId(readDeviceId); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadDiscreteInputsRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadDiscreteInputsRequest.java new file mode 100644 index 0000000..c0cd320 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadDiscreteInputsRequest.java @@ -0,0 +1,70 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.ReadCoilsResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.ReadDiscreteInputsResponse; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +final public class ReadDiscreteInputsRequest extends ReadCoilsRequest { + + public ReadDiscreteInputsRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return ReadDiscreteInputsResponse.class; + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + ReadDiscreteInputsResponse response = (ReadDiscreteInputsResponse) getResponse(); + try { + boolean[] range = dataHolder.readDiscreteInputRange(getStartAddress(), getQuantity()); + response.setCoils(range); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_DISCRETE_INPUTS.toInt(); + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + if (!(response instanceof ReadDiscreteInputsResponse)) { + return false; + } + ReadDiscreteInputsResponse r = (ReadDiscreteInputsResponse) response; + return (r.getByteCount() == ReadCoilsResponse.calcByteCount(getQuantity())); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadExceptionStatusRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadExceptionStatusRequest.java new file mode 100644 index 0000000..7edb8f3 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadExceptionStatusRequest.java @@ -0,0 +1,84 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.ReadExceptionStatusResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class ReadExceptionStatusRequest extends ModbusRequest { + + public ReadExceptionStatusRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return ReadExceptionStatusResponse.class; + } + + @Override + public void writeRequest(ModbusOutputStream fifo) throws IOException { + //no operation + } + + @Override + public int requestSize() { + return 0; + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + ReadExceptionStatusResponse response = (ReadExceptionStatusResponse) getResponse(); + try { + int exceptionStatus = dataHolder.readExceptionStatus(); + response.setExceptionStatus(exceptionStatus); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + return true; + } + + @Override + public void readPDU(ModbusInputStream fifo) throws ModbusNumberException, IOException { + //no operation + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_EXCEPTION_STATUS.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadFifoQueueRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadFifoQueueRequest.java new file mode 100644 index 0000000..d377b82 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadFifoQueueRequest.java @@ -0,0 +1,85 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractDataRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.ReadFifoQueueResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ReadFifoQueueRequest extends AbstractDataRequest { + + public ReadFifoQueueRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return ReadFifoQueueResponse.class; + } + + @Override + protected void writeData(ModbusOutputStream fifo) throws IOException { + //no op + } + + @Override + protected void readData(ModbusInputStream fifo) throws IOException, ModbusNumberException { + //no op + } + + @Override + protected int dataSize() { + return 0; + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + ReadFifoQueueResponse response = new ReadFifoQueueResponse(); + response.setServerAddress(getServerAddress()); + try { + int[] r = dataHolder.readFifoQueue(getStartAddress()); + response.setFifoValueRegister(r); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + return true; + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_FIFO_QUEUE.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadFileRecordRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadFileRecordRequest.java new file mode 100644 index 0000000..c8c8c0a --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadFileRecordRequest.java @@ -0,0 +1,132 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusFileRecord; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.ReadFileRecordResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class ReadFileRecordRequest extends ModbusRequest { + final static public int READ__SUB_REQ_LENGTH = 7; + final List records = new ArrayList(); + + public ReadFileRecordRequest() { + super(); + } + + public void addFileRecord(ModbusFileRecord record) { + this.records.add(record); + } + + public void addFileRecords(Collection records) { + this.records.addAll(records); + } + + @Override + protected Class getResponseClass() { + return ReadFileRecordResponse.class; + } + + @Override + public void writeRequest(ModbusOutputStream fifo) throws IOException { + fifo.write(READ__SUB_REQ_LENGTH * records.size()); + for (ModbusFileRecord record : records) { + fifo.write(ModbusFileRecord.REF_TYPE); + fifo.writeShortBE(record.getFileNumber()); + fifo.writeShortBE(record.getRecordNumber()); + fifo.writeShortBE(record.getRecordLength()); + } + } + + @Override + public void readPDU(ModbusInputStream fifo) throws ModbusNumberException, IOException { + int byteCount = fifo.read(); + if (byteCount > (Modbus.MAX_PDU_LENGTH - 2)) + throw new ModbusNumberException("Byte count greater than max allowable"); + int read = 0; + while (read < byteCount) { + if (fifo.read() != ModbusFileRecord.REF_TYPE) + throw new ModbusNumberException("Reference type mismatch."); + int file_number = fifo.readShortBE(); + int record_number = fifo.readShortBE(); + int record_length = fifo.readShortBE(); + read += READ__SUB_REQ_LENGTH; + records.add(new ModbusFileRecord(file_number, record_number, record_length)); + } + } + + @Override + public int requestSize() { + return 1 + READ__SUB_REQ_LENGTH * records.size(); + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + ReadFileRecordResponse response = (ReadFileRecordResponse) getResponse(); + try { + for (ModbusFileRecord r : records) { + dataHolder.readFileRecord(r); + } + /* + TODO: it's required to reduce the number of data-copying-operations here + */ + response.setFileRecords((ModbusFileRecord[]) records.toArray()); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + protected boolean validateResponseImpl(ModbusResponse response) { + if (!(response instanceof ReadFileRecordResponse)) { + return false; + } + ModbusFileRecord[] respRecords = ((ReadFileRecordResponse) response).getFileRecords(); + if (records.size() != respRecords.length) + return false; + for (int i = 0; i < records.size(); i++) { + if (respRecords[i].getRecordLength() != records.get(i).getRecordLength()) + return false; + } + return true; + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_FILE_RECORD.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadHoldingRegistersRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadHoldingRegistersRequest.java new file mode 100644 index 0000000..0d21d58 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadHoldingRegistersRequest.java @@ -0,0 +1,79 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractMultipleRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.ReadHoldingRegistersResponse; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public class ReadHoldingRegistersRequest extends AbstractMultipleRequest { + + public ReadHoldingRegistersRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return ReadHoldingRegistersResponse.class; + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + ReadHoldingRegistersResponse response = (ReadHoldingRegistersResponse) getResponse(); + response.setServerAddress(getServerAddress()); + try { + int[] range = dataHolder.readHoldingRegisterRange(getStartAddress(), getQuantity()); + response.setBuffer(range); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + if (!(response instanceof ReadHoldingRegistersResponse)) { + return false; + } + ReadHoldingRegistersResponse r = (ReadHoldingRegistersResponse) response; + return (r.getByteCount() == getQuantity() * 2); + } + + @Override + public boolean checkAddressRange(int startAddress, int quantity) { + return Modbus.checkReadRegisterCount(quantity) && + Modbus.checkStartAddress(startAddress) && + Modbus.checkEndAddress(startAddress + quantity); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_HOLDING_REGISTERS.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadInputRegistersRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadInputRegistersRequest.java new file mode 100644 index 0000000..302fdd2 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadInputRegistersRequest.java @@ -0,0 +1,70 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.ReadInputRegistersResponse; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +final public class ReadInputRegistersRequest extends ReadHoldingRegistersRequest { + + public ReadInputRegistersRequest() { + super(); + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + ReadInputRegistersResponse response = (ReadInputRegistersResponse) getResponse(); + response.setServerAddress(getServerAddress()); + try { + int[] range = dataHolder.readInputRegisterRange(getStartAddress(), getQuantity()); + response.setBuffer(range); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + if (!(response instanceof ReadInputRegistersResponse)) { + return false; + } + ReadInputRegistersResponse r = (ReadInputRegistersResponse) response; + return r.getByteCount() == getQuantity() * 2; + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_INPUT_REGISTERS.toInt(); + } + + @Override + protected Class getResponseClass() { + return ReadInputRegistersResponse.class; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadWriteMultipleRegistersRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadWriteMultipleRegistersRequest.java new file mode 100644 index 0000000..bb59eea --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReadWriteMultipleRegistersRequest.java @@ -0,0 +1,132 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.ReadWriteMultipleRegistersResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +//facade +public class ReadWriteMultipleRegistersRequest extends ModbusRequest { + + final private ReadHoldingRegistersRequest reader; + final private WriteMultipleRegistersRequest writer; + + public ReadWriteMultipleRegistersRequest() { + super(); + reader = new ReadHoldingRegistersRequest(); + writer = new WriteMultipleRegistersRequest(); + } + + @Override + protected Class getResponseClass() { + return ReadWriteMultipleRegistersResponse.class; + } + + @Override + public void writeRequest(ModbusOutputStream fifo) throws IOException { + reader.writeRequest(fifo); + writer.writeRequest(fifo); + } + + @Override + public int requestSize() { + return reader.requestSize() + writer.requestSize(); + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + ReadWriteMultipleRegistersResponse response = (ReadWriteMultipleRegistersResponse) getResponse(); + try { + dataHolder.writeHoldingRegisterRange(writer.getStartAddress(), writer.getRegisters()); + int[] range = dataHolder.readHoldingRegisterRange(reader.getStartAddress(), reader.getQuantity()); + response.setBuffer(range); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + if (!(response instanceof ReadWriteMultipleRegistersResponse)) { + return false; + } + ReadWriteMultipleRegistersResponse r = (ReadWriteMultipleRegistersResponse) response; + return r.getByteCount() == reader.getQuantity() * 2; + } + + @Override + public void readPDU(ModbusInputStream fifo) throws ModbusNumberException, IOException { + reader.readPDU(fifo); + writer.readPDU(fifo); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_WRITE_MULTIPLE_REGISTERS.toInt(); + } + + @Override + public void setServerAddress(int serverAddress) throws ModbusNumberException { + super.setServerAddress(serverAddress); + + reader.setServerAddress(serverAddress); + writer.setServerAddress(serverAddress); + } + + public int getReadAddress() { + return reader.getStartAddress(); + } + + /* + facade + */ + public void setReadAddress(int address) throws ModbusNumberException { + reader.setStartAddress(address); + } + + public int getReadQuantity() { + return reader.getQuantity(); + } + + public void setReadQuantity(int quantity) throws ModbusNumberException { + reader.setQuantity(quantity); + } + + public void setWriteAddress(int address) throws ModbusNumberException { + writer.setStartAddress(address); + } + + public void setWriteRegisters(int[] registers) throws ModbusNumberException { + writer.setRegisters(registers); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/ReportSlaveIdRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReportSlaveIdRequest.java new file mode 100644 index 0000000..4fe164a --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/ReportSlaveIdRequest.java @@ -0,0 +1,84 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.ReportSlaveIdResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class ReportSlaveIdRequest extends ModbusRequest { + + public ReportSlaveIdRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return ReportSlaveIdResponse.class; + } + + @Override + public void writeRequest(ModbusOutputStream fifo) throws IOException { + //no operation + } + + @Override + public int requestSize() { + return 0; + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + ReportSlaveIdResponse response = (ReportSlaveIdResponse) getResponse(); + try { + byte[] slaveId = dataHolder.readSlaveId(); + response.setSlaveId(slaveId); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + return true; + } + + @Override + public void readPDU(ModbusInputStream fifo) throws ModbusNumberException, IOException { + //no operation + } + + @Override + public int getFunction() { + return ModbusFunctionCode.REPORT_SLAVE_ID.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteFileRecordRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteFileRecordRequest.java new file mode 100644 index 0000000..3c4af11 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteFileRecordRequest.java @@ -0,0 +1,122 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusFileRecord; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.WriteFileRecordResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class WriteFileRecordRequest extends ModbusRequest { + + final static public int READ_SUB_REQ_LENGTH = 7; + private ModbusFileRecord fileRecord = null; + + public WriteFileRecordRequest() { + super(); + } + + public ModbusFileRecord getFileRecord() { + return fileRecord; + } + + public void setFileRecord(ModbusFileRecord record) { + this.fileRecord = record; + } + + @Override + protected Class getResponseClass() { + return WriteFileRecordResponse.class; + } + + @Override + public void writeRequest(ModbusOutputStream fifo) throws IOException { + ModbusFileRecord record = getFileRecord(); + fifo.write(READ_SUB_REQ_LENGTH + record.getRecordLength() * 2); + fifo.write(ModbusFileRecord.REF_TYPE); + fifo.writeShortBE(record.getFileNumber()); + fifo.writeShortBE(record.getRecordNumber()); + fifo.writeShortBE(record.getRecordLength()); + fifo.write(DataUtils.toByteArray(record.getRegisters())); + } + + @Override + public void readPDU(ModbusInputStream fifo) throws ModbusNumberException, IOException { + int byteCount = fifo.read(); + if (byteCount > (Modbus.MAX_PDU_LENGTH - 2)) + throw new ModbusNumberException("Byte count greater than max allowable"); + if (fifo.read() != ModbusFileRecord.REF_TYPE) + throw new ModbusNumberException("Reference type mismatch."); + int file_number = fifo.readShortBE(); + int record_number = fifo.readShortBE(); + int record_length = fifo.readShortBE(); + byte[] buffer = new byte[record_length * 2]; + if (fifo.read(buffer) != buffer.length) + throw new ModbusNumberException(record_length + " bytes expected, but not received."); + setFileRecord(new ModbusFileRecord(file_number, record_number, DataUtils.BeToIntArray(buffer))); + } + + @Override + public int requestSize() { + return 1 + READ_SUB_REQ_LENGTH * getFileRecord().getRecordLength() * 2; + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + WriteFileRecordResponse response = (WriteFileRecordResponse) getResponse(); + response.setFileRecord(getFileRecord()); + try { + dataHolder.writeFileRecord(response.getFileRecord()); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + protected boolean validateResponseImpl(ModbusResponse response) { + if (!(response instanceof WriteFileRecordResponse)) { + return false; + } + ModbusFileRecord reqRecord = getFileRecord(); + ModbusFileRecord respRecord = ((WriteFileRecordResponse) response).getFileRecord(); + return !(respRecord.getFileNumber() != reqRecord.getFileNumber() || + respRecord.getRecordNumber() != reqRecord.getRecordNumber() || + respRecord.getRecordLength() != reqRecord.getRecordLength()); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.WRITE_FILE_RECORD.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteMultipleCoilsRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteMultipleCoilsRequest.java new file mode 100644 index 0000000..e9ce41b --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteMultipleCoilsRequest.java @@ -0,0 +1,103 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractWriteMultipleRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.WriteMultipleCoilsResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +final public class WriteMultipleCoilsRequest extends AbstractWriteMultipleRequest { + + public WriteMultipleCoilsRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return WriteMultipleCoilsResponse.class; + } + + @Override + protected boolean checkAddressRange(int startAddress, int quantity) { + return Modbus.checkWriteCoilCount(quantity) && + Modbus.checkStartAddress(startAddress) && + Modbus.checkEndAddress(startAddress + quantity); + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + WriteMultipleCoilsResponse response = (WriteMultipleCoilsResponse) getResponse(); + response.setStartAddress(getStartAddress()); + response.setQuantity(getQuantity()); + try { + dataHolder.writeCoilRange(getStartAddress(), getCoils()); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + if (!(response instanceof WriteMultipleCoilsResponse)) { + return false; + } + WriteMultipleCoilsResponse r = (WriteMultipleCoilsResponse) response; + return r.getStartAddress() == getStartAddress() && r.getValue() == getQuantity(); + } + + @Override + public void readData(ModbusInputStream fifo) throws IOException, ModbusNumberException { + super.readData(fifo); + if ((int) Math.ceil((double) getQuantity() / 8) != getByteCount()) { + throw new ModbusNumberException("Byte count not matches quantity/8", getByteCount()); + } + if (!checkAddressRange(getStartAddress(), getQuantity())) + throw new ModbusNumberException("Coil count greater than max coil count", getQuantity()); + setCoils(DataUtils.toBitsArray(getBytes(), getQuantity())); + } + + public boolean[] getCoils() { + return DataUtils.toBitsArray(getBytes(), getQuantity()); + } + + public void setCoils(boolean[] coils) throws ModbusNumberException { + setBytes(DataUtils.toByteArray(coils)); + setQuantity(coils.length); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.WRITE_MULTIPLE_COILS.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteMultipleRegistersRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteMultipleRegistersRequest.java new file mode 100644 index 0000000..b3fa403 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteMultipleRegistersRequest.java @@ -0,0 +1,123 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractWriteMultipleRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.WriteMultipleRegistersResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; +import java.util.Arrays; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +final public class WriteMultipleRegistersRequest extends AbstractWriteMultipleRequest { + + public WriteMultipleRegistersRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return WriteMultipleRegistersResponse.class; + } + + @Override + public void setByteCount(int byteCount) throws ModbusNumberException { + if (byteCount % 2 != 0) { + throw new ModbusNumberException("bytes.length=" + byteCount + " should be an even number"); + } + super.setByteCount(byteCount); + setQuantity(byteCount / 2); + } + + @Override + protected boolean checkAddressRange(int startAddress, int quantity) { + return Modbus.checkWriteRegisterCount(quantity) && + Modbus.checkStartAddress(startAddress) && + Modbus.checkEndAddress(startAddress + quantity); + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + WriteMultipleRegistersResponse response = (WriteMultipleRegistersResponse) getResponse(); + response.setStartAddress(getStartAddress()); + response.setQuantity(getQuantity()); + try { + dataHolder.writeHoldingRegisterRange(getStartAddress(), getRegisters()); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + if (!(response instanceof WriteMultipleRegistersResponse)) { + return false; + } + WriteMultipleRegistersResponse r = (WriteMultipleRegistersResponse) response; + return r.getStartAddress() == getStartAddress() && r.getValue() == getQuantity(); + } + + @Override + public void readData(ModbusInputStream fifo) throws IOException, ModbusNumberException { + super.readData(fifo); + if (getQuantity() * 2 != getByteCount()) { + throw new ModbusNumberException("Byte count not matches quantity*2", getByteCount()); + } + if (!checkAddressRange(getStartAddress(), getQuantity())) + throw new ModbusNumberException("Register count greater than max register count", getQuantity()); + } + + public int[] getRegisters() { + return DataUtils.BeToIntArray(getBytes()); + } + + public void setRegisters(int[] registers) throws ModbusNumberException { + super.setBytes(DataUtils.toByteArray(registers)); + setByteCount(registers.length * 2); + } + + @Override + public byte[] getBytes() { + return Arrays.copyOf(super.getBytes(), super.getByteCount()); + } + + @Override + public void setBytes(byte[] values) throws ModbusNumberException { + super.setBytes(Arrays.copyOf(values, values.length)); + setByteCount(values.length); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.WRITE_MULTIPLE_REGISTERS.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteSingleCoilRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteSingleCoilRequest.java new file mode 100644 index 0000000..88a386b --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteSingleCoilRequest.java @@ -0,0 +1,78 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.WriteSingleCoilResponse; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class WriteSingleCoilRequest extends WriteSingleRegisterRequest { + + public WriteSingleCoilRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return WriteSingleCoilResponse.class; + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + WriteSingleCoilResponse response = (WriteSingleCoilResponse) getResponse(); + response.setStartAddress(getStartAddress()); + response.setValue(getValue()); + try { + dataHolder.writeCoil(getStartAddress(), getCoil()); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + if (!(response instanceof WriteSingleCoilResponse)) { + return false; + } + WriteSingleCoilResponse r = (WriteSingleCoilResponse) response; + return r.getStartAddress() == getStartAddress() && r.getValue() == getValue(); + } + + public boolean getCoil() { + return Modbus.toCoil(getValue()); + } + + public void setCoil(boolean coil) throws ModbusNumberException { + setValue(Modbus.fromCoil(coil)); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.WRITE_SINGLE_COIL.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteSingleRegisterRequest.java b/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteSingleRegisterRequest.java new file mode 100644 index 0000000..3448d3f --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/request/WriteSingleRegisterRequest.java @@ -0,0 +1,107 @@ +package com.intelligt.modbus.jlibmodbus.msg.request; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusProtocolException; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractDataRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.response.WriteSingleRegisterResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class WriteSingleRegisterRequest extends AbstractDataRequest { + + private int value; + + public WriteSingleRegisterRequest() { + super(); + } + + @Override + protected Class getResponseClass() { + return WriteSingleRegisterResponse.class; + } + + @Override + public ModbusResponse process(DataHolder dataHolder) throws ModbusNumberException { + WriteSingleRegisterResponse response = (WriteSingleRegisterResponse) getResponse(); + response.setStartAddress(getStartAddress()); + response.setValue(getValue()); + try { + dataHolder.writeHoldingRegister(getStartAddress(), getValue()); + } catch (ModbusProtocolException e) { + response.setException(); + response.setModbusExceptionCode(e.getException().getValue()); + } + return response; + } + + @Override + public boolean validateResponseImpl(ModbusResponse response) { + if (!(response instanceof WriteSingleRegisterResponse)) { + return false; + } + WriteSingleRegisterResponse r = (WriteSingleRegisterResponse) response; + return r.getStartAddress() == getStartAddress() && r.getValue() == getValue(); + } + + @Override + final protected void readData(ModbusInputStream fifo) throws IOException { + try { + setValue(fifo.readShortBE()); + } catch (ModbusNumberException e) { + e.printStackTrace(); + } + } + + @Override + public int getFunction() { + return ModbusFunctionCode.WRITE_SINGLE_REGISTER.toInt(); + } + + @Override + final public void writeData(ModbusOutputStream fifo) throws IOException { + fifo.writeShortBE(getValue()); + } + + @Override + protected int dataSize() { + return 2; + } + + public int getValue() { + return value; + } + + public void setValue(int value) throws ModbusNumberException { + if (!Modbus.checkRegisterValue(value)) { + throw new ModbusNumberException("Register value out of range", value); + } + this.value = ((short) value) & 0xffff; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/BroadcastResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/BroadcastResponse.java new file mode 100644 index 0000000..2ceafc5 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/BroadcastResponse.java @@ -0,0 +1,59 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * [https://github.com/kochedykov/jlibmodbus] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class BroadcastResponse extends ModbusResponse { + + private int functionCode = ModbusFunctionCode.UNKNOWN.toInt(); + + @Override + public int getFunction() { + return functionCode; + } + + public void setFunction(int functionCode) { + this.functionCode = functionCode; + } + + @Override + protected void readResponse(ModbusInputStream fifo) throws IOException, ModbusNumberException { + //do nothing + } + + @Override + protected void writeResponse(ModbusOutputStream fifo) throws IOException { + //do nothing + } + + @Override + protected int responseSize() { + return 0; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/DiagnosticsResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/DiagnosticsResponse.java new file mode 100644 index 0000000..e5ee1f1 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/DiagnosticsResponse.java @@ -0,0 +1,79 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.DiagnosticsSubFunctionCode; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class DiagnosticsResponse extends ModbusResponse { + + private DiagnosticsSubFunctionCode subFunctionCode; + private int subFunctionData = 0; + + public DiagnosticsResponse() { + super(); + } + + @Override + protected void readResponse(ModbusInputStream fifo) throws IOException, ModbusNumberException { + setSubFunctionCode(DiagnosticsSubFunctionCode.get(fifo.readShortBE())); + setSubFunctionData(fifo.readShortBE()); + } + + @Override + protected void writeResponse(ModbusOutputStream fifo) throws IOException { + fifo.writeShortBE(getSubFunctionCode().toInt()); + fifo.writeShortBE(getSubFunctionData()); + } + + @Override + protected int responseSize() { + return 4; + } + + @Override + public int getFunction() { + return ModbusFunctionCode.DIAGNOSTICS.toInt(); + } + + public DiagnosticsSubFunctionCode getSubFunctionCode() { + return subFunctionCode; + } + + public void setSubFunctionCode(DiagnosticsSubFunctionCode subFunctionCode) { + this.subFunctionCode = subFunctionCode; + } + + public int getSubFunctionData() { + return subFunctionData; + } + + public void setSubFunctionData(int subFunctionData) { + this.subFunctionData = subFunctionData; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/EncapsulatedInterfaceTransportResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/EncapsulatedInterfaceTransportResponse.java new file mode 100644 index 0000000..b97fe59 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/EncapsulatedInterfaceTransportResponse.java @@ -0,0 +1,74 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.base.mei.MEIFactory; +import com.intelligt.modbus.jlibmodbus.msg.base.mei.ModbusEncapsulatedInterface; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.MEITypeCode; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class EncapsulatedInterfaceTransportResponse extends ModbusResponse { + + private ModbusEncapsulatedInterface mei = null; + + public EncapsulatedInterfaceTransportResponse() { + super(); + } + + @Override + protected void readResponse(ModbusInputStream fifo) throws IOException, ModbusNumberException { + int meiTypeCode = fifo.read(); + setMei(MEIFactory.getMEI(MEITypeCode.get(meiTypeCode))); + if (getMei() == null) + throw new ModbusNumberException("Unknown MEI type", meiTypeCode); + getMei().readResponse(fifo); + } + + @Override + protected void writeResponse(ModbusOutputStream fifo) throws IOException { + fifo.write(getMei().getTypeCode().toInt()); + getMei().writeResponse(fifo); + } + + public ModbusEncapsulatedInterface getMei() { + return mei; + } + + public void setMei(ModbusEncapsulatedInterface mei) { + this.mei = mei; + } + + @Override + protected int responseSize() { + return 1 + (mei == null ? 0 : mei.getResponseSize()); + } + + public int getFunction() { + return ModbusFunctionCode.ENCAPSULATED_INTERFACE_TRANSPORT.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/GetCommEventCounterResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/GetCommEventCounterResponse.java new file mode 100644 index 0000000..6a514d4 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/GetCommEventCounterResponse.java @@ -0,0 +1,77 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class GetCommEventCounterResponse extends ModbusResponse { + + private int status; + private int eventCount; + + public GetCommEventCounterResponse() { + super(); + } + + @Override + protected void readResponse(ModbusInputStream fifo) throws IOException { + setStatus(fifo.readShortBE()); + setEventCount(fifo.readShortBE()); + } + + @Override + protected void writeResponse(ModbusOutputStream fifo) throws IOException { + fifo.writeShortBE(getStatus()); + fifo.writeShortBE(getEventCount()); + } + + @Override + protected int responseSize() { + return 4; + } + + @Override + public int getFunction() { + return ModbusFunctionCode.GET_COMM_EVENT_COUNTER.toInt(); + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public int getEventCount() { + return eventCount; + } + + public void setEventCount(int eventCount) { + this.eventCount = eventCount; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/GetCommEventLogResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/GetCommEventLogResponse.java new file mode 100644 index 0000000..aa27e94 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/GetCommEventLogResponse.java @@ -0,0 +1,116 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.comm.ModbusCommEvent; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class GetCommEventLogResponse extends ModbusResponse { + + public static final int EVENTS_OFFSET = 6; + private int status; + private int eventCount; + private int messageCount; + private List events = new LinkedList(); + + public GetCommEventLogResponse() { + super(); + } + + @Override + protected void readResponse(ModbusInputStream fifo) throws IOException, ModbusNumberException { + int byteCount = fifo.read(); + if (byteCount < EVENTS_OFFSET || byteCount > Modbus.MAX_PDU_LENGTH - 2) + throw new ModbusNumberException("Illegal byte count", byteCount); + setStatus(fifo.readShortBE()); + setEventCount(fifo.readShortBE()); + setMessageCount(fifo.readShortBE()); + int eventsCount = byteCount - EVENTS_OFFSET; + if (eventsCount > 0) { + for (int i = 0; i < eventsCount; i++) { + events.add(ModbusCommEvent.getEvent(fifo.read())); + } + } + } + + @Override + protected void writeResponse(ModbusOutputStream fifo) throws IOException { + fifo.write(EVENTS_OFFSET + events.size()); + fifo.writeShortBE(getStatus()); + fifo.writeShortBE(getEventCount()); + fifo.writeShortBE(getMessageCount()); + for (ModbusCommEvent event : getEventQueue()) { + fifo.write(event.getEvent()); + } + } + + @Override + protected int responseSize() { + return EVENTS_OFFSET + events.size(); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.GET_COMM_EVENT_LOG.toInt(); + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public int getEventCount() { + return eventCount; + } + + public void setEventCount(int eventCount) { + this.eventCount = eventCount; + } + + public List getEventQueue() { + return events; + } + + public void setEvents(List events) { + this.events = events; + } + + public int getMessageCount() { + return messageCount; + } + + public void setMessageCount(int messageCount) { + this.messageCount = messageCount; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/IllegalFunctionResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/IllegalFunctionResponse.java new file mode 100644 index 0000000..ca954ab --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/IllegalFunctionResponse.java @@ -0,0 +1,63 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class IllegalFunctionResponse extends ModbusResponse { + private int functionCode = 0; + + public IllegalFunctionResponse(int functionCode) { + super(); + this.functionCode = functionCode; + setException(); + } + + @Override + public int getFunction() { + return functionCode; + } + + public void setFunctionCode(int functionCode) { + this.functionCode = functionCode; + } + + @Override + protected void readResponse(ModbusInputStream fifo) throws IOException, ModbusNumberException { + //no op + } + + @Override + protected void writeResponse(ModbusOutputStream fifo) throws IOException { + //no op + } + + @Override + protected int responseSize() { + return 0; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/MaskWriteRegisterResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/MaskWriteRegisterResponse.java new file mode 100644 index 0000000..2e398e1 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/MaskWriteRegisterResponse.java @@ -0,0 +1,74 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractWriteResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class MaskWriteRegisterResponse extends AbstractWriteResponse { + + private int maskAnd; + private int maskOr; + + public MaskWriteRegisterResponse() { + super(); + } + + @Override + protected void readValue(ModbusInputStream fifo) throws IOException { + setMaskAnd(fifo.readShortBE()); + setMaskOr(fifo.readShortBE()); + } + + @Override + protected void writeValue(ModbusOutputStream fifo) throws IOException { + fifo.writeShortBE(getMaskAnd()); + fifo.writeShortBE(getMaskOr()); + } + + + @Override + public int getFunction() { + return ModbusFunctionCode.MASK_WRITE_REGISTER.toInt(); + } + + public int getMaskAnd() { + return maskAnd; + } + + public void setMaskAnd(int maskAnd) { + this.maskAnd = maskAnd; + } + + public int getMaskOr() { + return maskOr; + } + + public void setMaskOr(int maskOr) { + this.maskOr = maskOr; + } + +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadCoilsResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadCoilsResponse.java new file mode 100644 index 0000000..769c072 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadCoilsResponse.java @@ -0,0 +1,92 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.ModbusCoils; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractReadResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; +import java.util.Arrays; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ReadCoilsResponse extends AbstractReadResponse { + + private byte[] buffer = new byte[0]; + + public ReadCoilsResponse() { + super(); + } + + static public int calcByteCount(boolean[] coils) { + return calcByteCount(coils.length); + } + + static public int calcByteCount(int coilCount) { + return (int) Math.ceil((double) coilCount / 8); + } + + /** + * returns a copy of the raw byte-buffer + * + * @return registers bytes + */ + final public byte[] getBytes() { + return Arrays.copyOf(buffer, buffer.length); + } + + @Deprecated + final public boolean[] getCoils() { + return DataUtils.toBitsArray(buffer, buffer.length * 8); + } + + final public ModbusCoils getModbusCoils() { + return new ModbusCoils(buffer); + } + + final public void setCoils(boolean[] coils) throws ModbusNumberException { + this.buffer = DataUtils.toByteArray(coils); + setByteCount(calcByteCount(coils)); + } + + @Override + final protected void readData(ModbusInputStream fifo) throws IOException { + buffer = new byte[getByteCount()]; + int size; + if ((size = fifo.read(buffer)) < buffer.length) + Modbus.log().warning(buffer.length + " bytes expected, but " + size + " received."); + } + + @Override + final protected void writeData(ModbusOutputStream fifo) throws IOException { + fifo.write(buffer); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_COILS.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadDiscreteInputsResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadDiscreteInputsResponse.java new file mode 100644 index 0000000..6415201 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadDiscreteInputsResponse.java @@ -0,0 +1,36 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class ReadDiscreteInputsResponse extends ReadCoilsResponse { + + public ReadDiscreteInputsResponse() { + super(); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_DISCRETE_INPUTS.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadExceptionStatusResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadExceptionStatusResponse.java new file mode 100644 index 0000000..ad7fd08 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadExceptionStatusResponse.java @@ -0,0 +1,66 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class ReadExceptionStatusResponse extends ModbusResponse { + + private int exceptionStatus = 0; + + public ReadExceptionStatusResponse() { + super(); + } + + public int getExceptionStatus() { + return exceptionStatus; + } + + public void setExceptionStatus(int exceptionStatus) { + this.exceptionStatus = (byte) exceptionStatus & 0xff; + } + + @Override + protected void readResponse(ModbusInputStream fifo) throws IOException { + setExceptionStatus(fifo.read()); + } + + @Override + protected void writeResponse(ModbusOutputStream fifo) throws IOException { + fifo.write(getExceptionStatus()); + } + + @Override + protected int responseSize() { + return 1; + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_EXCEPTION_STATUS.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadFifoQueueResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadFifoQueueResponse.java new file mode 100644 index 0000000..9af7358 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadFifoQueueResponse.java @@ -0,0 +1,86 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ReadFifoQueueResponse extends ModbusResponse { + + private byte[] bytes; + + public ReadFifoQueueResponse() { + super(); + } + + private void checkFifoCount(int fifoCount) throws ModbusNumberException { + if (fifoCount > Modbus.MAX_FIFO_COUNT) + throw new ModbusNumberException("Fifo count greater than max fifo count", fifoCount); + } + + @Override + protected void readResponse(ModbusInputStream fifo) throws IOException, ModbusNumberException { + int byteCount = fifo.readShortBE(); + int fifoCount = fifo.readShortBE(); + if ((fifoCount * 2) != byteCount) + throw new ModbusNumberException("Fifo count not matches bytes*2", fifoCount); + checkFifoCount(fifoCount); + bytes = new byte[byteCount]; + if (fifo.read(bytes) != byteCount) { + throw new IOException("Can't read fifo value register"); + } + } + + @Override + protected void writeResponse(ModbusOutputStream fifo) throws IOException { + int[] r = getFifoValueRegister(); + fifo.writeShortBE(r.length * 2); + fifo.writeShortBE(r.length); + fifo.write(DataUtils.toByteArray(r)); + } + + @Override + protected int responseSize() { + return 2 + 2 + (bytes != null ? bytes.length : 0); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_FIFO_QUEUE.toInt(); + } + + public int[] getFifoValueRegister() { + return DataUtils.BeToIntArray(bytes); + } + + public void setFifoValueRegister(int[] fifoValueRegister) throws ModbusNumberException { + checkFifoCount(fifoValueRegister.length); + this.bytes = DataUtils.toByteArray(fifoValueRegister); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadFileRecordResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadFileRecordResponse.java new file mode 100644 index 0000000..d925ae1 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadFileRecordResponse.java @@ -0,0 +1,97 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractReadResponse; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusFileRecord; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class ReadFileRecordResponse extends AbstractReadResponse { + + public static final int READ_RESP_SUB_REQ_LENGTH = 2; + private List records; + + public ReadFileRecordResponse() { + super(); + this.records = new ArrayList(); + } + + @Override + protected void readData(ModbusInputStream fifo) throws IOException, ModbusNumberException { + int response_byte_count = getByteCount(); + int read = 0; + int i = 0; + while (read < response_byte_count) { + int record_byte_count = fifo.read() * 2; + if (fifo.read() != ModbusFileRecord.REF_TYPE) + throw new ModbusNumberException("Reference type mismatch."); + read += READ_RESP_SUB_REQ_LENGTH; + if (record_byte_count > response_byte_count - read) { + record_byte_count = response_byte_count - read; + } + byte[] buffer = new byte[record_byte_count]; + if (fifo.read(buffer) != record_byte_count) + throw new ModbusNumberException(record_byte_count + " bytes expected, but not received."); + read += record_byte_count; + ModbusFileRecord mfr = new ModbusFileRecord(0, i++, DataUtils.BeToIntArray(buffer)); + records.add(mfr); + } + setFileRecords(records.toArray(new ModbusFileRecord[records.size()])); + } + + @Override + protected void writeData(ModbusOutputStream fifo) throws IOException { + for (ModbusFileRecord r : getFileRecords()) { + fifo.write(r.getRecordLength()); + fifo.write(ModbusFileRecord.REF_TYPE); + fifo.write(DataUtils.toByteArray(r.getRegisters())); + } + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_FILE_RECORD.toInt(); + } + + public ModbusFileRecord[] getFileRecords() { + return (ModbusFileRecord[]) records.toArray(); + } + + public void setFileRecords(ModbusFileRecord[] fileRecords) throws ModbusNumberException { + records = Arrays.asList(fileRecords); + + int byteCount = 0; + for (ModbusFileRecord r : getFileRecords()) { + byteCount += 2 + r.getRecordLength() * 2; + } + setByteCount(byteCount); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadHoldingRegistersResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadHoldingRegistersResponse.java new file mode 100644 index 0000000..2167f17 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadHoldingRegistersResponse.java @@ -0,0 +1,87 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.ModbusHoldingRegisters; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractReadResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; +import java.util.Arrays; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ReadHoldingRegistersResponse extends AbstractReadResponse { + + private byte[] buffer = new byte[0]; + + public ReadHoldingRegistersResponse() { + super(); + } + + /** + * returns a copy of the raw byte-buffer + * + * @return registers bytes + */ + synchronized final public byte[] getBytes() { + return Arrays.copyOf(buffer, buffer.length); + } + + @Deprecated + synchronized final public int[] getRegisters() { + return DataUtils.BeToIntArray(buffer); + } + + synchronized final public ModbusHoldingRegisters getHoldingRegisters() { + ModbusHoldingRegisters mhr = new ModbusHoldingRegisters(); + mhr.setBytesBe(buffer); + return mhr; + } + + synchronized final public void setBuffer(int[] registers) throws ModbusNumberException { + this.buffer = DataUtils.toByteArray(registers); + setByteCount(this.buffer.length); + } + + @Override + synchronized final protected void readData(ModbusInputStream fifo) throws IOException { + if (buffer.length != getByteCount()) + buffer = new byte[getByteCount()]; + int size; + if ((size = fifo.read(buffer, 0, getByteCount())) < getByteCount()) + Modbus.log().warning(getByteCount() + " bytes expected, but " + size + " received."); + } + + @Override + synchronized final protected void writeData(ModbusOutputStream fifo) throws IOException { + fifo.write(buffer, 0, getByteCount()); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_HOLDING_REGISTERS.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadInputRegistersResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadInputRegistersResponse.java new file mode 100644 index 0000000..bd5cb89 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadInputRegistersResponse.java @@ -0,0 +1,36 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class ReadInputRegistersResponse extends ReadHoldingRegistersResponse { + + public ReadInputRegistersResponse() { + super(); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_INPUT_REGISTERS.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadWriteMultipleRegistersResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadWriteMultipleRegistersResponse.java new file mode 100644 index 0000000..570b898 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReadWriteMultipleRegistersResponse.java @@ -0,0 +1,36 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class ReadWriteMultipleRegistersResponse extends ReadHoldingRegistersResponse { + + public ReadWriteMultipleRegistersResponse() { + super(); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.READ_WRITE_MULTIPLE_REGISTERS.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/ReportSlaveIdResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReportSlaveIdResponse.java new file mode 100644 index 0000000..a1e2704 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/ReportSlaveIdResponse.java @@ -0,0 +1,73 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractReadResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; +import java.util.Arrays; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class ReportSlaveIdResponse extends AbstractReadResponse { + + private byte[] slaveId; + + public ReportSlaveIdResponse() { + super(); + } + + public byte[] getSlaveId() { + return slaveId != null ? Arrays.copyOf(slaveId, slaveId.length) : new byte[0]; + } + + public void setSlaveId(byte[] slaveId) throws ModbusNumberException { + if ((slaveId.length + 2) > Modbus.MAX_PDU_LENGTH) + throw new ModbusNumberException("Slave Id greater than max pdu length: ", getByteCount()); + setByteCount(slaveId.length); + this.slaveId = Arrays.copyOf(slaveId, slaveId.length); + } + + @Override + protected void readData(ModbusInputStream fifo) throws IOException { + if (Modbus.MAX_PDU_LENGTH < responseSize()) { + throw new IOException("Slave Id greater than max pdu length: " + getByteCount()); + } + slaveId = new byte[getByteCount()]; + int size; + if ((size = fifo.read(slaveId)) < slaveId.length) + Modbus.log().warning(slaveId.length + " bytes expected, but " + size + " received."); + } + + @Override + protected void writeData(ModbusOutputStream fifo) throws IOException { + fifo.write(slaveId); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.REPORT_SLAVE_ID.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteFileRecordResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteFileRecordResponse.java new file mode 100644 index 0000000..fb433bd --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteFileRecordResponse.java @@ -0,0 +1,87 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusFileRecord; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class WriteFileRecordResponse extends ModbusResponse { + + final static public int READ_SUB_REQ_LENGTH = 7; + private ModbusFileRecord record = null; + + public WriteFileRecordResponse() { + super(); + } + + @Override + protected void readResponse(ModbusInputStream fifo) throws IOException, ModbusNumberException { + int byteCount = fifo.read(); + if (byteCount > (Modbus.MAX_PDU_LENGTH - 2)) + throw new ModbusNumberException("Byte count greater than max allowable"); + if (fifo.read() != ModbusFileRecord.REF_TYPE) + throw new ModbusNumberException("Reference type mismatch."); + int file_number = fifo.readShortBE(); + int record_number = fifo.readShortBE(); + int record_length = fifo.readShortBE(); + byte[] buffer = new byte[record_length * 2]; + if (fifo.read(buffer) != buffer.length) + throw new ModbusNumberException(record_length + " bytes expected, but not received."); + record = new ModbusFileRecord(file_number, record_number, DataUtils.BeToIntArray(buffer)); + } + + @Override + protected void writeResponse(ModbusOutputStream fifo) throws IOException { + fifo.write(READ_SUB_REQ_LENGTH + record.getRecordLength() * 2); + fifo.write(ModbusFileRecord.REF_TYPE); + fifo.writeShortBE(record.getFileNumber()); + fifo.writeShortBE(record.getRecordNumber()); + fifo.writeShortBE(record.getRecordLength()); + fifo.write(DataUtils.toByteArray(record.getRegisters())); + } + + public ModbusFileRecord getFileRecord() { + return record; + } + + public void setFileRecord(ModbusFileRecord record) { + this.record = record; + } + + @Override + protected int responseSize() { + return 1 + READ_SUB_REQ_LENGTH * record.getRecordLength() * 2; + } + + @Override + public int getFunction() { + return ModbusFunctionCode.WRITE_FILE_RECORD.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteMultipleCoilsResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteMultipleCoilsResponse.java new file mode 100644 index 0000000..ffad1a7 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteMultipleCoilsResponse.java @@ -0,0 +1,51 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class WriteMultipleCoilsResponse extends WriteSingleRegisterResponse { + + public WriteMultipleCoilsResponse() { + super(); + } + + public int getQuantity() { + return getValue(); + } + + public void setQuantity(int quantity) throws ModbusNumberException { + setValue(quantity); + } + + @Override + protected boolean checkValue() { + return Modbus.checkWriteCoilCount(getValue()); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.WRITE_MULTIPLE_COILS.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteMultipleRegistersResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteMultipleRegistersResponse.java new file mode 100644 index 0000000..7f9d3fd --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteMultipleRegistersResponse.java @@ -0,0 +1,51 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class WriteMultipleRegistersResponse extends WriteSingleRegisterResponse { + + public WriteMultipleRegistersResponse() { + super(); + } + + public int getQuantity() { + return getValue(); + } + + public void setQuantity(int quantity) throws ModbusNumberException { + setValue(quantity); + } + + @Override + protected boolean checkValue() { + return Modbus.checkWriteRegisterCount(getValue()); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.WRITE_MULTIPLE_REGISTERS.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteSingleCoilResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteSingleCoilResponse.java new file mode 100644 index 0000000..30acd63 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteSingleCoilResponse.java @@ -0,0 +1,51 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class WriteSingleCoilResponse extends WriteSingleRegisterResponse { + + public WriteSingleCoilResponse() { + super(); + } + + public boolean getCoil() { + return Modbus.toCoil(getValue()); + } + + public void setCoil(boolean coil) throws ModbusNumberException { + setValue(Modbus.fromCoil(coil)); + } + + @Override + protected boolean checkValue() { + return getValue() == Modbus.COIL_VALUE_ON || getValue() == Modbus.COIL_VALUE_OFF; + } + + @Override + public int getFunction() { + return ModbusFunctionCode.WRITE_SINGLE_COIL.toInt(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteSingleRegisterResponse.java b/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteSingleRegisterResponse.java new file mode 100644 index 0000000..7898ca1 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/msg/response/WriteSingleRegisterResponse.java @@ -0,0 +1,73 @@ +package com.intelligt.modbus.jlibmodbus.msg.response; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.AbstractWriteResponse; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.ModbusFunctionCode; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class WriteSingleRegisterResponse extends AbstractWriteResponse { + + int value; + + public WriteSingleRegisterResponse() { + super(); + } + + @Override + final protected void readValue(ModbusInputStream fifo) throws IOException { + try { + setValue(fifo.readShortBE()); + } catch (ModbusNumberException e) { + e.printStackTrace(); + } + } + + @Override + final protected void writeValue(ModbusOutputStream fifo) throws IOException { + fifo.writeShortBE(getValue()); + } + + protected boolean checkValue() { + return Modbus.checkRegisterValue(getValue()); + } + + @Override + public int getFunction() { + return ModbusFunctionCode.WRITE_SINGLE_REGISTER.toInt(); + } + + final public int getValue() { + return value; + } + + final public void setValue(int value) throws ModbusNumberException { + this.value = ((short) value) & 0xffff; + if (!checkValue()) + throw new ModbusNumberException("Error in register value", value); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnection.java b/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnection.java new file mode 100644 index 0000000..5279a77 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnection.java @@ -0,0 +1,92 @@ +package com.intelligt.modbus.jlibmodbus.net; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingOutputStream; +import com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransport; +import com.intelligt.modbus.jlibmodbus.utils.FrameEventListenerListImpl; + +import java.util.concurrent.atomic.AtomicBoolean; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +abstract public class ModbusConnection extends FrameEventListenerListImpl { + + private int readTimeout = Modbus.MAX_RESPONSE_TIMEOUT; + final private AtomicBoolean opened = new AtomicBoolean(false); + + abstract public LoggingOutputStream getOutputStream(); + + abstract public LoggingInputStream getInputStream(); + + abstract public ModbusTransport getTransport(); + + final public void open() throws ModbusIOException { + openImpl(); + + setOpened(true); + getOutputStream().setListenerList(this); + getInputStream().setListenerList(this); + } + + final public void close() throws ModbusIOException { + try { + closeImpl(); + } finally { + setOpened(false); + } + } + + abstract protected void openImpl() throws ModbusIOException; + + abstract protected void closeImpl() throws ModbusIOException; + + public int getReadTimeout() { + return readTimeout; + } + + public void setReadTimeout(int timeout) { + readTimeout = timeout; + if (getTransport() != null) { + LoggingInputStream is = getInputStream(); + if (is != null) { + is.setReadTimeout(timeout); + } + } + } + + @Override + protected void finalize() + throws Throwable { + super.finalize(); + close(); + } + + public boolean isOpened() { + return opened.get(); + } + + private void setOpened(boolean opened) { + this.opened.set(opened); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionASCII.java b/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionASCII.java new file mode 100644 index 0000000..1596e2f --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionASCII.java @@ -0,0 +1,32 @@ +package com.intelligt.modbus.jlibmodbus.net; + +import com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransportFactory; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +class ModbusConnectionASCII extends ModbusConnectionSerial { + + ModbusConnectionASCII(SerialPort serial) { + super(serial, ModbusTransportFactory.createASCII(serial)); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionFactory.java b/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionFactory.java new file mode 100644 index 0000000..21c182c --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionFactory.java @@ -0,0 +1,47 @@ +package com.intelligt.modbus.jlibmodbus.net; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; +import com.intelligt.modbus.jlibmodbus.tcp.TcpParameters; + +import java.net.Socket; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public class ModbusConnectionFactory { + static public ModbusConnection getASCII(SerialPort serial) { + return new ModbusConnectionASCII(serial); + } + + static public ModbusConnection getRTU(SerialPort serial) { + return new ModbusConnectionRTU(serial); + } + + static public ModbusConnection getTcpMaster(TcpParameters tcpParameters) { + return new ModbusMasterConnectionTCP(tcpParameters); + } + + static public ModbusConnection getTcpSlave(Socket socket) throws ModbusIOException { + return new ModbusSlaveConnectionTCP(socket); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionRTU.java b/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionRTU.java new file mode 100644 index 0000000..60c13b9 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionRTU.java @@ -0,0 +1,32 @@ +package com.intelligt.modbus.jlibmodbus.net; + +import com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransportFactory; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +class ModbusConnectionRTU extends ModbusConnectionSerial { + + ModbusConnectionRTU(SerialPort serial) { + super(serial, ModbusTransportFactory.createRTU(serial)); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionSerial.java b/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionSerial.java new file mode 100644 index 0000000..5862510 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/ModbusConnectionSerial.java @@ -0,0 +1,86 @@ +package com.intelligt.modbus.jlibmodbus.net; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingOutputStream; +import com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransport; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; +import com.intelligt.modbus.jlibmodbus.serial.SerialPortException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * this class is an extension of the ModbusConnection class + * to implement features for all serial port based connections. + * + * @see ModbusConnectionRTU + * @see ModbusConnectionASCII + * @see ModbusConnection + */ +abstract class ModbusConnectionSerial extends ModbusConnection { + + /** + * instance of SerialPort class, + * which is a wrapper for concrete serial API implementation. + * + * @see SerialPort + */ + final private SerialPort serial; + final private ModbusTransport transport; + + ModbusConnectionSerial(SerialPort serial, ModbusTransport transport) { + this.serial = serial; + this.transport = transport; + } + + @Override + protected void openImpl() throws ModbusIOException { + if (!isOpened()) { + try { + this.serial.open(); + } catch (SerialPortException e) { + throw new ModbusIOException(e); + } + } + } + + @Override + protected void closeImpl() { + this.serial.close(); + } + + @Override + public LoggingOutputStream getOutputStream() { + return transport.getOutputStream(); + } + + @Override + public LoggingInputStream getInputStream() { + return transport.getInputStream(); + } + + @Override + public ModbusTransport getTransport() { + return transport; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/ModbusMasterConnectionTCP.java b/src/com/intelligt/modbus/jlibmodbus/net/ModbusMasterConnectionTCP.java new file mode 100644 index 0000000..c305026 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/ModbusMasterConnectionTCP.java @@ -0,0 +1,97 @@ +package com.intelligt.modbus.jlibmodbus.net; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingOutputStream; +import com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransport; +import com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransportFactory; +import com.intelligt.modbus.jlibmodbus.tcp.TcpParameters; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Socket; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +class ModbusMasterConnectionTCP extends ModbusConnection { + + final private TcpParameters parameters; + private ModbusTransport transport = null; + + ModbusMasterConnectionTCP(TcpParameters parameters) { + this.parameters = parameters; + } + + @Override + public LoggingOutputStream getOutputStream() { + return transport.getOutputStream(); + } + + @Override + public LoggingInputStream getInputStream() { + return transport.getInputStream(); + } + + @Override + public ModbusTransport getTransport() { + return transport; + } + + @Override + protected void openImpl() throws ModbusIOException { + if (!isOpened()) { + if (parameters != null) { + InetSocketAddress isa = new InetSocketAddress(parameters.getHost(), parameters.getPort()); + Socket socket = new Socket(); + try { + socket.connect(isa, parameters.getConnectionTimeout()); + socket.setKeepAlive(parameters.isKeepAlive()); + + transport = ModbusTransportFactory.createTCP(socket); + setReadTimeout(getReadTimeout()); + } catch (Exception e) { + try { + socket.close(); + } catch (IOException e1) { + // ignored + } + throw new ModbusIOException(e); + } + } else { + throw new ModbusIOException("TCP parameters is null"); + } + } + } + + @Override + protected void closeImpl() throws ModbusIOException { + try { + if (transport != null) { + transport.close(); + } + } catch (IOException e) { + throw new ModbusIOException(e); + } finally { + transport = null; + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/ModbusSlaveConnectionTCP.java b/src/com/intelligt/modbus/jlibmodbus/net/ModbusSlaveConnectionTCP.java new file mode 100644 index 0000000..277f727 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/ModbusSlaveConnectionTCP.java @@ -0,0 +1,94 @@ +package com.intelligt.modbus.jlibmodbus.net; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingOutputStream; +import com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransport; +import com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransportFactory; +import com.intelligt.modbus.jlibmodbus.tcp.TcpParameters; +import com.intelligt.modbus.jlibmodbus.utils.TcpClientInfo; + +import java.io.IOException; +import java.net.Socket; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusSlaveConnectionTCP extends ModbusConnection { + + private Socket socket; + private ModbusTransport transport = null; + private final TcpClientInfo clientInfo; + + ModbusSlaveConnectionTCP(Socket socket) throws ModbusIOException { + try { + this.socket = socket; + transport = ModbusTransportFactory.createTCP(socket); + clientInfo = new TcpClientInfo(new TcpParameters(socket.getInetAddress(), socket.getPort(), socket.getKeepAlive()), false); + + open(); + } catch (Exception e) { + throw new ModbusIOException(e); + } + } + + @Override + public LoggingOutputStream getOutputStream() { + return transport.getOutputStream(); + } + + @Override + public LoggingInputStream getInputStream() { + return transport.getInputStream(); + } + + @Override + public ModbusTransport getTransport() { + return transport; + } + + @Override + protected void openImpl() throws ModbusIOException { + clientInfo.setConnected(true); + } + + @Override + protected void closeImpl() throws ModbusIOException { + try { + if (socket != null) + socket.close(); + } catch (IOException e) { + throw new ModbusIOException(e); + } finally { + transport = null; + socket = null; + clientInfo.setConnected(false); + } + } + + public Socket getSocket() { + return socket; + } + + public TcpClientInfo getClientInfo() { + return clientInfo; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamASCII.java b/src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamASCII.java new file mode 100644 index 0000000..32c6e26 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamASCII.java @@ -0,0 +1,91 @@ +package com.intelligt.modbus.jlibmodbus.net.stream; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusChecksumException; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class InputStreamASCII extends InputStreamSerial { + + private int lrc = 0; + + public InputStreamASCII(SerialPort serial) { + super(serial); + } + + private void lrcAdd(byte b) { + lrc += b; + } + + private int lrcGet() { + return (byte) -lrc; + } + + @Override + public void frameCheck() throws IOException, ModbusChecksumException { + int c_lrc = (byte) lrcGet(); + int r_lrc = (byte) read(); + + int cr = readRaw(); + int lf = readRaw(); + // following checks delimiter has read (LF character by default) + if (cr != Modbus.ASCII_CODE_CR || lf != Modbus.getAsciiMsgDelimiter()) + Modbus.log().warning("\\r\\n not received."); + if (c_lrc != r_lrc) { + throw new ModbusChecksumException(r_lrc, c_lrc); + } + } + + @Override + public void frameInit() throws IOException { + lrc = 0; + char c = (char) readRaw(); + if (c != Modbus.ASCII_CODE_COLON) { + throw new IOException("no bytes read"); + } + } + + public int readRaw() throws IOException { + return super.read(); + } + + @Override + public int read() throws IOException { + int b; + char c = (char) readRaw(); + b = DataUtils.fromAscii(c, (char) readRaw()); + lrcAdd((byte) b); + return b; + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + for (int i = off; i < len; i++) { + b[i] = (byte) read(); + } + return len; + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamRTU.java b/src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamRTU.java new file mode 100644 index 0000000..c069179 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamRTU.java @@ -0,0 +1,70 @@ +package com.intelligt.modbus.jlibmodbus.net.stream; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusChecksumException; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; +import com.intelligt.modbus.jlibmodbus.utils.CRC16; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class InputStreamRTU extends InputStreamSerial { + + private int crc = CRC16.INITIAL_VALUE; + + public InputStreamRTU(SerialPort serial) { + super(serial); + } + + @Override + public void frameCheck() throws IOException, ModbusChecksumException { + int c_crc = getCrc(); + int r_crc = readShortLE(); + + if (c_crc != r_crc) { + throw new ModbusChecksumException(r_crc, c_crc); + } + } + + @Override + public void frameInit() { + crc = CRC16.INITIAL_VALUE; + } + + @Override + public int read() throws IOException { + int b = super.read(); + crc = CRC16.calc(crc, (byte) b); + return b; + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + int c = super.read(b, off, len); + crc = CRC16.calc(crc, b, off, len); + return c; + } + + private int getCrc() { + return crc; + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamSerial.java b/src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamSerial.java new file mode 100644 index 0000000..8995c08 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamSerial.java @@ -0,0 +1,50 @@ +package com.intelligt.modbus.jlibmodbus.net.stream; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusChecksumException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingInputStream; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public abstract class InputStreamSerial extends LoggingInputStream { + + InputStreamSerial(SerialPort serial) { + super(serial.getInputStream()); + } + + /** + * transport invokes it for validation of each frame + * + * @throws IOException when there is any communication trouble + * @throws ModbusChecksumException when invalid frame has received + */ + abstract public void frameCheck() throws IOException, ModbusChecksumException; + + /** + * it should be invoked before reading of a frame. + * + * @throws IOException when there is any communication trouble + */ + abstract public void frameInit() throws IOException; +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamTCP.java b/src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamTCP.java new file mode 100644 index 0000000..3d7a350 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/stream/InputStreamTCP.java @@ -0,0 +1,77 @@ +package com.intelligt.modbus.jlibmodbus.net.stream; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.net.Socket; +import java.net.SocketException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class InputStreamTCP extends LoggingInputStream { + + public InputStreamTCP(final Socket s) throws IOException { + super(new ModbusInputStream() { + + final private Socket socket = s; + final private BufferedInputStream in = new BufferedInputStream(s.getInputStream()); + + @Override + public int read() throws IOException { + int c = in.read(); + if (-1 == c) { + throw new IOException("Input stream is closed"); + } + return c; + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + int count = 0; + int k = 0; + while (count < len && k != -1) { + k = in.read(b, off + count, len - count); + if (-1 != k) + count += k; + } + return count; + } + + @Override + public void setReadTimeout(int readTimeout) { + try { + socket.setSoTimeout(readTimeout); + } catch (SocketException e) { + Modbus.log().warning(e.getLocalizedMessage()); + } + } + + @Override + public void close() throws IOException { + in.close(); + } + }); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamASCII.java b/src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamASCII.java new file mode 100644 index 0000000..dad68d3 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamASCII.java @@ -0,0 +1,88 @@ +package com.intelligt.modbus.jlibmodbus.net.stream; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; + +import java.io.IOException; +import java.nio.charset.Charset; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class OutputStreamASCII extends OutputStreamSerial { + + private int lrc = 0; + + public OutputStreamASCII(SerialPort serial) { + super(serial); + reset(); + } + + @Override + public void write(byte[] bytes) throws IOException { + write(bytes, 0, bytes.length); + } + + @Override + public void write(byte[] bytes, int offset, int length) throws IOException { + int tail = offset+length; + for (int i = offset; i < tail; i++) { + lrc += bytes[i]; + } + byte[] ascii = DataUtils.toAscii(bytes, offset, length).getBytes(Charset.forName("ASCII")); + super.write(ascii); + } + + @Override + public void write(int b) throws IOException { + lrc += (byte) b; + byte[] bytes = DataUtils.toAscii((byte) b).getBytes(Charset.forName("ASCII")); + super.write(bytes); + } + + private void writeChecksum() throws IOException { + byte[] bytes = DataUtils.toAscii((byte) -lrc).getBytes(Charset.forName("ASCII")); + super.write(bytes); + } + + public void writeRaw(int b) throws IOException { + super.write(b); + } + + @Override + public void flush() throws IOException { + writeChecksum(); + writeRaw(Modbus.ASCII_CODE_CR); + writeRaw(Modbus.ASCII_CODE_LF); + super.flush(); + reset(); + } + + public void reset() { + try { + lrc = 0; + writeRaw(Modbus.ASCII_CODE_COLON); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamRTU.java b/src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamRTU.java new file mode 100644 index 0000000..6a50d4a --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamRTU.java @@ -0,0 +1,40 @@ +package com.intelligt.modbus.jlibmodbus.net.stream; + +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; +import com.intelligt.modbus.jlibmodbus.utils.CRC16; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class OutputStreamRTU extends OutputStreamSerial { + + public OutputStreamRTU(SerialPort serial) { + super(serial); + } + + @Override + public void flush() throws IOException { + writeShortLE(CRC16.calc(toByteArray())); + super.flush(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamSerial.java b/src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamSerial.java new file mode 100644 index 0000000..ca47b21 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamSerial.java @@ -0,0 +1,32 @@ +package com.intelligt.modbus.jlibmodbus.net.stream; + +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingOutputStream; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class OutputStreamSerial extends LoggingOutputStream { + + OutputStreamSerial(SerialPort serial) { + super(serial.getOutputStream()); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamTCP.java b/src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamTCP.java new file mode 100644 index 0000000..58a0973 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/stream/OutputStreamTCP.java @@ -0,0 +1,57 @@ +package com.intelligt.modbus.jlibmodbus.net.stream; + +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingOutputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; + +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.net.Socket; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class OutputStreamTCP extends LoggingOutputStream { + + public OutputStreamTCP(final Socket s) throws IOException { + super(new ModbusOutputStream() { + final Socket socket = s; + final private BufferedOutputStream os = new BufferedOutputStream(socket.getOutputStream()); + + @Override + public void flush() throws IOException { + try { + byte[] bytes = toByteArray(); + os.write(bytes); + os.flush(); + } catch (Exception e) { + throw new IOException(e); + } finally { + super.flush(); + } + } + + @Override + public void close() throws IOException { + os.close(); + } + }); + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/net/stream/base/LoggingInputStream.java b/src/com/intelligt/modbus/jlibmodbus/net/stream/base/LoggingInputStream.java new file mode 100644 index 0000000..fbaa4f9 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/stream/base/LoggingInputStream.java @@ -0,0 +1,85 @@ +package com.intelligt.modbus.jlibmodbus.net.stream.base; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.utils.*; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * this class allows to log a content of the input stream stream. + * + * @author kochedykov + * @since 1.2 + */ +public class LoggingInputStream extends ModbusInputStream { + + private FrameEventListenerList listenerList = new FrameEventListenerListImpl(); + final static private String LOG_MESSAGE_TITLE = "Frame recv: "; + /** + * The input stream to be logged + */ + final private ModbusInputStream in; + final private ByteFifo fifo = new ByteFifo(Modbus.MAX_PDU_LENGTH); + + public LoggingInputStream(ModbusInputStream in) { + this.in = in; + } + + @Override + public int read() throws IOException { + int b = in.read(); + if (Modbus.isLoggingEnabled()) { + fifo.write(b); + } + return b; + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + int read = in.read(b, off, len); + if (Modbus.isLoggingEnabled()) { + fifo.write(b, off, read); + } + return read; + } + + @Override + public void setReadTimeout(int readTimeout) { + in.setReadTimeout(readTimeout); + } + + public void log() { + if (Modbus.isLoggingEnabled() && fifo.size() > 0) { + byte[] bytes = fifo.toByteArray(); + Modbus.log().info(LOG_MESSAGE_TITLE + DataUtils.toAscii(bytes)); + listenerList.fireFrameReceivedEvent(new FrameEvent(bytes)); + fifo.reset(); + } + } + + public void setListenerList(FrameEventListenerList listenerList) { + this.listenerList = listenerList; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/stream/base/LoggingOutputStream.java b/src/com/intelligt/modbus/jlibmodbus/net/stream/base/LoggingOutputStream.java new file mode 100644 index 0000000..56c534d --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/stream/base/LoggingOutputStream.java @@ -0,0 +1,98 @@ +package com.intelligt.modbus.jlibmodbus.net.stream.base; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; +import com.intelligt.modbus.jlibmodbus.utils.FrameEvent; +import com.intelligt.modbus.jlibmodbus.utils.FrameEventListenerList; +import com.intelligt.modbus.jlibmodbus.utils.FrameEventListenerListImpl; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * this class allows to log a content of the output stream before it'll be flushed. + * + * @author kochedykov + * @since 1.2 + */ +public class LoggingOutputStream extends ModbusOutputStream { + + private FrameEventListenerList listenerList = new FrameEventListenerListImpl(); + final static private String LOG_MESSAGE_TITLE = "Frame sent: "; + /** + * The output stream to be logged + */ + final private ModbusOutputStream out; + + public LoggingOutputStream(ModbusOutputStream out) { + this.out = out; + } + + @Override + public void write(byte[] b) throws IOException { + out.write(b); + if (Modbus.isLoggingEnabled()) { + super.write(b); + } + } + + @Override + public void write(byte[] b, int offset, int length) throws IOException { + out.write(b, offset, length); + if (Modbus.isLoggingEnabled()) { + super.write(b, offset, length); + } + } + + @Override + public void write(int b) throws IOException { + out.write(b); + if (Modbus.isLoggingEnabled()) { + super.write(b); + } + } + + @Override + public void flush() throws IOException { + out.flush(); + log(); + } + + public void log() { + if (Modbus.isLoggingEnabled() && super.getFifo().size() > 0) { + byte[] bytes = super.toByteArray(); + Modbus.log().info(LOG_MESSAGE_TITLE + DataUtils.toAscii(bytes)); + listenerList.fireFrameSentEvent(new FrameEvent(bytes)); + super.getFifo().reset(); + } + } + + public byte[] toByteArray() { + return out.toByteArray(); + } + + public void setListenerList(FrameEventListenerList listenerList) { + this.listenerList = listenerList; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/stream/base/ModbusInputStream.java b/src/com/intelligt/modbus/jlibmodbus/net/stream/base/ModbusInputStream.java new file mode 100644 index 0000000..cb1b3a8 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/stream/base/ModbusInputStream.java @@ -0,0 +1,89 @@ +package com.intelligt.modbus.jlibmodbus.net.stream.base; + +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; + +import java.io.IOException; +import java.io.InputStream; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * extends the InputStream class with ModbusInputStream#readShortLE() + * and ModbusInputStream#readShortBE() methods. Also it allows to set max read + * operation time with ModbusInputStream#setReadTimeout() method. + * + * @author kochedykov + * @since 1.0 + */ +abstract public class ModbusInputStream extends InputStream { + + /** + * default implementation of reading of a byte array. + * + * @param b a byte array to fill by values from the input stream. + * @return total number of values read from the input stream into the byte array + * @throws IOException if there is a read operation timeout + * @throws NullPointerException if b is null. + */ + @Override + public int read(byte[] b) throws IOException { + return read(b, 0, b.length); + } + + /** + * sets a timeout value. if there is a timeout of read operation a stream must throw new IO exception. + * + * @param readTimeout is a timeout value in milliseconds + */ + abstract public void setReadTimeout(int readTimeout); + + /** + * read two bytes in Big Endian Byte Order + * + * @return 16-bit value placed in first two bytes of integer value, second two bytes is equal zero. + * @throws IOException + * @see ModbusInputStream#readShortLE() + */ + public int readShortBE() throws IOException { + int h = read(); + int l = read(); + if (-1 == h || -1 == l) + return -1; + return DataUtils.toShort(h, l); + } + + /** + * read two bytes in Little Endian Byte Order + * + * @return 16-bit value placed in first two bytes of integer value, second two bytes is equal zero. + * @throws IOException + * @see ModbusInputStream#readShortBE() + */ + public int readShortLE() throws IOException { + int l = read(); + int h = read(); + if (-1 == h || -1 == l) + return -1; + return DataUtils.toShort(h, l); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/stream/base/ModbusOutputStream.java b/src/com/intelligt/modbus/jlibmodbus/net/stream/base/ModbusOutputStream.java new file mode 100644 index 0000000..7678395 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/stream/base/ModbusOutputStream.java @@ -0,0 +1,75 @@ +package com.intelligt.modbus.jlibmodbus.net.stream.base; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.utils.ByteFifo; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; + +import java.io.IOException; +import java.io.OutputStream; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +abstract public class ModbusOutputStream extends OutputStream { + + private final ByteFifo fifo = new ByteFifo(Modbus.MAX_TCP_ADU_LENGTH); + + @Override + public void write(byte[] b) throws IOException { + fifo.write(b); + } + + @Override + public void write(byte b[], int off, int len) throws IOException { + fifo.write(b, off, len); + } + + @Override + public void write(int b) throws IOException { + fifo.write(b); + } + + /** + * it should have invoked last + */ + @Override + public void flush() throws IOException { + fifo.reset(); + } + + public void writeShortBE(int s) throws IOException { + write(DataUtils.byteHigh(s)); + write(DataUtils.byteLow(s)); + } + + public void writeShortLE(int s) throws IOException { + write(DataUtils.byteLow(s)); + write(DataUtils.byteHigh(s)); + } + + public byte[] toByteArray() { + return fifo.toByteArray(); + } + + public ByteFifo getFifo() { + return fifo; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransport.java b/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransport.java new file mode 100644 index 0000000..5e6cc2c --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransport.java @@ -0,0 +1,96 @@ +package com.intelligt.modbus.jlibmodbus.net.transport; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.ModbusMessageFactory; +import com.intelligt.modbus.jlibmodbus.msg.ModbusRequestFactory; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusMessage; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.LoggingOutputStream; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public abstract class ModbusTransport { + + final private LoggingInputStream is; + final private LoggingOutputStream os; + + ModbusTransport(LoggingInputStream is, LoggingOutputStream os) { + this.is = is; + this.os = os; + } + + public void close() throws IOException { + is.close(); + os.close(); + } + + protected ModbusMessage createMessage(ModbusMessageFactory factory) throws IOException, ModbusNumberException, ModbusIOException { + int serverAddress = is.read(); + int functionCode = is.read(); + ModbusMessage msg = factory.createMessage(functionCode); + msg.setServerAddress(serverAddress); + msg.read(is); + return msg; + } + + public ModbusMessage readRequest() throws ModbusNumberException, ModbusIOException { + return readMessage(ModbusRequestFactory.getInstance()); + } + + public ModbusMessage readResponse(ModbusRequest request) throws ModbusNumberException, ModbusIOException { + return readMessage(request); + } + + final public ModbusMessage readMessage(ModbusMessageFactory factory) throws ModbusNumberException, ModbusIOException { + try { + return read(factory); + } finally { + getInputStream().log(); + } + } + + public void send(ModbusMessage msg) throws ModbusIOException { + try { + sendImpl(msg); + getOutputStream().flush(); + } catch (IOException e) { + throw new ModbusIOException(e); + } + + } + + public LoggingInputStream getInputStream() { + return is; + } + + public LoggingOutputStream getOutputStream() { + return os; + } + + abstract protected ModbusMessage read(ModbusMessageFactory factory) throws ModbusNumberException, ModbusIOException; + + abstract protected void sendImpl(ModbusMessage msg) throws ModbusIOException; +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportASCII.java b/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportASCII.java new file mode 100644 index 0000000..6218036 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportASCII.java @@ -0,0 +1,34 @@ +package com.intelligt.modbus.jlibmodbus.net.transport; + +import com.intelligt.modbus.jlibmodbus.net.stream.InputStreamASCII; +import com.intelligt.modbus.jlibmodbus.net.stream.OutputStreamASCII; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +class ModbusTransportASCII extends ModbusTransportSerial { + + ModbusTransportASCII(SerialPort serial) { + super(new InputStreamASCII(serial), new OutputStreamASCII(serial)); + } + +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportFactory.java b/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportFactory.java new file mode 100644 index 0000000..a4370c2 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportFactory.java @@ -0,0 +1,42 @@ +package com.intelligt.modbus.jlibmodbus.net.transport; + +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; + +import java.io.IOException; +import java.net.Socket; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public class ModbusTransportFactory { + static public ModbusTransport createRTU(SerialPort serial) { + return new ModbusTransportRTU(serial); + } + + static public ModbusTransport createASCII(SerialPort serial) { + return new ModbusTransportASCII(serial); + } + + static public ModbusTransport createTCP(Socket socket) throws IOException { + return new ModbusTransportTCP(socket); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportRTU.java b/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportRTU.java new file mode 100644 index 0000000..4f4bf2b --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportRTU.java @@ -0,0 +1,33 @@ +package com.intelligt.modbus.jlibmodbus.net.transport; + +import com.intelligt.modbus.jlibmodbus.net.stream.InputStreamRTU; +import com.intelligt.modbus.jlibmodbus.net.stream.OutputStreamRTU; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +class ModbusTransportRTU extends ModbusTransportSerial { + + ModbusTransportRTU(SerialPort serial) { + super(new InputStreamRTU(serial), new OutputStreamRTU(serial)); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportSerial.java b/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportSerial.java new file mode 100644 index 0000000..d3b5262 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportSerial.java @@ -0,0 +1,60 @@ +package com.intelligt.modbus.jlibmodbus.net.transport; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.ModbusMessageFactory; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusMessage; +import com.intelligt.modbus.jlibmodbus.net.stream.InputStreamSerial; +import com.intelligt.modbus.jlibmodbus.net.stream.OutputStreamSerial; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +class ModbusTransportSerial extends ModbusTransport { + + ModbusTransportSerial(InputStreamSerial is, OutputStreamSerial os) { + super(is, os); + } + + @Override + protected ModbusMessage read(ModbusMessageFactory factory) throws ModbusIOException, ModbusNumberException { + if (getInputStream() instanceof InputStreamSerial) { + InputStreamSerial is = (InputStreamSerial) getInputStream(); + try { + is.frameInit(); + ModbusMessage msg = createMessage(factory); + is.frameCheck(); + return msg; + } catch (IOException ioe) { + throw new ModbusIOException(ioe); + } + } else { + throw new ModbusIOException("Can't cast getInputStream() to InputStreamSerial"); + } + } + + @Override + protected void sendImpl(ModbusMessage msg) throws ModbusIOException { + msg.write(getOutputStream()); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportTCP.java b/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportTCP.java new file mode 100644 index 0000000..cc1bbcd --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/net/transport/ModbusTransportTCP.java @@ -0,0 +1,78 @@ +package com.intelligt.modbus.jlibmodbus.net.transport; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.ModbusMessageFactory; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusMessage; +import com.intelligt.modbus.jlibmodbus.net.stream.InputStreamTCP; +import com.intelligt.modbus.jlibmodbus.net.stream.OutputStreamTCP; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.tcp.TcpAduHeader; + +import java.io.IOException; +import java.net.Socket; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +class ModbusTransportTCP extends ModbusTransport { + + final private Socket socket; + + ModbusTransportTCP(Socket socket) throws IOException { + super(new InputStreamTCP(socket), new OutputStreamTCP(socket)); + this.socket = socket; + } + + @Override + protected ModbusMessage read(ModbusMessageFactory factory) throws ModbusNumberException, ModbusIOException { + ModbusInputStream is = getInputStream(); + TcpAduHeader header = new TcpAduHeader(); + header.read(is); + try { + ModbusMessage msg = createMessage(factory); + + msg.setTransactionId(header.getTransactionId()); + msg.setProtocolId(header.getProtocolId()); + + return msg; + } catch (IOException e) { + throw new ModbusIOException(e); + } + } + + @Override + public void sendImpl(ModbusMessage msg) throws ModbusIOException { + ModbusOutputStream os = getOutputStream(); + TcpAduHeader header = new TcpAduHeader(); + header.setProtocolId(msg.getProtocolId()); + header.setTransactionId(msg.getTransactionId()); + header.setPduSize(msg.size()); + header.write(os); + msg.write(os); + } + + @Override + public void close() throws IOException { + socket.close(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialParameters.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialParameters.java new file mode 100644 index 0000000..6c114ec --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialParameters.java @@ -0,0 +1,92 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class SerialParameters { + private String device = null; + private SerialPort.BaudRate baudRate; + private int dataBits; + private int stopBits; + private SerialPort.Parity parity; + + public SerialParameters() { + setBaudRate(SerialPort.BaudRate.BAUD_RATE_115200); + setDataBits(8); + setStopBits(1); + setParity(SerialPort.Parity.NONE); + } + + /** + * @param device the name(path) of the serial port + * @param baudRate baud rate + * @param dataBits the number of data bits + * @param stopBits the number of stop bits(1,2) + * @param parity parity check (NONE, EVEN, ODD, MARK, SPACE) + */ + public SerialParameters(String device, SerialPort.BaudRate baudRate, int dataBits, int stopBits, SerialPort.Parity parity) { + setDevice(device); + setBaudRate(baudRate); + setDataBits(dataBits); + setStopBits(stopBits); + setParity(parity); + } + + public String getDevice() { + return device; + } + + public void setDevice(String device) { + this.device = device; + } + + public int getBaudRate() { + return baudRate.getValue(); + } + + public void setBaudRate(SerialPort.BaudRate baudRate) { + this.baudRate = baudRate; + } + + public int getDataBits() { + return dataBits; + } + + public void setDataBits(int dataBits) { + this.dataBits = dataBits; + } + + public int getStopBits() { + return stopBits; + } + + public void setStopBits(int stopBits) { + this.stopBits = stopBits; + } + + public SerialPort.Parity getParity() { + return parity; + } + + public void setParity(SerialPort.Parity parity) { + this.parity = parity; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPort.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPort.java new file mode 100644 index 0000000..5c5e563 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPort.java @@ -0,0 +1,175 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public abstract class SerialPort { + + final private SerialParameters serialParameters; + private int readTimeout = Modbus.MAX_RESPONSE_TIMEOUT; + + public SerialPort(SerialParameters sp) { + this.serialParameters = sp; + } + + public SerialParameters getSerialParameters() { + return serialParameters; + } + + public int getReadTimeout() { + return readTimeout; + } + + public void setReadTimeout(int readTimeout) { + this.readTimeout = readTimeout; + } + + public ModbusOutputStream getOutputStream() { + return new ModbusOutputStream() { + final private SerialPort serial = SerialPort.this; + + @Override + public void flush() throws IOException { + try { + if (serial.isOpened()) { + serial.write(toByteArray()); + } + } finally { + super.flush(); + } + } + }; + } + + public ModbusInputStream getInputStream() { + + return new ModbusInputStream() { + + final private SerialPort serial = SerialPort.this; + + @Override + public int read() throws IOException { + return serial.read() & 0xff; + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + int size = 0; + while (size < len) { + size += serial.read(b, off + size, len - size); + } + return size; + } + + @Override + public void setReadTimeout(int readTimeout) { + serial.setReadTimeout(readTimeout); + } + }; + } + + abstract public void write(int b) throws IOException; + + abstract public void write(byte[] bytes) throws IOException; + + abstract public void open() throws SerialPortException; + + abstract public int read() throws IOException; + + abstract public int read(byte[] b, int off, int len) throws IOException; + + abstract public void close(); + + abstract public boolean isOpened(); + + public enum Parity { + NONE(0), + ODD(1), + EVEN(2), + MARK(3), + SPACE(4); + + private final int value; + + Parity(int value) { + this.value = value; + } + + static public Parity getParity(Integer value) { + for (Parity par : Parity.values()) { + if (par.value == value) { + return par; + } + } + throw new IllegalArgumentException("Illegal parity value:" + value); + } + + public int getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + } + + public enum BaudRate { + BAUD_RATE_4800(4800), + BAUD_RATE_9600(9600), + BAUD_RATE_14400(14400), + BAUD_RATE_19200(19200), + BAUD_RATE_38400(38400), + BAUD_RATE_57600(57600), + BAUD_RATE_115200(115200); + + private final int value; + + BaudRate(int value) { + this.value = value; + } + + static public BaudRate getBaudRate(int value) { + for (BaudRate br : BaudRate.values()) { + if (br.value == value) { + return br; + } + } + throw new IllegalArgumentException("Illegal baud rate value:" + value); + } + + public int getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortAT.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortAT.java new file mode 100644 index 0000000..8f346b3 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortAT.java @@ -0,0 +1,142 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import com.google.android.things.pio.PeripheralManager; +import com.google.android.things.pio.UartDevice; +import com.intelligt.modbus.jlibmodbus.Modbus; + +import java.io.IOException; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * + * [http://jlibmodbus.sourceforge.net] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public class SerialPortAT extends SerialPort { + + private UartDevice port; + byte[] buffer = new byte[Modbus.MAX_PDU_LENGTH]; + volatile long readTime = 0; + + public SerialPortAT(SerialParameters sp) { + super(sp); + port = null; + } + + @Override + public void write(int b) throws IOException { + try { + port.write(new byte[]{(byte)(b&0xff)}, 1); + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public void write(byte[] bytes) throws IOException { + try { + port.write(bytes, bytes.length); + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public void open() throws SerialPortException { + try { + SerialParameters sp = getSerialParameters(); + port = PeripheralManager.getInstance().openUartDevice(sp.getDevice()); + port.setBaudrate(sp.getBaudRate()); + port.setDataSize(sp.getDataBits()); + port.setParity(sp.getParity().getValue()); + port.setStopBits(sp.getStopBits()); + port.setHardwareFlowControl(UartDevice.HW_FLOW_CONTROL_NONE); + } catch (Exception ex) { + throw new SerialPortException(ex); + } + } + + @Override + public int read() throws IOException { + try { + readTime = System.currentTimeMillis(); + while (port.read(buffer, 1) < 1) { + if ((System.currentTimeMillis() - readTime) > getReadTimeout()) { + throw new IOException("Read timeout"); + } + } + return buffer[0]; + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public int read(byte[] b, int off, final int len) throws IOException { + try { + readTime = System.currentTimeMillis(); + int read; + int count = 0; + + int length = len-off; + + if (length < 0 || b.length < off+len) + throw new ArrayIndexOutOfBoundsException("len + off is greater than b.length"); + + while (count < length) { + read = port.read(buffer, length-count); + count += read; + if (count > length) { + int diff = count - length; + read -= diff; + count -= diff; + } + System.arraycopy(buffer, 0, b, off, read); + off += read; + + if ((System.currentTimeMillis() - readTime) > getReadTimeout()) { + throw new IOException("Read timeout"); + } + } + return count; + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public void close() { + if (isOpened()) { + try { + synchronized (this) { + port.close(); + port = null; + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + @Override + synchronized public boolean isOpened() { + return port != null; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortAbstractFactory.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortAbstractFactory.java new file mode 100644 index 0000000..7473b15 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortAbstractFactory.java @@ -0,0 +1,51 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * + * [http://jlibmodbus.sourceforge.net] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +import java.util.List; + +abstract public class SerialPortAbstractFactory { + + protected SerialPortAbstractFactory() { + } + + final public String getUnavailableString() { + return "Connector is missing"; + } + + abstract public SerialPort createSerialImpl(SerialParameters sp) throws SerialPortException; + abstract public List getPortIdentifiersImpl() throws SerialPortException; + + final SerialPort createSerial(SerialParameters sp) throws SerialPortException { + return createSerialImpl(sp); + } + + final List getPortIdentifiers() throws SerialPortException { + return getPortIdentifiersImpl(); + } + + String getVersion() { + return "The version number is unavailable."; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortException.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortException.java new file mode 100644 index 0000000..c767baa --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortException.java @@ -0,0 +1,32 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class SerialPortException extends Exception { + public SerialPortException(Exception cause) { + super(cause); + } + + public SerialPortException(String msg) { + super(msg); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryAT.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryAT.java new file mode 100644 index 0000000..a49bf47 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryAT.java @@ -0,0 +1,54 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import com.google.android.things.AndroidThings; +import com.google.android.things.pio.PeripheralManager; + +import java.util.List; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * + * [http://jlibmodbus.sourceforge.net] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class SerialPortFactoryAT extends SerialPortAbstractFactory { + + public SerialPortFactoryAT() { + } + + @Override + public SerialPort createSerialImpl(SerialParameters sp) { + return new SerialPortAT(sp); + } + + @Override + public List getPortIdentifiersImpl() { + final PeripheralManager pm = PeripheralManager.getInstance(); + return pm.getUartDeviceList(); + } + + @Override + public String getVersion() { + try { + return AndroidThings.RELEASE; + } catch (Exception e) { + return super.getVersion(); + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryJSSC.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryJSSC.java new file mode 100644 index 0000000..b5e0c62 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryJSSC.java @@ -0,0 +1,42 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import java.util.Arrays; +import java.util.List; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * + * [http://jlibmodbus.sourceforge.net] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class SerialPortFactoryJSSC extends SerialPortAbstractFactory { + + public SerialPortFactoryJSSC() { + } + + @Override + public SerialPort createSerialImpl(SerialParameters sp) { + return new SerialPortJSSC(sp); + } + + @Override + public List getPortIdentifiersImpl() { + return Arrays.asList(jssc.SerialPortList.getPortNames()); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryJSerialComm.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryJSerialComm.java new file mode 100644 index 0000000..1b49873 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryJSerialComm.java @@ -0,0 +1,47 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import java.util.ArrayList; +import java.util.List; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * + * [http://jlibmodbus.sourceforge.net] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class SerialPortFactoryJSerialComm extends SerialPortAbstractFactory { + + public SerialPortFactoryJSerialComm() { + } + + @Override + public SerialPort createSerialImpl(SerialParameters sp) { + return new SerialPortJSerialComm(sp); + } + + @Override + public List getPortIdentifiersImpl() { + com.fazecast.jSerialComm.SerialPort[] ports = com.fazecast.jSerialComm.SerialPort.getCommPorts(); + List portIdentifiers = new ArrayList(ports.length); + for (int i = 0; i < ports.length; i++) { + portIdentifiers.add(ports[i].getSystemPortName()); + } + return portIdentifiers; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryLoopback.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryLoopback.java new file mode 100644 index 0000000..a6c7a1c --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryLoopback.java @@ -0,0 +1,49 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import java.util.Arrays; +import java.util.List; + +/* + * Copyright (C) 2017 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Kevin Kieffer. + * email: + */ + +/** + * @author Kevin Kieffer + * @since 1.9.0 + */ +public class SerialPortFactoryLoopback extends SerialPortAbstractFactory { + + final private boolean isMaster; + + public SerialPortFactoryLoopback(boolean isMaster) { + this.isMaster = isMaster; + } + + @Override + public SerialPort createSerialImpl(SerialParameters sp) throws SerialPortException { + return new SerialPortLoopback(sp, isMaster); + } + + @Override + public List getPortIdentifiersImpl() { + return Arrays.asList(new String[0]); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryPJC.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryPJC.java new file mode 100644 index 0000000..b6c173e --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryPJC.java @@ -0,0 +1,64 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import purejavacomm.CommPortIdentifier; + +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * + * [http://jlibmodbus.sourceforge.net] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class SerialPortFactoryPJC extends SerialPortAbstractFactory { + + final private ValidatorSerialPortFactory validator = new ValidatorSerialPortFactory("purejavacomm.PureJavaComm", SerialPortFactoryPJC.class.getCanonicalName()); + + public SerialPortFactoryPJC() { + } + + @Override + public SerialPort createSerialImpl(SerialParameters sp) { + return new SerialPortPJC(sp); + } + + @Override + public List getPortIdentifiersImpl() { + Enumeration ports = CommPortIdentifier.getPortIdentifiers(); + List list = new ArrayList(); + while (ports.hasMoreElements()) { + CommPortIdentifier id = (CommPortIdentifier) ports.nextElement(); + if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) { + list.add(id.getName()); + } + } + return list; + } + + @Override + public String getVersion() { + try { + return purejavacomm.PureJavaComm.getVersion(); + } catch (Exception e) { + return super.getVersion(); + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryRXTX.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryRXTX.java new file mode 100644 index 0000000..9ea74f2 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryRXTX.java @@ -0,0 +1,63 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import gnu.io.CommPortIdentifier; + +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * + * [http://jlibmodbus.sourceforge.net] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class SerialPortFactoryRXTX extends SerialPortAbstractFactory { + + protected SerialPortFactoryRXTX() { + } + + @Override + public SerialPort createSerialImpl(SerialParameters sp) { + return new SerialPortRXTX(sp); + } + + @Override + public List getPortIdentifiersImpl() { + Enumeration ports = gnu.io.CommPortIdentifier.getPortIdentifiers(); + List list = new ArrayList(); + while (ports.hasMoreElements()) { + CommPortIdentifier id = (CommPortIdentifier) ports.nextElement(); + if (id.getPortType() == CommPortIdentifier.PORT_RS485 || + id.getPortType() == CommPortIdentifier.PORT_SERIAL) { + list.add(id.getName()); + } + } + return list; + } + + @Override + public String getVersion() { + try { + return gnu.io.RXTXVersion.getVersion(); + } catch (Exception e) { + return super.getVersion(); + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryTcpClient.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryTcpClient.java new file mode 100644 index 0000000..c6f9a0c --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryTcpClient.java @@ -0,0 +1,169 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.net.stream.InputStreamTCP; +import com.intelligt.modbus.jlibmodbus.net.stream.OutputStreamTCP; +import com.intelligt.modbus.jlibmodbus.tcp.TcpParameters; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketException; +import java.util.Arrays; +import java.util.List; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * + * [http://jlibmodbus.sourceforge.net] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public class SerialPortFactoryTcpClient extends SerialPortAbstractFactory { + + private TcpParameters tcpParameters; + + public SerialPortFactoryTcpClient(TcpParameters tcpParameters) { + setTcpParameters(tcpParameters); + } + + public TcpParameters getTcpParameters() { + return tcpParameters; + } + + public void setTcpParameters(TcpParameters tcpParameters) { + this.tcpParameters = tcpParameters; + } + + @Override + public SerialPort createSerialImpl(SerialParameters sp) { + return new SerialPortTcpClient(sp); + } + + @Override + public List getPortIdentifiersImpl() { + return Arrays.asList(new String[0]); + } + + private class SerialPortTcpClient extends SerialPort { + + private Socket socket; + private InputStreamTCP is; + private OutputStreamTCP os; + + SerialPortTcpClient(SerialParameters sp) { + super(sp); + } + + @Override + public void open() throws SerialPortException { + TcpParameters parameters = getTcpParameters(); + if (parameters != null) { + close(); + socket = new Socket(); + InetSocketAddress isa = new InetSocketAddress(parameters.getHost(), parameters.getPort()); + try { + socket.connect(isa, Modbus.MAX_CONNECTION_TIMEOUT); + socket.setKeepAlive(parameters.isKeepAlive()); + socket.setSoTimeout(getReadTimeout()); + + is = new InputStreamTCP(socket); + os = new OutputStreamTCP(socket); + + } catch (SocketException e) { + throw new SerialPortException(e); + } catch (IOException e) { + throw new SerialPortException(e); + } + } + } + + @Override + public void write(byte[] b) throws IOException { + if (isOpened()) { + os.write(b); + os.flush(); + } else { + throw new IOException("Port not opened"); + } + } + + @Override + public void write(int b) throws IOException { + if (isOpened()) { + os.write(b); + os.flush(); + } else { + throw new IOException("Port not opened"); + } + } + + @Override + public int read() throws IOException { + if (isOpened()) { + return is.read(); + } else { + throw new IOException("Port not opened"); + } + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + if (isOpened()) { + return is.read(b, off, len); + } else { + throw new IOException("Port not opened"); + } + } + + @Override + public void close() { + try { + if (isOpened()) { + is.close(); + os.close(); + socket.close(); + } + } catch (IOException e) { + Modbus.log().warning("Unable to close port: " + e.getLocalizedMessage()); + } finally { + is = null; + os = null; + socket = null; + } + } + + public void setReadTimeout(int readTimeout) { + super.setReadTimeout(readTimeout); + if (isOpened()) { + try { + socket.setSoTimeout(readTimeout); + } catch (SocketException e) { + e.printStackTrace(); + Modbus.log().warning("Unable to set readTimeout: " + e.getLocalizedMessage()); + } + } + } + + @Override + public boolean isOpened() { + return socket != null && socket.isConnected() && os != null && is != null; + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryTcpServer.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryTcpServer.java new file mode 100644 index 0000000..a9444a8 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortFactoryTcpServer.java @@ -0,0 +1,209 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.net.stream.InputStreamTCP; +import com.intelligt.modbus.jlibmodbus.net.stream.OutputStreamTCP; +import com.intelligt.modbus.jlibmodbus.tcp.TcpParameters; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketException; +import java.util.LinkedList; +import java.util.List; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * + * [http://jlibmodbus.sourceforge.net] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public class SerialPortFactoryTcpServer extends SerialPortAbstractFactory { + + final private TcpParameters tcpParameters; + + public SerialPortFactoryTcpServer(TcpParameters tcpParameters) { + this.tcpParameters = tcpParameters; + } + + public TcpParameters getTcpParameters() { + return tcpParameters; + } + + @Override + public SerialPort createSerialImpl(SerialParameters sp) { + return new SerialPortTcpServer(sp); + } + + @Override + public List getPortIdentifiersImpl() { + return new LinkedList(); + } + + class SerialPortTcpServer extends SerialPort implements Runnable { + volatile boolean listening = false; + private Thread mainThread = null; + private ServerSocket server = null; + private Socket client = null; + private InputStreamTCP is = null; + private OutputStreamTCP os = null; + private int timeout = 1000; + + SerialPortTcpServer(SerialParameters sp) { + super(sp); + } + + public int getTimeout() { + return timeout; + } + + public void setTimeout(int timeout) { + this.timeout = timeout; + } + + private boolean isListening() { + return listening; + } + + private void setListening(boolean listening) { + this.listening = listening; + } + + @Override + public void open() throws SerialPortException { + try { + server = new ServerSocket(getTcpParameters().getPort()); + mainThread = new Thread(this); + setListening(true); + mainThread.start(); + } catch (IOException e) { + throw new SerialPortException(e); + } + } + + @Override + public void write(byte[] b) throws IOException { + if (isOpened()) { + os.write(b); + os.flush(); + } else { + throw new IOException("Port not opened"); + } + } + + @Override + public void write(int b) throws IOException { + if (isOpened()) { + os.write(b); + os.flush(); + } else { + throw new IOException("Port not opened"); + } + } + + @Override + public int read() throws IOException { + if (isOpened()) { + return is.read(); + } else { + throw new IOException("Port not opened"); + } + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + if (isOpened()) { + return is.read(b, off, len); + } else { + throw new IOException("Port not opened"); + } + } + + @Override + public void close() { + setListening(false); + /* close server socket */ + try { + if (server != null) + server.close(); + } catch (IOException e) { + Modbus.log().warning(e.getLocalizedMessage()); + } finally { + server = null; + } + + try { + if (mainThread != null) { + mainThread.join(timeout * 2); + if (mainThread.isAlive()) + mainThread.interrupt(); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + mainThread = null; + } + } + + public void setReadTimeout(int readTimeout) { + setTimeout(readTimeout); + + synchronized (this) { + if (isOpened()) { + super.setReadTimeout(readTimeout); + try { + client.setSoTimeout(readTimeout); + } catch (SocketException e) { + e.printStackTrace(); + Modbus.log().warning("Unable to set readTimeout: " + e.getLocalizedMessage()); + } + } + } + } + + @Override + public boolean isOpened() { + return client != null && client.isConnected() && os != null && is != null; + } + + @Override + public void run() { + try { + while (isListening()) { + client = server.accept(); + is = new InputStreamTCP(client); + os = new OutputStreamTCP(client); + while (client.isConnected() && isListening()) { + Thread.sleep(timeout); + } + } + } catch (SocketException e) { + if (server != null && !server.isClosed()) { + Modbus.log().warning(e.getLocalizedMessage()); + e.printStackTrace(); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortJSSC.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortJSSC.java new file mode 100644 index 0000000..c353ab2 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortJSSC.java @@ -0,0 +1,105 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import java.io.IOException; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * + * [http://jlibmodbus.sourceforge.net] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public class SerialPortJSSC extends SerialPort { + + final private jssc.SerialPort port; + + public SerialPortJSSC(SerialParameters sp) { + super(sp); + this.port = new jssc.SerialPort(sp.getDevice()); + } + + @Override + public void write(int b) throws IOException { + try { + port.writeByte((byte) b); + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public void write(byte[] bytes) throws IOException { + try { + port.writeBytes(bytes); + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public void open() throws SerialPortException { + try { + port.openPort(); + SerialParameters sp = getSerialParameters(); + port.setParams(sp.getBaudRate(), sp.getDataBits(), sp.getStopBits(), sp.getParity().getValue()); + port.setFlowControlMode(jssc.SerialPort.FLOWCONTROL_NONE); + } catch (Exception ex) { + throw new SerialPortException(ex); + } + } + + @Override + public int read() throws IOException { + try { + if (getReadTimeout() > 0) + return port.readBytes(1, getReadTimeout())[0]; + return port.readBytes(1)[0]; + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + try { + byte[] rb = port.readBytes(len, getReadTimeout()); + System.arraycopy(rb, 0, b, off, len); + return rb.length; + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public void close() { + if (isOpened()) { + try { + port.closePort(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + @Override + public boolean isOpened() { + return port.isOpened(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortJSerialComm.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortJSerialComm.java new file mode 100644 index 0000000..1243d1b --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortJSerialComm.java @@ -0,0 +1,142 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * + * [http://jlibmodbus.sourceforge.net] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public class SerialPortJSerialComm extends SerialPort { + + private com.fazecast.jSerialComm.SerialPort port; + private InputStream in; + private OutputStream out; + final byte [] b = new byte[1]; + + public SerialPortJSerialComm(SerialParameters sp) { + super(sp); + } + + @Override + public void write(int b) throws IOException { + if (!isOpened()) { + throw new IOException("Port not opened"); + } + try { + out.write((byte) b); + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public void write(byte[] bytes) throws IOException { + if (!isOpened()) { + throw new IOException("Port not opened"); + } + try { + out.write(bytes); + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public void open() throws SerialPortException { + SerialParameters sp = getSerialParameters(); + port = com.fazecast.jSerialComm.SerialPort.getCommPort(sp.getDevice()); + port.openPort(); + + port.setComPortParameters(sp.getBaudRate(), sp.getDataBits(), sp.getStopBits(), sp.getParity().getValue()); + port.setFlowControl(com.fazecast.jSerialComm.SerialPort.FLOW_CONTROL_DISABLED); + + in = port.getInputStream(); + out = port.getOutputStream(); + + port.setComPortTimeouts(com.fazecast.jSerialComm.SerialPort.TIMEOUT_READ_BLOCKING, getReadTimeout(), 0); + + } + + @Override + public void setReadTimeout(int readTimeout) { + super.setReadTimeout(readTimeout); + + if (isOpened()) { + port.setComPortTimeouts(com.fazecast.jSerialComm.SerialPort.TIMEOUT_NONBLOCKING, getReadTimeout(), getReadTimeout()); + } + } + + @Override + public int read() throws IOException { + if (!isOpened()) { + throw new IOException("Port not opened"); + } + int c; + + try { + c = in.read(b, 0, b.length); + } catch (Exception e) { + throw new IOException(e); + } + if (c > 0) + return b[0]; + else + throw new IOException("Read timeout"); + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + if (!isOpened()) { + throw new IOException("Port not opened"); + } + int c; + try { + c = in.read(b, off, len); + } catch (Exception e) { + throw new IOException(e); + } + if (c > -1) + return c; + else + throw new IOException("Read timeout"); + } + + @Override + public void close() { + try { + if (isOpened()) { + in.close(); + out.close(); + port.closePort(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public boolean isOpened() { + return port.isOpen(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortLoopback.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortLoopback.java new file mode 100644 index 0000000..7b98d93 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortLoopback.java @@ -0,0 +1,123 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import java.io.IOException; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.TimeUnit; + +/* + * Copyright (C) 2017 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Kevin Kieffer. + * email: + */ + +/** + * @author Kevin Kieffer + * @since 1.9.0 + */ +public class SerialPortLoopback extends SerialPort { + + //This must be static to be used by all class instances + private static final LinkedBlockingDeque tx_from_master_fifo = new LinkedBlockingDeque(8192); + private static final LinkedBlockingDeque rx_to_master_fifo = new LinkedBlockingDeque(8192); + private final LinkedBlockingDeque myWriteFifo; + private final LinkedBlockingDeque myReadFifo; + private boolean isOpen = false; + + public SerialPortLoopback(SerialParameters sp, boolean isMaster) throws SerialPortException { + super(sp); + if (isMaster) { + myWriteFifo = tx_from_master_fifo; + myReadFifo = rx_to_master_fifo; + } else { + myWriteFifo = rx_to_master_fifo; + myReadFifo = tx_from_master_fifo; + } + } + + @Override + public void write(int b) throws IOException { + if (!myWriteFifo.offer((byte) b)) + throw new IOException("Loopback fifo full"); + } + + @Override + public void write(byte[] bytes) throws IOException { + if (!isOpen) + throw new IOException("Loopback is not open"); + for (Byte b : bytes) { + if (!myWriteFifo.offer(b)) + throw new IOException("Loopback fifo is full"); + } + } + + @Override + public void open() throws SerialPortException { + isOpen = true; + } + + @Override + public int read() throws IOException { + if (!isOpen) + throw new IOException("Loopback is not open"); + + try { + + Byte b = myReadFifo.poll((long) getReadTimeout(), TimeUnit.MILLISECONDS); + if (b == null) + throw new IOException("Timeout"); + + return (int) b & 0xff; + + } catch (InterruptedException ex) { + throw new IOException(ex); + } + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + + int count = 0; + for (int i = 0; i < len; i++) { + try { + Byte y = myReadFifo.poll((long) getReadTimeout(), TimeUnit.MILLISECONDS); + if (y == null) + break; + b[i + off] = y; + count++; + + } catch (InterruptedException ex) { + throw new IOException(ex); + } + } + if (count == 0) + throw new IOException("Timeout"); + + return count; + } + + @Override + public void close() { + isOpen = false; + } + + @Override + public boolean isOpened() { + return isOpen; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortPJC.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortPJC.java new file mode 100644 index 0000000..65692e8 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortPJC.java @@ -0,0 +1,187 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import purejavacomm.*; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.concurrent.atomic.AtomicBoolean; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * + * [http://jlibmodbus.sourceforge.net] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public class SerialPortPJC extends SerialPort implements SerialPortEventListener { + + private purejavacomm.SerialPort port; + final private AtomicBoolean opened = new AtomicBoolean(false); + private InputStream in; + private OutputStream out; + + + public SerialPortPJC(SerialParameters sp) { + super(sp); + } + + @Override + public void write(int b) throws IOException { + if (!isOpened()) { + throw new IOException("Port not opened"); + } + try { + out.write((byte) b); + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public void write(byte[] bytes) throws IOException { + if (!isOpened()) { + throw new IOException("Port not opened"); + } + try { + out.write(bytes); + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public void open() throws SerialPortException { + try { + SerialParameters sp = getSerialParameters(); + + CommPortIdentifier portIdentifier; + + portIdentifier = CommPortIdentifier.getPortIdentifier(sp.getDevice()); + if (portIdentifier.isCurrentlyOwned()) { + String msg = "Cannot open serial port " + sp.getDevice(); + Modbus.log().warning(msg); + throw new SerialPortException(msg); + } else { + CommPort commPort = portIdentifier.open(this.getClass().getName(), Modbus.MAX_CONNECTION_TIMEOUT); + + if (commPort instanceof purejavacomm.SerialPort) { + port = (purejavacomm.SerialPort) commPort; + port.setSerialPortParams(sp.getBaudRate(), sp.getDataBits(), sp.getStopBits(), sp.getParity().getValue()); + port.setFlowControlMode(gnu.io.SerialPort.FLOWCONTROL_NONE); + + in = port.getInputStream(); + out = port.getOutputStream(); + + port.enableReceiveTimeout(getReadTimeout()); + setOpened(true); + } else { + Modbus.log().severe(sp.getDevice() + " is not a serial port."); + } + } + } catch (NoSuchPortException e) { + throw new SerialPortException(e); + } catch (Exception ex) { + throw new SerialPortException(ex); + } + } + + @Override + public void setReadTimeout(int readTimeout) { + super.setReadTimeout(readTimeout); + try { + if (isOpened()) + port.enableReceiveTimeout(readTimeout); + } catch (UnsupportedCommOperationException e) { + Modbus.log().warning(e.getLocalizedMessage()); + } + } + + @Override + public int read() throws IOException { + if (!isOpened()) { + throw new IOException("Port not opened"); + } + int c; + try { + c = in.read(); + } catch (Exception e) { + throw new IOException(e); + } + if (c > -1) + return c; + else + throw new IOException("Read timeout"); + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + if (!isOpened()) { + throw new IOException("Port not opened"); + } + int c; + try { + c = in.read(b, off, len); + } catch (Exception e) { + throw new IOException(e); + } + if (c > -1) + return c; + else + throw new IOException("Read timeout"); + } + + @Override + public void close() { + try { + if (isOpened()) { + setOpened(false); + in.close(); + out.close(); + port.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public boolean isOpened() { + return opened.get(); + } + + public void setOpened(boolean opened) { + this.opened.set(opened); + } + + @Override + public void serialEvent(SerialPortEvent serialPortEvent) { + switch (serialPortEvent.getEventType()) { + case SerialPortEvent.OE: + case SerialPortEvent.PE: + case SerialPortEvent.FE: + Modbus.log().warning(port.getName() + ": framing error."); + break; + default: + break; + } + + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortRXTX.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortRXTX.java new file mode 100644 index 0000000..1e150b0 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialPortRXTX.java @@ -0,0 +1,187 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import gnu.io.*; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.concurrent.atomic.AtomicBoolean; + +/* + * Copyright (C) 2017 Vladislav Y. Kochedykov + * + * [http://jlibmodbus.sourceforge.net] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public class SerialPortRXTX extends SerialPort implements SerialPortEventListener { + + private gnu.io.SerialPort port; + final private AtomicBoolean opened = new AtomicBoolean(false); + private InputStream in; + private OutputStream out; + + + public SerialPortRXTX(SerialParameters sp) { + super(sp); + } + + @Override + public void write(int b) throws IOException { + if (!isOpened()) { + throw new IOException("Port not opened"); + } + try { + out.write((byte) b); + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public void write(byte[] bytes) throws IOException { + if (!isOpened()) { + throw new IOException("Port not opened"); + } + try { + out.write(bytes); + } catch (Exception e) { + throw new IOException(e); + } + } + + @Override + public void open() throws SerialPortException { + try { + SerialParameters sp = getSerialParameters(); + + CommPortIdentifier portIdentifier; + + portIdentifier = CommPortIdentifier.getPortIdentifier(sp.getDevice()); + if (portIdentifier.isCurrentlyOwned()) { + String msg = "Cannot open serial port " + sp.getDevice(); + Modbus.log().warning(msg); + throw new SerialPortException(msg); + } else { + CommPort commPort = portIdentifier.open(this.getClass().getName(), Modbus.MAX_CONNECTION_TIMEOUT); + + if (commPort instanceof gnu.io.SerialPort) { + port = (gnu.io.SerialPort) commPort; + port.setSerialPortParams(sp.getBaudRate(), sp.getDataBits(), sp.getStopBits(), sp.getParity().getValue()); + port.setFlowControlMode(gnu.io.SerialPort.FLOWCONTROL_NONE); + + in = port.getInputStream(); + out = port.getOutputStream(); + + port.enableReceiveTimeout(getReadTimeout()); + setOpened(true); + } else { + Modbus.log().severe(sp.getDevice() + " is not a serial port."); + } + } + } catch (NoSuchPortException e) { + throw new SerialPortException(e); + } catch (Exception ex) { + throw new SerialPortException(ex); + } + } + + @Override + public void setReadTimeout(int readTimeout) { + super.setReadTimeout(readTimeout); + try { + if (isOpened()) + port.enableReceiveTimeout(readTimeout); + } catch (UnsupportedCommOperationException e) { + Modbus.log().warning(e.getLocalizedMessage()); + } + } + + @Override + public int read() throws IOException { + if (!isOpened()) { + throw new IOException("Port not opened"); + } + int c; + try { + c = in.read(); + } catch (Exception e) { + throw new IOException(e); + } + if (c > -1) + return c; + else + throw new IOException("Read timeout"); + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + if (!isOpened()) { + throw new IOException("Port not opened"); + } + int c; + try { + c = in.read(b, off, len); + } catch (Exception e) { + throw new IOException(e); + } + if (c > -1) + return c; + else + throw new IOException("Read timeout"); + } + + @Override + public void close() { + try { + if (isOpened()) { + setOpened(false); + in.close(); + out.close(); + port.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public boolean isOpened() { + return opened.get(); + } + + public void setOpened(boolean opened) { + this.opened.set(opened); + } + + @Override + public void serialEvent(SerialPortEvent serialPortEvent) { + switch (serialPortEvent.getEventType()) { + case SerialPortEvent.OE: + case SerialPortEvent.PE: + case SerialPortEvent.FE: + Modbus.log().warning(port.getName() + ": framing error."); + break; + default: + break; + } + + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/SerialUtils.java b/src/com/intelligt/modbus/jlibmodbus/serial/SerialUtils.java new file mode 100644 index 0000000..1cb8555 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/SerialUtils.java @@ -0,0 +1,95 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import com.intelligt.modbus.jlibmodbus.Modbus; + +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class SerialUtils { + + static private Set validatorSet = new TreeSet(); + + static { + registerSerialPortFactory("com.fazecast.jSerialComm.SerialPort", "com.intelligt.modbus.jlibmodbus.serial.SerialPortFactoryJSerialComm"); + registerSerialPortFactory("jssc.SerialPort", "com.intelligt.modbus.jlibmodbus.serial.SerialPortFactoryJSSC"); + registerSerialPortFactory("purejavacomm.PureJavaComm", "com.intelligt.modbus.jlibmodbus.serial.SerialPortFactoryPJC"); + registerSerialPortFactory("gnu.io.RXTXVersion", "com.intelligt.modbus.jlibmodbus.serial.SerialPortFactoryRXTX"); + + registerSerialPortFactory("com.google.android.things.AndroidThings", "com.intelligt.modbus.jlibmodbus.serial.SerialPortFactoryAT"); + } + + static private SerialPortAbstractFactory factory = null; + + static public void registerSerialPortFactory(String connectorClassname, String factoryClassname) { + if (!validatorSet.add(new ValidatorSerialPortFactory(connectorClassname, factoryClassname))) { + Modbus.log().warning("The factory is already registered, skipping: " + factoryClassname); + } + } + + static public void trySelectConnector() throws SerialPortException { + Iterator iterator = validatorSet.iterator(); + while (iterator.hasNext() && getSerialPortFactory() == null) { + ValidatorSerialPortFactory validator = iterator.next(); + if (validator.validate() ) { + try { + setSerialPortFactory(validator.getFactory()); + } catch (ClassNotFoundException e) { + Modbus.log().warning("Cannot set a serial port factory " + validator.getFactoryClassname()); + } + } + } + if (getSerialPortFactory() == null) { + throw new SerialPortException("There are no available connectors"); + } + } + + static public SerialPort createSerial(SerialParameters sp) throws SerialPortException { + return getSerialPortFactory().createSerial(sp); + } + + static public List getPortIdentifiers() throws SerialPortException { + return getSerialPortFactory().getPortIdentifiers(); + } + + static public String getConnectorVersion() { + return getSerialPortFactory().getVersion(); + } + + /** + * @param factory - a concrete serial port factory instance + * @since 1.2.1 + */ + static public void setSerialPortFactory(SerialPortAbstractFactory factory) { + SerialUtils.factory = factory; + } + + static public SerialPortAbstractFactory getSerialPortFactory() { + if (SerialUtils.factory == null){ + SerialUtils.factory = new SerialPortFactoryJSSC(); + } + return SerialUtils.factory; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/serial/ValidatorSerialPortFactory.java b/src/com/intelligt/modbus/jlibmodbus/serial/ValidatorSerialPortFactory.java new file mode 100644 index 0000000..a4f1af1 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/serial/ValidatorSerialPortFactory.java @@ -0,0 +1,50 @@ +package com.intelligt.modbus.jlibmodbus.serial; + +import com.intelligt.modbus.jlibmodbus.Modbus; + +public class ValidatorSerialPortFactory implements Comparable { + final private String factoryClassname; + final private String connectorClassname; + + public ValidatorSerialPortFactory(String connectorClassname, String factoryClassname) { + this.factoryClassname = factoryClassname; + this.connectorClassname = connectorClassname; + } + + public String getFactoryClassname() { + return factoryClassname; + } + + public String getConnectorClassname() { + return connectorClassname; + } + + public boolean validate() { + try { + Class.forName(getConnectorClassname()); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } + + public SerialPortAbstractFactory getFactory() throws ClassNotFoundException { + if (validate()) { + try { + Class factoryClass = Class.forName(getFactoryClassname()); + Object o = factoryClass.getConstructors()[0].newInstance(); + if (o instanceof SerialPortAbstractFactory) { + return (SerialPortAbstractFactory) o; + } + } catch (Exception e) { + Modbus.log().warning("Invalid implementation of " + getFactoryClassname()); + } + } + throw new ClassNotFoundException(); + } + + @Override + public int compareTo(ValidatorSerialPortFactory o) { + return this.equals(o) ? 0 : 1; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlave.java b/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlave.java new file mode 100644 index 0000000..5cfc3d9 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlave.java @@ -0,0 +1,211 @@ +package com.intelligt.modbus.jlibmodbus.slave; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.data.DataHolderBuilder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.net.ModbusConnection; +import com.intelligt.modbus.jlibmodbus.utils.FrameEvent; +import com.intelligt.modbus.jlibmodbus.utils.FrameEventListener; +import com.intelligt.modbus.jlibmodbus.utils.FrameEventListenerList; + +import java.util.ArrayList; +import java.util.List; +import java.util.Observable; +import java.util.Observer; +import java.util.concurrent.atomic.AtomicBoolean; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +abstract public class ModbusSlave implements FrameEventListenerList { + final private List connectionList = new ArrayList(); + final private AtomicBoolean listening = new AtomicBoolean(false); + final private AtomicBoolean broadcastEnabled = new AtomicBoolean(false); + private Observable observable = new Observable() { + @Override + public void notifyObservers(Object arg) { + setChanged(); + super.notifyObservers(arg); + } + }; + private int serverAddress = Modbus.BROADCAST_ID; + private DataHolder dataHolder = new DataHolder(); + /** + * a timeout for single connection handler. if master makes a new connection for every data request, + * we should close it's last connection as soon as possible. Else, if master is working through a single connection, + * we should be waiting for the next request as long as it is possible :). + */ + private volatile int readTimeout = Modbus.MAX_RESPONSE_TIMEOUT; + + protected ModbusSlave() { + } + + public int getReadTimeout() { + return readTimeout; + } + + public void setReadTimeout(int readTimeout) { + this.readTimeout = readTimeout; + for (ModbusConnection conn : getConnectionList()) { + conn.setReadTimeout(readTimeout); + } + } + + abstract protected void listenImpl() throws ModbusIOException; + + abstract protected void shutdownImpl() throws ModbusIOException; + + /** + * starts the ModbusSlave thread. + */ + final public void listen() throws ModbusIOException { + listenImpl(); + setListening(true); + } + + /** + * should have stop the thread of the ModbusSlave. + */ + final public void shutdown() throws ModbusIOException { + setListening(false); + shutdownImpl(); + } + + public boolean isListening() { + return listening.get(); + } + + protected void setListening(boolean listening) { + this.listening.set(listening); + } + + /*Getters & Setters*/ + public DataHolder getDataHolder() { + return dataHolder; + } + + public void setDataHolder(DataHolderBuilder builder) { + setDataHolder(builder.build()); + } + + public void setDataHolder(DataHolder dataHolder) { + this.dataHolder = dataHolder; + } + + public int getServerAddress() { + return serverAddress; + } + + public void setServerAddress(int serverAddress) { + if (Modbus.checkServerAddress(serverAddress)) + this.serverAddress = serverAddress; + } + + public boolean isBroadcastEnabled() { + return broadcastEnabled.get(); + } + + public void setBroadcastEnabled(boolean broadcastEnabled) { + this.broadcastEnabled.set(broadcastEnabled); + } + + protected List getConnectionList() { + return connectionList; + } + + void connectionOpened(ModbusConnection connection) { + connection.setReadTimeout(getReadTimeout()); + getConnectionList().add(connection); + } + + void connectionClosed(ModbusConnection connection) { + getConnectionList().remove(connection); + } + + @Override + public void addListener(FrameEventListener listener) { + for (ModbusConnection c : getConnectionList()) { + c.addListener(listener); + } + } + + @Override + public void removeListener(FrameEventListener listener) { + for (ModbusConnection c : getConnectionList()) { + c.removeListener(listener); + } + } + + @Override + public void removeListeners() { + for (ModbusConnection c : getConnectionList()) { + c.removeListeners(); + } + } + + @Override + public void fireFrameReceivedEvent(FrameEvent event) { + for (ModbusConnection c : getConnectionList()) { + c.fireFrameReceivedEvent(event); + } + } + + @Override + public void fireFrameSentEvent(FrameEvent event) { + for (ModbusConnection c : getConnectionList()) { + c.fireFrameSentEvent(event); + } + } + + @Override + public int countListeners() { + int count = 0; + for (ModbusConnection c : getConnectionList()) { + count += c.countListeners(); + } + return count; + } + + /* + facade + */ + public void addObserver(Observer observer) { + observable.addObserver(observer); + } + + public void deleteObserver(Observer observer) { + observable.deleteObserver(observer); + } + + public void deleteObservers() { + observable.deleteObservers(); + } + + public int countObservers() { + return observable.countObservers(); + } + + protected void notifyObservers(Object o) { + observable.notifyObservers(o); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveASCII.java b/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveASCII.java new file mode 100644 index 0000000..40f5b58 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveASCII.java @@ -0,0 +1,44 @@ +package com.intelligt.modbus.jlibmodbus.slave; + +import com.intelligt.modbus.jlibmodbus.net.ModbusConnectionFactory; +import com.intelligt.modbus.jlibmodbus.serial.SerialParameters; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; +import com.intelligt.modbus.jlibmodbus.serial.SerialPortException; +import com.intelligt.modbus.jlibmodbus.serial.SerialUtils; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusSlaveASCII extends ModbusSlaveSerial { + + public ModbusSlaveASCII(SerialParameters sp) throws SerialPortException { + super(sp, ModbusConnectionFactory.getASCII(SerialUtils.createSerial(sp))); + } + + public ModbusSlaveASCII(String device, SerialPort.BaudRate baudRate, SerialPort.Parity parity) throws SerialPortException { + this(new SerialParameters(device, baudRate, 7, parity == SerialPort.Parity.NONE ? 2 : 1, parity)); + } + + public ModbusSlaveASCII(String device, SerialPort.BaudRate baudRate) throws SerialPortException { + this(device, baudRate, SerialPort.Parity.EVEN); + } + +} diff --git a/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveFactory.java b/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveFactory.java new file mode 100644 index 0000000..52c697f --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveFactory.java @@ -0,0 +1,87 @@ +package com.intelligt.modbus.jlibmodbus.slave; + +import com.intelligt.modbus.jlibmodbus.serial.SerialParameters; +import com.intelligt.modbus.jlibmodbus.serial.SerialPortException; +import com.intelligt.modbus.jlibmodbus.tcp.TcpParameters; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +final public class ModbusSlaveFactory { + + private ModbusSlaveFactory() { + + } + + /** + * Creates a ModbusSlaveRTU instance. + * + * @param sp parameters of the serial port + * @return the newly created rtu-slave + * @see SerialParameters + * @see ModbusSlaveRTU + * @see ModbusSlave + */ + static public ModbusSlave createModbusSlaveRTU(SerialParameters sp) throws SerialPortException { + return new ModbusSlaveRTU(sp); + } + + /** + * Creates a ModbusSlaveASCII instance. + * + * @param sp parameters of the serial port + * @return the newly created ascii-slave + * @see SerialParameters + * @see ModbusSlaveASCII + * @see ModbusSlave + */ + static public ModbusSlave createModbusSlaveASCII(SerialParameters sp) throws SerialPortException { + return new ModbusSlaveASCII(sp); + } + + /** + * Creates a ModbusSlaveTCP instance. + * + * @param tcpParameters tcp parameters. + * @return the newly created tcp-slave + * @see ModbusSlaveTCP + * @see ModbusSlave + * @see TcpParameters + */ + static public ModbusSlave createModbusSlaveTCP(TcpParameters tcpParameters) { + return new ModbusSlaveTCP(tcpParameters); + } + + /** + * Creates a ModbusSlaveTCP instance. + * + * @param tcpParameters tcp parameters. + * @param poolSize the number of threads in the pool + * @return the newly created tcp-slave + * @see ModbusSlaveTCP + * @see ModbusSlave + * @see TcpParameters + */ + static public ModbusSlave createModbusSlaveTCP(TcpParameters tcpParameters, int poolSize) { + return new ModbusSlaveTCP(tcpParameters, poolSize); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveRTU.java b/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveRTU.java new file mode 100644 index 0000000..8e23b6c --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveRTU.java @@ -0,0 +1,39 @@ +package com.intelligt.modbus.jlibmodbus.slave; + +import com.intelligt.modbus.jlibmodbus.net.ModbusConnectionFactory; +import com.intelligt.modbus.jlibmodbus.serial.SerialParameters; +import com.intelligt.modbus.jlibmodbus.serial.SerialPort; +import com.intelligt.modbus.jlibmodbus.serial.SerialPortException; +import com.intelligt.modbus.jlibmodbus.serial.SerialUtils; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusSlaveRTU extends ModbusSlaveSerial { + + public ModbusSlaveRTU(SerialParameters sp) throws SerialPortException { + super(sp, ModbusConnectionFactory.getRTU(SerialUtils.createSerial(sp))); + } + + public ModbusSlaveRTU(String device, SerialPort.BaudRate baudRate, int dataBits, int stopBits, SerialPort.Parity parity) throws SerialPortException { + this(new SerialParameters(device, baudRate, dataBits, stopBits, parity)); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveSerial.java b/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveSerial.java new file mode 100644 index 0000000..7871fec --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveSerial.java @@ -0,0 +1,116 @@ +package com.intelligt.modbus.jlibmodbus.slave; + +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.net.ModbusConnection; +import com.intelligt.modbus.jlibmodbus.serial.SerialParameters; +import com.intelligt.modbus.jlibmodbus.utils.FrameEvent; +import com.intelligt.modbus.jlibmodbus.utils.FrameEventListener; +import com.intelligt.modbus.jlibmodbus.utils.SerialPortInfo; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +class ModbusSlaveSerial extends ModbusSlave { + + final private ModbusConnection conn; + final private RequestHandler requestHandler; + final private SerialPortInfo serialPortInfo; + private Thread mainThread = null; + + ModbusSlaveSerial(SerialParameters serialParameters, ModbusConnection conn) { + this.conn = conn; + this.serialPortInfo = new SerialPortInfo(serialParameters); + this.requestHandler = new RequestHandlerSerial(this, conn); + } + + @Override + synchronized public void listenImpl() throws ModbusIOException { + if (isListening()) { + shutdown(); + } + mainThread = new Thread(requestHandler); + mainThread.start(); + } + + @Override + synchronized public void shutdownImpl() throws ModbusIOException { + requestHandler.closeConnection(); + try { + if (mainThread != null) { + mainThread.join(getReadTimeout() * 10); + if (mainThread.isAlive()) + mainThread.interrupt(); + } + mainThread = null; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + protected ModbusConnection getConnection() { + return conn; + } + + @Override + void connectionOpened(ModbusConnection connection) { + super.connectionOpened(connection); + serialPortInfo.setOpened(true); + notifyObservers(serialPortInfo); + } + + @Override + void connectionClosed(ModbusConnection connection) { + super.connectionClosed(connection); + serialPortInfo.setOpened(false); + notifyObservers(serialPortInfo); + } + + /* facade */ + @Override + public void addListener(FrameEventListener listener) { + getConnection().addListener(listener); + } + + @Override + public void removeListener(FrameEventListener listener) { + getConnection().removeListener(listener); + } + + @Override + public void removeListeners() { + getConnection().removeListeners(); + } + + @Override + public void fireFrameReceivedEvent(FrameEvent event) { + getConnection().fireFrameReceivedEvent(event); + } + + @Override + public void fireFrameSentEvent(FrameEvent event) { + fireFrameSentEvent(event); + } + + @Override + public int countListeners() { + return getConnection().countListeners(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveTCP.java b/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveTCP.java new file mode 100644 index 0000000..c88e396 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/slave/ModbusSlaveTCP.java @@ -0,0 +1,147 @@ +package com.intelligt.modbus.jlibmodbus.slave; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.net.ModbusConnection; +import com.intelligt.modbus.jlibmodbus.net.ModbusSlaveConnectionTCP; +import com.intelligt.modbus.jlibmodbus.tcp.TcpParameters; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class ModbusSlaveTCP extends ModbusSlave implements Runnable { + + final private static int DEFAULT_POOLS_SIZE = 10; + final private ExecutorService threadPool; + final private TcpParameters tcp; + private Thread mainThread = null; + private ServerSocket server = null; + + public ModbusSlaveTCP(TcpParameters tcp) { + this(tcp, DEFAULT_POOLS_SIZE); + } + + public ModbusSlaveTCP(TcpParameters tcp, int poolsSize) { + this.tcp = new TcpParameters(tcp); + threadPool = Executors.newFixedThreadPool(poolsSize); + } + + @Override + synchronized public void listenImpl() throws ModbusIOException { + try { + server = new ServerSocket(tcp.getPort()); + mainThread = new Thread(this); + setListening(true); + mainThread.start(); + } catch (IOException e) { + throw new ModbusIOException(e); + } + } + + @Override + synchronized public void shutdownImpl() { + /* + close server socket + */ + try { + if (server != null) + server.close(); + } catch (IOException e) { + Modbus.log().warning(e.getLocalizedMessage()); + } finally { + server = null; + } + /* + shutdown the thread pool + */ + threadPool.shutdown(); + try { + threadPool.awaitTermination(1, TimeUnit.SECONDS); + } catch (InterruptedException e) { + threadPool.shutdownNow(); + } + + try { + if (mainThread != null) { + mainThread.join(1000); + if (mainThread.isAlive()) + mainThread.interrupt(); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + mainThread = null; + } + } + + @Override + void connectionOpened(ModbusConnection connection) { + super.connectionOpened(connection); + notifyObservers(((ModbusSlaveConnectionTCP) connection).getClientInfo()); + } + + @Override + void connectionClosed(ModbusConnection connection) { + super.connectionClosed(connection); + notifyObservers(((ModbusSlaveConnectionTCP) connection).getClientInfo()); + } + + @Override + public void run() { + Socket s; + try { + while (isListening()) { + s = server.accept(); + try { + threadPool.execute(new RequestHandlerTCP(this, s)); + } catch (ModbusIOException ioe) { + Modbus.log().warning(ioe.getLocalizedMessage()); + s.close(); + } + } + } catch (SocketException e) { + if (server != null && !server.isClosed()) { + Modbus.log().warning(e.getLocalizedMessage()); + e.printStackTrace(); + } + } catch (IOException e) { + Modbus.log().warning(e.getLocalizedMessage()); + e.printStackTrace(); + } finally { + if (isListening()) { + try { + shutdown(); + } catch (ModbusIOException e) { + Modbus.log().warning(e.getLocalizedMessage()); + e.printStackTrace(); + } + } + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/slave/RequestHandler.java b/src/com/intelligt/modbus/jlibmodbus/slave/RequestHandler.java new file mode 100644 index 0000000..2e25c73 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/slave/RequestHandler.java @@ -0,0 +1,54 @@ +package com.intelligt.modbus.jlibmodbus.slave; + +import com.intelligt.modbus.jlibmodbus.net.ModbusConnection; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +abstract public class RequestHandler implements Runnable { + + final private ModbusSlave slave; + final private ModbusConnection conn; + volatile private boolean listening = false; + + public RequestHandler(ModbusSlave slave, ModbusConnection conn) { + this.slave = slave; + this.conn = conn; + } + + public boolean isListening() { + return listening; + } + + protected void setListening(boolean listening) { + this.listening = listening; + } + + abstract public void closeConnection(); + + public ModbusSlave getSlave() { + return slave; + } + + public ModbusConnection getConnection() { + return conn; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/slave/RequestHandlerSerial.java b/src/com/intelligt/modbus/jlibmodbus/slave/RequestHandlerSerial.java new file mode 100644 index 0000000..2061f95 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/slave/RequestHandlerSerial.java @@ -0,0 +1,118 @@ +package com.intelligt.modbus.jlibmodbus.slave; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.CommStatus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.data.comm.ModbusCommEventSend; +import com.intelligt.modbus.jlibmodbus.exception.ModbusChecksumException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusResponse; +import com.intelligt.modbus.jlibmodbus.msg.request.GetCommEventCounterRequest; +import com.intelligt.modbus.jlibmodbus.msg.request.GetCommEventLogRequest; +import com.intelligt.modbus.jlibmodbus.net.ModbusConnection; +import com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransport; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +class RequestHandlerSerial extends RequestHandler { + + RequestHandlerSerial(ModbusSlave slave, ModbusConnection conn) { + super(slave, conn); + } + + @Override + public void closeConnection() { + setListening(false); + } + + @Override + public void run() { + try { + getConnection().open(); + getSlave().connectionOpened(getConnection()); + setListening(true); + do { + DataHolder dataHolder = getSlave().getDataHolder(); + CommStatus commStatus = dataHolder.getCommStatus(); + ModbusTransport transport = getConnection().getTransport(); + try { + ModbusRequest request = (ModbusRequest) transport.readRequest(); + + commStatus.incBusMessageCounter(); + if (!(request instanceof GetCommEventCounterRequest || + request instanceof GetCommEventLogRequest)) { + commStatus.enter(); + } + if (request.getServerAddress() == getSlave().getServerAddress()) { + try { + ModbusResponse response = request.process(dataHolder); + commStatus.incSlaveMessageCounter(); + if (response.isException()) { + commStatus.addEvent(ModbusCommEventSend.createExceptionSentRead()); + commStatus.incExErrorCounter(); + } else { + if (!(request instanceof GetCommEventCounterRequest || + request instanceof GetCommEventLogRequest)) { + commStatus.incEventCounter(); + } + } + if (!commStatus.isListenOnlyMode()) + transport.send(response); + if (commStatus.isRestartCommunicationsOption()) { + commStatus.restartCommunicationsOption(); + getSlave().shutdown(); + getSlave().listen(); + } + } catch (RuntimeException re) { + throw re; + } catch (Exception e) { + /* + * quantity of messages addressed to the remote device for + * which it has returned no response (neither a normal response nor an exception response) + */ + commStatus.incNoResponseCounter(); + throw e; + } + } else if (/*broadcast*/ request.getServerAddress() == Modbus.BROADCAST_ID && getSlave().isBroadcastEnabled()) { + //we do not answer these requests to avoid collisions on the bus + request.process(dataHolder); + } + } catch (ModbusChecksumException e) { + commStatus.incCommErrorCounter(); + } catch (Exception e) { + Modbus.log().warning(e.getLocalizedMessage()); + //e.printStackTrace(); + } finally { + commStatus.leave(); + } + } while (isListening()); + + if (getConnection().isOpened()) { + getConnection().close(); + getSlave().connectionClosed(getConnection()); + } + } catch (ModbusIOException e) { + Modbus.log().warning(e.getMessage()); + } + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/slave/RequestHandlerTCP.java b/src/com/intelligt/modbus/jlibmodbus/slave/RequestHandlerTCP.java new file mode 100644 index 0000000..2fce103 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/slave/RequestHandlerTCP.java @@ -0,0 +1,98 @@ +package com.intelligt.modbus.jlibmodbus.slave; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.data.DataHolder; +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusMessage; +import com.intelligt.modbus.jlibmodbus.msg.base.ModbusRequest; +import com.intelligt.modbus.jlibmodbus.net.ModbusConnectionFactory; +import com.intelligt.modbus.jlibmodbus.net.transport.ModbusTransport; + +import java.io.IOException; +import java.net.Socket; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +class RequestHandlerTCP extends RequestHandler { + + final private Socket socket; + + RequestHandlerTCP(ModbusSlaveTCP slave, Socket s) throws ModbusIOException { + super(slave, ModbusConnectionFactory.getTcpSlave(s)); + socket = s; + } + + @Override + public void run() { + setListening(true); + try { + getSlave().connectionOpened(getConnection()); + do { + try { + DataHolder dataHolder = getSlave().getDataHolder(); + ModbusTransport transport = getConnection().getTransport(); + ModbusRequest request = (ModbusRequest) transport.readRequest(); + + if (/*default tcp session*/request.getServerAddress() == Modbus.TCP_DEFAULT_ID || + /*gateway*/request.getServerAddress() == getSlave().getServerAddress()) { + ModbusMessage response = request.process(dataHolder); + response.setTransactionId(request.getTransactionId()); + if (request.getServerAddress() != Modbus.BROADCAST_ID) + transport.send(response); + } else if (/*broadcast*/ request.getServerAddress() == Modbus.BROADCAST_ID && getSlave().isBroadcastEnabled()) { + //we do not answer broadcast requests + request.process(dataHolder); + } + } catch (ModbusNumberException e) { + Modbus.log().warning(e.getLocalizedMessage()); + } + } while (isListening()); + } catch (ModbusIOException e) { + if (getSlave().isListening()) { + Modbus.log().warning(e.getLocalizedMessage()); + } + } finally { + setListening(false); + try { + if (getConnection().isOpened()) { + getConnection().close(); + getSlave().connectionClosed(getConnection()); + } + } catch (ModbusIOException ioe) { + Modbus.log().warning(ioe.getMessage()); + } + } + } + + @Override + public void closeConnection() { + try { + if (socket.isConnected() && !isListening()) { + socket.close(); + setListening(false); + } + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/tcp/TcpAduHeader.java b/src/com/intelligt/modbus/jlibmodbus/tcp/TcpAduHeader.java new file mode 100644 index 0000000..480a218 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/tcp/TcpAduHeader.java @@ -0,0 +1,106 @@ +package com.intelligt.modbus.jlibmodbus.tcp; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.exception.ModbusIOException; +import com.intelligt.modbus.jlibmodbus.exception.ModbusNumberException; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusInputStream; +import com.intelligt.modbus.jlibmodbus.net.stream.base.ModbusOutputStream; +import com.intelligt.modbus.jlibmodbus.utils.DataUtils; + +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class TcpAduHeader { + final private byte[] buffer; + + public TcpAduHeader() { + /* + * 2 bytes for transaction id (often not used) + * 2 bytes for protocol id (should be set to 0) + * 2 bytes for pdu length (from 3 to 260) + */ + buffer = new byte[6]; + setProtocolId(Modbus.PROTOCOL_ID); + } + + private void setBufferValue(int value, int offset) { + buffer[offset++] = DataUtils.byteHigh(value); + buffer[offset] = DataUtils.byteLow(value); + } + + private int getPduSize() { + return DataUtils.toShort(buffer[4], buffer[5]); + } + + public void setPduSize(int value) { + setBufferValue(value, 4); + } + + public int getProtocolId() { + return DataUtils.toShort(buffer[2], buffer[3]); + } + + public void setProtocolId(int value) { + setBufferValue(value, 2); + } + + public int getTransactionId() { + return DataUtils.toShort(buffer[0], buffer[1]); + } + + public void setTransactionId(int value) { + setBufferValue(value, 0); + } + + private byte[] byteArray() { + return buffer; + } + + public void write(ModbusOutputStream fifo) throws ModbusIOException { + try { + fifo.write(byteArray()); + } catch (IOException e) { + throw new ModbusIOException(e); + } + } + + public void read(ModbusInputStream fifo) throws ModbusNumberException, ModbusIOException { + int size; + + try { + if ((size = fifo.read(byteArray())) > 0) { + + if (getPduSize() < Modbus.MIN_PDU_LENGTH) { + throw new ModbusNumberException("the PDU length is less than the minimum expected.", getPduSize()); + } + if (getPduSize() > Modbus.MAX_PDU_LENGTH) { + throw new ModbusNumberException("Maximum PDU size is reached.", getPduSize()); + } + } else { + throw new ModbusIOException(buffer.length + " bytes expected, but " + size + " received."); + } + } catch (IOException e) { + throw new ModbusIOException(e); + } + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/tcp/TcpParameters.java b/src/com/intelligt/modbus/jlibmodbus/tcp/TcpParameters.java new file mode 100644 index 0000000..fe37eae --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/tcp/TcpParameters.java @@ -0,0 +1,97 @@ +package com.intelligt.modbus.jlibmodbus.tcp; + +import com.intelligt.modbus.jlibmodbus.Modbus; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class TcpParameters { + private InetAddress host = null; + private int port; + private boolean keepAlive; + private int connectionTimeout = Modbus.MAX_CONNECTION_TIMEOUT; + + public TcpParameters() { + try { + setHost(InetAddress.getLocalHost()); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + setPort(Modbus.TCP_PORT); + setKeepAlive(true); + } + + public TcpParameters(TcpParameters p) { + this(p.getHost(), p.getPort(), p.isKeepAlive()); + setConnectionTimeout(p.getConnectionTimeout()); + } + + public TcpParameters(InetAddress host, int port, boolean keepAlive) { + setHost(host); + setPort(port); + setKeepAlive(keepAlive); + } + + public TcpParameters(String host, int port, boolean keepAlive) { + try { + setHost(InetAddress.getByName(host)); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + setPort(port); + setKeepAlive(keepAlive); + } + + public InetAddress getHost() { + return host; + } + + public void setHost(InetAddress host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public boolean isKeepAlive() { + return keepAlive; + } + + public void setKeepAlive(boolean keepAlive) { + this.keepAlive = keepAlive; + } + + public int getConnectionTimeout() { + return connectionTimeout; + } + + public void setConnectionTimeout(int connectionTimeout) { + this.connectionTimeout = connectionTimeout; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/ByteFifo.java b/src/com/intelligt/modbus/jlibmodbus/utils/ByteFifo.java new file mode 100644 index 0000000..20aae95 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/ByteFifo.java @@ -0,0 +1,102 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +final public class ByteFifo { + + final private ByteArrayOutputStream baos; + final private ByteArrayInputStream bais; + final private int capacity; + + public ByteFifo(int size) { + baos = new ByteArrayOutputStream(size); + bais = new ByteArrayInputStream(baos.getByteBuffer()); + capacity = size; + bais.mark(0); + reset(); + } + + public void reset() { + baos.reset(); + bais.reset(); + } + + public byte[] toByteArray() { + return baos.toByteArray(); + } + + public int size() { + return baos.size(); + } + + public int read() { + return available() > 0 ? bais.read() : -1; + } + + public int read(byte[] b) throws IOException { + return (available() < b.length) ? 0 : bais.read(b); + } + + public int read(byte[] b, int offset, int length) { + return (available() < b.length) ? 0 : bais.read(b, offset, length); + } + + public void write(int b) { + if (size() < capacity) { + baos.write(b); + } + } + + public void write(byte[] b) { + int available = (capacity - size()); + if (available > 0) { + int count = b.length < available ? b.length : available; + baos.write(b, 0, count); + } + } + + public void write(byte[] b, int off, int len) { + int available = (capacity - size()); + if (available > 0) { + int count = len < available ? len : available; + baos.write(b, off, count); + } + } + + public int available() { + return size() - (capacity - bais.available()); + } + + static private class ByteArrayOutputStream extends java.io.ByteArrayOutputStream { + + ByteArrayOutputStream(int size) { + super(size); + } + + byte[] getByteBuffer() { + return buf; + } + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/CRC16.java b/src/com/intelligt/modbus/jlibmodbus/utils/CRC16.java new file mode 100644 index 0000000..00f8a58 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/CRC16.java @@ -0,0 +1,106 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +public class CRC16 { + + final static public int INITIAL_VALUE = 0xFFFF; + final static private int[] table = { + 0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, + 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, + 0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, + 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, + 0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, + 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, + 0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, + 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, + 0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, + 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, + 0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, + 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, + 0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, + 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, + 0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, + 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, + 0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, + 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, + 0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, + 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, + 0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, + 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, + 0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, + 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, + 0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, + 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, + 0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, + 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, + 0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, + 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, + 0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, + 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040, + }; + + static public int calc(byte[] bytes) { + return calc(INITIAL_VALUE, bytes, bytes.length); + } + + static public int calc(int crc, byte[] bytes) { + return calc(crc, bytes, bytes.length); + } + + static public int calc(int crc, byte[] bytes, int length) { + return calc(crc, bytes, 0, length); + } + + static public int calc(int crc, byte[] bytes, int offset, int length) { + for (int i = offset; i < offset + length; i++) { + crc = calc(crc, bytes[i]); + } + + return crc; + } + + static public int calc(int crc, short[] words, int offset, int length) { + for (int i = offset; i < offset + length; i++) { + crc = calc(crc, (byte) (words[i] & 0xff)); + crc = calc(crc, (byte) ((words[i] >> 8) & 0xff)); + } + return crc; + } + + static public int calc(int crc, int[] dwords, int offset, int length) { + for (int i = offset; i < offset + length; i++) { + crc = calc(crc, (byte) (dwords[i] & 0xff)); + crc = calc(crc, (byte) ((dwords[i] >> 8) & 0xff)); + crc = calc(crc, (byte) ((dwords[i] >> 16) & 0xff)); + crc = calc(crc, (byte) ((dwords[i] >> 24) & 0xff)); + } + return crc; + } + + static public int calc(int crc, byte b) { + crc = (short) crc & 0xffff; + return (crc >>> 8) ^ table[(crc ^ b) & 0xff]; + } + +} diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/DataUtils.java b/src/com/intelligt/modbus/jlibmodbus/utils/DataUtils.java new file mode 100644 index 0000000..cca0a57 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/DataUtils.java @@ -0,0 +1,183 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +import java.util.Locale; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public class DataUtils { + + public static StringBuffer getString(byte[] b, int pos) { + StringBuffer sbu = new StringBuffer(); + sbu.append((char) b[pos]); + sbu.append((char) b[pos + 1]); +// sbu.append((char) b[pos + 2]); +// sbu.append((char) b[pos + 3]); +// sbu.append((char) b[pos + 4]); +// sbu.append((char) b[pos + 5]); +// sbu.append((char) b[pos + 6]); +// sbu.append((char) b[pos + 7]); + + return sbu; + } + static public int fromAscii(char h, char l) { + try { + return Integer.parseInt("" + h + l, 16); + } catch (NumberFormatException e) { + e.printStackTrace(); + return 0; + } + } + + static public String toAscii(byte b) { + return toHexString(b); + } + + static public String toAscii(byte[] bytes) { + return toAscii(bytes, 0, bytes.length); + } + + static public String toAscii(byte[] bytes, int offset, int length) { + StringBuilder sb = new StringBuilder(); + int tail = offset + length; + + for (int i = offset; i < tail; i++) { + sb.append(toHexString(bytes[i])); + } + + return sb.toString().toUpperCase(Locale.ENGLISH); + } + + static public String toHexString(byte b) { + return (((b & 0xff) < 0x10) ? "0" : "") + Integer.toString(b & 0xff, 16).toUpperCase(Locale.ENGLISH); + } + + static public byte[] toByteArray(boolean[] bits) { + byte[] dst = new byte[(int) Math.ceil((double) bits.length / 8)]; + for (int i = 0; i < bits.length; i++) { + dst[i / 8] |= (byte) ((bits[i] ? 1 : 0) << (i % 8)); + } + return dst; + } + + static public boolean[] toBitsArray(byte[] bytes, int bitCount) { + boolean[] dst = new boolean[bitCount]; + for (int i = 0; i < dst.length; i++) { + dst[i] = (bytes[i / 8] & (1 << (i % 8))) != 0; + } + return dst; + } + + static public int[] BeToIntArray(byte[] bytes) { + int[] dst = new int[bytes.length / 2]; + for (int i = 0, j = 0; i < dst.length; i++, j += 2) + dst[i] = ((bytes[j] & 0xff) << 8) | (bytes[j + 1] & 0xff); + return dst; + } + + static public int[] LeToIntArray(byte[] bytes) { + int[] dst = new int[bytes.length / 2]; + for (int i = 0, j = 0; i < dst.length; i++, j += 2) + dst[i] = ((bytes[j + 1] & 0xff) << 8) | (bytes[j] & 0xff); + return dst; + } + + static public byte[] toByteArray(int[] i16) { + byte[] dst = new byte[i16.length * 2]; + for (int i = 0, j = 0; i < i16.length; i++, j += 2) { + dst[j] = (byte) ((i16[i] >> 8) & 0xff); + dst[j + 1] = (byte) (i16[i] & 0xff); + } + return dst; + } + + static public byte[] toByteArray(short[] src) { + byte[] dst = new byte[src.length]; + for (int i = 0; i < src.length; i++) + dst[i] = (byte) src[i]; + return dst; + } + + public static byte[] toByteArray(short i16) { + return new byte[]{byteHigh(i16), byteLow(i16)}; + } + + public static int toShort(int h, int l) { + return ((h & 0xff) << 8) | (l & 0xff); + } + + public static byte[] toByteArray(int i32) { + byte[] regs = new byte[4]; + regs[0] = (byte) (0xff & (i32 >> 8)); + regs[1] = (byte) (0xff & i32); + regs[2] = (byte) (0xff & (i32 >> 24)); + regs[3] = (byte) (0xff & (i32 >> 16)); + return regs; + } + + public static float toFloat(byte[] bytes) { + return Float.intBitsToFloat( + ((bytes[0] & 0xff) << 8) | + (bytes[1] & 0xff) | + ((bytes[2] & 0xff) << 24) | + ((bytes[3] & 0xff) << 16)); + } + + public static byte[] toByteArray(float f32) { + return toByteArray(Float.floatToIntBits(f32)); + } + + public static byte byteLow(int b) { + return (byte) ((short) b & 0xff); + } + + public static byte byteHigh(int b) { + return (byte) (((short) b >> 8) & 0xff); + } + + public static int wordLow(int b) { + return b & 0xffff; + } + + public static int wordHigh(int b) { + return (b >> 16) & 0xffff; + } + + public static int dwordLow(long l) { + return (int) (l & 0xffffffff); + } + + public static int dwordHigh(long l) { + return (int) ((l >> 32) & 0xffffffff); + } + + public static int wordFromBytes(int l, int h) { + return (l & 0xff) | ((h & 0xff) << 8); + } + + public static int dwordFromWords(int l, int h) { + return (l & 0xffff) | ((h & 0xffff) << 16); + } + + public static long Int64FromDwords(int l, int h) { + return ((long) l & 0xffffffff) | (((long) h & 0xffffffff) << 32); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/DiagnosticsSubFunctionCode.java b/src/com/intelligt/modbus/jlibmodbus/utils/DiagnosticsSubFunctionCode.java new file mode 100644 index 0000000..e25363e --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/DiagnosticsSubFunctionCode.java @@ -0,0 +1,89 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * The list of sub-function codes supported by the serial line devices. + * Hex Dec + * 00 00 Return Query Data + * 01 01 Restart Communications Option + * 02 02 Return Diagnostic Register + * 03 03 Change ASCII Input Delimiter + * 04 04 Force Listen Only Mode + * 05.. 09 RESERVED + * 0A 10 Clear Counters and Diagnostic Register + * 0B 11 Return Bus Message Count + * 0C 12 Return Bus Communication Error Count + * 0D 13 Return Bus Exception Error Count + * 0E 14 Return Slave Message Count + * 0F 15 Return Slave No Response Count + * 10 16 Return Slave NAK Count + * 11 17 Return Slave Busy Count + * 12 18 Return Bus Character Overrun Count + * 13 19 RESERVED + * 14 20 Clear Overrun Counter and Flag + * N.A. 21 ... + * 65535 + */ +public enum DiagnosticsSubFunctionCode { + RETURN_QUERY_DATA(0x0), + RESTART_COMMUNICATIONS_OPTION(0x1), + RETURN_DIAGNOSTIC_REGISTER(0x2), + CHANGE_ASCII_INPUT_DELIMITER(0x3), + FORCE_LISTEN_ONLY_MODE(0x4), + CLEAR_COUNTERS_AND_DIAGNOSTIC_REGISTER(0xA), + RETURN_BUS_MESSAGE_COUNT(0xB), + RETURN_BUS_COMMUNICATION_ERROR_COUNT(0xC), + RETURN_BUS_EXCEPTION_ERROR_COUNT(0x0D), + RETURN_SLAVE_MESSAGE_COUNT(0x0E), + RETURN_SLAVE_NO_RESPONSE_COUNT(0x0F), + RETURN_SLAVE_NAK_COUNT(0x10), + RETURN_SLAVE_BUSY_COUNT(0x11), + RETURN_BUS_CHARACTER_OVERRUN_COUNT(0x12), + CLEAR_OVERRUN_COUNTER_AND_FLAG(0x14), + RESERVED(0xffff); + + final private int value; + + DiagnosticsSubFunctionCode(int value) { + this.value = value; + } + + static public DiagnosticsSubFunctionCode get(int value) { + for (DiagnosticsSubFunctionCode func : DiagnosticsSubFunctionCode.values()) { + if (func.value == value) { + return func; + } + } + return RESERVED; + } + + public int toInt() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/FrameEvent.java b/src/com/intelligt/modbus/jlibmodbus/utils/FrameEvent.java new file mode 100644 index 0000000..6a3f7b3 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/FrameEvent.java @@ -0,0 +1,40 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +import java.util.EventListener; +/* + * Copyright (C) 2017 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * @author kochedykov + * @since 1.9.0 + */ +public class FrameEvent implements EventListener { + final private byte[] bytes; + + public FrameEvent(byte[] bytes) { + this.bytes = bytes; + } + + public byte[] getBytes() { + return bytes; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/FrameEventListener.java b/src/com/intelligt/modbus/jlibmodbus/utils/FrameEventListener.java new file mode 100644 index 0000000..c16d187 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/FrameEventListener.java @@ -0,0 +1,34 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +import java.util.EventListener; +/* + * Copyright (C) 2017 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * @author kochedykov + * @since 1.9.0 + */ +public interface FrameEventListener extends EventListener { + void frameSentEvent(FrameEvent event); + + void frameReceivedEvent(FrameEvent event); +} diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/FrameEventListenerList.java b/src/com/intelligt/modbus/jlibmodbus/utils/FrameEventListenerList.java new file mode 100644 index 0000000..77b9553 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/FrameEventListenerList.java @@ -0,0 +1,40 @@ +package com.intelligt.modbus.jlibmodbus.utils; +/* + * Copyright (C) 2017 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * @author kochedykov + * @since 1.9.0 + */ +public interface FrameEventListenerList { + void addListener(FrameEventListener listener); + + void removeListener(FrameEventListener listener); + + void removeListeners(); + + void fireFrameReceivedEvent(FrameEvent event); + + void fireFrameSentEvent(FrameEvent event); + + int countListeners(); +} diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/FrameEventListenerListImpl.java b/src/com/intelligt/modbus/jlibmodbus/utils/FrameEventListenerListImpl.java new file mode 100644 index 0000000..449ae49 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/FrameEventListenerListImpl.java @@ -0,0 +1,71 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +import java.util.ArrayList; +import java.util.List; +/* + * Copyright (C) 2017 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * @author kochedykov + * @since 1.9.0 + */ +public class FrameEventListenerListImpl implements FrameEventListenerList { + private final List eventListenerList = new ArrayList(); + + public FrameEventListenerListImpl() { + + } + + public void addListener(FrameEventListener listener) { + synchronized (this) { + eventListenerList.add(listener); + } + } + + public void removeListener(FrameEventListener listener) { + synchronized (this) { + eventListenerList.remove(listener); + } + } + + @Override + public void removeListeners() { + eventListenerList.clear(); + } + + public void fireFrameReceivedEvent(FrameEvent event) { + for (FrameEventListener l : eventListenerList) { + l.frameReceivedEvent(event); + } + } + + public void fireFrameSentEvent(FrameEvent event) { + for (FrameEventListener l : eventListenerList) { + l.frameSentEvent(event); + } + } + + @Override + public int countListeners() { + return eventListenerList.size(); + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/LRC.java b/src/com/intelligt/modbus/jlibmodbus/utils/LRC.java new file mode 100644 index 0000000..be5db3d --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/LRC.java @@ -0,0 +1,37 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/** + * following class implements longitudinal redundancy checkFrame. + */ +public class LRC { + static public int calc(byte[] b) { + int lrc = 0; + + for (byte aB : b) { + lrc += aB; + } + return (byte) (-lrc) & 0xff; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/MEITypeCode.java b/src/com/intelligt/modbus/jlibmodbus/utils/MEITypeCode.java new file mode 100644 index 0000000..fa15f6f --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/MEITypeCode.java @@ -0,0 +1,52 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public enum MEITypeCode { + CAN_OPEN_PDU(0x0D), + READ_DEVICE_IDENTIFICATION(0x0E), + RESERVED(0xff); + + final private int value; + + MEITypeCode(int value) { + this.value = value; + } + + static public MEITypeCode get(int value) { + for (MEITypeCode func : MEITypeCode.values()) { + if (func.value == value) { + return func; + } + } + return RESERVED; + } + + public int toInt() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/ModbusExceptionCode.java b/src/com/intelligt/modbus/jlibmodbus/utils/ModbusExceptionCode.java new file mode 100644 index 0000000..29f27a7 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/ModbusExceptionCode.java @@ -0,0 +1,61 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ +public enum ModbusExceptionCode { + ILLEGAL_FUNCTION(0x01), + ILLEGAL_DATA_ADDRESS(0x02), + ILLEGAL_DATA_VALUE(0x03), + SLAVE_DEVICE_FAILURE(0x04), + ACKNOWLEDGE(0x05), + SLAVE_DEVICE_BUSY(0x06), + MEMORY_PARITY_ERROR(0x08), + GATEWAY_PATH_UNAVAILABLE(0x0A), + GATEWAY_TARGET_DEVICE_FAILED_TO_RESPOND(0x0B), + + UNKNOWN_EXCEPTION(0x100), + NO_EXCEPTION(0x101); + + private final int value; + + ModbusExceptionCode(int value) { + this.value = value; + } + + static public ModbusExceptionCode get(int value) { + for (ModbusExceptionCode type : ModbusExceptionCode.values()) { + if (type.value == value) { + return type; + } + } + return UNKNOWN_EXCEPTION; + } + + public int getValue() { + return value; + } + + @Override + public String toString() { + return name() + ": Exception Code = " + value; + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/ModbusFunctionCode.java b/src/com/intelligt/modbus/jlibmodbus/utils/ModbusFunctionCode.java new file mode 100644 index 0000000..dad7124 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/ModbusFunctionCode.java @@ -0,0 +1,151 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +/* + * Copyright (C) 2016 "Invertor" Factory", JSC + * [http://www.sbp-invertor.ru] + * + * This file is part of JLibModbus. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Authors: Vladislav Y. Kochedykov, software engineer. + * email: vladislav.kochedykov@gmail.com + */ + +/* +the list of available modbus functions + +01 (0x01) Read Coils +02 (0x02) Read Discrete Inputs +03 (0x03) Read Holding Registers +04 (0x04) Read Input Registers +05 (0x05) Write Single Coil +06 (0x06) Write Single Register +07 (0x07) Read Exception Status (Serial Line only) +08 (0x08) Diagnostics (Serial Line only) +11 (0x0B) Get Comm Event Counter (Serial Line only) +12 (0x0C) Get Comm Event Log (Serial Line only) +15 (0x0F) Write Multiple Coils +16 (0x10) Write Multiple registers +17 (0x11) Report Slave ID (Serial Line only) +20 (0x14) Read File Record +21 (0x15) Write File Record +22 (0x16) Mask Write Register +23 (0x17) Read/Write Multiple registers +24 (0x18) Read FIFO Queue +43 ( 0x2B) Encapsulated Interface Transport +43 / 13 (0x2B / 0x0D) CAN open General Reference Request and Response PDU +43 / 14 (0x2B / 0x0E) Read Device Identification +*/ + +import java.util.HashMap; +import java.util.Map; + +/** + * a enum containing all modbus-function-codes listed in the modbus protocol v1.1b: + *

+ * 01 (0x01) Read Coils + * 02 (0x02) Read Discrete Inputs + * 03 (0x03) Read Holding Registers + * 04 (0x04) Read Input Registers + * 05 (0x05) Write Single Coil + * 06 (0x06) Write Single Register + * 07 (0x07) Read Exception Status (Serial Line only) + * 08 (0x08) Diagnostics (Serial Line only) + * 11 (0x0B) Get Comm Event Counter (Serial Line only) + * 12 (0x0C) Get Comm Event Log (Serial Line only) + * 15 (0x0F) Write Multiple Coils + * 16 (0x10) Write Multiple registers + * 17 (0x11) Report Slave ID (Serial Line only) + * 20 (0x14) Read File Record + * 21 (0x15) Write File Record + * 22 (0x16) Mask Write Register + * 23 (0x17) Read/Write Multiple registers + * 24 (0x18) Read FIFO Queue + * 43 ( 0x2B) Encapsulated Interface Transport + * 43 / 13 (0x2B / 0x0D) CAN open General Reference Request and Response PDU + * 43 / 14 (0x2B / 0x0E) Read Device Identification + */ +public enum ModbusFunctionCode { + READ_COILS(0x1), + READ_DISCRETE_INPUTS(0x2), + READ_HOLDING_REGISTERS(0x3), + READ_INPUT_REGISTERS(0x4), + WRITE_SINGLE_COIL(0x5), + WRITE_SINGLE_REGISTER(0x6), + READ_EXCEPTION_STATUS(0x7),//serial line only + DIAGNOSTICS(0x8),//serial line only + GET_COMM_EVENT_COUNTER(0x0B),//serial line only + GET_COMM_EVENT_LOG(0x0C),//serial line only + WRITE_MULTIPLE_COILS(0x0F), + WRITE_MULTIPLE_REGISTERS(0x10), + REPORT_SLAVE_ID(0x11),//serial line only + READ_FILE_RECORD(0x14), + WRITE_FILE_RECORD(0x15), + MASK_WRITE_REGISTER(0x16), + READ_WRITE_MULTIPLE_REGISTERS(0x17), + READ_FIFO_QUEUE(0x18), + ENCAPSULATED_INTERFACE_TRANSPORT(0x2B), + /** + * this function code is not presented in the modbus protocol specification. + * ModbusFunctionCode.get(int value) returns UNKNOWN + * if value is not listed in ModbusFunctionCode. + */ + UNKNOWN(0xff); + + final static private int MODBUS_EXCEPTION_FLAG = 0x80; + /** + * create the map containing all values of this enum for the optimization purpose. + */ + final static private Map values = new HashMap(ModbusFunctionCode.values().length); + + static { + for (ModbusFunctionCode func : ModbusFunctionCode.values()) { + values.put(func.value, func); + } + } + + final private int value; + + ModbusFunctionCode(int value) { + this.value = value; + } + + static public ModbusFunctionCode get(int value) { + if (isException(value)) { + value &= ~MODBUS_EXCEPTION_FLAG; + } + + if (values.containsKey(value)) { + return values.get(value); + } + return UNKNOWN; + } + + static public boolean isException(int value) { + return (value & MODBUS_EXCEPTION_FLAG) != 0; + } + + static public int getExceptionValue(int functionCode) { + return functionCode | MODBUS_EXCEPTION_FLAG; + } + + public int toInt() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } +} \ No newline at end of file diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/ModbusSlaveSerialObserver.java b/src/com/intelligt/modbus/jlibmodbus/utils/ModbusSlaveSerialObserver.java new file mode 100644 index 0000000..6d82a5e --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/ModbusSlaveSerialObserver.java @@ -0,0 +1,22 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +import java.util.Observable; +import java.util.Observer; + +abstract public class ModbusSlaveSerialObserver implements Observer { + @Override + public void update(Observable o, Object arg) { + if (arg instanceof SerialPortInfo) { + SerialPortInfo serialPortInfo = (SerialPortInfo) arg; + if (serialPortInfo.isOpened()) { + clientAccepted(serialPortInfo); + } else { + clientDisconnected(serialPortInfo); + } + } + } + + public abstract void clientAccepted(SerialPortInfo info); + + public abstract void clientDisconnected(SerialPortInfo info); +} diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/ModbusSlaveTcpObserver.java b/src/com/intelligt/modbus/jlibmodbus/utils/ModbusSlaveTcpObserver.java new file mode 100644 index 0000000..3be8019 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/ModbusSlaveTcpObserver.java @@ -0,0 +1,22 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +import java.util.Observable; +import java.util.Observer; + +abstract public class ModbusSlaveTcpObserver implements Observer { + @Override + public void update(Observable o, Object arg) { + if (arg instanceof TcpClientInfo) { + TcpClientInfo clientInfo = (TcpClientInfo) arg; + if (clientInfo.isConnected()) { + clientAccepted(clientInfo); + } else { + clientDisconnected(clientInfo); + } + } + } + + public abstract void clientAccepted(TcpClientInfo info); + + public abstract void clientDisconnected(TcpClientInfo info); +} diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/SerialPortInfo.java b/src/com/intelligt/modbus/jlibmodbus/utils/SerialPortInfo.java new file mode 100644 index 0000000..1b0647b --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/SerialPortInfo.java @@ -0,0 +1,28 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +import com.intelligt.modbus.jlibmodbus.serial.SerialParameters; + +public class SerialPortInfo { + volatile boolean isOpened = false; + private SerialParameters serialParameters = new SerialParameters(); + + public SerialPortInfo(SerialParameters serialParameters) { + this.serialParameters = serialParameters; + } + + public SerialParameters getSerialParameters() { + return serialParameters; + } + + public void setSerialParameters(SerialParameters serialParameters) { + this.serialParameters = serialParameters; + } + + public boolean isOpened() { + return isOpened; + } + + public void setOpened(boolean opened) { + isOpened = opened; + } +} diff --git a/src/com/intelligt/modbus/jlibmodbus/utils/TcpClientInfo.java b/src/com/intelligt/modbus/jlibmodbus/utils/TcpClientInfo.java new file mode 100644 index 0000000..d3e81b1 --- /dev/null +++ b/src/com/intelligt/modbus/jlibmodbus/utils/TcpClientInfo.java @@ -0,0 +1,30 @@ +package com.intelligt.modbus.jlibmodbus.utils; + +import com.intelligt.modbus.jlibmodbus.tcp.TcpParameters; + +public class TcpClientInfo { + private TcpParameters tcpParameters = new TcpParameters(); + + volatile private boolean connected; + + public TcpClientInfo(TcpParameters tcpParameters, boolean connected) { + this.tcpParameters = tcpParameters; + this.connected = connected; + } + + public TcpParameters getTcpParameters() { + return tcpParameters; + } + + public void setTcpParameters(TcpParameters tcpParameters) { + this.tcpParameters = tcpParameters; + } + + public boolean isConnected() { + return connected; + } + + public void setConnected(boolean connected) { + this.connected = connected; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/entity/BasDevice.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/BasDevice.hbm.xml new file mode 100644 index 0000000..39f1f79 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/BasDevice.hbm.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/BasDevice.java b/src/com/wms/dss/ats/customs/abb/entity/BasDevice.java new file mode 100644 index 0000000..3b45a88 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/BasDevice.java @@ -0,0 +1,41 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class BasDevice { + + private String device_id; + private String device_name; + private String device_type; + private String locked; + + public String getDevice_id() { + return device_id; + } + + public void setDevice_id(String device_id) { + this.device_id = device_id; + } + + public String getDevice_name() { + return device_name; + } + + public void setDevice_name(String device_name) { + this.device_name = device_name; + } + + public String getDevice_type() { + return device_type; + } + + public void setDevice_type(String device_type) { + this.device_type = device_type; + } + + public String getLocked() { + return locked; + } + + public void setLocked(String locked) { + this.locked = locked; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/entity/BasFaultRecord.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/BasFaultRecord.hbm.xml new file mode 100644 index 0000000..4780d13 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/BasFaultRecord.hbm.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/BasFaultRecord.java b/src/com/wms/dss/ats/customs/abb/entity/BasFaultRecord.java new file mode 100644 index 0000000..5cb71ab --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/BasFaultRecord.java @@ -0,0 +1,121 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class BasFaultRecord { + + private String id; + private String deviceId; + private String deviceName; + private String deviceType; + private String taskNo; + private String jobId; + private String startTime; + private String finishTime; + private String alarmStatus; + private String alarmCode; + private String reset; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getTaskNo() { + return taskNo; + } + + public void setTaskNo(String taskNo) { + this.taskNo = taskNo; + } + + public String getJobId() { + return jobId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public String getFinishTime() { + return finishTime; + } + + public void setFinishTime(String finishTime) { + this.finishTime = finishTime; + } + + public String getAlarmStatus() { + return alarmStatus; + } + + public void setAlarmStatus(String alarmStatus) { + this.alarmStatus = alarmStatus; + } + + public String getAlarmCode() { + return alarmCode; + } + + public void setAlarmCode(String alarmCode) { + this.alarmCode = alarmCode; + } + + public String getReset() { + return reset; + } + + public void setReset(String reset) { + this.reset = reset; + } + + @Override + public String toString() { + return "BasFaultRecord{" + + "id='" + id + '\'' + + ", deviceId='" + deviceId + '\'' + + ", deviceName='" + deviceName + '\'' + + ", deviceType='" + deviceType + '\'' + + ", taskNo='" + taskNo + '\'' + + ", jobId='" + jobId + '\'' + + ", startTime='" + startTime + '\'' + + ", finishTime='" + finishTime + '\'' + + ", alarmStatus='" + alarmStatus + '\'' + + ", alarmCode='" + alarmCode + '\'' + + ", reset='" + reset + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/entity/CMP_Device.java b/src/com/wms/dss/ats/customs/abb/entity/CMP_Device.java new file mode 100644 index 0000000..5bf46ce --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/CMP_Device.java @@ -0,0 +1,45 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class CMP_Device { + public byte btId; //id + public String dtype; //ÀàÐÍ + public String dName; //Ãû³Æ + + public long RWH; //ÈÎÎñºÅ + public int MPXH; //ÂúÅÌÐźŠ+ public int KPXH; //¿ÕÅÌÐźŠ+ public int CZFS; //²Ù×÷·½Ê½ + public int SBZT; //É豸״̬ + public int TPLX; //ÍÐÅÌÀàÐÍ + public int YXXF; //ÔÊÐíÏ·¢ + public int JYM; //УÑéÂë + + public int CPXH; //²ðÅÌÐźŠ+ public int YPXH; //ÓÐÅÌÐźŠ+ public int BY1; //±¸Óà + public int BY2; //±¸Óà + + public CMP_Device() { + super(); + } + + public CMP_Device(byte btId, String dtype) { + super(); + this.btId = btId; + this.dtype = dtype; + } + + @Override + public String toString() { + return "CMP_Device{" + + "btId=" + btId + + ", dtype='" + dtype + '\'' + + ", dName='" + dName + '\'' + + ", RWH=" + RWH + + ", MPXH=" + MPXH + + ", KPXH=" + KPXH + + ", CZFS=" + CZFS + + ", SBZT=" + SBZT + + '}'; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/entity/DDJ_Device.java b/src/com/wms/dss/ats/customs/abb/entity/DDJ_Device.java new file mode 100644 index 0000000..087cb61 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/DDJ_Device.java @@ -0,0 +1,54 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class DDJ_Device { + + public byte btId;// DDjid + public String dtype;// ÀàÐÍ + public String dName; + + public int CZFS;// ²Ù×÷·½Ê½0δ֪1δѡÔñ2ÊÖ¶¯3°ë×Ô¶¯4µ¥»ú×Ô¶¯5Áª»ú + public int SBZT;// É豸״̬0´ý»ú1ÕýÔÚÖ´ÐÐ2 ÆäËû±àºÅ¼û¹ÊÕÏ´úÂë±í + public long ZXRWH;// ÕýÔÚÖ´ÐÐÈÎÎñºÅ + public int HCZT;// »õ²æ×´Ì¬0ÎÞ»õ1Óлõ + public int ZXJD;// Ö´Ðн׶Î1È¡»õÐÐ×ß2È¡»õ3·Å»õÐÐ×ß4·Å»õ5Íê³É + public int DQP;// µ±Ç°ÅÅ + public int DQL;// µ±Ç°ÁÐ + public int DQC;// µ±Ç°²ã + public int MBPH;// Ä¿±êÅÅ + public int MBLH;// Ä¿±êÁÐ + public int MBCH;// Ä¿±ê²ã + public int YXXF;// ÔÊÐíÏ·¢1ÔÊÐí + public int XTXH; + public String trayCode; + + public DDJ_Device() { + super(); + } + + public DDJ_Device(byte btId, String dtype) { + super(); + this.btId = btId; + this.dtype = dtype; + } + + @Override + public String toString() { + return "DDJDevice{" + + "btId=" + btId + + ", dtype='" + dtype + '\'' + + ", CZFS=" + CZFS + + ", SBZT=" + SBZT + + ", ZXRWH=" + ZXRWH + + ", HCZT=" + HCZT + + ", ZXJD=" + ZXJD + + ", DQP=" + DQP + + ", DQL=" + DQL + + ", DQC=" + DQC + + ", MBPH=" + MBPH + + ", MBLH=" + MBLH + + ", MBCH=" + MBCH + + ", YXXF=" + YXXF + + ", trayCode=" + trayCode + + '}'; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/entity/JXS_Device.java b/src/com/wms/dss/ats/customs/abb/entity/JXS_Device.java new file mode 100644 index 0000000..910ace5 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/JXS_Device.java @@ -0,0 +1,39 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class JXS_Device { + public byte btId; //id + public String dtype; //ÀàÐÍ + public String dName; //Ãû³Æ + + public int CZFS; //²Ù×÷·½Ê½ + public int SBZT; //É豸״̬ + public int stackId; //¶âÐÍid + public long RWH; //ÈÎÎñºÅ + public int WCXH; //Íê³ÉÐźŠ+ public int ZQSL; //ץȡÊýÁ¿ + + public JXS_Device() { + super(); + } + + public JXS_Device(byte btId, String dtype) { + super(); + this.btId = btId; + this.dtype = dtype; + } + + @Override + public String toString() { + return "JXS_Device{" + + "btId=" + btId + + ", dtype='" + dtype + '\'' + + ", dName='" + dName + '\'' + + ", CZFS=" + CZFS + + ", SBZT=" + SBZT + + ", stackId=" + stackId + + ", RWH=" + RWH + + ", WCXH=" + WCXH + + ", ZQSL=" + ZQSL + + '}'; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/entity/JxsFinishCpj.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/JxsFinishCpj.hbm.xml new file mode 100644 index 0000000..029beaa --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/JxsFinishCpj.hbm.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/JxsFinishCpj.java b/src/com/wms/dss/ats/customs/abb/entity/JxsFinishCpj.java new file mode 100644 index 0000000..fc9325d --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/JxsFinishCpj.java @@ -0,0 +1,59 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class JxsFinishCpj { + + private int jxs_id; + private int rwh; + private int qx; + private int cz; + private int tplx; + private int lx; + + public int getJxs_id() { + return jxs_id; + } + + public void setJxs_id(int jxs_id) { + this.jxs_id = jxs_id; + } + + public int getRwh() { + return rwh; + } + + public void setRwh(int rwh) { + this.rwh = rwh; + } + + public int getQx() { + return qx; + } + + public void setQx(int qx) { + this.qx = qx; + } + + public int getCz() { + return cz; + } + + public void setCz(int cz) { + this.cz = cz; + } + + public int getTplx() { + return tplx; + } + + public void setTplx(int tplx) { + this.tplx = tplx; + } + + public int getLx() { + return lx; + } + + public void setLx(int lx) { + this.lx = lx; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/entity/JxsJobMsg.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/JxsJobMsg.hbm.xml new file mode 100644 index 0000000..bed8014 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/JxsJobMsg.hbm.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/JxsJobMsg.java b/src/com/wms/dss/ats/customs/abb/entity/JxsJobMsg.java new file mode 100644 index 0000000..cdd37fa --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/JxsJobMsg.java @@ -0,0 +1,104 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class JxsJobMsg { + + private Integer jxsId; + private String stockoutId; + private String detailId; + private String productId; + private String lotNo; + private String stackingId; + private Integer stockNum; + private Integer outNum; + private Integer isHp; + private Integer jhNum; + private Integer sjNum; + + public Integer getJxsId() { + return jxsId; + } + + public void setJxsId(Integer jxsId) { + this.jxsId = jxsId; + } + + public String getStockoutId() { + return stockoutId; + } + + public void setStockoutId(String stockoutId) { + this.stockoutId = stockoutId; + } + + public String getDetailId() { + return detailId; + } + + public void setDetailId(String detailId) { + this.detailId = detailId; + } + + public String getProductId() { + return productId; + } + + public void setProductId(String productId) { + this.productId = productId; + } + + public String getLotNo() { + return lotNo; + } + + public void setLotNo(String lotNo) { + this.lotNo = lotNo; + } + + public String getStackingId() { + return stackingId; + } + + public void setStackingId(String stackingId) { + this.stackingId = stackingId; + } + + public Integer getStockNum() { + return stockNum; + } + + public void setStockNum(Integer stockNum) { + this.stockNum = stockNum; + } + + public Integer getOutNum() { + return outNum; + } + + public void setOutNum(Integer outNum) { + this.outNum = outNum; + } + + public Integer getIsHp() { + return isHp; + } + + public void setIsHp(Integer isHp) { + this.isHp = isHp; + } + + public Integer getJhNum() { + return jhNum; + } + + public void setJhNum(Integer jhNum) { + this.jhNum = jhNum; + } + + public Integer getSjNum() { + return sjNum; + } + + public void setSjNum(Integer sjNum) { + this.sjNum = sjNum; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/entity/JxsMsg.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/JxsMsg.hbm.xml new file mode 100644 index 0000000..de5c336 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/JxsMsg.hbm.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/JxsMsg.java b/src/com/wms/dss/ats/customs/abb/entity/JxsMsg.java new file mode 100644 index 0000000..aa5a9fc --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/JxsMsg.java @@ -0,0 +1,50 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class JxsMsg { + + private int id; + private String tray_code; + private String msg; + private String uuid; + private String create_time; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getTray_code() { + return tray_code; + } + + public void setTray_code(String tray_code) { + this.tray_code = tray_code; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getCreate_time() { + return create_time; + } + + public void setCreate_time(String create_time) { + this.create_time = create_time; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/entity/MsgCmp.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/MsgCmp.hbm.xml new file mode 100644 index 0000000..55b47bd --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/MsgCmp.hbm.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/MsgCmp.java b/src/com/wms/dss/ats/customs/abb/entity/MsgCmp.java new file mode 100644 index 0000000..6d937b9 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/MsgCmp.java @@ -0,0 +1,113 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class MsgCmp { + + private String id; + private String name; + private String floor; + private String czfs; + private String sbzt; + private String mpxh; + private String kpxh; + private String rwh; + private String cz; + private String tplx; + private String ypxh; + private String cpxh; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getFloor() { + return floor; + } + + public void setFloor(String floor) { + this.floor = floor; + } + + public String getCzfs() { + return czfs; + } + + public void setCzfs(String czfs) { + this.czfs = czfs; + } + + public String getSbzt() { + return sbzt; + } + + public void setSbzt(String sbzt) { + this.sbzt = sbzt; + } + + public String getMpxh() { + return mpxh; + } + + public void setMpxh(String mpxh) { + this.mpxh = mpxh; + } + + public String getKpxh() { + return kpxh; + } + + public void setKpxh(String kpxh) { + this.kpxh = kpxh; + } + + public String getRwh() { + return rwh; + } + + public void setRwh(String rwh) { + this.rwh = rwh; + } + + public String getCz() { + return cz; + } + + public void setCz(String cz) { + this.cz = cz; + } + + public String getTplx() { + return tplx; + } + + public void setTplx(String tplx) { + this.tplx = tplx; + } + + public String getYpxh() { + return ypxh; + } + + public void setYpxh(String ypxh) { + this.ypxh = ypxh; + } + + public String getCpxh() { + return cpxh; + } + + public void setCpxh(String cpxh) { + this.cpxh = cpxh; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/entity/MsgDdj.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/MsgDdj.hbm.xml new file mode 100644 index 0000000..3453d53 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/MsgDdj.hbm.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/MsgDdj.java b/src/com/wms/dss/ats/customs/abb/entity/MsgDdj.java new file mode 100644 index 0000000..3df346b --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/MsgDdj.java @@ -0,0 +1,122 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class MsgDdj { + + private String id; + private String name; + private String rwh; + private String jdbz; + private String sbzt; + private String czfs; + private String yxxf; + private String yp; + private String yl; + private String yc; + private String mbp; + private String mbl; + private String mbc; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getRwh() { + return rwh; + } + + public void setRwh(String rwh) { + this.rwh = rwh; + } + + public String getJdbz() { + return jdbz; + } + + public void setJdbz(String jdbz) { + this.jdbz = jdbz; + } + + public String getSbzt() { + return sbzt; + } + + public void setSbzt(String sbzt) { + this.sbzt = sbzt; + } + + public String getCzfs() { + return czfs; + } + + public void setCzfs(String czfs) { + this.czfs = czfs; + } + + public String getYxxf() { + return yxxf; + } + + public void setYxxf(String yxxf) { + this.yxxf = yxxf; + } + + public String getYp() { + return yp; + } + + public void setYp(String yp) { + this.yp = yp; + } + + public String getYl() { + return yl; + } + + public void setYl(String yl) { + this.yl = yl; + } + + public String getYc() { + return yc; + } + + public void setYc(String yc) { + this.yc = yc; + } + + public String getMbp() { + return mbp; + } + + public void setMbp(String mbp) { + this.mbp = mbp; + } + + public String getMbl() { + return mbl; + } + + public void setMbl(String mbl) { + this.mbl = mbl; + } + + public String getMbc() { + return mbc; + } + + public void setMbc(String mbc) { + this.mbc = mbc; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/entity/MsgJxs.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/MsgJxs.hbm.xml new file mode 100644 index 0000000..1114bef --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/MsgJxs.hbm.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/MsgJxs.java b/src/com/wms/dss/ats/customs/abb/entity/MsgJxs.java new file mode 100644 index 0000000..8704e54 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/MsgJxs.java @@ -0,0 +1,86 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class MsgJxs { + + private String id; + private String name; + private String floor; + private String czfs; + private String sbzt; + private String stack_id; + private String rwh; + private String wcxh; + private String zqsl; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getFloor() { + return floor; + } + + public void setFloor(String floor) { + this.floor = floor; + } + + public String getCzfs() { + return czfs; + } + + public void setCzfs(String czfs) { + this.czfs = czfs; + } + + public String getSbzt() { + return sbzt; + } + + public void setSbzt(String sbzt) { + this.sbzt = sbzt; + } + + public String getStack_id() { + return stack_id; + } + + public void setStack_id(String stack_id) { + this.stack_id = stack_id; + } + + public String getRwh() { + return rwh; + } + + public void setRwh(String rwh) { + this.rwh = rwh; + } + + public String getWcxh() { + return wcxh; + } + + public void setWcxh(String wcxh) { + this.wcxh = wcxh; + } + + public String getZqsl() { + return zqsl; + } + + public void setZqsl(String zqsl) { + this.zqsl = zqsl; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/entity/MsgRkkSsj.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/MsgRkkSsj.hbm.xml new file mode 100644 index 0000000..4519f73 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/MsgRkkSsj.hbm.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/MsgRkkSsj.java b/src/com/wms/dss/ats/customs/abb/entity/MsgRkkSsj.java new file mode 100644 index 0000000..347aae1 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/MsgRkkSsj.java @@ -0,0 +1,104 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class MsgRkkSsj { + + private String id; + private String name; + private String floor; + private String rkqq; + private String tmfk; + private String rkgd; + private String bjxx; + private String quantity; + private String ckdw; + private String ckkx; + private String rwh; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getFloor() { + return floor; + } + + public void setFloor(String floor) { + this.floor = floor; + } + + public String getRkqq() { + return rkqq; + } + + public void setRkqq(String rkqq) { + this.rkqq = rkqq; + } + + public String getTmfk() { + return tmfk; + } + + public void setTmfk(String tmfk) { + this.tmfk = tmfk; + } + + public String getRkgd() { + return rkgd; + } + + public void setRkgd(String rkgd) { + this.rkgd = rkgd; + } + + public String getBjxx() { + return bjxx; + } + + public void setBjxx(String bjxx) { + this.bjxx = bjxx; + } + + public String getQuantity() { + return quantity; + } + + public void setQuantity(String quantity) { + this.quantity = quantity; + } + + public String getCkdw() { + return ckdw; + } + + public void setCkdw(String ckdw) { + this.ckdw = ckdw; + } + + public String getCkkx() { + return ckkx; + } + + public void setCkkx(String ckkx) { + this.ckkx = ckkx; + } + + public String getRwh() { + return rwh; + } + + public void setRwh(String rwh) { + this.rwh = rwh; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/entity/MsgXdkSsj.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/MsgXdkSsj.hbm.xml new file mode 100644 index 0000000..948af9a --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/MsgXdkSsj.hbm.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/MsgXdkSsj.java b/src/com/wms/dss/ats/customs/abb/entity/MsgXdkSsj.java new file mode 100644 index 0000000..8aae912 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/MsgXdkSsj.java @@ -0,0 +1,77 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class MsgXdkSsj { + + private String id; + private String name; + private String floor; + private String roadway_id; + private String in_or_out; + private String rkdw; + private String ckkx; + private String rwh; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getFloor() { + return floor; + } + + public void setFloor(String floor) { + this.floor = floor; + } + + public String getRoadway_id() { + return roadway_id; + } + + public void setRoadway_id(String roadway_id) { + this.roadway_id = roadway_id; + } + + public String getIn_or_out() { + return in_or_out; + } + + public void setIn_or_out(String in_or_out) { + this.in_or_out = in_or_out; + } + + public String getRkdw() { + return rkdw; + } + + public void setRkdw(String rkdw) { + this.rkdw = rkdw; + } + + public String getCkkx() { + return ckkx; + } + + public void setCkkx(String ckkx) { + this.ckkx = ckkx; + } + + public String getRwh() { + return rwh; + } + + public void setRwh(String rwh) { + this.rwh = rwh; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/entity/MydoJob.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/MydoJob.hbm.xml new file mode 100644 index 0000000..49c9a7b --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/MydoJob.hbm.xml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/MydoJob.java b/src/com/wms/dss/ats/customs/abb/entity/MydoJob.java new file mode 100644 index 0000000..9db3dc0 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/MydoJob.java @@ -0,0 +1,303 @@ +package com.wms.dss.ats.customs.abb.entity; + +import java.sql.Timestamp; + +public class MydoJob { + private String job_id; //×÷Òµid ΨһÖ÷¼ü + private String status; //×÷ҵ״̬ δִÐÐ1 ´ýÖ´ÐÐ2 ÕýÖ´ÐÐ3 ÒÑÍê³É 4 ÒÑ×÷·Ï 5 + private String on_line_type; //1 Áª»ú 0 ÍÑ»ú + private String task_no; //ÈÎÎñºÅ Ï´«É豸 + private String supplier_id; //¹©Ó¦ÉÌid + private String customer_id; //¿Í»§id + private String tray_code; //ÍÐÅÌÌõÂë + private String roadway_id; //ÏïµÀ + private String cargo_space_id; //»õλid + private String target_roadway_id; //Ä¿±êÏïµÀ + private String target_cargo_space_id; //Ä¿±ê»õλ + private String line_id; //Éú²úÏßid + private String workshop_id; //³µ¼äid + private String entrance_id; //Èë¿Úid + private String Exit_id; //³ö¿Úid + private int priority; //ÓÅÏȼ¶ 0-10 0µÄÓÅÏȼ¶×î¸ß10µÄÓÅÏȼ¶×îµÍ + private String in_or_out; //³öÈë¿âÀàÐÍ£¨ 1¡¢Èë 2¡¢Õû³ö 3¡¢°ëÅ̳ö 4¡¢»ØÁ÷ 5¡¢Òƿ⣩ + private String execution_phase; //Ö´Ðн׶Π+ private String create_time; //½¨Á¢Ê±¼ä + private String start_time; //¿ªÊ¼Ê±¼ä + private String finish_time; //Íê³Éʱ¼ä + private String class_now_name; //²Ö¿âµ±Ç°°à×éÃû³Æ + private String class_workshop_name; //³µ¼äµ±Ç°°à´ÎÃû³Æ£¨ÔÊÐíΪ¿Õ£©Èë¿âʱÓà + private String warehouse_id; //¿â·¿id£¨ÔÊÐíΪ¿Õ£© + private String classgroup_number; //³µ¼ä°à×éºÅ + private String class_workshop_date_time;//³µ¼ä°à×éÖ´ÐÐʱ¼ä + private String class_id; //²Ö¿â°à×éºÅ + private String class_now_date_time; //²Ö¿â°à×éÖ´ÐÐʱ¼ä + private String fault_flag; //ÌõÂë״̬ + private String dev_id; // + private String floor; + private String location; + private String count_id; + + public String getCount_id() { + return count_id; + } + + public void setCount_id(String count_id) { + this.count_id = count_id; + } + + public String getJob_id() { + return job_id; + } + + public void setJob_id(String job_id) { + this.job_id = job_id; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getOn_line_type() { + return on_line_type; + } + + public void setOn_line_type(String on_line_type) { + this.on_line_type = on_line_type; + } + + public String getTask_no() { + return task_no; + } + + public void setTask_no(String task_no) { + this.task_no = task_no; + } + + public String getSupplier_id() { + return supplier_id; + } + + public void setSupplier_id(String supplier_id) { + this.supplier_id = supplier_id; + } + + public String getCustomer_id() { + return customer_id; + } + + public void setCustomer_id(String customer_id) { + this.customer_id = customer_id; + } + + public String getTray_code() { + return tray_code; + } + + public void setTray_code(String tray_code) { + this.tray_code = tray_code; + } + + public String getRoadway_id() { + return roadway_id; + } + + public void setRoadway_id(String roadway_id) { + this.roadway_id = roadway_id; + } + + public String getCargo_space_id() { + return cargo_space_id; + } + + public void setCargo_space_id(String cargo_space_id) { + this.cargo_space_id = cargo_space_id; + } + + public String getTarget_roadway_id() { + return target_roadway_id; + } + + public void setTarget_roadway_id(String target_roadway_id) { + this.target_roadway_id = target_roadway_id; + } + + public String getTarget_cargo_space_id() { + return target_cargo_space_id; + } + + public void setTarget_cargo_space_id(String target_cargo_space_id) { + this.target_cargo_space_id = target_cargo_space_id; + } + + public String getLine_id() { + return line_id; + } + + public void setLine_id(String line_id) { + this.line_id = line_id; + } + + public String getWorkshop_id() { + return workshop_id; + } + + public void setWorkshop_id(String workshop_id) { + this.workshop_id = workshop_id; + } + + public String getEntrance_id() { + return entrance_id; + } + + public void setEntrance_id(String entrance_id) { + this.entrance_id = entrance_id; + } + + public String getExit_id() { + return Exit_id; + } + + public void setExit_id(String exit_id) { + Exit_id = exit_id; + } + + public int getPriority() { + return priority; + } + + public void setPriority(int priority) { + this.priority = priority; + } + + public String getIn_or_out() { + return in_or_out; + } + + public void setIn_or_out(String in_or_out) { + this.in_or_out = in_or_out; + } + + public String getExecution_phase() { + return execution_phase; + } + + public void setExecution_phase(String execution_phase) { + this.execution_phase = execution_phase; + } + + public String getCreate_time() { + return create_time; + } + + public void setCreate_time(String create_time) { + this.create_time = create_time; + } + + public String getStart_time() { + return start_time; + } + + public void setStart_time(String start_time) { + this.start_time = start_time; + } + + public String getFinish_time() { + return finish_time; + } + + public void setFinish_time(String finish_time) { + this.finish_time = finish_time; + } + + public String getClass_now_name() { + return class_now_name; + } + + public void setClass_now_name(String class_now_name) { + this.class_now_name = class_now_name; + } + + public String getClass_workshop_name() { + return class_workshop_name; + } + + public void setClass_workshop_name(String class_workshop_name) { + this.class_workshop_name = class_workshop_name; + } + + public String getWarehouse_id() { + return warehouse_id; + } + + public void setWarehouse_id(String warehouse_id) { + this.warehouse_id = warehouse_id; + } + + public String getClassgroup_number() { + return classgroup_number; + } + + public void setClassgroup_number(String classgroup_number) { + this.classgroup_number = classgroup_number; + } + + public String getClass_workshop_date_time() { + return class_workshop_date_time; + } + + public void setClass_workshop_date_time(String class_workshop_date_time) { + this.class_workshop_date_time = class_workshop_date_time; + } + + public String getClass_id() { + return class_id; + } + + public void setClass_id(String class_id) { + this.class_id = class_id; + } + + public String getClass_now_date_time() { + return class_now_date_time; + } + + public void setClass_now_date_time(String class_now_date_time) { + this.class_now_date_time = class_now_date_time; + } + + public String getFault_flag() { + return fault_flag; + } + + public void setFault_flag(String fault_flag) { + this.fault_flag = fault_flag; + } + + public String getDev_id() { + return dev_id; + } + + public void setDev_id(String dev_id) { + this.dev_id = dev_id; + } + + public String getFloor() { + return floor; + } + + public void setFloor(String floor) { + this.floor = floor; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/entity/OpenLed.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/OpenLed.hbm.xml new file mode 100644 index 0000000..23b476d --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/OpenLed.hbm.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/OpenLed.java b/src/com/wms/dss/ats/customs/abb/entity/OpenLed.java new file mode 100644 index 0000000..687a178 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/OpenLed.java @@ -0,0 +1,94 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class OpenLed { + private int id; + private String ip; + private String ipot; + private int line; + private String msg1; + private String msg2; + private String msg3; + private String msg4; + private int status;// 0ÐèÏ·¢µ¥´ÎÏÔʾ15s 1.ÐíÏ·¢Ò»Ö±³ÖÐøÏÔʾ 2.Ï·¢µãÕóÆÁ£¬ 3 ״̬3ʱ15 ºóÏÔʾ³õʼֵ + private int write_time; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public String getIpot() { + return ipot; + } + + public void setIpot(String ipot) { + this.ipot = ipot; + } + + public int getLine() { + return line; + } + + public void setLine(int line) { + this.line = line; + } + + public String getMsg1() { + return msg1; + } + + public void setMsg1(String msg1) { + this.msg1 = msg1; + } + + public String getMsg2() { + return msg2; + } + + public void setMsg2(String msg2) { + this.msg2 = msg2; + } + + public String getMsg3() { + return msg3; + } + + public void setMsg3(String msg3) { + this.msg3 = msg3; + } + + public String getMsg4() { + return msg4; + } + + public void setMsg4(String msg4) { + this.msg4 = msg4; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public int getWrite_time() { + return write_time; + } + + public void setWrite_time(int write_time) { + this.write_time = write_time; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/entity/RKK_SSJ.java b/src/com/wms/dss/ats/customs/abb/entity/RKK_SSJ.java new file mode 100644 index 0000000..461bf6e --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/RKK_SSJ.java @@ -0,0 +1,58 @@ +package com.wms.dss.ats.customs.abb.entity; + +/** + * @author huijiang Jin + * @date 2023-03-13 13:41:45 + */ +public class RKK_SSJ { + public byte btId; //id + public String dtype; //ÀàÐÍ + public String dName; //É豸Ãû³Æ + + public int RKQQ; //Èë¿âÇëÇó + public String trayCode; //ÌõÂë + public int RKGD; //Èë¿â¸ß¶È + public int BJXX; //ÍâÐα¨¾¯ + public int CKDW; //³ö¿âµ½Î» + public int TPLX; //ÍÐÅÌÀàÐÍ + public long taskNo; //ÈÎÎñºÅ + public long xf_taskNo; //Ï·¢ÈÎÎñºÅ + public int by1; //¶âÐÍ + public int by2; //±¸Óà + public int CKKX; //³ö¿â¿ÕÏÐ + public int RKSL; //Èë¿âÊýÁ¿ + public int BDXH; //±È¶ÔÐźŠ+ public long RKLX; //Èë¿âÀàÐÍ + public int JYM; //УÑéÂë + public int YXXF; //ÔÊÐíÏ·¢ + public int QX; //È¥Ïò + public int floor; //ËùÔÚ²ã + public String address_xf; //Ï·¢µØÖ· + public String address_xf2; //Ï·¢µØÖ· + public RKK_SSJ(byte btId, String dtype) { + this.btId = btId; + this.dtype = dtype; + } + + public RKK_SSJ() { + super(); + } + + @Override + public String toString() { + return "RKK_SSJ{" + + "btId=" + btId + + ", dtype='" + dtype + '\'' + + ", dName='" + dName + '\'' + + ", RKQQ=" + RKQQ + + ", trayCode='" + trayCode + '\'' + + ", RKGD=" + RKGD + + ", BJXX=" + BJXX + + ", CKDW=" + CKDW + + ", taskNo=" + taskNo + + ", CKKX=" + CKKX + + ", RKSL=" + RKSL + + ", BDXH=" + BDXH + + '}'; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/entity/SendData.java b/src/com/wms/dss/ats/customs/abb/entity/SendData.java new file mode 100644 index 0000000..02446b9 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/SendData.java @@ -0,0 +1,39 @@ +package com.wms.dss.ats.customs.abb.entity; + +/** + * ·¢ËÍÊý¾ÝµÄʵÌåÀà + * @num ³¤¶È + * @num2 Öµ + */ +public class SendData { + private static final int DINT = 4; + private static final int INT = 2; + private int num; + private int num2; + + public SendData(int num, int num2) { + this.num = num; + this.num2 = num2; + } + + public SendData(int num, String num2) { + this.num = num; + this.num2 = Integer.parseInt(num2); + } + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public int getNum2() { + return num2; + } + + public void setNum2(int num2) { + this.num2 = num2; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/entity/StoredParameters.java b/src/com/wms/dss/ats/customs/abb/entity/StoredParameters.java new file mode 100644 index 0000000..46f6af0 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/StoredParameters.java @@ -0,0 +1,37 @@ +package com.wms.dss.ats.customs.abb.entity; + +/** + * ´æ´¢¹ý³ÌµÄʵÌåÀà + * @num µÚ¼¸¸ö²ÎÊý + * @num2 ²ÎÊý¶ÔÓ¦µÄÖµ + */ +public class StoredParameters { + private int num; + private String parameter; + + public StoredParameters(int num, String num2) { + this.num = num; + this.parameter = num2; + } + + public StoredParameters(int num, int permitIssuedBy) { + this.num = num; + this.parameter = String.valueOf(permitIssuedBy); + } + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public String getParameter() { + return parameter; + } + + public void setParameter(String parameter) { + this.parameter = parameter; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/entity/SysDictData.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/SysDictData.hbm.xml new file mode 100644 index 0000000..5ede203 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/SysDictData.hbm.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/SysDictData.java b/src/com/wms/dss/ats/customs/abb/entity/SysDictData.java new file mode 100644 index 0000000..158065f --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/SysDictData.java @@ -0,0 +1,51 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class SysDictData { + + + private String dict_sort; + private String dict_label; + private String dict_value; + private String dict_type; + private String remark; + + public String getDict_sort() { + return dict_sort; + } + + public void setDict_sort(String dict_sort) { + this.dict_sort = dict_sort; + } + + public String getDict_label() { + return dict_label; + } + + public void setDict_label(String dict_label) { + this.dict_label = dict_label; + } + + public String getDict_value() { + return dict_value; + } + + public void setDict_value(String dict_value) { + this.dict_value = dict_value; + } + + public String getDict_type() { + return dict_type; + } + + public void setDict_type(String dict_type) { + this.dict_type = dict_type; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/entity/WcsCmpIn.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/WcsCmpIn.hbm.xml new file mode 100644 index 0000000..670def1 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/WcsCmpIn.hbm.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/WcsCmpIn.java b/src/com/wms/dss/ats/customs/abb/entity/WcsCmpIn.java new file mode 100644 index 0000000..80b426e --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/WcsCmpIn.java @@ -0,0 +1,50 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class WcsCmpIn { + + private Integer id; + private String floor; + private String tray_type; + private String qty; + private String status; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getFloor() { + return floor; + } + + public void setFloor(String floor) { + this.floor = floor; + } + + public String getTray_type() { + return tray_type; + } + + public void setTray_type(String tray_type) { + this.tray_type = tray_type; + } + + public String getQty() { + return qty; + } + + public void setQty(String qty) { + this.qty = qty; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/entity/WmsDeviceExecutionQueue.hbm.xml b/src/com/wms/dss/ats/customs/abb/entity/WmsDeviceExecutionQueue.hbm.xml new file mode 100644 index 0000000..8afbdc2 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/WmsDeviceExecutionQueue.hbm.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/entity/WmsDeviceExecutionQueue.java b/src/com/wms/dss/ats/customs/abb/entity/WmsDeviceExecutionQueue.java new file mode 100644 index 0000000..3cd37d5 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/WmsDeviceExecutionQueue.java @@ -0,0 +1,176 @@ +package com.wms.dss.ats.customs.abb.entity; + +public class WmsDeviceExecutionQueue { + + private String id; //Ö÷¼ü±êʶ + private String rwh; //ÈÎÎñºÅ + private String devName; //É豸Ãû³Æ + private int devId; //É豸ºÅ + private int rwzt; //ÈÎÎñ״̬ + private int yph; //¶Ñ¶â»úÔ´ÅÅ + private int ylh; //¶Ñ¶â»úÔ´ÁÐ + private int ych; //¶Ñ¶â»úÔ´²ã + private int mbph; //¶Ñ¶â»úÄ¿±êÅÅ + private int mblh; //¶Ñ¶â»úÄ¿±êÁÐ + private int mbch; //¶Ñ¶â»úÄ¿±ê²ã + private String ddjxf; //¶Ñ¶â»úÏ·¢ + private int rwlx; //ÈÎÎñÀàÐÍ + private String scsj; //Éú³Éʱ¼ä + private String xfsj; //Ï·¢Ê±¼ä + private String jssj; //½áÊøÊ±¼ä + private int mlfs; //ÃüÁʽ + private int tplx; //ÍÐÅÌÀàÐÍ + private int qx; //ÍÐÅÌÀàÐÍ + + public int getQx() { + return qx; + } + + public void setQx(int qx) { + this.qx = qx; + } + + public int getTplx() { + return tplx; + } + + public void setTplx(int tplx) { + this.tplx = tplx; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getRwh() { + return rwh; + } + + public void setRwh(String rwh) { + this.rwh = rwh; + } + + public String getDevName() { + return devName; + } + + public void setDevName(String devName) { + this.devName = devName; + } + + public int getDevId() { + return devId; + } + + public void setDevId(int devId) { + this.devId = devId; + } + + public int getRwzt() { + return rwzt; + } + + public void setRwzt(int rwzt) { + this.rwzt = rwzt; + } + + public int getYph() { + return yph; + } + + public void setYph(int yph) { + this.yph = yph; + } + + public int getYlh() { + return ylh; + } + + public void setYlh(int ylh) { + this.ylh = ylh; + } + + public int getYch() { + return ych; + } + + public void setYch(int ych) { + this.ych = ych; + } + + public int getMbph() { + return mbph; + } + + public void setMbph(int mbph) { + this.mbph = mbph; + } + + public int getMblh() { + return mblh; + } + + public void setMblh(int mblh) { + this.mblh = mblh; + } + + public int getMbch() { + return mbch; + } + + public void setMbch(int mbch) { + this.mbch = mbch; + } + + public String getDdjxf() { + return ddjxf; + } + + public void setDdjxf(String ddjxf) { + this.ddjxf = ddjxf; + } + + public int getRwlx() { + return rwlx; + } + + public void setRwlx(int rwlx) { + this.rwlx = rwlx; + } + + public String getScsj() { + return scsj; + } + + public void setScsj(String scsj) { + this.scsj = scsj; + } + + public String getXfsj() { + return xfsj; + } + + public void setXfsj(String xfsj) { + this.xfsj = xfsj; + } + + public String getJssj() { + return jssj; + } + + public void setJssj(String jssj) { + this.jssj = jssj; + } + + public int getMlfs() { + return mlfs; + } + + public void setMlfs(int mlfs) { + this.mlfs = mlfs; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/entity/XDK_SSJ.java b/src/com/wms/dss/ats/customs/abb/entity/XDK_SSJ.java new file mode 100644 index 0000000..23ce0e4 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/entity/XDK_SSJ.java @@ -0,0 +1,36 @@ +package com.wms.dss.ats.customs.abb.entity; + +/** + * @author huijiang Jin + * @date 2023-03-13 13:59:11 + */ +public class XDK_SSJ { + public byte btId; // agvid + public String dtype; // ÀàÐÍ + public String dName; //É豸Ãû³Æ + + public int RKDW; + public int CKKX; + public long RWH; + + + public XDK_SSJ() { + } + + public XDK_SSJ(byte btId, String dtype) { + this.btId = btId; + this.dtype = dtype; + } + + @Override + public String toString() { + return "XDK_SSJ{" + + "btId=" + btId + + ", dtype='" + dtype + '\'' + + ", dName='" + dName + '\'' + + ", RKDW=" + RKDW + + ", CKKX=" + CKKX + + ", RWH=" + RWH + + '}'; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/form/ABBMainFrame.java b/src/com/wms/dss/ats/customs/abb/form/ABBMainFrame.java new file mode 100644 index 0000000..0ea2e67 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/form/ABBMainFrame.java @@ -0,0 +1,25 @@ +package com.wms.dss.ats.customs.abb.form; + +import com.wms.dss.common.server.form.ServerMainFrame; + +/** + * ÃèÊö: ÏÃÃÅABBÉ豸ͨÐŵ÷¶Èϵͳ + * @author + * @since WMS 3.0 + */ +public class ABBMainFrame extends ServerMainFrame { + + public ABBMainFrame() throws Exception { + super(); + } + public static void main(String[] arg) + { + try{ + new ABBMainFrame(); + } + catch(Exception ex){ + ex.printStackTrace(); + System.exit(-1); + } + } +} diff --git a/src/com/wms/dss/ats/customs/abb/form/StartCorrespond.java b/src/com/wms/dss/ats/customs/abb/form/StartCorrespond.java new file mode 100644 index 0000000..8e3a2ee --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/form/StartCorrespond.java @@ -0,0 +1,156 @@ +package com.wms.dss.ats.customs.abb.form; + +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTextArea; + +import com.wms.dss.common.server.config.DSSMenu; +import com.wms.dss.common.server.config.DSSMenuItem; +import com.wms.dss.common.server.form.FormObject; +import com.wms.dss.common.server.schedule.ThreadSchedule; + +/** + * ÃèÊö: Æô¶¯É豸ͨÐÅ + * @author hug 2013-4-12 + * @since WMS 3.0 + */ +public class StartCorrespond extends FormObject{ + protected JFrame gcf; + protected DSSMenuItem opMenuItem; + + public StartCorrespond() + {} + @Override + public void init(DSSMenuItem menuItem) { + gcf = new JFrame("¡ï¡ïÆô¶¯É豸ͨÐÅ¡ï¡ï"); + ImageIcon img = new ImageIcon("images\\a.gif"); + opMenuItem = menuItem; + + JPanel jPanel1 = new JPanel(); + JPanel jPanel2 = new JPanel(); + JPanel jPanel3 = new JPanel(); + JPanel jPanel4 = new JPanel(); + JPanel jPanel5 = new JPanel(); + + JTextArea jTextArea = new JTextArea(1,1); + Font ft = new Font("ËÎÌå",Font.BOLD,18); + //JLabel l1 = new JLabel(""); + + JButton jbtn1 = new JButton("ÊÇ"); + JButton jbtn2 = new JButton("·ñ"); + + gcf.getContentPane().add("North",jPanel1); + gcf.getContentPane().add("South",jPanel2); + gcf.getContentPane().add("East",jPanel3); + gcf.getContentPane().add("West",jPanel4); + gcf.getContentPane().add("Center",jPanel5); + + jPanel1.setBackground(new Color(240,248,255)); + jPanel2.setBackground(new Color(240,248,255)); + jPanel3.setBackground(new Color(240,248,255)); + jPanel4.setBackground(new Color(240,248,255)); + jPanel5.setBackground(new Color(240,248,255)); + + jPanel5.setBorder(BorderFactory.createLineBorder(new Color(43,166,197),1)); + + jTextArea.setText("ÊÇ ·ñ Æô ¶¯ Éè ±¸ ͨ ÐÅ ?"); + jTextArea.setForeground(Color.blue); + jTextArea.setFont(ft); + jPanel5.setLayout(new FlowLayout(FlowLayout.CENTER,25,20)); + jPanel5.add(jTextArea); + + jPanel5.add(jbtn1); + jPanel5.add(jbtn2); + + jbtn1.addActionListener(new JButtonH("ok")); + jbtn2.addActionListener(new JButtonH("exit")); + gcf.addWindowListener(new windows()); + + double w = Toolkit.getDefaultToolkit().getScreenSize().getWidth(); + double h = Toolkit.getDefaultToolkit().getScreenSize().getHeight(); + + gcf.setSize(300,200); + gcf.setIconImage(img.getImage()); + gcf.setLocation((int)((w-330)/2)+20,(int)((h-240)/2)); + gcf.setResizable(false); + gcf.setVisible(false); + // ×Ô¶¯Ñ¡Ôñ¡°ÊÇ¡±°´Å¥ + jbtn1.doClick(); + } + public class JButtonH implements ActionListener{ + private String btnName; + public JButtonH(String bName) + { + this.btnName = bName; + } + public void actionPerformed(ActionEvent e) + { + if(btnName.equals("exit")) + { + exitSch(); + }if(btnName.equals("ok")) + { try{ + startSch(); + } + catch(Exception ex){ + ex.printStackTrace(); + } + + }else + { + parentJFrame.setEnabled(true); + gcf.setVisible(false); + } + } + + public void exitSch(){ + parentJFrame.setEnabled(true); + gcf.setVisible(false); + } + + /** + * ¹¦ÄÜ:Æô¶¯É豸ͨÐÅ + * + */ + public void startSch() throws Exception + { + parentJFrame.setEnabled(true); + gcf.setVisible(false); + + //²Ëµ¥×´Ì¬ÏÔʾ + opMenuItem.jmenuItem.setEnabled(false); + DSSMenu tempMenu = opMenuItem.getDssMenu(); //»ñµÃ²Ëµ¥ + String secondMenuKey = (String)tempMenu.lsSecondMenuKey.get(2);//µÚ¶þ¸ö²Ëµ¥µÄµÚ¶þ¸ö²Ëµ¥Ïî + DSSMenuItem tempMenuItem = (DSSMenuItem)tempMenu.hsSecondMenu.get(secondMenuKey); + tempMenuItem.jmenuItem.setEnabled(true); + + ThreadSchedule threadSch = (ThreadSchedule)Class.forName(opMenuItem.menu11ThreadClass).newInstance(); + threadSch.setHashtable(m_serverMainFrame.m_hsSysParam); + //Ïß³ÌÖ´ÐÐ + threadSch.threadExec(); + tempMenuItem.threadSch = threadSch; + } + } + + + public class windows extends WindowAdapter + { + public void windowClosing(WindowEvent e) + { + parentJFrame.setEnabled(true); + } + } + +} diff --git a/src/com/wms/dss/ats/customs/abb/form/StopCorrespond.java b/src/com/wms/dss/ats/customs/abb/form/StopCorrespond.java new file mode 100644 index 0000000..dcbc646 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/form/StopCorrespond.java @@ -0,0 +1,148 @@ +package com.wms.dss.ats.customs.abb.form; + +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.Toolkit; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTextArea; + +import com.wms.dss.common.server.config.DSSMenu; +import com.wms.dss.common.server.config.DSSMenuItem; +import com.wms.dss.common.server.form.FormObject; + +/** + * ÃèÊö: Í£Ö¹É豸ͨÐÅ + * @author hug 2013-4-15 + * @since WMS 3.0 + */ +public class StopCorrespond extends FormObject{ + protected JFrame gcf; + protected DSSMenuItem opMenuItem; + public StopCorrespond() + {} + @Override + public void init(DSSMenuItem menuItem) { + + gcf = new JFrame("¡ï¡ïÍ£Ö¹É豸ͨÐÅ¡ï¡ï"); + ImageIcon img = new ImageIcon("images\\a.gif"); + opMenuItem = menuItem; + + JPanel JPanel1 = new JPanel(); + JPanel JPanel2 = new JPanel(); + JPanel JPanel3 = new JPanel(); + JPanel JPanel4 = new JPanel(); + JPanel JPanel5 = new JPanel(); + + JTextArea jta = new JTextArea(1,1); + Font ft = new Font("ËÎÌå",Font.BOLD,18); + + //JLabel l1 = new JLabel(""); + JButton jbtn1 = new JButton("ÊÇ"); + JButton jbtn2 = new JButton("·ñ"); + + gcf.getContentPane().add("North",JPanel1); + gcf.getContentPane().add("South",JPanel2); + gcf.getContentPane().add("East",JPanel3); + gcf.getContentPane().add("West",JPanel4); + gcf.getContentPane().add("Center",JPanel5); + + JPanel1.setBackground(new Color(240,248,255)); + JPanel2.setBackground(new Color(240,248,255)); + JPanel3.setBackground(new Color(240,248,255)); + JPanel4.setBackground(new Color(240,248,255)); + JPanel5.setBackground(new Color(240,248,255)); + + JPanel5.setBorder(BorderFactory.createLineBorder(new Color(43,166,197),1)); + + jta.setText("ÊÇ ·ñ Í£ Ö¹ Éè ±¸ ͨ ÐÅ ?"); + jta.setForeground(Color.blue); + jta.setFont(ft); + JPanel5.setLayout(new FlowLayout(FlowLayout.CENTER,25,20)); + JPanel5.add(jta); + + JPanel5.add(jbtn1); + JPanel5.add(jbtn2); + + jbtn1.addActionListener(new JButtonH("ok")); + jbtn2.addActionListener(new JButtonH("exit")); + gcf.addWindowListener(new windows()); + + double w = Toolkit.getDefaultToolkit().getScreenSize().getWidth(); + double h = Toolkit.getDefaultToolkit().getScreenSize().getHeight(); + + gcf.setSize(300,200); + gcf.setIconImage(img.getImage()); + gcf.setLocation((int)((w-330)/2)+20,(int)((h-240)/2)); + gcf.setResizable(false); + gcf.setVisible(false); + // ×Ô¶¯Ñ¡Ôñ¡°ÊÇ¡±°´Å¥ + jbtn1.doClick(); + } + public class JButtonH implements ActionListener + { + private String btnName; + + public JButtonH(String bName) + { + this.btnName = bName; + } + + public void actionPerformed(ActionEvent e) + { + if(btnName.equals("exit")) + { + cancelStop(); + }if(btnName.equals("ok")) + { + stopSch(); + }else + { + parentJFrame.setEnabled(true); + gcf.setVisible(false); + } + } + + public void cancelStop(){ + parentJFrame.setEnabled(true); + gcf.setVisible(false); + } + + /** + * ¹¦ÄÜ:Í£Ö¹É豸ͨÐÅ + * + */ + public void stopSch() + { + parentJFrame.setEnabled(true); + gcf.setVisible(false); + + //²Ëµ¥×´Ì¬´¦Àí + opMenuItem.jmenuItem.setEnabled(false); + DSSMenu tempMenu = opMenuItem.getDssMenu();//»ñµÃ²Ëµ¥ + String secondMenuKey = (String)tempMenu.lsSecondMenuKey.get(0); + DSSMenuItem tempMenuItem = (DSSMenuItem)tempMenu.hsSecondMenu.get(secondMenuKey); + tempMenuItem.jmenuItem.setEnabled(true); + + opMenuItem.threadSch.stopAll(true); + opMenuItem.threadSch = null; + } + } + public class windows extends WindowAdapter + { + public void windowClosing(WindowEvent e) + { + parentJFrame.setEnabled(true); + } + } + +} diff --git a/src/com/wms/dss/ats/customs/abb/led/LED1.java b/src/com/wms/dss/ats/customs/abb/led/LED1.java new file mode 100644 index 0000000..dfa3640 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/led/LED1.java @@ -0,0 +1,187 @@ +package com.wms.dss.ats.customs.abb.led; + +import com.wms.dss.ats.customs.abb.utils.LEDSender2010; +import com.wms.dss.ats.customs.abb.utils.MyUdpSocket; + +import java.awt.*; + +public class LED1 { + + public static MyUdpSocket my_udp; + public static LEDSender2010 ledsender = new LEDSender2010(); + public static int ledport = 6666; + public static int addr = 0; + + // ·¢ËÍUDP°ü£¬bufferΪ·¢ËÍÊý¾Ý£¬sizeΪ·¢ËÍÊý¾Ý³¤¶È + public static void udp_send_ip(String ip, byte[] buffer, int size) { + byte[] packet = new byte[size]; + ledsender.blockCopy(packet, 0, buffer, 0, size); + ledsender.print_stream(packet, size); + try { + my_udp.send(ip, ledport, packet, size); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + // ½ÓÊÕUDP°ü£¬bufferΪ½ÓÊÕÊý¾Ý£¬sizeΪ½ÓÊÕÊý¾Ý³¤¶È + public static int udp_receive(byte[] buffer) { + int size = 0; + size = my_udp.receive(); + if (size > 0) { + my_udp.get_receive_packet(buffer, size); + } + return size; + } + + public static void send_data_ip(String ip) { + int size = 0; + byte[] packet = new byte[1280]; + int i, j, k, x, r; + int tx, tx_repeat = 5; + boolean ok; + // ÏÂÃæÎªÍ¨Ñ¶´úÂ룬°üÀ¨Êý¾ÝµÄ²ð·Ö´ò°ü¡¢·¢ËÍ + // ÓÉÓÚÊÇUDPͨѶ£¬Ôö¼Ó + + // Èç¹ûÊý¾ÝÁ¿´óÓÚ + if (ledsender.GetDataSize() > (1 << 21)) { + System.out.println("LED½ÚÄ¿Êý¾Ý³¤¶È³¬³öÏÔʾÆÁ´æ´¢¿Õ¼ä"); + return; + } + ledsender.Compress(); + // Æðʼ°ü + ok = false; + for (tx = 0; tx < tx_repeat; tx++) { + size = ledsender.pkg_begin(packet, addr); + udp_send_ip(ip, packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0 && ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_BEGIN, 0) > 0) { + ok = true; + break; + } + } + if (ok) + break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + + // Êý¾Ý°ü + k = ledsender.get_pkg_count(512); + i = 1; + while (i <= k) { + ok = false; + for (tx = 0; tx < tx_repeat; tx++) { + j = i; + size = ledsender.pkg_data(packet, addr, i, 512); + udp_send_ip(ip, packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0) { + r = ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_DATA, i); + switch (r) { + case 0x1: + ok = true; + j = i + 1; + break; + case 0x2: + j = ledsender.fix_serialno; + break; + } + // ok=true; + // break; + } + if (ok) + break; + } + i = j; + if (ok) + break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + } + + // ½áÊø°ü + ok = false; + for (tx = 0; tx < tx_repeat; tx++) { + size = ledsender.pkg_end(packet, addr, i); + udp_send_ip(ip, packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0 && ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_END, i) > 0) { + ok = true; + break; + } + } + if (ok) + break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + + } + + public static void send_data(int line, String ip, String msg1, String msg2, String msg3, String msg4) { + // Éú³É½ÚÄ¿Êý¾Ý + ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_DOUBLE); + // Ìí¼Ó½ÚÄ¿ + ledsender.AddChapter(1, 2000); + // Ìí¼Ó·ÖÇø... + ledsender.AddRegion(0, 0, 192, 64); + // Ìí¼ÓÒ³Ãæ + ledsender.AddLeaf(1, 2000); + if (line == 1) { + // Ìí¼ÓÎÄ×Ö + ledsender.AddText(0, 18, 192, 64, msg1, "ËÎÌå", 17, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + } else if (line == 2) { + // Ìí¼ÓÎÄ×Ö + ledsender.AddText(0, 0, 192, 32, msg1, "ËÎÌå", 15, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 32, 192, 32, msg2, "ËÎÌå", 15, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + } else if (line == 3) { + // Ìí¼ÓÎÄ×Ö + ledsender.AddText(0, 0, 192, 21, msg1, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 21, 40, 21, "ÎïÁÏÃû£º", "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(50, 21, 192, 21, msg2, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 6, 0, 1, 0, 0, 0, + 10000); + ledsender.AddText(0, 42, 192, 22, msg3, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + } else if (line == 4) { + // Ìí¼ÓÎÄ×Ö + ledsender.AddText(0, 0, 192, 16, msg1, "ËÎÌå", 14, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 16, 192, 16, msg2, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 32, 192, 16, msg3, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 48, 192, 16, msg4, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + }else if (line == 5) { + // Ìí¼ÓÎÄ×Ö + ledsender.AddText(0, 16, 192, 64, msg1, "ËÎÌå", 28, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + } else { + return; + } + // ½ÚÄ¿·¢²¼ + send_data_ip(ip); + } + + public static void main(String[] args) { + LED1.my_udp = new MyUdpSocket(50001); + LED1.send_data(1, "10.170.23.241", "É豸ÔËÐУ¬×¢Òⰲȫ£¡", "ÌõÂ룺A2020-0303-D4-8888", "ÐÅÏ¢£ºÈë¿âÈÎÎñ", ""); + } + +} diff --git a/src/com/wms/dss/ats/customs/abb/led/LED2.java b/src/com/wms/dss/ats/customs/abb/led/LED2.java new file mode 100644 index 0000000..4774773 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/led/LED2.java @@ -0,0 +1,185 @@ +package com.wms.dss.ats.customs.abb.led; + +import com.wms.dss.ats.customs.abb.utils.LEDSender2010; +import com.wms.dss.ats.customs.abb.utils.MyUdpSocket; + +import java.awt.*; + +public class LED2 { + + public static MyUdpSocket my_udp; + public static LEDSender2010 ledsender = new LEDSender2010(); + public static int ledport = 6666; + public static int addr = 0; + + // ·¢ËÍUDP°ü£¬bufferΪ·¢ËÍÊý¾Ý£¬sizeΪ·¢ËÍÊý¾Ý³¤¶È + public static void udp_send_ip(String ip, byte[] buffer, int size) { + byte[] packet = new byte[size]; + ledsender.blockCopy(packet, 0, buffer, 0, size); + ledsender.print_stream(packet, size); + try { + my_udp.send(ip, ledport, packet, size); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + // ½ÓÊÕUDP°ü£¬bufferΪ½ÓÊÕÊý¾Ý£¬sizeΪ½ÓÊÕÊý¾Ý³¤¶È + public static int udp_receive(byte[] buffer) { + int size = 0; + size = my_udp.receive(); + if (size > 0) { + my_udp.get_receive_packet(buffer, size); + } + return size; + } + + public static void send_data_ip(String ip) { + int size = 0; + byte[] packet = new byte[1280]; + int i, j, k, x, r; + int tx, tx_repeat = 5; + boolean ok; + // ÏÂÃæÎªÍ¨Ñ¶´úÂ룬°üÀ¨Êý¾ÝµÄ²ð·Ö´ò°ü¡¢·¢ËÍ + // ÓÉÓÚÊÇUDPͨѶ£¬Ôö¼Ó + + // Èç¹ûÊý¾ÝÁ¿´óÓÚ + if (ledsender.GetDataSize() > (1 << 21)) { + System.out.println("LED½ÚÄ¿Êý¾Ý³¤¶È³¬³öÏÔʾÆÁ´æ´¢¿Õ¼ä"); + return; + } + ledsender.Compress(); + // Æðʼ°ü + ok = false; + for (tx = 0; tx < tx_repeat; tx++) { + size = ledsender.pkg_begin(packet, addr); + udp_send_ip(ip, packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0 && ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_BEGIN, 0) > 0) { + ok = true; + break; + } + } + if (ok) + break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + + // Êý¾Ý°ü + k = ledsender.get_pkg_count(512); + i = 1; + while (i <= k) { + ok = false; + for (tx = 0; tx < tx_repeat; tx++) { + j = i; + size = ledsender.pkg_data(packet, addr, i, 512); + udp_send_ip(ip, packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0) { + r = ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_DATA, i); + switch (r) { + case 0x1: + ok = true; + j = i + 1; + break; + case 0x2: + j = ledsender.fix_serialno; + break; + } + // ok=true; + // break; + } + if (ok) + break; + } + i = j; + if (ok) + break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + } + + // ½áÊø°ü + ok = false; + for (tx = 0; tx < tx_repeat; tx++) { + size = ledsender.pkg_end(packet, addr, i); + udp_send_ip(ip, packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0 && ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_END, i) > 0) { + ok = true; + break; + } + } + if (ok) + break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + + } + + public static void send_data(int line, String ip, String msg1, String msg2, String msg3, String msg4) { + // Éú³É½ÚÄ¿Êý¾Ý + ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_DOUBLE); + // Ìí¼Ó½ÚÄ¿ + ledsender.AddChapter(1, 2000); + // Ìí¼Ó·ÖÇø... + ledsender.AddRegion(0, 0, 192, 64); + // Ìí¼ÓÒ³Ãæ + ledsender.AddLeaf(1, 2000); + if (line == 1) { + // Ìí¼ÓÎÄ×Ö + ledsender.AddText(0, 18, 192, 64, msg1, "ËÎÌå", 17, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + } else if (line == 2) { + // Ìí¼ÓÎÄ×Ö + ledsender.AddText(0, 0, 192, 21, msg1, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); +// ledsender.AddText(0, 21, 40, 21, "ÎïÁÏÃû£º", "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, +// 10000); + ledsender.AddText(50, 21, 192, 21, msg2, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 6, 0, 1, 0, 0, 0, + 10000); + } else if (line == 3) { + // Ìí¼ÓÎÄ×Ö + ledsender.AddText(0, 0, 192, 21, msg1, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 21, 40, 21, "ÎïÁÏÃû£º", "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(50, 21, 192, 21, msg2, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 6, 0, 1, 0, 0, 0, + 10000); + ledsender.AddText(0, 42, 192, 22, msg3, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + } else if (line == 4) { + // Ìí¼ÓÎÄ×Ö + ledsender.AddText(0, 0, 192, 16, msg1, "ËÎÌå", 16, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 16, 192, 16, msg2, "ËÎÌå", 16, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 32, 192, 16, msg3, "ËÎÌå", 16, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 48, 192, 16, msg4, "ËÎÌå", 16, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + } else { + return; + } + // ½ÚÄ¿·¢²¼ + send_data_ip(ip); + } + + public static void main(String[] args) { + LED2.my_udp = new MyUdpSocket(50001); + LED2.send_data(1, "10.170.23.241", "É豸ÔËÐУ¬×¢Òⰲȫ£¡", "ÌõÂ룺A2020-0303-D4-8888", "ÐÅÏ¢£ºÈë¿âÈÎÎñ", ""); + } + +} diff --git a/src/com/wms/dss/ats/customs/abb/led/LED3.java b/src/com/wms/dss/ats/customs/abb/led/LED3.java new file mode 100644 index 0000000..fb78039 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/led/LED3.java @@ -0,0 +1,183 @@ +package com.wms.dss.ats.customs.abb.led; + +import com.wms.dss.ats.customs.abb.utils.LEDSender2010; +import com.wms.dss.ats.customs.abb.utils.MyUdpSocket; + +import java.awt.*; + +public class LED3 { + + public static MyUdpSocket my_udp; + public static LEDSender2010 ledsender = new LEDSender2010(); + public static int ledport = 6666; + public static int addr = 0; + + // ·¢ËÍUDP°ü£¬bufferΪ·¢ËÍÊý¾Ý£¬sizeΪ·¢ËÍÊý¾Ý³¤¶È + public static void udp_send_ip(String ip, byte[] buffer, int size) { + byte[] packet = new byte[size]; + ledsender.blockCopy(packet, 0, buffer, 0, size); + ledsender.print_stream(packet, size); + try { + my_udp.send(ip, ledport, packet, size); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + // ½ÓÊÕUDP°ü£¬bufferΪ½ÓÊÕÊý¾Ý£¬sizeΪ½ÓÊÕÊý¾Ý³¤¶È + public static int udp_receive(byte[] buffer) { + int size = 0; + size = my_udp.receive(); + if (size > 0) { + my_udp.get_receive_packet(buffer, size); + } + return size; + } + + public static void send_data_ip(String ip) { + int size = 0; + byte[] packet = new byte[1280]; + int i, j, k, x, r; + int tx, tx_repeat = 5; + boolean ok; + // ÏÂÃæÎªÍ¨Ñ¶´úÂ룬°üÀ¨Êý¾ÝµÄ²ð·Ö´ò°ü¡¢·¢ËÍ + // ÓÉÓÚÊÇUDPͨѶ£¬Ôö¼Ó + + // Èç¹ûÊý¾ÝÁ¿´óÓÚ + if (ledsender.GetDataSize() > (1 << 21)) { + System.out.println("LED½ÚÄ¿Êý¾Ý³¤¶È³¬³öÏÔʾÆÁ´æ´¢¿Õ¼ä"); + return; + } + ledsender.Compress(); + // Æðʼ°ü + ok = false; + for (tx = 0; tx < tx_repeat; tx++) { + size = ledsender.pkg_begin(packet, addr); + udp_send_ip(ip, packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0 && ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_BEGIN, 0) > 0) { + ok = true; + break; + } + } + if (ok) + break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + + // Êý¾Ý°ü + k = ledsender.get_pkg_count(512); + i = 1; + while (i <= k) { + ok = false; + for (tx = 0; tx < tx_repeat; tx++) { + j = i; + size = ledsender.pkg_data(packet, addr, i, 512); + udp_send_ip(ip, packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0) { + r = ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_DATA, i); + switch (r) { + case 0x1: + ok = true; + j = i + 1; + break; + case 0x2: + j = ledsender.fix_serialno; + break; + } + // ok=true; + // break; + } + if (ok) + break; + } + i = j; + if (ok) + break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + } + + // ½áÊø°ü + ok = false; + for (tx = 0; tx < tx_repeat; tx++) { + size = ledsender.pkg_end(packet, addr, i); + udp_send_ip(ip, packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0 && ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_END, i) > 0) { + ok = true; + break; + } + } + if (ok) + break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + + } + + public static void send_data(int line, String ip, String msg1, String msg2, String msg3, String msg4) { + // Éú³É½ÚÄ¿Êý¾Ý + ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_DOUBLE); + // Ìí¼Ó½ÚÄ¿ + ledsender.AddChapter(1, 2000); + // Ìí¼Ó·ÖÇø... + ledsender.AddRegion(0, 0, 192, 64); + // Ìí¼ÓÒ³Ãæ + ledsender.AddLeaf(1, 2000); + if (line == 1) { + // Ìí¼ÓÎÄ×Ö + ledsender.AddText(0, 18, 192, 64, msg1, "ËÎÌå", 17, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + } else if (line == 2) { + // Ìí¼ÓÎÄ×Ö + ledsender.AddText(0, 0, 192, 32, msg1, "ËÎÌå", 18, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 32, 192, 32, msg2, "ËÎÌå", 18, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + } else if (line == 3) { + // Ìí¼ÓÎÄ×Ö + ledsender.AddText(0, 0, 192, 21, msg1, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 21, 40, 21, "ÎïÁÏÃû£º", "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(50, 21, 192, 21, msg2, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 6, 0, 1, 0, 0, 0, + 10000); + ledsender.AddText(0, 42, 192, 22, msg3, "ËÎÌå", 12, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + } else if (line == 4) { + // Ìí¼ÓÎÄ×Ö + ledsender.AddText(0, 0, 192, 16, msg1, "ËÎÌå", 16, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 16, 192, 16, msg2, "ËÎÌå", 16, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 32, 192, 16, msg3, "ËÎÌå", 16, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + ledsender.AddText(0, 48, 192, 16, msg4, "ËÎÌå", 16, Color.BLACK, Color.YELLOW, 0, 0, false, 1, 0, 1, 0, 0, 5, + 10000); + } else { + return; + } + // ½ÚÄ¿·¢²¼ + send_data_ip(ip); + } + + public static void main(String[] args) { + LED3.my_udp = new MyUdpSocket(50001); + LED3.send_data(1, "10.170.23.241", "É豸ÔËÐУ¬×¢Òⰲȫ£¡", "ÌõÂ룺A2020-0303-D4-8888", "ÐÅÏ¢£ºÈë¿âÈÎÎñ", ""); + } + +} diff --git a/src/com/wms/dss/ats/customs/abb/modbus/Modbus4jUtils.java b/src/com/wms/dss/ats/customs/abb/modbus/Modbus4jUtils.java new file mode 100644 index 0000000..b67d6d1 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/modbus/Modbus4jUtils.java @@ -0,0 +1,335 @@ +package com.wms.dss.ats.customs.abb.modbus; + +import com.serotonin.modbus4j.BatchRead; +import com.serotonin.modbus4j.BatchResults; +import com.serotonin.modbus4j.ModbusFactory; +import com.serotonin.modbus4j.ModbusMaster; +import com.serotonin.modbus4j.code.DataType; +import com.serotonin.modbus4j.exception.ErrorResponseException; +import com.serotonin.modbus4j.exception.ModbusInitException; +import com.serotonin.modbus4j.exception.ModbusTransportException; +import com.serotonin.modbus4j.ip.IpParameters; +import com.serotonin.modbus4j.locator.BaseLocator; +import com.serotonin.modbus4j.msg.*; + +/** + * modbusͨѶ¹¤¾ßÀà,²ÉÓÃmodbus4jʵÏÖ + */ +public class Modbus4jUtils { + /** + * ¹¤³§¡£ + */ + static ModbusFactory modbusFactory; + + static { + if (modbusFactory == null) { + modbusFactory = new ModbusFactory(); + } + } + + /** + * »ñÈ¡master + * + * @return + * @throws ModbusInitException + */ + public static ModbusMaster getMaster() throws ModbusInitException { + IpParameters params = new IpParameters(); + params.setHost("192.168.56.230"); + params.setPort(502); + // + // modbusFactory.createRtuMaster(wapper); //RTU ЭÒé + // modbusFactory.createUdpMaster(params);//UDP ЭÒé + // modbusFactory.createAsciiMaster(wrapper);//ASCII ЭÒé + ModbusMaster master = modbusFactory.createTcpMaster(params, false);// TCP ЭÒé + + try { + master.setTimeout(3000); + //master.setRetries(3); + master.init(); + }catch (Exception e){ + e.printStackTrace(); + } + return master; + } + + /** + * ¶ÁÈ¡[01 Coil Status 0x]ÀàÐÍ ¿ª¹ØÊý¾Ý + * + * @param slaveId slaveId + * @param offset λÖà + * @return ¶Áȡֵ + * @throws ModbusTransportException Òì³£ + * @throws ErrorResponseException Òì³£ + * @throws ModbusInitException Òì³£ + */ + public static Boolean readCoilStatus(int slaveId, int offset) + throws ModbusTransportException, ErrorResponseException, ModbusInitException { + // 01 Coil Status + BaseLocator loc = BaseLocator.coilStatus(slaveId, offset); + Boolean value = getMaster().getValue(loc); + return value; + } + + /** + * ¶ÁÈ¡[02 Input Status 1x]ÀàÐÍ ¿ª¹ØÊý¾Ý + * + * @param slaveId + * @param offset + * @return + * @throws ModbusTransportException + * @throws ErrorResponseException + * @throws ModbusInitException + */ + public static Boolean readInputStatus(int slaveId, int offset) + throws ModbusTransportException, ErrorResponseException, ModbusInitException { + // 02 Input Status + BaseLocator loc = BaseLocator.inputStatus(slaveId, offset); + Boolean value = getMaster().getValue(loc); + return value; + } + + /** + * ¶ÁÈ¡[03 Holding RegisterÀàÐÍ 2x]Ä£ÄâÁ¿Êý¾Ý + * + * @param slaveId slave Id + * @param offset λÖà + * @param dataType Êý¾ÝÀàÐÍ,À´×Ôcom.serotonin.modbus.code.DataType + * @return + * @throws ModbusTransportException Òì³£ + * @throws ErrorResponseException Òì³£ + * @throws ModbusInitException Òì³£ + */ + public static Number readHoldingRegister(int slaveId, int offset, int dataType) + throws ModbusTransportException, ErrorResponseException, ModbusInitException { + // 03 Holding RegisterÀàÐÍÊý¾Ý¶ÁÈ¡ + BaseLocator loc = BaseLocator.holdingRegister(slaveId, offset, dataType); + Number value = getMaster().getValue(loc); + return value; + } + + + + /** + * ¶ÁÈ¡[04 Input Registers 3x]ÀàÐÍ Ä£ÄâÁ¿Êý¾Ý + * + * @param slaveId slaveId + * @param offset λÖà + * @param dataType Êý¾ÝÀàÐÍ,À´×Ôcom.serotonin.modbus.code.DataType + * @return ·µ»Ø½á¹û + * @throws ModbusTransportException Òì³£ + * @throws ErrorResponseException Òì³£ + * @throws ModbusInitException Òì³£ + */ + public static Number readInputRegisters(int slaveId, int offset, int dataType) + throws ModbusTransportException, ErrorResponseException, ModbusInitException { + // 04 Input RegistersÀàÐÍÊý¾Ý¶ÁÈ¡ + BaseLocator loc = BaseLocator.inputRegister(slaveId, offset, dataType); + Number value = getMaster().getValue(loc); + return value; + } + + /** + * ÅúÁ¿¶ÁȡʹÓ÷½·¨ + * + * @throws ModbusTransportException + * @throws ErrorResponseException + * @throws ModbusInitException + */ + public static void batchRead() throws ModbusTransportException, ErrorResponseException, ModbusInitException { + + BatchRead batch = new BatchRead(); + + batch.addLocator(0, BaseLocator.inputStatus(1, 10008)); + batch.addLocator(1, BaseLocator.inputStatus(1, 10009)); + batch.addLocator(2, BaseLocator.inputStatus(1, 10010)); + batch.addLocator(3, BaseLocator.inputStatus(1, 10011)); + + ModbusMaster master = getMaster(); + + batch.setContiguousRequests(false); + BatchResults results = master.send(batch); + + System.out.println(results.getValue(0)); + System.out.println(results.getValue(1)); + System.out.println(results.getValue(2)); + System.out.println(results.getValue(3)); + } + + /** + * д [01 Coil Status(0x)]дһ¸ö function ID = 5 + * + * @param slaveId slaveµÄID + * @param writeOffset λÖà + * @param writeValue Öµ + * @return ÊÇ·ñдÈë³É¹¦ + * @throws ModbusTransportException + * @throws ModbusInitException + */ + public static boolean writeCoil(int slaveId, int writeOffset, boolean writeValue) + throws ModbusTransportException, ModbusInitException { + // »ñÈ¡master + ModbusMaster tcpMaster = getMaster(); + // ´´½¨ÇëÇó + WriteCoilRequest request = new WriteCoilRequest(slaveId, writeOffset, writeValue); + // ·¢ËÍÇëÇó²¢»ñÈ¡ÏìÓ¦¶ÔÏó + WriteCoilResponse response = (WriteCoilResponse) tcpMaster.send(request); + if (response.isException()) { + return false; + } else { + return true; + } + } + + /** + * д[01 Coil Status(0x)] д¶à¸ö function ID = 15 + * + * @param slaveId slaveId + * @param startOffset ¿ªÊ¼Î»Öà + * @param bdata дÈëµÄÊý¾Ý + * @return ÊÇ·ñдÈë³É¹¦ + * @throws ModbusTransportException + * @throws ModbusInitException + */ + public static boolean writeCoils(int slaveId, int startOffset, boolean[] bdata) + throws ModbusTransportException, ModbusInitException { + // »ñÈ¡master + ModbusMaster tcpMaster = getMaster(); + // ´´½¨ÇëÇó + WriteCoilsRequest request = new WriteCoilsRequest(slaveId, startOffset, bdata); + // ·¢ËÍÇëÇó²¢»ñÈ¡ÏìÓ¦¶ÔÏó + WriteCoilsResponse response = (WriteCoilsResponse) tcpMaster.send(request); + if (response.isException()) { + return false; + } else { + return true; + } + + } + + /*** + * д[03 Holding Register(4x)] дһ¸ö function ID = 6 + * + * @param slaveId + * @param writeOffset + * @param writeValue + * @return + * @throws ModbusTransportException + * @throws ModbusInitException + */ + public static boolean writeRegister(int slaveId, int writeOffset, int writeValue) + throws ModbusTransportException, ModbusInitException { + // »ñÈ¡master + ModbusMaster tcpMaster = getMaster(); + // ´´½¨ÇëÇó¶ÔÏó + WriteRegisterRequest request = new WriteRegisterRequest(slaveId, writeOffset, writeValue); + WriteRegisterResponse response = (WriteRegisterResponse) tcpMaster.send(request); + if (response.isException()) { + //log.error(response.getExceptionMessage()); + return false; + } else { + return true; + } + + } + + /** + * дÈë[03 Holding Register(4x)]д¶à¸ö function ID=16 + * + * @param slaveId modbusµÄslaveID + * @param startOffset ÆðʼλÖÃÆ«ÒÆÁ¿Öµ + * @param sdata дÈëµÄÊý¾Ý + * @return ·µ»ØÊÇ·ñдÈë³É¹¦ + * @throws ModbusTransportException + * @throws ModbusInitException + */ + public static boolean writeRegisters(int slaveId, int startOffset, short[] sdata) + throws ModbusTransportException, ModbusInitException { + // »ñÈ¡master + ModbusMaster tcpMaster = getMaster(); + // ´´½¨ÇëÇó¶ÔÏó + WriteRegistersRequest request = new WriteRegistersRequest(slaveId, startOffset, sdata); + // ·¢ËÍÇëÇó²¢»ñÈ¡ÏìÓ¦¶ÔÏó + ModbusResponse response = tcpMaster.send(request); + byte exceptionCode = response.getExceptionCode(); + String exceptionMessage = response.getExceptionMessage(); + System.err.println(exceptionCode); + System.err.println(exceptionMessage); + if (response.isException()) { + //log.error(response.getExceptionMessage()); + return false; + } else { + return true; + } + } + + /** + * дÈëÊý×ÖÀàÐ͵ÄÄ£ÄâÁ¿£¨Èç:дÈëFloatÀàÐ͵ÄÄ£ÄâÁ¿¡¢DoubleÀàÐÍÄ£ÄâÁ¿¡¢ÕûÊýÀàÐÍShort¡¢Integer¡¢Long£© + * + * @param slaveId + * @param offset + * @param value дÈëÖµ,NumberµÄ×ÓÀà,ÀýÈçдÈëFloat¸¡µãÀàÐÍ,DoubleË«¾«¶ÈÀàÐÍ,ÒÔ¼°ÕûÐÍshort,int,long + * @throws ModbusTransportException + * @throws ErrorResponseException + * @throws ModbusInitException + */ + public static void writeHoldingRegister(int slaveId, int offset, Number value, int dataType) + throws ModbusTransportException, ErrorResponseException, ModbusInitException { + // »ñÈ¡master + ModbusMaster tcpMaster = getMaster(); + // ÀàÐÍ + BaseLocator locator = BaseLocator.holdingRegister(slaveId, offset, dataType); + + tcpMaster.setValue(locator, value); + + } + + + /** + * ²âÊÔ + * + * @param args + */ + public static void main(String[] args) { + try { + Modbus4jUtils.writeHoldingRegister(1, 10020, 0, DataType.TWO_BYTE_INT_UNSIGNED); + //ÊäÈëÃÜÂë + Modbus4jUtils.writeHoldingRegister(1, 10021, 10, DataType.TWO_BYTE_INT_UNSIGNED); + short s = 1; + Modbus4jUtils.writeHoldingRegister(1, 10021, s, DataType.TWO_BYTE_INT_UNSIGNED); + // 01²âÊÔ + // Boolean v011 = readCoilStatus(1, 10007); +// Boolean v012 = readCoilStatus(1, 1); +// Boolean v013 = readCoilStatus(1, 6); + // System.out.println("v011:" + v011); +// System.out.println("v012:" + v012); +// System.out.println("v013:" + v013); +// // 02²âÊÔ + // Boolean v021 = readInputStatus(1, 10008); +// Boolean v022 = readInputStatus(1, 1); +// Boolean v023 = readInputStatus(1, 2); +// System.out.println("v021:" + v021); +// System.out.println("v022:" + v022); +// System.out.println("v023:" + v023); +// +// // 03²âÊÔ + // Number v031 = readHoldingRegister1(1, 10001, DataType.TWO_BYTE_BCD);// ×¢Òâ,float +// Number v032 = readHoldingRegister(1, 3, DataType.FOUR_BYTE_FLOAT);// ͬÉÏ +// System.out.println("v031:" + v031.toString()); + + +// System.out.println("v032:" + v032); + + // 04²âÊÔ +// Number v041 = readInputRegisters(1, 32454, DataType.TWO_BYTE_INT_UNSIGNED);// + //Number v042 = readInputRegisters(1, 1, DataType.TWO_BYTE_INT_UNSIGNED);// +// System.out.println("v041:" + v041); + //System.out.println("v042:" + v042); + // ÅúÁ¿¶ÁÈ¡ +// batchRead(); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/com/wms/dss/ats/customs/abb/modbus/ModbusService.java b/src/com/wms/dss/ats/customs/abb/modbus/ModbusService.java new file mode 100644 index 0000000..2bb81d0 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/modbus/ModbusService.java @@ -0,0 +1,156 @@ +package com.wms.dss.ats.customs.abb.modbus; + +import com.serotonin.modbus4j.ModbusFactory; +import com.serotonin.modbus4j.ModbusMaster; +import com.serotonin.modbus4j.code.DataType; +import com.serotonin.modbus4j.exception.ErrorResponseException; +import com.serotonin.modbus4j.exception.ModbusTransportException; +import com.serotonin.modbus4j.ip.IpParameters; +import com.serotonin.modbus4j.locator.BaseLocator; +import com.serotonin.modbus4j.msg.WriteCoilRequest; +import com.serotonin.modbus4j.msg.WriteCoilResponse; +import com.wms.dss.common.server.form.Logger; + +/** + * @author zn kai + * @create 2022-03-31 11:14 + */ +public class ModbusService { + static ModbusFactory modbusFactory; + ModbusMaster modbusMaster = null; + private String strIp; + private int iPort; + + static { + modbusFactory = new ModbusFactory(); + } + + //private volatile Map masterMap = new HashMap<>(64); + + + /** + * »ñÈ¡ Modbus Master + * + * @param host + * @param port + */ + public void getMaster(String host, int port) { + try { + // if (!modbusMaster.isConnected()) { + IpParameters params = new IpParameters(); + params.setHost(host); + params.setPort(port); + modbusMaster = modbusFactory.createTcpMaster(params, true); + modbusMaster.setTimeout(2000); + modbusMaster.init(); + System.err.println("init:::"+modbusMaster.isInitialized()); + System.err.println("isConnected:::"+modbusMaster.isConnected()); + // } + } catch (Exception e) { + if (modbusMaster != null) { + modbusMaster.destroy(); + + } + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½Ó´íÎó" + e.getMessage()); + } + } + + public Boolean write(Integer slaveId, Integer functionCode, Integer offset, String attributeType, String value) throws Exception { + Boolean flag = null; + try { + flag = writeValue(modbusMaster, slaveId, functionCode, offset, attributeType, value); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + return flag; + } + + /** + * »ñÈ¡ Value + */ + public String readValue(ModbusMaster modbusMaster, Integer slaveId, Integer functionCode, Integer offset, String attributeType) throws ModbusTransportException, ErrorResponseException { + switch (functionCode) { + case 1: + BaseLocator coilLocator = BaseLocator.coilStatus(slaveId, offset); + Boolean coilValue = modbusMaster.getValue(coilLocator); + return String.valueOf(coilValue); + case 2: + BaseLocator inputLocator = BaseLocator.inputStatus(slaveId, offset); + Boolean inputStatusValue = modbusMaster.getValue(inputLocator); + return String.valueOf(inputStatusValue); + case 3: + BaseLocator holdingLocator = BaseLocator.holdingRegister(slaveId, offset, getValueType(attributeType)); + Number holdingValue = modbusMaster.getValue(holdingLocator); + return String.valueOf(holdingValue); + case 4: + BaseLocator inputRegister = BaseLocator.inputRegister(slaveId, offset, getValueType(attributeType)); + Number inputRegisterValue = modbusMaster.getValue(inputRegister); + return String.valueOf(inputRegisterValue); + default: + return "0"; + } + } + + /** + * д Value + */ + public boolean writeValue(ModbusMaster modbusMaster, Integer slaveId, Integer functionCode, Integer offset, String attributeType, String value) throws ModbusTransportException, ErrorResponseException { + switch (functionCode) { + case 1: + WriteCoilRequest coilRequest = new WriteCoilRequest(slaveId, offset, true); + WriteCoilResponse coilResponse = (WriteCoilResponse) modbusMaster.send(coilRequest); + return !coilResponse.isException(); + case 3: + BaseLocator locator = BaseLocator.holdingRegister(slaveId, offset, getValueType(attributeType)); + modbusMaster.setValue(locator,value); + return true; + default: + return false; + } + } + + private boolean value(String attributeType, String value) { + if (attributeType.toLowerCase().equals(value.toLowerCase())) { + return true; + } + return false; + } + + /** + * »ñÈ¡Êý¾ÝÀàÐÍ + * ˵Ã÷£º´Ë´¦¿É¸ù¾Ýʵ¼ÊÏîÄ¿Çé¿ö½øÐÐÍØÕ¹ + * 1.swap ½»»» + * 2.´ó¶Ë/С¶Ë,ĬÈÏÊÇ´ó¶Ë + * 3.ÍØÕ¹ÆäËûÊý¾ÝÀàÐÍ + * + * @param type Value Type + * @return Modbus Data Type + */ + public int getValueType(String type) { + switch (type.toLowerCase()) { + case ValueType.LONG: + return DataType.FOUR_BYTE_INT_SIGNED; + case ValueType.FLOAT: + return DataType.FOUR_BYTE_FLOAT; + case ValueType.DOUBLE: + return DataType.EIGHT_BYTE_FLOAT; + default: + return DataType.TWO_BYTE_INT_SIGNED; + } + } + + public static void main(String[] args) { + ModbusService service = new ModbusService(); + service.getMaster("10.9.66.21",502); + try { + String anInt = service.readValue(service.modbusMaster, 1, 3, 1, "String"); +// boolean b = service.writeValue(service.modbusMaster, 1, 3, 1, "String", "111"); +// System.err.println(b); + } catch (ModbusTransportException e) { + e.printStackTrace(); + } catch (ErrorResponseException e) { + e.printStackTrace(); + } + } +} diff --git a/src/com/wms/dss/ats/customs/abb/modbus/ValueType.java b/src/com/wms/dss/ats/customs/abb/modbus/ValueType.java new file mode 100644 index 0000000..6639537 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/modbus/ValueType.java @@ -0,0 +1,17 @@ +package com.wms.dss.ats.customs.abb.modbus; + +/** + * @author zn kai + * @create 2022-03-31 11:28 + */ +public class ValueType { + public static final String BYTE = "byte"; + public static final String SHORT = "short"; + public static final String INT = "int"; + public static final String LONG = "long"; + public static final String FLOAT = "float"; + public static final String DOUBLE = "double"; + public static final String BOOLEAN = "boolean"; + public static final String STRING = "string"; + public static final String ENUM = "enum"; +} diff --git a/src/com/wms/dss/ats/customs/abb/plc/HslRead.java b/src/com/wms/dss/ats/customs/abb/plc/HslRead.java new file mode 100644 index 0000000..abb63fc --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/plc/HslRead.java @@ -0,0 +1,105 @@ +package com.wms.dss.ats.customs.abb.plc; + +import HslCommunication.BasicFramework.SoftBasic; +import HslCommunication.Core.Net.IReadWriteNet; +import HslCommunication.Core.Types.OperateResult; +import HslCommunication.Core.Types.OperateResultExOne; + +import javax.swing.*; +import java.awt.*; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class HslRead { + + private static SimpleDateFormat dateFormat = new SimpleDateFormat("[HH:mm:ss] "); + + /** + * ½«½á¹ûÐÅÏ¢ÏÔʾ³öÀ´£¬ÔÚ½çÃæÀï½øÐÐÏÔʾ + * @param result µÈ´ýÏÔʾµÄ½á¹ûÐÅÏ¢ + * @param x + * @param address ¶ÁÈ¡µÄµØÖ·Êý¾Ý + * @param textBox ÏÔʾ½á¹ûµÄÎı¾¿ò + * @param scrollPane Ö§³Ö¹ö¶¯ÌõµÄ¿Ø¼þ + * @param ÀàÐͶÔÏó + * @return + * @return + * @return + * @return + * @return + */ + public static T ReadResultRender(OperateResultExOne result ) { + + T x = null ; + if (result.IsSuccess) { + if (result.Content.getClass().isArray()) { + + } else { + x= (T) result.Content; + } + } else { + + JOptionPane.showMessageDialog( + null, + dateFormat.format(new Date()) + "] Read Failed\r\nReason:" + result.ToMessageShowString(), + "Result", + JOptionPane.WARNING_MESSAGE); + } + return x; + } + + public static int WriteResultRender(OperateResult result, String address ) { //void + int x=0; + if (result.IsSuccess) { +// JOptionPane.showMessageDialog( +// null, +// dateFormat.format(new Date()) + "[" + address + "] Write Success", +// "Result", +// JOptionPane.PLAIN_MESSAGE); + x=1; + } else { +// JOptionPane.showMessageDialog( +// null, +// dateFormat.format(new Date()) + "[" + address + "] Write Failed\r\nReason:" + result.ToMessageShowString(), +// "Result", +// JOptionPane.WARNING_MESSAGE); + x=2; + } + return x; + } + + public static void BulkReadRenderResult(IReadWriteNet readWrite, JTextField addTextBox, JTextField lengthTextBox, JTextArea resultTextBox ) { + try { + OperateResultExOne read = readWrite.Read(addTextBox.getText(), Short.parseShort(lengthTextBox.getText())); + if (read.IsSuccess) { + resultTextBox.setText("Result£º" + SoftBasic.ByteToHexString(read.Content)); + } else { + JOptionPane.showMessageDialog(null, "Read Failed£º" + read.ToMessageShowString(), "Result", JOptionPane.WARNING_MESSAGE); + } + } catch (Exception ex) { + JOptionPane.showMessageDialog(null, "Read Failed£º" + ex.getMessage(), "Result", JOptionPane.ERROR_MESSAGE); + } + } + + public static void SetPanelEnabled(JPanel panel, boolean enable) { + Component[] components = panel.getComponents(); + + //System.out.println("Component Length:" + components.length); + for (Component component : components) { + if (component instanceof JPanel) { + SetPanelEnabled((JPanel) component, enable); + } else { + component.setEnabled(enable); + } + } + + } + + public static String IpAddressInputWrong = "IpAddress input wrong"; + public static String PortInputWrong = "Port input wrong"; + public static String SlotInputWrong = "Slot input wrong"; + public static String BaudRateInputWrong = "Baud rate input wrong"; + public static String DataBitsInputWrong = "Data bit input wrong"; + public static String StopBitInputWrong = "Stop bit input wrong"; + +} diff --git a/src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientDDJ1.java b/src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientDDJ1.java new file mode 100644 index 0000000..eec4048 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientDDJ1.java @@ -0,0 +1,304 @@ +package com.wms.dss.ats.customs.abb.plc; + +import HslCommunication.BasicFramework.SoftBasic; +import HslCommunication.Core.Net.IReadWriteNet; +import HslCommunication.Core.Types.OperateResult; +import HslCommunication.Core.Types.OperateResultExOne; +import HslCommunication.Profinet.Siemens.SiemensPLCS; +import HslCommunication.Profinet.Siemens.SiemensS7Net; +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.ricosoft.common.logger.Logger; +import com.wms.dss.ats.customs.abb.entity.BasDevice; +import com.wms.dss.ats.customs.abb.entity.BasFaultRecord; +import com.wms.dss.ats.customs.abb.entity.DDJ_Device; +import com.wms.dss.ats.customs.abb.entity.MydoJob; +import com.wms.dss.ats.customs.abb.utils.QueryDbDataUtils; +import com.wms.dss.ats.customs.abb.utils.Tools; +import com.wms.dss.ats.customs.abb.utils.UtilId; +import org.libnodave.PLCinterface; +import org.libnodave.TCPConnection; +import org.s7.standard.ynuo.ReadDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface.groupPlcObj; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.*; + +public class IsoTcpClientDDJ1 extends Thread { + /* ʱ¼ä´Á */ + long t1, t2; + /* ipµØÖ· */ + String strIp = ""; + /* ¶Ë¿ÚºÅ */ + int iPort = 102; + /* ²Û¿ÚºÅ */ + int slot = 1; + PLCinterface di; + TCPConnection dc; + /* socket¿Í»§¶Ë */ + Socket sock; + /* Êä³öÁ÷ */ + OutputStream oStream = null; + /* ÊäÈëÁ÷ */ + InputStream iStream = null; + /* дÈ뻺´æÊý¾Ý */ + byte[] by; + EntityDAO dao; + public Hashtable hsSysParam = null; + public Hashtable hsComParam = null; + public SiemensS7Net siemensS7Net = null; + public static IReadWriteNet readWriteNet = null; + public boolean success = false; + public HashMap hsDDJParam = null; + + @SuppressWarnings("unchecked") + public IsoTcpClientDDJ1(Hashtable hsComParam, Hashtable hsSysParam, EntityDAO dao) { + this.hsComParam = hsComParam; + this.hsSysParam = hsSysParam; + this.hsDDJParam = (HashMap) this.hsComParam.get("hsddjMap1"); + this.strIp = (String) hsComParam.get("strIpddj"); + this.iPort = (Integer) hsComParam.get("iPortddj"); + this.slot = (Integer) hsComParam.get("slotddj"); + this.dao = dao; + + } + + void ConnectServer() { + siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500); + try { + siemensS7Net.setIpAddress(this.strIp); + siemensS7Net.setPort(this.iPort); + siemensS7Net.setRack((byte) Integer.parseInt("0")); + siemensS7Net.setSlot((byte) this.slot); + + OperateResult connect = siemensS7Net.ConnectServer(); + if (connect.IsSuccess) { + setIsConnect(true); + readWriteNet = siemensS7Net; + //Logger.info("q"); + } else { +// JOptionPane.showMessageDialog(null,"Connect Failed:" + connect.ToMessageShowString(),"Result",JOptionPane.WARNING_MESSAGE); + } + } catch (Exception ex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½ÓÒì³£ " + ex.getMessage()); + } + } + + public void setIsConnect(boolean bflag) { + if (success != true) { + success = bflag; + } + } + + public boolean IsConnect() { + if (success == true) { + return success; + } + return false; + } + + void closeServer() { + if (readWriteNet != null) { + OperateResult connectclose = siemensS7Net.ConnectClose(); + } + setIsConnect(false); + } + + void reConnect() { + closeServer(); + ConnectServer(); + Logger.info("ÖØÆô¶Ñ¶â»ú1"); + } + + public void run() { + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + try { +// Logger.info("--------------------Ïß³Ì--------¶ÁÈ¡¶Ñ¶â»ú1ÐÅÏ¢-----------¿ªÊ¼---------------------"); + if (IsConnect()) { + String address = "0", ddj_id = "0"; + ddj_id = "ddj-1"; + address = "DB60.0"; + DDJ_Device ddj1 = (DDJ_Device) hsDDJParam.get(ddj_id); + ddj1.dName = "1ºÅ¶Ñ¶â»ú"; + ddj1.CZFS = 0; //תΪ16½øÖƵÄÕûÐÍ + ddj1.SBZT = 0; + ddj1.ZXRWH = 0; + ddj1.HCZT = 0; + ddj1.ZXJD = 0; + ddj1.DQP = 0; + ddj1.DQL = 0; + ddj1.DQC = 0; + ddj1.MBPH = 0; + ddj1.MBLH = 0; + ddj1.MBCH = 0; + ddj1.YXXF = 0; + ddj1.XTXH = 0; + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("28"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "0"; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + ddj1.CZFS = (int) Long.parseLong(ddsx1.substring(0, 4), 16); //תΪ16½øÖƵÄÕûÐÍ + ddj1.SBZT = (int) Long.parseLong(ddsx1.substring(4, 8), 16); + ddj1.ZXRWH = Long.parseLong(ddsx1.substring(8, 16), 16); + ddj1.HCZT = (int) Long.parseLong(ddsx1.substring(16, 20), 16); + ddj1.ZXJD = (int) Long.parseLong(ddsx1.substring(20, 24), 16); + ddj1.DQP = (int) Long.parseLong(ddsx1.substring(24, 28), 16); + ddj1.DQL = (int) Long.parseLong(ddsx1.substring(28, 32), 16); + ddj1.DQC = (int) Long.parseLong(ddsx1.substring(32, 36), 16); + ddj1.MBPH = (int) Long.parseLong(ddsx1.substring(36, 40), 16); + ddj1.MBLH = (int) Long.parseLong(ddsx1.substring(40, 44), 16); + ddj1.MBCH = (int) Long.parseLong(ddsx1.substring(44, 48), 16); + ddj1.YXXF = (int) Long.parseLong(ddsx1.substring(48, 52), 16); + ddj1.XTXH = (int) Long.parseLong(ddsx1.substring(52, 56), 16); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateTime = sdf.format(new Date()); + if (ddj1.SBZT > 1000) { + List list = QueryDbDataUtils.getRecordByTaskAndId(dao, ddj1.btId, ddj1.ZXRWH); + MydoJob job = QueryDbDataUtils.findMydoJobByTaskNo(dao, ddj1.ZXRWH); + if (job != null) { + List list1 = QueryDbDataUtils.getRecordByTaskAndJobId(dao, ddj1.btId, job.getJob_id()); + if (list.size() == 0 && list1.size() == 0) { + BasFaultRecord record = new BasFaultRecord(); + record.setId(UtilId.uuids()); + record.setDeviceId(String.valueOf(ddj1.btId)); + record.setDeviceName(ddj1.btId + "ºÅ¶Ñ¶â»ú"); + record.setDeviceType("¶Ñ¶â»ú"); + record.setTaskNo(String.valueOf(ddj1.ZXRWH)); + record.setJobId(job.getJob_id()); + + record.setStartTime(dateTime); + record.setAlarmCode(String.valueOf(ddj1.SBZT)); + record.setAlarmStatus(getZt(ddj1.SBZT)); + record.setReset("0"); + dao.save(record); + } + } + } + if (ddj1.SBZT < 1000 && ddj1.CZFS == 5) { + List list = QueryDbDataUtils.getRecordByTaskAndId(dao, ddj1.btId, ddj1.ZXRWH); + if (list.size() == 1) { + BasFaultRecord record = list.get(0); + record.setReset("1"); + record.setFinishTime(dateTime); + dao.updateSql("update BasFaultRecord set reset = 1,finish_time = '" + dateTime + "' where id = '" + list.get(0).getId() + "'"); + } + } + }// ±äÁ¿.Substring(²ÎÊý1,²ÎÊý2); ÕûÐÍ4¸ö×Ö½Ú ³¤ÕûÐÍ8¸ö×Ö½Ú + + dao.updateSql("update MsgDdj set rwh='" + ddj1.ZXRWH + "',czfs='" + ddj1.CZFS + "'," + + " jdbz='" + ddj1.ZXJD + "',sbzt='" + ddj1.SBZT + "',yxxf='" + ddj1.YXXF + "'," + + " yp='" + ddj1.DQP + "',yl='" + ddj1.DQL + "',yc='" + ddj1.DQC + "'," + + " mbp='" + ddj1.MBPH + "',mbl='" + ddj1.MBLH + "',mbc='" + ddj1.MBCH + "' " + + " where id='" + ddj1.btId + "'"); + +// Logger.info("--------------------Ïß³Ì--------¶ÁÈ¡¶Ñ¶â»ú1ÐÅÏ¢-----------½áÊø---------------------"); + Thread.sleep(800); + } else { + BasDevice basDevice = QueryDbDataUtils.basDevice(dao, 1); + if (basDevice != null && "N".equals(basDevice.getLocked())) { + Logger.info("----------ÎÞÁ´½Ó----------Ïß³Ì--------¶ÁÈ¡¶Ñ¶â»ú1ÐÅÏ¢-----------½áÊø---------------------"); + reConnect(); + } + } + } catch (Exception ex) { + Logger.info("------catch--------------Ïß³Ì--------¶ÁÈ¡¶Ñ¶â»ú1ÐÅÏ¢-----------½áÊø0--------------------"); + reConnect(); + } + // ÿ´ÎÑ­»·´ò¿ª¹Ø±ÕÁ´½Ó + //reConnect(); + } + closeServer(); + } + + ///¶Ñ¶â»úÈÎÎñÏ·¢ + public static int WritetoDDJ(String address, byte[] tsak) { + int a = 0; + if (readWriteNet != null) { + a = HslRead.WriteResultRender(readWriteNet.Write(address, tsak), address); + } + return a; + } + + private String getZt(int value) { + + if (value == 0) { + return "´ý»ú"; + } else if (value == 1) { + return "¹¤×÷"; + } else if (value == 1031) { + return "¼±Í£"; + } else if (value == 1032) { + return "»õ²æ²»ÔÚÖÐλ"; + } else if (value == 1033) { + return "ÐÐ×߱䯵±¨¾¯"; + } else if (value == 1034) { + return "Éý½µ±äƵ±¨¾¯"; + } else if (value == 1035) { + return "»õ²æ±äƵ±¨¾¯"; + } else if (value == 1036) { + return "»õ²æ±äƵ±¨¾¯"; + } else if (value == 1037) { + return "ÔËÐÐÏÞλ¹ÊÕÏ"; + } else if (value == 1038) { + return "Éý½µÏÞλ¹ÊÕÏ"; + } else if (value == 1039) { + return "ÔËÐв»ÄܾÀÆ«"; + } else if (value == 1040) { + return "Éý½µ²»ÄܾÀÆ«"; + } else if (value == 1041) { + return "ˮƽ²â¾à³ö´í"; + } else if (value == 1042) { + return "´¹Ö±BPS³ö´í"; + } else if (value == 1043) { + return "³¬ËÙ±£»¤"; + } else if (value == 1044) { + return "ǰ±ß³¬¿í"; + } else if (value == 1045) { + return "ºó±ß³¬¿í"; + } else if (value == 1046) { + return "×ó±ßÍáб"; + } else if (value == 1047) { + return "ÓÒ±ßÍáб"; + } else if (value == 1048) { + return "³¬¸ß1"; + } else if (value == 1049) { + return "³¬¸ß2"; + } else if (value == 1050) { + return "·Å»õÍê±Ï»õ²æÓлõ"; + } else if (value == 1051) { + return "È¡»õʱ»õ²æÓлõ"; + } else if (value == 1052) { + return "·Å»õÄ¿±êÓлõ"; + } else if (value == 1053) { + return "È¡»õÍê±ÏÎÞ»õ"; + } else if (value == 1054) { + return "·Å»õʱ»õ²æÎÞ»õ"; + } else if (value == 1055) { + return "»õ²æ¶¯×÷³¬Ê±"; + } else if (value == 1056) { + return "»õ²æ²»ÄܾÀÆ«"; + } else if (value == 1057) { + return "΢Éý½µ³¬Ê±"; + } else if (value == 1058) { + return "ËÉÉþ¹ýÔØ"; + } else if (value == 1059) { + return "É趨³¬ÏÞ"; + } else if (value == 1060) { + return "ȡ˫Éìʱµ¥ÉìÓлõ"; + } else if (value == 1061) { + return "·ÅË«Éìʱµ¥ÉìÓлõ"; + } else if (value == 1062) { + return "Èë¿âÊäËÍ»úÈÎÎñ²»·û"; + } else if (value == 1063) { + return "°²È«ÃÅ´ò¿ª"; + } else if (value == 9999) { + return "É豸δÁª»ú"; + } else { + return "δ֪"; + } + + } +} diff --git a/src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientDDJ2.java b/src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientDDJ2.java new file mode 100644 index 0000000..29da1e4 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientDDJ2.java @@ -0,0 +1,293 @@ +package com.wms.dss.ats.customs.abb.plc; + +import HslCommunication.BasicFramework.SoftBasic; +import HslCommunication.Core.Net.IReadWriteNet; +import HslCommunication.Core.Types.OperateResult; +import HslCommunication.Core.Types.OperateResultExOne; +import HslCommunication.Profinet.Siemens.SiemensPLCS; +import HslCommunication.Profinet.Siemens.SiemensS7Net; +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.ricosoft.common.logger.Logger; +import com.wms.dss.ats.customs.abb.entity.BasDevice; +import com.wms.dss.ats.customs.abb.entity.BasFaultRecord; +import com.wms.dss.ats.customs.abb.entity.DDJ_Device; +import com.wms.dss.ats.customs.abb.entity.MydoJob; +import com.wms.dss.ats.customs.abb.utils.QueryDbDataUtils; +import com.wms.dss.ats.customs.abb.utils.Tools; +import com.wms.dss.ats.customs.abb.utils.UtilId; +import org.libnodave.PLCinterface; +import org.libnodave.TCPConnection; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; + +public class IsoTcpClientDDJ2 extends Thread{ + /* ʱ¼ä´Á */ + long t1, t2; + /* ipµØÖ· */ + String strIp = ""; + /* ¶Ë¿ÚºÅ */ + int iPort = 102; + /* ²Û¿ÚºÅ */ + int slot = 1; + PLCinterface di; + TCPConnection dc; + /* socket¿Í»§¶Ë */ + Socket sock; + /* Êä³öÁ÷ */ + OutputStream oStream = null; + /* ÊäÈëÁ÷ */ + InputStream iStream = null; + /* дÈ뻺´æÊý¾Ý */ + byte[] by; + EntityDAO dao; + public Hashtable hsSysParam = null; + public Hashtable hsComParam = null; + public SiemensS7Net siemensS7Net = null; + public static IReadWriteNet readWriteNet = null; + public boolean success=false; + public HashMap hsDDJParam = null; + @SuppressWarnings("unchecked") + public IsoTcpClientDDJ2(Hashtable hsComParam, Hashtable hsSysParam, EntityDAO dao) { + this.hsComParam = hsComParam; + this.hsSysParam = hsSysParam; + this.hsDDJParam = (HashMap) this.hsComParam.get("hsddjMap2"); + this.strIp = (String) hsComParam.get("strIpddj"); + this.iPort = (Integer) hsComParam.get("iPortddj"); + this.slot = (Integer) hsComParam.get("slotddj"); + this.dao = dao; + } + void ConnectServer() { + siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500); + try { + siemensS7Net.setIpAddress(this.strIp); + siemensS7Net.setPort(this.iPort); + siemensS7Net.setRack((byte) Integer.parseInt("0")); + siemensS7Net.setSlot((byte) this.slot); + + OperateResult connect = siemensS7Net.ConnectServer(); + if(connect.IsSuccess){ + setIsConnect(true); + readWriteNet = siemensS7Net; + //Logger.info("q"); + } else { +// JOptionPane.showMessageDialog(null,"Connect Failed:" + connect.ToMessageShowString(),"Result",JOptionPane.WARNING_MESSAGE); + } + } + catch (Exception ex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½ÓÒì³£ " + ex.getMessage()); + } + } + public void setIsConnect(boolean bflag) { + if (success != true) { + success = bflag; + } + } + public boolean IsConnect() { + if (success == true) { + return success; + } + return false; + } + void closeServer() { + if (readWriteNet != null) { + OperateResult connectclose = siemensS7Net.ConnectClose(); + } + setIsConnect(false); + } + void reConnect() { + closeServer(); + ConnectServer(); + Logger.info("ÖØÆô¶Ñ¶â»ú2"); + } + public void run() { + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + try { +// Logger.info("--------------------Ïß³Ì--------¶ÁÈ¡¶Ñ¶â»ú2ÐÅÏ¢-----------¿ªÊ¼---------------------"); + if (IsConnect()) { + String address = "0", ddj_id = "0"; + ddj_id = "ddj-2"; + address = "DB60.0"; + DDJ_Device ddj2 = (DDJ_Device) hsDDJParam.get(ddj_id); + ddj2.dName = "2ºÅ¶Ñ¶â»ú"; + ddj2.CZFS = 0; //תΪ16½øÖƵÄÕûÐÍ + ddj2.SBZT = 0; + ddj2.ZXRWH = 0; + ddj2.HCZT = 0; + ddj2.ZXJD = 0; + ddj2.DQP = 0; + ddj2.DQL = 0; + ddj2.DQC = 0; + ddj2.MBPH = 0; + ddj2.MBLH = 0; + ddj2.MBCH = 0; + ddj2.YXXF = 0; + ddj2.XTXH = 0; + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("28"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx2 = "0"; + if (read1.IsSuccess) { + ddsx2 = SoftBasic.ByteToHexString(read1.Content); + ddj2.CZFS = (int) Long.parseLong(ddsx2.substring(0, 4), 16); //תΪ16½øÖƵÄÕûÐÍ + ddj2.SBZT = (int) Long.parseLong(ddsx2.substring(4, 8), 16); + ddj2.ZXRWH = Long.parseLong(ddsx2.substring(8, 16), 16); + ddj2.HCZT = (int) Long.parseLong(ddsx2.substring(16, 20), 16); + ddj2.ZXJD = (int) Long.parseLong(ddsx2.substring(20, 24), 16); + ddj2.DQP = (int) Long.parseLong(ddsx2.substring(24, 28), 16); + ddj2.DQL = (int) Long.parseLong(ddsx2.substring(28, 32), 16); + ddj2.DQC = (int) Long.parseLong(ddsx2.substring(32, 36), 16); + ddj2.MBPH = (int) Long.parseLong(ddsx2.substring(36, 40), 16); + ddj2.MBLH = (int) Long.parseLong(ddsx2.substring(40, 44), 16); + ddj2.MBCH = (int) Long.parseLong(ddsx2.substring(44, 48), 16); + ddj2.YXXF = (int) Long.parseLong(ddsx2.substring(48, 52), 16); + ddj2.XTXH = (int) Long.parseLong(ddsx2.substring(52, 56), 16); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateTime = sdf.format(new Date()); + if (ddj2.SBZT > 1000) { + List list = QueryDbDataUtils.getRecordByTaskAndId(dao, ddj2.btId, ddj2.ZXRWH); + MydoJob job = QueryDbDataUtils.findMydoJobByTaskNo(dao, ddj2.ZXRWH); + if (job != null) { + List list1 = QueryDbDataUtils.getRecordByTaskAndJobId(dao, ddj2.btId, job.getJob_id()); + if (list.size() == 0 && list1.size() ==0) { + BasFaultRecord record = new BasFaultRecord(); + record.setId(UtilId.uuids()); + record.setDeviceId(String.valueOf(ddj2.btId)); + record.setDeviceName(ddj2.btId + "ºÅ¶Ñ¶â»ú"); + record.setDeviceType("¶Ñ¶â»ú"); + record.setTaskNo(String.valueOf(ddj2.ZXRWH)); + record.setJobId(job.getJob_id()); + record.setStartTime(dateTime); + record.setAlarmCode(String.valueOf(ddj2.SBZT)); + record.setAlarmStatus(getZt(ddj2.SBZT)); + record.setReset("0"); + dao.save(record); + } + } + } + if(ddj2.SBZT < 1000 && ddj2.CZFS == 5){ + List list = QueryDbDataUtils.getRecordByTaskAndId(dao,ddj2.btId,ddj2.ZXRWH); + if(list.size() == 1) { + BasFaultRecord record = list.get(0); + record.setReset("1"); + record.setFinishTime(dateTime); + dao.updateSql("update BasFaultRecord set reset = 1,finish_time = '"+dateTime+"' where id = '"+list.get(0).getId()+"'"); + } + } + }// ±äÁ¿.Substring(²ÎÊý1,²ÎÊý2); ÕûÐÍ4¸ö×Ö½Ú ³¤ÕûÐÍ8¸ö×Ö½Ú +// Logger.info("--------------------Ïß³Ì--------¶ÁÈ¡¶Ñ¶â»ú2ÐÅÏ¢-----------½áÊø---------------------"); + dao.updateSql("update MsgDdj set rwh='"+ddj2.ZXRWH+"',czfs='"+ddj2.CZFS+"'," + + " jdbz='"+ddj2.ZXJD+"',sbzt='"+ddj2.SBZT+"',yxxf='"+ddj2.YXXF+"'," + + " yp='"+ddj2.DQP+"',yl='"+ddj2.DQL+"',yc='"+ddj2.DQC+"'," + + " mbp='"+ddj2.MBPH+"',mbl='"+ddj2.MBLH+"',mbc='"+ddj2.MBCH+"' " + + " where id='"+ddj2.btId+"'"); + + Thread.sleep(800); + } else { + BasDevice basDevice = QueryDbDataUtils.basDevice(dao, 2); + if (basDevice != null && "N".equals(basDevice.getLocked())) { + Logger.info("----------ÎÞÁ´½Ó----------Ïß³Ì--------¶ÁÈ¡¶Ñ¶â»ú3ÐÅÏ¢-----------½áÊø---------------------"); + reConnect(); + } + } + } catch (Exception ex) { + Logger.info("------catch--------------Ïß³Ì--------¶ÁÈ¡¶Ñ¶â»ú2ÐÅÏ¢-----------½áÊø0--------------------"); + reConnect(); + } + // ÿ´ÎÑ­»·´ò¿ª¹Ø±ÕÁ´½Ó + //reConnect(); + } + closeServer(); + } + ///¶Ñ¶â»úÈÎÎñÏ·¢ + public static int WritetoDDJ(String address,byte[] tsak ) { + int a=0; + if (readWriteNet != null) { + a= HslRead.WriteResultRender(readWriteNet.Write(address, tsak), address); + } + return a; + } + private String getZt(int value) { + + if (value == 0) { + return "´ý»ú"; + } else if (value == 1) { + return "¹¤×÷"; + } else if (value == 1031) { + return "¼±Í£"; + } else if (value == 1032) { + return "»õ²æ²»ÔÚÖÐλ"; + } else if (value == 1033) { + return "ÐÐ×߱䯵±¨¾¯"; + } else if (value == 1034) { + return "Éý½µ±äƵ±¨¾¯"; + } else if (value == 1035) { + return "»õ²æ±äƵ±¨¾¯"; + } else if (value == 1036) { + return "»õ²æ±äƵ±¨¾¯"; + } else if (value == 1037) { + return "ÔËÐÐÏÞλ¹ÊÕÏ"; + } else if (value == 1038) { + return "Éý½µÏÞλ¹ÊÕÏ"; + } else if (value == 1039) { + return "ÔËÐв»ÄܾÀÆ«"; + } else if (value == 1040) { + return "Éý½µ²»ÄܾÀÆ«"; + } else if (value == 1041) { + return "ˮƽ²â¾à³ö´í"; + } else if (value == 1042) { + return "´¹Ö±BPS³ö´í"; + } else if (value == 1043) { + return "³¬ËÙ±£»¤"; + } else if (value == 1044) { + return "ǰ±ß³¬¿í"; + } else if (value == 1045) { + return "ºó±ß³¬¿í"; + } else if (value == 1046) { + return "×ó±ßÍáб"; + } else if (value == 1047) { + return "ÓÒ±ßÍáб"; + } else if (value == 1048) { + return "³¬¸ß1"; + } else if (value == 1049) { + return "³¬¸ß2"; + } else if (value == 1050) { + return "·Å»õÍê±Ï»õ²æÓлõ"; + } else if (value == 1051) { + return "È¡»õʱ»õ²æÓлõ"; + } else if (value == 1052) { + return "·Å»õÄ¿±êÓлõ"; + } else if (value == 1053) { + return "È¡»õÍê±ÏÎÞ»õ"; + } else if (value == 1054) { + return "·Å»õʱ»õ²æÎÞ»õ"; + } else if (value == 1055) { + return "»õ²æ¶¯×÷³¬Ê±"; + } else if (value == 1056) { + return "»õ²æ²»ÄܾÀÆ«"; + } else if (value == 1057) { + return "΢Éý½µ³¬Ê±"; + } else if (value == 1058) { + return "ËÉÉþ¹ýÔØ"; + } else if (value == 1059) { + return "É趨³¬ÏÞ"; + } else if (value == 1060) { + return "ȡ˫Éìʱµ¥ÉìÓлõ"; + } else if (value == 1061) { + return "·ÅË«Éìʱµ¥ÉìÓлõ"; + } else if (value == 1062) { + return "Èë¿âÊäËÍ»úÈÎÎñ²»·û"; + } else if (value == 1063) { + return "°²È«ÃÅ´ò¿ª"; + } else if (value == 9999) { + return "É豸δÁª»ú"; + }else{ + return "δ֪"; + } + + } +} diff --git a/src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientDDJ3.java b/src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientDDJ3.java new file mode 100644 index 0000000..3f22d82 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientDDJ3.java @@ -0,0 +1,294 @@ +package com.wms.dss.ats.customs.abb.plc; + +import HslCommunication.BasicFramework.SoftBasic; +import HslCommunication.Core.Net.IReadWriteNet; +import HslCommunication.Core.Types.OperateResult; +import HslCommunication.Core.Types.OperateResultExOne; +import HslCommunication.Profinet.Siemens.SiemensPLCS; +import HslCommunication.Profinet.Siemens.SiemensS7Net; +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.ricosoft.common.logger.Logger; +import com.wms.dss.ats.customs.abb.entity.BasDevice; +import com.wms.dss.ats.customs.abb.entity.BasFaultRecord; +import com.wms.dss.ats.customs.abb.entity.DDJ_Device; +import com.wms.dss.ats.customs.abb.entity.MydoJob; +import com.wms.dss.ats.customs.abb.utils.QueryDbDataUtils; +import com.wms.dss.ats.customs.abb.utils.Tools; +import com.wms.dss.ats.customs.abb.utils.UtilId; +import org.libnodave.PLCinterface; +import org.libnodave.TCPConnection; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; + +public class IsoTcpClientDDJ3 extends Thread{ + /* ʱ¼ä´Á */ + long t1, t2; + /* ipµØÖ· */ + String strIp = ""; + /* ¶Ë¿ÚºÅ */ + int iPort = 102; + /* ²Û¿ÚºÅ */ + int slot = 1; + PLCinterface di; + TCPConnection dc; + /* socket¿Í»§¶Ë */ + Socket sock; + /* Êä³öÁ÷ */ + OutputStream oStream = null; + /* ÊäÈëÁ÷ */ + InputStream iStream = null; + /* дÈ뻺´æÊý¾Ý */ + byte[] by; + EntityDAO dao; + public Hashtable hsSysParam = null; + public Hashtable hsComParam = null; + public SiemensS7Net siemensS7Net = null; + public static IReadWriteNet readWriteNet = null; + public boolean success=false; + public HashMap hsDDJParam = null; + @SuppressWarnings("unchecked") + public IsoTcpClientDDJ3(Hashtable hsComParam, Hashtable hsSysParam, EntityDAO dao) { + this.hsComParam = hsComParam; + this.hsSysParam = hsSysParam; + this.hsDDJParam = (HashMap) this.hsComParam.get("hsddjMap3"); + this.strIp = (String) hsComParam.get("strIpddj"); + this.iPort = (Integer) hsComParam.get("iPortddj"); + this.slot = (Integer) hsComParam.get("slotddj"); + this.dao = dao; + } + void ConnectServer() { + siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500); + try { + siemensS7Net.setIpAddress(this.strIp); + siemensS7Net.setPort(this.iPort); + siemensS7Net.setRack((byte) Integer.parseInt("0")); + siemensS7Net.setSlot((byte) this.slot); + + OperateResult connect = siemensS7Net.ConnectServer(); + if(connect.IsSuccess){ + setIsConnect(true); + readWriteNet = siemensS7Net; + //Logger.info("q"); + } else { +// JOptionPane.showMessageDialog(null,"Connect Failed:" + connect.ToMessageShowString(),"Result",JOptionPane.WARNING_MESSAGE); + } + } + catch (Exception ex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½ÓÒì³£ " + ex.getMessage()); + } + } + public void setIsConnect(boolean bflag) { + if (success != true) { + success = bflag; + } + } + public boolean IsConnect() { + if (success == true) { + return success; + } + return false; + } + void closeServer() { + if (readWriteNet != null) { + OperateResult connectclose = siemensS7Net.ConnectClose(); + } + setIsConnect(false); + } + void reConnect() { + closeServer(); + ConnectServer(); + Logger.info("ÖØÆô¶Ñ¶â»ú3"); + } + public void run() { + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + try { +// Logger.info("--------------------Ïß³Ì--------¶ÁÈ¡¶Ñ¶â»ú3ÐÅÏ¢-----------¿ªÊ¼---------------------"); + if (IsConnect()) { + String address = "0", ddj_id = "0"; + ddj_id = "ddj-3"; + address = "DB60.0"; + DDJ_Device ddj3 = (DDJ_Device) hsDDJParam.get(ddj_id); + ddj3.dName = "3ºÅ¶Ñ¶â»ú"; + ddj3.CZFS = 0; //תΪ36½øÖƵÄÕûÐÍ + ddj3.SBZT = 0; + ddj3.ZXRWH = 0; + ddj3.HCZT = 0; + ddj3.ZXJD = 0; + ddj3.DQP = 0; + ddj3.DQL = 0; + ddj3.DQC = 0; + ddj3.MBPH = 0; + ddj3.MBLH = 0; + ddj3.MBCH = 0; + ddj3.YXXF = 0; + ddj3.XTXH = 0; + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("28"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx3 = "0"; + if (read1.IsSuccess) { + ddsx3 = SoftBasic.ByteToHexString(read1.Content); + ddj3.CZFS = (int) Long.parseLong(ddsx3.substring(0, 4), 16); //תΪ16½øÖƵÄÕûÐÍ + ddj3.SBZT = (int) Long.parseLong(ddsx3.substring(4, 8), 16); + ddj3.ZXRWH = Long.parseLong(ddsx3.substring(8, 16), 16); + ddj3.HCZT = (int) Long.parseLong(ddsx3.substring(16, 20), 16); + ddj3.ZXJD = (int) Long.parseLong(ddsx3.substring(20, 24), 16); + ddj3.DQP = (int) Long.parseLong(ddsx3.substring(24, 28), 16); + ddj3.DQL = (int) Long.parseLong(ddsx3.substring(28, 32), 16); + ddj3.DQC = (int) Long.parseLong(ddsx3.substring(32, 36), 16); + ddj3.MBPH = (int) Long.parseLong(ddsx3.substring(36, 40), 16); + ddj3.MBLH = (int) Long.parseLong(ddsx3.substring(40, 44), 16); + ddj3.MBCH = (int) Long.parseLong(ddsx3.substring(44, 48), 16); + ddj3.YXXF = (int) Long.parseLong(ddsx3.substring(48, 52), 16); + ddj3.XTXH = (int) Long.parseLong(ddsx3.substring(52, 56), 16); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateTime = sdf.format(new Date()); + if (ddj3.SBZT > 1000) { + List list = QueryDbDataUtils.getRecordByTaskAndId(dao, ddj3.btId, ddj3.ZXRWH); + MydoJob job = QueryDbDataUtils.findMydoJobByTaskNo(dao, ddj3.ZXRWH); + if (job != null) { + List list1 = QueryDbDataUtils.getRecordByTaskAndJobId(dao, ddj3.btId, job.getJob_id()); + if (list.size() == 0 && list1.size() ==0) { + BasFaultRecord record = new BasFaultRecord(); + record.setId(UtilId.uuids()); + record.setDeviceId(String.valueOf(ddj3.btId)); + record.setDeviceName(ddj3.btId + "ºÅ¶Ñ¶â»ú"); + record.setDeviceType("¶Ñ¶â»ú"); + record.setTaskNo(String.valueOf(ddj3.ZXRWH)); + record.setJobId(job.getJob_id()); + record.setStartTime(dateTime); + record.setAlarmCode(String.valueOf(ddj3.SBZT)); + record.setAlarmStatus(getZt(ddj3.SBZT)); + record.setReset("0"); + dao.save(record); + } + } + } + if(ddj3.SBZT < 1000 && ddj3.CZFS == 5){ + List list = QueryDbDataUtils.getRecordByTaskAndId(dao,ddj3.btId,ddj3.ZXRWH); + if(list.size() == 1) { + BasFaultRecord record = list.get(0); + record.setReset("1"); + record.setFinishTime(dateTime); +// dao.save(record); + dao.updateSql("update BasFaultRecord set reset = 1,finish_time = '"+dateTime+"' where id = '"+list.get(0).getId()+"'"); + } + } + }// ±äÁ¿.Substring(²ÎÊý1,²ÎÊý2); ÕûÐÍ4¸ö×Ö½Ú ³¤ÕûÐÍ8¸ö×Ö½Ú +// Logger.info("--------------------Ïß³Ì--------¶ÁÈ¡¶Ñ¶â»ú3ÐÅÏ¢-----------½áÊø---------------------"); + dao.updateSql("update MsgDdj set rwh='"+ddj3.ZXRWH+"',czfs='"+ddj3.CZFS+"'," + + " jdbz='"+ddj3.ZXJD+"',sbzt='"+ddj3.SBZT+"',yxxf='"+ddj3.YXXF+"'," + + " yp='"+ddj3.DQP+"',yl='"+ddj3.DQL+"',yc='"+ddj3.DQC+"'," + + " mbp='"+ddj3.MBPH+"',mbl='"+ddj3.MBLH+"',mbc='"+ddj3.MBCH+"' " + + " where id='"+ddj3.btId+"'"); + + Thread.sleep(800); + } else { + BasDevice basDevice = QueryDbDataUtils.basDevice(dao, 3); + if (basDevice != null && "N".equals(basDevice.getLocked())) { + Logger.info("----------ÎÞÁ´½Ó----------Ïß³Ì--------¶ÁÈ¡¶Ñ¶â»ú3ÐÅÏ¢-----------½áÊø---------------------"); + reConnect(); + } + } + } catch (Exception ex) { + Logger.info("------catch--------------Ïß³Ì--------¶ÁÈ¡¶Ñ¶â»ú3ÐÅÏ¢-----------½áÊø0--------------------"); + reConnect(); + } + // ÿ´ÎÑ­»·´ò¿ª¹Ø±ÕÁ´½Ó + //reConnect(); + } + closeServer(); + } + ///¶Ñ¶â»úÈÎÎñÏ·¢ + public static int WritetoDDJ(String address,byte[] tsak ) { + int a=0; + if (readWriteNet != null) { + a= HslRead.WriteResultRender(readWriteNet.Write(address, tsak), address); + } + return a; + } + private String getZt(int value) { + + if (value == 0) { + return "´ý»ú"; + } else if (value == 1) { + return "¹¤×÷"; + } else if (value == 1031) { + return "¼±Í£"; + } else if (value == 1032) { + return "»õ²æ²»ÔÚÖÐλ"; + } else if (value == 1033) { + return "ÐÐ×߱䯵±¨¾¯"; + } else if (value == 1034) { + return "Éý½µ±äƵ±¨¾¯"; + } else if (value == 1035) { + return "»õ²æ±äƵ±¨¾¯"; + } else if (value == 1036) { + return "»õ²æ±äƵ±¨¾¯"; + } else if (value == 1037) { + return "ÔËÐÐÏÞλ¹ÊÕÏ"; + } else if (value == 1038) { + return "Éý½µÏÞλ¹ÊÕÏ"; + } else if (value == 1039) { + return "ÔËÐв»ÄܾÀÆ«"; + } else if (value == 1040) { + return "Éý½µ²»ÄܾÀÆ«"; + } else if (value == 1041) { + return "ˮƽ²â¾à³ö´í"; + } else if (value == 1042) { + return "´¹Ö±BPS³ö´í"; + } else if (value == 1043) { + return "³¬ËÙ±£»¤"; + } else if (value == 1044) { + return "ǰ±ß³¬¿í"; + } else if (value == 1045) { + return "ºó±ß³¬¿í"; + } else if (value == 1046) { + return "×ó±ßÍáб"; + } else if (value == 1047) { + return "ÓÒ±ßÍáб"; + } else if (value == 1048) { + return "³¬¸ß1"; + } else if (value == 1049) { + return "³¬¸ß2"; + } else if (value == 1050) { + return "·Å»õÍê±Ï»õ²æÓлõ"; + } else if (value == 1051) { + return "È¡»õʱ»õ²æÓлõ"; + } else if (value == 1052) { + return "·Å»õÄ¿±êÓлõ"; + } else if (value == 1053) { + return "È¡»õÍê±ÏÎÞ»õ"; + } else if (value == 1054) { + return "·Å»õʱ»õ²æÎÞ»õ"; + } else if (value == 1055) { + return "»õ²æ¶¯×÷³¬Ê±"; + } else if (value == 1056) { + return "»õ²æ²»ÄܾÀÆ«"; + } else if (value == 1057) { + return "΢Éý½µ³¬Ê±"; + } else if (value == 1058) { + return "ËÉÉþ¹ýÔØ"; + } else if (value == 1059) { + return "É趨³¬ÏÞ"; + } else if (value == 1060) { + return "ȡ˫Éìʱµ¥ÉìÓлõ"; + } else if (value == 1061) { + return "·ÅË«Éìʱµ¥ÉìÓлõ"; + } else if (value == 1062) { + return "Èë¿âÊäËÍ»úÈÎÎñ²»·û"; + } else if (value == 1063) { + return "°²È«ÃÅ´ò¿ª"; + } else if (value == 9999) { + return "É豸δÁª»ú"; + }else{ + return "δ֪"; + } + + } +} diff --git a/src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientSSJ.java b/src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientSSJ.java new file mode 100644 index 0000000..c3ef6e5 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/plc/IsoTcpClientSSJ.java @@ -0,0 +1,863 @@ +package com.wms.dss.ats.customs.abb.plc; + +import HslCommunication.BasicFramework.SoftBasic; +import HslCommunication.Core.Net.IReadWriteNet; +import HslCommunication.Core.Types.OperateResult; +import HslCommunication.Core.Types.OperateResultExOne; +import HslCommunication.Profinet.Siemens.SiemensPLCS; +import HslCommunication.Profinet.Siemens.SiemensS7Net; +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.ricosoft.common.logger.Logger; +import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer; +import com.wms.dss.ats.customs.abb.entity.CMP_Device; +import com.wms.dss.ats.customs.abb.entity.JXS_Device; +import com.wms.dss.ats.customs.abb.entity.RKK_SSJ; +import com.wms.dss.ats.customs.abb.entity.XDK_SSJ; +import com.wms.dss.ats.customs.abb.utils.Tools; +import org.libnodave.PLCinterface; +import org.libnodave.TCPConnection; +import org.s7.standard.ynuo.ReadDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface.groupPlcObj; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.util.*; + +public class IsoTcpClientSSJ extends Thread { + /* ʱ¼ä´Á */ + long t1, t2; + /* ipµØÖ· */ + String strIp = ""; + /* ¶Ë¿ÚºÅ */ + int iPort = 102; + /* ²Û¿ÚºÅ */ + int slot = 1; + PLCinterface di; + TCPConnection dc; + /* socket¿Í»§¶Ë */ + Socket sock; + /* Êä³öÁ÷ */ + OutputStream oStream = null; + /* ÊäÈëÁ÷ */ + InputStream iStream = null; + /* дÈ뻺´æÊý¾Ý */ + byte[] by; + + EntityDAO dao; + public Hashtable hsSysParam = null; + public Hashtable hsComParam = null; + public SiemensS7Net siemensS7Net = null; + public static IReadWriteNet readWriteNet = null; + public boolean success = false; + public HashMap hsSSJParam = null; + + @SuppressWarnings("unchecked") + public IsoTcpClientSSJ(Hashtable hsComParam, Hashtable hsSysParam, EntityDAO dao) { + this.hsComParam = hsComParam; + this.hsSysParam = hsSysParam; + this.hsSSJParam = (HashMap) this.hsComParam.get("hsssjMap"); + this.strIp = (String) hsComParam.get("strIpddj"); + this.iPort = (Integer) hsComParam.get("iPortddj"); + this.slot = (Integer) hsComParam.get("slotddj"); + this.dao = dao; + + } + + void ConnectServer() { + siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500); + try { + siemensS7Net.setIpAddress(this.strIp); + siemensS7Net.setPort(this.iPort); + siemensS7Net.setRack((byte) Integer.parseInt("0")); + siemensS7Net.setSlot((byte) this.slot); + + OperateResult connect = siemensS7Net.ConnectServer(); + if (connect.IsSuccess) { + setIsConnect(true); + readWriteNet = siemensS7Net; + //Logger.info("q"); + } else { +// JOptionPane.showMessageDialog( +// null, +// "Connect Failed:" + connect.ToMessageShowString(), +// "Result", +// JOptionPane.WARNING_MESSAGE); + } + } catch (Exception ex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½ÓÒì³£ " + ex.getMessage()); + } + + } + + public void setIsConnect(boolean bflag) { + if (success != true) { + success = bflag; + } + } + + public boolean IsConnect() { + if (success == true) { + return success; + } + return false; + } + + void closeServer() { + if (readWriteNet != null) { + OperateResult connectclose = siemensS7Net.ConnectClose(); + } + setIsConnect(false); + + } + + void reConnect() { + closeServer(); + ConnectServer(); + Logger.info("ÊäËÍ»úPLC¶ÁÈ¡Ïß³ÌÆô¶¯"); + } + + public void run() { + Iterator iterR = null; + Iterator iterW = null; + List groups = null; + groupPlcObj group = null; + WriteDotPlcInterface plcWVar = null; + ReadDotPlcInterface plcRDotVar = null; + Map.Entry entry = null; + int a = 0, j = 0; + boolean ReConn = false; + int iPrintcount = 5;//5´Î½øÐдòÓ¡ + int currDecRun = 0;// µ±Ç°Ö´ÐдÎÊý + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + try { +// Logger.info("--------------------Ïß³Ì--------¶ÁÈ¡Èë¿â¿ÚÊäËÍ»úÐÅÏ¢-----------¿ªÊ¼---------------------"); + if (IsConnect()) { +// Logger.info("ÊäËÍ»úÐÅÏ¢¶ÁÈ¡¿ªÊ¼"); + //1Â¥Èë³ö¿â¿Ú + for (int i = 1; i <= 1; i++) { + String address = "0", rkk_ssj_id = "0", name = "0"; + rkk_ssj_id = "qqtm-1"; + address = "DB51.0"; + name = "1027"; + + RKK_SSJ ssj = (RKK_SSJ) hsSSJParam.get(rkk_ssj_id); + ssj.RKQQ = 0;// + ssj.RKGD = 0; + ssj.taskNo = 0; + ssj.dName = name; + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("8"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "0000000000000000"; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + ssj.taskNo = Long.parseLong(ddsx1.substring(0, 8), 16); + ssj.RKQQ = (int) Long.parseLong(ddsx1.substring(8, 12), 16); + ssj.RKGD = (int) Long.parseLong(ddsx1.substring(12, 16), 16); +// System.out.println(ssj.toString()); + } + rkss_update(ssj); + } + //1Â¥Èë³ö¿â¿Ú + for (int i = 1; i <= 1; i++) { + String address = "0", rkk_ssj_id = "0", name = "0"; + rkk_ssj_id = "oneRkk-1"; + address = "DB51.10"; + name = "1007"; + + RKK_SSJ ssj = (RKK_SSJ) hsSSJParam.get(rkk_ssj_id); + + ssj.CKKX = 0; + ssj.CKDW = 0; + ssj.RKQQ = 0; + ssj.taskNo = 0; + ssj.BJXX = 0; + ssj.RKGD = 0; + ssj.RKLX = 0; + ssj.JYM = 0; + ssj.trayCode = ""; + + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("30"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "000000000000000000000000000000000000000000000000000000000000"; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + ssj.CKKX = (int) Long.parseLong(ddsx1.substring(0, 4), 16); + ssj.CKDW = (int) Long.parseLong(ddsx1.substring(4, 8), 16); + ssj.RKQQ = (int) Long.parseLong(ddsx1.substring(8, 12), 16); + ssj.taskNo = Long.parseLong(ddsx1.substring(12, 20), 16); + ssj.BJXX = (int) Long.parseLong(ddsx1.substring(20, 24), 16); + ssj.RKGD = (int) Long.parseLong(ddsx1.substring(24, 28), 16); + ssj.RKLX = Long.parseLong(ddsx1.substring(28, 36), 16); + ssj.JYM = (int) Long.parseLong(ddsx1.substring(36, 40), 16); + byte[] trayCodez; + byte[] trayz; + String trayCode = ddsx1.substring(44, 60); + trayCodez = SoftBasic.HexStringToBytes(trayCode); + trayz = SoftBasic.HexStringToBytes(trayCode.substring(0, 2)); + String tra = Tools.bytetostringtool(trayz); + if (!"?".equals(tra) && !"".equals(tra)) { + ssj.trayCode = Tools.bytetostringtool(trayCodez); + } else { + ssj.trayCode = ""; + } + } + ssj.dName = name; + rkss_update(ssj); + } + //1Â¥Èë³ö¿â¿Ú + for (int i = 1; i <= 2; i++) { + + String address = "0", rkk_ssj_id = "0", name = "0"; + if (i == 1) { + rkk_ssj_id = "oneCkk-1"; + address = "DB51.52"; + name = "1028"; + } + if (i == 2) { + rkk_ssj_id = "oneCkk-2"; + address = "DB51.60"; + name = "1029"; + } + + RKK_SSJ ssj = (RKK_SSJ) hsSSJParam.get(rkk_ssj_id); + + ssj.BJXX = 0; + ssj.taskNo = 0; + ssj.CKDW = 0; + ssj.dName = name; + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("8"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "0000000000000000"; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + ssj.BJXX = (int) Long.parseLong(ddsx1.substring(0, 4), 16); + ssj.taskNo = Long.parseLong(ddsx1.substring(4, 12), 16); + ssj.CKDW = (int) Long.parseLong(ddsx1.substring(12, 16), 16); + } + rkss_update(ssj); + } + //Òì³£¿Ú + for (int i = 1; i <= 2; i++) { + String address = "0", rkk_ssj_id = "0", name = "0"; + int floor = 0; + if (i == 1) { + rkk_ssj_id = "YCRkk-1"; + address = "DB65.112"; + name = "2048"; + floor = 2; + } + if (i == 2) { + rkk_ssj_id = "YCRkk-2"; + address = "DB95.112"; + name = "3048"; + floor = 3; + } + + RKK_SSJ ssj = (RKK_SSJ) hsSSJParam.get(rkk_ssj_id); + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("14"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "0"; + ssj.taskNo = 0; + ssj.RKLX = 0; + ssj.QX = 0; + ssj.CKDW = 0; + ssj.YXXF = 0; + ssj.JYM = 0; + ssj.floor = floor; + ssj.dName = name; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + ssj.taskNo = Long.parseLong(ddsx1.substring(0, 8), 16); + ssj.RKLX = (int) Long.parseLong(ddsx1.substring(8, 12), 16); + ssj.QX = (int) Long.parseLong(ddsx1.substring(12, 16), 16); + ssj.CKDW = (int) Long.parseLong(ddsx1.substring(16, 20), 16); + ssj.YXXF = (int) Long.parseLong(ddsx1.substring(20, 24), 16); + ssj.JYM = (int) Long.parseLong(ddsx1.substring(24, 28), 16); + + } + rkss_update_yc(ssj); + } + //²øÄ¤»ú¡¢´¹Ö±´ò´ø»ú¡¢Ë®Æ½´ò´ø + for (int i = 1; i <= 6; i++) { + String address = "0", rkk_ssj_id = "0", name = "0"; + int floor = 0; + if (i == 1) { + rkk_ssj_id = "CMJ-1"; + address = "DB65.20"; + name = "CM001"; + floor = 2; + } + if (i == 2) { + rkk_ssj_id = "CMJ-2"; + address = "DB95.20"; + name = "CM002"; + floor = 3; + } + if (i == 3) { + rkk_ssj_id = "czdd-1"; + address = "DB65.40"; + name = "2036"; + floor = 2; + } + if (i == 4) { + rkk_ssj_id = "czdd-2"; + address = "DB95.40"; + name = "3036"; + floor = 3; + } + if (i == 5) { + rkk_ssj_id = "spdd-1"; + address = "DB65.0"; + name = "2045"; + floor = 2; + } + if (i == 6) { + rkk_ssj_id = "spdd-2"; + address = "DB95.0"; + name = "3045"; + floor = 3; + } + RKK_SSJ ssj = (RKK_SSJ) hsSSJParam.get(rkk_ssj_id); + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("12"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "0"; + ssj.taskNo = 0; + ssj.RKLX = 0; + ssj.QX = 0; + ssj.CKDW = 0; + ssj.JYM = 0; + ssj.floor = floor; + ssj.dName = name; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + ssj.taskNo = Long.parseLong(ddsx1.substring(0, 8), 16); + ssj.RKLX = (int) Long.parseLong(ddsx1.substring(8, 12), 16); + ssj.QX = (int) Long.parseLong(ddsx1.substring(12, 16), 16); + ssj.CKDW = (int) Long.parseLong(ddsx1.substring(16, 20), 16); + ssj.JYM = (int) Long.parseLong(ddsx1.substring(20, 24), 16); + + } + rkss_update_CM_DD(ssj); + } + //²ð¶â¿Ú + for (int i = 1; i <= 2; i++) { + String address = "0", rkk_ssj_id = "0", name = "0"; + int floor = 0; + if (i == 1) { + rkk_ssj_id = "CDJXS-1"; + address = "DB200.0"; + name = "2037"; + floor = 2; + + } + if (i == 2) { + rkk_ssj_id = "CDJXS-3"; + address = "DB200.100"; + name = "3037"; + floor = 3; + } + + RKK_SSJ ssj = (RKK_SSJ) hsSSJParam.get(rkk_ssj_id); + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("50"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "0"; + ssj.dName = name; + ssj.floor = floor; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + ssj.RKQQ = (int) Long.parseLong(ddsx1.substring(0, 4), 16); + ssj.RKGD = (int) Long.parseLong(ddsx1.substring(4, 8), 16); + ssj.BJXX = (int) Long.parseLong(ddsx1.substring(8, 12), 16); + ssj.RKSL = (int) Long.parseLong(ddsx1.substring(12, 16), 16); + ssj.CKDW = (int) Long.parseLong(ddsx1.substring(16, 20), 16); + ssj.taskNo = Long.parseLong(ddsx1.substring(20, 28), 16); + ssj.TPLX = (int) Long.parseLong(ddsx1.substring(28, 32), 16); + ssj.xf_taskNo = Long.parseLong(ddsx1.substring(64, 72), 16); + ssj.by1 = (int) Long.parseLong(ddsx1.substring(52, 56), 16); + + } + jxss_update(ssj); + } + //Âë¶â¿Ú + for (int i = 1; i <= 2; i++) { + String address = "0", rkk_ssj_id = "0", name = "0"; + int floor = 0; + if (i == 1) { + rkk_ssj_id = "MDJXS-2"; + address = "DB200.50"; + name = "2038"; + floor = 2; + } + if (i == 2) { + rkk_ssj_id = "MDJXS-4"; + address = "DB200.150"; + name = "3038"; + floor = 3; + } + + RKK_SSJ ssj = (RKK_SSJ) hsSSJParam.get(rkk_ssj_id); + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("26"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "0"; + ssj.dName = name; + ssj.RKQQ = 0; + ssj.RKGD = 0; + ssj.BJXX = 0; + ssj.RKSL = 0; + ssj.CKDW = 0; + ssj.floor = floor; + ssj.taskNo = 0; + ssj.trayCode = ""; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + ssj.RKQQ = (int) Long.parseLong(ddsx1.substring(0, 4), 16); + ssj.RKGD = (int) Long.parseLong(ddsx1.substring(4, 8), 16); + ssj.BJXX = (int) Long.parseLong(ddsx1.substring(8, 12), 16); + ssj.RKSL = (int) Long.parseLong(ddsx1.substring(12, 16), 16); + ssj.CKDW = (int) Long.parseLong(ddsx1.substring(16, 20), 16); + ssj.taskNo = Long.parseLong(ddsx1.substring(20, 28), 16); + ssj.TPLX = (int) Long.parseLong(ddsx1.substring(28, 32), 16); + byte[] trayCodez; + byte[] trayz; + String trayCode = ddsx1.substring(36, 52); + trayCodez = SoftBasic.HexStringToBytes(trayCode); + trayz = SoftBasic.HexStringToBytes(trayCode.substring(0, 2)); + String tra = Tools.bytetostringtool(trayz); + if (!"?".equals(tra) && !"".equals(tra)) { + ssj.trayCode = Tools.bytetostringtool(trayCodez); + } else { + ssj.trayCode = ""; + } + } + jxss_update(ssj); + } + //²ðÂëÅÌ»ú + for (int i = 1; i <= 4; i++) { + String address = "0", address1 = "0", rkk_ssj_id = "0", name = "0"; + if (i == 1) { + rkk_ssj_id = "cmp-1"; + address = "DB65.60"; + address1 = "DB65.138"; + name = "2Â¥ÂëÅÌMP001"; + } + if (i == 2) { + rkk_ssj_id = "cmp-2"; + address = "DB65.86"; + address1 = "DB65.160"; + name = "2Â¥²ðÅÌCP001"; + } + if (i == 3) { + rkk_ssj_id = "cmp-3"; + address = "DB95.60"; + address1 = "DB95.138"; + name = "3Â¥ÂëÅÌMP002"; + } + if (i == 4) { + rkk_ssj_id = "cmp-4"; + address = "DB95.86"; + address1 = "DB95.160"; + name = "3Â¥²ðÅÌCP002"; + } + + CMP_Device cmp = (CMP_Device) hsSSJParam.get(rkk_ssj_id); + cmp.SBZT = 0; + cmp.KPXH = 0; + cmp.MPXH = 0; + cmp.RWH = 0; + cmp.TPLX = 0; + cmp.YXXF = 0; + cmp.JYM = 0; + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("16"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + OperateResultExOne read2 = readWriteNet.Read(address1, Short.parseShort("8"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "0"; + String ddsx2 = "0"; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + cmp.SBZT = (int) Long.parseLong(ddsx1.substring(0, 4), 16); + cmp.KPXH = (int) Long.parseLong(ddsx1.substring(4, 8), 16); + cmp.MPXH = (int) Long.parseLong(ddsx1.substring(8, 12), 16); + cmp.RWH = Long.parseLong(ddsx1.substring(12, 20), 16); + cmp.TPLX = (int) Long.parseLong(ddsx1.substring(20, 24), 16); + cmp.YXXF = (int) Long.parseLong(ddsx1.substring(24, 28), 16); + cmp.JYM = (int) Long.parseLong(ddsx1.substring(28, 32), 16); + cmp.dName = name; + } + if (read2.IsSuccess) { + ddsx2 = SoftBasic.ByteToHexString(read2.Content); + if (i == 1 || i == 3) { + cmp.YPXH = (int) Long.parseLong(ddsx2.substring(0, 4), 16); + cmp.BY1 = (int) Long.parseLong(ddsx2.substring(8, 12), 16); + } else { + cmp.CPXH = (int) Long.parseLong(ddsx2.substring(0, 4), 16); + cmp.YPXH = (int) Long.parseLong(ddsx2.substring(4, 8), 16); + cmp.BY1 = (int) Long.parseLong(ddsx2.substring(12, 16), 16); + } + } + cmp_update(cmp); + } + //Ìù±ê»ú(ºÏ¸ñÖ¤) + for (int i = 1; i <= 8; i++) { + String address = "0", address_xf = "0", address_xf2 = "0", rkk_ssj_id = "0", name = "0"; + int floor = 0; + if (i == 1) { + rkk_ssj_id = "TBHGZ-1"; + address = "DB72.0"; + name = "2032"; + address_xf = "DB72.12"; + floor = 2; + } + if (i == 2) { + rkk_ssj_id = "TBHGZ-2"; + address = "DB102.0"; + name = "3032"; + address_xf = "DB102.12"; + floor = 3; + } + if (i == 3) { + rkk_ssj_id = "TBZBQ-1"; + address = "DB72.20"; + name = "2033"; + address_xf = "DB72.32"; + floor = 2; + } + if (i == 4) { + rkk_ssj_id = "TBZBQ-2"; + address = "DB102.20"; + name = "3033"; + address_xf = "DB102.32"; + floor = 3; + } + if (i == 5) { + rkk_ssj_id = "TBMBQ-1"; + address = "DB65.184"; + name = "2030"; + address_xf = "DB65.196"; + address_xf2 = "DB65.228"; + floor = 2; + } + if (i == 6) { + rkk_ssj_id = "TBMBQ-2"; + address = "DB95.184"; + name = "3030"; + address_xf = "DB95.196"; + address_xf2 = "DB95.228"; + floor = 3; + } + if (i == 7) { + rkk_ssj_id = "OCR-1"; + address = "DB72.40"; + name = "2034"; + address_xf = "DB72.52"; + floor = 2; + } + if (i == 8) { + rkk_ssj_id = "OCR-2"; + address = "DB102.40"; + name = "3034"; + address_xf = "DB102.52"; + floor = 3; + } + RKK_SSJ ssj = (RKK_SSJ) hsSSJParam.get(rkk_ssj_id); + ssj.CKDW = 0; + ssj.taskNo = 0; + ssj.RKLX = 0; + ssj.QX = 0; + ssj.JYM = 0; + ssj.address_xf = address_xf; + ssj.address_xf2 = address_xf2; + ssj.floor = floor; + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("12"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "0"; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + + ssj.taskNo = Long.parseLong(ddsx1.substring(0, 8), 16); + ssj.RKLX = (int) Long.parseLong(ddsx1.substring(8, 12), 16); + ssj.QX = (int) Long.parseLong(ddsx1.substring(12, 16), 16); + ssj.CKDW = (int) Long.parseLong(ddsx1.substring(16, 20), 16); + ssj.JYM = (int) Long.parseLong(ddsx1.substring(20, 24), 16); + ssj.dName = name; + } + rkss_update_CM_DD(ssj); + } + //³ÆÖØ + for (int i = 1; i <= 2; i++) { + String address = "0", address_xf = "0", address_xf2 = "0", rkk_ssj_id = "0", name = "0"; + int floor = 0; + if (i == 1) { + rkk_ssj_id = "CZ-1"; + address = "DB72.60"; + name = "2032"; + address_xf = "DB72.72"; + floor = 2; + } + if (i == 2) { + rkk_ssj_id = "CZ-2"; + address = "DB102.60"; + name = "3032"; + address_xf = "DB102.72"; + floor = 3; + } + + RKK_SSJ ssj = (RKK_SSJ) hsSSJParam.get(rkk_ssj_id); + ssj.CKDW = 0; + ssj.taskNo = 0; + ssj.RKLX = 0; + ssj.QX = 0; + ssj.JYM = 0; + ssj.address_xf = address_xf; + ssj.address_xf2 = address_xf2; + ssj.floor = floor; + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("12"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "0"; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + + ssj.taskNo = Long.parseLong(ddsx1.substring(0, 8), 16); + ssj.RKLX = (int) Long.parseLong(ddsx1.substring(8, 12), 16); + ssj.QX = (int) Long.parseLong(ddsx1.substring(12, 16), 16); + ssj.CKDW = (int) Long.parseLong(ddsx1.substring(16, 20), 16); + ssj.JYM = (int) Long.parseLong(ddsx1.substring(20, 24), 16); + ssj.dName = name; + } + rkss_update_CM_DD(ssj); + } + //ÏïµÀ¿ÚÊäËÍ»ú + for (int i = 1; i <= 18; i++) { + String address = "0", rkk_ssj_id = "0", name = "0"; + if (i == 1) { + rkk_ssj_id = "xdk-1"; + address = "DB103.0"; + name = "L1001"; + } + if (i == 2) { + rkk_ssj_id = "xdk-2"; + address = "DB103.10"; + name = "L1002"; + } + if (i == 3) { + rkk_ssj_id = "xdk-3"; + address = "DB103.20"; + name = "L1003"; + } + if (i == 4) { + rkk_ssj_id = "xdk-4"; + address = "DB103.30"; + name = "L1004"; + } + if (i == 5) { + rkk_ssj_id = "xdk-5"; + address = "DB103.40"; + name = "L1005"; + } + if (i == 6) { + rkk_ssj_id = "xdk-6"; + address = "DB103.50"; + name = "L1006"; + } + + if (i == 7) { + rkk_ssj_id = "xdk-7"; + address = "DB103.60"; + name = "L2001"; + } + if (i == 8) { + rkk_ssj_id = "xdk-8"; + address = "DB103.70"; + name = "L2002"; + } + if (i == 9) { + rkk_ssj_id = "xdk-9"; + address = "DB103.80"; + name = "L2003"; + } + if (i == 10) { + rkk_ssj_id = "xdk-10"; + address = "DB103.90"; + name = "L2004"; + } + if (i == 11) { + rkk_ssj_id = "xdk-11"; + address = "DB103.100"; + name = "L2005"; + } + if (i == 12) { + rkk_ssj_id = "xdk-12"; + address = "DB103.110"; + name = "L2006"; + } + + if (i == 13) { + rkk_ssj_id = "xdk-13"; + address = "DB103.120"; + name = "L3001"; + } + if (i == 14) { + rkk_ssj_id = "xdk-14"; + address = "DB103.130"; + name = "L3002"; + } + if (i == 15) { + rkk_ssj_id = "xdk-15"; + address = "DB103.140"; + name = "L3003"; + } + if (i == 16) { + rkk_ssj_id = "xdk-16"; + address = "DB103.150"; + name = "L3004"; + } + if (i == 17) { + rkk_ssj_id = "xdk-17"; + address = "DB103.160"; + name = "L3005"; + } + if (i == 18) { + rkk_ssj_id = "xdk-18"; + address = "DB103.170"; + name = "L3006"; + } + + XDK_SSJ ssj = (XDK_SSJ) hsSSJParam.get(rkk_ssj_id); + ssj.CKKX = 0; + ssj.RKDW = 0; + ssj.RWH = 0; + + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("10"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "0"; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + ssj.CKKX = (int) Long.parseLong(ddsx1.substring(0, 4), 16); + ssj.RKDW = (int) Long.parseLong(ddsx1.substring(4, 8), 16); + ssj.RWH = Long.parseLong(ddsx1.substring(8, 16), 16); + ssj.dName = name; + } + xdkss_update(ssj); + } + //¶þ¥˺Ĥ + for (int i = 1; i <= 2; i++) { + String address = "0",address_xf = "0", rkk_ssj_id = "0", name = "0"; + int floor = 0; + if (i == 1) { + rkk_ssj_id = "sm2-1"; + address = "DB65.206"; + address_xf = "DB65.214"; + name = "˺Ĥ1"; + floor = 2; + } + if (i == 2) { + rkk_ssj_id = "sm2-2"; + address = "DB65.210"; + address_xf = "DB65.216"; + name = "˺Ĥ2"; + floor = 3; + } + + RKK_SSJ ssj = (RKK_SSJ) hsSSJParam.get(rkk_ssj_id); + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("4"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "0"; + ssj.dName = name; + ssj.RKQQ = 0; + ssj.RKGD = 0; + ssj.BJXX = 0; + ssj.RKSL = 0; + ssj.CKDW = 0; + ssj.floor = floor; + ssj.taskNo = 0; + ssj.trayCode = ""; + ssj.address_xf = address_xf; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + ssj.taskNo = Long.parseLong(ddsx1.substring(0, 8), 16); + + } +// jxss_update(ssj); + } + //Èý¥˺Ĥ + for (int i = 1; i <= 2; i++) { + String address = "0",address_xf = "0", rkk_ssj_id = "0", name = "0"; + int floor = 0; + if (i == 1) { + rkk_ssj_id = "sm3-1"; + address = "DB95.206"; + address_xf = "DB95.214"; + name = "˺Ĥ1"; + floor = 2; + } + if (i == 2) { + rkk_ssj_id = "sm3-2"; + address = "DB95.210"; + address_xf = "DB95.216"; + name = "˺Ĥ2"; + floor = 3; + } + + RKK_SSJ ssj = (RKK_SSJ) hsSSJParam.get(rkk_ssj_id); + OperateResultExOne read1 = readWriteNet.Read(address, Short.parseShort("4"));//readWriteNet.Read(µØÖ·£¬ShortµÄ¶ÁÈ¡µØÖ·³¤¶È) + String ddsx1 = "0"; + ssj.dName = name; + ssj.RKQQ = 0; + ssj.RKGD = 0; + ssj.BJXX = 0; + ssj.RKSL = 0; + ssj.CKDW = 0; + ssj.floor = floor; + ssj.taskNo = 0; + ssj.trayCode = ""; + ssj.address_xf = address_xf; + if (read1.IsSuccess) { + ddsx1 = SoftBasic.ByteToHexString(read1.Content); + ssj.taskNo = Long.parseLong(ddsx1.substring(0, 8), 16); + + } +// jxss_update(ssj); + } + } else { + Logger.info("----------ÎÞÁ´½Ó----------Ïß³Ì--------¶ÁÈ¡PLCÐÅÏ¢-----------½áÊø---------------------"); + reConnect(); + } +// Logger.info("--------------------Ïß³Ì--------¶ÁÈ¡PLCÐÅÏ¢-----------½áÊø---------------------"); + Thread.sleep(800); + } catch (Exception ex) { + Logger.info("------catch--------------Ïß³Ì--------¶ÁÈ¡PLCÐÅÏ¢-----------½áÊø0--------------------"); + ex.printStackTrace(); + reConnect(); + } + } + closeServer(); + } + + ///ÊäËÍ»úÈÎÎñÏ·¢ + public static int WritetoSSJ(String address, byte[] tsak) { + int a = 0; + if (readWriteNet != null) { + a = HslRead.WriteResultRender(readWriteNet.Write(address, tsak), address); + } + return a; + } + + public void rkss_update(RKK_SSJ ssj) { + dao.updateSql("update MsgRkkSsj set rkqq =" + ssj.RKQQ + ",rkgd =" + ssj.RKGD + ",bjxx =" + ssj.BJXX + + ",tmfk= '" + ssj.trayCode + "',ckdw = " + ssj.CKDW + ",ckkx = " + ssj.CKKX + ",rwh = '" + ssj.taskNo + + "',quantity = " + ssj.RKSL + " where name = '" + ssj.dName + "'"); + } + public void rkss_update_yc(RKK_SSJ ssj) { + dao.updateSql("update MsgRkkSsj set rkqq ='" + ssj.YXXF + "',ckdw = " + ssj.CKDW + ",rwh = '" + ssj.taskNo + + "',quantity = " + ssj.QX + " where name = '" + ssj.dName + "'"); + } + public void rkss_update_CM_DD(RKK_SSJ ssj) { + dao.updateSql("update MsgRkkSsj set rkqq ='" + ssj.RKQQ + "',ckdw = " + ssj.CKDW + ",ckkx = " + ssj.CKKX + ",rwh = '" + ssj.taskNo + + "',quantity = " + ssj.QX + " where name = '" + ssj.dName + "'"); + } + public void xdkss_update(XDK_SSJ ssj) { + dao.updateSql("update MsgXdkSsj set rkdw = " + ssj.RKDW + ",ckkx = '" + ssj.CKKX + "',rwh = " + ssj.RWH + " where name = '" + ssj.dName + "'"); + } + + public void jxss_update(RKK_SSJ ssj) { + dao.updateSql("update MsgJxs set rkgd =" + ssj.RKGD + ",sbzt =" + ssj.BJXX + + ",tray_code= '" + ssj.trayCode + "',ckdw = " + ssj.CKDW + ",tplx = " + ssj.TPLX + ",rwh = '" + ssj.taskNo + + "',rkqq = " + ssj.RKQQ + ",rksl = " + ssj.RKSL + " where id = '" + ssj.btId + "'"); + } + + public void cmp_update(CMP_Device cmp) { + dao.updateSql("update MsgCmp set sbzt =" + cmp.SBZT + ",kpxh =" + cmp.KPXH +",czfs =" + cmp.YXXF + + ",mpxh= '" + cmp.MPXH + "',rwh = " + cmp.RWH + ",tplx = " + cmp.TPLX + ",cz = '" + cmp.BY1 + + "',cpxh = " + cmp.CPXH + ",ypxh = " + cmp.YPXH + " where id = '" + cmp.btId + "'"); + } + +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/plc/PLCCorrespondService.java b/src/com/wms/dss/ats/customs/abb/plc/PLCCorrespondService.java new file mode 100644 index 0000000..fbd4719 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/plc/PLCCorrespondService.java @@ -0,0 +1,45 @@ +package com.wms.dss.ats.customs.abb.plc; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.common.server.schedule.ThreadSchedule; + +import java.util.HashMap; +import java.util.Hashtable; + + +/** + * ÃèÊö: É豸ͨÐÅ·þÎñ + * + * @author zhu 2020-3-20 + * @since WCS 3.0 + */ +public class PLCCorrespondService extends ThreadSchedule { + + + @Override + public void stopAll(boolean bVal) { + //¹Ø±Õ + m_hsSysParam.put("bStopFlag", "true"); + } + + @Override + public void threadExec() { + // Ö´ÐÐÉ豸ͨÐÅÏß³Ì + startcomm(m_hsSysParam); + } + + public static void initDevice(HashMap hsDDJMap) { // + + } + + public void startcomm(Hashtable m_hsSysParam) { + m_hsSysParam.put("bStopFlag", "false"); + EntityDAO m_dao = (EntityDAO) m_hsSysParam.get("dao"); + + ReadPLCSSJ.read(m_hsSysParam,m_dao); + ReadPLCDDJ1.read(m_hsSysParam,m_dao); + ReadPLCDDJ2.read(m_hsSysParam,m_dao); + ReadPLCDDJ3.read(m_hsSysParam,m_dao); + Readdd_PLC.read(m_hsSysParam,m_dao); + } +} diff --git a/src/com/wms/dss/ats/customs/abb/plc/ReadPLCDDJ1.java b/src/com/wms/dss/ats/customs/abb/plc/ReadPLCDDJ1.java new file mode 100644 index 0000000..c1a9cfe --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/plc/ReadPLCDDJ1.java @@ -0,0 +1,36 @@ +package com.wms.dss.ats.customs.abb.plc; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.entity.DDJ_Device; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Hashtable; + +public class ReadPLCDDJ1 { + + public static void read(Hashtable m_hsSysParam,EntityDAO m_dao) { + Hashtable hsComParam = new Hashtable(); + + HashMap hsDDJMap1 = new HashMap(); + Hashtable hsDDJMap = new Hashtable(); + String strIp = "192.168.56.11";///plc¶ÔÓ¦ipµØÖ· + String strPort = "102"; + String strSLot = "1"; + hsComParam.put("strIpddj", strIp); + hsComParam.put("iPortddj", Integer.parseInt(strPort)); + hsComParam.put("slotddj", Integer.parseInt(strSLot)); + + DDJ_Device ddj = new DDJ_Device((byte)1, "ddj"); + hsDDJMap1.put(ddj.dtype + "-" + ddj.btId, ddj); + + hsComParam.put("hsddjMap1", hsDDJMap1); + m_hsSysParam.put( "hsComParamDDJ1", hsComParam); + + + // PLCͨѶ¿Í»§¶Ë + IsoTcpClientDDJ1 tp = new IsoTcpClientDDJ1(hsComParam, m_hsSysParam,m_dao); + tp.start(); + + } +} diff --git a/src/com/wms/dss/ats/customs/abb/plc/ReadPLCDDJ2.java b/src/com/wms/dss/ats/customs/abb/plc/ReadPLCDDJ2.java new file mode 100644 index 0000000..8bb4f54 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/plc/ReadPLCDDJ2.java @@ -0,0 +1,37 @@ +package com.wms.dss.ats.customs.abb.plc; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.entity.DDJ_Device; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Hashtable; + +public class ReadPLCDDJ2 { + + public static void read(Hashtable m_hsSysParam,EntityDAO m_dao) { + Hashtable hsComParam = new Hashtable(); + + HashMap hsDDJMap2 = new HashMap(); + Hashtable hsDDJMap = new Hashtable(); + String strIp = "192.168.56.21";///plc¶ÔÓ¦ipµØÖ· + String strPort = "102"; + String strSLot = "1"; + hsComParam.put("strIpddj", strIp); + hsComParam.put("iPortddj", Integer.parseInt(strPort)); + hsComParam.put("slotddj", Integer.parseInt(strSLot)); + + DDJ_Device ddj = new DDJ_Device((byte)2, "ddj"); +// hsDDJMap.put(ddj.dtype + "-" + ddj.btId, ddj); + hsDDJMap2.put(ddj.dtype + "-" + ddj.btId, ddj); + +// hsComParam.put("hsddjMap", hsDDJMap); + hsComParam.put("hsddjMap2", hsDDJMap2); + m_hsSysParam.put( "hsComParamDDJ2", hsComParam); + + // PLCͨѶ¿Í»§¶Ë + IsoTcpClientDDJ2 tp = new IsoTcpClientDDJ2(hsComParam, m_hsSysParam,m_dao); + tp.start(); + + } +} diff --git a/src/com/wms/dss/ats/customs/abb/plc/ReadPLCDDJ3.java b/src/com/wms/dss/ats/customs/abb/plc/ReadPLCDDJ3.java new file mode 100644 index 0000000..06b18d4 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/plc/ReadPLCDDJ3.java @@ -0,0 +1,37 @@ +package com.wms.dss.ats.customs.abb.plc; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.entity.DDJ_Device; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Hashtable; + +public class ReadPLCDDJ3 { + + public static void read(Hashtable m_hsSysParam,EntityDAO m_dao) { + Hashtable hsComParam = new Hashtable(); + + HashMap hsDDJMap3 = new HashMap(); + Hashtable hsDDJMap = new Hashtable(); + String strIp = "192.168.56.31";///plc¶ÔÓ¦ipµØÖ· + String strPort = "102"; + String strSLot = "1"; + hsComParam.put("strIpddj", strIp); + hsComParam.put("iPortddj", Integer.parseInt(strPort)); + hsComParam.put("slotddj", Integer.parseInt(strSLot)); + + DDJ_Device ddj = new DDJ_Device((byte)3, "ddj"); +// hsDDJMap.put(ddj.dtype + "-" + ddj.btId, ddj); + hsDDJMap3.put(ddj.dtype + "-" + ddj.btId, ddj); + +// hsComParam.put("hsddjMap", hsDDJMap); + hsComParam.put("hsddjMap3", hsDDJMap3); + m_hsSysParam.put( "hsComParamDDJ3", hsComParam); + + // PLCͨѶ¿Í»§¶Ë + IsoTcpClientDDJ3 tp = new IsoTcpClientDDJ3(hsComParam, m_hsSysParam,m_dao); + tp.start(); + + } +} diff --git a/src/com/wms/dss/ats/customs/abb/plc/ReadPLCSSJ.java b/src/com/wms/dss/ats/customs/abb/plc/ReadPLCSSJ.java new file mode 100644 index 0000000..3835583 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/plc/ReadPLCSSJ.java @@ -0,0 +1,152 @@ +package com.wms.dss.ats.customs.abb.plc; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.entity.*; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; + +public class ReadPLCSSJ { + + public static void read(Hashtable m_hsSysParam,EntityDAO m_dao) { + Hashtable hsComParam = new Hashtable(); + + HashMap hsssjMap = new HashMap(); + + String strIp = "192.168.56.41";///plc¶ÔÓ¦ipµØÖ· + String strPort = "102"; + String strSLot = "1"; + hsComParam.put("strIpddj", strIp); + hsComParam.put("iPortddj", Integer.parseInt(strPort)); + hsComParam.put("slotddj", Integer.parseInt(strSLot)); + + /** + * 1Â¥Èë³ö¿â¿Ú + */ + for (int i = 1; i <= 1; i++) { + RKK_SSJ rkk_ssj = new RKK_SSJ((byte) i, "qqtm"); + hsssjMap.put(rkk_ssj.dtype + "-" + rkk_ssj.btId, rkk_ssj); + } + for (int i = 1; i <= 1; i++) { + RKK_SSJ rkk_ssj = new RKK_SSJ((byte) i, "oneRkk"); + hsssjMap.put(rkk_ssj.dtype + "-" + rkk_ssj.btId, rkk_ssj); + } + for (int i = 1; i <= 2; i++) { + RKK_SSJ rkk_ssj = new RKK_SSJ((byte) i, "oneCkk"); + hsssjMap.put(rkk_ssj.dtype + "-" + rkk_ssj.btId, rkk_ssj); + } + /** + * Òì³£Èë¿â¿Ú + */ + for (int i = 1; i <= 2; i++) { + RKK_SSJ rkk_ssj = new RKK_SSJ((byte) i, "YCRkk"); + hsssjMap.put(rkk_ssj.dtype + "-" + rkk_ssj.btId, rkk_ssj); + } + /** + * ²øÄ¤»ú½»»¥ + */ + for (int i = 1; i <= 2; i++) { + RKK_SSJ rkk_ssj = new RKK_SSJ((byte) i, "CMJ"); + hsssjMap.put(rkk_ssj.dtype + "-" + rkk_ssj.btId, rkk_ssj); + } + /** + * ´¹Ö±´ò´ø + */ + for (int i = 1; i <= 2; i++) { + RKK_SSJ rkk_ssj = new RKK_SSJ((byte) i, "czdd"); + hsssjMap.put(rkk_ssj.dtype + "-" + rkk_ssj.btId, rkk_ssj); + } + /** + * ˮƽ´ò´ø + */ + for (int i = 1; i <= 2; i++) { + RKK_SSJ rkk_ssj = new RKK_SSJ((byte) i, "spdd"); + hsssjMap.put(rkk_ssj.dtype + "-" + rkk_ssj.btId, rkk_ssj); + } + /** + * ²ð¶â¿Ú + */ + for (int i = 1; i <= 2; i++) { + RKK_SSJ rkk_ssj = new RKK_SSJ((byte) (2*i-1), "CDJXS"); + hsssjMap.put(rkk_ssj.dtype + "-" + rkk_ssj.btId, rkk_ssj); + } + /** + * Âë¶â¿Ú + */ + for (int i = 1; i <= 2; i++) { + RKK_SSJ rkk_ssj = new RKK_SSJ((byte) (2*i), "MDJXS"); + hsssjMap.put(rkk_ssj.dtype + "-" + rkk_ssj.btId, rkk_ssj); + } + + /** + * ²ðÂëÅÌ»ú + */ + for (int i = 1; i <= 4; i++) { + CMP_Device cmp = new CMP_Device((byte) i, "cmp"); + hsssjMap.put(cmp.dtype + "-" +cmp.btId, cmp); + } + + /** + * Ìù±ê»ú(ºÏ¸ñÖ¤) + */ + for (int i = 1; i <= 2; i++) { + RKK_SSJ ssj = new RKK_SSJ((byte) i, "TBHGZ"); + hsssjMap.put(ssj.dtype + "-" + ssj.btId, ssj); + } + /** + * Ìù±ê»ú(×Ó±êÇ©) + */ + for (int i = 1; i <= 2; i++) { + RKK_SSJ ssj = new RKK_SSJ((byte) i, "TBZBQ"); + hsssjMap.put(ssj.dtype + "-" + ssj.btId, ssj); + } + for (int i = 1; i <= 2; i++) { + RKK_SSJ ssj = new RKK_SSJ((byte) i, "CZ"); + hsssjMap.put(ssj.dtype + "-" + ssj.btId, ssj); + } + /** + * Ìù±ê»ú(ĸ±êÇ©) + */ + for (int i = 1; i <= 2; i++) { + RKK_SSJ ssj = new RKK_SSJ((byte) i, "TBMBQ"); + hsssjMap.put(ssj.dtype + "-" + ssj.btId, ssj); + } + /** + * ocr + */ + for (int i = 1; i <= 2; i++) { + RKK_SSJ ssj = new RKK_SSJ((byte) i, "OCR"); + hsssjMap.put(ssj.dtype + "-" + ssj.btId, ssj); + } + /** + * ¶Ñ¶â»úÏïµÀ¿ÚÊäËÍ»ú + */ + for (int i = 1; i <= 18; i++) { + XDK_SSJ xdk_ssj = new XDK_SSJ((byte) i, "xdk"); + hsssjMap.put(xdk_ssj.dtype + "-" + xdk_ssj.btId, xdk_ssj); + } + /** + * ˺Ĥ¹¤Î»Ï·¢ + */ + for (int i = 1; i <= 2; i++) { + RKK_SSJ rkk_ssj = new RKK_SSJ((byte) i, "sm2"); + hsssjMap.put(rkk_ssj.dtype + "-" + rkk_ssj.btId, rkk_ssj); + } + + for (int i = 1; i <= 2; i++) { + RKK_SSJ rkk_ssj = new RKK_SSJ((byte) i, "sm3"); + hsssjMap.put(rkk_ssj.dtype + "-" + rkk_ssj.btId, rkk_ssj); + } + hsComParam.put("hsssjMap", hsssjMap); + m_hsSysParam.put( "hsComParamSSJ", hsComParam); + + // PLCͨѶ¿Í»§¶Ë + IsoTcpClientSSJ tp = new IsoTcpClientSSJ(hsComParam, m_hsSysParam,m_dao); + tp.setName("ÊäËÍ»ú-PLC-¶ÁÈ¡"); + tp.start(); + + } +} diff --git a/src/com/wms/dss/ats/customs/abb/plc/Readdd_PLC.java b/src/com/wms/dss/ats/customs/abb/plc/Readdd_PLC.java new file mode 100644 index 0000000..db70c5b --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/plc/Readdd_PLC.java @@ -0,0 +1,23 @@ +package com.wms.dss.ats.customs.abb.plc; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.schedule.DDJService; + +import java.util.Hashtable; + +public class Readdd_PLC { + + public static void read(Hashtable m_hsSysParam, EntityDAO dao) { + + + DDJService DDJService1 = new DDJService(DDJService.DDJ_IP_ADDRESS_1, 502,dao); + DDJService1.ddjDevice.btId = 1; + DDJService DDJService2 = new DDJService(DDJService.DDJ_IP_ADDRESS_2, 502,dao); + DDJService2.ddjDevice.btId = 2; + + m_hsSysParam.put("ddj1", DDJService1); + m_hsSysParam.put("ddj2", DDJService2); + + + } +} diff --git a/src/com/wms/dss/ats/customs/abb/plc/备注.txt b/src/com/wms/dss/ats/customs/abb/plc/备注.txt new file mode 100644 index 0000000..fa6f9a1 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/plc/备注.txt @@ -0,0 +1 @@ +ÓëPLCͨÐÅ,¶ÁÈ¡PLC±äÁ¿,±£´æÔÚÊý¾Ý¿âÖÐ \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/schedule/ABBThreadSchedule.java b/src/com/wms/dss/ats/customs/abb/schedule/ABBThreadSchedule.java new file mode 100644 index 0000000..2e3b007 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/schedule/ABBThreadSchedule.java @@ -0,0 +1,68 @@ +package com.wms.dss.ats.customs.abb.schedule; + +import com.ricosoft.common.logger.Logger; +import com.wms.dss.common.server.schedule.ThreadSchedule; + +/** + * ÃèÊö: µ÷¶È×ÜÏß³Ì + * + * @since WMS 3.1 ZGWµÚÒ»´ÎÌá½» + */ +public class ABBThreadSchedule extends ThreadSchedule { + + protected DDJ1Thread ddjThread1 = null; + protected DDJ2Thread ddjThread2 = null; + protected DDJ3Thread ddjThread3 = null; + protected SSJ_CMP_Thread ssjThread = null; + protected SSJ_ONE_Thread ssj_frist_thread = null; + protected SSJ_JXS_Thread ssj_jxs_thread = null; + protected ThreadCK_SSJ_LED led_ssjThread = null; + public void stopAll(boolean bVal) { + m_hsSysParam.put("bDStopFlag", "true"); + //crane1.setStop(bVal); + } + + @Override + public void threadExec() { + m_hsSysParam.put("bDStopFlag", "false"); + try { + //¶Ñ¶â»ú + ddjThread1 = new DDJ1Thread( m_hsSysParam); + ddjThread1.setName("¶Ñ¶â»ú¡ª1¡ªÏß³Ì"); + ddjThread1.start();//¶Ñ¶â»úµ÷¶È + Thread.sleep(400); + //¶Ñ¶â»ú + ddjThread2 = new DDJ2Thread( m_hsSysParam); + ddjThread2.setName("¶Ñ¶â»ú¡ª2¡ªÏß³Ì"); + ddjThread2.start();//¶Ñ¶â»úµ÷¶È + Thread.sleep(400); + //¶Ñ¶â»ú + ddjThread3 = new DDJ3Thread( m_hsSysParam); + ddjThread3.setName("¶Ñ¶â»ú¡ª3¡ªÏß³Ì"); + ddjThread3.start();//¶Ñ¶â»úµ÷¶È + Thread.sleep(400); + //²ðÂëÅÌ + ssjThread = new SSJ_CMP_Thread( m_hsSysParam); + ssjThread.setName("²ðÂëÅÌ¡ªÒì³£¿Ú¡ªÏß³Ì"); + ssjThread.start(); + Thread.sleep(400); + //ÊäËÍ»ú + ssj_jxs_thread = new SSJ_JXS_Thread( m_hsSysParam); + ssj_jxs_thread.setName("»úеÊÖ¡ªÏß³Ì"); + ssj_jxs_thread.start(); + Thread.sleep(400); + //ÊäËÍ»ú + ssj_frist_thread = new SSJ_ONE_Thread( m_hsSysParam); + ssj_frist_thread.setName("һ¥¡ª¡ªÊäËÍ»úÏß³Ì"); + ssj_frist_thread.start(); + Thread.sleep(400); + //LED + led_ssjThread = new ThreadCK_SSJ_LED( m_hsSysParam); + led_ssjThread.setName("LED¡ªÏß³Ì"); + led_ssjThread.start();// + Thread.sleep(400); + } catch (Exception er) { + Logger.error("........É豸µ÷¶ÈÏß³ÌÆô¶¯³ö´í........" + er.getMessage()); + } + } +} diff --git a/src/com/wms/dss/ats/customs/abb/schedule/DDJ1Thread.java b/src/com/wms/dss/ats/customs/abb/schedule/DDJ1Thread.java new file mode 100644 index 0000000..a0aace9 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/schedule/DDJ1Thread.java @@ -0,0 +1,434 @@ +package com.wms.dss.ats.customs.abb.schedule; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.entity.*; +import com.wms.dss.ats.customs.abb.plc.*; +import com.wms.dss.ats.customs.abb.utils.QueryDbDataUtils; +import com.wms.dss.ats.customs.abb.utils.Tools; +import com.wms.dss.common.server.config.WMSDDSConfig; +import com.wms.dss.common.server.form.Logger; +import com.wms.dss.common.server.schedule.CraneThread; + +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.SQLOutput; +import java.text.SimpleDateFormat; +import java.util.*; + +/* + *@Version 1.0 + * ¶Ñ¶â»úÏß³Ì + **/ +public class DDJ1Thread extends CraneThread { + + protected byte btid = 0; + String strConfigPath = ""; + Hashtable hsComParamDDJ1 = null; + Hashtable hsComParamSSJ = null; + + + @Override + public void setStop(boolean b) { + m_bStop = b; + } + + public DDJ1Thread(Hashtable hsSysParam) { + super(hsSysParam); + m_bStop = false; + m_hsSysParam = hsSysParam; + m_dao = (EntityDAO) hsSysParam.get("dao"); + hsComParamDDJ1 = (Hashtable) m_hsSysParam.get("hsComParamDDJ1"); + hsComParamSSJ = (Hashtable) m_hsSysParam.get("hsComParamSSJ"); + strConfigPath = ((WMSDDSConfig) hsSysParam.get("config")).getConfigPath(); + } + + @Override + public void run() { + while (!m_bStop) { + try { +// Logger.info("=======================¶Ñ¶â»úÏß³Ì1Æô¶¯==========================="); + //»ñÈ¡DB¿éÖеÄÐÅÏ¢ + DbGet.hsComParamDDJ1 = hsComParamDDJ1; + DbGet.hsComParamSSJ = hsComParamSSJ; + + int ddjh = 0; //¶Ñ¶â»úºÅ + try { ///¶Ñ¶â»úµ÷¶È + List ddj = DbGet.getDDJ_Device1(); + if (ddj != null && ddj.size() > 0) { + for (int i = 0; i < ddj.size(); i++) { + //¶Ñ¶â»úÑ­»· + ddjh = ddj.get(i).btId; + DDJ_Device ddj_c = ddj.get(i); + ddj_dd(ddj_c, ddjh); + } + } + } catch (Exception ex) { + //conn.close(); + Logger.info("¶Ñ¶â»úÏß³Ì×é1µ÷¶ÈÖ´ÐÐÒì³£" + ddjh + ex.getMessage()); + }///¶Ñ¶â»úµ÷¶È + } catch (Exception e) { + Logger.info("==========¶Ñ¶â»úÏß³Ì×é1Òì³£,Òì³£ÐÅÏ¢¡¾" + e.getMessage() + "¡¿========"); + e.printStackTrace(); + } finally { +// Logger.info("=======================¶Ñ¶â»úÏß³Ì×é1ÐÝÃß==========================="); + try { + sleep(2500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + } + + //¶Ñ¶â»úµ÷¶È + private void ddj_dd(DDJ_Device ddj_c, int i) throws SQLException { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { + int ddjh = i; + + /** + * µÚÒ»²¿·Ö + * ¶Ñ¶â»úÏ߳̽øÀ´ºóµÚÒ»¼þÊÂÏȽøÐжѶâ»úÕýÖ´ÐÐÈÎÎñµÄÕËÎñ´¦Àí + * ÒÔ·À´æÔÚ©´¦Àí£¬Ã»´¦ÀíµÄÇé¿ö·¢Éú + */ + if (ddj_c.CZFS == 5 && ddj_c.ZXJD == 5) { /// + WmsDeviceExecutionQueue queue = QueryDbDataUtils.ddj_zxdl(m_dao, ddj_c.ZXRWH,5); + if (queue != null) { + imp_complete(String.valueOf(ddj_c.ZXRWH)); + } + } + + /** + * µÚ¶þ²¿·Ö + * ¸ú×Ù×÷ÒµÖ´Ðн׶Π+ */ + if (ddj_c.CZFS == 5 && (ddj_c.ZXJD == 2 || ddj_c.ZXJD == 3 || ddj_c.ZXJD == 4)) { + WmsDeviceExecutionQueue queue = QueryDbDataUtils.ddj_zxdl(m_dao, ddj_c.ZXRWH,5); + if(queue != null){ + MydoJob job = QueryDbDataUtils.findMydoJobByTaskNo(m_dao,ddj_c.ZXRWH); + if(job != null){ + m_dao.updateSql("update MydoJob set execution_phase=7 where task_no='"+ddj_c.ZXRWH+"'"); + } + } + } + /** + * µÚÈý²¿·Ö + * ¶Ñ¶â»ú·Å»õÄ¿±êÓлõ + * ´¦Àí·½Ê½£ºÖØÐ·ÖÅ䴢λ + */ + if (ddj_c.CZFS == 5 && (ddj_c.SBZT == 1052) && ddj_c.ZXJD < 5) { + ///·Å»õÄ¿±êÓлõ ÖØÐ·ÖÅ䴢λ + WmsDeviceExecutionQueue sbzxdl222 = QueryDbDataUtils.ddj_zxdl(m_dao, ddj_c.ZXRWH,5); + MydoJob mydoJob =QueryDbDataUtils.getSlotJobByTask(m_dao,ddj_c.ZXRWH); + if (sbzxdl222 != null) { + find_space_again(m_dao, sbzxdl222.getRwh()); + } + if (sbzxdl222 == null) { + System.out.println("ÈÎÎñºÅ" + ddj_c.ZXRWH + "-----------¶Ñ¶â»úÒѾ­´¢Î»ÖØ·Ö-------"); + } + } + + /** + * µÚËIJ¿·Ö + * Ö´Ðгö¿â×÷ҵʱȡ»õÔ´ÎÞ»õ + * ´¦Àí·½Ê½£ºÔÚ¸ÃÏïµÀÔÚѰÕÒͬÀà»õÎï½øÐгö¿â + */ +// if (ddj_c.CZFS == 5 && ddj_c.SBZT == 1047 && ddj_c.ZXJD < 5) { +// WmsDeviceExecutionQueue sbzxdl222 = QueryDbDataUtils.ddj_zxdl(m_dao, ddj_c.ZXRWH); +// if (sbzxdl222 != null) { +//// ddj_ywh(sbzxdl222, (int) ddj_c.ZXRWH); +// } +// if (sbzxdl222 == null) { +// System.out.println("ÈÎÎñºÅ" + ddj_c.ZXRWH + "-----------¶Ñ¶â»úÈ¡»õÔ´ÎÞ»õ-------"); +// } +// } + + /** + * µÚÎ岿·Ö + * Éú³É¶Ñ¶â»úÖ´ÐжÓÁÐ + */ + List ssjList = DbGet.getSSJ_roadway3(); + if(ssjList != null && ssjList.size() > 0){ + for(int j = 0; j < ssjList.size(); j++){ + XDK_SSJ ssj = ssjList.get(j); + int rwlx = 0; + int floor = 0; + if(ssj.btId == 6 || ssj.btId == 12 || ssj.btId == 18){ + if(ssj.btId == 6){ + rwlx = 1; + floor = 1; + } + if(ssj.btId == 12){ + rwlx = 3; + floor = 2; + } + if(ssj.btId == 18){ + rwlx = 5; + floor = 3; + } + if(ssj.RKDW == 1 && ssj.RWH > 0){ + WmsDeviceExecutionQueue queue = QueryDbDataUtils.getQueueByRoadAndRwlx(m_dao,ddjh,rwlx); + MydoJob inJob1 = QueryDbDataUtils.getInJobByRoadwayAndCargo(m_dao,ddjh,ssj.RWH); + if(queue == null && inJob1 != null && "1".equals(inJob1.getCount_id())){ + createDDJQueue(m_dao,ddjh,ssj.btId,0,ssj.RKDW,ssj.RWH,rwlx); + } + MydoJob inJob = QueryDbDataUtils.getInJobByRoadwayAndTask(m_dao,ddjh,ssj.RWH); + if(inJob != null && "1".equals(inJob.getCount_id())){ + allot_space(m_dao,ssj.RWH); + } + MydoJob outJob = QueryDbDataUtils.getOUTJobByRoadwayAndTask(m_dao,ddjh,ssj.RWH); + WmsDeviceExecutionQueue queueOut = QueryDbDataUtils.getQueueByRoadAndRwlx1(m_dao,ddjh,2); + if(outJob != null && "1".equals(outJob.getCount_id()) && queueOut == null){ + XDK_SSJ ssj_one_out = DbGet.getSSJ_one_out(5); + //TODO ±¸»õÖ±½Ó³ö¿â +// if(ssj_one_out.CKKX == 1) { + createDDJQueue1(m_dao, ddjh, ssj.btId, ssj_one_out.btId, ssj.RWH, 2); +// } + } + } + + } + if(ssj.btId == 5 || ssj.btId == 11 || ssj.btId == 17){ + if(ssj.btId == 5){ + rwlx = 2; + floor = 1; + } + if(ssj.btId == 11){ + rwlx = 4; + floor = 2; + } + if(ssj.btId == 17){ + rwlx = 6; + floor = 3; + } + WmsDeviceExecutionQueue queue = QueryDbDataUtils.getQueueByRoadAndRwlx(m_dao,ddjh,rwlx); + List outList = QueryDbDataUtils.getOutJobByRoad(m_dao,ddjh,floor); + if(ssj.CKKX == 1 && ssj.RWH == 0 && queue == null && outList.size() > 0){ + createDDJQueue(m_dao,ddjh,ssj.btId,ssj.CKKX,0,ssj.RWH ,rwlx); + } + } + } + } + + /** + * µÚÁù²¿·Ö + * ¸ø¶Ñ¶â»úÏ·¢ÈÎÎñ + */ + //·Å»õÄ¿±êÓлõÖØÐÂÏ·¢ + if (ddj_c.YXXF == 1 && ddj_c.CZFS == 5 && ddj_c.SBZT == 1052){ + WmsDeviceExecutionQueue queueFinish = QueryDbDataUtils.getQueueByRoadAndXf(m_dao, ddjh, 1); + WmsDeviceExecutionQueue queueBegin = QueryDbDataUtils.getQueueByTask(m_dao, ddjh, ddj_c.ZXRWH); + if (queueFinish == null && queueBegin != null){ + int isSend = issuedDDJTask(ddjh, queueBegin); + if (isSend == 1){ + String nowTime = sdf.format(new Date()); + m_dao.updateSql("update WmsDeviceExecutionQueue set rwzt = 2, ddjxf = '1', xfsj = '" + nowTime + "' where rwh = " + queueBegin.getRwh()); + Logger.info("Ïò" + ddjh + "ºÅ¶Ñ¶â»úÖØÐÂÏ·¢ÈÎÎñ³É¹¦£¡ÈÎÎñºÅΪ£º" + queueBegin.getRwh()); + } + } + } + //Õý³£Ï·¢ + if (ddj_c.YXXF == 1 && ddj_c.CZFS == 5 && ddj_c.SBZT == 0){ + WmsDeviceExecutionQueue queueFinish = QueryDbDataUtils.getQueueByRoadAndXf(m_dao, ddjh, 1); + List queueList = QueryDbDataUtils.getQueueByRoad(m_dao,ddjh); + WmsDeviceExecutionQueue queueBegin = QueryDbDataUtils.getQueueByTask(m_dao, ddjh, ddj_c.ZXRWH); + if (queueFinish == null && queueBegin != null){ + int isSend = issuedDDJTask(ddjh, queueBegin); + if (isSend == 1){ + String nowTime = sdf.format(new Date()); + m_dao.updateSql("update WmsDeviceExecutionQueue set rwzt = 2, ddjxf = '1', xfsj = '" + nowTime + "' where rwh = " + queueBegin.getRwh()); + Logger.info("Ïò" + ddjh + "ºÅ¶Ñ¶â»úÖØÐÂÏ·¢ÈÎÎñ³É¹¦£¡ÈÎÎñºÅΪ£º" + queueBegin.getRwh()); + } + }else { + if (queueFinish == null && queueList.size() > 0) { + int isSend = issuedDDJTask(ddjh, queueList.get(0)); + if (isSend == 1) { + String nowTime = sdf.format(new Date()); + m_dao.updateSql("update WmsDeviceExecutionQueue set rwzt = 2, ddjxf = '1', xfsj = '" + nowTime + "' where rwh = " + queueList.get(0).getRwh()); + Logger.info("Ïò" + ddjh + "ºÅ¶Ñ¶â»úÏ·¢ÈÎÎñ³É¹¦£¡ÈÎÎñºÅΪ£º" + queueList.get(0).getRwh()); + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + Logger.error("¶Ñ¶â»úÏß³Ì×é1µ÷¶ÈÖ´ÐÐʧ°Ü£¡£¡£¡£¡£¡£¡£¡"); + } + } + + private void allot_space(EntityDAO m_dao, long rwh) { + StoredParameters taskParameter = new StoredParameters(1, String.valueOf(rwh)); + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_slot_space(?,?)}", 2, taskParameter); + switch (back) { + case 10: + Logger.info("proc_slot_space Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + rwh); + break; + case 1: + Logger.info("proc_slot_space ³ö¿âÈÎÎñ²»ÐèÒªÖØ·Ö£¬ÈÎÎñºÅ£º" + rwh); + break; + case 2: + Logger.info("proc_slot_space ÕÒ²»µ½Ö´ÐжÓÁУ¬ÈÎÎñºÅ£º" + rwh); + break; + case 3: + Logger.info("proc_slot_space ÕÒ²»µ½»õ룬ÈÎÎñºÅ£º" + rwh); + break; + default: + throw new SQLException("proc_slot_space δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + rwh); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + private void find_space_again(EntityDAO m_dao, String taskNo) { + StoredParameters taskParameter = new StoredParameters(1, taskNo); + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_slot_space_again(?,?)}", 2, taskParameter); + switch (back) { + case 10: + Logger.info("proc_slot_space_again Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 1: + Logger.info("proc_slot_space_again ³ö¿âÈÎÎñ²»ÐèÒªÖØ·Ö£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 2: + Logger.info("proc_slot_space_again ÕÒ²»µ½Ö´ÐжÓÁУ¬ÈÎÎñºÅ£º" + taskNo); + break; + case 3: + Logger.info("proc_slot_space_again ÕÒ²»µ½»õ룬ÈÎÎñºÅ£º" + taskNo); + break; + default: + throw new SQLException("proc_slot_space_again δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + taskNo); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + /** + * ¸ø¶Ñ¶â»úÏ·¢ÈÎÎñ + * @param queueBegin ¶Ñ¶â»úÖ´ÐеĶÓÁÐ + */ + private int issuedDDJTask(int devId, WmsDeviceExecutionQueue queueBegin) { + String address = "DB61.0"; + long taskNo = Long.parseLong(queueBegin.getRwh()); + int yph = queueBegin.getYph(); + int ylh = queueBegin.getYlh(); + int ych = queueBegin.getYch(); + int mbph = queueBegin.getMbph(); + int mblh = queueBegin.getMblh(); + int mbch = queueBegin.getMbch(); + int mlfs = 5; + int xfwc = 1; + int qx = queueBegin.getQx(); + int tplx = queueBegin.getTplx(); + int jym = Tools.getJYM((int) taskNo, yph, ylh, ych, mbph, mblh, mbch, mlfs, 0,tplx,qx); + byte[] sendData = Tools.sendDataToDevice(taskNo, null, yph, ylh, ych, mbph, mblh, mbch, mlfs, qx, tplx, xfwc, jym); + int isSend = IsoTcpClientDDJ1.WritetoDDJ(address, sendData); + return isSend; + + } + + /** + * + * @param m_dao + * @param devId + * @param ssjId + * @param outStatus + * @param inStatus + * @param taskNo + * @param rwlx + */ + private void createDDJQueue(EntityDAO m_dao, int devId, int ssjId, int outStatus, int inStatus, long taskNo, int rwlx) { + StoredParameters devParameter = new StoredParameters(1, devId); + StoredParameters ssjParameter = new StoredParameters(2, ssjId); + StoredParameters outParameter = new StoredParameters(3, outStatus); + StoredParameters inParameter = new StoredParameters(4, inStatus); + StoredParameters taskParameter = new StoredParameters(5, String.valueOf(taskNo)); + StoredParameters typeParameter = new StoredParameters(6, rwlx); + + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_add_sbzxdl_ddj(?,?,?,?,?,?,?)}", + 7, devParameter, ssjParameter, outParameter, inParameter, taskParameter, + typeParameter); + switch (back) { + case 10: + Logger.info("proc_add_sbzxdl_ddj Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 1: + Logger.info("proc_add_sbzxdl_ddj ÎÞ¸ÃÈÎÎñ£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 9: + Logger.info("proc_add_sbzxdl_ddj º¯ÊýÒì³££¬ÈÎÎñºÅ£º" + taskNo); + break; + case 2: + Logger.info("proc_add_sbzxdl_ddj ÅÅÁвãÒì³££¬ÈÎÎñºÅ£º" + taskNo); + break; + default: + throw new SQLException("proc_add_sbzxdl_ddj δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + taskNo); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + private void createDDJQueue1(EntityDAO m_dao, int devId, int ssjId, int outId, long taskNo, int rwlx) { + StoredParameters devParameter = new StoredParameters(1, devId); + StoredParameters ssjParameter = new StoredParameters(2, ssjId); + StoredParameters outParameter = new StoredParameters(3, outId); + StoredParameters taskParameter = new StoredParameters(4, String.valueOf(taskNo)); + StoredParameters typeParameter = new StoredParameters(5, rwlx); + + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_add_sbzxdl_ddj_bh_out(?,?,?,?,?,?)}", + 6, devParameter, ssjParameter, outParameter, taskParameter, + typeParameter); + switch (back) { + case 10: + Logger.info("proc_add_sbzxdl_ddj_bh_out Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 1: + Logger.info("proc_add_sbzxdl_ddj_bh_out ÎÞ¸ÃÈÎÎñ£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 9: + Logger.info("proc_add_sbzxdl_ddj_bh_out º¯ÊýÒì³££¬ÈÎÎñºÅ£º" + taskNo); + break; + case 2: + Logger.info("proc_add_sbzxdl_ddj_bh_out ÅÅÁвãÒì³££¬ÈÎÎñºÅ£º" + taskNo); + break; + default: + throw new SQLException("proc_add_sbzxdl_ddj_bh_out δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + taskNo); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + /** + * ¶Ñ¶â»úÕËÎñ´¦Àí + * @param taskNo + * @throws SQLException + */ + private void imp_complete(String taskNo) throws SQLException { + StoredParameters taskParameter = new StoredParameters(1, taskNo); + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_imp_complete(?,?)}", 2, taskParameter); + switch (back) { + case 10: + Logger.info("proc_imp_complete Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 9: + Logger.info("proc_imp_complete Ö´ÐÐÓÐÎó£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 1: + Logger.info("proc_imp_complete ÕÒ²»µ½×÷Òµ£¬ÈÎÎñºÅ£º" + taskNo); + break; + default: + throw new SQLException("proc_imp_complete δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + taskNo); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } +} diff --git a/src/com/wms/dss/ats/customs/abb/schedule/DDJ2Thread.java b/src/com/wms/dss/ats/customs/abb/schedule/DDJ2Thread.java new file mode 100644 index 0000000..7c4c045 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/schedule/DDJ2Thread.java @@ -0,0 +1,423 @@ +package com.wms.dss.ats.customs.abb.schedule; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.entity.*; +import com.wms.dss.ats.customs.abb.plc.IsoTcpClientDDJ2; +import com.wms.dss.ats.customs.abb.utils.QueryDbDataUtils; +import com.wms.dss.ats.customs.abb.utils.Tools; +import com.wms.dss.common.server.config.WMSDDSConfig; +import com.wms.dss.common.server.form.Logger; +import com.wms.dss.common.server.schedule.CraneThread; + +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Hashtable; +import java.util.List; + +/* + *@Version 1.0 + * ¶Ñ¶â»úÏß³Ì + **/ +public class DDJ2Thread extends CraneThread { + + protected byte btid = 0; + String strConfigPath = ""; + Hashtable hsComParamDDJ2 = null; + Hashtable hsComParamSSJ = null; + + + @Override + public void setStop(boolean b) { + m_bStop = b; + } + + public DDJ2Thread(Hashtable hsSysParam) { + super(hsSysParam); + m_bStop = false; + m_hsSysParam = hsSysParam; + m_dao = (EntityDAO) hsSysParam.get("dao"); + hsComParamDDJ2 = (Hashtable) m_hsSysParam.get("hsComParamDDJ2"); + hsComParamSSJ = (Hashtable) m_hsSysParam.get("hsComParamSSJ"); + strConfigPath = ((WMSDDSConfig) hsSysParam.get("config")).getConfigPath(); + } + + @Override + public void run() { + while (!m_bStop) { + try { +// Logger.info("=======================¶Ñ¶â»úÏß³Ì2Æô¶¯==========================="); + //»ñÈ¡DB¿éÖеÄÐÅÏ¢ + DbGet.hsComParamDDJ2 = hsComParamDDJ2; + DbGet.hsComParamSSJ = hsComParamSSJ; + + int ddjh = 0; //¶Ñ¶â»úºÅ + try { ///¶Ñ¶â»úµ÷¶È + List ddj = DbGet.getDDJ_Device2(); + if (ddj != null && ddj.size() > 0) { + for (int i = 0; i < ddj.size(); i++) { + //¶Ñ¶â»úÑ­»· + ddjh = ddj.get(i).btId; + DDJ_Device ddj_c = ddj.get(i); + ddj_dd(ddj_c, ddjh); + } + } + } catch (Exception ex) { + //conn.close(); + Logger.info("¶Ñ¶â»úÏß³Ì×é2µ÷¶ÈÖ´ÐÐÒì³£" + ddjh + ex.getMessage()); + }///¶Ñ¶â»úµ÷¶È + } catch (Exception e) { + Logger.info("==========¶Ñ¶â»úÏß³Ì×é2Òì³£,Òì³£ÐÅÏ¢¡¾" + e.getMessage() + "¡¿========"); + e.printStackTrace(); + } finally { +// Logger.info("=======================¶Ñ¶â»úÏß³Ì×é2ÐÝÃß==========================="); + try { + sleep(2500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + } + + //¶Ñ¶â»úµ÷¶È + private void ddj_dd(DDJ_Device ddj_c, int i) throws SQLException { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { + int ddjh = i; + + /** + * µÚÒ»²¿·Ö + * ¶Ñ¶â»úÏ߳̽øÀ´ºóµÚÒ»¼þÊÂÏȽøÐжѶâ»úÕýÖ´ÐÐÈÎÎñµÄÕËÎñ´¦Àí + * ÒÔ·À´æÔÚ©´¦Àí£¬Ã»´¦ÀíµÄÇé¿ö·¢Éú + */ + if (ddj_c.CZFS == 5 && ddj_c.ZXJD == 5) { /// + WmsDeviceExecutionQueue queue = QueryDbDataUtils.ddj_zxdl(m_dao, ddj_c.ZXRWH,5); + if (queue != null) { + imp_complete(String.valueOf(ddj_c.ZXRWH)); + } + } + + /** + * µÚ¶þ²¿·Ö + * ¸ú×Ù×÷ÒµÖ´Ðн׶Π+ */ + if (ddj_c.CZFS == 5 && (ddj_c.ZXJD == 2 || ddj_c.ZXJD == 3 || ddj_c.ZXJD == 4)) { + WmsDeviceExecutionQueue queue = QueryDbDataUtils.ddj_zxdl(m_dao, ddj_c.ZXRWH,5); + if(queue != null){ + MydoJob job = QueryDbDataUtils.findMydoJobByTaskNo(m_dao,ddj_c.ZXRWH); + if(job != null){ + m_dao.updateSql("update MydoJob set execution_phase=7 where task_no='"+ddj_c.ZXRWH+"'"); + } + } + } + /** + * µÚÈý²¿·Ö + * ¶Ñ¶â»ú·Å»õÄ¿±êÓлõ + * ´¦Àí·½Ê½£ºÖØÐ·ÖÅ䴢λ + */ + if (ddj_c.CZFS == 5 && (ddj_c.SBZT == 1052) && ddj_c.ZXJD < 5) { + ///·Å»õÄ¿±êÓлõ ÖØÐ·ÖÅ䴢λ + WmsDeviceExecutionQueue sbzxdl222 = QueryDbDataUtils.ddj_zxdl(m_dao, ddj_c.ZXRWH,5); + MydoJob mydoJob =QueryDbDataUtils.getSlotJobByTask(m_dao,ddj_c.ZXRWH); + if (sbzxdl222 != null) { + find_space_again(m_dao, sbzxdl222.getRwh()); + } + if (sbzxdl222 == null) { + System.out.println("ÈÎÎñºÅ" + ddj_c.ZXRWH + "-----------¶Ñ¶â»úÒѾ­´¢Î»ÖØ·Ö-------"); + } + } + + /** + * µÚËIJ¿·Ö + * Ö´Ðгö¿â×÷ҵʱȡ»õÔ´ÎÞ»õ + * ´¦Àí·½Ê½£ºÔÚ¸ÃÏïµÀÔÚѰÕÒͬÀà»õÎï½øÐгö¿â + */ +// if (ddj_c.CZFS == 5 && ddj_c.SBZT == 1047 && ddj_c.ZXJD < 5) { +// WmsDeviceExecutionQueue sbzxdl222 = QueryDbDataUtils.ddj_zxdl(m_dao, ddj_c.ZXRWH); +// if (sbzxdl222 != null) { +//// ddj_ywh(sbzxdl222, (int) ddj_c.ZXRWH); +// } +// if (sbzxdl222 == null) { +// System.out.println("ÈÎÎñºÅ" + ddj_c.ZXRWH + "-----------¶Ñ¶â»úÈ¡»õÔ´ÎÞ»õ-------"); +// } +// } + + /** + * µÚÎ岿·Ö + * Éú³É¶Ñ¶â»úÖ´ÐжÓÁÐ + */ + List ssjList = DbGet.getSSJ_roadway2(); + if(ssjList != null && ssjList.size() > 0){ + for(int j = 0; j < ssjList.size(); j++){ + XDK_SSJ ssj = ssjList.get(j); + int rwlx = 0; + int floor = 0; + if(ssj.btId == 3 || ssj.btId == 9 || ssj.btId == 15){ + if(ssj.btId == 3){ + rwlx = 1; + floor = 1; + } + if(ssj.btId == 9){ + rwlx = 3; + floor = 2; + } + if(ssj.btId == 15){ + rwlx = 5; + floor = 3; + } + if(ssj.RKDW == 1 && ssj.RWH > 0){ + WmsDeviceExecutionQueue queue = QueryDbDataUtils.getQueueByRoadAndRwlx(m_dao,ddjh,rwlx); + MydoJob inJob1 = QueryDbDataUtils.getInJobByRoadwayAndCargo(m_dao,ddjh,ssj.RWH); + if(queue == null && inJob1 != null && "1".equals(inJob1.getCount_id())){ + createDDJQueue(m_dao,ddjh,ssj.btId,0,ssj.RKDW,ssj.RWH,rwlx); + } + MydoJob inJob = QueryDbDataUtils.getInJobByRoadwayAndTask(m_dao,ddjh,ssj.RWH); + if(inJob != null && "1".equals(inJob.getCount_id())){ + allot_space(m_dao,ssj.RWH); + } + MydoJob outJob = QueryDbDataUtils.getOUTJobByRoadwayAndTask(m_dao,ddjh,ssj.RWH); + WmsDeviceExecutionQueue queueOut = QueryDbDataUtils.getQueueByRoadAndRwlx1(m_dao,ddjh,2); + if(outJob != null && "1".equals(outJob.getCount_id()) && queueOut == null){ + XDK_SSJ ssj_one_out = DbGet.getSSJ_one_out(4); + //TODO ±¸»õÖ±½Ó³ö¿â +// if(ssj_one_out.CKKX == 1) { + createDDJQueue1(m_dao, ddjh, ssj.btId, ssj_one_out.btId, ssj.RWH, 2); +// } + } + } + } + if(ssj.btId == 4 || ssj.btId == 10 || ssj.btId == 16){ + if(ssj.btId == 4){ + rwlx = 2; + floor = 1; + } + if(ssj.btId == 10){ + rwlx = 4; + floor = 2; + } + if(ssj.btId == 16){ + rwlx = 6; + floor = 3; + } + WmsDeviceExecutionQueue queue = QueryDbDataUtils.getQueueByRoadAndRwlx(m_dao,ddjh,rwlx); + List outList = QueryDbDataUtils.getOutJobByRoad(m_dao,ddjh,floor); + if(ssj.CKKX == 1 && ssj.RWH == 0 && queue == null && outList.size() > 0){ + createDDJQueue(m_dao,ddjh,ssj.btId,ssj.CKKX,0,ssj.RWH ,rwlx); + } + } + } + } + + /** + * µÚÁù²¿·Ö + * ¸ø¶Ñ¶â»úÏ·¢ÈÎÎñ + */ + //·Å»õÄ¿±êÓлõÖØÐÂÏ·¢ + if (ddj_c.YXXF == 1 && ddj_c.CZFS == 5 && ddj_c.SBZT == 1052){ + WmsDeviceExecutionQueue queueFinish = QueryDbDataUtils.getQueueByRoadAndXf(m_dao, ddjh, 1); + WmsDeviceExecutionQueue queueBegin = QueryDbDataUtils.getQueueByTask(m_dao, ddjh, ddj_c.ZXRWH); + if (queueFinish == null && queueBegin != null){ + int isSend = issuedDDJTask(ddjh, queueBegin); + if (isSend == 1){ + String nowTime = sdf.format(new Date()); + m_dao.updateSql("update WmsDeviceExecutionQueue set rwzt = 2, ddjxf = '1', xfsj = '" + nowTime + "' where rwh = " + queueBegin.getRwh()); + Logger.info("Ïò" + ddjh + "ºÅ¶Ñ¶â»úÖØÐÂÏ·¢ÈÎÎñ³É¹¦£¡ÈÎÎñºÅΪ£º" + queueBegin.getRwh()); + } + } + } + //Õý³£Ï·¢ + if (ddj_c.YXXF == 1 && ddj_c.CZFS == 5 && ddj_c.SBZT == 0){ + WmsDeviceExecutionQueue queueFinish = QueryDbDataUtils.getQueueByRoadAndXf(m_dao, ddjh, 1); + List queueList = QueryDbDataUtils.getQueueByRoad(m_dao,ddjh); + if (queueFinish == null && queueList.size() > 0){ + int isSend = issuedDDJTask(ddjh, queueList.get(0)); + if (isSend == 1){ + String nowTime = sdf.format(new Date()); + m_dao.updateSql("update WmsDeviceExecutionQueue set rwzt = 2, ddjxf = '1', xfsj = '" + nowTime + "' where rwh = " + queueList.get(0).getRwh()); + Logger.info("Ïò" + ddjh + "ºÅ¶Ñ¶â»úÏ·¢ÈÎÎñ³É¹¦£¡ÈÎÎñºÅΪ£º" + queueList.get(0).getRwh()); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + Logger.error("¶Ñ¶â»úÏß³Ì×é2µ÷¶ÈÖ´ÐÐʧ°Ü£¡£¡£¡£¡£¡£¡£¡"); + } + } + + private void allot_space(EntityDAO m_dao, long rwh) { + StoredParameters taskParameter = new StoredParameters(1, String.valueOf(rwh)); + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_slot_space(?,?)}", 2, taskParameter); + switch (back) { + case 10: + Logger.info("proc_slot_space Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + rwh); + break; + case 1: + Logger.info("proc_slot_space ³ö¿âÈÎÎñ²»ÐèÒªÖØ·Ö£¬ÈÎÎñºÅ£º" + rwh); + break; + case 2: + Logger.info("proc_slot_space ÕÒ²»µ½Ö´ÐжÓÁУ¬ÈÎÎñºÅ£º" + rwh); + break; + case 3: + Logger.info("proc_slot_space ÕÒ²»µ½»õ룬ÈÎÎñºÅ£º" + rwh); + break; + default: + throw new SQLException("proc_slot_space δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + rwh); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + private void find_space_again(EntityDAO m_dao, String taskNo) { + StoredParameters taskParameter = new StoredParameters(1, taskNo); + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_slot_space_again(?,?)}", 2, taskParameter); + switch (back) { + case 10: + Logger.info("proc_slot_space_again Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 1: + Logger.info("proc_slot_space_again ³ö¿âÈÎÎñ²»ÐèÒªÖØ·Ö£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 2: + Logger.info("proc_slot_space_again ÕÒ²»µ½Ö´ÐжÓÁУ¬ÈÎÎñºÅ£º" + taskNo); + break; + case 3: + Logger.info("proc_slot_space_again ÕÒ²»µ½»õ룬ÈÎÎñºÅ£º" + taskNo); + break; + default: + throw new SQLException("proc_slot_space_again δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + taskNo); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + /** + * ¸ø¶Ñ¶â»úÏ·¢ÈÎÎñ + * @param queueBegin ¶Ñ¶â»úÖ´ÐеĶÓÁÐ + */ + private int issuedDDJTask(int devId, WmsDeviceExecutionQueue queueBegin) { + String address = "DB61.0"; + long taskNo = Long.parseLong(queueBegin.getRwh()); + int yph = queueBegin.getYph(); + int ylh = queueBegin.getYlh(); + int ych = queueBegin.getYch(); + int mbph = queueBegin.getMbph(); + int mblh = queueBegin.getMblh(); + int mbch = queueBegin.getMbch(); + int mlfs = 5; + int xfwc = 1; + int qx = queueBegin.getQx(); + int tplx = queueBegin.getTplx(); + int jym = Tools.getJYM((int) taskNo, yph, ylh, ych, mbph, mblh, mbch, mlfs, 0,tplx,qx); + byte[] sendData = Tools.sendDataToDevice(taskNo, null, yph, ylh, ych, mbph, mblh, mbch, mlfs, qx, tplx, xfwc, jym); + int isSend = IsoTcpClientDDJ2.WritetoDDJ(address, sendData); + + return isSend; + + } + + /** + * + * @param m_dao + * @param devId + * @param ssjId + * @param outStatus + * @param inStatus + * @param taskNo + * @param rwlx + */ + private void createDDJQueue(EntityDAO m_dao, int devId, int ssjId, int outStatus, int inStatus, long taskNo, int rwlx) { + StoredParameters devParameter = new StoredParameters(1, devId); + StoredParameters ssjParameter = new StoredParameters(2, ssjId); + StoredParameters outParameter = new StoredParameters(3, outStatus); + StoredParameters inParameter = new StoredParameters(4, inStatus); + StoredParameters taskParameter = new StoredParameters(5, String.valueOf(taskNo)); + StoredParameters typeParameter = new StoredParameters(6, rwlx); + + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_add_sbzxdl_ddj(?,?,?,?,?,?,?)}", + 7, devParameter, ssjParameter, outParameter, inParameter, taskParameter, + typeParameter); + switch (back) { + case 10: + Logger.info(" proc_add_sbzxdl_ddj Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 1: + Logger.info("proc_add_sbzxdl_ddj ÎÞ¸ÃÈÎÎñ£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 9: + Logger.info("proc_add_sbzxdl_ddj º¯ÊýÒì³££¬ÈÎÎñºÅ£º" + taskNo); + break; + case 2: + Logger.info("proc_add_sbzxdl_ddj ÅÅÁвãÒì³££¬ÈÎÎñºÅ£º" + taskNo); + break; + default: + throw new SQLException("proc_add_sbzxdl_ddj δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + taskNo); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + private void createDDJQueue1(EntityDAO m_dao, int devId, int ssjId, int outId, long taskNo, int rwlx) { + StoredParameters devParameter = new StoredParameters(1, devId); + StoredParameters ssjParameter = new StoredParameters(2, ssjId); + StoredParameters outParameter = new StoredParameters(3, outId); + StoredParameters taskParameter = new StoredParameters(4, String.valueOf(taskNo)); + StoredParameters typeParameter = new StoredParameters(5, rwlx); + + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_add_sbzxdl_ddj_bh_out(?,?,?,?,?,?)}", + 6, devParameter, ssjParameter, outParameter, taskParameter, + typeParameter); + switch (back) { + case 10: + Logger.info("proc_add_sbzxdl_ddj_bh_out Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 1: + Logger.info("proc_add_sbzxdl_ddj_bh_out ÎÞ¸ÃÈÎÎñ£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 9: + Logger.info("proc_add_sbzxdl_ddj_bh_out º¯ÊýÒì³££¬ÈÎÎñºÅ£º" + taskNo); + break; + case 2: + Logger.info("proc_add_sbzxdl_ddj_bh_out ÅÅÁвãÒì³££¬ÈÎÎñºÅ£º" + taskNo); + break; + default: + throw new SQLException("proc_add_sbzxdl_ddj_bh_out δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + taskNo); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + /** + * ¶Ñ¶â»úÕËÎñ´¦Àí + * @param taskNo + * @throws SQLException + */ + private void imp_complete(String taskNo) throws SQLException { + StoredParameters taskParameter = new StoredParameters(1, taskNo); + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_imp_complete(?,?)}", 2, taskParameter); + switch (back) { + case 10: + Logger.info("proc_imp_complete Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 9: + Logger.info("proc_imp_complete Ö´ÐÐÓÐÎó£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 1: + Logger.info("proc_imp_complete ÕÒ²»µ½×÷Òµ£¬ÈÎÎñºÅ£º" + taskNo); + break; + default: + throw new SQLException("proc_imp_complete δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + taskNo); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } +} diff --git a/src/com/wms/dss/ats/customs/abb/schedule/DDJ3Thread.java b/src/com/wms/dss/ats/customs/abb/schedule/DDJ3Thread.java new file mode 100644 index 0000000..11d7b80 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/schedule/DDJ3Thread.java @@ -0,0 +1,426 @@ +package com.wms.dss.ats.customs.abb.schedule; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.entity.*; +import com.wms.dss.ats.customs.abb.plc.IsoTcpClientDDJ1; +import com.wms.dss.ats.customs.abb.plc.IsoTcpClientDDJ2; +import com.wms.dss.ats.customs.abb.plc.IsoTcpClientDDJ3; +import com.wms.dss.ats.customs.abb.utils.QueryDbDataUtils; +import com.wms.dss.ats.customs.abb.utils.Tools; +import com.wms.dss.common.server.config.WMSDDSConfig; +import com.wms.dss.common.server.form.Logger; +import com.wms.dss.common.server.schedule.CraneThread; + +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Hashtable; +import java.util.List; + +/* + *@Version 1.0 + * ¶Ñ¶â»úÏß³Ì + **/ +public class DDJ3Thread extends CraneThread { + + protected byte btid = 0; + String strConfigPath = ""; + Hashtable hsComParamDDJ3 = null; + Hashtable hsComParamSSJ = null; + + + @Override + public void setStop(boolean b) { + m_bStop = b; + } + + public DDJ3Thread(Hashtable hsSysParam) { + super(hsSysParam); + m_bStop = false; + m_hsSysParam = hsSysParam; + m_dao = (EntityDAO) hsSysParam.get("dao"); + hsComParamDDJ3 = (Hashtable) m_hsSysParam.get("hsComParamDDJ3"); + hsComParamSSJ = (Hashtable) m_hsSysParam.get("hsComParamSSJ"); + strConfigPath = ((WMSDDSConfig) hsSysParam.get("config")).getConfigPath(); + } + + @Override + public void run() { + while (!m_bStop) { + try { +// Logger.info("=======================¶Ñ¶â»úÏß³Ì3Æô¶¯==========================="); + //»ñÈ¡DB¿éÖеÄÐÅÏ¢ + DbGet.hsComParamDDJ3 = hsComParamDDJ3; + DbGet.hsComParamSSJ = hsComParamSSJ; + + int ddjh = 0; //¶Ñ¶â»úºÅ + try { ///¶Ñ¶â»úµ÷¶È + List ddj = DbGet.getDDJ_Device3(); + if (ddj != null && ddj.size() > 0) { + for (int i = 0; i < ddj.size(); i++) { + //¶Ñ¶â»úÑ­»· + ddjh = ddj.get(i).btId; + DDJ_Device ddj_c = ddj.get(i); + ddj_dd(ddj_c, ddjh); + } + } + } catch (Exception ex) { + //conn.close(); + Logger.info("¶Ñ¶â»úÏß³Ì×é3µ÷¶ÈÖ´ÐÐÒì³£" + ddjh + ex.getMessage()); + }///¶Ñ¶â»úµ÷¶È + } catch (Exception e) { + Logger.info("==========¶Ñ¶â»úÏß³Ì×é3Òì³£,Òì³£ÐÅÏ¢¡¾" + e.getMessage() + "¡¿========"); + e.printStackTrace(); + } finally { +// Logger.info("=======================¶Ñ¶â»úÏß³Ì×é3ÐÝÃß==========================="); + try { + sleep(2500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + } + + //¶Ñ¶â»úµ÷¶È + private void ddj_dd(DDJ_Device ddj_c, int i) throws SQLException { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { + int ddjh = i; + + /** + * µÚÒ»²¿·Ö + * ¶Ñ¶â»úÏ߳̽øÀ´ºóµÚÒ»¼þÊÂÏȽøÐжѶâ»úÕýÖ´ÐÐÈÎÎñµÄÕËÎñ´¦Àí + * ÒÔ·À´æÔÚ©´¦Àí£¬Ã»´¦ÀíµÄÇé¿ö·¢Éú + */ + if (ddj_c.CZFS == 5 && ddj_c.ZXJD == 5) { /// + WmsDeviceExecutionQueue queue = QueryDbDataUtils.ddj_zxdl(m_dao, ddj_c.ZXRWH,5); + if (queue != null) { + imp_complete(String.valueOf(ddj_c.ZXRWH)); + } + } + + /** + * µÚ¶þ²¿·Ö + * ¸ú×Ù×÷ÒµÖ´Ðн׶Π+ */ + if (ddj_c.CZFS == 5 && (ddj_c.ZXJD == 2 || ddj_c.ZXJD == 3 || ddj_c.ZXJD == 4)) { + WmsDeviceExecutionQueue queue = QueryDbDataUtils.ddj_zxdl(m_dao, ddj_c.ZXRWH,5); + if(queue != null){ + MydoJob job = QueryDbDataUtils.findMydoJobByTaskNo(m_dao,ddj_c.ZXRWH); + if(job != null){ + m_dao.updateSql("update MydoJob set execution_phase=7 where task_no='"+ddj_c.ZXRWH+"'"); + } + } + } + /** + * µÚÈý²¿·Ö + * ¶Ñ¶â»ú·Å»õÄ¿±êÓлõ + * ´¦Àí·½Ê½£ºÖØÐ·ÖÅ䴢λ + */ + if (ddj_c.CZFS == 5 && (ddj_c.SBZT == 1052) && ddj_c.ZXJD < 5) { + ///·Å»õÄ¿±êÓлõ ÖØÐ·ÖÅ䴢λ + WmsDeviceExecutionQueue sbzxdl222 = QueryDbDataUtils.ddj_zxdl(m_dao, ddj_c.ZXRWH,5); + MydoJob mydoJob =QueryDbDataUtils.getSlotJobByTask(m_dao,ddj_c.ZXRWH); + if (sbzxdl222 != null) { + find_space_again(m_dao, sbzxdl222.getRwh()); + } + if (sbzxdl222 == null) { + System.out.println("ÈÎÎñºÅ" + ddj_c.ZXRWH + "-----------¶Ñ¶â»úÒѾ­´¢Î»ÖØ·Ö-------"); + } + } + + /** + * µÚËIJ¿·Ö + * Ö´Ðгö¿â×÷ҵʱȡ»õÔ´ÎÞ»õ + * ´¦Àí·½Ê½£ºÔÚ¸ÃÏïµÀÔÚѰÕÒͬÀà»õÎï½øÐгö¿â + */ +// if (ddj_c.CZFS == 5 && ddj_c.SBZT == 1047 && ddj_c.ZXJD < 5) { +// WmsDeviceExecutionQueue sbzxdl222 = QueryDbDataUtils.ddj_zxdl(m_dao, ddj_c.ZXRWH); +// if (sbzxdl222 != null) { +//// ddj_ywh(sbzxdl222, (int) ddj_c.ZXRWH); +// } +// if (sbzxdl222 == null) { +// System.out.println("ÈÎÎñºÅ" + ddj_c.ZXRWH + "-----------¶Ñ¶â»úÈ¡»õÔ´ÎÞ»õ-------"); +// } +// } + + /** + * µÚÎ岿·Ö + * Éú³É¶Ñ¶â»úÖ´ÐжÓÁÐ + */ + List ssjList = DbGet.getSSJ_roadway1(); + if(ssjList != null && ssjList.size() > 0){ + for(int j = 0; j < ssjList.size(); j++){ + XDK_SSJ ssj = ssjList.get(j); + int rwlx = 0; + int floor = 0; + if(ssj.btId == 1 || ssj.btId == 8 || ssj.btId == 14){ + if(ssj.btId == 1){ + rwlx = 1; + floor = 1; + } + if(ssj.btId == 8){ + rwlx = 3; + floor = 2; + } + if(ssj.btId == 14){ + rwlx = 5; + floor = 3; + } + + if(ssj.RKDW == 1 && ssj.RWH > 0){ + WmsDeviceExecutionQueue queue = QueryDbDataUtils.getQueueByRoadAndRwlx(m_dao,ddjh,rwlx); + MydoJob inJob1 = QueryDbDataUtils.getInJobByRoadwayAndCargo(m_dao,ddjh,ssj.RWH); + if(queue == null && inJob1 != null && "1".equals(inJob1.getCount_id())){ + createDDJQueue(m_dao,ddjh,ssj.btId,0,ssj.RKDW,ssj.RWH,rwlx); + } + MydoJob inJob = QueryDbDataUtils.getInJobByRoadwayAndTask(m_dao,ddjh,ssj.RWH); + if(inJob != null && "1".equals(inJob.getCount_id())){ + allot_space(m_dao,ssj.RWH); + } + MydoJob outJob = QueryDbDataUtils.getOUTJobByRoadwayAndTask(m_dao,ddjh,ssj.RWH); + WmsDeviceExecutionQueue queueOut = QueryDbDataUtils.getQueueByRoadAndRwlx1(m_dao,ddjh,2); + if(outJob != null && "1".equals(outJob.getCount_id()) && queueOut == null){ + XDK_SSJ ssj_one_out = DbGet.getSSJ_one_out(2); + //TODO ±¸»õÖ±½Ó³ö¿â +// if(ssj_one_out.CKKX == 1) { + createDDJQueue1(m_dao, ddjh, ssj.btId, ssj_one_out.btId, ssj.RWH, 2); +// } + } + } + } + if(ssj.btId == 2 || ssj.btId == 7 || ssj.btId == 13){ + if(ssj.btId == 2){ + rwlx = 2; + floor = 1; + } + if(ssj.btId == 7){ + rwlx = 4; + floor = 2; + } + if(ssj.btId == 13){ + rwlx = 6; + floor = 3; + } + WmsDeviceExecutionQueue queue = QueryDbDataUtils.getQueueByRoadAndRwlx(m_dao,ddjh,rwlx); + List outList = QueryDbDataUtils.getOutJobByRoad(m_dao,ddjh,floor); + if(ssj.CKKX == 1 && ssj.RWH == 0 && queue == null && outList.size() > 0){ + createDDJQueue(m_dao,ddjh,ssj.btId,ssj.CKKX,0,ssj.RWH ,rwlx); + } + } + } + } + + /** + * µÚÁù²¿·Ö + * ¸ø¶Ñ¶â»úÏ·¢ÈÎÎñ + */ + //·Å»õÄ¿±êÓлõÖØÐÂÏ·¢ + if (ddj_c.YXXF == 1 && ddj_c.CZFS == 5 && ddj_c.SBZT == 1052){ + WmsDeviceExecutionQueue queueFinish = QueryDbDataUtils.getQueueByRoadAndXf(m_dao, ddjh, 1); + WmsDeviceExecutionQueue queueBegin = QueryDbDataUtils.getQueueByTask(m_dao, ddjh, ddj_c.ZXRWH); + if (queueFinish == null && queueBegin != null){ + int isSend = issuedDDJTask(ddjh, queueBegin); + if (isSend == 1){ + String nowTime = sdf.format(new Date()); + m_dao.updateSql("update WmsDeviceExecutionQueue set rwzt = 2, ddjxf = '1', xfsj = '" + nowTime + "' where rwh = " + queueBegin.getRwh()); + Logger.info("Ïò" + ddjh + "ºÅ¶Ñ¶â»úÖØÐÂÏ·¢ÈÎÎñ³É¹¦£¡ÈÎÎñºÅΪ£º" + queueBegin.getRwh()); + } + } + } + //Õý³£Ï·¢ + if (ddj_c.YXXF == 1 && ddj_c.CZFS == 5 && ddj_c.SBZT == 0){ + WmsDeviceExecutionQueue queueFinish = QueryDbDataUtils.getQueueByRoadAndXf(m_dao, ddjh, 1); + List queueList = QueryDbDataUtils.getQueueByRoad(m_dao,ddjh); + if (queueFinish == null && queueList.size() > 0){ + int isSend = issuedDDJTask(ddjh, queueList.get(0)); + if (isSend == 1){ + String nowTime = sdf.format(new Date()); + m_dao.updateSql("update WmsDeviceExecutionQueue set rwzt = 2, ddjxf = '1', xfsj = '" + nowTime + "' where rwh = " + queueList.get(0).getRwh()); + Logger.info("Ïò" + ddjh + "ºÅ¶Ñ¶â»úÏ·¢ÈÎÎñ³É¹¦£¡ÈÎÎñºÅΪ£º" + queueList.get(0).getRwh()); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + Logger.error("¶Ñ¶â»úÏß³Ì×é3µ÷¶ÈÖ´ÐÐʧ°Ü£¡£¡£¡£¡£¡£¡£¡"); + } + } + + private void allot_space(EntityDAO m_dao, long rwh) { + StoredParameters taskParameter = new StoredParameters(1, String.valueOf(rwh)); + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_slot_space(?,?)}", 2, taskParameter); + switch (back) { + case 10: + Logger.info("proc_slot_space Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + rwh); + break; + case 1: + Logger.info("proc_slot_space ³ö¿âÈÎÎñ²»ÐèÒªÖØ·Ö£¬ÈÎÎñºÅ£º" + rwh); + break; + case 2: + Logger.info("proc_slot_space ÕÒ²»µ½Ö´ÐжÓÁУ¬ÈÎÎñºÅ£º" + rwh); + break; + case 3: + Logger.info("proc_slot_space ÕÒ²»µ½»õ룬ÈÎÎñºÅ£º" + rwh); + break; + default: + throw new SQLException("proc_slot_space δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + rwh); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + + private void find_space_again(EntityDAO m_dao, String taskNo) { + StoredParameters taskParameter = new StoredParameters(1, taskNo); + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_slot_space_again(?,?)}", 2, taskParameter); + switch (back) { + case 10: + Logger.info("proc_slot_space_again Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 1: + Logger.info("proc_slot_space_again ³ö¿âÈÎÎñ²»ÐèÒªÖØ·Ö£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 2: + Logger.info("proc_slot_space_again ÕÒ²»µ½Ö´ÐжÓÁУ¬ÈÎÎñºÅ£º" + taskNo); + break; + case 3: + Logger.info("proc_slot_space_again ÕÒ²»µ½»õ룬ÈÎÎñºÅ£º" + taskNo); + break; + default: + throw new SQLException("proc_slot_space_again δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + taskNo); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + /** + * ¸ø¶Ñ¶â»úÏ·¢ÈÎÎñ + * @param queueBegin ¶Ñ¶â»úÖ´ÐеĶÓÁÐ + */ + private int issuedDDJTask(int devId, WmsDeviceExecutionQueue queueBegin) { + String address = "DB61.0"; + long taskNo = Long.parseLong(queueBegin.getRwh()); + int yph = queueBegin.getYph(); + int ylh = queueBegin.getYlh(); + int ych = queueBegin.getYch(); + int mbph = queueBegin.getMbph(); + int mblh = queueBegin.getMblh(); + int mbch = queueBegin.getMbch(); + int mlfs = 5; + int xfwc = 1; + int qx = queueBegin.getQx(); + int tplx = queueBegin.getTplx(); + int jym = Tools.getJYM((int) taskNo, yph, ylh, ych, mbph, mblh, mbch, mlfs, 0,tplx,qx); + byte[] sendData = Tools.sendDataToDevice(taskNo, null, yph, ylh, ych, mbph, mblh, mbch, mlfs, qx, tplx, xfwc, jym); + int isSend = IsoTcpClientDDJ3.WritetoDDJ(address, sendData); + return isSend; + + } + + /** + * + * @param m_dao + * @param devId + * @param ssjId + * @param outStatus + * @param inStatus + * @param taskNo + * @param rwlx + */ + private void createDDJQueue(EntityDAO m_dao, int devId, int ssjId, int outStatus, int inStatus, long taskNo, int rwlx) { + StoredParameters devParameter = new StoredParameters(1, devId); + StoredParameters ssjParameter = new StoredParameters(2, ssjId); + StoredParameters outParameter = new StoredParameters(3, outStatus); + StoredParameters inParameter = new StoredParameters(4, inStatus); + StoredParameters taskParameter = new StoredParameters(5, String.valueOf(taskNo)); + StoredParameters typeParameter = new StoredParameters(6, rwlx); + + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_add_sbzxdl_ddj(?,?,?,?,?,?,?)}", + 7, devParameter, ssjParameter, outParameter, inParameter, taskParameter, + typeParameter); + switch (back) { + case 10: + Logger.info(" proc_add_sbzxdl_ddj Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 1: + Logger.info("proc_add_sbzxdl_ddj ÎÞ¸ÃÈÎÎñ£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 9: + Logger.info("proc_add_sbzxdl_ddj º¯ÊýÒì³££¬ÈÎÎñºÅ£º" + taskNo); + break; + case 2: + Logger.info("proc_add_sbzxdl_ddj ÅÅÁвãÒì³££¬ÈÎÎñºÅ£º" + taskNo); + break; + default: + throw new SQLException("proc_add_sbzxdl_ddj δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + taskNo); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + private void createDDJQueue1(EntityDAO m_dao, int devId, int ssjId, int outId, long taskNo, int rwlx) { + StoredParameters devParameter = new StoredParameters(1, devId); + StoredParameters ssjParameter = new StoredParameters(2, ssjId); + StoredParameters outParameter = new StoredParameters(3, outId); + StoredParameters taskParameter = new StoredParameters(4, String.valueOf(taskNo)); + StoredParameters typeParameter = new StoredParameters(5, rwlx); + + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_add_sbzxdl_ddj_bh_out(?,?,?,?,?,?)}", + 6, devParameter, ssjParameter, outParameter, taskParameter, + typeParameter); + switch (back) { + case 10: + Logger.info("proc_add_sbzxdl_ddj_bh_out Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 1: + Logger.info("proc_add_sbzxdl_ddj_bh_out ÎÞ¸ÃÈÎÎñ£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 9: + Logger.info("proc_add_sbzxdl_ddj_bh_out º¯ÊýÒì³££¬ÈÎÎñºÅ£º" + taskNo); + break; + case 2: + Logger.info("proc_add_sbzxdl_ddj_bh_out ÅÅÁвãÒì³££¬ÈÎÎñºÅ£º" + taskNo); + break; + default: + throw new SQLException("proc_add_sbzxdl_ddj_bh_out δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + taskNo); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + /** + * ¶Ñ¶â»úÕËÎñ´¦Àí + * @param taskNo + * @throws SQLException + */ + private void imp_complete(String taskNo) throws SQLException { + StoredParameters taskParameter = new StoredParameters(1, taskNo); + try{ + int back = Tools.storedProcedure(m_dao, "{call proc_imp_complete(?,?)}", 2, taskParameter); + switch (back) { + case 10: + Logger.info("proc_imp_complete Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 9: + Logger.info("proc_imp_complete Ö´ÐÐÓÐÎó£¬ÈÎÎñºÅ£º" + taskNo); + break; + case 1: + Logger.info("proc_imp_complete ÕÒ²»µ½×÷Òµ£¬ÈÎÎñºÅ£º" + taskNo); + break; + default: + throw new SQLException("proc_imp_complete δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + taskNo); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } +} diff --git a/src/com/wms/dss/ats/customs/abb/schedule/DDJService.java b/src/com/wms/dss/ats/customs/abb/schedule/DDJService.java new file mode 100644 index 0000000..acb3f57 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/schedule/DDJService.java @@ -0,0 +1,330 @@ +package com.wms.dss.ats.customs.abb.schedule; + +import com.intelligt.modbus.jlibmodbus.Modbus; +import com.intelligt.modbus.jlibmodbus.master.ModbusMaster; +import com.intelligt.modbus.jlibmodbus.master.ModbusMasterFactory; +import com.intelligt.modbus.jlibmodbus.msg.request.ReadHoldingRegistersRequest; +import com.intelligt.modbus.jlibmodbus.msg.request.WriteMultipleRegistersRequest; +import com.intelligt.modbus.jlibmodbus.msg.response.ReadHoldingRegistersResponse; +import com.intelligt.modbus.jlibmodbus.tcp.TcpParameters; +import com.ricosoft.common.dao.dataSource.EntityDAO; + +import com.wms.dss.ats.customs.abb.entity.*; +import com.wms.dss.ats.customs.abb.utils.ConstantUtils; +import com.wms.dss.ats.customs.abb.utils.ParseUtil; +import com.wms.dss.ats.customs.abb.utils.QueryDbDataUtils; + + +import java.net.InetAddress; +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.logging.Logger; + +/** + * @author ¶Ñ¶â»ú + * @create 2022-03-31 13:39 + */ +public class DDJService implements ConstantUtils { + public static final String DDJ_IP_ADDRESS_1 = "192.168.58.88"; + public static final String DDJ_IP_ADDRESS_2 = "192.168.58.90"; + + private String strIp; + private int iPort; + ModbusMaster master; + private byte[] buffer = new byte[2048]; + public DDJ_Device ddjDevice = new DDJ_Device(); + EntityDAO dao; + boolean isFinish = false; + + + ReadHoldingRegistersRequest requestRead = new ReadHoldingRegistersRequest(); + + WriteMultipleRegistersRequest requestWriter = new WriteMultipleRegistersRequest(); + + public DDJService(String strIp, int iPort, EntityDAO dao) { + this.dao = dao; + this.strIp = strIp; + this.iPort = iPort; + } + + + /** + * ֵƴ½Ó + * + * @param startValue ÆðʼµØÖ· + * @param endValue ½áÊøµØÖ· + * @param split Æ´½Ó·ûºÅ + * @return + */ + public String getDataSplice(int startValue, int endValue, String split) { + String data = ""; + try { + for (int i = startValue; i <= endValue; i = i + 2) { + Object readValue = ParseUtil.getReadValue(read(i, 13), read(i + 1, 13), 1); + if ("000000".equals(readValue)) { + break; + } + data += (String) readValue + ","; + } + } catch (Exception e) { + e.printStackTrace(); + } + return data; + } + /*** + * ¶ÁÈ¡ + */ + protected void readValue(String ip) { + try { + //&& isFinish + if (master.isConnected()) { + //writeValue(20, new String[]{String.valueOf(2000000 % 65536), String.valueOf(2000000 / 65536)}); + } + } catch (Exception e) { + //e.printStackTrace(); + agvClear(); + closeServer(); + connectService(); + } + + } + + private String DDJId(String strIp) { + String ic = null; + if("10.9.66.11".equals(strIp)){ + ic = "1" ; + }if("10.9.66.16".equals(strIp)){ + ic = "2" ; + }if("10.9.66.21".equals(strIp)){ + ic = "3" ; + }if("10.9.66.26".equals(strIp)){ + ic = "4" ; + }if("10.9.66.31".equals(strIp)){ + ic = "5" ; + }if("10.9.66.36".equals(strIp)){ + ic = "6" ; + }if("10.9.66.41".equals(strIp)){ + ic = "7" ; + }if("10.9.66.46".equals(strIp)){ + ic = "8" ; + } + return ic; + + } + + /*** + *Ï·¢ + * @param values Ï·¢Öµ + * @param valueSite Õ¾µãÊý×é + */ + protected boolean writeValue(String[] values, int[] valueSite) { + try { + byte[] nodes = ParseUtil.byteConcatArray(values); + requestWriter.setServerAddress(Modbus.TCP_DEFAULT_ID); + requestWriter.setStartAddress(valueSite[0]); //offset + requestWriter.setQuantity(values.length); +// int[] valueSite = ParseUtil.getWriterValueSite(offset, values.length); + requestWriter.setRegisters(valueSite); + requestWriter.setBytes(nodes); + master.sendRequest(requestWriter); + } catch (Exception e) { + isFinish = false; + closeServer(); + connectService(); + e.printStackTrace(); + } + return isFinish; + } + + /** + * ¶ÁÈ¡ + * + * @param offset µØÖ· + * @param quantity ³¤¶È + * @return + */ + private byte[] read(Integer offset, Integer quantity) { + try { + requestRead.setServerAddress(Modbus.TCP_DEFAULT_ID); + requestRead.setStartAddress(offset); + requestRead.setQuantity(quantity); + ReadHoldingRegistersResponse response = (ReadHoldingRegistersResponse) requestRead.getResponse(); + master.processRequest(requestRead); + buffer = response.getHoldingRegisters().getBytes(); + } catch (Exception e) { + isFinish = false; +// Logger.info(agv.agvId + "{" + agv.dqc + "²ã}¶ÁÈ¡³¬Ê±,λÖÃ:" + agv.dqzd + ";" + e.getMessage()); + closeServer(); + connectService(); + } + return buffer; + } + + + protected void connectService() { + try { + TcpParameters tcpParameters = new TcpParameters(); + InetAddress address = InetAddress.getByName(strIp); + tcpParameters.setHost(address); + tcpParameters.setKeepAlive(true); + tcpParameters.setPort(Modbus.TCP_PORT); + tcpParameters.setConnectionTimeout(500); + master = ModbusMasterFactory.createModbusMasterTCP(tcpParameters); + master.setResponseTimeout(1000); + Modbus.setAutoIncrementTransactionId(true); + if (!master.isConnected()) { + master.connect();// ¿ªÆôÁ¬½Ó + isFinish = true; + } + } catch (Exception e) { +// System.err.println("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½Ó´íÎó" + e.getMessage()); + } + } + + private void closeServer() { + isFinish = false; + agvClear(); + try { + if (master != null) { + master.disconnect(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + } + //Ï·¢¶Ñ¶â»ú + protected int sendToDdj(String ddjTask) { + + int re = 0; + + String[] yp = new String[]{String.valueOf(ddjTask.split(",")[0])}; + int[] yph = new int[]{600}; + writeValue(yp, yph); + int ms = ParseUtil.getWORD(read(600, 13), 0); + if(ms == Integer.parseInt(yp[0])){ + re = re+1; + } + String[] yl = new String[]{String.valueOf(ddjTask.split(",")[1])}; + int[] ylh = new int[]{604}; + writeValue(yl, ylh); + int gd1 = ParseUtil.getWORD(read(604, 13), 0); + if(gd1 == Integer.parseInt(yl[0])){ + re = re+1; + } + String[] yc = new String[]{String.valueOf(ddjTask.split(",")[2])}; + int[] ych = new int[]{606}; + writeValue(yc, ych); + int gd2 = ParseUtil.getWORD(read(606, 13), 0); + if (gd2 == Integer.parseInt(yc[0])) { + re = re+1; + } + String[] mbp = new String[]{String.valueOf(ddjTask.split(",")[3])}; + int[] mbph = new int[]{608}; + writeValue(mbp, mbph); + int gd3 = ParseUtil.getWORD(read(608, 13), 0); + if(gd3 == Integer.parseInt(mbp[0])){ + re = re+1; + } + return re; + } + + + /** + * »ñÈ¡id + * + * @param ip + * @return + */ +// private String DDJId(String ip) { +// int id = 0; +// if (ip.equals(DDJ_IP_ADDRESS_1)) { +// id = 1; +// } else if (ip.equals(DDJ_IP_ADDRESS_2)) { +// id = 2; +// } else if (ip.equals(DDJ_IP_ADDRESS_3)) { +// id = 3; +// } else if (ip.equals(DDJ_IP_ADDRESS_4)) { +// id = 4; +// } else if (ip.equals(DDJ_IP_ADDRESS_5)) { +// id = 5; +// } else if (ip.equals(DDJ_IP_ADDRESS_6)) { +// id = 6; +// } else if (ip.equals(DDJ_IP_ADDRESS_7)) { +// id = 7; +// } else if (ip.equals(DDJ_IP_ADDRESS_8)) { +// id = 8; +// } +// return String.valueOf(id); +// } + + /** + * ×÷ÒµÍê³É + * + * @param taskNo + * @throws SQLException + */ + private void procImpComplete(Integer taskNo) { + Connection conn = null; + CallableStatement cs = null; + try { + conn = dao.getConnection(); + cs = conn.prepareCall("{call proc_imp_complete(?,?)}"); + cs.setString(1, String.valueOf(taskNo)); + cs.registerOutParameter(2, java.sql.Types.INTEGER); + cs.execute(); + int back = cs.getInt(2); + +// Logger.info(agv.agvId + "{" + agv.dqc + "}²ã" + "proc_imp_complete" + "Ö´ÐУº" + taskNo + ",msg:" + back); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (cs != null) { + try { + cs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + if (conn != null) { + try { + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + } + + private String exitAddress(int kh) { + String code = ""; +// if (kh == 1) { +// code = "07110" + agv.dqc; +// } else if (kh == 2) { +// code = "07410" + agv.dqc; +// } + return code; + } + + private void agvClear() { + ddjDevice.btId = 0; + ddjDevice.CZFS = 0; + ddjDevice.SBZT = 0; + ddjDevice.ZXRWH = 0; + ddjDevice.HCZT = 0; + ddjDevice.ZXJD =0; + ddjDevice.DQP = 0; + ddjDevice.DQL = 0; + ddjDevice.DQC = 0; + + } + + + +} diff --git a/src/com/wms/dss/ats/customs/abb/schedule/DbGet.java b/src/com/wms/dss/ats/customs/abb/schedule/DbGet.java new file mode 100644 index 0000000..e09f351 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/schedule/DbGet.java @@ -0,0 +1,383 @@ +package com.wms.dss.ats.customs.abb.schedule; + +import com.wms.dss.ats.customs.abb.entity.*; +import com.wms.dss.common.server.form.Logger; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; + +/** + * @author 13623 + */ /* + *@Version 1.0 + * Êý¾Ý»ñÈ¡ + **/ +public class DbGet { + static Hashtable hsComParamDDJ1 = null; + static Hashtable hsComParamDDJ2 = null; + static Hashtable hsComParamDDJ3 = null; + static Hashtable hsComParamSSJ = null; + + public static List getDDJ_Device1() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamDDJ1.get("hsddjMap1"); + ls.add((DDJ_Device) hsDDJMap1.get("ddj-1")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡1ºÅ¶Ñ¶â»ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getDDJ_Device2() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamDDJ2.get("hsddjMap2"); + ls.add((DDJ_Device) hsDDJMap1.get("ddj-2")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡2ºÅ¶Ñ¶â»ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getDDJ_Device3() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamDDJ3.get("hsddjMap3"); + ls.add((DDJ_Device) hsDDJMap1.get("ddj-3")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡3ºÅ¶Ñ¶â»ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getSSJ_roadway1() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-1")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-2")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-7")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-8")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-13")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-14")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡1ºÅ¶Ñ¶â»úÏïµÀ¿Ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + public static XDK_SSJ getSSJ_one_out(int id) { + XDK_SSJ ls = new XDK_SSJ(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls =(XDK_SSJ) hsDDJMap1.get("xdk-"+id); + + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡1ºÅ¶Ñ¶â»ú1Â¥³ö¿âÏïµÀ¿Ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + public static List getSSJ_roadway2() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-3")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-4")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-9")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-10")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-15")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-16")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡2ºÅ¶Ñ¶â»úÏïµÀ¿Ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getSSJ_roadway3() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-5")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-6")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-11")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-12")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-17")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-18")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡3ºÅ¶Ñ¶â»úÏïµÀ¿Ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getOneRSSJ() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("oneRkk-1")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡1²ãÈë³ö¿â¿Ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getOneCSSJ() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("oneCkk-1")); + ls.add((RKK_SSJ) hsDDJMap1.get("oneCkk-2")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡1²ãÈë³ö¿â¿Ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + /** + * Ìù±êÊäËÍ»ú + * + * @return + */ + public static RKK_SSJ getTBSSJ() { + RKK_SSJ ls = null; + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls = (RKK_SSJ) hsDDJMap1.get("qqtm-1"); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡1²ãÈë¿â¿ÚÌù±êÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getSSJ_OneIn() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-1")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-3")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-6")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡1²ãÈë¿âÏïµÀ¿Ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getCMP() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((CMP_Device) hsDDJMap1.get("cmp-1")); + ls.add((CMP_Device) hsDDJMap1.get("cmp-2")); + ls.add((CMP_Device) hsDDJMap1.get("cmp-3")); + ls.add((CMP_Device) hsDDJMap1.get("cmp-4")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡²ðÂëÅÌ»ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getSSJ_TwoIn() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-8")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-9")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-12")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡2²ãÈë¿âÏïµÀ¿Ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getSSJ_ThreeIn() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-14")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-15")); + ls.add((XDK_SSJ) hsDDJMap1.get("xdk-18")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡3²ãÈë¿âÏïµÀ¿Ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getYc_SSJ() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("YCRkk-1")); + HashMap hsDDJMap2 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap2.get("YCRkk-2")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡Òì³£Èë¿â¿Ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getcm_dd_SSJ() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("CMJ-1")); + HashMap hsDDJMap2 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap2.get("CMJ-2")); + HashMap hsDDJMap3 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("czdd-1")); + HashMap hsDDJMap4 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap2.get("czdd-2")); + HashMap hsDDJMap5 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("spdd-1")); + HashMap hsDDJMap6 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap2.get("spdd-2")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡²øÄ¤-´ò´ø-ÊäËÍ»ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getJXS_Ma() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("MDJXS-2")); + ls.add((RKK_SSJ) hsDDJMap1.get("MDJXS-4")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡Âë¶â»úеÊÖ״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + public static RKK_SSJ getJXS_r(int id) { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("MDJXS-"+id)); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡Âë¶â»úеÊÖ״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls.get(0); + } + public static List getSSJ_CD() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("CDJXS-1")); + ls.add((RKK_SSJ) hsDDJMap1.get("CDJXS-3")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡ÊäËÍ»ú²ð¶â״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getOCR() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("OCR-1")); + ls.add((RKK_SSJ) hsDDJMap1.get("OCR-2")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡OCR״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + public static List getHGZ() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("TBHGZ-1")); + ls.add((RKK_SSJ) hsDDJMap1.get("TBHGZ-2")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡TBHGZÊäËÍ»ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + public static List getCZ() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("CZ-1")); + ls.add((RKK_SSJ) hsDDJMap1.get("CZ-2")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡CZÊäËÍ»ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + public static List getZMBQ() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("TBZBQ-1")); + ls.add((RKK_SSJ) hsDDJMap1.get("TBZBQ-2")); + ls.add((RKK_SSJ) hsDDJMap1.get("TBMBQ-1")); + ls.add((RKK_SSJ) hsDDJMap1.get("TBMBQ-2")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡TBHGZÊäËÍ»ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + + public static List getsm_2() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("sm2-1")); + ls.add((RKK_SSJ) hsDDJMap1.get("sm2-2")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡sm2ÊäËÍ»ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + public static List getsm_3() { + List ls = new ArrayList<>(); + try { + HashMap hsDDJMap1 = (HashMap) hsComParamSSJ.get("hsssjMap"); + ls.add((RKK_SSJ) hsDDJMap1.get("sm3-1")); + ls.add((RKK_SSJ) hsDDJMap1.get("sm3-2")); + } catch (Exception ex) { + ex.printStackTrace(); + Logger.error("»ñÈ¡sm2ÊäËÍ»ú״̬ÐÅÏ¢Òì³£" + ex.getMessage()); + } + return ls; + } + +} + + + + + + + + + + + + + + + diff --git a/src/com/wms/dss/ats/customs/abb/schedule/SSJ_CMP_Thread.java b/src/com/wms/dss/ats/customs/abb/schedule/SSJ_CMP_Thread.java new file mode 100644 index 0000000..174edb4 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/schedule/SSJ_CMP_Thread.java @@ -0,0 +1,929 @@ +package com.wms.dss.ats.customs.abb.schedule; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.entity.*; +import com.wms.dss.ats.customs.abb.plc.IsoTcpClientSSJ; +import com.wms.dss.ats.customs.abb.utils.CheckWeight; +import com.wms.dss.ats.customs.abb.utils.QueryDbDataUtils; +import com.wms.dss.ats.customs.abb.utils.Tools; +import com.wms.dss.ats.customs.abb.utils.ZsGet; +import com.wms.dss.common.server.config.WMSDDSConfig; +import com.wms.dss.common.server.form.Logger; +import com.wms.dss.common.server.schedule.CraneThread; + +import java.io.IOException; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Hashtable; +import java.util.List; + + +/* + *@Version 1.0 + **/ +public class SSJ_CMP_Thread extends CraneThread { + + protected byte btid = 0; + String strConfigPath = ""; + Hashtable hsComParamSSJ = null; + DDJService DDJService1; + DDJService DDJService2; + static String weight1; + static String weight2; + + @Override + public void setStop(boolean b) { + m_bStop = b; + } + + public SSJ_CMP_Thread(Hashtable hsSysParam) { + super(hsSysParam); + m_bStop = false; + m_hsSysParam = hsSysParam; + hsComParamSSJ = (Hashtable) hsSysParam.get("hsComParamSSJ"); + m_dao = (EntityDAO) hsSysParam.get("dao"); + strConfigPath = ((WMSDDSConfig) hsSysParam.get("config")).getConfigPath(); + DDJService1 = (DDJService) m_hsSysParam.get("ddj1"); + DDJService2 = (DDJService) m_hsSysParam.get("ddj2"); + } + + @Override + public void run() { + DDJService1.readValue("192.168.58.88"); + DDJService2.readValue("192.168.58.90"); + while (!m_bStop) { + + DbGet.hsComParamSSJ = hsComParamSSJ; + + try { +// Logger.debug("=======================ÊäËÍ»úÏß³ÌÆô¶¯==========================="); +// DDJService1.sendToDdj("1,2470,3550,0"); + /** + * 2 3Â¥²ðÂëÅÌ»ú½»»¥ + */ + cmpj(); + /** + * 2 Â¥²ðĤ½»»¥ + */ + sm_2(); + /** + * 3 Â¥²ðĤ½»»¥ + */ + sm_3(); + /** + * ¶þÈýÂ¥ Òì³£¿ÚÈë¿â + */ + ycrk(); + /** + * ¶þÈýÂ¥ ²øÄ¤ + */ + cmdd(); + /** + * ¶þÈýÂ¥ ocr + */ + ocrs(); + /** + * ¶þÈýÂ¥ ³ÆÖØ + */ + CZ(); + /** + * ¶þÈýÂ¥ ºÏ¸ñÖ¤ + */ + tb_hgz(); + /** + * ¶þÈýÂ¥ ×Öĸ±êÇ© + */ + tb_bq(); + } catch (Exception e) { + Logger.info("==========ÊäËÍ»úÏß³ÌÒì³£,Òì³£ÐÅÏ¢¡¾" + e.getMessage() + "¡¿=========="); + e.printStackTrace(); + } finally { + try { + sleep(2500); + } catch (InterruptedException e) { + e.printStackTrace(); + } +// Logger.info("=======================ÊäËÍ»úÏß³ÌÐÝÃß==========================="); + } + } + } + + //ºÏ¸ñÖ¤Ìù±ê + private void tb_hgz() throws IOException { + List HGZList = DbGet.getHGZ(); + for (RKK_SSJ hgz : HGZList) { + if (hgz.CKDW == 1 && hgz.taskNo > 0 && hgz.QX == 1) { + + int rwh = (int) hgz.taskNo; + String re = ocr(m_dao, hgz.dtype, hgz.btId, (int) hgz.taskNo); + int xfwc = Integer.parseInt(re); + int jym = Tools.getJYM(rwh, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ(hgz.address_xf, sendData); + if (isSend == 1) { + if (hgz.xf_taskNo != hgz.taskNo) { + ocr(m_dao, "hgz", hgz.btId, (int) hgz.taskNo); + Logger.info("¡¾ºÏ¸ñÖ¤Ìù±ê½»»¥¡¿£ºÏò" + hgz.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",Ìù±êÀàÐÍ£º" + xfwc + "(1£ºÌù£¬2£º²»Ìù)³É¹¦£¡"); + } + hgz.xf_taskNo = hgz.taskNo; + + + } + } + } + } + + //×Öĸ±êÇ©Ìù±ê + private void tb_bq() throws Exception { + List HGZList = DbGet.getZMBQ(); + for (RKK_SSJ tb_bq : HGZList) { + if (tb_bq.CKDW == 1 && tb_bq.taskNo > 0) { + String re = ocr(m_dao, tb_bq.dtype, tb_bq.btId, (int) tb_bq.taskNo); + // Ìù±ê×Ó±êÇ© + if ("TBZBQ".equals(tb_bq.dtype) && tb_bq.QX == 2) { + int rwh = (int) tb_bq.taskNo; + int xfwc = Integer.parseInt(re); + int jym = Tools.getJYM(rwh, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ(tb_bq.address_xf, sendData); + if (isSend == 1) { + Logger.info("¡¾×Ó±êÇ©Ìù±ê½»»¥¡¿£ºÏò" + tb_bq.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",Ìù±êÀàÐÍ£º" + xfwc + "(1£ºÌù£¬2£º²»Ìù)³É¹¦£¡"); + } + // Ìù±êĸ±êÇ© + } else if ("TBMBQ".equals(tb_bq.dtype)) { + + // ²»Ìù + if ("0".equals(re)) { + int rwh = (int) tb_bq.taskNo; + int tbcs = 0; + int xfwc = 2; + int jym = Tools.getJYM(rwh, tbcs, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, tbcs, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ(tb_bq.address_xf, sendData); + if (isSend == 1) { + Logger.info("¡¾Ä¸±êÇ©Ìù±ê½»»¥¡¿£ºÏò" + tb_bq.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",Ìù±êÀàÐÍ£º" + xfwc + "(1£ºÌù£¬2£º²»Ìù)³É¹¦£¡"); + } + // Ìù + } else if (!"".equals(re) && re != null) { + MydoJob inJobByRoadwayAndTask1 = QueryDbDataUtils.getInJobByRoadwayAndTask1(m_dao, tb_bq.taskNo); + int wz = 0; + if (inJobByRoadwayAndTask1 != null && "5".equals(inJobByRoadwayAndTask1.getOn_line_type())) { + wz = 1; + } + byte[] sendData1 = new byte[]{0, (byte) wz}; + int isSend1 = IsoTcpClientSSJ.WritetoSSJ(tb_bq.address_xf2, sendData1); + if (isSend1 == 1) { + Logger.info("¡¾Ä¸±êÇ©Ìù±ê½»»¥¡¿£ºÏò" + tb_bq.dName + "Ï·¢Î»Öô¥·¢Î²ÍУº" + wz + "(1£ºÊÇ£¬0£º·ñ)³É¹¦£¡"); + } + int rwh = (int) tb_bq.taskNo; + int tbcs = Integer.parseInt(re); + int xfwc = 1; + int jym = Tools.getJYM(rwh, tbcs, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, tbcs, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ(tb_bq.address_xf, sendData); + if (isSend == 1) { + Logger.info("¡¾Ä¸±êÇ©Ìù±ê½»»¥¡¿£ºÏò" + tb_bq.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",Ìù±êÀàÐÍ£º" + xfwc + "(1£ºÌù£¬2£º²»Ìù)³É¹¦£¡Ìù±ê´ÎÊý£º" + tbcs); + } + } + m_dao.updateSql("update MydoJob set execution_phase=6 where task_no='" + tb_bq.taskNo + "'"); + } + + } + } + } + + // ocr + private void ocrs() throws Exception { + List OCRList = DbGet.getOCR(); + for (RKK_SSJ ocr : OCRList) { + RKK_SSJ jxs_r = DbGet.getJXS_r(ocr.btId * 2); + if (ocr.CKDW == 1 && ocr.taskNo > 0 && ocr.QX == 3 && jxs_r.trayCode.length() == 8 && jxs_r.RKQQ != 1 && !"E".equals(jxs_r.trayCode.substring(0, 1))) { + int jxsMsg = QueryDbDataUtils.getJxsMsg(m_dao, jxs_r.trayCode); + JxsJobMsg jobMsg = QueryDbDataUtils.getJxsJobById(m_dao, jxs_r.btId); + MydoJob mydoJobByTray = QueryDbDataUtils.findMydoJobByTray(m_dao, jxs_r.trayCode); + if (jobMsg != null && jxsMsg < jobMsg.getOutNum() && mydoJobByTray == null) { + String ip = ""; + if (ocr.btId == 1) { + ip = "192.168.58.16"; + } else { + ip = "192.168.58.17"; + } + //TODO ¼ìÑéOCR ²éѯµ±Ç°tb_ocr±íÄÚÐÅÏ¢£¬·µ»Øµ±Ç°Í°µÄÐÅÏ¢ + String re = ocr(m_dao, ocr.dtype, ocr.btId, (int) ocr.taskNo); + OpenLed openLed = QueryDbDataUtils.findOpenLed1(m_dao, 4).get(0); + Logger.info("¡¾OCRÐÅÏ¢·¢ËÍ¡¿£º" + ocr.dName + "£º" + re); + if (!"1".equals(re)) { + //TODO ºÍº£¿µOCR½»»¥£¬Ð´ÈëÊý¾ÝÒÔÉÏ·µ»Ø£¬¸ù¾Ý·´À¡£¬¸üÐÂÿͰµÄʵ¼Ê·µ»Ø½á¹û + String aDouble = "0"; + String result = null; + if (openLed.getStatus() == 4) { + if (ocr.btId == 1) { + result = "2,1,1,1"; + } + if (ocr.btId == 2) { + result = "3,1,1,1"; + } + } else { + result = ZsGet.interfaceUtil(ocr.floor, ip, 7930, re); + Logger.info("¡¾OCRÐÅÏ¢½ÓÊÜ¡¿£º" + ocr.dName + "£º" + result); + } + int jxsMsgs = jxsMsg+1; + String ress = ","+result.split(",")[2]+","+result.split(",")[3]; + // TODO ¸ù¾ÝÐÅϢдÈ뵱ǰ»úеÊÖÂë¶âÊý¾Ý + int ii = ocr.btId; + m_dao.updateSql("update JxsMsg set msg = msg+'"+ress+"',tray_code='"+ jxs_r.trayCode+"',id = "+jxsMsgs+" where floor = '"+ii+"' and task='" + ocr.taskNo + "'"); + int rwh = (int) ocr.taskNo; + int xfwc = 1; + int jym = Tools.getJYM(rwh, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, xfwc, jym); + // TODO Ï·¢OCR + int isSend = IsoTcpClientSSJ.WritetoSSJ(ocr.address_xf, sendData); + if (isSend == 1) { + Logger.info("¡¾OCRÐÅÏ¢½»»¥¡¿£ºÏò" + ocr.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",ÀàÐÍ£º" + xfwc + "³É¹¦£¡"); + } + } + } else { + Logger.info("¡¾OCRÐÅÏ¢½»»¥¡¿£ºµ±Ç°ÍÐÅÌÐÅÏ¢ÒÑÍê³É£¬µÈ´ýÐÂÍÐÅ̵½Î»"); + } + } + } + } + // ocr + private void CZ() throws Exception { + List OCRList = DbGet.getCZ(); + for (RKK_SSJ ocr : OCRList) { + RKK_SSJ jxs_r = DbGet.getJXS_r(ocr.btId * 2); + if (ocr.CKDW == 1 && ocr.taskNo > 0 && ocr.QX == 5 && jxs_r.RKQQ != 1 ) { + + int jxsMsg = QueryDbDataUtils.getJxsMsg1(m_dao, jxs_r.trayCode); + JxsJobMsg jobMsg = QueryDbDataUtils.getJxsJobById(m_dao, jxs_r.btId); + MydoJob mydoJobByTray = QueryDbDataUtils.findMydoJobByTray(m_dao, jxs_r.trayCode); + if (jobMsg != null && jxsMsg <= jobMsg.getOutNum() ) { + String weightIp = ""; + Integer weightPort; + if (ocr.btId == 1) { + weightIp = "192.168.56.92"; // ³ÆÖØIP + weightPort = 4001; + } else { + weightIp = "192.168.56.93"; + weightPort = 4002; + } + + String aDouble = "0"; + String result = null; + + if (ocr.btId == 1) { + result = "2,1"; + } + if (ocr.btId == 2) { + result = "3,1"; + } + + // TODO ³ÆÖØÐÅÏ¢¶ÁÈ¡ ºóÐøÊÇ·ñÐèÒªÔö¼ÓÐÅÏ¢µ½´æ´¢¹ý³Ì½øÐбȶԣ¿£¿£¿£¿£¿£¿£¿£¿ + aDouble = checkWeight(weightIp, weightPort); + if ("0".equals(aDouble)) { + if (ocr.btId == 1) { + aDouble = weight1; + } else { + aDouble = weight2; + } + } else { + if (ocr.btId == 1) { + weight1 = aDouble; + } else { + weight2 = aDouble; + } + // TODO ¸ù¾ÝÐÅϢдÈ뵱ǰ»úеÊÖÂë¶âÊý¾Ý + ocr_msg_add(m_dao, jxs_r.trayCode+"B", result, ocr.btId, (int) ocr.taskNo, aDouble); + int rwh = (int) ocr.taskNo; + int xfwc = 1; + int jym = Tools.getJYM(rwh, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, xfwc, jym); + // TODO Ï·¢OCR + int isSend = IsoTcpClientSSJ.WritetoSSJ(ocr.address_xf, sendData); + if (isSend == 1) { + Logger.info("¡¾³ÆÖØÐÅÏ¢½»»¥¡¿£ºÏò" + ocr.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",ÀàÐÍ£º" + xfwc + "³É¹¦£¡"); + } + } + + + } else { + Logger.info("¡¾OCRÐÅÏ¢½»»¥¡¿£ºµ±Ç°ÍÐÅÌÐÅÏ¢ÒÑÍê³É£¬µÈ´ýÐÂÍÐÅ̵½Î»"); + } + } + } + } + // ³ÆÖØÐÅÏ¢¶ÁÈ¡ÏÔʾ + private String checkWeight(String weightIp, Integer weightPort) { + String s = CheckWeight.WeightOut(weightIp, weightPort); + Double aDouble = new Double(s); + System.err.println("³ÆÖØÐÅÏ¢£ºIP:" + weightIp + ",¶Ë¿Ú£º" + weightPort + ",¶ÁÈ¡ÖØÁ¿£º" + aDouble + "Kg"); + return s; + } + + //²øÄ¤´ò´ø + private void cmdd() { + List CMList = DbGet.getcm_dd_SSJ(); + for (RKK_SSJ cmj : CMList) { + if (cmj.CKDW == 1 && cmj.taskNo > 0) { + int re = cm_or_dd(m_dao, cmj.dtype + "-" + cmj.btId, (int) cmj.taskNo); + if (re != 0) { + int rwh = (int) cmj.taskNo; + int jym = Tools.getJYM(rwh); + byte[] sendData = Tools.sendDataToDevice(rwh, null, re, jym); + String address = ""; + if (cmj.btId == 1) { + if ("CMJ".equals(cmj.dtype)) { + address = "DB65.32"; + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + Logger.info("¡¾¶þÂ¥²øÄ¤ÈÎÎñÏ·¢¡¿£ºÏò" + cmj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",¶þÂ¥²øÄ¤ÀàÐÍ£º" + re + "³É¹¦£¡"); + } + } + // ˮƽ´ò´ø + if ("spdd".equals(cmj.dtype)) { + address = "DB65.12"; + String res = spdd_mode(m_dao, (int) cmj.taskNo); + if (!"0".equals(res)) { + int result = DDJService1.sendToDdj(res); + if (result == 4) { + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + Logger.info("¡¾¶þ¥ˮƽ´ò´øÈÎÎñÏ·¢¡¿£ºÏò" + cmj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",¶þ¥ˮƽ´ò´øÀàÐÍÒÔ¼°¸ß¶È£º" + res + "³É¹¦£¡"); + } + } + } else { + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + Logger.info("¡¾¶þ¥ˮƽ´ò´øÈÎÎñÏ·¢¡¿£ºÏò" + cmj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",¶þ¥ˮƽ´ò´øÀàÐÍ£º" + res + "³É¹¦£¡"); + } + + } + } + //´¹Ö±´ò´ø + if ("czdd".equals(cmj.dtype)) { + address = "DB65.52"; + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + Logger.info("¡¾¶þÂ¥´¹Ö±´ò´øÈÎÎñÏ·¢¡¿£ºÏò" + cmj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",¶þÂ¥´¹Ö±´ò´øÀàÐÍ£º" + re + "³É¹¦£¡"); + } + } + } else if (cmj.btId == 2) { + if ("CMJ".equals(cmj.dtype)) { + address = "DB95.32"; + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + Logger.info("¡¾ÈýÂ¥²øÄ¤ÈÎÎñÏ·¢¡¿£ºÏò" + cmj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",ÈýÂ¥²øÄ¤ÀàÐÍ£º" + re + "³É¹¦£¡"); + } + } + // ˮƽ´ò´ø + if ("spdd".equals(cmj.dtype)) { + address = "DB95.12"; + String res = spdd_mode(m_dao, (int) cmj.taskNo); + if (!"0".equals(res)) { +// DDJService2.sendToDdj(res); + int result = DDJService2.sendToDdj(res); + if (result == 4) { + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + Logger.info("¡¾Èý¥ˮƽ´ò´øÈÎÎñÏ·¢¡¿£ºÏò" + cmj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",Èý¥ˮƽ´ò´øÀàÒÔ¼°¸ß¶È£º" + res + "³É¹¦£¡"); + } + } + } else { + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + Logger.info("¡¾ÈýÂ¥´¹Ö±´ò´øÈÎÎñÏ·¢¡¿£ºÏò" + cmj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",Èý¥ˮƽ´ò´øÀàÐÍ£º" + res + "³É¹¦£¡"); + } + + } + } + //´¹Ö±´ò´ø + if ("czdd".equals(cmj.dtype)) { + address = "DB95.52"; + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + Logger.info("¡¾ÈýÂ¥´¹Ö±´ò´øÈÎÎñÏ·¢¡¿£ºÏò" + cmj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + ",´ò´ø²øÄ¤ÀàÐÍ£º" + re + "³É¹¦£¡"); + } + } + } + + } + } + } + } + + // Òì³£Èë¿â + private void ycrk() throws Exception { + List ycList = DbGet.getYc_SSJ(); + for (RKK_SSJ ssj : ycList) { + if (ssj.YXXF == 1 && ssj.taskNo > 0) { + MydoJob inJob = QueryDbDataUtils.findMydoJobByTaskNo(m_dao, ssj.taskNo); + if (inJob != null) { + if (inJob.getRoadway_id() == null) { + if (ssj.floor == 2) { + int kx1 = 1; + int kx2 = 1; + int kx3 = 1; + SysDictData sysDictData2 = QueryDbDataUtils.getTplx1(m_dao, inJob.getFault_flag()); + if ("1".equals(sysDictData2.getRemark())) { + kx2 = 0; + } + if ("2".equals(sysDictData2.getRemark()) || "3".equals(sysDictData2.getRemark()) ) { + kx1 = 0; + kx3 = 0; + } + if (kx1 == 1 || kx2 == 1 || kx3 == 1) { + allot_roadway(inJob.getTask_no(), Integer.parseInt(inJob.getDev_id()), kx1, kx2, kx3); + } + + } + if (ssj.floor == 3) { + int kx1 = 1; + int kx2 = 1; + int kx3 = 1; + SysDictData sysDictData2 = QueryDbDataUtils.getTplx1(m_dao, inJob.getFault_flag()); + if ("1".equals(sysDictData2.getRemark())) { + kx2 = 0; + } + if ("2".equals(sysDictData2.getRemark()) || "3".equals(sysDictData2.getRemark()) ) { + kx1 = 0; + kx3 = 0; + } + if (kx1 == 1 || kx2 == 1 || kx3 == 1) { + allot_roadway(inJob.getTask_no(), Integer.parseInt(inJob.getDev_id()), kx1, kx2, kx3); + } + + } + } + MydoJob ycJob = QueryDbDataUtils.findMydoJobByTaskNo(m_dao, ssj.taskNo); + if (ycJob.getRoadway_id() != null) { + int type = 0; + SysDictData sysDictData2 = QueryDbDataUtils.getTplx1(m_dao, ycJob.getFault_flag()); + type = Integer.parseInt(sysDictData2.getRemark()); + int rwh = Integer.parseInt(ycJob.getTask_no()); + int qx = Integer.parseInt(ycJob.getRoadway_id()); + int xfwc = 1; + int jym = Tools.getJYM(rwh, qx, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, qx, type, xfwc, jym); + String address = ""; + if (ssj.floor == 2) { + address = "DB65.126"; + } else if (ssj.floor == 3) { + address = "DB95.126"; + } + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + m_dao.updateSql("update MydoJob set execution_phase=2 where task_no='" + rwh + "'"); + Logger.info("Ïò" + ssj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + "³É¹¦£¡"); + m_dao.updateSql("update OpenLed set status = 3 where id='" + ssj.floor + "'"); + } + } + } + } + if (ssj.CKDW == 1 && ssj.taskNo > 0) { + MydoJob inJob = QueryDbDataUtils.findMydoJobByTaskNo(m_dao, ssj.taskNo); + if (inJob != null && "0".equals(inJob.getCount_id())) { + led_msg_add(m_dao, inJob.getTray_code(), ssj.floor); + m_dao.updateSql("update MydoJob set count_id = 1 where task_no='" + ssj.taskNo + "'"); + } + } + } + } + + // ²ðÂëÅÌ»ú + private void cmpj() throws Exception { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + SimpleDateFormat sdf1 = new SimpleDateFormat("HHmmss"); + + List cmpList = DbGet.getCMP(); + for (CMP_Device cmp : cmpList) { + String type = ""; + SysDictData sysDictData = QueryDbDataUtils.getTplx(m_dao, cmp.TPLX,cmp.BY1); + type = sysDictData.getDict_value(); + + int floor = 0; + if (cmp.btId == 1 || cmp.btId == 2) { + floor = 2; + } + if (cmp.btId == 3 || cmp.btId == 4) { + floor = 3; + } + //TODO ²ðÅÌ»ú³ö¿ÕÍÐÅÌÍê³É + if (cmp.KPXH == 0 && cmp.YPXH == 1 && cmp.SBZT == 1 && cmp.RWH > 0 && cmp.TPLX > 0 && (cmp.btId == 2 || cmp.btId == 4)) { + List tpOut = QueryDbDataUtils.getTpOutByTask(m_dao, floor); + if (tpOut.size() > 0) { + proc_out_job_finish(m_dao, tpOut.get(0).getTask_no()); + } + } + //ÓÐÅÌÏ·¢²ÄÖÊ + if (cmp.YPXH == 1 && cmp.SBZT == 1 && cmp.BY1 == 0) { + WcsCmpIn cmpIn = QueryDbDataUtils.getCmpIn(m_dao, cmp.btId); + if (cmpIn != null) { + byte cz = 0; + SysDictData sysDictData1 = QueryDbDataUtils.getTplx1(m_dao, cmpIn.getTray_type()); + cz = (byte) Integer.parseInt(sysDictData1.getDict_sort()); + byte[] sendData = new byte[]{0, cz}; + String address = ""; + if (cmp.btId == 1) { + address = "DB65.154"; + } else if (cmp.btId == 2) { + address = "DB65.178"; + } else if (cmp.btId == 3) { + address = "DB95.154"; + } else if (cmp.btId == 4) { + address = "DB95.178"; + } + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + Logger.info("¡¾ÂëÅÌ»ú²ÄÖÊÏ·¢¡¿£ºÏò" + cmp.dName + "Ï·¢²ÄÖÊ£º" + cz + "³É¹¦£¡"); + } + } + } + //²ðÅÌ»ú ¿ÕÅÌÐźŠ×Ô¶¯ É豸´ý»ú״̬£¬´¥·¢²¹¿ÕÍÐ + //TODO ²ðÅÌ»ú³ö¿ÕÍÐÅÌ + if (cmp.KPXH == 1 && cmp.SBZT == 1 && (cmp.btId == 2 || cmp.btId == 4) && cmp.TPLX == 0 && cmp.BY1 == 0) { + List tpOut = QueryDbDataUtils.getTpOutByFloor(m_dao, floor, cmp.btId); + JxsJobMsg jxsJobMsg = QueryDbDataUtils.getJxsJobById(m_dao, cmp.btId); + if (tpOut.size() == 0 && jxsJobMsg != null) { + add_tp_out_job(m_dao, "0", floor, "18"); + } + } + //TODO ÇåÅÌ + if (cmp.YPXH == 1 && cmp.MPXH != 1 && cmp.SBZT == 1 && cmp.TPLX > 0 && cmp.BY1 > 0) { + WcsCmpIn cmpIn = QueryDbDataUtils.getCmpIn(m_dao, cmp.btId); + if (cmpIn != null && !type.equals(cmpIn.getTray_type()) && "0".equals(cmpIn.getStatus())) { + int rwh = 99; + int qx = 10; + int xfwc = 1; + int jym = Tools.getJYM(rwh, qx, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, qx, xfwc, cmp.BY1, 0, jym); + String address = ""; + if (cmp.btId == 1) { + address = "DB65.146"; + } else if (cmp.btId == 2) { + address = "DB65.170"; + } else if (cmp.btId == 3) { + address = "DB95.146"; + } else if (cmp.btId == 4) { + address = "DB95.170"; + } + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { +// m_dao.updateSql("update WcsCmpIn set status=2 where id='" + cmp.btId + "'"); + Logger.info("¡¾ÇåÅÌÈÎÎñÏ·¢¡¿Ïò" + cmp.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + "³É¹¦£¡"); + } + } else if (cmpIn != null && type.equals(cmpIn.getTray_type()) && "0".equals(cmpIn.getStatus())) { + m_dao.updateSql("update WcsCmpIn set status=2 where id='" + cmp.btId + "'"); + } + + } + //TODO Âë¶â»úеÊÖÇëÇó²ðÅÌ + if (cmp.YPXH == 1 && cmp.MPXH != 1 && cmp.SBZT == 1 && cmp.CPXH == 1 && (cmp.btId == 2 || cmp.btId == 4) && cmp.TPLX > 0 && cmp.BY1 > 0) { + WcsCmpIn cmpIn = QueryDbDataUtils.getCmpIn(m_dao, cmp.btId); + JxsJobMsg jobMsg = QueryDbDataUtils.getJxsJobById(m_dao, cmp.btId); + if (jobMsg != null && cmpIn != null && !"0".equals(cmpIn.getQty()) && type.equals(cmpIn.getTray_type())) { + int rwh = ((int) cmp.RWH + 1000); + int qx = 7; + int xfwc = 1; + int jym = Tools.getJYM(rwh, qx, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, qx, xfwc, jym); + String address = ""; + if (cmp.btId == 1) { + address = "DB65.76"; + } else if (cmp.btId == 2) { + address = "DB65.102"; + } else if (cmp.btId == 3) { + address = "DB95.76"; + } else if (cmp.btId == 4) { + address = "DB95.102"; + } + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + m_dao.updateSql("update MydoJob set execution_phase=2 where task_no='" + rwh + "'"); + m_dao.updateSql("update WcsCmpIn set qty=qty-1 where id='" + cmp.btId + "'"); + Logger.info("¡¾²ðÅÌÈÎÎñÏ·¢¡¿£ºÏò" + cmp.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + "³É¹¦£¡"); + } + } + } + //TODO ÂëÅÌ»úÈë¿ÕÍÐÅÌ + if (cmp.MPXH == 1 && cmp.SBZT == 1 && cmp.YXXF == 1 && cmp.TPLX > 0 && cmp.BY1 > 0) { + List tpIn = QueryDbDataUtils.getTpInByFloor(m_dao, floor, cmp.btId); + if (tpIn.size() == 0) { + if (!"".equals(type)) { + add_tp_in_job(m_dao, type + sdf1.format(new Date()), 8, cmp.btId, floor, type); + } + } + + List inList = QueryDbDataUtils.getInJobByFloor(m_dao, floor, cmp.btId); + if (inList.size() == 1) { + SysDictData sysDictData1 = QueryDbDataUtils.getTplx1(m_dao, inList.get(0).getFault_flag()); + if (floor == 2) { + int kx1 = 1; + int kx2 = 1; + if ("1".equals(sysDictData1.getRemark())) { + kx2 = 0; + } + if ("2".equals(sysDictData1.getRemark()) || "3".equals(sysDictData1.getRemark())) { + kx1 = 0; + } + if (kx1 == 1 || kx2 == 1 ) { + allot_roadway(inList.get(0).getTask_no(), 1, kx1, kx2, 0); + } + } + if (floor == 3) { + int kx1 = 1; + int kx2 = 1; + if ("1".equals(sysDictData1.getRemark())) { + kx2 = 0; + } + if ("2".equals(sysDictData1.getRemark()) || "3".equals(sysDictData1.getRemark())) { + kx1 = 0; + } + if (kx1 == 1 || kx2 == 1) { + allot_roadway(inList.get(0).getTask_no(), 1, kx1, kx2, 0); + } + } + } + + List roadList = QueryDbDataUtils.getInTpByFloorAndRoad(m_dao, floor, cmp.btId); + if (roadList.size() == 1 && "1".equals(roadList.get(0).getExecution_phase())) { + int rwh = Integer.parseInt(roadList.get(0).getTask_no()); + int qx = Integer.parseInt(roadList.get(0).getRoadway_id()); + int xfwc = 1; + int jym = Tools.getJYM(rwh, qx, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, qx, xfwc, jym); + String address = ""; + if (cmp.btId == 1) { + address = "DB65.76"; + } else if (cmp.btId == 2) { + address = "DB65.102"; + } else if (cmp.btId == 3) { + address = "DB95.76"; + } else if (cmp.btId == 4) { + address = "DB95.102"; + } + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + m_dao.updateSql("update MydoJob set execution_phase=2,entrance_id = entrance_id +10 where task_no='" + rwh + "'"); + Logger.info("¡¾ÂëÅÌ»úÈë¿ÕÍÐÅÌ¡¿£ºÏò" + cmp.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + "³É¹¦£¡"); + } + } + } + } + } + + //˺Ĥ´ò´ø + private void sm_2() { + List SMList = DbGet.getsm_2(); + for (RKK_SSJ smj : SMList) { + if (smj.taskNo > 0) { + byte re = (byte) cm_or_dd(m_dao, smj.dtype + "-" + smj.btId, (int) smj.taskNo); + if (re != 0) { + byte[] sendData = new byte[]{0, re}; + int isSend = IsoTcpClientSSJ.WritetoSSJ(smj.address_xf, sendData); + if (isSend == 1) { + Logger.info("¡¾¶þ¥˺ĤÈÎÎñÏ·¢¡¿£ºÏò" + smj.dName + "Ï·¢ÈÎÎñºÅ£º" + smj + ",¶þ¥˺ĤÀàÐÍ£º" + re + "³É¹¦£¡"); + } + } + + } + } + } + + //˺Ĥ´ò´ø + private void sm_3() { + List SMList = DbGet.getsm_3(); + for (RKK_SSJ smj : SMList) { + if (smj.taskNo > 0) { + byte re = (byte) cm_or_dd(m_dao, smj.dtype + "-" + smj.btId, (int) smj.taskNo); + if (re != 0) { + byte[] sendData = new byte[]{0, re}; + int isSend = IsoTcpClientSSJ.WritetoSSJ(smj.address_xf, sendData); + if (isSend == 1) { + Logger.info("¡¾Èý¥˺ĤÈÎÎñÏ·¢¡¿£ºÏò" + smj.dName + "Ï·¢ÈÎÎñºÅ£º" + smj + ",Èý¥˺ĤÀàÐÍ£º" + re + "³É¹¦£¡"); + } + } + + } + } + } + + //TODO µ÷Óú¯Êý ******************************************************************************* + + private String ocr(EntityDAO m_dao, String type, int id, int tray_code) { + StoredParameters trayParameter = new StoredParameters(1, type); + StoredParameters idParameter = new StoredParameters(2, id); + StoredParameters entrParameter = new StoredParameters(3, tray_code); + int back = -1; + String backMsg = ""; + try { + backMsg = Tools.storedPro(m_dao, "{call ocr_tb(?,?,?,?,?)}", + 4, 5, trayParameter, idParameter, entrParameter); + + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + return backMsg; + } + + private int cm_or_dd(EntityDAO m_dao, String type, int task_no) { + StoredParameters trayParameter = new StoredParameters(1, type.substring(0, type.length() - 2)); + StoredParameters entrParameter = new StoredParameters(2, task_no); + int back = -1; + + try { + back = Tools.storedProcedure(m_dao, "{call cm_or_dd(?,?,?)}", + 3, trayParameter, entrParameter); + switch (back) { + case 0: +// Logger.info(" cm_or_dd Ö´Ðгɹ¦£¬É豸£º" + type + "£ºÎÞÐźÅ"); + break; + case 1: + Logger.info("cm_or_dd ²øÄ¤»ò´ò´ø£¬É豸£º" + type + "£º´ò´ø²øÄ¤"); + break; + case 2: + Logger.info("cm_or_dd ´ò´ø£¬É豸£º" + type + "£º²»´ò´ø²»²øÄ¤"); + break; + case 3: + Logger.info("cm_or_dd Èë¿ÚÒÑÓÐÈë¿âÈÎÎñ£¬É豸£º" + type + back); + break; + case 4: + Logger.info("cm_or_dd Èë¿ÚÒÑÓÐÈë¿âÈÎÎñ£¬É豸£º" + type + back); + break; + case 5: + Logger.info("cm_or_dd Èë¿ÚÒÑÓÐÈë¿âÈÎÎñ£¬É豸£º" + type + back); + break; + default: + throw new SQLException("cm_or_dd δ֪µÄ·µ»ØÖµ£¬É豸£º" + type); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + return back; + } + + private void add_tp_in_job(EntityDAO m_dao, String tray_code, int quantity, int entrance_id, int floor, String type) { + StoredParameters trayParameter = new StoredParameters(1, tray_code); + StoredParameters quanParameter = new StoredParameters(2, String.valueOf(quantity)); + StoredParameters entrParameter = new StoredParameters(3, entrance_id); + StoredParameters floorParameter = new StoredParameters(4, floor); + StoredParameters typeParameter = new StoredParameters(5, type); + + try { + int back = Tools.storedProcedure(m_dao, "{call proc_tp_in(?,?,?,?,?,?)}", + 6, trayParameter, quanParameter, entrParameter, floorParameter, typeParameter); + switch (back) { + case 10: + Logger.info(" proc_tp_in Ö´Ðгɹ¦£¬ÍÐÅÌÀàÐÍ£º" + type); + break; + case 1: + Logger.info("proc_tp_in ÍÐÅÌÒÑÓÐÈë¿âÈÎÎñ£¬ÍÐÅÌÀàÐÍ£º" + type); + break; + case 2: + Logger.info("proc_tp_in ÍÐÅÌÒÑÓÐ¿â´æ£¬ÍÐÅÌÀàÐÍ£º" + type); + break; + case 3: + Logger.info("proc_tp_in Èë¿ÚÒÑÓÐÈë¿âÈÎÎñ£¬ÍÐÅÌÀàÐÍ£º" + type); + break; + default: + throw new SQLException("proc_tp_in δ֪µÄ·µ»ØÖµ£¬ÍÐÅÌÀàÐÍ£º" + type); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + private void add_tp_out_job(EntityDAO m_dao, String type, int floor, String in_or_out) { + StoredParameters typeParameter = new StoredParameters(1, type); + StoredParameters floorParameter = new StoredParameters(2, String.valueOf(floor)); + StoredParameters inOutParameter = new StoredParameters(3, in_or_out); + + try { + int back = Tools.storedProcedure(m_dao, "{call proc_tp_out(?,?,?,?)}", + 4, typeParameter, floorParameter, inOutParameter); + switch (back) { + case 10: + Logger.info(" proc_tp_out Ö´Ðгɹ¦£¬ÍÐÅÌÀàÐÍ£º" + type); + break; + case 1: + Logger.info("proc_tp_out ÎÞ¿â´æ£¬ÍÐÅÌÀàÐÍ£º" + type); + break; + case 2: + Logger.info("proc_tp_out ÎÞ±¸Áϼƻ®£¬ÍÐÅÌÀàÐÍ£º" + type); + break; + default: + throw new SQLException("proc_tp_out δ֪µÄ·µ»ØÖµ£¬ÍÐÅÌÀàÐÍ£º" + type); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + private void proc_out_job_finish(EntityDAO m_dao, String task_no) { + StoredParameters typeParameter = new StoredParameters(1, task_no); + + try { + int back = Tools.storedProcedure(m_dao, "{call proc_out_job_finish(?,?)}", + 2, typeParameter); + switch (back) { + case 10: + Logger.info(" proc_out_job_finish Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + task_no); + break; + case 1: + Logger.info("proc_out_job_finish ÎÞÈÎÎñ£¬ÈÎÎñºÅ£º" + task_no); + break; + case 9: + Logger.info("proc_out_job_finish º¯ÊýÒì³££¬ÈÎÎñºÅ£º" + task_no); + break; + default: + throw new SQLException("proc_out_job_finish δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + task_no); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + private void allot_roadway(String task_no, int gd, int kx1, int kx2, int kx3) { + StoredParameters taskParameter = new StoredParameters(1, task_no); + StoredParameters gdParameter = new StoredParameters(2, gd); + StoredParameters kx1Parameter = new StoredParameters(3, kx1); + StoredParameters kx2Parameter = new StoredParameters(4, kx2); + StoredParameters kx3Parameter = new StoredParameters(5, kx3); + + try { + int back = Tools.storedProcedure(m_dao, "{call proc_slot_roadway(?,?,?,?,?,?)}", + 6, taskParameter, gdParameter, kx1Parameter, kx2Parameter, kx3Parameter); + switch (back) { + case 10: + Logger.info(" proc_slot_roadway Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + task_no); + break; + case 1: + Logger.info("proc_slot_roadway ÎÞ¸ÃÈÎÎñ£¬ÈÎÎñºÅ£º" + task_no); + break; + case 2: + Logger.info("proc_slot_roadway ÎÞ¿ÉÓÃÏïµÀ£¬ÈÎÎñºÅ£º" + task_no); + break; + default: + throw new SQLException("proc_slot_roadway δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + task_no); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + private void ocr_msg_add(EntityDAO m_dao, String trayCode, String result, int id, int task, String aDouble) { + StoredParameters taskParameter = new StoredParameters(1, trayCode); + StoredParameters gdParameter = new StoredParameters(2, result); + StoredParameters idParameter = new StoredParameters(3, id); + StoredParameters tasknoParameter = new StoredParameters(4, task); + StoredParameters aDoubleParameter = new StoredParameters(5, aDouble); + + try { + int back = Tools.storedProcedure(m_dao, "{call ocr_msg_add(?,?,?,?,?,?)}", + 6, taskParameter, gdParameter, idParameter, tasknoParameter, aDoubleParameter); + switch (back) { + case 10: + Logger.info("¡¾OCR¶Ô±ÈÐÅÏ¢Ìí¼Ó¡¿£ºocr_msg_add Ö´Ðгɹ¦£¬ÍÐÅ̱àÂ룺" + trayCode); + break; + default: + throw new SQLException("proc_slot_roadway δ֪µÄ·µ»ØÖµ£¬ÍÐÅ̱àÂ룺" + trayCode); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + private String spdd_mode(EntityDAO m_dao, int task_no) { + StoredParameters taskParameter = new StoredParameters(1, task_no); + String back = "0"; + try { + back = Tools.storedPro(m_dao, "{call spdd_mode(?,?,?)}", + 2, 3, taskParameter); + Logger.info("¡¾OCR¶Ô±ÈÐÅÏ¢Ìí¼Ó¡¿£ºspdd_mode Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + task_no + ",ģʽ£º" + back); + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + return back; + } + + private void led_msg_add(EntityDAO m_dao, String trayCode, int floor) { + StoredParameters taskParameter = new StoredParameters(1, trayCode); + StoredParameters gdParameter = new StoredParameters(2, floor); + + try { + int back = Tools.storedProcedure(m_dao, "{call led_msg_add(?,?,?)}", + 3, taskParameter, gdParameter); + switch (back) { + case 0: + Logger.info("¡¾Òì³£¿ÚLEDÐÅÏ¢Ìí¼Ó¡¿£ºled_msg_add Ö´Ðгɹ¦£¬ÍÐÅ̱àÂ룺" + trayCode); + break; + default: + throw new SQLException("proc_slot_roadway δ֪µÄ·µ»ØÖµ£¬ÍÐÅ̱àÂ룺" + trayCode); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } +} diff --git a/src/com/wms/dss/ats/customs/abb/schedule/SSJ_JXS_Thread.java b/src/com/wms/dss/ats/customs/abb/schedule/SSJ_JXS_Thread.java new file mode 100644 index 0000000..b3fdeab --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/schedule/SSJ_JXS_Thread.java @@ -0,0 +1,447 @@ +package com.wms.dss.ats.customs.abb.schedule; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.entity.*; +import com.wms.dss.ats.customs.abb.plc.IsoTcpClientSSJ; +import com.wms.dss.ats.customs.abb.utils.QueryDbDataUtils; +import com.wms.dss.ats.customs.abb.utils.Tools; +import com.wms.dss.common.server.config.WMSDDSConfig; +import com.wms.dss.common.server.form.Logger; +import com.wms.dss.common.server.schedule.CraneThread; + +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Hashtable; +import java.util.List; + + +/* + *@Version 1.0 + **/ +public class SSJ_JXS_Thread extends CraneThread { + + protected byte btid = 0; + String strConfigPath = ""; + Hashtable hsComParamSSJ = null; + + @Override + public void setStop(boolean b) { + m_bStop = b; + } + + public SSJ_JXS_Thread(Hashtable hsSysParam) { + super(hsSysParam); + m_bStop = false; + m_hsSysParam = hsSysParam; + hsComParamSSJ = (Hashtable) hsSysParam.get("hsComParamSSJ"); + m_dao = (EntityDAO) hsSysParam.get("dao"); + strConfigPath = ((WMSDDSConfig) hsSysParam.get("config")).getConfigPath(); + } + + @Override + public void run() { + int taskNoBack = 1001; + while (!m_bStop) { + + DbGet.hsComParamSSJ = hsComParamSSJ; + + try { +// Logger.debug("=======================ÊäËÍ»úÏß³ÌÆô¶¯==========================="); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + /** + * 2,3Â¥²ð¶â»úеÊÖ´¦Àí + */ + jxs_cd(); + /** + * 2,3Â¥Âë¶âÈë¿â + */ + jxs_md(); + } catch (Exception e) { + Logger.info("==========ÊäËÍ»úÏß³ÌÒì³£,Òì³£ÐÅÏ¢¡¾" + e.getMessage() + "¡¿=========="); + e.printStackTrace(); + } finally { + try { + sleep(2500); + } catch (InterruptedException e) { + e.printStackTrace(); + } +// Logger.info("=======================ÊäËÍ»úÏß³ÌÐÝÃß==========================="); + } + } + } + + private void del_jxs_in_job(EntityDAO m_dao, String trayCode, byte btId, int zqsl, int tplx) { + StoredParameters trayParameter = new StoredParameters(1, String.valueOf(trayCode)); + StoredParameters idParameter = new StoredParameters(2, btId); + StoredParameters quanParameter = new StoredParameters(3, zqsl); + StoredParameters tplxParameter = new StoredParameters(4, tplx); + + try { + int back = Tools.storedProcedure(m_dao, "{call proc_jxs_in_finish(?,?,?,?,?)}", + 5, trayParameter, idParameter, quanParameter, tplxParameter); + switch (back) { + case 10: + Logger.info(" proc_jxs_in_finish Ö´Ðгɹ¦£¬»úеÊÖ±àºÅ£º" + btId); + break; + case 1: + Logger.info("proc_jxs_in_finish ûÓÐÂë¶â¼Æ»®£¬»úеÊÖ±àºÅ£º" + btId); + break; + case 2: + Logger.info("proc_jxs_in_finish ¸ÃÍÐÅÌÒÑÓÐ¿â´æ£¬»úеÊÖ±àºÅ£º" + btId); + break; + case 3: + Logger.info("proc_jxs_in_finish ¸ÃÍÐÅÌÒÑÓÐÈÎÎñ£¬»úеÊÖ±àºÅ£º" + btId); + break; + default: + throw new SQLException("proc_jxs_in_finish δ֪µÄ·µ»ØÖµ£¬»úеÊÖ±àºÅ£º" + btId); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + private void del_jxs_out_job(EntityDAO m_dao, long taskNo, byte btId) { + StoredParameters taskParameter = new StoredParameters(1, String.valueOf(taskNo)); + StoredParameters idParameter = new StoredParameters(2, btId); + try { + int back = Tools.storedProcedure(m_dao, "{call proc_jxs_out_finish(?,?,?)}", + 3, taskParameter, idParameter); + switch (back) { + case 10: + Logger.info(" proc_jxs_out_finish Ö´Ðгɹ¦£¬»úеÊÖ±àºÅ£º" + btId); + break; + case 1: + Logger.info("proc_jxs_out_finish ÓÐÕýÔÚÖ´ÐеÄÈÎÎñ£¬»úеÊÖ±àºÅ£º" + btId); + break; + default: + throw new SQLException("proc_jxs_out_finish δ֪µÄ·µ»ØÖµ£¬»úеÊÖ±àºÅ£º" + btId); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + private void add_jxs_job_msg(EntityDAO m_dao, byte btId, long taskNo) { + StoredParameters idParameter = new StoredParameters(1, btId); + StoredParameters taskParameter = new StoredParameters(2, String.valueOf(taskNo)); + try { + int back = Tools.storedProcedure(m_dao, "{call proc_add_jxs_job(?,?,?)}", + 3, idParameter, taskParameter); + switch (back) { + case 10: + Logger.info(" proc_add_jxs_job Ö´Ðгɹ¦£¬»úеÊÖ±àºÅ£º" + btId); + break; + case 1: + Logger.info("proc_add_jxs_job ÓÐÕýÔÚÖ´ÐеÄÈÎÎñ£¬»úеÊÖ±àºÅ£º" + btId); + break; + default: + throw new SQLException("proc_add_jxs_job δ֪µÄ·µ»ØÖµ£¬»úеÊÖ±àºÅ£º" + btId); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + private void allot_roadway(String task_no, int gd, int kx1, int kx2, int kx3) { + StoredParameters taskParameter = new StoredParameters(1, task_no); + StoredParameters gdParameter = new StoredParameters(2, gd); + StoredParameters kx1Parameter = new StoredParameters(3, kx1); + StoredParameters kx2Parameter = new StoredParameters(4, kx2); + StoredParameters kx3Parameter = new StoredParameters(5, kx3); + + try { + int back = Tools.storedProcedure(m_dao, "{call proc_slot_roadway(?,?,?,?,?,?)}", + 6, taskParameter, gdParameter, kx1Parameter, kx2Parameter, kx3Parameter); + switch (back) { + case 10: + Logger.info(" proc_slot_roadway Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + task_no); + break; + case 1: + Logger.info("proc_slot_roadway ÎÞ¸ÃÈÎÎñ£¬ÈÎÎñºÅ£º" + task_no); + break; + case 2: + Logger.info("proc_slot_roadway ÎÞ¿ÉÓÃÏïµÀ£¬ÈÎÎñºÅ£º" + task_no); + break; + default: + throw new SQLException("proc_slot_roadway δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + task_no); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + private void second_bh_cl(String tray_code) { + StoredParameters taskParameter = new StoredParameters(1, tray_code); + + try { + int back = Tools.storedProcedure(m_dao, "{call second_bh_cl(?,?)}", + 2, taskParameter); + switch (back) { + case 10: + Logger.info(" second_bh_cl Ö´Ðгɹ¦£¬ÍÐÅ̱àÂ룺" + tray_code); + break; + case 1: + Logger.info("second_bh_cl ÎÞ¸ÃÈÎÎñ£¬ÍÐÅ̱àÂ룺" + tray_code); + break; + default: + throw new SQLException("second_bh_cl δ֪µÄ·µ»ØÖµ£¬ÍÐÅ̱àÂ룺" + tray_code); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + + // ²ð¶â»úеÊÖ + public void jxs_cd() throws Exception { + List ssjList = DbGet.getSSJ_CD(); + for (RKK_SSJ ssj : ssjList) { + String address = ""; + if (ssj.btId == 1) { + address = "DB200.32"; + } + if (ssj.btId == 3) { + address = "DB200.132"; + } + if (ssj.CKDW == 1 && ssj.taskNo > 0 && ssj.RKQQ == 0 && ssj.by1 == 1) { + JxsJobMsg jxsJobMsg = QueryDbDataUtils.getJxsJobById(m_dao, ssj.btId); + MydoJob outJobByTask = QueryDbDataUtils.getOutJobByTask(m_dao, ssj.taskNo); + if (outJobByTask != null && !"21".equals(outJobByTask.getIn_or_out())&& !"50".equals(outJobByTask.getIn_or_out())) { + if (jxsJobMsg == null) { + add_jxs_job_msg(m_dao, ssj.btId, ssj.taskNo); + } + JxsJobMsg jobMsg = QueryDbDataUtils.getJxsJobById(m_dao, ssj.btId); + if (jobMsg != null) { + /*int flag = 0; + if (jobMsg.getIsHp() == 0) { + JxsJobMsg jxsJobMsg1 = QueryDbDataUtils.getJxsJobById(m_dao, (byte) (ssj.btId + 1)); + if (jxsJobMsg1 != null) { + if (jxsJobMsg1.getLotNo().equals(jobMsg.getLotNo())) { + flag = 1; + } + } + } else { + flag = 1; + }*/ + int taskNo = (int) ssj.taskNo; + int stacking_id = Integer.parseInt(jobMsg.getStackingId()); + int dqsl = jobMsg.getStockNum(); + int zqsl = jobMsg.getOutNum(); + int xfwc = 1; + int jym = Tools.getJYM(taskNo, stacking_id, dqsl, zqsl, 0); + byte[] sendData = Tools.sendDataToDevice(taskNo, null, 0, dqsl, zqsl, stacking_id, 0, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + Logger.info("¡¾²ð¶âÈÎÎñÏ·¢¡¿£ºÏò" + ssj.dName + "Ï·¢ÈÎÎñºÅ£º" + taskNo + "£¬¶âÐÍ£º" + stacking_id + "£¬¿â´æÊýÁ¿£º" + dqsl + "£¬²ð¶âÊýÁ¿£º" + zqsl + " -³É¹¦£¡"); + } + } + } + if (outJobByTask != null && "21".equals(outJobByTask.getIn_or_out())) { + //TODO ¶þ´Î±¸»õ²ð¶âµ½Î»´¦ÀíÈÎÎñ + second_bh_cl(outJobByTask.getTray_code()); + } + List hlJob = QueryDbDataUtils.getInJobByTray1(m_dao, (int) ssj.taskNo, ssj.floor); + if (hlJob.size() > 0) { + int kx1 = 1; + int kx2 = 1; + int kx3 = 1; + SysDictData sysDictData1 = QueryDbDataUtils.getTplx1(m_dao, hlJob.get(0).getFault_flag()); + + if ("1".equals(sysDictData1.getRemark())) { + kx2 = 0; + } + if ("2".equals(sysDictData1.getRemark()) || "3".equals(sysDictData1.getRemark())) { + kx1 = 0; + kx3 = 0; + } + if (kx1 == 1 || kx2 == 1 || kx3 == 1) { + allot_roadway(hlJob.get(0).getTask_no(), 1, kx1, kx2, kx3); + } + } + MydoJob inJob = QueryDbDataUtils.findMydoJobByTaskNo(m_dao, ssj.taskNo); + if (inJob != null && inJob.getRoadway_id() != null && !"10".equals(inJob.getIn_or_out()) && !"11".equals(inJob.getIn_or_out())) { + int rwh = Integer.parseInt(inJob.getTask_no()); + int qx = Integer.parseInt(inJob.getRoadway_id()); + int xfwc = 2; + int jym = Tools.getJYM(rwh, qx, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, qx, 0, 0, 0, 0, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + m_dao.updateSql("update MydoJob set execution_phase=2 where task_no='" + rwh + "'"); + Logger.info("¡¾¶þ´Î±¸»õÈÎÎñÏ·¢»Ø¿â¡¿£ºÏò" + ssj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + "£¬È¥Ïò£º" + qx + "-³É¹¦£¡"); + } + } + } + if (ssj.RKQQ != 1 && ssj.BJXX == 0) { + m_dao.deleteSql("delete from JxsFinishCpj where jxs_id =" + ssj.btId); + } + + if (ssj.RKQQ == 1 && ssj.TPLX > 0 && ssj.BJXX == 0) { + JxsFinishCpj jxsFinishCpj = QueryDbDataUtils.selectByJxsFinishCpj(m_dao, ssj.btId); + if (jxsFinishCpj != null && jxsFinishCpj.getLx() == 10) { + int rwh = (int) ssj.taskNo; + int qx = 5; + int xfwc = 1; + int jym = Tools.getJYM(rwh, qx, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, qx, 0, 0, 0, 0, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + Logger.info("¡¾²ð¶âÍê³ÉÏ·¢¿ÕÍÐÅÌ¡¿£ºÏò" + ssj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + "³É¹¦£¡"); + } + + byte cz = (byte) jxsFinishCpj.getCz(); + byte[] sendData1 = new byte[]{0, cz}; + String address1 = ""; + if (ssj.floor == 2) { + address1 = "DB65.154"; + } else if (ssj.floor == 3) { + address1 = "DB95.154"; + } + int isSend1 = IsoTcpClientSSJ.WritetoSSJ(address1, sendData1); + if (isSend1 == 1) { + Logger.info("¡¾ÂëÅÌ»ú²ÄÖÊÏ·¢¡¿£ºÏò" + ssj.dName + "Ï·¢²ÄÖÊ£º" + cz + "³É¹¦£¡"); + } + + } + + } + + if (ssj.RKQQ == 1 && ssj.TPLX > 0 && ssj.BJXX == 0) { + //µ±Íê³ÉÊýÁ¿µÈÓÚµ±Ç°ÈÎÎñ³ö¿âÊýÁ¿£¬Íê³ÉÈÎÎñ¡£ÐèÒª»ØÁ÷Ï·¢»ØÁ÷ÈÎÎñ/¿ÕÍлØÂëÅÌ»ú Íê³Éµ±Ç°»úеÊÖÈÎÎñ + JxsJobMsg jobMsg = QueryDbDataUtils.getJxsJobById(m_dao, ssj.btId); + if (jobMsg != null) { + MydoJob job = QueryDbDataUtils.findMydoJobByTaskNo(m_dao, ssj.taskNo); + if ("10".equals(job.getIn_or_out())) { + //Õû³ö ¿ÕÍÐÅÌÈ¥ÂëÅÌ»ú + del_jxs_out_job(m_dao, ssj.taskNo, ssj.btId); + } + if ("11".equals(job.getIn_or_out())) { + //¼ì³ö Éú³É»ØÁ÷Èë¿â + del_jxs_out_job(m_dao, ssj.taskNo, ssj.btId); + + List hlJob = QueryDbDataUtils.getInJobByTray(m_dao, job.getTray_code(), Integer.parseInt(job.getFloor())); + if (hlJob.size() > 0) { + int kx1 = 1; + int kx2 = 1; + int kx3 = 1; + SysDictData sysDictData1 = QueryDbDataUtils.getTplx1(m_dao, hlJob.get(0).getFault_flag()); + + if ("1".equals(sysDictData1.getRemark())) { + kx2 = 0; + } + if ("2".equals(sysDictData1.getRemark()) || "3".equals(sysDictData1.getRemark())) { + kx1 = 0; + kx2 = 1; + kx3 = 0; + } + if (kx1 == 1 || kx2 == 1 || kx3 == 1) { + allot_roadway(hlJob.get(0).getTask_no(), 1, kx1, kx2, kx3); + } + } + MydoJob inJob = QueryDbDataUtils.findMydoJobByTaskNo(m_dao, Long.parseLong(hlJob.get(0).getTask_no())); + if (inJob.getRoadway_id() != null) { + int rwh = Integer.parseInt(inJob.getTask_no()); + int qx = Integer.parseInt(inJob.getRoadway_id()); + int xfwc = 1; + int jym = Tools.getJYM(rwh, qx, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, qx, 0, 0, 0, 0, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + m_dao.updateSql("update MydoJob set execution_phase=2 where task_no='" + rwh + "'"); + Logger.info("¡¾²ð¶âÍê³ÉÏ·¢»ØÁ÷¡¿£ºÏò" + ssj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + "£¬È¥Ïò£º" + qx + "-³É¹¦£¡"); + } + } + } + + } + + + + } + } + } + + public void jxs_md() throws Exception { + List ssjListMd = DbGet.getJXS_Ma(); + for (RKK_SSJ ssj : ssjListMd) { + String address = ""; + if (ssj.btId == 2) { + address = "DB200.82"; + } + if (ssj.btId == 4) { + address = "DB200.182"; + } + if (ssj.CKDW == 1 && ssj.taskNo > 0) { + //ÏòÂë¶â»úеÊÖÏ·¢¶âÐÍ + JxsJobMsg jobMsg = QueryDbDataUtils.getJxsJobById(m_dao, ssj.btId); + if (jobMsg != null) { + int stacking_id = Integer.parseInt(jobMsg.getStackingId()); + + int taskNo = 0; + int dqsl = jobMsg.getOutNum(); + int zqsl = 0; + int xfwc = 1; + int jym = Tools.getJYM(taskNo, stacking_id, dqsl, zqsl, 0); + byte[] sendData = Tools.sendDataToDevice(taskNo, null, 0, dqsl, zqsl, stacking_id, 0, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + Logger.info("¡¾Âë¶âÈÎÎñÏ·¢¡¿£ºÏò" + ssj.dName + "Ï·¢¶âÐÍ£º" + stacking_id + " ³É¹¦£¡"); + } + } + } + JxsJobMsg jxsJobMsg = QueryDbDataUtils.getJxsJobById(m_dao, ssj.btId); + + if (ssj.RKQQ == 1 && ssj.taskNo > 0) { + List inJob = QueryDbDataUtils.getInJobByTray(m_dao, ssj.trayCode, ssj.floor); + if (inJob.size() == 0 && jxsJobMsg != null && jxsJobMsg.getOutNum() == ssj.RKSL) { + del_jxs_in_job(m_dao, ssj.trayCode, ssj.btId, ssj.RKSL, ssj.TPLX); + } + if (inJob.size() > 0 && "1".equals(inJob.get(0).getCount_id())) { + int kx1 = 1; + int kx2 = 1; + int kx3 = 1; + SysDictData sysDictData1 = QueryDbDataUtils.getTplx1(m_dao, inJob.get(0).getFault_flag()); + + if ("1".equals(sysDictData1.getRemark())) { + kx2 = 0; + } + if ("2".equals(sysDictData1.getRemark()) || "3".equals(sysDictData1.getRemark())) { + kx1 = 0; + kx2 = 1; + kx3 = 0; + } + if (kx1 == 1 || kx2 == 1 || kx3 == 1) { + allot_roadway(inJob.get(0).getTask_no(), Integer.parseInt(inJob.get(0).getDev_id()), kx1, kx2, kx3); + } + } + if (inJob.size() > 0 && "0".equals(inJob.get(0).getCount_id())) { + int rwh = Integer.parseInt(inJob.get(0).getTask_no()); + int qx = 8; + int xfwc = 1; + int jym = Tools.getJYM(rwh, qx, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, qx, 0, 0, 0, 0, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + Logger.info("¡¾Âë¶âÍê³Éµ½Òì³£¿ÚÏ·¢¡¿£ºÏò" + ssj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + "³É¹¦£¡"); + } + } + List roadJob = QueryDbDataUtils.getInJobByTrayAndRoad(m_dao, ssj.trayCode, ssj.floor); + if (roadJob.size() == 1 && "1".equals(roadJob.get(0).getCount_id())) { + int rwh = Integer.parseInt(roadJob.get(0).getTask_no()); + int qx = Integer.parseInt(roadJob.get(0).getRoadway_id()); + int xfwc = 1; + int jym = Tools.getJYM(rwh, qx, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, qx, 0, 0, 0, 0, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ(address, sendData); + if (isSend == 1) { + m_dao.updateSql("update MydoJob set execution_phase=2 where task_no='" + rwh + "'"); + Logger.info("¡¾Âë¶âÈÎÎñÍê³ÉÏ·¢¡¿£ºÏò" + ssj.dName + "Ï·¢ÈÎÎñºÅ£º" + rwh + "³É¹¦£¡"); + } + } + + } + } + } +} diff --git a/src/com/wms/dss/ats/customs/abb/schedule/SSJ_ONE_Thread.java b/src/com/wms/dss/ats/customs/abb/schedule/SSJ_ONE_Thread.java new file mode 100644 index 0000000..08fe87e --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/schedule/SSJ_ONE_Thread.java @@ -0,0 +1,309 @@ +package com.wms.dss.ats.customs.abb.schedule; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.entity.*; +import com.wms.dss.ats.customs.abb.plc.IsoTcpClientSSJ; +import com.wms.dss.ats.customs.abb.utils.QueryDbDataUtils; +import com.wms.dss.ats.customs.abb.utils.Tools; +import com.wms.dss.common.server.config.WMSDDSConfig; +import com.wms.dss.common.server.form.Logger; +import com.wms.dss.common.server.schedule.CraneThread; + +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + + +/* + *@Version 1.0 + **/ +public class SSJ_ONE_Thread extends CraneThread { + + protected byte btid = 0; + String strConfigPath = ""; + Hashtable hsComParamSSJ = null; + + @Override + public void setStop(boolean b) { + m_bStop = b; + } + + public SSJ_ONE_Thread(Hashtable hsSysParam) { + super(hsSysParam); + m_bStop = false; + m_hsSysParam = hsSysParam; + hsComParamSSJ = (Hashtable) hsSysParam.get("hsComParamSSJ"); + m_dao = (EntityDAO) hsSysParam.get("dao"); + strConfigPath = ((WMSDDSConfig) hsSysParam.get("config")).getConfigPath(); + } + + @Override + public void run() { + int taskNoBack = 1001; + while (!m_bStop) { + + DbGet.hsComParamSSJ = hsComParamSSJ; + try { +// Logger.info("=======================ÊäËÍ»úÏß³ÌÆô¶¯==========================="); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + /** 1Â¥Ìù±ê **/ + RKK_SSJ tmqq = DbGet.getTBSSJ(); + List oneSSJ1 = DbGet.getOneRSSJ(); + if (tmqq != null && tmqq.RKQQ > 0 && tmqq.RKGD > 0 && tmqq.taskNo > 0 && oneSSJ1.get(0).RKQQ !=1) { + String msg = null; + //TODO Ìí¼ÓÌùÍÐÅÌÂëÐÅÏ¢µÄº¯Êý£¨¸ù¾Ý¿ªÆô×Óµ¥¾ÝµÄÍÐÅÌÀàÐÍ£¬Éú³É¶ÔÓ¦ÌõÂëÍ·µÄÍÐÅ̱àÂ룬²åÈëµ½Ìù±ê¼Ç±í£© + List inJobByent = QueryDbDataUtils.getInJobByent(m_dao, 1); + if (inJobByent.size() > 0) { + if (inJobByent.get(0).getTray_code() != null && !"".equals(inJobByent.get(0).getTray_code())) { + byte[] sendData = {0, 2}; + Logger.info("¡¾Ò»Â¥Ìù±ê»úÈÎÎñ¡¿£ºÏ·¢£ºÕý³£ÈÎÎñ²»´òÓ¡£¬ÍÐÅÌÂë £º"+inJobByent.get(0).getTray_code()); + int isSend = IsoTcpClientSSJ.WritetoSSJ("DB51.8", sendData); + } else { + byte[] sendData = {0, 1}; + Logger.info("¡¾Ò»Â¥Ìù±ê»úÈÎÎñ¡¿£ºÏ·¢£ºÈÎÎñÎÞÍÐÅÌÂëÏ·¢´òÓ¡"); + int isSend = IsoTcpClientSSJ.WritetoSSJ("DB51.8", sendData); + } + } + if (inJobByent.size() == 0) { + int i = tb_msg_dy(1); + byte[] sendData = {0, (byte)i}; + int isSend = IsoTcpClientSSJ.WritetoSSJ("DB51.8", sendData); + Logger.info("¡¾Ò»Â¥Ìù±ê»úÈÎÎñ¡¿£ºÏ·¢£ºÎÞÈÎÎñÏ·¢Ìù±ê»ú"); + } + } + /** 1Â¥Èë¿â¿Ú½»»¥ **/ + List oneSSJ = DbGet.getOneRSSJ(); + for (RKK_SSJ ssj : oneSSJ) { +// ssj.RKQQ = 1 ; ssj.RKGD =1; ssj.BJXX = 0; ssj.trayCode = "H0000003"; + if (ssj.RKQQ == 1 && ssj.RKGD > 0 && ssj.trayCode.length() == 8) { + String tray_code = ssj.trayCode.trim(); + String head = tray_code.substring(0,1); + SysDictData sysDictData1 = QueryDbDataUtils.getTplx1(m_dao, head); + boolean res =true; + switch (ssj.TPLX) { + case 1: + if(!"1".equals(sysDictData1.getRemark())){ + res = false; + } + break; + case 2: + if(!"2".equals(sysDictData1.getRemark())){ + res = false; + } + break; + case 3: + if(!"3".equals(sysDictData1.getRemark())){ + res = false; + } + break; + } + if(!res) { + int rwh = 0; + int qx = 0; + int xfwc =2; + int jym = Tools.getJYM(rwh, qx, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, qx, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ("DB51.40", sendData); + if (isSend == 1) { + + Logger.info("Ïò1Â¥ÊäËÍ»úL1007Ï·¢ÈÎÎñºÅ£º" + rwh + ",Ï·¢Íê³É£º"+xfwc+"³É¹¦£¡"); + } + } + List inJobs = QueryDbDataUtils.getInJobByTray(m_dao, tray_code, 1); + if (inJobs.size() == 0) { + // Éú³ÉÈë¿â×÷Òµ + int re = proc_add_job(tray_code, 1); + if(re != 10){ + int rwh = 99; + int qx = 0; + int xfwc = 2; + int jym = Tools.getJYM(rwh, qx, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ("DB51.40", sendData); + + } + } + if (inJobs.size() == 1 && "0".equals(inJobs.get(0).getExecution_phase())) { + int kx1 = 0; + int kx2 = 0; + int kx3 = 0; + List roads = DbGet.getSSJ_OneIn(); + kx3 = roads.get(0).CKKX; + kx2 = roads.get(1).CKKX; + kx1 = roads.get(2).CKKX; + //TODO ¸ù¾ÝÍÐÅÌÌõÂëÀàÐÍ ¾ö¶¨Èë¿âÏïµÀ + if ("8".equals(inJobs.get(0).getIn_or_out())) { + kx3 = 0; + } + SysDictData sysDictData2 = QueryDbDataUtils.getTplx1(m_dao, inJobs.get(0).getFault_flag()); + if ("1".equals(sysDictData2.getRemark())) { + kx2 = 0; + } + if ("2".equals(sysDictData2.getRemark()) || "3".equals(sysDictData2.getRemark()) ) { + kx1 = 0; + kx3 = 0; + } + int re = 0; + //·ÖÏïµÀ + if (kx1 == 1 || kx2 == 1 || kx3 == 1) { + re = allot_roadway(inJobs.get(0).getTask_no(), ssj.RKGD, kx1, kx2, kx3); + } + } + List roadJob = QueryDbDataUtils.getInJobByTrayAndRoad(m_dao, tray_code, 1); + if (roadJob.size() == 1 && "1".equals(roadJob.get(0).getExecution_phase())) { + int rwh = Integer.parseInt(roadJob.get(0).getTask_no()); + int qx = Integer.parseInt(roadJob.get(0).getRoadway_id()); + int xfwc = 1; + int jym = Tools.getJYM(rwh, qx, 0); + byte[] sendData = Tools.sendDataToDevice(rwh, null, qx, xfwc, jym); + int isSend = IsoTcpClientSSJ.WritetoSSJ("DB51.40", sendData); + if (isSend == 1) { + m_dao.updateSql("update MydoJob set execution_phase=2 where task_no='" + rwh + "'"); + Logger.info("Ïò1Â¥ÊäËÍ»úL1007Ï·¢ÈÎÎñºÅ£º" + rwh + "£¬È¥Ïò£º"+qx+"³É¹¦£¡"); + } + } + } + } + /** 1Â¥Èë³ö¿â¿Ú½»»¥**/ + List oneCSSJ = DbGet.getOneCSSJ(); + for (RKK_SSJ ssj : oneCSSJ) { + if (ssj.taskNo > 0) { + MydoJob outJob = QueryDbDataUtils.getOutJobByTask(m_dao, ssj.taskNo); + if (outJob != null) { + m_dao.updateSql("update MydoJob set execution_phase=10 where task_no='" + ssj.taskNo + "'"); + //TODO ³ö¿âÍê³É´¦Àí×÷Òµ + proc_out_job_finish(outJob.getTray_code()); + } + } + } + } catch (Exception e) { + Logger.info("==========ÊäËÍ»úÏß³ÌÒì³£,Òì³£ÐÅÏ¢¡¾" + e.getMessage() + "¡¿=========="); + e.printStackTrace(); + } finally { + try { + sleep(2500); + } catch (InterruptedException e) { + e.printStackTrace(); + } +// Logger.info("=======================ÊäËÍ»úÏß³ÌÐÝÃß==========================="); + } + } + } + private void led_msg_add(EntityDAO m_dao, String trayCode, int floor) { + StoredParameters taskParameter = new StoredParameters(1, trayCode); + StoredParameters gdParameter = new StoredParameters(2, floor); + + try { + int back = Tools.storedProcedure(m_dao, "{call led_msg_add(?,?,?)}", + 3, taskParameter, gdParameter); + switch (back) { + case 0: + Logger.info("¡¾Òì³£¿ÚLEDÐÅÏ¢Ìí¼Ó¡¿£ºled_msg_add Ö´Ðгɹ¦£¬ÍÐÅ̱àÂ룺" + trayCode); + break; + default: + throw new SQLException("proc_slot_roadway δ֪µÄ·µ»ØÖµ£¬ÍÐÅ̱àÂ룺" + trayCode); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + } + private int allot_roadway(String task_no, int gd, int kx1, int kx2, int kx3) { + StoredParameters taskParameter = new StoredParameters(1, task_no); + StoredParameters gdParameter = new StoredParameters(2, gd); + StoredParameters kx1Parameter = new StoredParameters(3, kx1); + StoredParameters kx2Parameter = new StoredParameters(4, kx2); + StoredParameters kx3Parameter = new StoredParameters(5, kx3); + int back = 0; + try { + back = Tools.storedProcedure(m_dao, "{call proc_slot_roadway(?,?,?,?,?,?)}", + 6, taskParameter, gdParameter, kx1Parameter, kx2Parameter, kx3Parameter); + switch (back) { + case 10: + Logger.info(" proc_slot_roadway Ö´Ðгɹ¦£¬ÈÎÎñºÅ£º" + task_no); + break; + case 1: + Logger.info("proc_slot_roadway ÎÞ¸ÃÈÎÎñ£¬ÈÎÎñºÅ£º" + task_no); + break; + case 2: + Logger.info("proc_slot_roadway ÎÞ¿ÉÓÃÏïµÀ£¬ÈÎÎñºÅ£º" + task_no); + break; + default: + throw new SQLException("proc_slot_roadway δ֪µÄ·µ»ØÖµ£¬ÈÎÎñºÅ£º" + task_no); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + return back; + } + + private int proc_add_job(String tray_code, int floor) { + StoredParameters trayParameter = new StoredParameters(1, tray_code); + StoredParameters floorParameter = new StoredParameters(2, floor); + int back = 0; + try { + back = Tools.storedProcedure(m_dao, "{call proc_add_job(?,?,?)}", + 3, trayParameter, floorParameter); + switch (back) { + case 10: + Logger.info(" proc_add_job Ö´Ðгɹ¦£¬ÍÐÅÌÂ룺" + tray_code); + + break; + case 1: + Logger.info("proc_add_job ÌõÂëÖØ¸´£¬ÍÐÅÌÂ룺" + tray_code); + led_msg_add(m_dao,"ÌõÂëÖØ¸´,ÍÐÅÌÂ룺" + tray_code, 1); + break; + case 2: + Logger.info("proc_add_job ÎÞ¿ªÆðµÄÈë¿â¼Æ»®£¬ÍÐÅÌÂ룺" + tray_code); + led_msg_add(m_dao,"ÎÞ¿ªÆðµÄÈë¿â¼Æ»®£¬ÍÐÅÌÂ룺" + tray_code, 1); + break; + default: + led_msg_add(m_dao,"δ֪µÄ·µ»ØÖµ£¬ÍÐÅÌÂ룺" + tray_code, 1); + throw new SQLException("proc_add_job δ֪µÄ·µ»ØÖµ£¬ÍÐÅÌÂ룺" + tray_code); + + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + return back; + } + private int proc_out_job_finish(String tray_code) { + StoredParameters trayParameter = new StoredParameters(1, tray_code); + int back = 0; + try { + back = Tools.storedProcedure(m_dao, "{call proc_ck_makeSure(?,?)}", + 2, trayParameter); + switch (back) { + case 10: + Logger.info(" proc_ck_makeSure Ö´Ðгɹ¦£¬ÍÐÅÌÂ룺" + tray_code); + break; + case 1: + Logger.info("proc_ck_makeSure ÌõÂëÖØ¸´£¬ÍÐÅÌÂ룺" + tray_code); + break; + case 2: + Logger.info("proc_ck_makeSure ÒÑÉú³É×÷Òµ£¬ÍÐÅÌÂ룺" + tray_code); + break; + case 9: + Logger.info("proc_ck_makeSure Ö´ÐÐÒì³££¬ÍÐÅÌÂ룺" + tray_code); + break; + default: + throw new SQLException("proc_ck_makeSure δ֪µÄ·µ»ØÖµ£¬ÍÐÅÌÂ룺" + tray_code); + } + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + return back; + } + private int tb_msg_dy(int id) { + StoredParameters trayParameter = new StoredParameters(1, id); + int back = 0; + try { + back = Tools.storedProcedure(m_dao, "{call tb_msg_dy(?,?)}", + 2, trayParameter); + } catch (SQLException throwables) { + throwables.printStackTrace(); + } + return back; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/schedule/ThreadCK_SSJ_LED.java b/src/com/wms/dss/ats/customs/abb/schedule/ThreadCK_SSJ_LED.java new file mode 100644 index 0000000..da4fcba --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/schedule/ThreadCK_SSJ_LED.java @@ -0,0 +1,112 @@ +package com.wms.dss.ats.customs.abb.schedule; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.entity.*; +import com.wms.dss.ats.customs.abb.led.*; +import com.wms.dss.ats.customs.abb.utils.MyUdpSocket; +import com.wms.dss.ats.customs.abb.utils.QueryDbDataUtils; +import com.wms.dss.ats.customs.abb.utils.Tools; +import com.wms.dss.common.server.config.WMSDDSConfig; +import com.wms.dss.common.server.form.Logger; +import com.wms.dss.common.server.schedule.CraneThread; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Types; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Hashtable; +import java.util.List; + +/* + *@Version 1.0 + **/ +public class ThreadCK_SSJ_LED extends CraneThread { + + int ledflag[] = {1,1,1,1,1,1,1,1}; + long ledtime[] = {0,0,0,0,0,0,0,0}; + private Socket socket = null; + private OutputStream os = null; + private InputStream is = null; + + protected byte btid = 0; // + String strConfigPath = ""; + Hashtable hsComParamSSJ = null; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + + @Override + public void setStop(boolean b) { + m_bStop = b; + } + + public ThreadCK_SSJ_LED(Hashtable hsSysParam) { + super(hsSysParam); + m_bStop = false; + m_hsSysParam = hsSysParam; + hsComParamSSJ = (Hashtable) hsSysParam.get("hsComParamssj"); + m_dao = (EntityDAO) hsSysParam.get("dao"); + strConfigPath = ((WMSDDSConfig) hsSysParam.get("config")).getConfigPath(); + } + + @Override + public void run() { + LED1.my_udp = new MyUdpSocket(50001); + LED2.my_udp = new MyUdpSocket(50002); + LED3.my_udp = new MyUdpSocket(50003); + + Logger.info("--------------------³ö¿âÏß³Ì---LEDÈÎÎñ´¦Àí-----------¿ªÊ¼---------------------"); + while (!m_bStop) { + try { + List openLeds = QueryDbDataUtils.findOpenLed(m_dao); + for (OpenLed openLed : openLeds) { + if(openLed.getStatus()==0) { + sendToLed(openLed.getId(), openLed.getLine(), openLed.getIp(), openLed.getMsg1(), openLed.getMsg2(), openLed.getMsg3(), openLed.getMsg4()); + m_dao.updateSql("update OpenLed set status= 3 where id="+openLed.getId()); + ledtime[openLed.getId()-1]=System.currentTimeMillis(); + ledflag[openLed.getId()-1] = 1; + } + if(openLed.getStatus()==1) { + sendToLed(openLed.getId(), openLed.getLine(), openLed.getIp(), openLed.getMsg1(), openLed.getMsg2(), openLed.getMsg3(), openLed.getMsg4()); + m_dao.updateSql("update OpenLed set status= 2 where id="+openLed.getId()); + ledtime[openLed.getId()-1]=System.currentTimeMillis(); + ledflag[openLed.getId()-1] = 1; + } + if(openLed.getStatus()==3) { + long time = System.currentTimeMillis() - ledtime[openLed.getId()-1]; + if (time > openLed.getWrite_time() && ledflag[openLed.getId()-1] ==1){ + sendToLed(openLed.getId(), 1, openLed.getIp(), "Öл¯À¶Ìì·ú²ÄÁÏÓÐÏÞ¹«Ë¾", "","",""); + ledflag[openLed.getId()-1] = 0; + } + } + + } + } catch (Exception e) { + Logger.info("----------LEDÏß³ÌÒì³£---------Òì³£ÐÅÏ¢¡¾" + e.getMessage() + "¡¿---------"); + e.printStackTrace(); + } finally { + try { + sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + private void sendToLed(int dev_id, int line, String ip, String msg1, String msg2, String msg3, String msg4) { + + if (dev_id == 1) { + LED1.send_data(line, ip, msg1, msg2, msg3, msg4); + } else if (dev_id == 2) { + LED2.send_data(line, ip, msg1, msg2, msg3, msg4); + } else if (dev_id == 3) { + LED3.send_data(line, ip, msg1, msg2, msg3, msg4); + } + Logger.info("ÏòLED" + dev_id + ",ipΪ:" + ip + " Ï·¢:" + msg1 + msg2 + msg3 + msg4); + +// ledtime[dev_id] = System.currentTimeMillis(); + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/test/Test.java b/src/com/wms/dss/ats/customs/abb/test/Test.java new file mode 100644 index 0000000..d7ff8bd --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/test/Test.java @@ -0,0 +1,26 @@ +package com.wms.dss.ats.customs.abb.test; + +import java.util.Hashtable; + +import com.wms.dss.common.server.schedule.ThreadSchedule; + +public class Test { + //Êä³ö1\ + @org.junit.jupiter.api.Test + public static void main() throws Exception { + main(); + } + + //Êä³ö1\ + @org.junit.jupiter.api.Test + public static void main(String[] args){ + String name = "false,11111"; + System.out.println(name.substring(6)); + } + + public static class Param extends ThreadSchedule{ + public Hashtable getParam(){ + return m_hsSysParam; + } + } +} diff --git a/src/com/wms/dss/ats/customs/abb/utils/AllocatePropUtils.java b/src/com/wms/dss/ats/customs/abb/utils/AllocatePropUtils.java new file mode 100644 index 0000000..49b5f05 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/AllocatePropUtils.java @@ -0,0 +1,526 @@ +package com.wms.dss.ats.customs.abb.utils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.Hashtable; +import com.wms.dss.ats.common.command.CarCommand; +import com.wms.dss.ats.common.command.CraneCommand; + +/** + * ÃèÊö: ÈÎÎñ»òÖ¸ÁîµÄÎļþ²Ù×÷ + * + * @author yao 2017-5-8 + * @since WMS 3.0 + */ +public class AllocatePropUtils { + /** + * ¹¦ÄÜ:»ñȡС³µÖ¸Áî + * + * @author hug 2013-5-8 + * @param strConfigPath + * @param bit + * @return + */ + public static CarCommand getLastCarCmd(String strConfigPath, byte bit, String xctype) { + FileInputStream fin = null; + ObjectInputStream in = null; + + try { + File file = new File(strConfigPath + "carcommand" + xctype + bit + ".dat"); + if (file.exists()) { + fin = new FileInputStream(file); + in = new ObjectInputStream(fin); + Object obj = in.readObject(); + if (obj != null) { + return (CarCommand) obj; + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + if (fin != null) { + try { + fin.close(); + } catch (Exception e) { + } + } + if (in != null) { + try { + in.close(); + } catch (Exception e) { + } + } + } + return null; + } + + /** + * ¹¦ÄÜ:±£´æÐ¡³µÖ¸Áî + * + * @author hug 2013-5-8 + * @param strConfigPath + * @param carCommand + * @param bit + */ + public static void saveCarCommand(String strConfigPath, CarCommand carCommand, byte bit, String xctype) { + FileOutputStream fos = null; + ObjectOutputStream out = null; + + try { + fos = new FileOutputStream(strConfigPath + "carcommand" + xctype + bit + ".dat"); + out = new ObjectOutputStream(fos); + out.writeObject(carCommand); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (Exception e) { + } + } + if (out != null) { + try { + out.close(); + } catch (Exception e) { + } + } + } + } + + /** + * ¹¦ÄÜ:±£´æ¶Ñ¶â»ú×îºóÏ·¢µÄÖ¸Áî + * + * @param strConfigPath + * @param bit + * @param craneCmd + */ + public static void saveCraneCommand(String strConfigPath, byte bit, CraneCommand craneCmd) { + FileOutputStream fos = null; + ObjectOutputStream out = null; + + try { + fos = new FileOutputStream(strConfigPath + "cranecommand" + bit + ".dat"); + out = new ObjectOutputStream(fos); + out.writeObject(craneCmd); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (Exception e) { + } + } + if (out != null) { + try { + out.close(); + } catch (Exception e) { + } + } + } + } + + /** + * ¹¦ÄÜ:±£´æÊäËÍÏß×îºóÏ·¢µÄÖ¸Áî + * + * @param strConfigPath + * @param bit + * @param craneCmd + */ + public static void saveSSXCommand(String strConfigPath, byte bit, Hashtable ssjcmd) { + FileOutputStream fos = null; + ObjectOutputStream out = null; + + try { + fos = new FileOutputStream(strConfigPath + "ssxcommand" + bit + ".dat"); + out = new ObjectOutputStream(fos); + out.writeObject(ssjcmd); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (Exception e) { + } + } + if (out != null) { + try { + out.close(); + } catch (Exception e) { + } + } + } + } + + /** + * ¹¦ÄÜ:±£´æÊäËÍÏß×îºóÏ·¢µÄÖ¸Áî + * + * @param strConfigPath + * @param bit + * @param craneCmd + */ + public static void saveSSXLCCommand(String strConfigPath, byte bit, Hashtable ssjcmd) { + FileOutputStream fos = null; + ObjectOutputStream out = null; + + try { + fos = new FileOutputStream(strConfigPath + "ssxcommandLC" + bit + ".dat"); + out = new ObjectOutputStream(fos); + out.writeObject(ssjcmd); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (Exception e) { + } + } + if (out != null) { + try { + out.close(); + } catch (Exception e) { + } + } + } + } + + /** + * ¹¦ÄÜ:±£´æ¸Ã¶Ñ¶â»úÈÎÎñ + * + * @param strConfigPath + * @param bit + * @param hsExecTask + */ +// public static void saveExecTask(String strConfigPath, byte bit, Hashtable hsExecTask) { +// FileOutputStream fos = null; +// ObjectOutputStream out = null; +// try { +// fos = new FileOutputStream(strConfigPath + "exectask" + bit + ".dat"); +// out = new ObjectOutputStream(fos); +// out.writeObject(hsExecTask); +// } catch (Exception ex) { +// ex.printStackTrace(); +// } finally { +// if (fos != null) { +// try { +// fos.close(); +// } catch (Exception e) { +// } +// } +// if (out != null) { +// try { +// out.close(); +// } catch (Exception e) { +// } +// } +// } +// } + + /** + * ¹¦ÄÜ:¶ÁÈ¡¶Ñ¶â»úδÍê³ÉµÄÈÎÎñ + * + * @param strConfigPath + * @param bit + * ¶Ñ¶â»úºÅ + * @return + */ +// public static Hashtable getLastExecTask(String strConfigPath, byte bit) { +// FileInputStream fin = null; +// ObjectInputStream in = null; +// try { +// File file = new File(strConfigPath + "exectask" + bit + ".dat"); +// if (file.exists()) { +// fin = new FileInputStream(file); +// in = new ObjectInputStream(fin); +// Object obj = in.readObject(); +// if (obj != null) { +// return (Hashtable) obj; +// } +// } +// } catch (Exception ex) { +// ex.printStackTrace(); +// } finally { +// if (fin != null) { +// try { +// fin.close(); +// } catch (Exception e) { +// } +// } +// if (in != null) { +// try { +// in.close(); +// } catch (Exception e) { +// } +// } +// } +// return null; +// } + + /** + * ¹¦ÄÜ:»ñÈ¡¶Ñ¶â»ú×îºóÖ¸Áî + * + * @param strConfigPath + * @param bit + * @return + */ +// public static CraneCommand getLastCraneCmd(String strConfigPath, byte bit) { +// FileInputStream fin = null; +// ObjectInputStream in = null; +// try { +// File file = new File(strConfigPath + "cranecommand" + bit + ".dat"); +// if (file.exists()) { +// fin = new FileInputStream(file); +// in = new ObjectInputStream(fin); +// Object obj = in.readObject(); +// if (obj != null) { +// return (CraneCommand) obj; +// } +// } +// } catch (Exception ex) { +// ex.printStackTrace(); +// } finally { +// if (fin != null) { +// try { +// fin.close(); +// } catch (Exception e) { +// } +// } +// if (in != null) { +// try { +// in.close(); +// } catch (Exception e) { +// } +// } +// } +// return null; +// } + + /** + * ¹¦ÄÜ:³ö¿â¶ËÈë¿ÚÊäËÍ»ú×îºóÖ¸Áî + * + * @param strConfigPath + * @param bit + * @return + */ + public static Hashtable getLastCKDRKSSJcmd(String strConfigPath, byte bit) { + FileInputStream fin = null; + ObjectInputStream in = null; + + try { + File file = new File(strConfigPath + "CKDRKSSJcmd" + bit + ".dat"); + if (file.exists()) { + fin = new FileInputStream(file); + in = new ObjectInputStream(fin); + Object obj = in.readObject(); + if (obj != null) { + return (Hashtable) obj; + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + if (fin != null) { + try { + fin.close(); + } catch (Exception e) { + } + } + if (in != null) { + try { + in.close(); + } catch (Exception e) { + } + } + } + + return null; + } + + /** + * ¹¦ÄÜ:»ñÈ¡ÊäËÍÏß×îºóÖ¸Áî + * + * @param strConfigPath + * @param bit + * @return + */ + public static Hashtable getLastCKDRKSSJcmdLC(String strConfigPath, byte bit) { + FileInputStream fin = null; + ObjectInputStream in = null; + + try { + File file = new File(strConfigPath + "CKDRKSSJcmdLC" + bit + ".dat"); + if (file.exists()) { + fin = new FileInputStream(file); + in = new ObjectInputStream(fin); + Object obj = in.readObject(); + if (obj != null) { + return (Hashtable) obj; + } + } + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + if (fin != null) { + try { + fin.close(); + } catch (Exception e) { + } + } + if (in != null) { + try { + in.close(); + } catch (Exception e) { + } + } + } + + return null; + } + + /** + * ¹¦ÄÜ:¶ÁÈ¡³öÍÐÅÌδÍê³ÉµÄÈÎÎñ + * + * @param strConfigPath + * @return + */ +// public static Hashtable getOutTrayExecTask(String strConfigPath) { +// FileInputStream fin = null; +// ObjectInputStream in = null; +// try { +// File file = new File(strConfigPath + "outtraytask.dat"); +// if (file.exists()) { +// fin = new FileInputStream(file); +// in = new ObjectInputStream(fin); +// Object obj = in.readObject(); +// if (obj != null) { +// return (Hashtable) obj; +// } +// } +// } catch (Exception ex) { +// ex.printStackTrace(); +// } finally { +// if (fin != null) { +// try { +// fin.close(); +// } catch (Exception e) { +// } +// } +// if (in != null) { +// try { +// in.close(); +// } catch (Exception e) { +// } +// } +// } +// return null; +// } + + /** + * ¹¦ÄÜ:±£´æ³öÍÐÅÌδÍê³ÉµÄÈÎÎñ + * + * @param strConfigPath + * @param bit + * @param hsExecTask + */ +// public static void saveOutTrayExecTask(String strConfigPath, Hashtable hsExecTask) { +// FileOutputStream fos = null; +// ObjectOutputStream out = null; +// try { +// fos = new FileOutputStream(strConfigPath + "outtraytask.dat"); +// out = new ObjectOutputStream(fos); +// out.writeObject(hsExecTask); +// } catch (Exception ex) { +// ex.printStackTrace(); +// } finally { +// if (fos != null) { +// try { +// fos.close(); +// } catch (Exception e) { +// } +// } +// if (out != null) { +// try { +// out.close(); +// } catch (Exception e) { +// } +// } +// } +// } + + /** + * ¹¦ÄÜ:¶ÁÈ¡³é¼ì³ö¿â»ò·µ°ü³ö¿âδÍê³ÉµÄÈÎÎñ + * + * @param strConfigPath + * @return + */ +// public static Hashtable getCJOutExecTask(String strConfigPath) { +// FileInputStream fin = null; +// ObjectInputStream in = null; +// try { +// File file = new File(strConfigPath + "cjouttask.dat"); +// if (file.exists()) { +// fin = new FileInputStream(file); +// in = new ObjectInputStream(fin); +// Object obj = in.readObject(); +// if (obj != null) { +// return (Hashtable) obj; +// } +// } +// } catch (Exception ex) { +// ex.printStackTrace(); +// } finally { +// if (fin != null) { +// try { +// fin.close(); +// } catch (Exception e) { +// } +// } +// if (in != null) { +// try { +// in.close(); +// } catch (Exception e) { +// } +// } +// } +// return null; +// } + + /** + * ¹¦ÄÜ:±£´æ³é¼ì³ö¿â»ò·µ°ü³ö¿âδÍê³ÉµÄÈÎÎñ + * + * @param strConfigPath + * @param bit + * @param hsExecTask + */ +// public static void saveCJOutExecTask(String strConfigPath, Hashtable hsExecTask) { +// FileOutputStream fos = null; +// ObjectOutputStream out = null; +// try { +// fos = new FileOutputStream(strConfigPath + "cjouttask.dat"); +// out = new ObjectOutputStream(fos); +// out.writeObject(hsExecTask); +// } catch (Exception ex) { +// ex.printStackTrace(); +// } finally { +// if (fos != null) { +// try { +// fos.close(); +// } catch (Exception e) { +// } +// } +// if (out != null) { +// try { +// out.close(); +// } catch (Exception e) { +// } +// } +// } +// } + +} diff --git a/src/com/wms/dss/ats/customs/abb/utils/CheckWeight.java b/src/com/wms/dss/ats/customs/abb/utils/CheckWeight.java new file mode 100644 index 0000000..1a9d11d --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/CheckWeight.java @@ -0,0 +1,106 @@ +package com.wms.dss.ats.customs.abb.utils; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; + +import static java.lang.Thread.sleep; + +public class CheckWeight { + + public static char[] getSubstring(char[] array) { + char start = '\u0002'; // ¿ªÊ¼×Ö·û + char end = '\r'; // ½áÊø×Ö·û + int startIndex = -1; + int endIndex = -1; + + // ±éÀú×Ö·ûÊý×éѰÕÒ¿ªÊ¼ºÍ½áÊø×Ö·ûµÄË÷Òý + for (int i = 0; i < array.length; i++) { + if (array[i] == start && startIndex == -1) { + startIndex = i; // ÕÒµ½¿ªÊ¼×Ö·û + } + if (array[i] == end) { + endIndex = i; // ÕÒµ½½áÊø×Ö·û + break; // ÕÒµ½ºó¿ÉÒÔÍ˳ö + } + } + + // ¼ì²éÊÇ·ñÕÒµ½ÓÐЧµÄ¿ªÊ¼ºÍ½áÊø×Ö·û + if (startIndex != -1 && endIndex != -1 && endIndex > startIndex) { + // ´´½¨ÐµÄ×Ö·ûÊý×éÒÔ´æ´¢½ØÈ¡µÄ×Ó×Ö·û´® + char[] substring = new char[endIndex - startIndex + 1]; + System.arraycopy(array, startIndex, substring, 0, substring.length); + return substring; // ·µ»Ø½ØÈ¡µÄ×Ó×Ö·û´® + } + + return null; // Èç¹ûûÓÐÕÒµ½ºÏÊʵÄ×Ö·û£¬·µ»Ø null + } + + + public static String interfaceUtil(String host, int port, String jsonString) throws IOException { + String taskback = null; + try (Socket socket = new Socket(host, port); // ʹÓÃtry-with-resourcesÈ·±£×ÊÔ´ÊÍ·Å + OutputStream os = socket.getOutputStream()) { + InputStream is = null; + byte[] buffer = jsonString.getBytes(); // ½«Êý¾Ýת»»Îª×Ö½ÚÊý×é + os.write(buffer); // ½«Êý¾ÝдÈëSocketÊä³öÁ÷ +// System.out.println("Data sent successfully."); + is = socket.getInputStream();// + sleep(1000); + int size = is.available(); + if (size > 0) { +// System.out.println(floor+"²ã:Ocr" + "½ÓÊÜÏìÓ¦³¤¶È£º" + size); + byte[] resp = new byte[size]; + is.read(resp); + taskback = taskback(resp);//Â¥²ã£¬ÖØÁ¿£¬Åú´Î£¬ÈÕÆÚ + } + } catch (IOException |InterruptedException e) { + e.printStackTrace(); + } + + + return taskback; + } + + + public static String taskback(byte[] arr) { + + StringBuilder sb = new StringBuilder(); + for (int asciiValue : arr) { + char character = (char) asciiValue; + sb.append(character); + } + String str = sb.toString(); + + return str; + } + + public static String WeightOut(String ip, Integer port) { + String Num = ""; + try { + String s = interfaceUtil(ip, port, ""); + char[] charArray = s.toCharArray(); + if (charArray.length > 0) { + // Êý×é½ØÈ¡ + char[] result = getSubstring(charArray); + if(result == null){ + result = new char[]{0, 0, 0, 0, 0, 0,0,0,0,0}; + Num = "0"; + }else{ + String s1 = new String(result); + String substring = s1.substring(6, 8); + String substring1 = s1.substring(8, 10); + Num = substring + "." + substring1; + } + + } + + } catch (IOException e) { + throw new RuntimeException(e); + } + return Num; + } + + +} diff --git a/src/com/wms/dss/ats/customs/abb/utils/ConstantUtils.java b/src/com/wms/dss/ats/customs/abb/utils/ConstantUtils.java new file mode 100644 index 0000000..7118905 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/ConstantUtils.java @@ -0,0 +1,242 @@ +package com.wms.dss.ats.customs.abb.utils; + +/** + * @author zn kai + * @create 2021-10-27 15:48 + */ +public interface ConstantUtils { + String LED_IP_3 = "192.168.10.227"; + String LED_IP_4 = "192.168.10.226"; + + int AGV_POWER_SMALL = 30; + + int AGV_POWER_MIDDLE = 50; + + int AGV_POWER_MAX = 100; + + /** + * ³äµç¼ÆÊ± + */ + long AGV_FREE_TIME = 30L; + + + /** + * ±ÜÈõã + */ + int AVOID_ADDRESS_X_1 = 7; + int AVOID_ADDRESS_Y_1 = 11; + + int AVOID_ADDRESS_X_2 = 9; + int AVOID_ADDRESS_Y_2 = 11; + + + int AVOID_ADDRESS_X_3 = 7; + int AVOID_ADDRESS_Y_3 = 41; + + + int AVOID_ADDRESS_X_4 = 9; + int AVOID_ADDRESS_Y_4 = 41; + + int POWER_ADDRESS_X = 7; + int POWER_ADDRESS_Y = 12; + + + /** + * agvÖ¸Áîβ + */ + String AGV_ORDER_LAST = "03FC"; + + + /** + * ²»Ö´ÐÐÈκζ¯×÷ + */ + String AGV_ORDER_EMPTY = "00"; + + /** + * È¡»õ + */ + String AGV_ORDER_QH = "01"; + + /** + * ·Å»õ + */ + String AGV_ORDER_FH = "02"; + + /** + * ³äµç + */ + String AGV_ORDER_CHARGE = "03"; + + /** + * ¹Ø±Õ³äµç + */ + String AGV_ORDER_CLEAR_CHARGE = "04"; + + /** + * »»ÆÂµÀ + */ + String AGV_ORDER_TO_SLOP = "05"; + + /** + * »»ÏïµÀ + */ + String AGV_ORDER_TO_ROADWAY = "06"; + + /** + * ÍÐÅÌУ׼+ÍÐÅ̶¥Éý + */ + String AGV_ORDER_TRAY_CHECK = "09"; + + /** + * ÔÝÍ£»Ö¸´ + */ + String AGV_ORDER_STOP_REGAIN = "82"; + + /** + * °´ËÙ¶ÈÔÝÍ£ + */ + String AGV_ORDER_STOP = "87"; + + /** + * ³õʼ»¯Ö¸Áî + */ + String AGV_ORDER_RESET = "8E"; + + String AGV_ORDER_REVOKE = "8F"; + + + /** + * ÈÎÎñ½á¹û ---ÈÎÎñÖ´Ðгɹ¦ + */ + String AGV_TASK_RESULT_0 = "00"; + + /** + * ÈÎÎñ½ÓÊճɹ¦ + */ + String AGV_TASK_RESULT_1 = "01"; + + /** + * ½ÓÊÕµ½Öظ´ÈÎÎñ + */ + String AGV_TASK_RESULT_2 = "02"; + + + /** + * ²Ù×÷Ö¸Áî½á¹û--- ÈÎÎñÖ´Ðгɹ¦ + */ + String AGV_EXECUTE_RESULT_0 = "00"; + + /** + * ½ÓÊճɹ¦ + */ + String AGV_EXECUTE_RESULT_1 = "01"; + + /** + * ½ÓÊÕµ½Öظ´Ö¸Áî + */ + String AGV_EXECUTE_RESULT_2 = "02"; + + + /** + * С³µ×´Ì¬ ÈÎÎñÖ´ÐÐÖÐ + */ + String AGV_STATUS_HEX_1 = "01"; + + /** + * Ö¸ÁîÖ´ÐÐÖÐ + */ + String AGV_STATUS_HEX_2 = "02"; + + /** + * ÈÎÎñÖ´ÐÐÖÐ + */ + int AGV_STATUS_1 = 1; + + /** + * ¾ÍÐ÷ + */ + int AGV_STATUS_3 = 3; + + /** + * ÔÝÍ£ + */ + int AGV_STATUS_4 = 4; + + /** + * ³äµçÖÐ + */ + int AGV_STATUS_5 = 5; + + + /** + * ½Úµã´ýÃü + */ + String AGV_STATUS_11 = "0B"; + + /** + * ÎÞÕϰ­Â·¾¶ + */ + int PATH_BLOCK_EMPTY = 1; + + /** + * ÓÐÕϰ­Â·¾¶ + */ + int PATH_BLOCK = 2; + + /** + * Èë + */ + int QUEUE_RWLX_1 = 1; + + /** + * ³ö + */ + int QUEUE_RWLX_2 = 2; + + /** + * ±ÜÈà + */ + int QUEUE_RWLX_3 = 3; + + /** + * »»²ã + */ + int QUEUE_RWLX_4 = 4; + + /** + * ÒÆ¿â + */ + int QUEUE_RWLX_5 = 5; + + /** + * ³õʼ + */ + int QUEUE_ZXJD_0 = 0; + + /** + * È¡»õ + */ + int QUEUE_ZXJD_1 = 1; + + /** + * ·Å»õ + */ + int QUEUE_ZXJD_2 = 2; + + /** + * ³õʼ + */ + int QUEUE_RWZT_0 = 0; + + /** + * Ï·¢ + */ + int QUEUE_RWZT_1 = 1; + + /** + * Íê³É + */ + int QUEUE_RWZT_2 = 2; + + +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/utils/HTTPREST.java b/src/com/wms/dss/ats/customs/abb/utils/HTTPREST.java new file mode 100644 index 0000000..5c6b08f --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/HTTPREST.java @@ -0,0 +1,34 @@ +package com.wms.dss.ats.customs.abb.utils; + + +import com.google.gson.Gson; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.util.HashMap; +import java.util.Map; + +/** + * @author ZGW + */ +public class HTTPREST { + private static final Map paramHeader = new HashMap<>(); +// µ÷ÓÃrest ½Ó¿ÚµÄÄ£°å +// public static RK_Return buildRkJob(SizeJobBuild sizeJobBuild){ +// Gson gson = new Gson(); +// String exportTaskJson = gson.toJson(sizeJobBuild); +// System.out.println(exportTaskJson); +// String jsonResult = null; +// RK_Return rkReturn=new RK_Return(); +// try { +// //TODO Éú³ÉÈë¿â×÷Òµ½Ó¿Úµ÷Óà +// jsonResult = HttpClientUtility.sendPost("http://127.0.0.1:8099/out/mydojob/generate/job",exportTaskJson,paramHeader); +// rkReturn=gson.fromJson(jsonResult,RK_Return.class); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// return rkReturn; +// } +} diff --git a/src/com/wms/dss/ats/customs/abb/utils/HttpClientUtility.java b/src/com/wms/dss/ats/customs/abb/utils/HttpClientUtility.java new file mode 100644 index 0000000..8b50d4b --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/HttpClientUtility.java @@ -0,0 +1,196 @@ +package com.wms.dss.ats.customs.abb.utils; + +import org.apache.http.HttpEntity; +import org.apache.http.NameValuePair; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +//import com.sap.me.frame.BasicBOBeanException; +//import com.sap.me.frame.Data; + +/** + * @author zhihao.sang + * @Description: restful请求工具类 + * @date 2020å¹´6月25æ—¥ 上å�ˆ11:14:31 + */ +public class HttpClientUtility { + + /** + * @Description: å�‘é€�带jsonå�‚æ•°ã€�Headerçš„post请求至ThingWorx + * @param url + * @param jsonString + * @param paramHeader + * @return + * @throws IOException + * @throws BasicBOBeanException + */ +// public static String thingWorxPost(String url, String jsonString, Map paramHeader) throws IOException, BasicBOBeanException { +// // 创建请求客户端 +// CloseableHttpClient httpClient = HttpClients.custom().build(); +// // 创建post请求 +// HttpPost httpPost = new HttpPost(url); +// // 设置headerä¿¡æ�¯ +// setHeader(httpPost, paramHeader); +// // 设置JSONæ•°æ�® +// StringEntity entityStr = new StringEntity(jsonString, ContentType.APPLICATION_JSON); +// httpPost.setEntity(entityStr); +// // 设置连接超时时间:15ç§’ +// httpPost.setConfig(RequestConfig.custom().setConnectTimeout(15000).build()); +// // 执行并获å�–返回 +// CloseableHttpResponse response = httpClient.execute(httpPost); +// HttpEntity entity = response.getEntity(); +// String resp = EntityUtils.toString(entity, StandardCharsets.UTF_8); +// EntityUtils.consume(entity); +// // 关闭连接 +// response.close(); +// if (response.getStatusLine().getStatusCode() != 200) { +// // 20226.simple = 调用Thingworx接å�£å¤±è´¥ï¼š%MESSAGE% +// throw new BasicBOBeanException(20226, new Data("MESSAGE", resp)); +// } +// return resp; +// } + + /** + * @Description: 请求头赋值 + * @param request + * @param paramHeader + */ + private static void setHeader(HttpRequestBase request, Map paramHeader) { + // 设置Header + if (paramHeader != null) { + paramHeader.forEach(request::addHeader); + } + } + + + /** + * + * @Description: 带æ�ƒé™�的请求 + * @param url + * @param jsonString + * @param paramHeader + * @param userName + * @param password + * @return + * @throws IOException + */ + public static String sendPost(String url, String jsonString, Map paramHeader, String userName, String password) throws IOException { + CredentialsProvider provider = new BasicCredentialsProvider(); + UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password); + provider.setCredentials(AuthScope.ANY, credentials); + CloseableHttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(provider).build(); + String resp = ""; + HttpPost httpPost = new HttpPost(url); + setHeader(httpPost, paramHeader); + StringEntity entityStr = new StringEntity(jsonString, ContentType.create("text/plain", "UTF-8")); + httpPost.setEntity(entityStr); + CloseableHttpResponse response = null; + response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + resp = EntityUtils.toString(entity, "UTF-8"); + EntityUtils.consume(entity); + response.close(); + if (resp == null || resp.equals("")) { + return ""; + } + return resp; + } + + /** + * + * @Description: å�‘é€�带jsonå�‚æ•°ã€�Headerçš„post请求 + * @param url + * @param jsonString + * @param paramHeader + * @return + * @throws IOException + */ + public static String sendPost(String url, String jsonString, Map paramHeader) throws IOException { + if (jsonString == null || jsonString.isEmpty()) { + return sendPost(url, paramHeader); + } + String resp = ""; + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(url); + httpPost.setHeader("Authorization",paramHeader.get("Authorization")); + setHeader(httpPost, paramHeader); + StringEntity entityStr = new StringEntity(jsonString, ContentType.create("application/json", "UTF-8")); + httpPost.setEntity(entityStr); + CloseableHttpResponse response = null; + response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + resp = EntityUtils.toString(entity, "UTF-8"); + EntityUtils.consume(entity); + response.close(); + if (resp == null || resp.equals("")) { + return ""; + } + return resp; + } + + /** + * + * @Description: å�‘é€�带Headerçš„HttpPost请求 + * @param url + * @param paramHeader + * @return + * @throws IOException + */ + public static String sendPost(String url, Map paramHeader) throws IOException { + // 1.获得一个httpclient对象 + CloseableHttpClient httpclient = HttpClients.createDefault(); + // 2.生æˆ�一个post请求 + HttpPost httpPost = new HttpPost(url); + // setHeader(httpPost, paramHeader); + CloseableHttpResponse response = null; + //创建å�‚数列表 + if(paramHeader!=null){ + List paramValueList = new ArrayList(); + for (String key : paramHeader.keySet()) { + Object value = paramHeader.get(key); + if(value!=null){ + paramValueList.add(new NameValuePair() { + + @Override + public String getValue() { + return value + ""; + } + + @Override + public String getName() { + return key; + } + }); + + } + } + //模拟表å�• + UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramValueList, "UTF-8"); + httpPost.setEntity(entity); + } + // 3.执行post请求并返回结果 + response = httpclient.execute(httpPost); + // 4.处ç�†ç»“果,这里将结果返回为字符串 + HttpEntity entity = response.getEntity(); + String result = null; + result = EntityUtils.toString(entity); + return result; + } + +} diff --git a/src/com/wms/dss/ats/customs/abb/utils/HttpConnection.java b/src/com/wms/dss/ats/customs/abb/utils/HttpConnection.java new file mode 100644 index 0000000..3b6c000 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/HttpConnection.java @@ -0,0 +1,109 @@ +package com.wms.dss.ats.customs.abb.utils; + +import com.ricosoft.common.logger.Logger; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.URL; + +/** + * @author zn kai + * @create 2020-06-02 17:49 + */ +public class HttpConnection { + + /** + * µ÷ÓÃwms½Ó¿Ú + * + * @param uri µØÖ· + * @param data ÇëÇóÊý¾Ý + */ + public static String httpConn(String uri, String data) { + String le = null; + HttpURLConnection conn = null; + try { + URL url = new URL(uri); + conn = (HttpURLConnection) url.openConnection(); + //µ±´´½¨ÁËÒ»¸öHttpURLConnectionºó,Æäʵµ×²ã´´½¨ÁËÒ»¸ösocket¶ÔÏó + conn.setConnectTimeout(3000);//ÉèÖÃÁ¬½ÓÖ÷»ú³¬Ê±Ê±¼ä + conn.setReadTimeout(2000);//ÉèÖôÓÖ÷»ú¶ÁÈ¡Êý¾Ý³¬Ê±Ê±¼ä + conn.setRequestMethod("POST");//ÇëÇó·½Ê½ + conn.setDoOutput(true);//¶ÁÈ¡Êä³öÁ÷£¬ÔÚʹÓÃPOSTÏò·þÎñÆ÷Ìá½»Êý¾Ýʱ±ØÐëÒª½«¸Ã·½·¨ÉèÖÃΪtrue + conn.setDoInput(true);// ÉèÖÃÊÇ·ñ´ÓhttpUrlConnection¶ÁÈ룬ĬÈÏÇé¿öÏÂÊÇtrue; + conn.setUseCaches(false);//postÇëÇó²»ÄÜʹÓûº´æ + //conn.setRequestProperty("Connection", "Keep-Alive"); + //É趨´«Ë͵ÄÄÚÈÝÀàÐÍÊÇ¿ÉÐòÁл¯µÄjava¶ÔÏó + //conn.setRequestProperty("Content-type", "application/x-java-serialized-object"); + // Á¬½Ó£¬´ÓÉÏÊöurl.openConnection()ÖÁ´ËµÄÅäÖñØÐëÒªÔÚconnect֮ǰÍê³É£¬ + conn.connect(); + //дÈëÐèÒª·¢Ë͵ÄÊý¾Ý + String body = "job=job1&jobGroup=jobGroup1"; + + //par p = new par(); + //p.setJob("1"); + //p.setJobGroup("1"); + //String json = JsonUtil.getJson(p); + + //´Ë´¦getOutputStream»áÒþº¬µÄ½øÐÐconnect(¼´£ºÈçͬµ÷ÓÃÉÏÃæµÄconnect()·½·¨, ËùÒÔ²»µ÷ÓÃÉÏÊöµÄconnect()Ò²¿ÉÒÔ + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8")); + writer.write(data); + writer.close();//closeÖ´Ðлáflush + //·þÎñÆ÷·µ»ØµÄ״̬Âë + int responseCode = conn.getResponseCode(); + + //¶ÁÈ¡·þÎñÆ÷·µ»ØµÄÊý¾Ý + BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8")); + StringBuilder response = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + response.append(line); + } + //¶ÁÈ¡ÍêÏìÓ¦Êý¾ÝÖ®ºó,µ÷ÓÃclose·½·¨¹Ø±ÕÊäÈëÁ÷, + // JDK httpЭÒé´¦ÀíÆ÷»á½«Õâ¸öÁ¬½Ó·Åµ½Ò»¸öÁ¬½Ó»º´æÖУ¬ÒÔ±ãÖ®ºóµÄHTTPÇëÇó½øÐи´Óà + reader.close(); + //System.err.println("statusCode:"+responseCode+"------status:"+response.toString()); + le = response.toString(); + } catch (Exception e) { + Logger.info("wms½Ó¿ÚÁ¬½Óʧ°Ü::" + e.getMessage()); + try { + Thread.sleep(500); + } catch (InterruptedException e1) { + + } + } finally { + if (conn != null) { + //¹Ø±Õ Http Á¬½Ó,ÊÍ·Å×ÊÔ´ + conn.disconnect(); //±íʾ¹Ø±Õµ×²ãsocketÁ¬½Ó£¬²»»áÆôÓÃkeepAlive + } + } + return le; + } + + public static void main(String[] args) { + String a= "1aa"; + String b= "2bb"; + String c= "3cc"; + String result = HttpConnection.httpConn("http://10.182.211.121:8888/api/hik/HIK/selectTask", "eqpId="+a+"&materialBaseId="+b+"&lotId="+c); + System.out.println("·µ»Ø½á¹û£º£º£º£º£º£º"+result); + + String ddjleftTaskNo = "000001"; + Long aLong = Long.valueOf(ddjleftTaskNo); + System.out.println("aLong:::"+aLong); + + String trayCode = HttpConnection.httpConn("http://10.182.211.121:8888/rfid/three", "ip=10.182.28.249"); + System.err.println("¶Áµ½RFIDÍÐÅÌÂë:::::::"+trayCode); + + long l = System.currentTimeMillis(); + + System.out.println(l); +// +// UUID uuid = UUID.randomUUID();//uuid +// String a=uuid.toString().replace("-", "").toUpperCase();//ÍÐÅÌÂëÁÙʱ´ëÊ© +//// String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));//ÍÐÅÌÂëÁÙʱ´ëÊ© +// String trayCode = "NOREAD"+a; +// System.out.println(trayCode); + } +} diff --git a/src/com/wms/dss/ats/customs/abb/utils/LEDSender2010.java b/src/com/wms/dss/ats/customs/abb/utils/LEDSender2010.java new file mode 100644 index 0000000..bd56403 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/LEDSender2010.java @@ -0,0 +1,3230 @@ +package com.wms.dss.ats.customs.abb.utils; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.font.FontRenderContext; +import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Calendar; + +public class LEDSender2010 { + + // ====ÒýÈ붯×÷·½Ê½Áбí(ÊýÖµ´Ó0¿ªÊ¼)==== + // 0 = 'Ëæ»ú', + // 1 = 'Á¢¼´ÏÔʾ', + // 2 = '×ó¹öÏÔʾ', + // 3 = 'ÉϹöÏÔʾ', + // 4 = 'ÓÒ¹öÏÔʾ', + // 5 = 'ϹöÏÔʾ', + // 6 = 'Á¬Ðø×ó¹öÏÔʾ', + // 7 = 'Á¬ÐøÉϹöÏÔʾ', + // 8 = 'Á¬ÐøÓÒ¹öÏÔʾ', + // 9 = 'Á¬ÐøÏ¹öÏÔʾ', + // 10 = 'ÖмäÏòÉÏÏÂÕ¹¿ª', + // 11 = 'ÖмäÏòÁ½±ßÕ¹¿ª', + // 12 = 'ÖмäÏòËÄÖÜÕ¹¿ª', + // 13 = '´ÓÓÒÏò×óÒÆÈë', + // 14 = '´Ó×óÏòÓÒÒÆÈë', + // 15 = '´Ó×óÏòÓÒÕ¹¿ª', + // 16 = '´ÓÓÒÏò×óÕ¹¿ª', + // 17 = '´ÓÓÒÉϽÇÒÆÈë', + // 18 = '´ÓÓÒϽÇÒÆÈë', + // 19 = '´Ó×óÉϽÇÒÆÈë', + // 20 = '´Ó×óϽÇÒÆÈë', + // 21 = '´ÓÉÏÏòÏÂÒÆÈë', + // 22 = '´ÓÏÂÏòÉÏÒÆÈë', + // 23 = 'ºáÏò°ÙÒ¶´°', + // 24 = '×ÝÏò°ÙÒ¶´°', + // ===================================== + + // ====Òý³ö¶¯×÷·½Ê½Áбí(ÊýÖµ´Ó0¿ªÊ¼)==== + // 0 = 'Ëæ»ú', + // 1 = '²»Ïûʧ', + // 2 = 'Á¢¼´Ïûʧ', + // 3 = 'ÉÏÏÂÏòÖмäºÏ£', + // 4 = 'Á½±ßÏòÖмäºÏ£', + // 5 = 'ËÄÖÜÏòÖмäºÏ£', + // 6 = '´Ó×óÏòÓÒÒÆ³ö', + // 7 = '´ÓÓÒÏò×óÒÆ³ö', + // 8 = '´ÓÓÒÏò×óºÏ£', + // 9 = '´Ó×óÏòÓҺϣ', + // 10 = '´ÓÓÒÉϽÇÒÆ³ö', + // 11 = '´ÓÓÒϽÇÒÆ³ö', + // 12 = '´Ó×óÉϽÇÒÆ³ö', + // 13 = '´Ó×óϽÇÒÆ³ö', + // 14 = '´ÓÏÂÏòÉÏÒÆ³ö', + // 15 = '´ÓÉÏÏòÏÂÒÆ³ö', + // 16 = 'ºáÏò°ÙÒ¶´°', + // 17 = '×ÝÏò°ÙÒ¶´°' + // ===================================== + + // ====Í£Áô¶¯×÷·½Ê½Áбí(ÊýÖµ´Ó0¿ªÊ¼)==== + // 0 = '¾²Ì¬ÏÔʾ', + // 1 = 'ÉÁ˸ÏÔʾ' + // ===================================== + + public static final int PKP_PREFIX = 0x55; + public static final int PKP_SUFFIX = 0xAA; + public static final int PKP_FILLCH = 0xBB; + + public static final int ALIGN_LEFT = 0x0; + public static final int ALIGN_TOP = 0x0; + public static final int ALIGN_CENTER = 0x1; + public static final int ALIGN_RIGHT = 0x2; + public static final int ALIGN_BOTTOM = 0x2; + + public static final int ROOT_PLAY = 0x21; //½ÚÄ¿Êý¾Ý£¬±£´æµ½RAM£¬µôµç¶ªÊ§ + public static final int ROOT_DOWNLOAD = 0x22; //½ÚÄ¿Êý¾Ý£¬±£´æµ½Flash + public static final int ROOT_PLAY_CHAPTER = 0x23; //²åÈë»òÕ߸üÐÂijһĻ + public static final int ROOT_DOWNLOAD_CHAPTER = 0x24; + public static final int ROOT_PLAY_REGION = 0x25; //²åÈë»òÕ߸üÐÂijһ·ÖÇø + public static final int ROOT_DOWNLOAD_REGION = 0x26; + public static final int ROOT_PLAY_LEAF = 0x27; //²åÈë»òÕ߸üÐÂÄ³Ò»Ò³Ãæ + public static final int ROOT_DOWNLOAD_LEAF = 0x28; + public static final int ROOT_PLAY_OBJECT = 0x29; //²åÈë»òÕ߸üÐÂijһ¶ÔÏó + public static final int ROOT_DOWNLOAD_OBJECT = 0x2a; + + public static final int COLOR_TYPE_DOUBLE = 0x2; + public static final int COLOR_TYPE_THREE = 0x3; + public static final int COLOR_TYPE_FULL = 0x4; + + public static final int BITMAP_RED = 0x1; + public static final int BITMAP_GREEN = 0x2; + public static final int BITMAP_YELLOW = 0x3; + public static final int BITMAP_COLOR = 0x4; + public static final int BITMAP_RGB = 0x3; + public static final int BITMAP_FULLCOLOR = 0x5; + + public static final int PKC_BEGIN = 0; + public static final int PKC_END = 1; + public static final int PKC_DATA = 2; + public static final int PKC_RESPOND = 3; + public static final int PKC_NOTIFY = 100; + + public static final int PKC_ADJUST_TIME = 6; + public static final int PKC_GET_PARAM = 7; + public static final int PKC_SET_PARAM = 8; + public static final int PKC_GET_POWER = 9; + public static final int PKC_SET_POWER = 10; + public static final int PKC_GET_BRIGHT = 11; + public static final int PKC_SET_BRIGHT = 12; + public static final int PKC_COM_TRANSFER = 21; + public static final int PKC_SET_SWITCH = 27; + public static final int PKC_GET_POWER_SCHEDULE = 60; + public static final int PKC_SET_POWER_SCHEDULE = 61; + public static final int PKC_RESET_DISPLAY = 99; + + public static final int OBJECT_CHAPTER = 0x3F; + public static final int OBJECT_REGION = 0x3E; + public static final int OBJECT_LEAF = 0x30; + public static final int OBJECT_WINDOW = 0x31; + public static final int OBJECT_DCLOCK = 0x32; + public static final int OBJECT_STRING = 0x33; + public static final int OBJECT_STRING_DCLOCK = 0x35; + public static final int OBJECT_PIXELS = 0x36; + public static final int OBJECT_PIXELSET = 0x37; + public static final int OBJECT_WINDOWS = 0x3B; + public static final int OBJECT_STRINGS = 0x3C; + public static final int OBJECT_SCHEDULE_WINDOW = 0x3E; + public static final int OBJECT_VOICE = 0x5F; + + public static final int DF_YEAR = 1; + public static final int DF_MONTH = 2; + public static final int DF_DAY = 3; + public static final int DF_WEEK = 4; + public static final int DF_HOUR = 5; + public static final int DF_MINUTE = 6; + public static final int DF_SECOND = 7; + public static final int DF_USER = 8; + + public static final int NOTIFY_ROOT_DOWNLOAD = 0x00010003; //¸üÐÂFlash²¥·Å½ÚÄ¿ + public static final int NOTIFY_ROOT_PLAY = 0x00020003; //¸üÐÂFlash²¥·Å½ÚÄ¿ + + /* + typedef struct PKG_HEADER{ + WORD Command; + BYTE srcAddr; + BYTE dstAddr; + DWORD SerialNo; + }TPKG_Header, *PPKG_Header; + */ + static final int PKG_HEADER_STRUCT_SIZE = 8; //2+1+1+4 + static final int PKG_HEADER_COMMAND_OFFSET = 0; + static final int PKG_HEADER_SRCADDR_OFFSET = 2; + static final int PKG_HEADER_DSTADDR_OFFSET = 3; + static final int PKG_HEADER_SERIALNO_OFFSET = 4; + + /* + typedef struct _SYSTEMTIME { + WORD wYear; + WORD wMonth; + WORD wDayOfWeek; + WORD wDay; + WORD wHour; + WORD wMinute; + WORD wSecond; + WORD wMilliseconds; + } SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME; + */ + static final int SYSTEMTIME_SIZE = 16; + static final int SYSTEMTIME_YEAR_OFFSET = 0; + static final int SYSTEMTIME_MONTH_OFFSET = 2; + static final int SYSTEMTIME_WEEK_OFFSET = 4; + static final int SYSTEMTIME_DAY_OFFSET = 6; + static final int SYSTEMTIME_HOUR_OFFSET = 8; + static final int SYSTEMTIME_MINUTE_OFFSET = 10; + static final int SYSTEMTIME_SECOND_OFFSET = 12; + static final int SYSTEMTIME_MSECOND_OFFSET = 14; + + /* + TPowerSchedule = packed record + Enabled: DWord; + Mode: DWord; + OpenTime: array [0..20] of TTimeStamp; + CloseTime: array [0..20] of TTimeStamp; + Checksum: DWord; + end; + PPowerSchedule = ^TPowerSchedule; + */ + static final int PWOERSCHEDULE_SIZE = 348; + static final int PWOERSCHEDULE_ENABLED_OFFSET = 0; + static final int PWOERSCHEDULE_MODE_OFFSET = 4; + static final int PWOERSCHEDULE_OPENTIME_OFFSET = 8; + static final int PWOERSCHEDULE_CLOSETIME_OFFSET = 176; + static final int PWOERSCHEDULE_SUNDAY_OPENTIME_OFFSET = 8; + static final int PWOERSCHEDULE_SUNDAY_CLOSETIME_OFFSET = 176; + static final int PWOERSCHEDULE_MONDAY_OPENTIME_OFFSET = 32; + static final int PWOERSCHEDULE_MONDAY_CLOSETIME_OFFSET = 200; + static final int PWOERSCHEDULE_TUESDAY_OPENTIME_OFFSET = 56; + static final int PWOERSCHEDULE_TUESDAY_CLOSETIME_OFFSET = 224; + static final int PWOERSCHEDULE_WEDNESDAY_OPENTIME_OFFSET = 80; + static final int PWOERSCHEDULE_WEDNESDAY_CLOSETIME_OFFSET = 248; + static final int PWOERSCHEDULE_THURSDAY_OPENTIME_OFFSET = 104; + static final int PWOERSCHEDULE_THURSDAY_CLOSETIME_OFFSET = 272; + static final int PWOERSCHEDULE_FRIDAY_OPENTIME_OFFSET = 128; + static final int PWOERSCHEDULE_FRIDAY_CLOSETIME_OFFSET = 296; + static final int PWOERSCHEDULE_SATURDAY_OPENTIME_OFFSET = 152; + static final int PWOERSCHEDULE_SATURDAY_CLOSETIME_OFFSET = 320; + + /* + //Êý¾ÝÁ÷Í·²¿ + typedef struct ROOT{ + WORD id; + WORD color; + DWORD size; + DWORD count; + long survive; + WORD flag; + WORD Reserved; + }TRoot, *PRoot; + */ + static final int ROOT_STRUCT_SIZE = 20; //2+2+4+4+4+2+2 + static final int ROOT_COLORTYPE_OFFSET = 2; + static final int ROOT_SIZE_OFFSET = 4; + static final int ROOT_COUNT_OFFSET = 8; + static final int ROOT_SURVIVE_OFFSET = 12; + static final int ROOT_FLAG_OFFSET = 16; + + /* + //¾Ö²¿Ë¢Ð²Ù×÷Êý¾Ý½á¹¹ÉùÃ÷ + typedef struct CUSTOMACTION{ + TRoot header; //Êý¾ÝÁ÷Í·²¿ + WORD actionmode; //²Ù×÷ģʽ(²åÈë/Ìæ»») + WORD chapterindex; //ÔÚÄĸöÕ½ڲåÈë»òÕßÌæ»» + WORD regionindex; //ÔÚÄĸöÇøÓò´°²åÈë»òÕßÌæ»» + WORD leafindex; //ÔÚÄĸöÒ³Ãæ²åÈë»òÕßÌæ»» + WORD objectindex; //ÔÚÄĸöλÖòåÈë»òÕßÌæ»»¿Ø¼þ + WORD reserved; + }TCustomAction, *PCustomAction; + */ + static final int ROOT_SUB_STRUCT_SIZE = ROOT_STRUCT_SIZE + 12; //2+2+4+4+4+2+2 + static final int ROOT_SUB_ACTION_MODE = 0; + static final int ROOT_SUB_CHAPTER_INDEX = 2; + static final int ROOT_SUB_REGION_INDEX = 4; + static final int ROOT_SUB_LEAF_INDEX = 6; + static final int ROOT_SUB_OBJECT_INDEX = 8; + + /* + typedef struct PLAYSCHEDULE{ + WORD kind; //²¥·Å¼Æ»®ÀàÐÍ0=ʼÖÕ²¥·Å£»1=°´Ã¿ÈÕÆðֹʱ¼ä²¥·Å£»3=°´Ö¸¶¨µÄÆðÖ¹ÈÕÆÚʱ¼ä²¥·Å + WORD week; //ÐÇÆÚÈÕµ½ÁùÄÄÌìÓÐЧ + TTimeStamp fromtime; //¿ªÊ¼Ê±¼ä + TTimeStamp totime; //½áÊøÊ±¼ä + }TPlaySchedule, *PPlaySchedule; + */ + static final int PLAY_SCHEDULE_SIZE = 20; + static final int PLAY_SCHEDULE_KIND_OFFSET = 0; + static final int PLAY_SCHEDULE_WEEK_OFFSET = 2; + static final int PLAY_SCHEDULE_FROMTIME_OFFSET = 4; + static final int PLAY_SCHEDULE_FROMDATE_OFFSET = 8; + static final int PLAY_SCHEDULE_TOTIME_OFFSET = 12; + static final int PLAY_SCHEDULE_TODATE_OFFSET = 16; + /* + //Õ½ÚÊý¾Ý½á¹¹Ìå + typedef struct CHAPTER{ + WORD id; //±êʶ£¬ÓÃÓÚÊý¾ÝУÑé + WORD no; //½ÚÄ¿±àºÅ£¬ÖÃ0 + WORD wait; //ÊÇ·ñµÈ´ý²¥·ÅÍê³É(=1µÈ´ý; =0µ½Ê±¼ä¾ÍÇÐ) + WORD repeat; //½ÚÄ¿²¥·Å´ÎÊý£¬Ô¤ÁôδʵÏÖ£¬ÖÃ0 + WORD count; //Âß¼­´°¿ÚÊýÁ¿ + BYTE compress; //ÊÇ·ñѹËõ£¬Ô¤ÁôδʵÏÖ£¬ÖÃ0 + BYTE priority; //ÓÅÏȼ¶£¬Ô¤ÁôδʵÏÖ£¬ÖÃ0 + DWORD time; //½ÚÄ¿ÏÔʾʱ³¤£¬µ¥Î»ºÁÃë + DWORD size; //±êʶ¸Ã½ÚÄ¿×Ö½ÚÊý(°üº¬Êý¾Ý×Ö½ÚÊýºÍ¸ÃÔªËØ±¾Éí×Ö½ÚÊýÖ®ºÍ) + TPlaySchedule schedule; //²¥·Å¼Æ»® + }TChapter, *PChapter; + */ + static final int CHAPTER_STRUCT_SIZE = 20 + PLAY_SCHEDULE_SIZE; //2+2+2+2+2+1+1+4+4+PLAY_SCHEDULE_SIZE + static final int CHAPTER_SIZE_OFFSET = 16; + static final int CHAPTER_COUNT_OFFSET = 8; + static final int CHAPTER_WAIT_OFFSET = 4; + static final int CHAPTER_PRIORITY_OFFSET = 11; + static final int CHAPTER_TIME_OFFSET = 12; + static final int CHAPTER_PLAY_SCHEDULE_KIND_OFFSET = 20 + PLAY_SCHEDULE_KIND_OFFSET; + static final int CHAPTER_PLAY_SCHEDULE_WEEK_OFFSET = 20 + PLAY_SCHEDULE_WEEK_OFFSET; + static final int CHAPTER_PLAY_SCHEDULE_FROMTIME_OFFSET = 20 + PLAY_SCHEDULE_FROMTIME_OFFSET; + static final int CHAPTER_PLAY_SCHEDULE_FROMDATE_OFFSET = 20 + PLAY_SCHEDULE_FROMDATE_OFFSET; + static final int CHAPTER_PLAY_SCHEDULE_TOTIME_OFFSET = 20 + PLAY_SCHEDULE_TOTIME_OFFSET; + static final int CHAPTER_PLAY_SCHEDULE_TODATE_OFFSET = 20 + PLAY_SCHEDULE_TODATE_OFFSET; + + /* + //ÇøÓò´°Êý¾Ý½á¹¹Ìå + typedef struct REGION{ + WORD id; //±êʶ£¬ÓÃÓÚÊý¾ÝУÑé + WORD no; //Âß¼­´°¿Ú±àºÅ£¬ÖÃ0 + WORD over; //½ÚÄ¿ÊÇ·ñ²¥·ÅÍê³É(µ±modeΪµÈ´ý¶ÔÏó²¥·ÅÍê³Éʱ£¬´Ë×Ö¶ÎÓÐЧ¡£¶Ô¼ÆËã»ú´Ë×Ö¶ÎÎÞЧ) + WORD count; //Ò³ÃæÊýÄ¿ + DWORD size; //±êʶ¸ÃÂß¼­´°¿Ú×Ö½ÚÊý(°üº¬Êý¾Ý×Ö½ÚÊýºÍ¸ÃÔªËØ±¾Éí×Ö½ÚÊýÖ®ºÍ) + TRect rect; //Âß¼­´°¿ÚλÖôóС + BYTE border; + BYTE Reserved1; + WORD Reserved2; + }TRegion, *PRegion; + */ + static final int REGION_STRUCT_SIZE = 32; //2+2+2+2+4+16+1+1+2 + static final int REGION_SIZE_OFFSET = 8; + static final int REGION_COUNT_OFFSET = 6; + static final int REGION_LEFT_OFFSET = 12; + static final int REGION_TOP_OFFSET = 16; + static final int REGION_RIGHT_OFFSET = 20; + static final int REGION_BOTTOM_OFFSET = 24; + + /* + //Ò³ÃæÊý¾Ý½á¹¹Ìå + typedef struct LEAF{ + WORD id; //Ò³Ãæ±àºÅ(ÔÚÒ³ÃæÌæ»»Ê±£¬¸ù¾Ý´Ë±àºÅÌæ»») + WORD no; + WORD wait; //ÊÇ·ñµÈ´ý²¥·ÅÍê³É(=1µÈ´ý; =0µ½Ê±¼ä¾ÍÇÐ) + WORD serial; //ÊÇ·ñ´®Ðз½Ê½²¥·Å£¬ÖÃ0 + WORD count; //¶ÔÏóÊýÄ¿ + WORD Reserved; + DWORD time; //Ò³ÃæÏÔʾʱ¼ä + DWORD size; //±êʶ¸ÃÒ³Ãæ×Ö½ÚÊý(°üº¬Êý¾Ý×Ö½ÚÊýºÍ¸ÃÔªËØ±¾Éí×Ö½ÚÊýÖ®ºÍ) + WORD Reserved1; + WORD Reserved2; + }TLeaf, *PLeaf; + */ + static final int LEAF_STRUCT_SIZE = 24; //2+2+2+2+2+2+4+4+2+2 + static final int LEAF_SIZE_OFFSET = 16; + static final int LEAF_COUNT_OFFSET = 8; + static final int LEAF_WAIT_OFFSET = 4; + static final int LEAF_TIME_OFFSET = 12; + + /* + //¶ÔÏóͨÓÃÊôÐԽṹÌå + typedef struct OBJECT{ + WORD id; //¶ÔÏó±êʶ + BYTE transparent; //ÊÇ·ñ͸Ã÷ + BYTE flag; //һЩ¿ØÖÆÎ» + DWORD size; //¶ÔÏó×Ö½ÚÊý + TRect rect; //¶ÔÏóÏÔÊ¾ÇøÓò + }TObject, *PObject; + */ + static final int OBJECT_STRUCT_SIZE = 24; //2+1+1+4+16 + static final int OBJECT_TRANSPARENT_OFFSET = 2; + static final int OBJECT_SIZE_OFFSET = 4; + static final int OBJECT_LEFT_OFFSET = 8; + static final int OBJECT_TOP_OFFSET = 12; + static final int OBJECT_RIGHT_OFFSET = 16; + static final int OBJECT_BOTTOM_OFFSET = 20; + + /* + //¶à²¥·Å¶ÔÏóÊý¾Ý½á¹¹£¬ºóÃæ¸ú¶à¸öTWindow¶ÔÏó»òÕß¶à¸öTString¶ÔÏó + typedef struct WINDOWS{ + TObject object; //¶ÔÏóµÄÒ»°ã¶¨Òå + BYTE method; //¶¯×÷·½Ê½ + BYTE speed; //¶¯×÷ËÙ¶È + WORD count; //°üº¬µÄµÄWindowÊýÁ¿ + }TWindows, *PWindows; + */ + static final int STRINGS_STRUCT_SIZE = OBJECT_STRUCT_SIZE + 4; //1+1+2 + static final int STRINGS_COUNT_OFFSET = OBJECT_STRUCT_SIZE + 2; + static final int WINDOWS_STRUCT_SIZE = OBJECT_STRUCT_SIZE + 4; //1+1+2 + static final int WINDOWS_COUNT_OFFSET = OBJECT_STRUCT_SIZE + 2; + + /* + //ÄÚÂëÎÄ×Ö¶ÔÏó + typedef struct STRING{ + WORD id; + BYTE inMethod; //ÒýÈ뷽ʽ + BYTE outMethod; //Òý³ö·½Ê½ + BYTE stopMethod; //Í£Áô·½Ê½ + BYTE alignment; //¶ÔÆë·½Ê½ + WORD inSpeed; //ÒýÈëËÙ¶È + WORD outSpeed; //Òý³öËÙ¶È + WORD stopSpeed; //Í£ÁôËÙ¶È(ÀýÈçΪÉÁ˸ʱ£¬±íʾÉÁ˸ËÙ¶È) + DWORD stoptime; //Í£Áôʱ¼ä + long stopx; //Í£ÁôλÖà + DWORD size; //Êý¾Ý³¤¶È + DWORD color; //×Ö·ûÑÕÉ« + WORD fontset; //×Ö·û¼¯(Ò»°ãÇé¿ö 0=16µãÕó 1=24µãÕó) + WORD Reserved2; + }TString, *PString; + */ + static final int STRING_STRUCT_SIZE = 32; //2+1+1+1+1+2+2+2+4+4+4+4+2+2 + static final int STRING_IN_METHOD_OFFSET = 2; + static final int STRING_OUT_METHOD_OFFSET = 3; + static final int STRING_STOP_METHOD_OFFSET = 4; + static final int STRING_IN_SPEED_OFFSET = 6; + static final int STRING_OUT_SPEED_OFFSET = 8; + static final int STRING_STOP_SPEED_OFFSET = 10; + static final int STRING_STOP_TIME_OFFSET = 12; + static final int STRING_SIZE_OFFSET = 20; + static final int STRING_COLOR_OFFSET = 24; + static final int STRING_FONT_SET_OFFSET = 28; + + /* + //ÄÚÂëÈÕÆÚʱ¼ä¶ÔÏó + typedef struct STRINGDCLOCK{ + TObject object; //¶ÔÏóµÄÒ»°ã¶¨Òå + BYTE type; //ÀàÐÍ£ºÌìÎÄʱ¼ä¡¢×÷սʱ¼ä + BYTE direct; //·½Ïò£¬=0Õý³££¬=1ÄæÊ±ÕëÐýת90¶È£¬=2˳ʱÕëÐýת90¶È + WORD step; //²½³¤ + TTimeStamp basetime; //»ù׼ʱ¼ä(×÷սʱ¼äʹÓÃ) + TTimeStamp fromtime; //¿ªÊ¼Ê±¼ä(×÷սʱ¼äʹÓÃ) + TTimeStamp totime; //½áÊøÊ±¼ä(×÷սʱ¼äʹÓÃ) + long year_offset; //ÄêÆ«ÒÆÁ¿ + long month_offset; //ÔÂÆ«ÒÆÁ¿ + long day_offset; //ÌìÆ«ÒÆÁ¿ + long time_offset; //ʱ¼äÆ«ÒÆÁ¿(ºÁÃë) + WORD formats[MAX_DATETIME_FORMAT]; //ÏÔʾ¸ñʽ[32] + DWORD color; + BYTE fontset; + BYTE reserved; + WORD reserved2; + }TStringDClock, *PStringDClock; + */ + static final int SDCLOCK_STRUCT_SIZE = OBJECT_STRUCT_SIZE+116; //2+1+1+1+1+2+2+2+4+4+4+4+2+2 + static final int SDCLOCK_FORMAT_OFFSET = 44; + static final int SDCLOCK_COLOR_OFFSET = 108; + static final int SDCLOCK_FONTSET_OFFSET = 112; + + /* + //ÈÕÆÚʱ¼ä¶ÔÏó + typedef struct DClock{ + TObject object; //¶ÔÏóµÄÒ»°ã¶¨Òå + BYTE type; //ÀàÐÍ£ºÌìÎÄʱ¼ä¡¢×÷սʱ¼ä + BYTE direct; //·½Ïò£¬=0Õý³££¬=1ÄæÊ±ÕëÐýת90¶È£¬=2˳ʱÕëÐýת90¶È + WORD step; //²½³¤ + TTimeStamp basetime; //»ù׼ʱ¼ä(×÷սʱ¼äʹÓÃ) + TTimeStamp fromtime; //¿ªÊ¼Ê±¼ä(×÷սʱ¼äʹÓÃ) + TTimeStamp totime; //½áÊøÊ±¼ä(×÷սʱ¼äʹÓÃ) + long year_offset; //ÄêÆ«ÒÆÁ¿ + long month_offset; //ÔÂÆ«ÒÆÁ¿ + long day_offset; //ÌìÆ«ÒÆÁ¿ + long time_offset; //ʱ¼äÆ«ÒÆÁ¿(ºÁÃë) + WORD formats[MAX_DATETIME_FORMAT]; //ÏÔʾ¸ñʽ + }TDClock, *PDClock; + */ + static final int DCLOCK_STRUCT_SIZE = OBJECT_STRUCT_SIZE+108; //2+1+1+1+1+2+2+2+4+4+4+4+2+2 + static final int DCLOCK_FORMAT_OFFSET = 44; + + /* + //Õý¼ÆÊ±¡¢µ¹¼ÆÊ±¶ÔÏó + typedef struct COUNTER{ + TObject object; + TTimeStamp basetime; + WORD type; + WORD format; + WORD Reserved1; + WORD Reserved2; + }TCounter, *PCounter; + */ + static final int COUNTER_STRUCT_SIZE = OBJECT_STRUCT_SIZE+24; //2+1+1+1+1+2+2+2+4+4+4+4+2+2 + static final int COUNTER_BASETIME_OFFSET = 0; + static final int COUNTER_TYPE_OFFSET = 8; + static final int COUNTER_FORMAT_OFFSET = 10; + + /* + //ÓïÒô²¥·Å¶ÔÏó + typedef struct VOICE{ + TObject object; //¶ÔÏóµÄÒ»°ã¶¨Òå + DWORD interval; + DWORD times; + BYTE voice_speaker; + BYTE voice_volumn; + BYTE voice_tone; + BYTE voice_speed; + DWORD reversed[4]; + }TVoice, *PVoice; + */ + static final int VOICE_STRUCT_SIZE = OBJECT_STRUCT_SIZE + 16; + static final int VOICE_INTERVAL_OFFSET = OBJECT_STRUCT_SIZE; + static final int VOICE_TIMES_OFFSET = OBJECT_STRUCT_SIZE + 4; + static final int VOICE_SPEAKER_OFFSET = OBJECT_STRUCT_SIZE + 8; + static final int VOICE_VOLUMN_OFFSET = OBJECT_STRUCT_SIZE + 9; + static final int VOICE_TONE_OFFSET = OBJECT_STRUCT_SIZE + 10; + static final int VOICE_SPEED_OFFSET = OBJECT_STRUCT_SIZE + 11; + + /* + //ͼƬ¶ÔÏ󣬺óÃæ¸ú×ÅÒ»¸öµãÕóTPixels + typedef struct WINDOW{ + WORD id; + BYTE inMethod; //ÒýÈ뷽ʽ + BYTE outMethod; //Òý³ö·½Ê½ + BYTE stopMethod; //Í£Áô·½Ê½ + BYTE flag; //һЩ¿ØÖƱêÖ¾ + WORD inSpeed; //ÒýÈëËÙ¶È + WORD outSpeed; //Òý³öËÙ¶È + WORD stopSpeed; //Í£ÁôËÙ¶È(ÀýÈçΪÉÁ˸ʱ£¬±íʾÉÁ˸ËÙ¶È) + DWORD stoptime; //Í£Áôʱ¼ä + long stopx; //Í£ÁôλÖà + DWORD size; //Êý¾Ý³¤¶È + }TWindow, *PWindow; + */ + static final int WINDOW_STRUCT_SIZE = 24; //2+1+1+1+1+2+2+2+4+4+4 + static final int WINDOW_IN_METHOD_OFFSET = 2; + static final int WINDOW_OUT_METHOD_OFFSET = 3; + static final int WINDOW_STOP_METHOD_OFFSET = 4; + static final int WINDOW_IN_SPEED_OFFSET = 6; + static final int WINDOW_OUT_SPEED_OFFSET = 8; + static final int WINDOW_STOP_SPEED_OFFSET = 10; + static final int WINDOW_STOP_TIME_OFFSET = 12; + static final int WINDOW_SIZE_OFFSET = 20; + + /* + //ͼƬ¶ÔÏ󣬺óÃæ¸ú×ÅÒ»¸öµãÕóTPixels + typedef struct SCHEDULEWINDOW{ + WORD id; + BYTE inMethod; //ÒýÈ뷽ʽ + BYTE outMethod; //Òý³ö·½Ê½ + BYTE stopMethod; //Í£Áô·½Ê½ + BYTE flag; //һЩ¿ØÖƱêÖ¾ + WORD inSpeed; //ÒýÈëËÙ¶È + WORD outSpeed; //Òý³öËÙ¶È + WORD stopSpeed; //Í£ÁôËÙ¶È(ÀýÈçΪÉÁ˸ʱ£¬±íʾÉÁ˸ËÙ¶È) + DWORD stoptime; //Í£Áôʱ¼ä + long stopx; //Í£ÁôλÖà + DWORD size; //Êý¾Ý³¤¶È + TPlaySchedule schedule; //²¥·Å¼Æ»® + }TScheduleWindow, *PScheduleWindow; + */ + static final int SCHEDULE_WINDOW_STRUCT_SIZE = WINDOW_STRUCT_SIZE + PLAY_SCHEDULE_SIZE; //2+1+1+1+1+2+2+2+4+4+4+20 + + /* + //µãÕó¼¯Êý¾Ý½á¹¹¶¨Ò壨µãÕ󼯰üº¬¶à¸öµãÕó£© + typedef struct PIXELSET{ + WORD id; //¶ÔÏó±êʶ + WORD count; //TPixels¶ÔÏóÊýÄ¿ + DWORD size; //¶ÔÏó×Ö½ÚÊý + }TPixelSet, *PPixelSet; + */ + static final int PIXELSET_STRUCT_SIZE = 8; //2+2+4 + static final int PIXELSET_COUNT_OFFSET = 2; + static final int PIXELSET_SIZE_OFFSET = 4; + + /* + //µãÕóÊý¾Ý½á¹¹¶¨Òå + typedef struct PIXELS{ + WORD id; //¶ÔÏó±êʶ + WORD bits; //ÿÏóËØÎ»Êý + long width; //µãÕó¿í¶È + long height; //µãÕó¸ß¶È + DWORD size; //¶ÔÏó´óС + }TPixels, *PPixels; + */ + static final int PIXELS_STRUCT_SIZE = 16; //2+2+4+4+4 + static final int PIXELS_BITS_OFFSET = 2; + static final int PIXELS_WIDTH_OFFSET = 4; + static final int PIXELS_HEIGHT_OFFSET = 8; + static final int PIXELS_SIZE_OFFSET = 12; + + /* + typedef struct PKG_RESPOND{ + TPKG_Header Header; + WORD Command; + WORD Result; + }TPKG_Respond, *PPKG_Respond; + */ + static final int RESPOND_STRUCT_SIZE = 12; + static final int RESPOND_COMMAND_OFFSET = 0; + static final int RESPOND_RESULT_OFFSET = 2; + + /* + typedef struct BOARDPARAM{ + WORD width; + WORD height; + WORD type; + WORD frequency; + DWORD flag; + DWORD uart; //+2+2+2+2+4+4=16 + BYTE mac[ETHER_ADDRESS_LENGTH]; + BYTE ip[IP_ADDRESS_LENGTH]; + BYTE gateMAC[ETHER_ADDRESS_LENGTH]; + BYTE serverIP[IP_ADDRESS_LENGTH]; //+6+4+6+4=36 + BYTE brightness; + BYTE importflag; + BYTE rootcount; + BYTE disconnect_sec; + DWORD rom_size; + long left; + long top; //+4+4+4+4=52 + WORD scan_mode; + WORD server_port; + WORD line_order; + WORD oe_time; + WORD shift_freq; + WORD refresh_freq; //+2+2+2+2+2+2=64; + BYTE GateIP[IP_ADDRESS_LENGTH]; + BYTE ipMask[IP_ADDRESS_LENGTH]; //+4+4=72 + BYTE name[32]; + DWORD ident; + DWORD address; //+32+4+4=112 + DWORD pkp_rx_timeo; + DWORD pkp_tx_timeo; + DWORD pkp_tx_repeat; + BYTE dnsIP[IP_ADDRESS_LENGTH]; + BYTE dnsMAC[ETHER_ADDRESS_LENGTH]; + WORD ReportTime; //+12+4+6+2=136 + //Èç¹ûserver_host=0£¬Ôòserver_domainÓÐЧ + BYTE serverDomain[32]; + //ÏÔʾÆÁµÄÃÜÔ¿£¬ÓÃÓÚÆÁ±ÎÃÜÔ¿²»·ûµÄÊý¾Ý°ü£¬×èÖ¹·Ç·¨Óû§ÏòÏÔʾÆÁÉÏ·¢ËÍÐÅÏ¢ + DWORD key; + DWORD pkp_length; //+32+4+4=176 + //¶ÔÓ¦µÄbinÎļþÃû + char bin_name[32]; //+32=208 + ////////////////////////////////////////////////////// + //¹â¸ÐÏà¹Ø²ÎÊý + BYTE light_sense; + BYTE light_sense_auto; + WORD light_sense_reserved; + WORD light_sense_split_val[8]; + BYTE light_sense_bright_val[8]; //+28=236 + ////////////////////////////////////////////////////// + //Ë«¿¨Ê±ÖÓͬ²½ÊܿضËIPµØÖ· + BYTE TimeSyncIP[IP_ADDRESS_LENGTH]; //+4=240 + ////////////////////////////////////////////////////// + //×Ô¶¯ÖØÆô²ÎÊý + BYTE auto_reset_enabled; + BYTE auto_reset_type; + BYTE auto_reset_hour; + BYTE auto_reset_minute; + }TBoardParam, *PBoardParam; + */ + static final int BOARDPARAM_STRUCT_SIZE = 512; + static final int BOARDPARAM_WIDTH_OFFSET = 0; + static final int BOARDPARAM_HEIGHT_OFFSET = 2; + static final int BOARDPARAM_COLORMODE_OFFSET = 4; + static final int BOARDPARAM_IP_OFFSET = 22; + + static int root_seek = -1; + static int root_size = 0; + static int root_count = 0; + static int chapter_seek = -1; + static int chapter_size = 0; + static int chapter_count = 0; + static int region_seek = -1; + static int region_size = 0; + static int region_count = 0; + static int leaf_seek = -1; + static int leaf_size = 0; + static int leaf_count = 0; + static int strings_seek = -1; + static int strings_size = 0; + static int strings_count = 0; + static int windows_seek = -1; + static int windows_size = 0; + static int windows_count = 0; + static int data_seek = 0; + + public static byte[] data_stream; + public static byte[] cmd_stream; + public static byte[] respond_stream; + public static byte[] packet_stream; + public static int packet_size; + + public static int get_boardparam_respond_size = 0; + + public static final int RGB_SPLIT = 64; + + public int fix_serialno=0; + + static private int current_color_type=0; + + public void print_stream(byte[] stream, int size){ + int i; + short x; + String s; + for (i=0; i>8)&0xFF); + } + + static short lo_of_int(int value){ + return (short)(value&0xFFFF); + } + + static short hi_of_int(int value){ + return (short)((value>>16)&0xFFFF); + } + + static void byteFill(byte[] buffer, int index, byte value){ + buffer[index]=value; + } + + static int asByte(byte[] buffer, int index){ + return buffer[index]; + } + + static void shortFill(byte[] buffer, int index, short value){ + buffer[index]=lo_of_short(value); + buffer[index+1]=hi_of_short(value); + } + + static int asShort(byte[] buffer, int index){ + int value; + short result=0; + if (buffer[index]>=0) value=buffer[index]; else value=(256+buffer[index]); + result+=value; + if (buffer[index+1]>=0) value=buffer[index+1]; else value=(256+buffer[index+1]); + result+=(value<<8); + return (short)result; + } + + static String asIP(byte[] buffer, int index){ + int[] ip=new int[4]; + int i; + for(i=0; i<4; i++){ + if (buffer[index+i]>=0) ip[i]=buffer[index+i]; else ip[i]=(256+buffer[index+i]); + } + return ip[0]+"."+ip[1]+"."+ip[2]+"."+ip[3]; + } + + static String asMAC(byte[] buffer, int index){ + int[] mac=new int[6]; + int i; + for(i=0; i<6; i++){ + if (buffer[index+i]>=0) mac[i]=buffer[index+i]; else mac[i]=(256+buffer[index+i]); + } + return mac[0]+"-"+mac[1]+"-"+mac[2]+"-"+mac[3]+"-"+mac[4]+"-"+mac[5]; + } + + static void intFill(byte[] buffer, int index, int value){ + buffer[index]=lo_of_short(lo_of_int(value)); + buffer[index+1]=hi_of_short(lo_of_int(value)); + buffer[index+2]=lo_of_short(hi_of_int(value)); + buffer[index+3]=hi_of_short(hi_of_int(value)); + } + + static void timeFill(byte[] buffer, int index, int hour, int minute, int second){ + int time; + time=((hour*60+minute)*60+second)*1000; + intFill(buffer, index, time); + } + + static void dateFill(byte[] buffer, int index, int year, int month, int day){ + int date; + int MonthDays[][]={{31,28,31,30,31,30,31,31,30,31,30,31}, {31,29,31,30,31,30,31,31,30,31,30,31}}; + int i,y,m,d; + + y=year-1; + for (m=0,d=year; d>100; d-=100, m++) ; + if ((year&3)==0 && ((m&3)==0 || d!=0)) d=1; else d=0; + + date=day; + for (i=1; i<=month-1; i++) date+=MonthDays[d][i-1]; + date+=y*365+(y>>2)-(y/100)+(y/400); + + intFill(buffer, index, date); + } + + static void timestampFill(byte[] buffer, int index, int year, int month, int day, int hour, int minute, int second){ + timeFill(buffer, index, hour, minute, second); + dateFill(buffer, index+4, year, month, day); + } + + static int asInt(byte[] buffer, int index){ + int value; + int result=0; + if (buffer[index]>=0) value=buffer[index]; else value=(256+buffer[index]); + result+=value; + if (buffer[index+1]>=0) value=buffer[index+1]; else value=(256+buffer[index+1]); + result+=(value<<8); + if (buffer[index+2]>=0) value=buffer[index+2]; else value=(256+buffer[index+2]); + result+=(value<<16); + if (buffer[index+3]>=0) value=buffer[index+3]; else value=(256+buffer[index+3]); + result+=(value<<24); + return result; + } + + static void blockFill(byte[] buffer, int index, int count, byte value){ + int i; + for (i=index; i>8)&0xFF); + opacket[y++]=(byte)PKP_PREFIX; + for (x=0; x0) len=((len+0x3)&(~0x3)); + gb2312=new byte[len]; + blockFill(gb2312, 0, len, (byte)0); + blockCopy(gb2312, 0, s, 0, s.length); + } catch (Exception e) { + e.printStackTrace(); + gb2312=new byte[0]; + } + + seek=data_seek; + size=STRING_STRUCT_SIZE+len; + size=((size+0x3)&(~0x3)); + blockFill(data_stream, seek, size, (byte)0); + shortFill(data_stream, seek, (short)OBJECT_STRING); + byteFill(data_stream, seek+STRING_IN_METHOD_OFFSET, (byte)inmethod); + shortFill(data_stream, seek+STRING_IN_SPEED_OFFSET, (short)inspeed); + byteFill(data_stream, seek+STRING_OUT_METHOD_OFFSET, (byte)outmethod); + shortFill(data_stream, seek+STRING_OUT_SPEED_OFFSET, (short)outspeed); + byteFill(data_stream, seek+STRING_STOP_METHOD_OFFSET, (byte)stopmethod); + shortFill(data_stream, seek+STRING_STOP_SPEED_OFFSET, (short)stopspeed); + intFill(data_stream, seek+STRING_STOP_TIME_OFFSET, stoptime); + intFill(data_stream, seek+STRING_COLOR_OFFSET, color); + shortFill(data_stream, seek+STRING_FONT_SET_OFFSET, (short)fontset); + intFill(data_stream, seek+STRING_SIZE_OFFSET, size); + //stringCopy(data_stream, seek+STRING_STRUCT_SIZE, text, len); + blockCopy(data_stream, seek+STRING_STRUCT_SIZE, gb2312, 0, len); + strings_count++; + shortFill(data_stream, strings_seek+STRINGS_COUNT_OFFSET, (short)strings_count); + strings_size+=size; + intFill(data_stream, strings_seek+OBJECT_SIZE_OFFSET, strings_size); + if (leaf_seek>0) { + leaf_size+=size; + intFill(data_stream, leaf_seek+LEAF_SIZE_OFFSET, leaf_size); + } + if (region_seek>0) { + region_size+=size; + intFill(data_stream, region_seek+REGION_SIZE_OFFSET, region_size); + } + if (chapter_seek>0) { + chapter_size+=size; + intFill(data_stream, chapter_seek+CHAPTER_SIZE_OFFSET, chapter_size); + } + root_size+=size; + intFill(data_stream, root_seek+ROOT_SIZE_OFFSET, root_size); + data_seek=seek+size; + //System.out.println("childstring="+data_seek); + } + + public void AddWindows(int left, int top, int width, int height) { + windows_seek=data_seek; + windows_count=0; + windows_size=WINDOWS_STRUCT_SIZE; + blockFill(data_stream, windows_seek, windows_size, (byte)0); + shortFill(data_stream, windows_seek, (short)OBJECT_WINDOWS); + blockFill(data_stream, windows_seek+OBJECT_TRANSPARENT_OFFSET, 1, (byte)1); + intFill(data_stream, windows_seek+OBJECT_LEFT_OFFSET, left); + intFill(data_stream, windows_seek+OBJECT_TOP_OFFSET, top); + intFill(data_stream, windows_seek+OBJECT_RIGHT_OFFSET, left+width); + intFill(data_stream, windows_seek+OBJECT_BOTTOM_OFFSET, top+height); + shortFill(data_stream, windows_seek+WINDOWS_COUNT_OFFSET, (short)windows_count); + intFill(data_stream, windows_seek+OBJECT_SIZE_OFFSET, windows_size); + if (leaf_seek>0) { + leaf_count++; + shortFill(data_stream, leaf_seek+LEAF_COUNT_OFFSET, (short)leaf_count); + leaf_size+=windows_size; + intFill(data_stream, leaf_seek+LEAF_SIZE_OFFSET, leaf_size); + } + if (region_seek>0) { + region_size+=windows_size; + intFill(data_stream, region_seek+REGION_SIZE_OFFSET, region_size); + } + if (chapter_seek>0) { + chapter_size+=windows_size; + intFill(data_stream, chapter_seek+CHAPTER_SIZE_OFFSET, chapter_size); + } + root_size+=windows_size; + intFill(data_stream, root_seek+ROOT_SIZE_OFFSET, root_size); + data_seek=windows_seek+windows_size; + //System.out.println("windows="+data_seek); + } + + //dib_buffer µãÕóͼƬRGBÊý×é + //dib_buffer_size Êý×鳤¶È + //dib_width µãÕó¿í¶È + //dib_height µãÕó¸ß¶È + static int AddPixelsRG(int[] dib_buffer, int dib_buffer_size, int dib_width, int dib_height) { + int pixels_seek, pixels_size, pixels_height; + int x, y; + int shift[] = new int[4]; + int shift_value[] = new int[4]; + int shift_mask[] = new int[4]; + int bits_value[] = new int[4]; + int bits_seek, bits_size; + int buffer_seek=0; + int byte_seek=3; + + pixels_height=((dib_height+0xF)&(~0xF)); + bits_size=(pixels_height>>2)*dib_width; + pixels_seek=data_seek; + pixels_size=PIXELS_STRUCT_SIZE+bits_size; + blockFill(data_stream, pixels_seek, pixels_size, (byte)0); + + shortFill(data_stream, pixels_seek, (short)OBJECT_PIXELS); + shortFill(data_stream, pixels_seek+PIXELS_BITS_OFFSET, (short)BITMAP_YELLOW); + intFill(data_stream, pixels_seek+PIXELS_WIDTH_OFFSET, (int)dib_width); + intFill(data_stream, pixels_seek+PIXELS_HEIGHT_OFFSET, (int)pixels_height); + intFill(data_stream, pixels_seek+PIXELS_SIZE_OFFSET, (int)pixels_size); + + bits_seek=pixels_seek+PIXELS_STRUCT_SIZE; + for (x=0; x>8)&0xFF)>RGB_SPLIT) shift_value[byte_seek]|=shift[byte_seek]; + shift[byte_seek]>>=1; + if ((dib_buffer[buffer_seek]&0xFF)>RGB_SPLIT) shift_value[byte_seek]|=shift[byte_seek]; + shift[byte_seek]>>=1; + buffer_seek++; + if (shift_value[byte_seek]>0){ + bits_value[byte_seek]&=(~shift_mask[byte_seek]); + bits_value[byte_seek]|=shift_value[byte_seek]; + } + shift_mask[byte_seek]>>=2; + if (byte_seek==0 && shift[byte_seek]==0){ + data_stream[bits_seek]=(byte)bits_value[0]; + data_stream[bits_seek+1]=(byte)bits_value[1]; + data_stream[bits_seek+2]=(byte)bits_value[2]; + data_stream[bits_seek+3]=(byte)bits_value[3]; + bits_seek+=4; + shift[0]=0x0; shift[1]=0x0; shift[2]=0x0; shift[3]=0x80; + shift_mask[0]=0x0; shift_mask[1]=0x0; shift_mask[2]=0x0; shift_mask[3]=0xC0; + bits_value[0]=0x0; bits_value[1]=0x0; bits_value[2]=0x0; bits_value[3]=0x0; + byte_seek=3; + } + if (shift[byte_seek]==0){ + byte_seek--; + shift[byte_seek]=0x80; + shift_mask[byte_seek]=0xC0; + bits_value[byte_seek]=0; + } + } + if (shift[3]!=0x80){ + data_stream[bits_seek]=(byte)bits_value[0]; + data_stream[bits_seek+1]=(byte)bits_value[1]; + data_stream[bits_seek+2]=(byte)bits_value[2]; + data_stream[bits_seek+3]=(byte)bits_value[3]; + bits_seek+=4; + } + } + + return pixels_size; + } + + //dib_buffer µãÕóͼƬRGBÊý×é + //dib_buffer_size Êý×鳤¶È + //dib_width µãÕó¿í¶È + //dib_height µãÕó¸ß¶È + static int AddPixelsRGB(int[] dib_buffer, int dib_buffer_size, int dib_width, int dib_height) { + int pixels_seek, pixels_size, pixels_height; + int x, y, i; + int shift[] = new int[4]; + int shift_value_r[] = new int[4]; + int shift_value_g[] = new int[4]; + int shift_value_b[] = new int[4]; + int bits_seek, bits_size; + int buffer_seek=0; + int byte_seek=3; + + pixels_height=((dib_height+0x1F)&(~0x1F)); + bits_size=(pixels_height>>3)*dib_width*3; + pixels_seek=data_seek; + pixels_size=PIXELS_STRUCT_SIZE+bits_size; + blockFill(data_stream, pixels_seek, pixels_size, (byte)0); + + shortFill(data_stream, pixels_seek, (short)OBJECT_PIXELS); + shortFill(data_stream, pixels_seek+PIXELS_BITS_OFFSET, (short)BITMAP_RGB); + intFill(data_stream, pixels_seek+PIXELS_WIDTH_OFFSET, (int)dib_width); + intFill(data_stream, pixels_seek+PIXELS_HEIGHT_OFFSET, (int)pixels_height); + intFill(data_stream, pixels_seek+PIXELS_SIZE_OFFSET, (int)pixels_size); + + bits_seek=pixels_seek+PIXELS_STRUCT_SIZE; + for (x=0; xRGB_SPLIT) { + for (i=0; i<4; i++) shift_value_r[i]|=shift[i]; + } + if (((dib_buffer[buffer_seek]>>8)&0xFF)>RGB_SPLIT) { + for (i=0; i<4; i++) shift_value_g[i]|=shift[i]; + } + if (((dib_buffer[buffer_seek]>>16)&0xFF)>RGB_SPLIT) { + for (i=0; i<4; i++) shift_value_b[i]|=shift[i]; + } + shift[byte_seek]>>=1; + buffer_seek++; + if (byte_seek==0 && shift[byte_seek]==0){ + for (i=0; i<4; i++) data_stream[bits_seek+i]=(byte)shift_value_r[i]; + bits_seek+=4; + for (i=0; i<4; i++) data_stream[bits_seek+i]=(byte)shift_value_g[i]; + bits_seek+=4; + for (i=0; i<4; i++) data_stream[bits_seek+i]=(byte)shift_value_b[i]; + bits_seek+=4; + shift[0]=0x0; shift[1]=0x0; shift[2]=0x0; shift[3]=0x80; + byte_seek=3; + for (i=0; i<4; i++) shift_value_r[i]=0; + for (i=0; i<4; i++) shift_value_g[i]=0; + for (i=0; i<4; i++) shift_value_b[i]=0; + } + if (shift[byte_seek]==0){ + byte_seek--; + shift[byte_seek]=0x80; + } + } + if (shift[3]!=0x80){ + for (i=0; i<4; i++) data_stream[bits_seek+i]=(byte)shift_value_r[i]; + bits_seek+=4; + for (i=0; i<4; i++) data_stream[bits_seek+i]=(byte)shift_value_g[i]; + bits_seek+=4; + for (i=0; i<4; i++) data_stream[bits_seek+i]=(byte)shift_value_b[i]; + bits_seek+=4; + } + } + + return pixels_size; + } + + //dib_buffer µãÕóͼƬRGBÊý×é + //dib_buffer_size Êý×鳤¶È + //dib_width µãÕó¿í¶È + //dib_height µãÕó¸ß¶È + static int AddPixelsFull(int[] dib_buffer, int dib_buffer_size, int dib_width, int dib_height) { + int pixels_seek, pixels_size, pixels_height; + int x, y, z, i; + int shift[] = new int[4]; + int data_value[] = new int[4]; + int r_value, g_value, b_value; + int bits_seek, bits_size; + int buffer_seek=0; + int byte_seek=3; + + pixels_height=dib_height; + bits_size=pixels_height*dib_width*4; + pixels_seek=data_seek; + pixels_size=PIXELS_STRUCT_SIZE+bits_size; + blockFill(data_stream, pixels_seek, pixels_size, (byte)0); + + shortFill(data_stream, pixels_seek, (short)OBJECT_PIXELS); + shortFill(data_stream, pixels_seek+PIXELS_BITS_OFFSET, (short)BITMAP_RGB); + intFill(data_stream, pixels_seek+PIXELS_WIDTH_OFFSET, (int)dib_width); + intFill(data_stream, pixels_seek+PIXELS_HEIGHT_OFFSET, (int)pixels_height); + intFill(data_stream, pixels_seek+PIXELS_SIZE_OFFSET, (int)pixels_size); + + bits_seek=pixels_seek+PIXELS_STRUCT_SIZE; + for (x=0; x>8)&0xFF); + b_value=((dib_buffer[buffer_seek]>>16)&0xFF); + if (r_value>0 || g_value>0 || b_value>0){ + for (z=0; z<8; z++){ + data_value[byte_seek]<<=1; + if ((r_value & 0x80) > 0) data_value[byte_seek]|=1; + data_value[byte_seek]<<=1; + if ((g_value & 0x80) > 0) data_value[byte_seek]|=1; + data_value[byte_seek]<<=1; + if ((b_value & 0x80) > 0) data_value[byte_seek]|=1; + data_value[byte_seek]<<=1; + r_value<<=1; + g_value<<=1; + b_value<<=1; + shift[byte_seek]>>=4; + if (shift[byte_seek]==0){ + if (byte_seek==0) byte_seek=3; else byte_seek--; + shift[byte_seek]=0x80; + } + } + } + for (i=0; i<4; i++) data_stream[bits_seek+i]=(byte)data_value[i]; + bits_seek+=4; + buffer_seek++; + } + } + + return pixels_size; + } + + static int AddPixels(int[] dib_buffer, int dib_buffer_size, int dib_width, int dib_height) { + switch(current_color_type) { + case COLOR_TYPE_THREE: + return AddPixelsRGB(dib_buffer, dib_buffer_size, dib_width, dib_height); + case COLOR_TYPE_FULL: + return AddPixelsFull(dib_buffer, dib_buffer_size, dib_width, dib_height); + default: + return AddPixelsRG(dib_buffer, dib_buffer_size, dib_width, dib_height); + } + } + + //buffer µãÕóͼƬRGBÊý×é + //buffer_size Êý×鳤¶È + //width µãÕó¿í¶È + //height µãÕó¸ß¶È + //inmethod ÒýÈ뷽ʽ£¬ÔÚ´ËjavaÎļþ×îÉÏ·½Óж¨Òå + //outmethod Òý³ö·½Ê½£¬ÔÚ´ËjavaÎļþ×îÉÏ·½Óж¨Òå + //inspeed, outspeed ÒýÈëÒý³öËÙ¶È£¬0µ½5 + //stopmethod Í£Áô·½Ê½£¬ÇëÖÃ0 + //stopspeed Í£ÁôËÙ¶È£¬ÇëÖÃ0 + public void AddChildWindow(int[] buffer, int buffer_size, int width, int height, int inmethod, int inspeed, int outmethod, int outspeed, int stopmethod, int stopspeed, int stoptime) { + int seek, size; + int pixels_size; + + seek=data_seek; + size=WINDOW_STRUCT_SIZE; + blockFill(data_stream, seek, size, (byte)0); + + shortFill(data_stream, seek, (short)OBJECT_WINDOW); + byteFill(data_stream, seek+WINDOW_IN_METHOD_OFFSET, (byte)inmethod); + shortFill(data_stream, seek+WINDOW_IN_SPEED_OFFSET, (short)inspeed); + byteFill(data_stream, seek+WINDOW_OUT_METHOD_OFFSET, (byte)outmethod); + shortFill(data_stream, seek+WINDOW_OUT_SPEED_OFFSET, (short)outspeed); + byteFill(data_stream, seek+WINDOW_STOP_METHOD_OFFSET, (byte)stopmethod); + shortFill(data_stream, seek+WINDOW_STOP_SPEED_OFFSET, (short)stopspeed); + intFill(data_stream, seek+WINDOW_STOP_TIME_OFFSET, stoptime); + intFill(data_stream, seek+WINDOW_SIZE_OFFSET, size); + + data_seek+=WINDOW_STRUCT_SIZE; + pixels_size=AddPixels(buffer, buffer_size, width, height); + + size+=pixels_size; + intFill(data_stream, seek+WINDOW_SIZE_OFFSET, size); + windows_count++; + shortFill(data_stream, windows_seek+WINDOWS_COUNT_OFFSET, (short)windows_count); + windows_size+=size; + intFill(data_stream, windows_seek+OBJECT_SIZE_OFFSET, windows_size); + if (leaf_seek>0) { + leaf_size+=size; + intFill(data_stream, leaf_seek+LEAF_SIZE_OFFSET, leaf_size); + } + if (region_seek>0) { + region_size+=size; + intFill(data_stream, region_seek+REGION_SIZE_OFFSET, region_size); + } + if (chapter_seek>0) { + chapter_size+=size; + intFill(data_stream, chapter_seek+CHAPTER_SIZE_OFFSET, chapter_size); + } + root_size+=size; + intFill(data_stream, root_seek+ROOT_SIZE_OFFSET, root_size); + data_seek=seek+size; + //System.out.println("childwindow="+data_seek); + } + + //buffer µãÕóͼƬRGBÊý×é + //buffer_size Êý×鳤¶È + //width µãÕó¿í¶È + //height µãÕó¸ß¶È + //inmethod ÒýÈ뷽ʽ£¬ÔÚ´ËjavaÎļþ×îÉÏ·½Óж¨Òå + //outmethod Òý³ö·½Ê½£¬ÔÚ´ËjavaÎļþ×îÉÏ·½Óж¨Òå + //inspeed, outspeed ÒýÈëÒý³öËÙ¶È£¬0µ½5 + //stopmethod Í£Áô·½Ê½£¬ÇëÖÃ0 + //stopspeed Í£ÁôËÙ¶È£¬ÇëÖÃ0 + //kind ¼Æ»®Ä£Ê½£¬=0ʼÖÕ²¥·Å£¬=1°´Ò»ÖÜÿÈÕ²¥·Å£¬=2°´Æðֹʱ¼ä²¥·Å£¬=3²»²¥·Å + //week Ò»Öܶ¨Ò壬µ±kind=1ʱÓÐЧ£¬´Óbit0-bit6±íʾÖÜÈÕµ½ÖÜÁù + // ÖÜÈÕ0x1 ÖÜÒ»0x2 Öܶþ0x4 ÖÜÈý0x8 ÖÜËÄ0x10 ÖÜÎå0x20 ÖÜÁù0x30 + // Õâ¸öÖµ¿ÉÒÔÏà¼Ó×éºÏ£¬ÀýÈçÖ»²¥·ÅÖÜÒ»¡¢Öܶþ¡¢ÖÜÈýÕâ3Ì죬Ôòweek¸³Öµ0x2+0x4+0x8¼´¿É + public void AddChildScheduleWindow(int[] buffer, int buffer_size, int width, int height, + int inmethod, int inspeed, int outmethod, int outspeed, int stopmethod, int stopspeed, int stoptime, + int kind, int week, + int from_year, int from_month, int from_day, int from_hour, int from_minute, int from_second, + int to_year, int to_month, int to_day, int to_hour, int to_minute, int to_second) { + int seek, size; + int pixels_size; + + seek=data_seek; + size=SCHEDULE_WINDOW_STRUCT_SIZE; + blockFill(data_stream, seek, size, (byte)0); + + shortFill(data_stream, seek, (short)OBJECT_SCHEDULE_WINDOW); + byteFill(data_stream, seek+WINDOW_IN_METHOD_OFFSET, (byte)inmethod); + shortFill(data_stream, seek+WINDOW_IN_SPEED_OFFSET, (short)inspeed); + byteFill(data_stream, seek+WINDOW_OUT_METHOD_OFFSET, (byte)outmethod); + shortFill(data_stream, seek+WINDOW_OUT_SPEED_OFFSET, (short)outspeed); + byteFill(data_stream, seek+WINDOW_STOP_METHOD_OFFSET, (byte)stopmethod); + shortFill(data_stream, seek+WINDOW_STOP_SPEED_OFFSET, (short)stopspeed); + intFill(data_stream, seek+WINDOW_STOP_TIME_OFFSET, stoptime); + intFill(data_stream, seek+WINDOW_SIZE_OFFSET, size); + shortFill(data_stream, seek+WINDOW_STRUCT_SIZE+PLAY_SCHEDULE_KIND_OFFSET, (short)kind); + shortFill(data_stream, seek+WINDOW_STRUCT_SIZE+PLAY_SCHEDULE_WEEK_OFFSET, (short)week); + intFill(data_stream, seek+WINDOW_STRUCT_SIZE+PLAY_SCHEDULE_FROMTIME_OFFSET, SystemTimeToTime(from_hour, from_minute, from_second)); + intFill(data_stream, seek+WINDOW_STRUCT_SIZE+PLAY_SCHEDULE_FROMDATE_OFFSET, SystemTimeToDate(from_year, from_month, from_day)); + intFill(data_stream, seek+WINDOW_STRUCT_SIZE+PLAY_SCHEDULE_TOTIME_OFFSET, SystemTimeToTime(to_hour, to_minute, to_second)); + intFill(data_stream, seek+WINDOW_STRUCT_SIZE+PLAY_SCHEDULE_TODATE_OFFSET, SystemTimeToDate(to_year, to_month, to_day)); + + data_seek+=SCHEDULE_WINDOW_STRUCT_SIZE; + pixels_size=AddPixels(buffer, buffer_size, width, height); + + size+=pixels_size; + intFill(data_stream, seek+WINDOW_SIZE_OFFSET, size); + windows_count++; + shortFill(data_stream, windows_seek+WINDOWS_COUNT_OFFSET, (short)windows_count); + windows_size+=size; + intFill(data_stream, windows_seek+OBJECT_SIZE_OFFSET, windows_size); + if (leaf_seek>0) { + leaf_size+=size; + intFill(data_stream, leaf_seek+LEAF_SIZE_OFFSET, leaf_size); + } + if (region_seek>0) { + region_size+=size; + intFill(data_stream, region_seek+REGION_SIZE_OFFSET, region_size); + } + if (chapter_seek>0) { + chapter_size+=size; + intFill(data_stream, chapter_seek+CHAPTER_SIZE_OFFSET, chapter_size); + } + root_size+=size; + intFill(data_stream, root_seek+ROOT_SIZE_OFFSET, root_size); + data_seek=seek+size; + //System.out.println("childwindow="+data_seek); + } + + static int AddPicturePixels(String filename) { + int pixels_size=0; + BufferedImage bi; + try { + bi = ImageIO.read(new FileInputStream(filename)); + pixels_size=AddPixels(getBufferedImageRGB(bi), bi.getWidth() * bi.getHeight(), bi.getWidth(), bi.getHeight()); + } catch (Exception e) { + e.printStackTrace(); + } + return pixels_size; + } + + //filename ͼƬÎļþÃû + //inmethod ÒýÈ뷽ʽ£¬ÔÚ´ËjavaÎļþ×îÉÏ·½Óж¨Òå + //outmethod Òý³ö·½Ê½£¬ÔÚ´ËjavaÎļþ×îÉÏ·½Óж¨Òå + //inspeed, outspeed ÒýÈëÒý³öËÙ¶È£¬0µ½5 + //stopmethod Í£Áô·½Ê½£¬ÇëÖÃ0 + //stopspeed Í£ÁôËÙ¶È£¬ÇëÖÃ0 + public void AddChildPicture(String filename, int inmethod, int inspeed, int outmethod, int outspeed, int stopmethod, int stopspeed, int stoptime) { + int seek, size; + int pixels_size; + + seek=data_seek; + size=WINDOW_STRUCT_SIZE; + blockFill(data_stream, seek, size, (byte)0); + + shortFill(data_stream, seek, (short)OBJECT_WINDOW); + byteFill(data_stream, seek+WINDOW_IN_METHOD_OFFSET, (byte)inmethod); + shortFill(data_stream, seek+WINDOW_IN_SPEED_OFFSET, (short)inspeed); + byteFill(data_stream, seek+WINDOW_OUT_METHOD_OFFSET, (byte)outmethod); + shortFill(data_stream, seek+WINDOW_OUT_SPEED_OFFSET, (short)outspeed); + byteFill(data_stream, seek+WINDOW_STOP_METHOD_OFFSET, (byte)stopmethod); + shortFill(data_stream, seek+WINDOW_STOP_SPEED_OFFSET, (short)stopspeed); + intFill(data_stream, seek+WINDOW_STOP_TIME_OFFSET, stoptime); + intFill(data_stream, seek+WINDOW_SIZE_OFFSET, size); + + data_seek+=WINDOW_STRUCT_SIZE; + pixels_size=AddPicturePixels(filename); + + size+=pixels_size; + intFill(data_stream, seek+WINDOW_SIZE_OFFSET, size); + windows_count++; + shortFill(data_stream, windows_seek+WINDOWS_COUNT_OFFSET, (short)windows_count); + windows_size+=size; + intFill(data_stream, windows_seek+OBJECT_SIZE_OFFSET, windows_size); + if (leaf_seek>0) { + leaf_size+=size; + intFill(data_stream, leaf_seek+LEAF_SIZE_OFFSET, leaf_size); + } + if (region_seek>0) { + region_size+=size; + intFill(data_stream, region_seek+REGION_SIZE_OFFSET, region_size); + } + if (chapter_seek>0) { + chapter_size+=size; + intFill(data_stream, chapter_seek+CHAPTER_SIZE_OFFSET, chapter_size); + } + root_size+=size; + intFill(data_stream, root_seek+ROOT_SIZE_OFFSET, root_size); + data_seek=seek+size; + //System.out.println("childwindow="+data_seek); + } + + static int GetTextPixelsWidth(String text, String fontname, int fontsize, int fontstyle) { + int value=0; + BufferedImage bi; + try { + bi = createImage(text, new Font(fontname, fontstyle, fontsize), Color.BLACK, Color.YELLOW); + value = bi.getWidth(); + } catch (Exception e) { + e.printStackTrace(); + } + return value; + } + + static int GetTextPixelsHeight(String text, String fontname, int fontsize, int fontstyle) { + int value=0; + BufferedImage bi; + try { + bi = createImage(text, new Font(fontname, fontstyle, fontsize), Color.BLACK, Color.YELLOW); + value = bi.getHeight(); + } catch (Exception e) { + e.printStackTrace(); + } + return value; + } + + /* + * ¸ù¾Ýstr,fontµÄÑùʽ·µ»ØÍ¼Ïñ»º´æ + */ + static BufferedImage createImage(String str, Font font, Color bkcolor, Color color) throws Exception { + // »ñÈ¡fontµÄÑùʽӦÓÃÔÚstrÉϵÄÕû¸ö¾ØÐÎ + Rectangle2D r = font.getStringBounds(str, new FontRenderContext(AffineTransform.getScaleInstance(1, 1), false, false)); + int unitHeight = (int) Math.floor(r.getHeight());// »ñÈ¡µ¥¸ö×Ö·ûµÄ¸ß¶È + // »ñÈ¡Õû¸östrÓÃÁËfontÑùʽµÄ¿í¶ÈÕâÀïÓÃËÄÉáÎåÈëºó+1±£Ö¤¿í¶È¾ø¶ÔÄÜÈÝÄÉÕâ¸ö×Ö·û´®×÷ΪͼƬµÄ¿í¶È + int width = (int) Math.round(r.getWidth()) + 1; + int height = unitHeight + 3;// °Ñµ¥¸ö×Ö·ûµÄ¸ß¶È+3±£Ö¤¸ß¶È¾ø¶ÔÄÜÈÝÄÉ×Ö·û´®×÷ΪͼƬµÄ¸ß¶È + // ´´½¨Í¼Æ¬ + //logger.error(host+"<> ="+width+"="+height); + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); + Graphics g = image.getGraphics(); + g.setColor(bkcolor); + g.fillRect(0, 0, width, height);// ÏÈÓúÚÉ«Ìî³äÕûÕÅͼƬ,Ò²¾ÍÊDZ³¾° + g.setColor(color);// ÔÙ»»³ÉºìÉ« + g.setFont(font);// ÉèÖû­±Ê×ÖÌå + g.drawString(str, 0, font.getSize());// »­³ö×Ö·û´® + g.dispose(); + return image; + } + + static int GetJuhaoOffsetX(int fontsize){ + return -4; + } + + static int GetJuhaoOffsetY(int fontsize){ + return 8; + } + + /* + * ¸ù¾Ýstr,fontµÄÑùʽ·µ»ØÍ¼Ïñ»º´æ + */ + static BufferedImage createImageJuhao(String str, Font font, Color bkcolor, Color color, int fontsize) throws Exception { + // »ñÈ¡fontµÄÑùʽӦÓÃÔÚstrÉϵÄÕû¸ö¾ØÐÎ + FontRenderContext rc = new FontRenderContext(AffineTransform.getScaleInstance(1, 1), false, false); + Rectangle2D r = font.getStringBounds(str, rc); + String sTemp; + int unitHeight = (int) Math.floor(r.getHeight());// »ñÈ¡µ¥¸ö×Ö·ûµÄ¸ß¶È + // »ñÈ¡Õû¸östrÓÃÁËfontÑùʽµÄ¿í¶ÈÕâÀïÓÃËÄÉáÎåÈëºó+1±£Ö¤¿í¶È¾ø¶ÔÄÜÈÝÄÉÕâ¸ö×Ö·û´®×÷ΪͼƬµÄ¿í¶È + int width = (int) Math.round(r.getWidth()) + 1; + int height = unitHeight + 3;// °Ñµ¥¸ö×Ö·ûµÄ¸ß¶È+3±£Ö¤¸ß¶È¾ø¶ÔÄÜÈÝÄÉ×Ö·û´®×÷ΪͼƬµÄ¸ß¶È + int[] iWidths; + String[] sItems; + int i, k, x, y; + + x = 0; + sTemp = str; + k = sTemp.indexOf("¡£"); + while (k >= 0){ + x+=2; + sTemp = sTemp.substring(k+1); + k = sTemp.indexOf("¡£"); + } + if (!sTemp.isEmpty()) { + x++; + } + sItems = new String[x]; + iWidths = new int[x]; + + x = 0; + sTemp = str; + k = sTemp.indexOf("¡£"); + while (k >= 0){ + sItems[x++] = sTemp.substring(0, k); + sItems[x++] = "¡£"; + sTemp = sTemp.substring(k+1); + k = sTemp.indexOf("¡£"); + } + if (!sTemp.isEmpty()) { + sItems[x++] = sTemp; + } + + k = x; + width = 0; + for (i=0; i> ="+width+"="+height); + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); + Graphics g = image.getGraphics(); + g.setColor(bkcolor); + g.fillRect(0, 0, width, height);// ÏÈÓúÚÉ«Ìî³äÕûÕÅͼƬ,Ò²¾ÍÊDZ³¾° + g.setColor(color);// ÔÙ»»³ÉºìÉ« + g.setFont(font);// ÉèÖû­±Ê×ÖÌå + + x = 0; + y = font.getSize(); + for (i=0; i strlist = new ArrayList(); + ArrayList widthlist = new ArrayList(); + String szChar=""; + String szLine=""; + i=0; + while (iwidth) width=cwidth; + strlist.add(szLine); + widthlist.add(cwidth); + cwidth=0; + height+=cy; + szLine=""; + ch_return=true; + i++; + } + else if (szChar.compareTo("\n")==0) + { + if (!ch_return) + { + r=font.getStringBounds("V", new FontRenderContext(AffineTransform.getScaleInstance(1, 1), false, false)); + // »ñÈ¡µ¥¸ö×Ö·ûµÄ¸ß¶È£¬ °Ñµ¥¸ö×Ö·ûµÄ¸ß¶È+3±£Ö¤¸ß¶È¾ø¶ÔÄÜÈÝÄÉ×Ö·û´®×÷ΪͼƬµÄ¸ß¶È + cy = (int) Math.floor(r.getHeight()) + 3; + if (cwidth>width) width=cwidth; + strlist.add(szLine); + widthlist.add(cwidth); + cwidth=0; + height+=cy; + szLine=""; + } + ch_return=false; + i++; + } + else + { + r=font.getStringBounds(szChar, new FontRenderContext(AffineTransform.getScaleInstance(1, 1), false, false)); + // »ñÈ¡Õû¸östrÓÃÁËfontÑùʽµÄ¿í¶ÈÕâÀïÓÃËÄÉáÎåÈëºó+1±£Ö¤¿í¶È¾ø¶ÔÄÜÈÝÄÉÕâ¸ö×Ö·û´®×÷ΪͼƬµÄ¿í¶È + cx = (int) Math.round(r.getWidth()) + 1; + // »ñÈ¡µ¥¸ö×Ö·ûµÄ¸ß¶È£¬ °Ñµ¥¸ö×Ö·ûµÄ¸ß¶È+3±£Ö¤¸ß¶È¾ø¶ÔÄÜÈÝÄÉ×Ö·û´®×÷ΪͼƬµÄ¸ß¶È + cy = (int) Math.floor(r.getHeight()) + 3; + if (cwidth>0 && cwidth+cx>matrixwidth){ + if (cwidth>width) width=cwidth; + strlist.add(szLine); + widthlist.add(cwidth); + cwidth=cx; + height+=cy; + szLine=szChar; + } + else{ + cwidth+=cx; + szLine=szLine+szChar; + } + ch_return=false; + i++; + } + System.out.print(ch); + } + if (cwidth>0){ + if (cwidth>width) width=cwidth; + strlist.add(szLine); + widthlist.add(cwidth); + height+=cy; + } + if (width==0 || height==0){ + width=10; height=10; + } + // ´´½¨Í¼Æ¬ + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); + Graphics g = image.getGraphics(); + g.setColor(bkcolor); + g.fillRect(0, 0, width, height);// ÏÈÓúÚÉ«Ìî³äÕûÕÅͼƬ,Ò²¾ÍÊDZ³¾° + g.setColor(color);// ÔÙ»»³ÉºìÉ« + g.setFont(font);// ÉèÖû­±Ê×ÖÌå + y=font.getSize(); + for (i=0; i> 16; + green = (pix & 0x00ff00) >> 8; + blue = (pix & 0xff); + imageRGB[i*height+j] = (int) blue << 16 | (int) green << 8 | (int) red; + } + } + + return imageRGB; + } + + static int AddTextPixels(String text, String fontname, int fontsize, Color bkcolor, Color fontcolor, int fontstyle, int halign, boolean wordwrap, int matrixwidth) { + int pixels_size=0; + BufferedImage bi; + try { + //´Ë´¦»á³öÏÖÒì³££¬½øÈëexception£¬Ôì³ÉµãÕóÊý¾ÝûÓÐÌí¼ÓÉÏ£¬½ÚĿУÑé¾Í»áʧ°Ü + //ÇëÔÚ´Ë´¦´òÓ¡ÈÕÖ¾£¬ÏÔʾ´«ÈëµÄËùÓвÎÊý + //logger.error(host+"<> ="+text+"="+fontname+"="+fontstyle+"="+fontsize+"="+bkcolor+"="+fontcolor+"="+halign+"="+wordwrap+"="+matrixwidth); + bi = createImageEx(text, new Font(fontname, fontstyle, fontsize), bkcolor, fontcolor, halign, wordwrap, matrixwidth); + //logger.error(host+"<> ="+bi.getWidth()+"="+bi.getHeight()); + pixels_size=AddPixels(getBufferedImageRGB(bi), bi.getWidth() * bi.getHeight(), bi.getWidth(), bi.getHeight()); + } catch (Exception e) { + //logger.error(host+"<> ="+e.getMessage()); + e.printStackTrace(); + } + return pixels_size; + } + + static int AddTextPixelsJuhao(String text, String fontname, int fontsize, Color bkcolor, Color fontcolor, int fontstyle, int halign, boolean wordwrap, int matrixwidth) { + int pixels_size=0; + BufferedImage bi; + try { + //´Ë´¦»á³öÏÖÒì³££¬½øÈëexception£¬Ôì³ÉµãÕóÊý¾ÝûÓÐÌí¼ÓÉÏ£¬½ÚĿУÑé¾Í»áʧ°Ü + //ÇëÔÚ´Ë´¦´òÓ¡ÈÕÖ¾£¬ÏÔʾ´«ÈëµÄËùÓвÎÊý + //logger.error(host+"<> ="+text+"="+fontname+"="+fontstyle+"="+fontsize+"="+bkcolor+"="+fontcolor+"="+halign+"="+wordwrap+"="+matrixwidth); + bi = createImageJuhao(text, new Font(fontname, fontstyle, fontsize), bkcolor, fontcolor, fontsize); + //logger.error(host+"<> ="+bi.getWidth()+"="+bi.getHeight()); + pixels_size=AddPixels(getBufferedImageRGB(bi), bi.getWidth() * bi.getHeight(), bi.getWidth(), bi.getHeight()); + } catch (Exception e) { + //logger.error(host+"<> ="+e.getMessage()); + e.printStackTrace(); + } + return pixels_size; + } + + //buffer µãÕóͼƬRGBÊý×é + //buffer_size Êý×鳤¶È + //width µãÕó¿í¶È + //height µãÕó¸ß¶È + //inmethod ÒýÈ뷽ʽ£¬ÔÚ´ËjavaÎļþ×îÉÏ·½Óж¨Òå + //outmethod Òý³ö·½Ê½£¬ÔÚ´ËjavaÎļþ×îÉÏ·½Óж¨Òå + //inspeed, outspeed ÒýÈëÒý³öËÙ¶È£¬0µ½5 + //stopmethod Í£Áô·½Ê½£¬ÇëÖÃ0 + //stopspeed Í£ÁôËÙ¶È£¬ÇëÖÃ0 + public void AddChildText(String text, String fontname, int fontsize, Color bkcolor, Color fontcolor, int fontstyle, int halign, boolean wordwrap, int inmethod, int inspeed, int outmethod, int outspeed, int stopmethod, int stopspeed, int stoptime) { + int seek, size; + int pixels_size; + int matrix_width; + + seek=data_seek; + size=WINDOW_STRUCT_SIZE; + blockFill(data_stream, seek, size, (byte)0); + + shortFill(data_stream, seek, (short)OBJECT_WINDOW); + byteFill(data_stream, seek+WINDOW_IN_METHOD_OFFSET, (byte)inmethod); + shortFill(data_stream, seek+WINDOW_IN_SPEED_OFFSET, (short)inspeed); + byteFill(data_stream, seek+WINDOW_OUT_METHOD_OFFSET, (byte)outmethod); + shortFill(data_stream, seek+WINDOW_OUT_SPEED_OFFSET, (short)outspeed); + byteFill(data_stream, seek+WINDOW_STOP_METHOD_OFFSET, (byte)stopmethod); + shortFill(data_stream, seek+WINDOW_STOP_SPEED_OFFSET, (short)stopspeed); + intFill(data_stream, seek+WINDOW_STOP_TIME_OFFSET, stoptime); + intFill(data_stream, seek+WINDOW_SIZE_OFFSET, size); + + data_seek+=WINDOW_STRUCT_SIZE; + matrix_width=asInt(data_stream, windows_seek+OBJECT_RIGHT_OFFSET)-asInt(data_stream, windows_seek+OBJECT_LEFT_OFFSET); + pixels_size=AddTextPixels(text, fontname, fontsize, bkcolor, fontcolor, fontstyle, halign, wordwrap, matrix_width); + + size+=pixels_size; + intFill(data_stream, seek+WINDOW_SIZE_OFFSET, size); + windows_count++; + shortFill(data_stream, windows_seek+WINDOWS_COUNT_OFFSET, (short)windows_count); + windows_size+=size; + intFill(data_stream, windows_seek+OBJECT_SIZE_OFFSET, windows_size); + if (leaf_seek>0) { + leaf_size+=size; + intFill(data_stream, leaf_seek+LEAF_SIZE_OFFSET, leaf_size); + } + if (region_seek>0) { + region_size+=size; + intFill(data_stream, region_seek+REGION_SIZE_OFFSET, region_size); + } + if (chapter_seek>0) { + chapter_size+=size; + intFill(data_stream, chapter_seek+CHAPTER_SIZE_OFFSET, chapter_size); + } + root_size+=size; + intFill(data_stream, root_seek+ROOT_SIZE_OFFSET, root_size); + data_seek=seek+size; + //System.out.println("childwindow="+data_seek); + } + + //buffer µãÕóͼƬRGBÊý×é + //buffer_size Êý×鳤¶È + //width µãÕó¿í¶È + //height µãÕó¸ß¶È + //inmethod ÒýÈ뷽ʽ£¬ÔÚ´ËjavaÎļþ×îÉÏ·½Óж¨Òå + //outmethod Òý³ö·½Ê½£¬ÔÚ´ËjavaÎļþ×îÉÏ·½Óж¨Òå + //inspeed, outspeed ÒýÈëÒý³öËÙ¶È£¬0µ½5 + //stopmethod Í£Áô·½Ê½£¬ÇëÖÃ0 + //stopspeed Í£ÁôËÙ¶È£¬ÇëÖÃ0 + public void AddChildTextJuhao(String text, String fontname, int fontsize, Color bkcolor, Color fontcolor, int fontstyle, int halign, boolean wordwrap, int inmethod, int inspeed, int outmethod, int outspeed, int stopmethod, int stopspeed, int stoptime) { + int seek, size; + int pixels_size; + int matrix_width; + + seek=data_seek; + size=WINDOW_STRUCT_SIZE; + blockFill(data_stream, seek, size, (byte)0); + + shortFill(data_stream, seek, (short)OBJECT_WINDOW); + byteFill(data_stream, seek+WINDOW_IN_METHOD_OFFSET, (byte)inmethod); + shortFill(data_stream, seek+WINDOW_IN_SPEED_OFFSET, (short)inspeed); + byteFill(data_stream, seek+WINDOW_OUT_METHOD_OFFSET, (byte)outmethod); + shortFill(data_stream, seek+WINDOW_OUT_SPEED_OFFSET, (short)outspeed); + byteFill(data_stream, seek+WINDOW_STOP_METHOD_OFFSET, (byte)stopmethod); + shortFill(data_stream, seek+WINDOW_STOP_SPEED_OFFSET, (short)stopspeed); + intFill(data_stream, seek+WINDOW_STOP_TIME_OFFSET, stoptime); + intFill(data_stream, seek+WINDOW_SIZE_OFFSET, size); + + data_seek+=WINDOW_STRUCT_SIZE; + matrix_width=asInt(data_stream, windows_seek+OBJECT_RIGHT_OFFSET)-asInt(data_stream, windows_seek+OBJECT_LEFT_OFFSET); + pixels_size=AddTextPixelsJuhao(text, fontname, fontsize, bkcolor, fontcolor, fontstyle, halign, wordwrap, matrix_width); + + size+=pixels_size; + intFill(data_stream, seek+WINDOW_SIZE_OFFSET, size); + windows_count++; + shortFill(data_stream, windows_seek+WINDOWS_COUNT_OFFSET, (short)windows_count); + windows_size+=size; + intFill(data_stream, windows_seek+OBJECT_SIZE_OFFSET, windows_size); + if (leaf_seek>0) { + leaf_size+=size; + intFill(data_stream, leaf_seek+LEAF_SIZE_OFFSET, leaf_size); + } + if (region_seek>0) { + region_size+=size; + intFill(data_stream, region_seek+REGION_SIZE_OFFSET, region_size); + } + if (chapter_seek>0) { + chapter_size+=size; + intFill(data_stream, chapter_seek+CHAPTER_SIZE_OFFSET, chapter_size); + } + root_size+=size; + intFill(data_stream, root_seek+ROOT_SIZE_OFFSET, root_size); + data_seek=seek+size; + //System.out.println("childwindow="+data_seek); + } + + //buffer µãÕóͼƬRGBÊý×é + //buffer_size Êý×鳤¶È + //width µãÕó¿í¶È + //height µãÕó¸ß¶È + //inmethod ÒýÈ뷽ʽ£¬ÔÚ´ËjavaÎļþ×îÉÏ·½Óж¨Òå + //outmethod Òý³ö·½Ê½£¬ÔÚ´ËjavaÎļþ×îÉÏ·½Óж¨Òå + //inspeed, outspeed ÒýÈëÒý³öËÙ¶È£¬0µ½5 + //stopmethod Í£Áô·½Ê½£¬ÇëÖÃ0 + //stopspeed Í£ÁôËÙ¶È£¬ÇëÖÃ0 + public void AddChildScheduleText(String text, String fontname, int fontsize, Color bkcolor, Color fontcolor, int fontstyle, int halign, boolean wordwrap, + int inmethod, int inspeed, int outmethod, int outspeed, int stopmethod, int stopspeed, int stoptime, + int kind, int week, + int from_year, int from_month, int from_day, int from_hour, int from_minute, int from_second, + int to_year, int to_month, int to_day, int to_hour, int to_minute, int to_second) { + int seek, size; + int pixels_size; + int matrix_width; + + seek=data_seek; + size=SCHEDULE_WINDOW_STRUCT_SIZE; + blockFill(data_stream, seek, size, (byte)0); + + shortFill(data_stream, seek, (short)OBJECT_SCHEDULE_WINDOW); + byteFill(data_stream, seek+WINDOW_IN_METHOD_OFFSET, (byte)inmethod); + shortFill(data_stream, seek+WINDOW_IN_SPEED_OFFSET, (short)inspeed); + byteFill(data_stream, seek+WINDOW_OUT_METHOD_OFFSET, (byte)outmethod); + shortFill(data_stream, seek+WINDOW_OUT_SPEED_OFFSET, (short)outspeed); + byteFill(data_stream, seek+WINDOW_STOP_METHOD_OFFSET, (byte)stopmethod); + shortFill(data_stream, seek+WINDOW_STOP_SPEED_OFFSET, (short)stopspeed); + intFill(data_stream, seek+WINDOW_STOP_TIME_OFFSET, stoptime); + intFill(data_stream, seek+WINDOW_SIZE_OFFSET, size); + shortFill(data_stream, seek+WINDOW_STRUCT_SIZE+PLAY_SCHEDULE_KIND_OFFSET, (short)kind); + shortFill(data_stream, seek+WINDOW_STRUCT_SIZE+PLAY_SCHEDULE_WEEK_OFFSET, (short)week); + intFill(data_stream, seek+WINDOW_STRUCT_SIZE+PLAY_SCHEDULE_FROMTIME_OFFSET, SystemTimeToTime(from_hour, from_minute, from_second)); + intFill(data_stream, seek+WINDOW_STRUCT_SIZE+PLAY_SCHEDULE_FROMDATE_OFFSET, SystemTimeToDate(from_year, from_month, from_day)); + intFill(data_stream, seek+WINDOW_STRUCT_SIZE+PLAY_SCHEDULE_TOTIME_OFFSET, SystemTimeToTime(to_hour, to_minute, to_second)); + intFill(data_stream, seek+WINDOW_STRUCT_SIZE+PLAY_SCHEDULE_TODATE_OFFSET, SystemTimeToDate(to_year, to_month, to_day)); + + data_seek+=SCHEDULE_WINDOW_STRUCT_SIZE; + matrix_width=asInt(data_stream, windows_seek+OBJECT_RIGHT_OFFSET)-asInt(data_stream, windows_seek+OBJECT_LEFT_OFFSET); + pixels_size=AddTextPixels(text, fontname, fontsize, bkcolor, fontcolor, fontstyle, halign, wordwrap, matrix_width); + + size+=pixels_size; + intFill(data_stream, seek+WINDOW_SIZE_OFFSET, size); + windows_count++; + shortFill(data_stream, windows_seek+WINDOWS_COUNT_OFFSET, (short)windows_count); + windows_size+=size; + intFill(data_stream, windows_seek+OBJECT_SIZE_OFFSET, windows_size); + if (leaf_seek>0) { + leaf_size+=size; + intFill(data_stream, leaf_seek+LEAF_SIZE_OFFSET, leaf_size); + } + if (region_seek>0) { + region_size+=size; + intFill(data_stream, region_seek+REGION_SIZE_OFFSET, region_size); + } + if (chapter_seek>0) { + chapter_size+=size; + intFill(data_stream, chapter_seek+CHAPTER_SIZE_OFFSET, chapter_size); + } + root_size+=size; + intFill(data_stream, root_seek+ROOT_SIZE_OFFSET, root_size); + data_seek=seek+size; + //System.out.println("childwindow="+data_seek); + } + + //ÈÕÆÚʱ¼äÏÔʾ¸ñʽ´¦Àíº¯Êý + private void SDClockFormat(byte[] stream, int index, String format){ + if (format=="#y"){ + stream[index]=DF_YEAR; + stream[index+1]=0; + }else if (format=="#m"){ + stream[index]=DF_MONTH; + stream[index+1]=0; + }else if (format=="#w"){ + stream[index]=DF_WEEK; + stream[index+1]=0; + }else if (format=="#d"){ + stream[index]=DF_DAY; + stream[index+1]=0; + }else if (format=="#h"){ + stream[index]=DF_HOUR; + stream[index+1]=0; + }else if (format=="#n"){ + stream[index]=DF_MINUTE; + stream[index+1]=0; + }else if (format=="#s"){ + stream[index]=DF_SECOND; + stream[index+1]=0; + }else if (format=="Äê"){ + stream[index]=DF_USER; + stream[index+1]=0; + }else if (format=="ÔÂ"){ + stream[index]=DF_USER; + stream[index+1]=1; + }else if (format=="ÈÕ"){ + stream[index]=DF_USER; + stream[index+1]=2; + }else if (format=="ʱ"){ + stream[index]=DF_USER; + stream[index+1]=3; + }else if (format=="·Ö"){ + stream[index]=DF_USER; + stream[index+1]=4; + }else if (format=="Ãë"){ + stream[index]=DF_USER; + stream[index+1]=5; + }else if (format=="ÐÇ"){ + stream[index]=DF_USER; + stream[index+1]=6; + }else if (format=="ÆÚ"){ + stream[index]=DF_USER; + stream[index+1]=7; + }else if (format=="-"){ + stream[index]=DF_USER; + stream[index+1]=8; + }else if (format==":"){ + stream[index]=DF_USER; + stream[index+1]=9; + }else if (format==" "){ + stream[index]=DF_USER; + stream[index+1]=10; + } + } + + public void AddStringDateTime(int left, int top, int width, int height, int color, int fontset, String[] formats, int formats_count) { + int seek, size; + int i; + seek=data_seek; + size=SDCLOCK_STRUCT_SIZE; + blockFill(data_stream, seek, size, (byte)0); + shortFill(data_stream, seek, (short)OBJECT_STRING_DCLOCK); + blockFill(data_stream, seek+OBJECT_TRANSPARENT_OFFSET, 1, (byte)1); + intFill(data_stream, seek+OBJECT_LEFT_OFFSET, left); + intFill(data_stream, seek+OBJECT_TOP_OFFSET, top); + intFill(data_stream, seek+OBJECT_RIGHT_OFFSET, left+width); + intFill(data_stream, seek+OBJECT_BOTTOM_OFFSET, top+height); + for (i=0; i0) { + leaf_count++; + shortFill(data_stream, leaf_seek+LEAF_COUNT_OFFSET, (short)leaf_count); + leaf_size+=size; + intFill(data_stream, leaf_seek+LEAF_SIZE_OFFSET, leaf_size); + } + if (region_seek>0) { + region_size+=size; + intFill(data_stream, region_seek+REGION_SIZE_OFFSET, region_size); + } + if (chapter_seek>0) { + chapter_size+=size; + intFill(data_stream, chapter_seek+CHAPTER_SIZE_OFFSET, chapter_size); + } + root_size+=size; + intFill(data_stream, root_seek+ROOT_SIZE_OFFSET, root_size); + data_seek=seek+size; + //System.out.println("strings="+data_seek); + } + + //Ìí¼ÓÄÚÂëÎÄ×Ö£¬ÐèÒª¿ØÖÆ¿¨ÏÂÔØ×Ö¿â + //left,top,width,height: ×óÉÏ¿í¸ß + //text: ÎÄ×Ö + //inmethod: ÒýÈ뷽ʽ + //inspeed: ÒýÈëËÙ¶È + //outmethod: Òý³ö·½Ê½ + //outspeed: Òý³öËÙ¶È + //stopmethod: Í£Áô·½Ê½ + //stopspeed: Í£ÁôËÙ¶È + //stoptime: Í£Áôʱ¼ä£¨ºÁÃ룩 + public void AddString(int left, int top, int width, int height, String text, int inmethod, int inspeed, int outmethod, int outspeed, int stopmethod, int stopspeed, int stoptime, int color, int fontset) { + AddStrings(left, top, width, height); + AddChildString(text, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime, color, fontset); + } + + //Ìí¼ÓµãÕóͼƬ + //left,top,width,height: ×óÉÏ¿í¸ß + //buffer: ͼƬµãÕóÊý¾Ý + //buffer_size: Êý¾Ý³¤¶È + //inmethod: ÒýÈ뷽ʽ + //inspeed: ÒýÈëËÙ¶È + //outmethod: Òý³ö·½Ê½ + //outspeed: Òý³öËÙ¶È + //stopmethod: Í£Áô·½Ê½ + //stopspeed: Í£ÁôËÙ¶È + //stoptime: Í£Áôʱ¼ä£¨ºÁÃ룩 + public void AddWindow(int left, int top, int width, int height, int[] buffer, int buffer_size, int dib_width, int dib_height, int inmethod, int inspeed, int outmethod, int outspeed, int stopmethod, int stopspeed, int stoptime) { + AddWindows(left, top, width, height); + AddChildWindow(buffer, buffer_size, dib_width, dib_height, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime); + } + + //Ìí¼ÓͼƬÎļþ + //left,top,width,height: ×óÉÏ¿í¸ß + //filename: ͼƬÎļþÃû + //inmethod: ÒýÈ뷽ʽ + //inspeed: ÒýÈëËÙ¶È + //outmethod: Òý³ö·½Ê½ + //outspeed: Òý³öËÙ¶È + //stopmethod: Í£Áô·½Ê½ + //stopspeed: Í£ÁôËÙ¶È + //stoptime: Í£Áôʱ¼ä£¨ºÁÃ룩 + public void AddPicture(int left, int top, int width, int height, String filename, int inmethod, int inspeed, int outmethod, int outspeed, int stopmethod, int stopspeed, int stoptime) { + AddWindows(left, top, width, height); + AddChildPicture(filename, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime); + } + + //Ìí¼ÓµãÕóÎÄ×Ö + //left,top,width,height: ×óÉÏ¿í¸ß + //text: ÎÄ×Ö + //fontname: ×ÖÌåÃû³Æ + //fontsize: ×ÖÌå´óС + //bkcolor: ±³¾°É«£¨ÎÞЧ£¬ÖÃ0£© + //fontcolor: ×ÖÌåÑÕÉ« + //fontstyle: ×ÖÌå·ç¸ñ£¨ÎÞЧ£¬ÖÃ0£© + //inmethod: ÒýÈ뷽ʽ + //inspeed: ÒýÈëËÙ¶È + //outmethod: Òý³ö·½Ê½ + //outspeed: Òý³öËÙ¶È + //stopmethod: Í£Áô·½Ê½ + //stopspeed: Í£ÁôËÙ¶È + //stoptime: Í£Áôʱ¼ä£¨ºÁÃ룩 + public void AddText(int left, int top, int width, int height, String text, String fontname, int fontsize, Color bkcolor, Color fontcolor, int fontstyle, int halign, boolean wordwrap, int inmethod, int inspeed, int outmethod, int outspeed, int stopmethod, int stopspeed, int stoptime) { + AddWindows(left, top, width, height); + AddChildText(text, fontname, fontsize, bkcolor, fontcolor, fontstyle, halign, wordwrap, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime); + } + + //Ìí¼ÓµãÕóÎÄ×Ö + //left,top,width,height: ×óÉÏ¿í¸ß + //text: ÎÄ×Ö + //halign: ºáÏò¶ÔÆë·½Ê½ 0¿¿×ó£¬1¾ÓÖУ¬2¿¿ÓÒ + //valign: ×ÝÏò¶ÔÆë·½Ê½ 0¿¿ÉÏ£¬1¾ÓÖУ¬2¿¿Ï + //fontname: ×ÖÌåÃû³Æ + //fontsize: ×ÖÌå´óС + //bkcolor: ±³¾°É«£¨ÎÞЧ£¬ÖÃ0£© + //fontcolor: ×ÖÌåÑÕÉ« + //fontstyle: ×ÖÌå·ç¸ñ£¨ÎÞЧ£¬ÖÃ0£© + //inmethod: ÒýÈ뷽ʽ + //inspeed: ÒýÈëËÙ¶È + //outmethod: Òý³ö·½Ê½ + //outspeed: Òý³öËÙ¶È + //stopmethod: Í£Áô·½Ê½ + //stopspeed: Í£ÁôËÙ¶È + //stoptime: Í£Áôʱ¼ä£¨ºÁÃ룩 + public void AddTextEx(int left, int top, int width, int height, String text, int halign, int valign, String fontname, int fontsize, Color bkcolor, Color fontcolor, int fontstyle, int inmethod, int inspeed, int outmethod, int outspeed, int stopmethod, int stopspeed, int stoptime) { + int textwidth, textheight; + AddWindows(left, top, width, height); + AddChildText(text, fontname, fontsize, bkcolor, fontcolor, fontstyle, halign, false, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime); + + textwidth=GetTextPixelsWidth(text, fontname, fontsize, fontstyle); + if (textwidth>1)); + break; + case ALIGN_RIGHT: + intFill(data_stream, windows_seek+OBJECT_LEFT_OFFSET, left+width-textwidth); + break; + } + } + textheight=GetTextPixelsHeight(text, fontname, fontsize, fontstyle); + if (textheight>1)); + break; + case ALIGN_BOTTOM: + intFill(data_stream, windows_seek+OBJECT_TOP_OFFSET, top+height-textheight); + break; + } + } + } + + //Ìí¼ÓµãÕóÎÄ×Ö + //left,top,width,height: ×óÉÏ¿í¸ß + //text: ÎÄ×Ö + //fontname: ×ÖÌåÃû³Æ + //fontsize: ×ÖÌå´óС + //bkcolor: ±³¾°É«£¨ÎÞЧ£¬ÖÃ0£© + //fontcolor: ×ÖÌåÑÕÉ« + //fontstyle: ×ÖÌå·ç¸ñ£¨ÎÞЧ£¬ÖÃ0£© + //inmethod: ÒýÈ뷽ʽ + //inspeed: ÒýÈëËÙ¶È + //outmethod: Òý³ö·½Ê½ + //outspeed: Òý³öËÙ¶È + //stopmethod: Í£Áô·½Ê½ + //stopspeed: Í£ÁôËÙ¶È + //stoptime: Í£Áôʱ¼ä£¨ºÁÃ룩 + public void AddTextJuhao(int left, int top, int width, int height, String text, String fontname, int fontsize, Color bkcolor, Color fontcolor, int fontstyle, int halign, boolean wordwrap, int inmethod, int inspeed, int outmethod, int outspeed, int stopmethod, int stopspeed, int stoptime) { + AddWindows(left, top, width, height); + AddChildTextJuhao(text, fontname, fontsize, bkcolor, fontcolor, fontstyle, halign, wordwrap, inmethod, inspeed, outmethod, outspeed, stopmethod, stopspeed, stoptime); + } + + //ÈÕÆÚʱ¼äÏÔʾ¸ñʽ´¦Àíº¯Êý + private int DClockFormat(byte[] stream, int index, String format){ + if (format=="#y"){ + stream[index]=DF_USER; + stream[index+1]=2; + stream[index+2]=DF_USER; + stream[index+3]=0; + stream[index+4]=DF_YEAR; + stream[index+5]=0; + stream[index+6]=DF_YEAR; + stream[index+7]=1; + return 8; + }else if (format=="#m"){ + stream[index]=DF_MONTH; + stream[index+1]=0; + stream[index+2]=DF_MONTH; + stream[index+3]=1; + return 4; + }else if (format=="#w"){ + stream[index]=DF_WEEK; + stream[index+1]=10; + return 2; + }else if (format=="#d"){ + stream[index]=DF_DAY; + stream[index+1]=0; + stream[index+2]=DF_DAY; + stream[index+3]=1; + return 4; + }else if (format=="#h"){ + stream[index]=DF_HOUR; + stream[index+1]=0; + stream[index+2]=DF_HOUR; + stream[index+3]=1; + return 4; + }else if (format=="#n"){ + stream[index]=DF_MINUTE; + stream[index+1]=0; + stream[index+2]=DF_MINUTE; + stream[index+3]=1; + return 4; + }else if (format=="#s"){ + stream[index]=DF_SECOND; + stream[index+1]=0; + stream[index+2]=DF_SECOND; + stream[index+3]=1; + return 4; + }else if (format=="Äê"){ + stream[index]=DF_USER; + stream[index+1]=17; + return 2; + }else if (format=="ÔÂ"){ + stream[index]=DF_USER; + stream[index+1]=18; + return 2; + }else if (format=="ÈÕ"){ + stream[index]=DF_USER; + stream[index+1]=19; + return 2; + }else if (format=="ʱ"){ + stream[index]=DF_USER; + stream[index+1]=20; + return 2; + }else if (format=="·Ö"){ + stream[index]=DF_USER; + stream[index+1]=21; + return 2; + }else if (format=="Ãë"){ + stream[index]=DF_USER; + stream[index+1]=22; + return 2; + }else if (format=="ÐÇÆÚ"){ + stream[index]=DF_USER; + stream[index+1]=23; + return 2; + }else if (format=="-"){ + stream[index]=DF_USER; + stream[index+1]=24; + return 2; + }else if (format==":"){ + stream[index]=DF_USER; + stream[index+1]=25; + return 2; + }else if (format==" "){ + stream[index]=DF_USER; + stream[index+1]=26; + return 2; + } + return 0; + } + + public void AddDateTime(int left, int top, int width, int height, String[] formats, int formats_count, String fontname, int fontsize, Color bkcolor, Color fontcolor, int fontstyle) + { + int seek, format_seek, size; + int i; + int pixels_size; + int pixelset_size; + + seek=data_seek; + size=DCLOCK_STRUCT_SIZE; + blockFill(data_stream, seek, size, (byte)0); + shortFill(data_stream, seek, (short)OBJECT_DCLOCK); + blockFill(data_stream, seek+OBJECT_TRANSPARENT_OFFSET, 1, (byte)1); + intFill(data_stream, seek+OBJECT_LEFT_OFFSET, left); + intFill(data_stream, seek+OBJECT_TOP_OFFSET, top); + intFill(data_stream, seek+OBJECT_RIGHT_OFFSET, left+width); + intFill(data_stream, seek+OBJECT_BOTTOM_OFFSET, top+height); + format_seek=OBJECT_STRUCT_SIZE+DCLOCK_FORMAT_OFFSET; + for (i=0; i0) { + leaf_count++; + shortFill(data_stream, leaf_seek+LEAF_COUNT_OFFSET, (short)leaf_count); + leaf_size+=size; + intFill(data_stream, leaf_seek+LEAF_SIZE_OFFSET, leaf_size); + } + if (region_seek>0) { + region_size+=size; + intFill(data_stream, region_seek+REGION_SIZE_OFFSET, region_size); + } + if (chapter_seek>0) { + chapter_size+=size; + intFill(data_stream, chapter_seek+CHAPTER_SIZE_OFFSET, chapter_size); + } + root_size+=size; + intFill(data_stream, root_seek+ROOT_SIZE_OFFSET, root_size); + data_seek=seek+size; + } + + //interval Á½´ÎÓïÒô²¥·Åʱ¼ä¼ä¸ô + //times ÖØ¸´´ÎÊý =0ʱ£¬ÎÞÏÞÑ­»·Öظ´²¥·Å + //speeker ÀʶÁÕß 0-5 + //volumn ÒôÁ¿ 0-9 + //speed ÓïËÙ 0-9 + //tone Óïµ÷ 0-9 + public void AddVoice(String text, int interval, int times, int speaker, int volumn, int speed, int tone) + { + int seek, size; + int len=0; + byte[] gb2312; + try { + byte[] s=text.getBytes("GB2312"); + print_stream(s, s.length); + len=s.length+1; + if ((len&0x3)>0) len=((len+0x3)&(~0x3)); + gb2312=new byte[len]; + blockFill(gb2312, 0, len, (byte)0); + blockCopy(gb2312, 0, s, 0, s.length); + } catch (Exception e) { + e.printStackTrace(); + gb2312=new byte[0]; + } + seek=data_seek; + size=VOICE_STRUCT_SIZE+len; + size=((size+0x3)&(~0x3)); + blockFill(data_stream, seek, size, (byte)0); + shortFill(data_stream, seek, (short)OBJECT_VOICE); + intFill(data_stream, seek+OBJECT_SIZE_OFFSET, size); + intFill(data_stream, seek+VOICE_INTERVAL_OFFSET, interval); + intFill(data_stream, seek+VOICE_TIMES_OFFSET, times); + byteFill(data_stream, seek+VOICE_SPEAKER_OFFSET, (byte)speaker); + byteFill(data_stream, seek+VOICE_VOLUMN_OFFSET, (byte)volumn); + byteFill(data_stream, seek+VOICE_SPEED_OFFSET, (byte)speed); + byteFill(data_stream, seek+VOICE_TONE_OFFSET, (byte)tone); + blockCopy(data_stream, seek+VOICE_STRUCT_SIZE, gb2312, 0, len); + + if (leaf_seek>0) { + leaf_count++; + shortFill(data_stream, leaf_seek+LEAF_COUNT_OFFSET, (short)leaf_count); + leaf_size+=size; + intFill(data_stream, leaf_seek+LEAF_SIZE_OFFSET, leaf_size); + } + if (region_seek>0) { + region_size+=size; + intFill(data_stream, region_seek+REGION_SIZE_OFFSET, region_size); + } + if (chapter_seek>0) { + chapter_size+=size; + intFill(data_stream, chapter_seek+CHAPTER_SIZE_OFFSET, chapter_size); + } + root_size+=strings_size; + intFill(data_stream, root_seek+ROOT_SIZE_OFFSET, root_size); + data_seek=seek+size; + //System.out.println("strings="+data_seek); + } + + // Æðʼ°ü + public int pkg_begin(byte[] packet, int addr) { + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_BEGIN); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE); + } + + // ½áÊø°ü + public int pkg_end(byte[] packet, int addr, int serial_no) { + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_END); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + intFill(cmd_stream, PKG_HEADER_SERIALNO_OFFSET, serial_no); + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE); + } + + // Êý¾Ý°ü + public int pkg_data(byte[] packet, int addr, int serial_no, int pkg_length) { + int size; + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_DATA); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + intFill(cmd_stream, PKG_HEADER_SERIALNO_OFFSET, serial_no); + size=(data_seek-(serial_no-1)*pkg_length); + if (size>0){ + if (size>pkg_length) size=pkg_length; + blockCopy(cmd_stream, PKG_HEADER_STRUCT_SIZE, data_stream, (serial_no-1)*pkg_length, size); + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE+size); + } + else{ + return 0; + } + } + + // »ñÈ¡Êý¾Ý°üÊýÁ¿ + public int get_pkg_count(int pkg_length){ + if ((data_seek%pkg_length)>0){ + return data_seek/pkg_length+1; + } + else{ + return data_seek/pkg_length; + } + } + + public int parse_trans_respond(byte[] packet, int size, int command, int serialno){ + size=Depack(respond_stream, packet, size); + if (size>=RESPOND_STRUCT_SIZE && asShort(respond_stream, 0)==PKC_RESPOND && + asShort(respond_stream, PKG_HEADER_STRUCT_SIZE+RESPOND_COMMAND_OFFSET)==command){ + switch (command){ + case PKC_DATA: + if (asShort(respond_stream, PKG_HEADER_STRUCT_SIZE+RESPOND_RESULT_OFFSET)==1) + { + if (serialno==asInt(respond_stream, PKG_HEADER_SERIALNO_OFFSET)) + return 1; + } + else + { + fix_serialno=asInt(respond_stream, PKG_HEADER_SERIALNO_OFFSET); + return 2; + } + break; + default: + if (serialno==asInt(respond_stream, PKG_HEADER_SERIALNO_OFFSET)) + return 1; + break; + } + } + return 0; + } + + public int parse_notify(byte[] packet, int size){ + size=Depack(respond_stream, packet, size); + if (size>=PKG_HEADER_STRUCT_SIZE && asShort(respond_stream, PKG_HEADER_COMMAND_OFFSET)==PKC_NOTIFY){ + return asInt(respond_stream, PKG_HEADER_SERIALNO_OFFSET); + } + return 0; + } + + // ¸´Î»¿ØÖÆ¿¨½ÚÄ¿ÏÔʾ + public int pkg_reset_display(byte[] packet, int addr, int power) { + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_SET_POWER); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE); + } + + // ¶ÁÈ¡µçԴ״̬ + public int pkg_get_power(byte[] packet, int addr) { + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_GET_POWER); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE); + } + + // ÉèÖõçԴ״̬£¬power=0¹Ø±ÕµçÔ´£¬power=1´ò¿ªµçÔ´ + public int pkg_set_power(byte[] packet, int addr, int power) { + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_SET_POWER); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + intFill(cmd_stream, PKG_HEADER_SERIALNO_OFFSET, power); + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE); + } + + // ¶ÁÈ¡ÁÁ¶È + public int pkg_get_bright(byte[] packet, int addr) { + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_GET_BRIGHT); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE); + } + + // ÉèÖÃÁÁ¶È£¬bright=0µ½7 + public int pkg_set_bright(byte[] packet, int addr, int bright) { + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_SET_BRIGHT); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + intFill(cmd_stream, PKG_HEADER_SERIALNO_OFFSET, bright); + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE); + } + + // УÕýʱ¼ä + public int pkg_adjust_time_ex(byte[] packet, int addr, int year, int month, int week, int day, int hour, int minute, int second) { + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE+SYSTEMTIME_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_ADJUST_TIME); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + shortFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+SYSTEMTIME_YEAR_OFFSET, (short)year); + shortFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+SYSTEMTIME_MONTH_OFFSET, (short)month); + shortFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+SYSTEMTIME_WEEK_OFFSET, (short)week); + shortFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+SYSTEMTIME_DAY_OFFSET, (short)day); + shortFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+SYSTEMTIME_HOUR_OFFSET, (short)hour); + shortFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+SYSTEMTIME_MINUTE_OFFSET, (short)minute); + shortFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+SYSTEMTIME_SECOND_OFFSET, (short)second); + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE+SYSTEMTIME_SIZE); + } + + // УÕýʱ¼ä + public int pkg_adjust_time(byte[] packet, int addr) { + Calendar c = Calendar.getInstance(); + //12Ð¡Ê±ÖÆ + //return pkg_adjust_time_ex(packet, addr, c.get(Calendar.YEAR), c.get(Calendar.MONTH)+1, c.get(Calendar.DAY_OF_WEEK)-1, + // c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.HOUR), c.get(Calendar.MINUTE), c.get(Calendar.SECOND)); + //24Ð¡Ê±ÖÆ + return pkg_adjust_time_ex(packet, addr, c.get(Calendar.YEAR), c.get(Calendar.MONTH)+1, c.get(Calendar.DAY_OF_WEEK)-1, + c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND)); + } + + // ÉèÖÃ5VÊä³ö״̬£¬value=0¹Ø±Õ5VÊä³ö£¬value=1¿ªÆô5VÊä³ö + public int pkg_set_switch(byte[] packet, int addr, int value) { + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_SET_SWITCH); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + intFill(cmd_stream, PKG_HEADER_SERIALNO_OFFSET, value); + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE); + } + + // ¶ÁÈ¡¿ØÖÆ¿¨²ÎÊý + public int pkg_get_boardparam(byte[] packet, int addr) { + get_boardparam_respond_size = 0; + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_GET_PARAM); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE); + } + + // ÉèÖÿØÖÆ¿¨²ÎÊý_IP + public int pkg_set_boardparam_ip(byte[] packet, int addr, byte[] ip) { + int boart_param_size; + if (get_boardparam_respond_size>0) + { + boart_param_size=get_boardparam_respond_size-RESPOND_STRUCT_SIZE; + get_boardparam_respond_size = 0; + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE+boart_param_size, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_SET_PARAM); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + blockCopy(cmd_stream, PKG_HEADER_STRUCT_SIZE, respond_stream, RESPOND_STRUCT_SIZE, boart_param_size); + blockCopy(cmd_stream, PKG_HEADER_STRUCT_SIZE + BOARDPARAM_IP_OFFSET, ip, 0, 4); + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE+boart_param_size); + } + return 0; + } + + // ÉèÖö¨Ê±¿ª¹ØÆÁ¼Æ»® -- °´Ò»ÖÜ7ÌìÿÈÕ¶¨Ê±¿ª¹ØÆÁ£¬Ã¿ÈÕ¿ÉÒÔ¶¨Òå3¸öʱ¶Î + public int pkg_power_schedule_weekday(byte[] packet, int addr, boolean enabled) { + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_SET_POWER_SCHEDULE); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + if (enabled){ + intFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_ENABLED_OFFSET, 0x55AAAA55); + }else{ + intFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_ENABLED_OFFSET, 0); + } + intFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_MODE_OFFSET, 0); + + //ÖÜÈÕ£¬3¸ö¿ª¹ØÆÁʱ¶Î£¬ÖÜ1µ½ÖÜ6ͬÀí + // ʱ¶Î1 + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_SUNDAY_OPENTIME_OFFSET, 2015, 9, 30, 9, 0, 0); + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_SUNDAY_CLOSETIME_OFFSET, 2015, 9, 30, 12, 0, 0); + // ʱ¶Î2 + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_SUNDAY_OPENTIME_OFFSET+8, 2015, 9, 30, 13, 30, 0); + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_SUNDAY_CLOSETIME_OFFSET+8, 2015, 9, 30, 18, 22, 0); + // ʱ¶Î3 + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_SUNDAY_OPENTIME_OFFSET+16, 2015, 9, 30, 18, 23, 0); + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_SUNDAY_CLOSETIME_OFFSET+16, 2015, 9, 30, 21, 0, 0); + //ÖÜÒ» + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_MONDAY_OPENTIME_OFFSET, 2015, 9, 30, 8, 30, 0); + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_MONDAY_CLOSETIME_OFFSET, 2015, 9, 30, 17, 0, 0); + //Öܶþ + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_TUESDAY_OPENTIME_OFFSET, 2015, 9, 30, 8, 30, 0); + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_TUESDAY_CLOSETIME_OFFSET, 2015, 9, 30, 17, 0, 0); + //ÖÜÈý + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_WEDNESDAY_OPENTIME_OFFSET, 2015, 9, 30, 8, 30, 0); + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_WEDNESDAY_CLOSETIME_OFFSET, 2015, 9, 30, 17, 0, 0); + //ÖÜËÄ + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_THURSDAY_OPENTIME_OFFSET, 2015, 9, 30, 8, 30, 0); + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_THURSDAY_CLOSETIME_OFFSET, 2015, 9, 30, 17, 0, 0); + //ÖÜÎå + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_FRIDAY_OPENTIME_OFFSET, 2015, 9, 30, 8, 30, 0); + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_FRIDAY_CLOSETIME_OFFSET, 2015, 9, 30, 17, 0, 0); + //ÖÜÁù + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_SATURDAY_OPENTIME_OFFSET, 2015, 9, 30, 9, 0, 0); + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_SATURDAY_CLOSETIME_OFFSET, 2015, 9, 30, 12, 0, 0); + + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_SIZE); + } + + // ÉèÖö¨Ê±¿ª¹ØÆÁ¼Æ»® -- °´Ö¸¶¨µÄÆðÖ¹ÈÕÆÚʱ¼ä²¥·Å£¬Ò»¹²¿ÉÒÔ¶¨Òå21¸öʱ¶Î + public int pkg_power_schedule_period(byte[] packet, int addr, boolean enabled) { + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_SET_POWER_SCHEDULE); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + if (enabled){ + intFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_ENABLED_OFFSET, 0x55AAAA55); + }else{ + intFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_ENABLED_OFFSET, 0); + } + intFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_MODE_OFFSET, 1); + + //Ò»¹²21¸öʱ¶Î£¬Ã¿¸öʱ¶ÎÆ«ÒÆÁ¿¼ä¸ô8¸ö×Ö½Ú + //ÏÂÃæÀý×ÓΪ£ºÎåÒ»¿ªÆÁ3Ì죬ÁùÒ»¡¢ÆßÒ»¡¢°ËÒ»¸÷¿ªÆÁ1Ìì + // ʱ¶Î1 + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_OPENTIME_OFFSET, 2015, 5, 1, 0, 0, 0); + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_SUNDAY_CLOSETIME_OFFSET, 2015, 5, 3, 23, 59, 59); + // ʱ¶Î2 + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_OPENTIME_OFFSET+8, 2015, 6, 1, 0, 0, 0); + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_CLOSETIME_OFFSET+8, 2015, 6, 1, 23, 59, 59); + // ʱ¶Î3 + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_OPENTIME_OFFSET+16, 2015, 7, 1, 0, 0, 0); + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_CLOSETIME_OFFSET+16, 2015, 7, 1, 23, 59, 59); + // ʱ¶Î4 + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_OPENTIME_OFFSET+24, 2015, 8, 1, 0, 0, 0); + timestampFill(cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_CLOSETIME_OFFSET+24, 2015, 8, 1, 23, 59, 59); + // ...... + + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE+PWOERSCHEDULE_SIZE); + } + + // ´®¿Úת·¢ + public int pkg_com_transfer(byte[] packet, int addr, byte[] buffer, int size) { + blockFill(cmd_stream, 0, PKG_HEADER_STRUCT_SIZE, (byte)0); + shortFill(cmd_stream, PKG_HEADER_COMMAND_OFFSET, (short)PKC_COM_TRANSFER); + byteFill(cmd_stream, PKG_HEADER_DSTADDR_OFFSET, (byte)addr); + blockCopy(cmd_stream, PKG_HEADER_STRUCT_SIZE, buffer, 0, size); + return Pack(packet, cmd_stream, PKG_HEADER_STRUCT_SIZE+size); + } + + private void Encrypt(byte[] src, byte[] dst, int start, int size){ + int key=57943; + int key1=36028; + int key2=47926; + int vsrc, vdst; + int i; + for (i=0; i<=((size>>1)-1); i++) + { + vsrc=asShort(src, (i+(start>>1))<<1); + if (vsrc<0) vsrc=65536+vsrc; + vdst=vsrc^key; + shortFill(dst, (i+(start>>1))<<1, (short)vdst); + key=key*key1+key2; + } + } + + private int DecryptToStream(String filename, byte[] stream, int start){ + InputStream in = null; + int seek=start; + int crc1, crc2; + try { + // Ò»´Î¶Á¶à¸ö×Ö½Ú + byte[] buffer = new byte[130]; + int rsize = 0; + in = new FileInputStream(filename); + // ¶ÁÈë¶à¸ö×Ö½Úµ½×Ö½ÚÊý×éÖУ¬bytereadΪһ´Î¶ÁÈëµÄ×Ö½ÚÊý + while ((rsize = in.read(buffer)) != -1) { + if (rsize!=0){ + crc1=CreateCRC(buffer, rsize-2); + crc2=asShort(buffer, rsize - 2); + if (crc2<0) crc2=65536+crc2; + if (crc1==crc2){ + blockCopy(stream, seek, buffer, 0, rsize-2); + seek+=(rsize-2); + } + } + } + Encrypt(stream, stream, start, seek-start); + } catch (Exception e1) { + e1.printStackTrace(); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e1) { + } + } + } + return seek; + } + + public void Upgrade(String filename) { + root_seek=0; + root_count=0; + root_size=12; + blockFill(data_stream, root_seek, root_size, (byte)0); + shortFill(data_stream, root_seek, (short)0x13); + root_size=DecryptToStream(filename, data_stream, root_size); + intFill(data_stream, root_seek+ROOT_SIZE_OFFSET, root_size); + data_seek=root_seek+root_size; + } + + // ½âÎö»ñÈ¡µçԴ״̬µÄÓ¦´ð + public int parse_cmd_respond(byte[] packet, int size){ + size=Depack(respond_stream, packet, size); + if (size>=RESPOND_STRUCT_SIZE && asShort(respond_stream, 0)==PKC_RESPOND){ + switch(asShort(respond_stream, PKG_HEADER_STRUCT_SIZE+RESPOND_COMMAND_OFFSET)){ + case PKC_GET_POWER: + if (asInt(respond_stream, PKG_HEADER_SERIALNO_OFFSET)==0){ + System.out.println("¶ÁÈ¡µçԴ״̬Íê³É£¬µçÔ´¹Ø±Õ"); + }else{ + System.out.println("¶ÁÈ¡µçԴ״̬Íê³É£¬µçÔ´¿ªÆô"); + } + break; + case PKC_SET_POWER: + if (asInt(respond_stream, PKG_HEADER_SERIALNO_OFFSET)==0){ + System.out.println("ÉèÖõçԴ״̬Íê³É£¬µçÔ´¹Ø±Õ"); + }else{ + System.out.println("ÉèÖõçԴ״̬Íê³É£¬µçÔ´¿ªÆô"); + } + break; + case PKC_GET_BRIGHT: + System.out.println("¶ÁÈ¡ÁÁ¶ÈÍê³É£¬ÁÁ¶È="+asInt(respond_stream, PKG_HEADER_SERIALNO_OFFSET)); + break; + case PKC_SET_BRIGHT: + System.out.println("ÉèÖÃÁÁ¶ÈÍê³É£¬ÁÁ¶È="+asInt(respond_stream, PKG_HEADER_SERIALNO_OFFSET)); + break; + case PKC_ADJUST_TIME: + System.out.println("УÕýʱ¼äÍê³É"); + break; + case PKC_SET_POWER_SCHEDULE: + System.out.println("ÉèÖö¨Ê±¿ª¹ØÆÁÍê³É"); + break; + case PKC_GET_PARAM: + System.out.println("¶ÁÈ¡¿ØÖÆ¿¨²ÎÊýÍê³É¡£" + + " ¿í¶È="+asShort(respond_stream, RESPOND_STRUCT_SIZE+BOARDPARAM_WIDTH_OFFSET) + + " ¸ß¶È="+asShort(respond_stream, RESPOND_STRUCT_SIZE+BOARDPARAM_HEIGHT_OFFSET) + + " »ùÉ«="+asShort(respond_stream, RESPOND_STRUCT_SIZE+BOARDPARAM_COLORMODE_OFFSET) + ); + get_boardparam_respond_size=size; + break; + case PKC_SET_PARAM: + System.out.println("ÉèÖÿØÖÆ¿¨²ÎÊýÍê³É"); + break; + } + return 1; + } + return 0; + } + + public void Compress(){ + LZSS lzss = new LZSS(); + byte[] lzss_buf = new byte[root_size + 1024]; + int lzss_size; + blockCopy(lzss_buf, 0, data_stream, 0, ROOT_STRUCT_SIZE); + lzss_size = lzss.Encode(data_stream, ROOT_STRUCT_SIZE, root_size-ROOT_STRUCT_SIZE, lzss_buf, ROOT_STRUCT_SIZE); + intFill(lzss_buf, ROOT_SIZE_OFFSET, lzss_size+ROOT_STRUCT_SIZE); + shortFill(lzss_buf, ROOT_FLAG_OFFSET, (short)(asShort(lzss_buf, ROOT_FLAG_OFFSET) | 1)); + blockCopy(data_stream, 0, lzss_buf, 0, lzss_size+ROOT_STRUCT_SIZE); + data_seek=lzss_size+ROOT_STRUCT_SIZE; + } + + public int GetDataSize(){ + return data_seek; + } + + public LEDSender2010() { + data_stream = new byte[1<<24]; + cmd_stream = new byte[1024]; + respond_stream = new byte[1024]; + packet_stream = new byte[1280]; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/utils/LZSS.java b/src/com/wms/dss/ats/customs/abb/utils/LZSS.java new file mode 100644 index 0000000..68fde71 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/LZSS.java @@ -0,0 +1,164 @@ +package com.wms.dss.ats.customs.abb.utils; + +public class LZSS { + + static int N = 4096; + static int F = 18; + static int THRESHOLD = 2; + static int NIL = N; + + static int textsize = 0; + static int codesize = 0; + static int printcount = 0; + static int text_buf[]; + static int match_position, match_length; + static int lson[], rson[], dad[]; + + public LZSS() { + lson = new int[N + 1]; + rson = new int[N + 257]; + dad = new int[N + 1]; + text_buf = new int[N + F - 1]; + } + + private static void InitTree() /* initialize trees */ + { + int i; + textsize = 0; codesize = 0; printcount = 0; + for (i = N + 1; i <= N + 256; i++) rson[i] = NIL; + for (i = 0; i < N; i++) dad[i] = NIL; + } + + private static void InsertNode(int r) + { + int i, p, cmp; + //unsigned char *key; + + //key = &text_buf[r]; + cmp = 1; p = N + 1 + text_buf[r]; + rson[r] = NIL; lson[r] = NIL; match_length = 0; + for ( ; ; ) { + if (cmp >= 0) { + if (rson[p] != NIL) p = rson[p]; + else { rson[p] = r; dad[r] = p; return; } + } else { + if (lson[p] != NIL) p = lson[p]; + else { lson[p] = r; dad[r] = p; return; } + } + for (i = 1; i < F; i++) + if ((cmp = text_buf[r + i] - text_buf[p + i]) != 0) break; + if (i > match_length) { + match_position = p; + if ((match_length = i) >= F) break; + } + } + dad[r] = dad[p]; lson[r] = lson[p]; rson[r] = rson[p]; + dad[lson[p]] = r; dad[rson[p]] = r; + if (rson[dad[p]] == p) rson[dad[p]] = r; + else lson[dad[p]] = r; + dad[p] = NIL; + } + + private static void DeleteNode(int p) + { + int q; + + if (dad[p] == NIL) return; + if (rson[p] == NIL) q = lson[p]; + else if (lson[p] == NIL) q = rson[p]; + else { + q = lson[p]; + if (rson[q] != NIL) { + do { q = rson[q]; } while (rson[q] != NIL); + rson[dad[q]] = lson[q]; dad[lson[q]] = dad[q]; + lson[q] = lson[p]; dad[lson[p]] = q; + } + rson[q] = rson[p]; dad[rson[p]] = q; + } + dad[q] = dad[p]; + if (rson[dad[p]] == p) rson[dad[p]] = q; else lson[dad[p]] = q; + dad[p] = NIL; + } + + public int Encode(byte[] ibuf, int istart, int isize, byte[] obuf, int ostart) + { + int i, c, len, r, s, last_match_length, code_buf_ptr; + int[] code_buf = new int[17]; + int mask; + int x, x1; + + x=x1=0; + InitTree(); + code_buf[0] = 0; + code_buf_ptr = mask = 1; + s = 0; r = N - F; + for (i = s; i < r; i++) text_buf[i] = ' '; + for (len = 0, c = 0; len < F && c < isize; len++, c++) + { + if (ibuf[istart + x] >= 0) + text_buf[r + len] = ibuf[istart + x]; + else + text_buf[r + len] = 0x100 + ibuf[istart + x]; + x++; + } + if ((textsize = len) == 0) return 0; + for (i = 1; i <= F; i++) InsertNode(r - i); + InsertNode(r); + do { + if (match_length > len) match_length = len; + if (match_length <= THRESHOLD) { + match_length = 1; + code_buf[0] |= mask; + code_buf[code_buf_ptr++] = text_buf[r]; + } else { + code_buf[code_buf_ptr++] = match_position & 0xff; + code_buf[code_buf_ptr++] = ((((match_position >> 4) & 0xf0) | (match_length - (THRESHOLD + 1))) & 0xff); + } + mask <<= 1; + mask &= 0xff; + if (mask == 0) { + if (codesize + code_buf_ptr > isize) return 0; + for (i = 0; i < code_buf_ptr; i++) + { + obuf[ostart + x1] = (byte)code_buf[i]; + x1++; + } + codesize += code_buf_ptr; + code_buf[0] = 0; code_buf_ptr = mask = 1; + } + last_match_length = match_length; + for (i = 0; i < last_match_length && c < isize; i++, c++) { + DeleteNode(s); /* Delete old strings and */ + if (ibuf[istart + x] >= 0) + text_buf[s] = ibuf[istart + x]; + else + text_buf[s] = 0x100 + ibuf[istart + x]; + if (s < F - 1) + { + if (ibuf[istart + x] >= 0) + text_buf[s + N] = ibuf[istart + x]; + else + text_buf[s + N] = 0x100 + ibuf[istart + x]; + } + s = (s + 1) & (N - 1); r = (r + 1) & (N - 1); + InsertNode(r); /* Register the string in text_buf[r..r+F-1] */ + x++; + } + while (i++ < last_match_length) { + DeleteNode(s); + s = (s + 1) & (N - 1); r = (r + 1) & (N - 1); + len--; + if (len > 0) InsertNode(r); + } + } while (len > 0); + if (code_buf_ptr > 1) { + for (i = 0; i < code_buf_ptr; i++) + { + obuf[ostart + x1] = (byte)(code_buf[i]&0xff); + x1++; + } + codesize += code_buf_ptr; + } + return x1; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/utils/MyUdpSocket.java b/src/com/wms/dss/ats/customs/abb/utils/MyUdpSocket.java new file mode 100644 index 0000000..e125e3f --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/MyUdpSocket.java @@ -0,0 +1,94 @@ +package com.wms.dss.ats.customs.abb.utils; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.DatagramChannel; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.util.Set; + +public class MyUdpSocket { + private DatagramChannel channel; + private Selector selector; + private final int MAX_SIZE = 1280; + private static int client_port; + private static String client_ip; + ByteBuffer receive_buffer = ByteBuffer.allocate(MAX_SIZE); + + public MyUdpSocket(int port) { + try { + channel = DatagramChannel.open(); + selector = Selector.open(); + // µ÷Õû´ËͨµÀΪ·Ç×èÈûģʽ + channel.configureBlocking(false); + // »ñÈ¡ÓëÌ×½Ó×ÖͨµÀ¹ØÁªµÄÌ×½Ó×Ö£¬²¢½«¸ÃÌ×½Ó×ְ󶨵½±¾»úÖ¸¶¨¶Ë¿Ú + channel.socket().bind(new InetSocketAddress(port)); + // ΪͨµÀÑ¡ÔñÆ÷×¢²áͨµÀ£¬²¢Ö¸¶¨²Ù×÷µÄÑ¡Ôñ¼ü¼¯ + channel.register(selector, SelectionKey.OP_READ); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public final void send(String ip, int port, byte[] buffer, int size) throws IOException { + InetSocketAddress client = new InetSocketAddress(ip, port); + channel.send(ByteBuffer.wrap(buffer, 0, size), client); // ¸øEchoClient»Ø¸´Ò»¸öÊý¾Ý±¨ + } + + public final void close() throws IOException { + selector.close(); + channel.close(); + } + + public final int get_client_port() { + return client_port; + } + + public final String get_client_ip() { + return client_ip; + } + + public final void get_receive_buffer(byte[] buffer) { + receive_buffer.get(buffer); + } + + public final int receive() { + try { + receive_buffer.clear(); + if (selector.select(10) != 0) { + Set readyKeys = selector.selectedKeys(); + for (SelectionKey key : readyKeys) { + readyKeys.remove(key); + if (key.isReadable()) { + DatagramChannel dc = (DatagramChannel) key.channel(); + InetSocketAddress client = (InetSocketAddress) dc.receive(receive_buffer); // ½ÓÊÕÀ´×ÔÈÎÒâÒ»¸öClientµÄÊý¾Ý±¨ + if (client != null) { + client_ip = client.getAddress().getHostAddress(); + client_port = client.getPort(); + // System.out.println(client_ip+":"+client_port+" + // size="+receive_buffer.position()); + key.interestOps(SelectionKey.OP_READ); + return receive_buffer.position(); + } else { + return 0; + } + } else { + return 0; + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return 0; + } + + public final void get_receive_packet(byte[] packet, int size) { + int i; + for (i = 0; i < size; i++) { + packet[i] = receive_buffer.array()[i]; + } + } + +} diff --git a/src/com/wms/dss/ats/customs/abb/utils/ParseUtil.java b/src/com/wms/dss/ats/customs/abb/utils/ParseUtil.java new file mode 100644 index 0000000..4555902 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/ParseUtil.java @@ -0,0 +1,538 @@ +package com.wms.dss.ats.customs.abb.utils; + +import HslCommunication.BasicFramework.SoftBasic; +import org.apache.commons.codec.binary.Base64; +import org.libnodave.Nodave; + +import java.math.BigInteger; +import java.util.List; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author zn kai + * @create 2021-06-28 14:04 + */ +public class ParseUtil { + + + /** + * Õ¾µãÅÅÐò + * + * @param offset + * @param valueSize + * @return + */ + public static int[] getWriteValueSite(int offset, int valueSize) { + int[] stieArray = new int[valueSize]; + stieArray[0] = offset; + for (int i = 1; i < valueSize; i++) { + stieArray[i] = offset += 1; + } + return stieArray; + } + + /** + * Ï·¢ Êý×é´¦Àí DWORD + * + * @param values + * @return + */ + public static String[] getWriteValueDWORD(String[] values) { + String[] data = new String[values.length * 2]; + int index = 0; + for (int i = 0; i < values.length; i++) { + data[index] = String.valueOf(Integer.parseInt(values[i]) % 65536); + data[index + 1] = String.valueOf(Integer.parseInt(values[i]) / 65536); + index += 2; + } + return data; + } + + /** + * »ñȡȡµÃµ½µÄÖµ DWORD + * + * @param start + * @param end + * @param site 0 ²»ÐèҪƴ½Ó + * @return + */ + + public static Object getReadValue(byte[] start, byte[] end, int site) { + int wordStart = getWORD(start, 0); + int wordEnd = getWORD(end, 0); + int value = wordStart == 0 || (wordStart != 0 && wordEnd != 0) ? wordStart + wordEnd * 65536 : wordStart; + if (site == 0) { + return value; + } + return String.format("%06d", value); + } + + + public static String byte2Base64StringFun(byte[] b) { + return Base64.encodeBase64String(b); + } + + public static String getSTRING30(byte[] bt, int pos) { + return Nodave.SBEString30(bt, pos).toString(); + } + + public static float getFloat(byte[] bt, int pos) { + return Nodave.BEFloat(bt, pos); + } + + public static long getDWORD(byte[] bt, int pos) { + return Nodave.USBELong(bt, pos); + } + + public static long getDINT(byte[] bt, int pos) { + return Nodave.SBELong(bt, pos); + } + + public static String getSTRING(byte[] bt, int pos) { + return Nodave.SBEString(bt, pos).toString(); + } + + public static int getWORD(byte[] bt, int pos) { + return Nodave.USBEWord(bt, pos); + } + + public static int getINT(byte[] bt, int pos) { + return Nodave.SBEWord(bt, pos); + } + + public static int getBYTE(byte[] bt, int pos) { + return Nodave.SByte(bt, pos); + } + + public static int getCHAR(byte[] bt, int pos) { + return Nodave.SByte(bt, pos); + } + + public static long getUS32(byte[] bt, int pos) { + return Nodave.USBELong(bt, pos); + } + + public static long getS32(byte[] bt, int pos) { + return Nodave.SBELong(bt, pos); + } + + public static int getUS16(byte[] bt, int pos) { + return Nodave.USBEWord(bt, pos); + } + + public static int getS16(byte[] bt, int pos) { + return Nodave.SBEWord(bt, pos); + } + + public static int getUS8(byte[] bt, int pos) { + return Nodave.USByte(bt, pos); + } + + public static int getS8(byte[] bt, int pos) { + return Nodave.SByte(bt, pos); + } + + public static byte[] byteConcatArray(String[] arr) { + int length = 0; + for (String a : arr) { + byte[] x = Nodave.bswap_16(Integer.parseInt(a)); + length += x.length; + } + byte[] bt6 = new byte[length]; + + int len = 0; + for (String a : arr) { + byte[] b = Nodave.bswap_16(Integer.parseInt(a)); + System.arraycopy(b, 0, bt6, len, b.length); + if (len < bt6.length) { + len += b.length; + } + } + return bt6; + } + + /** + * ½«¶þ½øÖÆ×ª»»³É16½øÖÆ + * + * @param buf + * @return + */ + public static String parseByte2HexStr(byte buf[]) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < buf.length; i++) { + String hex = Integer.toHexString(buf[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + sb.append(hex.toUpperCase()); + } + return sb.toString(); + } + + /** + * ½«16½øÖÆ×ª»»Îª¶þ½øÖÆ + * + * @param hexStr + * @return + */ + public static byte[] parseHexStr2Byte(String hexStr) { + if (hexStr.length() < 1) + return null; + byte[] result = new byte[hexStr.length() / 2]; + for (int i = 0; i < hexStr.length() / 2; i++) { + int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16); + int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), + 16); + result[i] = (byte) (high * 16 + low); + } + return result; + } + + + /** + * ·¢ËÍ16½øÖÆ×Ö·û´® + * + * @param hexString + * @return + */ + public static byte[] hexStringToBytes(String hexString) { + if (hexString == null || hexString.equals("")) { + return null; + } + // toUpperCase½«×Ö·û´®ÖеÄËùÓÐ×Ö·ûת»»Îª´óд + hexString = hexString.toUpperCase(); + int length = hexString.length() / 2; + // toCharArray½«´Ë×Ö·û´®×ª»»ÎªÒ»¸öеÄ×Ö·ûÊý×é¡£ + char[] hexChars = hexString.toCharArray(); + byte[] d = new byte[length]; + for (int i = 0; i < length; i++) { + int pos = i * 2; + d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); + } + return d; + } + + //charToByte·µ»ØÔÚÖ¸¶¨×Ö·ûµÄµÚÒ»¸ö·¢ÉúµÄ×Ö·û´®ÖеÄË÷Òý£¬¼´·µ»ØÆ¥Åä×Ö·û + private static byte charToByte(char c) { + return (byte) "0123456789ABCDEF".indexOf(c); + } + + /** + * ½«×Ö½ÚÊý×éת»»Îª16½øÖÆ×Ö·û´® + * + * @param bytes + * @param len + * @return + */ + public static String binaryToHexString(byte[] bytes, int len) { + String hexStr = "0123456789ABCDEF"; + String result = ""; + String hex = ""; + for (int i = 0; i < len; i++) { + hex = String.valueOf(hexStr.charAt((bytes[i] & 0xF0) >> 4)); + hex += String.valueOf(hexStr.charAt(bytes[i] & 0x0F)); + result += hex; + } + /*for (byte b : bytes) { + hex = String.valueOf(hexStr.charAt((b & 0xF0) >> 4)); + hex += String.valueOf(hexStr.charAt(b & 0x0F)); + result += hex + " "; + }*/ + return result; + } + + public static String getCRC2(byte[] bytes) { +// ModBus ͨÐÅЭÒéµÄ CRC ( ÈßÓàÑ­»·Ð£ÑéÂ뺬2¸ö×Ö½Ú, ¼´ 16 λ¶þ½øÖÆÊý¡£ +// CRC ÂëÓÉ·¢ËÍÉ豸¼ÆËã, ·ÅÖÃÓÚËù·¢ËÍÐÅÏ¢Ö¡µÄβ²¿¡£ +// ½ÓÊÕÐÅÏ¢É豸ÔÙÖØÐ¼ÆËãËù½ÓÊÕÐÅÏ¢ (³ý CRC Ö®ÍâµÄ²¿·Ö£©µÄ CRC, +// ±È½Ï¼ÆËãµÃµ½µÄ CRC ÊÇ·ñÓë½ÓÊÕµ½CRCÏà·û, Èç¹ûÁ½Õß²»Ïà·û, ÔòÈÏΪÊý¾Ý³ö´í¡£ +// +// 1) Ô¤Öà 1 ¸ö 16 λµÄ¼Ä´æÆ÷ΪʮÁù½øÖÆFFFF(¼´È«Îª 1) , ³Æ´Ë¼Ä´æÆ÷Ϊ CRC¼Ä´æÆ÷¡£ +// 2) °ÑµÚÒ»¸ö 8 λ¶þ½øÖÆÊý¾Ý (ͨÐÅÐÅÏ¢Ö¡µÄµÚÒ»¸ö×Ö½Ú) Óë 16 λµÄ CRC¼Ä´æÆ÷µÄµÍ 8 λÏàÒì»ò, °Ñ½á¹û·ÅÓÚ CRC¼Ä´æÆ÷¡£ +// 3) °Ñ CRC ¼Ä´æÆ÷µÄÄÚÈÝÓÒÒÆÒ»Î»( ³¯µÍλ)Óà 0 Ìî²¹×î¸ßλ, ²¢¼ì²éÓÒÒÆºóµÄÒÆ³öλ¡£ +// 4) Èç¹ûÒÆ³öλΪ 0, ÖØ¸´µÚ 3 ²½ ( ÔÙ´ÎÓÒÒÆÒ»Î»); Èç¹ûÒÆ³öλΪ 1, CRC ¼Ä´æÆ÷Óë¶àÏîʽA001 ( 1010 0000 0000 0001) ½øÐÐÒì»ò¡£ +// 5) ÖØ¸´²½Öè 3 ºÍ²½Öè 4, Ö±µ½ÓÒÒÆ 8 ´Î,ÕâÑùÕû¸ö8λÊý¾ÝÈ«²¿½øÐÐÁË´¦Àí¡£ +// 6) ÖØ¸´²½Öè 2 µ½²½Öè 5, ½øÐÐͨÐÅÐÅÏ¢Ö¡ÏÂÒ»¸ö×ֽڵĴ¦Àí¡£ +// 7) ½«¸ÃͨÐÅÐÅÏ¢Ö¡ËùÓÐ×Ö½Ú°´ÉÏÊö²½Öè¼ÆËãÍê³Éºó,µÃµ½µÄ16λCRC¼Ä´æÆ÷µÄ¸ß¡¢µÍ×Ö½Ú½øÐн»»»¡£ +// 8) ×îºóµÃµ½µÄ CRC¼Ä´æÆ÷ÄÚÈݼ´Îª CRCÂë¡£ + + int CRC = 0x0000ffff; + int POLYNOMIAL = 0x0000a001; + + int i, j; + for (i = 0; i < bytes.length; i++) { + CRC ^= (int) bytes[i]; + for (j = 0; j < 8; j++) { + if ((CRC & 0x00000001) == 1) { + CRC >>= 1; + CRC ^= POLYNOMIAL; + } else { + CRC >>= 1; + } + } + } + //¸ßµÍλת»»£¬¿´Çé¿öʹÓã¨Æ©Èç±¾ÈËÕâ´Î¶Ôled²ÊÆÁµÄͨѶ¿ª·¢¾Í¹æ¶¨Ð£ÑéÂë¸ßλÔÚǰµÍλÔÚºó£¬Ò²¾Í²»ÐèҪת»»¸ßµÍλ) + //CRC = ( (CRC & 0x0000FF00) >> 8) | ( (CRC & 0x000000FF ) << 8); + return Integer.toHexString(CRC); + } + + public static String getCRC(String data) { + data = data.replace(" ", ""); + int len = data.length(); + if (!(len % 2 == 0)) { + return "0000"; + } + int num = len / 2; + byte[] para = new byte[num]; + for (int i = 0; i < num; i++) { + int value = Integer.valueOf(data.substring(i * 2, 2 * (i + 1)), 16); + para[i] = (byte) value; + } + return getCRC(para); + } + + /** + * ¼ÆËãCRC16УÑéÂë + * + * @param bytes ×Ö½ÚÊý×é + * @return {@link String} УÑéÂë + * @since 1.0 + */ + public static String getCRC(byte[] bytes) { + // CRC¼Ä´æÆ÷ȫΪ1 + int CRC = 0x0000ffff; + // ¶àÏîʽУÑéÖµ + int POLYNOMIAL = 0x0000a001; + int i, j; + for (i = 0; i < bytes.length; i++) { + CRC ^= ((int) bytes[i] & 0x000000ff); + for (j = 0; j < 8; j++) { + if ((CRC & 0x00000001) != 0) { + CRC >>= 1; + CRC ^= POLYNOMIAL; + } else { + CRC >>= 1; + } + } + } + // ½á¹ûת»»Îª16½øÖÆ + String result = Integer.toHexString(CRC).toUpperCase(); + if (result.length() != 4) { + StringBuffer sb = new StringBuffer("0000"); + result = sb.replace(4 - result.length(), 4, result).toString(); + } + //¸ßλÔÚǰµØÎ»ÔÚºó + //return result.substring(2, 4) + " " + result.substring(0, 2); + // ½»»»¸ßµÍ룬µÍλÔÚǰ¸ßλÔÚºó + return result.substring(2, 4) + result.substring(0, 2); + } + + + /** + * byteÊý×éת»»Îª¶þ½øÖÆ×Ö·û´®,ÿ¸ö×Ö½ÚÒÔ","¸ô¿ª + **/ + public static char[] byteArrToBinStr(byte[] b) { + StringBuffer result = new StringBuffer(); + for (int i = 0; i < b.length; i++) { + result.append(Long.toString(b[i] & 0xff, 2) + ","); + } + //Öµ + String compCode = result.toString().substring(0, result.length() - 1); + String myStr = "0000000000000000"; + String str = compCode + myStr.substring(0, myStr.length() - compCode.length()); + + return str.toCharArray(); + } + + /** + * 16½øÖÆ×ª10½øÖÆ + * + * @param content + * @return + */ + public static int hex16To10(String content) { + BigInteger integer = new BigInteger(content, 16); + return integer.intValue(); + } + + /** + * 10½øÖÆ×ª16½øÖÆ + * + * @param numb + * @return + */ + public static String encode10ToHEX16(Integer numb) { + + String hex = Integer.toHexString(numb); + return hex; + } + + /** + * 10ת16 2λ + * + * @param n + * @return + */ + public static String intToHex(int n) { + if (n == 0) { + return "00"; + } + StringBuilder sb = new StringBuilder(8); + String a; + char[] b = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + while (n != 0) { + sb = sb.append(b[n % 16]); + n = n / 16; + } + a = sb.reverse().toString(); + return a.length() < 2 ? "0" + a : a; + } + + //16½øÖÆÊýת¶þ½øÖÆ + public static void toHex(int num) { + + //& Á½Á½Îª1¼´Îª1 + //>>>ÎÞ·ûºÅÓÒÒÆ + /** + * eg.60 + * 0000-0000 0000-0000 0000-0000 0011-1100 60µÄ¶þ½øÖƱíʾ + * & 0000-0000 0000-0000 0000-0000 0000-1111 15µÄ¶þ½øÖƱíʾ + * &ºóµÄÖµ 0000-0000 0000-0000 0000-0000 0000-1100 ֵΪ12¼´16½øÖƵÄC + */ + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < 8; i++) { + int temp = num & 15; + if (temp > 9) { + sb.append((char) (temp - 10 + 'A'));//ǿת³É16½øÖÆ + + } else { + sb.append(temp); + } + num = num >>> 4; + } + System.out.println(sb.reverse());//0000003C + + } + + + /** + * 16½øÖÆ×ª2½øÖÆ ÓÃÓÚÌáÉý»ú״̬ + * + * @param num + * @return + */ + public static int[] hex16ToBinary(String num) { + String str = Integer.toBinaryString(hex16To10(num)); + char[] chars = str.toCharArray(); + + int[] in = new int[16]; + for (int i = 0; i < chars.length; i++) { + in[i] = chars[chars.length - i - 1] - '0'; + } + return in; + } + + + /** + * ¶à¸öbyte ºÏ²¢³ÉÒ»¸öbyte + * + * @param values + * @return + */ + public static byte[] byteMerge(byte[]... values) { + int length_byte = 0; + for (int i = 0; i < values.length; i++) { + length_byte += values[i].length; + } + byte[] all_byte = new byte[length_byte]; + int countLength = 0; + for (int i = 0; i < values.length; i++) { + byte[] b = values[i]; + System.arraycopy(b, 0, all_byte, countLength, b.length); + countLength += b.length; + } + return all_byte; + } + + public static String[] stringMerge(String[]... values) { + int length_byte = 0; + for (int i = 0; i < values.length; i++) { + length_byte += values[i].length; + } + String[] all_byte = new String[length_byte]; + int countLength = 0; + for (int i = 0; i < values.length; i++) { + String[] b = values[i]; + System.arraycopy(b, 0, all_byte, countLength, b.length); + countLength += b.length; + } + return all_byte; + } + + public static int[] intMerge(int[]... values) { + int length_byte = 0; + for (int i = 0; i < values.length; i++) { + length_byte += values[i].length; + } + int[] all_byte = new int[length_byte]; + int countLength = 0; + for (int i = 0; i < values.length; i++) { + int[] b = values[i]; + System.arraycopy(b, 0, all_byte, countLength, b.length); + countLength += b.length; + } + return all_byte; + } + + + /** + * int תbyte + * + * @param value + * @param len + * @return + */ + public static byte[] int2Bytes(int value, int len) { + byte[] b = new byte[len]; + for (int i = 0; i < len; i++) { + b[len - i - 1] = (byte) ((value >> 8 * i) & 0xff); + } + return b; + } + + public static String uuids() { + UUID uuid = UUID.randomUUID(); + String a = uuid.toString().replace("-", "").toUpperCase(); + return a; + } + + + public static int optInt(int start, String data) { + return Integer.parseInt(data.substring(start * 2, (start + 2) * 2), 16); + } + + public static int optDInt(int start, String data) { + return Integer.parseInt(data.substring(start * 2, (start + 4) * 2), 16); + } + + public static String optString(int start, String data) { + byte[] bytes = SoftBasic.HexStringToBytes(data.substring(start * 2, (start + 8) * 2)); + return Tools.bytetostringtool(bytes); + } + + /** + * Æ¥Åä×Ö·û´®ÊÇ·ñÊý×Ö¿ªÍ· + * @param str + * @return + */ + public static boolean isNumeric(String str) { + Pattern pattern = Pattern.compile("[0-9]*"); + Matcher isNum = pattern.matcher(str.charAt(0)+""); + if (!isNum.matches()) { + return false; + } + return true; + } +} \ No newline at end of file diff --git a/src/com/wms/dss/ats/customs/abb/utils/ProtocolDemo.java b/src/com/wms/dss/ats/customs/abb/utils/ProtocolDemo.java new file mode 100644 index 0000000..76d14b5 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/ProtocolDemo.java @@ -0,0 +1,949 @@ +package com.wms.dss.ats.customs.abb.utils; + + + +import java.awt.*; +//import java.util.Calendar; + +public class ProtocolDemo { + + // ====ÒýÈ붯×÷·½Ê½Áбí(ÊýÖµ´Ó0¿ªÊ¼)==== + // 0 = 'Ëæ»ú', + // 1 = 'Á¢¼´ÏÔʾ', + // 2 = '×ó¹öÏÔʾ', + // 3 = 'ÉϹöÏÔʾ', + // 4 = 'ÓÒ¹öÏÔʾ', + // 5 = 'ϹöÏÔʾ', + // 6 = 'Á¬Ðø×ó¹öÏÔʾ', + // 7 = 'Á¬ÐøÉϹöÏÔʾ', + // 8 = 'Á¬ÐøÓÒ¹ö', + // 9 = 'Á¬ÐøÏ¹ö', + // 10 = 'ÖмäÏòÉÏÏÂÕ¹¿ª', + // 11 = 'ÖмäÏòÁ½±ßÕ¹¿ª', + // 12 = 'ÖмäÏòËÄÖÜÕ¹¿ª', + // 13 = '´ÓÓÒÏò×óÒÆÈë', + // 14 = '´Ó×óÏòÓÒÒÆÈë', + // 15 = '´Ó×óÏòÓÒÕ¹¿ª', + // 16 = '´ÓÓÒÏò×óÕ¹¿ª', + // 17 = '´ÓÓÒÉϽÇÒÆÈë', + // 18 = '´ÓÓÒϽÇÒÆÈë', + // 19 = '´Ó×óÉϽÇÒÆÈë', + // 20 = '´Ó×óϽÇÒÆÈë', + // 21 = '´ÓÉÏÏòÏÂÒÆÈë', + // 22 = '´ÓÏÂÏòÉÏÒÆÈë', + // 23 = 'ºáÏò°ÙÒ¶´°', + // 24 = '×ÝÏò°ÙÒ¶´°', + // ===================================== + + // ====Òý³ö¶¯×÷·½Ê½Áбí(ÊýÖµ´Ó0¿ªÊ¼)==== + // 0 = 'Ëæ»ú', + // 1 = '²»Ïûʧ', + // 2 = 'Á¢¼´Ïûʧ', + // 3 = 'ÉÏÏÂÏòÖмäºÏ£', + // 4 = 'Á½±ßÏòÖмäºÏ£', + // 5 = 'ËÄÖÜÏòÖмäºÏ£', + // 6 = '´Ó×óÏòÓÒÒÆ³ö', + // 7 = '´ÓÓÒÏò×óÒÆ³ö', + // 8 = '´ÓÓÒÏò×óºÏ£', + // 9 = '´Ó×óÏòÓҺϣ', + // 10 = '´ÓÓÒÉϽÇÒÆ³ö', + // 11 = '´ÓÓÒϽÇÒÆ³ö', + // 12 = '´Ó×óÉϽÇÒÆ³ö', + // 13 = '´Ó×óϽÇÒÆ³ö', + // 14 = '´ÓÏÂÏòÉÏÒÆ³ö', + // 15 = '´ÓÉÏÏòÏÂÒÆ³ö', + // 16 = 'ºáÏò°ÙÒ¶´°', + // 17 = '×ÝÏò°ÙÒ¶´°' + // ===================================== + + // ====Í£Áô¶¯×÷·½Ê½Áбí(ÊýÖµ´Ó0¿ªÊ¼)==== + // 0 = '¾²Ì¬ÏÔʾ', + // 1 = 'ÉÁ˸ÏÔʾ' + // ===================================== + + public static MyUdpSocket my_udp; + public static LEDSender2010 ledsender = new LEDSender2010(); + //public static String ledhost = "127.0.0.1"; + public static String ledhost = "10.170.23.237"; + public static int ledport = 6666; + public static int addr = 0; + + public static void mysleep(int msec) { + try { + Thread.sleep(msec); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + //·¢ËÍUDP°ü£¬bufferΪ·¢ËÍÊý¾Ý£¬sizeΪ·¢ËÍÊý¾Ý³¤¶È + public static void udp_send(byte[] buffer, int size) { + byte[] packet = new byte[size]; + ledsender.blockCopy(packet, 0, buffer, 0, size); + ledsender.print_stream(packet, size); + try { + my_udp.send(ledhost, ledport, packet, size); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public static void udp_send1(String ip, byte[] buffer, int size) { + byte[] packet = new byte[size]; + ledsender.blockCopy(packet, 0, buffer, 0, size); + ledsender.print_stream(packet, size); + try { + my_udp.send(ip, ledport, packet, size); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + //½ÓÊÕUDP°ü£¬bufferΪ½ÓÊÕÊý¾Ý£¬sizeΪ½ÓÊÕÊý¾Ý³¤¶È + public static int udp_receive(byte[] buffer) { + int size = 0; + size = my_udp.receive(); + if (size > 0) { + my_udp.get_receive_packet(buffer, size); + } + return size; + } + + public static int do_command(byte[] buffer, int size) { + byte[] packet = new byte[1280]; + int tx, tx_repeat = 5; + int isize = 0; + int i; + + for (tx = 0; tx < tx_repeat; tx++) { + udp_send(buffer, size); + for (i = 0; i < 50; i++) { + isize = udp_receive(packet); + if (isize > 0 && ledsender.parse_cmd_respond(packet, isize) == 1) { + return 1; + } + } + } + System.out.println("³¬Ê±"); + return 0; + } + + public static void demo_reset_display() { + int size; + byte[] packet = new byte[1280]; + size = ledsender.pkg_reset_display(packet, (byte) addr, 1); + System.out.println("¸´Î»½ÚÄ¿ÏÔʾ..."); + do_command(packet, size); + } + + public static void demo_power_on() { + int size; + byte[] packet = new byte[1280]; + size = ledsender.pkg_set_power(packet, (byte) addr, 1); + System.out.println("´ò¿ªµçÔ´..."); + do_command(packet, size); + } + + public static void demo_power_off() { + int size; + byte[] packet = new byte[1280]; + size = ledsender.pkg_set_power(packet, (byte) addr, 0); + System.out.println("¹Ø±ÕµçÔ´..."); + do_command(packet, size); + } + + public static void demo_get_power() { + int size; + byte[] packet = new byte[1280]; + size = ledsender.pkg_get_power(packet, (byte) addr); + System.out.println("¶ÁÈ¡µçԴ״̬..."); + do_command(packet, size); + } + + public static void demo_set_bright() { + int size; + byte[] packet = new byte[1280]; + size = ledsender.pkg_set_bright(packet, (byte) addr, 7); + System.out.println("ÉèÖÃÁÁ¶È..."); + do_command(packet, size); + } + + public static void demo_get_bright() { + int size; + byte[] packet = new byte[1280]; + size = ledsender.pkg_get_bright(packet, (byte) addr); + System.out.println("¶ÁÈ¡ÁÁ¶È..."); + do_command(packet, size); + } + + public static void demo_adjust_time() { + int size; + byte[] packet = new byte[1280]; + //Calendar calendar = Calendar.getInstance(); + //Ö¸¶¨Ê±¼äУʱ£¬12Ð¡Ê±ÖÆ + //size=ledsender.pkg_adjust_time_ex(packet, (byte)addr, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_WEEK)-1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND)); + //Ö¸¶¨Ê±¼äУʱ£¬24Ð¡Ê±ÖÆ + //size=ledsender.pkg_adjust_time_ex(packet, (byte)addr, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_WEEK)-1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND)); + //ÒÔµ±Ç°ÏµÍ³Ê±¼äУʱ + size = ledsender.pkg_adjust_time(packet, (byte) addr); + System.out.println("УÕýʱ¼ä..."); + do_command(packet, size); + } + + public static void demo_switch_on() { + int size; + byte[] packet = new byte[1280]; + size = ledsender.pkg_set_switch(packet, (byte) addr, 1); + System.out.println("¿ªÆô5VÊä³ö..."); + do_command(packet, size); + } + + public static void demo_switch_off() { + int size; + byte[] packet = new byte[1280]; + size = ledsender.pkg_set_switch(packet, (byte) addr, 0); + System.out.println("¹Ø±Õ5VÊä³ö..."); + do_command(packet, size); + } + + public static void demo_get_boardparam() { + int size; + byte[] packet = new byte[1280]; + size = ledsender.pkg_get_boardparam(packet, (byte) addr); + System.out.println("¶ÁÈ¡¿ØÖÆ¿¨²ÎÊý..."); + do_command(packet, size); + } + + public static void demo_set_boardparam_ip(String ip) { + int size; + byte[] packet = new byte[1280]; + byte[] ips = new byte[4]; + int i, k, k1, x; + size = ledsender.pkg_get_boardparam(packet, (byte) addr); + System.out.println("¶ÁÈ¡¿ØÖÆ¿¨²ÎÊý..."); + if (do_command(packet, size) == 1) { + k = 0; + x = 0; + ip = ip + '.'; + for (i = 0; i < 4; i++) { + k1 = ip.indexOf('.', k); + if (k1 > k) { + ips[i] = (byte) Integer.parseInt(ip.substring(k, k1)); + k = k1 + 1; + x++; + } + } + if (x == 4) { + size = ledsender.pkg_set_boardparam_ip(packet, (byte) addr, ips); + if (size > 0) { + do_command(packet, size); + } + } + } + } + + public static void demo_power_schedule() { + int size; + byte[] packet = new byte[1280]; + //°´Ò»ÖÜ7ÌìÿÈÕ¶¨Ê±¿ª¹ØÆÁ£¬Ã¿ÈÕ¿ÉÒÔ¶¨Òå3¸öʱ¶Î + size = ledsender.pkg_power_schedule_weekday(packet, (byte) addr, true); + //°´Ö¸¶¨µÄÆðÖ¹ÈÕÆÚʱ¼ä²¥·Å£¬Ò»¹²¿ÉÒÔ¶¨Òå21¸öʱ¶Î + //size=ledsender.pkg_power_schedule_period(packet, (byte)addr, true); + System.out.println("ÉèÖö¨Ê±¿ª¹ØÆÁ¼Æ»®..."); + do_command(packet, size); + } + + //dib_bufferΪµãÕóͼƬµÄRGBÊý×飬Êý×éΪÕûÐÎÊý×飬Êý×éµÄÿ¸öµ¥Ôª´ú±íÒ»¸öÏñËØµãµÄRGBÖµ + // ÏñËØµã(X,Y)µÄRGBÖµ°´ÕÕÒ»ÁÐÒ»ÁÐ˳ÐòÅÅÁУ¬ÀýÈç¿í64£¬¸ß32µÄÆÁ + // (0,0),(0,1),(0,2),...(0,31) (1,0),(1,1),(1,2),...(1,31) (2,0),(2,1),(2,2),...(2,31) ... (63,0),(63,1),(63,2),...(63,31) + // ÏñËØµãµÄRGBÖµÓÃÕûÊý±íʾ£¬0-7λ±íʾºìÉ«£¬8-15λ±íʾÂÌÉ«£¬16-23±íʾÀ¶É«£¬24-31λ±£ÁôÖÃ0 + // ¼´£ºdib_buffer[n]&0xFF ±íʾºìÉ« + // (dib_buffer[n]>>8)&0xFF ±íʾÂÌÉ« + // (dib_buffer[n]>>16)&0xFF ±íʾÀ¶É« + public static int dib_width = 64; + public static int dib_height = 64; + public static int dib_buffer_size = dib_width * dib_height; + public static int[] dib_buffer = new int[dib_buffer_size]; + + public static void draw_dib() { + int x, y, z = 0; + int seek = 0; + int color = 0xFF; + for (x = 0; x < dib_width; x++) { + for (y = 0; y < dib_height; y++) { + dib_buffer[seek++] = color; + } + z++; + if (z >= 4) { + switch (color) { + case 0xFF: + color = 0xFF00; + break; + case 0xFF00: + color = 0xFFFF; + break; + case 0xFFFF: + color = 0xFF; + break; + default: + color = 0xFF; + break; + } + z = 0; + } + } + } + + public static void send_data() { + int size = 0; + byte[] packet = new byte[1280]; + int i, j, k, x, r; + int tx, tx_repeat = 5; + boolean ok; + //ÏÂÃæÎªÍ¨Ñ¶´úÂ룬°üÀ¨Êý¾ÝµÄ²ð·Ö´ò°ü¡¢·¢ËÍ + // ÓÉÓÚÊÇUDPͨѶ£¬Ôö¼Ó + + //Èç¹ûÊý¾ÝÁ¿´óÓÚ + if (ledsender.GetDataSize() > (1 << 21)) { + System.out.println("LED½ÚÄ¿Êý¾Ý³¤¶È³¬³öÏÔʾÆÁ´æ´¢¿Õ¼ä"); + return; + } + + System.out.println("LED½ÚĿѹËõǰÊý¾Ý³¤¶È" + ledsender.GetDataSize() + "£¬Êý¾Ý°üÊýÁ¿" + ledsender.get_pkg_count(512)); + ledsender.Compress(); + System.out.println("LED½ÚĿѹËõºóÊý¾Ý³¤¶È" + ledsender.GetDataSize() + "£¬Êý¾Ý°üÊýÁ¿" + ledsender.get_pkg_count(512)); + + //Æðʼ°ü + ok = false; + //System.out.println("·¢ËÍÆðʼ°ü...£¬ÐòÁкÅ=0"); + for (tx = 0; tx < tx_repeat; tx++) { + size = ledsender.pkg_begin(packet, addr); + udp_send(packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0 && ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_BEGIN, 0) > 0) { + //System.out.println("Æðʼ°ü·¢ËÍÍê³É£¬ÐòÁкÅ=0"); + ok = true; + break; + } + } + if (ok) break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + + //Êý¾Ý°ü + k = ledsender.get_pkg_count(512); + i = 1; + while (i <= k) { + ok = false; + //System.out.println("·¢ËÍÊý¾Ý°ü...£¬ÐòÁкÅ="+i); + for (tx = 0; tx < tx_repeat; tx++) { + j = i; + size = ledsender.pkg_data(packet, addr, i, 512); + udp_send(packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0) { + r = ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_DATA, i); + switch (r) { + case 0x1: + //System.out.println("Êý¾Ý°ü·¢ËÍÍê³É£¬ÐòÁкÅ="+i); + ok = true; + j = i + 1; + break; + case 0x2: + //System.out.println("Êý¾Ý°üÐòÁкÅУ¶Ô´íÎó£¬Ó¦ÊÕ="+i+"£¬ÊµÊÕ="+ledsender.fix_serialno); + j = ledsender.fix_serialno; + break; + } + //ok=true; + //break; + } + if (ok) break; + } + i = j; + if (ok) break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + } + + //½áÊø°ü + ok = false; + //System.out.println("·¢ËͽáÊø°ü...£¬ÐòÁкÅ="+i); + for (tx = 0; tx < tx_repeat; tx++) { + size = ledsender.pkg_end(packet, addr, i); + udp_send(packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0 && ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_END, i) > 0) { + //System.out.println("½áÊø°ü·¢ËÍÍê³É£¬ÐòÁкÅ="+i); + ok = true; + break; + } + } + if (ok) break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + + /* + ok=false; + for (x=0; x<100; x++){ + size=udp_receive(packet); + switch (ledsender.parse_notify(packet, size)){ + case LEDSender2010.NOTIFY_ROOT_PLAY: + System.out.println("·¢ËͽÚÄ¿Êý¾ÝУÑé³É¹¦"); + ok=true; + break; + case LEDSender2010.NOTIFY_ROOT_DOWNLOAD: + System.out.println("ÏÂÔØ½ÚÄ¿Êý¾ÝУÑé³É¹¦"); + ok=true; + break; + } + if (ok) break; + } + if (!ok) System.out.println("½ÚÄ¿Êý¾ÝУÑé´íÎ󣬷¢ËÍ/ÏÂÔØÊ§°Ü"); + */ + } + + public static void send_data1(String ip) { + int size = 0; + byte[] packet = new byte[1280]; + int i, j, k, x, r; + int tx, tx_repeat = 5; + boolean ok; + //ÏÂÃæÎªÍ¨Ñ¶´úÂ룬°üÀ¨Êý¾ÝµÄ²ð·Ö´ò°ü¡¢·¢ËÍ + // ÓÉÓÚÊÇUDPͨѶ£¬Ôö¼Ó + + //Èç¹ûÊý¾ÝÁ¿´óÓÚ + if (ledsender.GetDataSize() > (1 << 21)) { + System.out.println("LED½ÚÄ¿Êý¾Ý³¤¶È³¬³öÏÔʾÆÁ´æ´¢¿Õ¼ä"); + return; + } + + //System.out.println("LED½ÚĿѹËõǰÊý¾Ý³¤¶È"+ledsender.GetDataSize()+"£¬Êý¾Ý°üÊýÁ¿"+ledsender.get_pkg_count(512)); + ledsender.Compress(); + //System.out.println("LED½ÚĿѹËõºóÊý¾Ý³¤¶È"+ledsender.GetDataSize()+"£¬Êý¾Ý°üÊýÁ¿"+ledsender.get_pkg_count(512)); + + //Æðʼ°ü + ok = false; + //System.out.println("·¢ËÍÆðʼ°ü...£¬ÐòÁкÅ=0"); + for (tx = 0; tx < tx_repeat; tx++) { + size = ledsender.pkg_begin(packet, addr); + udp_send1(ip, packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0 && ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_BEGIN, 0) > 0) { + //System.out.println("Æðʼ°ü·¢ËÍÍê³É£¬ÐòÁкÅ=0"); + ok = true; + break; + } + } + if (ok) break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + + //Êý¾Ý°ü + k = ledsender.get_pkg_count(512); + i = 1; + while (i <= k) { + ok = false; + //System.out.println("·¢ËÍÊý¾Ý°ü...£¬ÐòÁкÅ="+i); + for (tx = 0; tx < tx_repeat; tx++) { + j = i; + size = ledsender.pkg_data(packet, addr, i, 512); + udp_send1(ip, packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0) { + r = ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_DATA, i); + switch (r) { + case 0x1: + //System.out.println("Êý¾Ý°ü·¢ËÍÍê³É£¬ÐòÁкÅ="+i); + ok = true; + j = i + 1; + break; + case 0x2: + //System.out.println("Êý¾Ý°üÐòÁкÅУ¶Ô´íÎó£¬Ó¦ÊÕ="+i+"£¬ÊµÊÕ="+ledsender.fix_serialno); + j = ledsender.fix_serialno; + break; + } + //ok=true; + //break; + } + if (ok) break; + } + i = j; + if (ok) break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + } + + //½áÊø°ü + ok = false; + //System.out.println("·¢ËͽáÊø°ü...£¬ÐòÁкÅ="+i); + for (tx = 0; tx < tx_repeat; tx++) { + size = ledsender.pkg_end(packet, addr, i); + udp_send1(ip, packet, size); + for (x = 0; x < 50; x++) { + size = udp_receive(packet); + if (size > 0 && ledsender.parse_trans_respond(packet, size, LEDSender2010.PKC_END, i) > 0) { + //System.out.println("½áÊø°ü·¢ËÍÍê³É£¬ÐòÁкÅ="+i); + ok = true; + break; + } + } + if (ok) break; + } + if (!ok) { + System.out.println("³¬Ê±"); + return; + } + + } + + public static void demo_upgrade() { + ledsender.Upgrade("d:\\vsd.bin"); + send_data(); + } + + public static void demo_play() { + //String[] formats={"#y", "Äê", "#m", "ÔÂ", "#d", "ÈÕ", " ", "#h", ":", "#n", ":", "#s"}; + //String[] formats={"#h", ":", "#n", ":", "#s"}; + + //Éú³É½ÚÄ¿Êý¾Ý + ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_DOUBLE); + //ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_THREE); + //ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_FULL); + ledsender.AddChapter(1, 1000); + ledsender.AddRegion(0, 0, 256, 64); + + /* + //µãÕóͼƬ + ledsender.AddLeaf(1, 2000); + //draw_dib(); + //ledsender.AddDib(0, 0, 64, 64, dib_buffer, dib_buffer_size, dib_width, dib_height, 1, 5, 2, 5, 0, 0, 1000); + BufferedImage bi; + try { + bi = LEDSender2010.createImageEx("ÖлªÈËÃñ¹²ºÍ¹ú", new Font("ËÎÌå", Font.BOLD, 24), Color.BLACK, Color.CYAN, 0, false, 64); + System.out.println("width:"+bi.getWidth()+"height:"+bi.getHeight()); + ledsender.AddWindow(0, 0, 64, 64, LEDSender2010.getBufferedImageRGB(bi), bi.getWidth() * bi.getHeight(), bi.getWidth(), bi.getHeight(), 2, 0, 2, 0, 0, 0, 0); + } catch (Exception e) { + e.printStackTrace(); + } + */ + + //µãÕóÎÄ×Ö£¨µ¥ÐУ¬Ö§³Ö¶ÔÆë·½Ê½£© + ledsender.AddLeaf(1, 2000); + //ledsender.AddTextJuhao(0, 0, 64, 32, "»¶Ó­¹âÁÙ¡£Ð»Ð»»Ý¹Ë¡£", "ËÎÌå", 24, Color.BLACK, Color.RED, 0, 2, true, 2, 0, 2, 0, 0, 0, 0); + ledsender.AddTextEx(0, 0, 128, 32, "»¶Ó­¹âÁÙ", LEDSender2010.ALIGN_LEFT, LEDSender2010.ALIGN_TOP, "ËÎÌå", 16, Color.BLACK, new Color(255, 0, 0), 0, 1, 0, 2, 0, 0, 0, 0); + //ledsender.AddTextEx(128, 0, 160, 32, "лл»Ý¹Ë", LEDSender2010.ALIGN_LEFT, LEDSender2010.ALIGN_TOP, "ËÎÌå", 16, Color.BLACK, Color.RED, 0, 1, 0, 2, 0, 0, 0, 0); + + //ledsender.AddLeaf(1, 2000); + //ledsender.AddTextEx(0, 0, 128, 32, "ͬһ¸öÖйú", LEDSender2010.ALIGN_LEFT, LEDSender2010.ALIGN_TOP, "ËÎÌå", 16, Color.BLACK, Color.RED, 0, 1, 0, 2, 0, 0, 0, 0); + //ledsender.AddTextEx(128, 0, 160, 32, "ͬһ¸öÃÎÏë", LEDSender2010.ALIGN_LEFT, LEDSender2010.ALIGN_TOP, "ËÎÌå", 16, Color.BLACK, Color.RED, 0, 1, 0, 2, 0, 0, 0, 0); + + /* + //24µãÕóÄÚÂëÎÄ×Ö + ledsender.AddLeaf(1, 2000); + ledsender.AddString(0, 0, 64, 32, "»¶Ó­¹âÁÙabc", 2, 0, 2, 0, 0, 0, 0, 0xFF, 1); + //24µãÕóÈÕÆÚʱ¼ä£¬¸ñʽyyyyÄêmmÔÂddÈÕ + ledsender.AddLeaf(1, 2000); + ledsender.AddStringDateTime(0, 0, 256, 32, 0xFFFF, 1, formats, 6); + */ + + send_data(); + } + + public static void demo_play2() { + + //Éú³É½ÚÄ¿Êý¾Ý + ledsender.MakeRoot(LEDSender2010.ROOT_DOWNLOAD, LEDSender2010.COLOR_TYPE_DOUBLE); + //ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_THREE); + ledsender.AddChapter(1, 1000000); + ledsender.AddRegion(0, 0, 256, 64); + + //µãÕóÎÄ×Ö£¨µ¥ÐУ¬Ö§³Ö¶ÔÆë·½Ê½£© + ledsender.AddLeaf(1, 200000); + ledsender.AddWindows(0, 0, 64, 32); + ledsender.AddChildText("»¶Ó­¹âÁÙ", "ËÎÌå", 16, Color.BLACK, Color.RED, 0, 0, false, 6, 0, 2, 0, 0, 0, 0); + ledsender.AddChildText("лл»Ý¹Ë", "ËÎÌå", 16, Color.BLACK, Color.RED, 0, 0, false, 6, 0, 2, 0, 0, 0, 0); + + send_data(); + } + + public static void demo_play_chapterschedule() { + //String[] formats={"#y", "Äê", "#m", "ÔÂ", "#d", "ÈÕ", " ", "#h", ":", "#n", ":", "#s"}; + //String[] formats={"#h", ":", "#n", ":", "#s"}; + + //Éú³É½ÚÄ¿Êý¾Ý + ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_DOUBLE); + + ledsender.AddChapterEx(1, 1000, 1, 1, 0x7F, 2016, 8, 17, 0, 0, 0, 2016, 12, 27, 23, 59, 59); + ledsender.AddRegion(0, 0, 64, 64); + + //µãÕóÎÄ×Ö£¨×Ô¶¯»»ÐУ© + ledsender.AddLeaf(1, 2000); + ledsender.AddText(0, 0, 64, 32, "»¶Ó­¹âÁÙabc", "ËÎÌå", 14, Color.BLACK, Color.RED, 0, 2, true, 3, 0, 2, 0, 0, 0, 0); + + ledsender.AddChapterEx(1, 1000, 1, 1, 0x7F, 2016, 4, 28, 10, 10, 0, 2016, 12, 27, 23, 15, 0); + ledsender.AddRegion(0, 0, 64, 64); + + //µãÕóÎÄ×Ö£¨µ¥ÐУ¬Ö§³Ö¶ÔÆë·½Ê½£© + ledsender.AddLeaf(1, 2000); + ledsender.AddTextEx(0, 0, 64, 32, "лл»Ý¹Ëabc", LEDSender2010.ALIGN_CENTER, LEDSender2010.ALIGN_TOP, "ËÎÌå", 14, Color.BLACK, Color.RED, 0, 1, 0, 2, 0, 0, 0, 0); + + send_data(); + } + + public static void demo_play_picture() { + //Éú³É½ÚÄ¿Êý¾Ý + ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_DOUBLE); + ledsender.AddChapter(1, 1000); + ledsender.AddRegion(0, 0, 64, 64); + ledsender.AddLeaf(1, 2000); + ledsender.AddPicture(0, 0, 64, 64, "c:\\demo.bmp", 1, 0, 2, 0, 0, 0, 0); + send_data(); + } + + public static void demo_play_voice() { + //Éú³É½ÚÄ¿Êý¾Ý + ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_DOUBLE); + ledsender.AddChapter(1, 1000); + ledsender.AddRegion(0, 0, 64, 64); + ledsender.AddLeaf(1, 2000); + ledsender.AddTextEx(0, 0, 64, 32, "»¶Ó­¹âÁÙ", LEDSender2010.ALIGN_CENTER, LEDSender2010.ALIGN_TOP, "ËÎÌå", 16, Color.BLACK, Color.RED, 0, 1, 0, 2, 0, 0, 0, 0); + ledsender.AddVoice("»¶Ó­¹âÁÙ", 5000, 10, 0, 5, 5, 1); + send_data(); + } + + public static void demo_datetime_play() { + String[] formats_datetime = {"#y", "Äê", "#m", "ÔÂ", "#d", "ÈÕ", " ", "#h", ":", "#n", ":", "#s"}; + String[] formats_date = {"#y", "Äê", "#m", "ÔÂ", "#d", "ÈÕ"}; + String[] formats_time = {"#h", ":", "#n", ":", "#s"}; + String[] formats_week = {"ÐÇÆÚ", "#w"}; + + //Éú³É½ÚÄ¿Êý¾Ý + ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_DOUBLE); + //ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_THREE); + ledsender.AddChapter(1, 10000); + ledsender.AddRegion(0, 0, 64, 64); + + ledsender.AddLeaf(1, 2000); + ledsender.AddDateTime(0, 0, 64, 32, formats_datetime, 12, "ËÎÌå", 14, Color.BLACK, Color.YELLOW, 0); + ledsender.AddLeaf(1, 2000); + ledsender.AddDateTime(0, 0, 64, 32, formats_date, 6, "ËÎÌå", 14, Color.BLACK, Color.RED, 0); + ledsender.AddLeaf(1, 2000); + ledsender.AddDateTime(0, 0, 64, 32, formats_time, 5, "ËÎÌå", 14, Color.BLACK, Color.GREEN, 0); + ledsender.AddLeaf(1, 2000); + ledsender.AddDateTime(0, 0, 64, 32, formats_week, 2, "ËÎÌå", 14, Color.BLACK, Color.RED, 0); + + send_data(); + } + + public static void demo_schedule_child_play() { + //Éú³É½ÚÄ¿Êý¾Ý + //String[] formats_datetime={"#y", "Äê", "#m", "ÔÂ", "#d", "ÈÕ", " ", "#h", ":", "#n", ":", "#s"}; + + ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_DOUBLE); + ledsender.AddChapter(1, 10000); + ledsender.AddRegion(0, 0, 64, 64); + + ledsender.AddLeaf(1, 2000); + ledsender.AddWindows(0, 0, 64, 32); + //ledsender.AddChildText("abc", "ËÎÌå", 14, Color.BLACK, Color.RED, 0, false, 1, 0, 2, 0, 0, 0, 0); + ledsender.AddChildScheduleText("»¶Ó­¹âÁÙ", "ËÎÌå", 14, Color.BLACK, Color.RED, 0, 0, false, 1, 0, 2, 0, 0, 0, 2000, 2, 0x0, 2018, 2, 5, 7, 10, 0, 2018, 2, 6, 23, 15, 0); + ledsender.AddChildScheduleText("лл»Ý¹Ë", "ËÎÌå", 14, Color.BLACK, Color.RED, 0, 0, false, 1, 0, 2, 0, 0, 0, 2000, 2, 0x0, 2018, 2, 5, 7, 10, 0, 2018, 2, 6, 23, 15, 0); + ledsender.AddChildScheduleText("ͬһ¸öÊÀ½ç", "ËÎÌå", 14, Color.BLACK, Color.RED, 0, 0, false, 1, 0, 2, 0, 0, 0, 2000, 2, 0x0, 2018, 2, 8, 7, 10, 0, 2018, 2, 9, 23, 15, 0); + ledsender.AddChildScheduleText("ͬһ¸öÃÎÏë", "ËÎÌå", 14, Color.BLACK, Color.RED, 0, 0, false, 1, 0, 2, 0, 0, 0, 2000, 2, 0x0, 2018, 2, 8, 7, 10, 0, 2018, 2, 9, 23, 15, 0); + + send_data(); + } + + public static void demo_fontset_import(MyUdpSocket udp, String ip, int num, String text) { + byte[] packet = new byte[1024]; + byte[] s; + int i, size; + int c; + + size = 0; + try { + s = text.getBytes("GB2312"); + size = 0; + packet[size++] = 0x55; + packet[size++] = 0x25; + packet[size++] = 0x3E; + packet[size++] = (byte) (((num / 100) % 10) + 0x30); + packet[size++] = (byte) (((num / 10) % 10) + 0x30); + packet[size++] = (byte) ((num % 10) + 0x30); + for (i = 0; i < s.length; i++) { + if (s[i] >= 0) c = s[i]; + else c = (256 + s[i]); + switch (c >> 4) { + case 0: + packet[size++] = 0x30; + break; + case 1: + packet[size++] = 0x31; + break; + case 2: + packet[size++] = 0x32; + break; + case 3: + packet[size++] = 0x33; + break; + case 4: + packet[size++] = 0x34; + break; + case 5: + packet[size++] = 0x35; + break; + case 6: + packet[size++] = 0x36; + break; + case 7: + packet[size++] = 0x37; + break; + case 8: + packet[size++] = 0x38; + break; + case 9: + packet[size++] = 0x39; + break; + case 10: + packet[size++] = 0x61; + break; + case 11: + packet[size++] = 0x62; + break; + case 12: + packet[size++] = 0x63; + break; + case 13: + packet[size++] = 0x64; + break; + case 14: + packet[size++] = 0x65; + break; + case 15: + packet[size++] = 0x66; + break; + default: + packet[size++] = 0x30; + break; + } + switch (c & 0xF) { + case 0: + packet[size++] = 0x30; + break; + case 1: + packet[size++] = 0x31; + break; + case 2: + packet[size++] = 0x32; + break; + case 3: + packet[size++] = 0x33; + break; + case 4: + packet[size++] = 0x34; + break; + case 5: + packet[size++] = 0x35; + break; + case 6: + packet[size++] = 0x36; + break; + case 7: + packet[size++] = 0x37; + break; + case 8: + packet[size++] = 0x38; + break; + case 9: + packet[size++] = 0x39; + break; + case 10: + packet[size++] = 0x61; + break; + case 11: + packet[size++] = 0x62; + break; + case 12: + packet[size++] = 0x63; + break; + case 13: + packet[size++] = 0x64; + break; + case 14: + packet[size++] = 0x65; + break; + case 15: + packet[size++] = 0x66; + break; + default: + packet[size++] = 0x30; + break; + } + } + packet[size++] = 0x23; + packet[size++] = (byte) 0xAA; + } catch (Exception e) { + } + + if (size > 0) { + try { + udp = new MyUdpSocket(8868); + udp.send(ip, 6666, packet, size); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + //Ö»¸üÐÂÒ»¸ö½ÚÄ¿ + public static void demo_play_sub_chapter() { + ledsender.MakeChapter(LEDSender2010.ROOT_PLAY_CHAPTER, LEDSender2010.COLOR_TYPE_DOUBLE, 1, 0, 1, 1000); + ledsender.AddRegion(0, 0, 64, 64); + ledsender.AddLeaf(1, 2000); + ledsender.AddTextEx(0, 0, 64, 32, "abc", LEDSender2010.ALIGN_CENTER, LEDSender2010.ALIGN_TOP, "ËÎÌå", 14, Color.BLACK, Color.RED, 0, 1, 0, 2, 0, 0, 0, 0); + send_data(); + } + + public static void demo_play_sub_chapter_ex() { + ledsender.MakeChapterEx(LEDSender2010.ROOT_PLAY_CHAPTER, LEDSender2010.COLOR_TYPE_DOUBLE, 1, 0, 1, 1000, 1, 1, 0x7F, 2016, 8, 17, 0, 0, 0, 2016, 12, 27, 23, 59, 59); + ledsender.AddRegion(0, 0, 64, 64); + ledsender.AddLeaf(1, 2000); + ledsender.AddTextEx(0, 0, 64, 32, "abc", LEDSender2010.ALIGN_CENTER, LEDSender2010.ALIGN_TOP, "ËÎÌå", 14, Color.BLACK, Color.RED, 0, 1, 0, 2, 0, 0, 0, 0); + send_data(); + } + + //Ö»¸üÐÂÒ»¸ö·ÖÇø + public static void demo_play_sub_region() { + ledsender.MakeRegion(LEDSender2010.ROOT_PLAY_REGION, LEDSender2010.COLOR_TYPE_DOUBLE, 1, 0, 1, 0, 16, 128, 16); + ledsender.AddLeaf(1, 2000); + ledsender.AddTextEx(0, 0, 64, 32, "abc", LEDSender2010.ALIGN_CENTER, LEDSender2010.ALIGN_TOP, "ËÎÌå", 14, Color.BLACK, Color.RED, 0, 1, 0, 2, 0, 0, 0, 0); + send_data(); + } + + //Ö»¸üÐÂÒ»¸öÒ³Ãæ + public static void demo_play_sub_leaf() { + String[] formats_datetime = {"#h", ":", "#n", ":", "#s"}; + ledsender.MakeLeaf(LEDSender2010.ROOT_PLAY_LEAF, LEDSender2010.COLOR_TYPE_DOUBLE, 1, 0, 0, 1, 1, 1000); + ledsender.AddTextEx(0, 0, 64, 16, "abc", LEDSender2010.ALIGN_CENTER, LEDSender2010.ALIGN_TOP, "ËÎÌå", 14, Color.BLACK, Color.RED, 0, 1, 0, 2, 0, 0, 0, 0); + ledsender.AddDateTime(0, 16, 64, 16, formats_datetime, 12, "ËÎÌå", 14, Color.BLACK, Color.YELLOW, 0); + send_data(); + } + + //Ö»¸üÐÂÒ»¸ö¶ÔÏó + public static void demo_play_sub_object() { + ledsender.MakeObject(LEDSender2010.ROOT_PLAY_OBJECT, LEDSender2010.COLOR_TYPE_DOUBLE, 1, 0, 0, 0, 1); + //´Ë´¦Ö»ÄÜÌí¼ÓÒ»¸ö¶ÔÏó + ledsender.AddTextEx(0, 0, 64, 32, "abc", LEDSender2010.ALIGN_CENTER, LEDSender2010.ALIGN_TOP, "ËÎÌå", 12, Color.BLACK, Color.RED, 0, 1, 0, 2, 0, 0, 0, 0); + send_data(); + } + + //×Ô¶¨Òå·½·¨ ¾²Ì¬ÏÔʾµ¥ÐÐÐÅÏ¢ + public static void demo_play_chapterschedule1(String ip, String msg) { + + //Éú³É½ÚÄ¿Êý¾Ý + ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_DOUBLE); + + ledsender.AddChapterEx(1, 1000, 1, 1, 0x7F, 2016, 8, 17, 0, 0, 0, 2016, 12, 27, 23, 59, 59); + ledsender.AddRegion(0, 0, 192, 64); + + //µãÕóÎÄ×Ö£¨×Ô¶¯»»ÐУ© + ledsender.AddLeaf(1, 2000); + ledsender.AddText(8, 24, 192, 64, msg, "ºÚÌå", 16, Color.BLACK, Color.YELLOW, 0, 2, false, 1, 0, 2, 0, 0, 5, 10000); + + send_data1(ip); + } + + //×Ô¶¨Òå·½·¨ ¶¯Ì¬ÏÔʾÁ½ÐÐÐÅÏ¢ + public static void demo_play_chapterschedule2(String ip, String msg1, String msg2) { + + //Éú³É½ÚÄ¿Êý¾Ý + ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_DOUBLE); + + ledsender.AddChapterEx(1, 1000, 1, 1, 0x7F, 2016, 8, 17, 0, 0, 0, 2016, 12, 27, 23, 59, 59); + ledsender.AddRegion(0, 0, 192, 64); + + //µãÕóÎÄ×Ö£¨×Ô¶¯»»ÐУ© + ledsender.AddLeaf(1, 2000); + ledsender.AddText(0, 11, 192, 32, msg1, "ºÚÌå", 16, Color.BLACK, Color.YELLOW, 0, 2, false, 1, 0, 2, 0, 0, 5, 10000); + ledsender.AddText(0, 37, 192, 32, msg2, "ºÚÌå", 16, Color.BLACK, Color.YELLOW, 0, 2, false, 1, 0, 2, 0, 0, 5, 10000); + + send_data1(ip); + } + + //×Ô¶¨Òå·½·¨ÏÔʾÈýÐÐÎÄ×Ö + public static void demo_play_chapterschedule3(String ip, String msg1, String msg2, String msg3, String msg4, String msg5, String msg) { + + //Éú³É½ÚÄ¿Êý¾Ý + ledsender.MakeRoot(LEDSender2010.ROOT_PLAY, LEDSender2010.COLOR_TYPE_DOUBLE); + + ledsender.AddChapterEx(1, 1000, 1, 1, 0x7F, 2016, 8, 17, 0, 0, 0, 2016, 12, 27, 23, 59, 59); + ledsender.AddRegion(0, 0, 192, 64); + + //µãÕóÎÄ×Ö£¨×Ô¶¯»»ÐУ© + ledsender.AddLeaf(1, 2000); + ledsender.AddText(10, 0, 192, 21, msg, "ºÚÌå", 13, Color.BLACK, Color.YELLOW, 0, 2, false, 1, 0, 2, 0, 0, 5, 10000); + ledsender.AddText(0, 12, 192, 21, msg1, "ºÚÌå", 13, Color.BLACK, Color.YELLOW, 0, 2, false, 1, 0, 2, 0, 0, 5, 10000); + ledsender.AddText(0, 24, 192, 21, msg2, "ºÚÌå", 13, Color.BLACK, Color.YELLOW, 0, 2, false, 1, 0, 2, 0, 0, 5, 10000); + ledsender.AddText(0, 36, 192, 22, msg3, "ºÚÌå", 13, Color.BLACK, Color.YELLOW, 0, 2, false, 1, 0, 2, 0, 0, 5, 10000); + ledsender.AddText(0, 48, 192, 22, msg4, "ºÚÌå", 13, Color.BLACK, Color.YELLOW, 0, 2, false, 1, 0, 2, 0, 0, 5, 10000); +// ledsender.AddText(0, 50, 192, 22, msg5, "ºÚÌå", 13, Color.BLACK, Color.YELLOW, 0, 2, false, 1, 0, 2, 0, 0, 5, 10000); + + send_data1(ip); + } + + + public static void main(String[] args) { + + // TODO Auto-generated method stub + + try { + my_udp = new MyUdpSocket(8818); + } catch (Exception ex) { + ex.printStackTrace(); + } + + //demo_play(); + //demo_play_voice(); + //demo_fontset_import(my_udp, "192.168.1.99", 0, "ÄãºÃÅóÓÑ123"); + //demo_reset_display(); + //demo_play_chapterschedule(); + //demo_upgrade(); + //demo_datetime_play(); + //demo_play_picture(); + //demo_schedule_child_play(); + demo_get_boardparam(); + //demo_set_boardparam_ip("192.168.1.99"); + //demo_power_off(); + //demo_power_on(); + //demo_get_power(); + //demo_set_bright(); + //demo_get_bright(); + //demo_adjust_time(); + //demo_switch_on(); + //demo_switch_off(); + //demo_power_schedule(); + + System.out.println("ÔËÐнáÊø."); + } + +} diff --git a/src/com/wms/dss/ats/customs/abb/utils/QueryDbDataUtils.java b/src/com/wms/dss/ats/customs/abb/utils/QueryDbDataUtils.java new file mode 100644 index 0000000..88fd0d2 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/QueryDbDataUtils.java @@ -0,0 +1,527 @@ +package com.wms.dss.ats.customs.abb.utils; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.entity.*; +import com.wms.dss.common.server.form.Logger; + +import java.util.ArrayList; +import java.util.List; + +/* + *@Version 1.0 + * Êý¾Ý»ñÈ¡ + **/ +public class QueryDbDataUtils { + public static List findOpenLed(EntityDAO dao) { + List openLed = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from OpenLed "); + openLed = dao.searchEntities(strBud.toString()); + + } catch (Exception e) { + Logger.info("²éѯµãÕóÆÁÒì³££¡£¡£¡£¡"); + } + return openLed; + } + public static List findOpenLed1(EntityDAO dao,int id) { + List openLed = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from OpenLed where id = 4"); + openLed = dao.searchEntities(strBud.toString()); + + } catch (Exception e) { + Logger.info("²éѯµãÕóÆÁÒì³££¡£¡£¡£¡"); + } + return openLed; + } + public static WmsDeviceExecutionQueue ddj_zxdl(EntityDAO dao, long rwh, int mlfs) throws Exception { + WmsDeviceExecutionQueue stask_ddj_zxdl = null; + try { + StringBuilder strBud = new StringBuilder();//////ÇмÇÉú³ÉÈë¿â×÷ҵʱĬÈÏÏïµÀºÅΪ0 + strBud.append("from WmsDeviceExecutionQueue where devName='¶Ñ¶â»ú' and ddjxf='1' and rwh=").append(rwh).append(" and mlfs =").append(mlfs); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + stask_ddj_zxdl = (WmsDeviceExecutionQueue) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐddj_zxdl»ñÈ¡¶ÓÁÐÐÅÏ¢´íÎó£º" + e.getMessage()); + } + return stask_ddj_zxdl; + } + + public static BasDevice basDevice(EntityDAO dao, int id) throws Exception { + BasDevice basDevice = null; + try { + StringBuilder strBud = new StringBuilder();//////ÇмÇÉú³ÉÈë¿â×÷ҵʱĬÈÏÏïµÀºÅΪ0 + strBud.append("from BasDevice where device_id =").append(id); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + basDevice = (BasDevice) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐddj_zxdl»ñÈ¡¶ÓÁÐÐÅÏ¢´íÎó£º" + e.getMessage()); + } + return basDevice; + } + + public static WmsDeviceExecutionQueue getQueueByRoadAndRwlx(EntityDAO dao, int ddjh, int rwlx) throws Exception { + WmsDeviceExecutionQueue stask_ddj_zxdl = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from WmsDeviceExecutionQueue where devName='¶Ñ¶â»ú' and ddjxf != 0 and devId=").append(ddjh).append(" and rwlx =").append(rwlx); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + stask_ddj_zxdl = (WmsDeviceExecutionQueue) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetQueueByRoadAndRwlx»ñÈ¡¶ÓÁÐÐÅÏ¢´íÎó£º" + e.getMessage()); + } + return stask_ddj_zxdl; + } + public static WmsDeviceExecutionQueue getQueueByRoadAndRwlx1(EntityDAO dao, int ddjh, int rwlx) throws Exception { + WmsDeviceExecutionQueue stask_ddj_zxdl = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from WmsDeviceExecutionQueue where devName='¶Ñ¶â»ú' and ddjxf = 0 and devId=").append(ddjh).append(" and rwlx =").append(rwlx); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + stask_ddj_zxdl = (WmsDeviceExecutionQueue) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetQueueByRoadAndRwlx»ñÈ¡¶ÓÁÐÐÅÏ¢´íÎó£º" + e.getMessage()); + } + return stask_ddj_zxdl; + } + public static WmsDeviceExecutionQueue getQueueByRoadAndXf(EntityDAO dao, int ddjh, int ddjxf) throws Exception { + WmsDeviceExecutionQueue stask_ddj_zxdl = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from WmsDeviceExecutionQueue where devName='¶Ñ¶â»ú' and devId=").append(ddjh).append(" and ddjxf =").append(ddjxf); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + stask_ddj_zxdl = (WmsDeviceExecutionQueue) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetQueueByRoadAndXf»ñÈ¡¶ÓÁÐÐÅÏ¢´íÎó£º" + e.getMessage()); + } + return stask_ddj_zxdl; + } + + public static WmsDeviceExecutionQueue getQueueByTask(EntityDAO dao, int ddjh, long zxrwh) throws Exception { + WmsDeviceExecutionQueue stask_ddj_zxdl = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from WmsDeviceExecutionQueue where ddjxf=0 and devId=").append(ddjh).append(" and rwh =").append(zxrwh); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + stask_ddj_zxdl = (WmsDeviceExecutionQueue) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetQueueByTask»ñÈ¡¶ÓÁÐÐÅÏ¢´íÎó£º" + e.getMessage()); + } + return stask_ddj_zxdl; + } + + public static List getQueueByRoad(EntityDAO dao, int ddjh) throws Exception { + List queueList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from WmsDeviceExecutionQueue where ddjxf=0 and devId=").append(ddjh).append(" ORDER BY scsj" ); + queueList = dao.searchEntities(strBud.toString()); + + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetQueueByTask»ñÈ¡¶ÓÁÐÐÅÏ¢´íÎó£º" + e.getMessage()); + } + return queueList; + } + + public static int getJxsMsg(EntityDAO dao, String tray_code) throws Exception { + List queueList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from JxsMsg where tray_code ='").append(tray_code).append("'"); + queueList = dao.searchEntities(strBud.toString()); + + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetQueueByTask»ñÈ¡¶ÓÁÐÐÅÏ¢´íÎó£º" + e.getMessage()); + } + return queueList.size(); + } + + public static MydoJob findMydoJobByTaskNo(EntityDAO dao, long taskNo) throws Exception { + MydoJob mydoJob = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where task_no = '").append(taskNo).append("'"); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + mydoJob = (MydoJob) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐfindMydoJobByTaskNo»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÈÎÎñºÅΪ£º" + taskNo); + } + return mydoJob; + } + + public static MydoJob findMydoJobByTray(EntityDAO dao, String tray_code) throws Exception { + MydoJob mydoJob = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where tray_code = '").append(tray_code).append("'"); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + mydoJob = (MydoJob) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐfindMydoJobByTaskNo»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÈÎÎñºÅΪ£º" + tray_code); + } + return mydoJob; + } + + public static MydoJob getInJobByRoadwayAndTask(EntityDAO dao, int ddjh, long rwh) throws Exception { + MydoJob mydoJob = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out < 10 and cargo_space_id is null and task_no = ").append(rwh).append(" and roadway_id =").append(ddjh); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + mydoJob = (MydoJob) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetInJobByRoadwayAndTask»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÈÎÎñºÅΪ£º" + rwh); + } + return mydoJob; + + } + public static MydoJob getInJobByRoadwayAndTask1(EntityDAO dao, long rwh) throws Exception { + MydoJob mydoJob = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out in (3,50) and task_no = ").append(rwh); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + mydoJob = (MydoJob) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetInJobByRoadwayAndTask»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÈÎÎñºÅΪ£º" + rwh); + } + return mydoJob; + + } + public static MydoJob getOUTJobByRoadwayAndTask(EntityDAO dao, int ddjh, long rwh) throws Exception { + MydoJob mydoJob = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out > 9 and cargo_space_id is null and task_no = ").append(rwh).append(" and roadway_id =").append(ddjh); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + mydoJob = (MydoJob) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetInJobByRoadwayAndTask»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÈÎÎñºÅΪ£º" + rwh); + } + return mydoJob; + + } + + public static MydoJob getInJobByRoadwayAndCargo(EntityDAO dao, int ddjh, long rwh) throws Exception { + MydoJob mydoJob = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out < 10 and cargo_space_id is not null and task_no = ").append(rwh).append(" and roadway_id =").append(ddjh); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + mydoJob = (MydoJob) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetInJobByRoadwayAndTask»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÈÎÎñºÅΪ£º" + rwh); + } + return mydoJob; + + } + + public static MydoJob getSlotJobByTask(EntityDAO dao, long rwh) throws Exception { + MydoJob mydoJob = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where (in_or_out < 10 or in_or_out=20) and location is null and task_no = ").append(rwh); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + mydoJob = (MydoJob) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetSlotJobByTask»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÈÎÎñºÅΪ£º" + rwh); + } + return mydoJob; + } + + public static List getOutJobByRoad(EntityDAO dao, int ddjh, int floor) throws Exception { + List outList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out>9 and status=1 and roadway_id = ").append(ddjh).append(" and floor = ").append(floor); + outList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetOutJobByRoad»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÏïµÀºÅΪ£º" + ddjh); + } + return outList; + } + + public static MydoJob getOutJobByTask(EntityDAO dao, long taskNo) throws Exception { + MydoJob mydoJob = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out > 9 and task_no = ").append(taskNo); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + mydoJob = (MydoJob) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetOutJobByTask»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÈÎÎñºÅΪ£º" + taskNo); + } + return mydoJob; + } + + public static List getInJobByTray(EntityDAO dao, String trayCode, int floor) throws Exception { + List inList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where (in_or_out < 10 or in_or_out = 50 ) and status in(1,3) and tray_code = '") + .append(trayCode).append("' and floor = ").append(floor); + inList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetInJobByTray»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÍÐÅÌÂëΪ£º" + trayCode); + } + return inList; + } + + public static List getInJobByTray1(EntityDAO dao, int task_no, int floor) throws Exception { + List inList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where (in_or_out = 3 or in_or_out = 50 ) and status in(1,3) ").append(" and floor = ").append(floor).append(" and task_no = ").append(task_no); + inList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetInJobByTray»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡"); + } + return inList; + } + + public static List getInJobNoTray(EntityDAO dao, int floor) throws Exception { + List inList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out < 10 and status=1 and tray_code is null and floor=").append(floor); + inList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetInJobNoTray»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡"); + } + return inList; + } + + public static List getInJobByent(EntityDAO dao, int floor) throws Exception { + List inList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out < 10 and status=1 and entrance_id = '1' and floor=").append(floor); + inList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetInJobNoTray»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡"); + } + return inList; + } + + public static List getInJobByTrayAndRoad(EntityDAO dao, String tray_code, int floor) throws Exception { + List inList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where (in_or_out < 10 or in_or_out =50 ) and status= 3 and roadway_id is not null and tray_code='").append(tray_code).append("' and floor =").append(floor); + inList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetInJobByTrayAndRoad»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÍÐÅÌÂëΪ£º" + tray_code); + } + return inList; + } + + public static List getTpOutByFloor(EntityDAO dao, int floor, int id) throws Exception { + List inList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out = 18 and floor ='").append(floor).append("'"); + inList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetTpOutByFloor»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡µ±Ç°²ãΪ£º" + floor); + } + return inList; + } + + public static List getTpOutByTask(EntityDAO dao, int floor, long task_no) throws Exception { + List inList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out = 18 and floor ='").append(floor).append("' and task_no =").append(task_no); + inList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetTpOutByFloor»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡µ±Ç°²ãΪ£º" + floor); + } + return inList; + } + + public static List getTpOutByTask(EntityDAO dao, int floor) throws Exception { + List inList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out = 18 and floor ='").append(floor).append("'"); + inList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetTpOutByFloor»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡µ±Ç°²ãΪ£º" + floor); + } + return inList; + } + + public static List getTpInByFloor(EntityDAO dao, int floor, int id) throws Exception { + List inList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out = 8 and execution_phase < 4 and floor =").append(floor).append(" and entrance_id = '").append(id).append("'"); + inList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetTpInByFloor»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡µ±Ç°²ãΪ£º" + floor); + } + return inList; + } + + public static List getInJobByFloor(EntityDAO dao, int floor, int id) throws Exception { + List inList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out = 8 and status = 1 and floor =").append(floor).append(" and entrance_id = '").append(id).append("'"); + inList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetInJobByFloor»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡µ±Ç°²ãΪ£º" + floor); + } + return inList; + } + + public static List getInTpByFloorAndRoad(EntityDAO dao, int floor, int id) throws Exception { + List inList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from MydoJob where in_or_out = 8 and status = 3 and roadway_id is not null and floor =").append(floor).append(" and entrance_id = '").append(id).append("'"); + inList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetInTpByFloorAndRoad»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡µ±Ç°²ãΪ£º" + floor); + } + return inList; + } + + public static JxsJobMsg getJxsJobById(EntityDAO dao, byte btId) throws Exception { + JxsJobMsg jxsJobMsg = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from JxsJobMsg where stacking_id > 0 and jxs_id = ").append(btId); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + jxsJobMsg = (JxsJobMsg) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetJxsJobById»ñÈ¡»úеÊÖ×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÈÎÎñºÅΪ£º" + btId); + } + return jxsJobMsg; + } + + public static List getRecordByTaskAndId(EntityDAO dao, byte btId, long zxrwh) throws Exception { + List inList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from BasFaultRecord where reset = 0 and deviceId ='").append(btId).append("'") + .append(" and taskNo=").append(zxrwh); + inList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetRecordByTaskAndId»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÈÎÎñºÅΪ£º" + zxrwh); + } + return inList; + } + + public static List getRecordByTaskAndJobId(EntityDAO dao, byte btId, String job_id) throws Exception { + List inList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from BasFaultRecord where jobId ='").append(job_id).append("'") + .append(" and device_id='").append(btId).append("'"); + inList = dao.searchEntities(strBud.toString()); + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetRecordByTaskAndJobId»ñÈ¡×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÈÎÎñºÅΪ£º" + btId); + } + return inList; + } + + + public static WcsCmpIn getCmpIn(EntityDAO dao, byte btId) throws Exception { + WcsCmpIn jxsJobMsg = null; + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from WcsCmpIn where id = ").append(btId); + List ls = dao.searchEntities(strBud.toString()); + if (ls != null && ls.size() > 0) { + jxsJobMsg = (WcsCmpIn) ls.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetJxsJobById»ñÈ¡»úеÊÖ×÷ÒµÐÅÏ¢ÓÐÎ󣡣¡£¡£¡ÈÎÎñºÅΪ£º" + btId); + } + return jxsJobMsg; + } + + public static JxsFinishCpj selectByJxsFinishCpj(EntityDAO m_dao, byte btId) { + JxsFinishCpj jxsFinishCpj = null; + List list = m_dao.searchEntities("from JxsFinishCpj where jxs_id='" + btId + "'"); + if (list.size() > 0) { + jxsFinishCpj = list.get(0); + } + + return jxsFinishCpj; + } + + public static int getJxsMsg1(EntityDAO dao, String tray_code) throws Exception { + List queueList = new ArrayList<>(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from JxsMsg where tray_code like'").append(tray_code).append("%'"); + queueList = dao.searchEntities(strBud.toString()); + + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetQueueByTask»ñÈ¡¶ÓÁÐÐÅÏ¢´íÎó£º" + e.getMessage()); + } + return queueList.size(); + } + public static SysDictData getTplx(EntityDAO dao, int tplx, int by1) throws Exception { + SysDictData sysDictData = new SysDictData(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from SysDictData where dict_sort ='").append(by1).append("' and remark = '").append(tplx).append("'"); + List list = dao.searchEntities(strBud.toString()); + if (list.size() > 0) { + sysDictData = list.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetTplx»ñÈ¡¶ÓÁÐÐÅÏ¢´íÎó£º" + e.getMessage()); + } + return sysDictData; + } + public static SysDictData getTplx1(EntityDAO dao, String tplx) throws Exception { + SysDictData sysDictData = new SysDictData(); + try { + StringBuilder strBud = new StringBuilder(); + strBud.append("from SysDictData where dict_value ='").append(tplx).append("'"); + List list = dao.searchEntities(strBud.toString()); + if (list.size() > 0) { + sysDictData = list.get(0); + } + } catch (Exception e) { + throw new Exception("Ö´ÐÐgetTplx1»ñÈ¡¶ÓÁÐÐÅÏ¢´íÎó£º" + e.getMessage()); + } + return sysDictData; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/utils/Tools.java b/src/com/wms/dss/ats/customs/abb/utils/Tools.java new file mode 100644 index 0000000..f5120b6 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/Tools.java @@ -0,0 +1,502 @@ +package com.wms.dss.ats.customs.abb.utils; + +import HslCommunication.BasicFramework.SoftBasic; +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.ats.customs.abb.entity.SendData; +import com.wms.dss.ats.customs.abb.entity.StoredParameters; +import com.wms.dss.common.server.form.Logger; +import org.libnodave.Nodave; + +import java.io.Serializable; +import java.nio.charset.StandardCharsets; +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Types; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; + +/** + * æ��è¿°:cyc16校验ç � + * + * @author zhu + */ +public class Tools implements Serializable { + public static int Debug = 0x20; + public final static int DEBUG_CONVERSIONS = 0x1000; + + + public static void main(String[] arg) { + int jym = getJYM(1, 2, 3); + System.out.println(jym); + } + + /*4ã€�CRC-16校验ç �计算方法: + 常用查表法和计算法。计算方法一般都是: + (1)ã€�预置1个16ä½�的寄存器为å��六进制FFFF(å�³å…¨ä¸º1),称此寄存器为CRC寄存器; + (2)ã€�把第一个8ä½�二进制数æ�®ï¼ˆæ—¢é€šè®¯ä¿¡æ�¯å¸§çš„第一个字节)与16ä½�çš„CRC寄存器的低 + 8ä½�相异或,把结果放于CRC寄存器,高八ä½�æ•°æ�®ä¸�å�˜ï¼› + (3)ã€�把CRC寄存器的内容å�³ç§»ä¸€ä½�(æœ�低ä½�)用0填补最高ä½�,并检查å�³ç§»å�Žçš„移出ä½�ï¼› + (4)ã€�如果移出ä½�为0:é‡�å¤�第3步(å†�次å�³ç§»ä¸€ä½�);如果移出ä½�为1,CRC寄存器与多 + 项å¼�A001(1010 0000 0000 0001)进行异或; + (5)ã€�é‡�å¤�步骤3å’Œ4,直到å�³ç§»8次,这样整个8ä½�æ•°æ�®å…¨éƒ¨è¿›è¡Œäº†å¤„ç�†ï¼› + (6)ã€�é‡�å¤�步骤2到步骤5,进行通讯信æ�¯å¸§ä¸‹ä¸€ä¸ªå­—节的处ç�†ï¼› + (7)ã€�将该通讯信æ�¯å¸§æ‰€æœ‰å­—节按上述步骤计算完æˆ�å�Žï¼Œå¾—到的16ä½�CRC寄存器的高ã€�低 + 字节进行交æ�¢ï¼› + (8)ã€�最å�Žå¾—到的CRC寄存器内容å�³ä¸ºï¼šCRCç �。 + 以上计算步骤中的多项å¼�A001是8005按ä½�颠倒å�Žçš„结果。 + 查表法是将移ä½�异或的计算结果å�šæˆ�了一个表,就是将0~256放入一个长度为16ä½�的寄存器中的低八ä½�,高八ä½�å¡«å……0,然å�Žå°†è¯¥å¯„存器与多项å¼�0XA001按照上述3ã€�4步骤,直到八ä½�全部移出,最å�Žå¯„存器中的值就是表格中的数æ�®ï¼Œé«˜å…«ä½�ã€�低八ä½�分别å�•独一个表。*/ + + /** 托盘æ�¡ç �è§£æž�**/ + public static String bytetostringtool(byte[] aaa) { + String tptm = ""; + for(int i=0;i> 8) & 0xff);// 次低ä½� + targets[1] = (byte) ((res >> 16) & 0xff);// 次高ä½� + targets[0] = (byte) (res >>> 24);// 最高ä½�,无符å�·å�³ç§»ã€‚ + return targets; + } + + /** + * 多个byte å�ˆå¹¶æˆ�一个byte + */ + public static byte[] byteMerge(byte[]... values) { + int length_byte = 0; + for (byte[] value : values) { + length_byte += value.length; + } + byte[] all_byte = new byte[length_byte]; + int countLength = 0; + for (byte[] b : values) { + System.arraycopy(b, 0, all_byte, countLength, b.length); + countLength += b.length; + } + return all_byte; + } + + /** + * int 转byte + */ + public static byte[] intToBytes(int value, int len) { + byte[] b = new byte[len]; + for (int i = 0; i < len; i++) { + b[len - i - 1] = (byte) ((value >> 8 * i) & 0xff); + } + return b; + } + + /** + * 下å�‘到PLCçš„å��馈字节 + */ + public static byte[] sendData(SendData... list) { + byte[][] values = new byte[list.length][0]; + for (int i = 0; i < list.length; i++) { + byte[] bytes = Tools.intToBytes(list[i].getNum(), list[i].getNum2()); + System.out.println(bytes.length); + values[i] = bytes; + } + int length_byte = 0; + for (byte[] value : values) { + length_byte += value.length; + } + byte[] all_byte = new byte[length_byte]; + int countLength = 0; + for (byte[] b : values) { + System.arraycopy(b, 0, all_byte, countLength, b.length); + countLength += b.length; + } + return all_byte; + } + + //下å�‘字节数组 + public static byte[] sendDataToDevice(long taskNo,String trayCode, int...ints){ + int length = 0; + byte[] xfData = null; + if (trayCode == null){ + length = 4 + (ints.length * 2); + xfData = new byte[length]; + byte[] RWH = new byte[4]; + RWH = Tools.int2byte((int) taskNo); + for (int i = 0; i < length; i++){ + if (i < 4){ + xfData[i] = RWH[i]; + } else { + if (i % 2 == 0){ + byte[] param = new byte[2]; + param = intbyte(ints[(i - 4) / 2]); + xfData[i] = param[0]; + xfData[i + 1] = param[1]; + } + } + } + } else { + length = 12 + (ints.length * 2); + xfData = new byte[length]; + byte[] RWH = new byte[4]; + RWH = Tools.int2byte((int) taskNo); + byte[] tCode = new byte[8]; + if ("".equals(trayCode)){ + for (int i = 0;i < tCode.length;i++){ + tCode[i] = 0; + } + }else { + byte[] code = trayCode.getBytes(); + for (int i = 0; i < tCode.length; i++) { + tCode[i] = code[i]; + } + } + for (int i = 0; i< length; i++){ + if (i < 4){ + xfData[i] = RWH[i]; + } else if (i > 3 && i< 12) { + xfData[i] = tCode[i - 4]; + } else { + if (i % 2 == 0){ + byte[] param = new byte[2]; + param = intbyte(ints[(i - 12) / 2]); + xfData[i] = param[0]; + xfData[i + 1] = param[1]; + } + } + } + } + return xfData; + } + + /** + * 字节数组转字符船 + */ + public static String byteToString(String substring) { + return new String(SoftBasic.HexStringToBytes(substring), StandardCharsets.UTF_8); + } + + /** + * 调用存储过程å°�装 + */ + public static int storedProcedure(EntityDAO m_dao, String name, Integer out, StoredParameters... storedParameters) throws SQLException { + Connection conn = null; + int back = 0; + try { + conn = m_dao.getConnection(); + CallableStatement cs = conn.prepareCall(name); + for (StoredParameters sendDatum : storedParameters) { + cs.setString(sendDatum.getNum(), sendDatum.getParameter()); + } + cs.registerOutParameter(out, java.sql.Types.INTEGER); + cs.execute(); + back = cs.getInt(out); + } catch (Exception e) { + e.printStackTrace(); + Logger.info(name + "-failed execution of stored procedure:" + e.getMessage()); + } finally { + if (conn != null) { + conn.close(); + } + } +// Logger.info(name + "-Successful execution of stored procedure"); + return back; + } + /** + * 调用存储过程å°�装 + */ + public static String storedPro(EntityDAO m_dao, String name, Integer out,Integer outMsg, StoredParameters... storedParameters) throws SQLException { + Connection conn = null; + int back = 0; + String msg = ""; + try { + conn = m_dao.getConnection(); + CallableStatement cs = conn.prepareCall(name); + for (StoredParameters sendDatum : storedParameters) { + cs.setString(sendDatum.getNum(), sendDatum.getParameter()); + } + cs.registerOutParameter(out, java.sql.Types.INTEGER); + cs.registerOutParameter(outMsg, Types.VARCHAR); + cs.execute(); + back = cs.getInt(out); + msg = cs.getString(outMsg); + } catch (Exception e) { + e.printStackTrace(); + Logger.info(name + "-failed execution of stored procedure:" + e.getMessage()); + } finally { + if (conn != null) { + conn.close(); + } + } +// Logger.info(name + "-Successful execution of stored procedure"); + return msg; + } + public static String getDate() { + Date t = new Date(); + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return df.format(t); + } + + //int 转2字节 + public static byte[] intbyte(int res) {///Java中10进制转byte[] + byte[] targets = new byte[2]; + targets[1] = (byte) ((res >> 0) & 0xff);// 次高ä½� + targets[0] = (byte) (res >>> 8);// 最高ä½�,无符å�·å�³ç§»ã€‚ + return targets; + } + + public static int[] binarysToints(String hex){ + int[] a = new int[4]; + String hexString = change32(hex); + a[0] = Integer.parseInt(hexString.substring(0,8),2);//将二进制字符串转为整形 + a[1] = Integer.parseInt(hexString.substring(8,16),2); + a[2] = Integer.parseInt(hexString.substring(16,24),2); + a[3] = Integer.parseInt(hexString.substring(24,32),2); + return a; + } +} diff --git a/src/com/wms/dss/ats/customs/abb/utils/UtilId.java b/src/com/wms/dss/ats/customs/abb/utils/UtilId.java new file mode 100644 index 0000000..2136730 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/UtilId.java @@ -0,0 +1,13 @@ +package com.wms.dss.ats.customs.abb.utils; + +import java.util.UUID; + +public class UtilId { + + public static String uuids(){ + UUID uuid = UUID.randomUUID();//ç›� + String a=uuid.toString().replace("-", "").toUpperCase(); + return a; + } + +} diff --git a/src/com/wms/dss/ats/customs/abb/utils/ZsGet.java b/src/com/wms/dss/ats/customs/abb/utils/ZsGet.java new file mode 100644 index 0000000..07b4880 --- /dev/null +++ b/src/com/wms/dss/ats/customs/abb/utils/ZsGet.java @@ -0,0 +1,100 @@ +package com.wms.dss.ats.customs.abb.utils; + +import com.wms.dss.ats.customs.abb.plc.IsoTcpClientSSJ; +import net.sf.json.JSONObject; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Proxy; +import java.net.Socket; +import java.util.HashMap; +import java.util.Map; + +import static java.lang.Thread.sleep; + + +public class ZsGet { + + public static String interfaceUtil(String url, String jsonString) throws IOException + { + String resp = ""; + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(url); + StringEntity entityStr = new StringEntity(jsonString, ContentType.create("application/json", "UTF-8")); + httpPost.setEntity(entityStr); + CloseableHttpResponse response = null; + response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + resp = EntityUtils.toString(entity, "UTF-8"); + JSONObject jsonobj = JSONObject.fromObject(resp); + EntityUtils.consume(entity); + response.close(); + jsonobj.get("code").toString(); + return jsonobj.get("code").toString(); + } + public static String interfaceUtil(int floor,String host,int port, String jsonString) throws IOException + { + String taskback = null; + try (Socket socket = new Socket(host, port); // ʹÓÃtry-with-resourcesÈ·±£×ÊÔ´ÊÍ·Å + OutputStream os = socket.getOutputStream()) { + InputStream is = null; + byte[] buffer = jsonString.getBytes(); // ½«Êý¾Ýת»»Îª×Ö½ÚÊý×é + os.write(buffer); // ½«Êý¾ÝдÈëSocketÊä³öÁ÷ +// System.out.println("Data sent successfully."); + is = socket.getInputStream();// + sleep(1500); + int size = is.available(); + if (size > 0) { +// System.out.println(floor+"²ã:Ocr" + "½ÓÊÜÏìÓ¦³¤¶È£º" + size); + byte[] resp = new byte[size]; + is.read(resp); + taskback = taskback(resp);//Â¥²ã£¬ÖØÁ¿£¬Åú´Î£¬ÈÕÆÚ + } + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + + + return taskback; + } + private static void checkWeight(String weightIp, Integer weightPort) { + String s = CheckWeight.WeightOut(weightIp, weightPort); + Double aDouble = new Double(s); + System.err.println("³ÆÖØÐÅÏ¢£ºIP:" + weightIp + ",¶Ë¿Ú£º" + weightPort + ",¶ÁÈ¡ÖØÁ¿£º" + aDouble + "Kg"); + } + + public static void main(String[] args) throws IOException { + Map params = new HashMap(); + String s = interfaceUtil(2,"192.168.58.16",7930, "1,1,15,L1203648,2024.09.28");//getÇëÇó + System.out.println(s); + Tools.sendDataToDevice(0, null, 3); +// System.out.println(); +// String weightIp = "192.168.56.92"; +// int weightPort = 4001; +// checkWeight(weightIp, weightPort); +// byte[] sendData = new byte[]{0, 1}; +// int isSend = IsoTcpClientSSJ.WritetoSSJ("DB65.178", sendData); +// System.out.println(isSend); + } + + public static String taskback (byte[] arr){ + + StringBuilder sb = new StringBuilder(); + for (int asciiValue : arr) { + char character = (char) asciiValue; + sb.append(character); + } + String str = sb.toString(); + return str; + } +} + diff --git a/src/log4j.properties b/src/log4j.properties new file mode 100644 index 0000000..1a62926 --- /dev/null +++ b/src/log4j.properties @@ -0,0 +1,41 @@ +# Configure logging for testing +# 日志输出级别为INFO,debug1 */ + /* This code seems to be specific to 200 family. */ + + public final static int RESULT_ITEM_NOT_AVAILABLE = 10; + /* means a a piece of data is not available in the CPU, e.g. */ + /* when trying to read a non existing DB */ + + public final static int RESULT_ADDRESS_OUT_OF_RANGE = 5; + /* means the data address is beyond the CPUs address range */ + public final static int RESULT_WRITE_DATA_SIZE_MISMATCH = 7; + /* means the write data size doesn't fit item size */ + public final static int RESULT_CANNOT_EVALUATE_PDU = -123; + public final static int RESULT_CPU_RETURNED_NO_DATA = -124; + + public final static int RESULT_UNKNOWN_ERROR = -125; + public final static int RESULT_EMPTY_RESULT_ERROR = -126; + public final static int RESULT_EMPTY_RESULT_SET_ERROR = -127; + public final static int RESULT_UNEXPECTED_FUNC = -128; + public final static int RESULT_UNKNOWN_DATA_UNIT_SIZE = -129; + + public final static int RESULT_SHORT_PACKET = -1024; + public final static int RESULT_TIMEOUT = -1025; + + public static byte[] toPLCfloat(float f) { + int i = Float.floatToIntBits(f); + if ((Debug & DEBUG_CONVERSIONS) != 0) + System.out.println("i: " + i); + return bswap_32(i); + } + + public static byte[] toPLCfloat(double d) { + float f = (float) d; + return toPLCfloat(f); + } + + public static byte[] bswap_32(int a) { + byte[] b = new byte[4]; + b[3] = (byte) (a & 0xff); + a = a >> 8; + b[2] = (byte) (a & 0xff); + a = a >> 8; + b[1] = (byte) (a & 0xff); + a = a >> 8; + b[0] = (byte) (a & 0xff); + if ((Debug & DEBUG_CONVERSIONS) != 0) + dump("In: " + a + " out:", b, 0, 4); + return b; + } + + public static byte[] bswap_32(long a) { + byte[] b = new byte[4]; + b[3] = (byte) (a & 0xff); + a = a >> 8; + b[2] = (byte) (a & 0xff); + a = a >> 8; + b[1] = (byte) (a & 0xff); + a = a >> 8; + b[0] = (byte) (a & 0xff); + if ((Debug & DEBUG_CONVERSIONS) != 0) + dump("In: " + a + " out:", b, 0, 4); + return b; + } + + public static byte[] bswap_64(int a) { + byte[] b = new byte[8]; + b[7] = (byte) (a & 0xff); + a = a >> 8; + b[6] = (byte) (a & 0xff); + a = a >> 8; + b[5] = (byte) (a & 0xff); + a = a >> 8; + b[4] = (byte) (a & 0xff); + a = a >> 8; + b[3] = (byte) (a & 0xff); + a = a >> 8; + b[2] = (byte) (a & 0xff); + a = a >> 8; + b[1] = (byte) (a & 0xff); + a = a >> 8; + b[0] = (byte) (a & 0xff); + + if ((Debug & DEBUG_CONVERSIONS) != 0) + dump("In: " + a + " out:", b, 0, 8); + return b; + } + + public static byte[] bswap_64(long a) { + byte[] b = new byte[8]; + // b[7] = (byte) (a & 0xff); + // a = a >> 8; + // b[6] = (byte) (a & 0xff); + // a = a >> 8; + // b[5] = (byte) (a & 0xff); + // a = a >> 8; + // b[4] = (byte) (a & 0xff); + // a = a >> 8; + // b[3] = (byte) (a & 0xff); + // a = a >> 8; + // b[2] = (byte) (a & 0xff); + // a = a >> 8; + // b[1] = (byte) (a & 0xff); + // a = a >> 8; + // b[0] = (byte) (a & 0xff); + + b[0] = (byte) (a & 0xff); + a = a >> 8; + b[1] = (byte) (a & 0xff); + a = a >> 8; + b[2] = (byte) (a & 0xff); + a = a >> 8; + b[3] = (byte) (a & 0xff); + a = a >> 8; + b[4] = (byte) (a & 0xff); + a = a >> 8; + b[5] = (byte) (a & 0xff); + a = a >> 8; + b[6] = (byte) (a & 0xff); + a = a >> 8; + b[7] = (byte) (a & 0xff); + + if ((Debug & DEBUG_CONVERSIONS) != 0) + dump("In: " + a + " out:", b, 0, 8); + return b; + } + + public static byte[] bswap_16(int a) { + byte[] b = new byte[2]; + b[1] = (byte) (a & 0xff); + a = a >> 8; + b[0] = (byte) (a & 0xff); + if ((Debug & DEBUG_CONVERSIONS) != 0) + dump("In: " + a + " out:", b, 0, 2); + return b; + } + + /** + * This doesn't swap anything, but the name fits into the series + * + * @param a + * @return + */ + public static byte[] bswap_8(int a) { + byte[] b = new byte[1]; + b[0] = (byte) (a & 0xff); + return b; + } + + /** + * Dumps len hex codes from byte array mem beginning at index start. + * + * @param text: + * a text to print before the list + * @return + */ + public static void dump(String text, byte[] mem, int start, int len) { + System.out.print(text + " "); + for (int i = start; i < start + len; i++) { + int j = mem[i]; + if (j < 0) + j += 256; + String s = Integer.toHexString(j); + if (s.length() < 2) + s = "0" + s; + System.out.print(s + ","); + } + System.out.println(" "); + } + + public static long USBELong(byte[] b, int pos) { + int i = b[pos]; + int j = b[pos + 1]; + int k = b[pos + 2]; + int l = b[pos + 3]; + // System.out.println( + // pos + " 0:" + i + " 1:" + j + " 2:" + k + " 3:" + l); + if (i < 0) + i += 256; + if (j < 0) + j += 256; + if (k < 0) + k += 256; + if (l < 0) + l += 256; + return (256 * k + l) + 65536L * (256 * i + j); + } + + public static long SBELong(byte[] b, int pos) { + int i = b[pos]; + int j = b[pos + 1]; + int k = b[pos + 2]; + int l = b[pos + 3]; + // if (i < 0) + // i += 256; + if (j < 0) + j += 256; + if (k < 0) + k += 256; + if (l < 0) + l += 256; + return (256 * k + l) + 65536L * (256 * i + j); + } + + /////////////////////////////////////////////// + public static StringBuffer SBEString(byte[] b, int pos) { + StringBuffer sbu = new StringBuffer(); + sbu.append((char) b[pos]); + sbu.append((char) b[pos + 1]); + sbu.append((char) b[pos + 2]); + sbu.append((char) b[pos + 3]); + sbu.append((char) b[pos + 4]); + sbu.append((char) b[pos + 5]); + sbu.append((char) b[pos + 6]); + sbu.append((char) b[pos + 7]); + + return sbu; + } + + /** + * ½«b[pos]¼°b[pos + 1] »»Ëã³É10½øÖÆÖµ + * + * @param b + * @param pos + * @return + */ + public static int USBEWord(byte[] b, int pos) { + int i = b[pos]; + int k = b[pos + 1]; + if (i < 0) + i += 256; + if (k < 0) + k += 256; + return (256 * i + k); + } + + /** + * ½«valֵת»»³É×Ö½Úb[pos]¼°b[pos + 1] + * + * @param b + * @param pos + * @param val + */ + public static void setUSBEWord(byte[] b, int pos, int val) { + b[pos] = ((byte) (val / 0x100)); + b[pos + 1] = ((byte) (val % 0x100)); + } + + /** + * ½«valֵת»»³ÉÒ»¸ö×Ö½Ú + * + * @param b + * @param pos + * @param val + */ + public static void setUSByte(byte[] b, int pos, int val) { + b[pos] = ((byte) (val & 0xff)); + } + + /** + * ½«³¤ÕûÐÎaת»»³É4¸ö×Ö½Ú + * + * @param b + * @param pos + * @param a + */ + public static void setUSBELong(byte[] b, int pos, long a) { + b[pos + 3] = (byte) (a & 0xff); + a = a >> 8; + b[pos + 2] = (byte) (a & 0xff); + a = a >> 8; + b[pos + 1] = (byte) (a & 0xff); + a = a >> 8; + b[pos] = (byte) (a & 0xff); + } + + /** + * + * @param b + * @param pos + * @param f + */ + public static void setBEFloat(byte[] b, int pos, float f) { + /* + * ÁíÍâÐèÒªÖªµÀµÄÊÇ£¬floatÀàÐÍÕ¼ÓÃ4¸ö×Ö½Ú£¬´Ó×îµÍ루×îÓұߣ©µ½×î¸ß루×î×ó±ß£©µÄ±àºÅÊÇ´Ó0-31¡£ÕâÑùµÄ»°£¬ÉÏÃæµÄ½âÊ;ÍÈÝÒ׿´¶®ÁË¡£ + * Ò²¾ÍÊÇ˵£¬×ª»»³ÉµÄ32¸ö0¡¢1×Ö·û´®ÖУ¬31ºÅ±íʾ·ûºÅ£¬30-23±íʾָÊý£¬22-0±íʾβÊý¡£ °´ÕÕIEEE + * 754±ê×¼£¬32λ¸¡µãÊýÔÚ¼ÆËã»úÖжþ½øÖÆ´æ´¢ÐÎʽ¹²Èý²¿·Ö£ºS(1룬·ûºÅ) E(8룬½×Âë) M(23λ£¬Î²Êý) + * ¸øÄã¾Ù¸öÀý×Ó°É£¬Float.floatToIntBits(20.5f)°´ÕÕÈçÏ·½Ê½¼ÆË㣺 + * 20.59D=10100.1B=1.01001*2^4B Ö¸Êýe=4 S=0-->ÕýÊý + * E=4+127=131D=10000011B-->ÕæÊµÖ¸Êýe±ä³É½×ÂëEʱÐè¼Ó127 M=01001B Ôò32λ2½øÖÆ´æ´¢ÐÎʽΪ£º0 + * 10000011 01001000000000000000000 ת»»³É10½øÖƼ´1101266944 + */ + int a = Float.floatToIntBits(f); + b[pos + 3] = (byte) (a & 0xff); + a = a >> 8; + b[pos + 2] = (byte) (a & 0xff); + a = a >> 8; + b[pos + 1] = (byte) (a & 0xff); + a = a >> 8; + b[pos] = (byte) (a & 0xff); + } + + public static int SBEWord(byte[] b, int pos) { + int i = b[pos]; + int k = b[pos + 1]; + // if (i < 0) + // i += 256; + if (k < 0) + k += 256; + return (256 * i + k); + } + + public static int USByte(byte[] b, int pos) { + int i = b[pos]; + if (i < 0) + i += 256; + return (i); + } + + public static int SByte(byte[] b, int pos) { + int i = b[pos]; + return (i); + } + + public static float BEFloat(byte[] b, int pos) { + int i = 0; + // System.out.println("pos" + pos); + + if ((Debug & DEBUG_CONVERSIONS) != 0) + System.out.println("C " + i); + i |= Nodave.USByte(b, pos); + if ((Debug & DEBUG_CONVERSIONS) != 0) + System.out.println("Co " + i); + i <<= 8; + if ((Debug & DEBUG_CONVERSIONS) != 0) + System.out.println("Con " + i); + i |= Nodave.USByte(b, pos + 1); + if ((Debug & DEBUG_CONVERSIONS) != 0) + System.out.println("Conv " + i); + i <<= 8; + if ((Debug & DEBUG_CONVERSIONS) != 0) + System.out.println("Conve " + i); + i |= Nodave.USByte(b, pos + 2); + if ((Debug & DEBUG_CONVERSIONS) != 0) + System.out.println("Conver " + i); + i <<= 8; + if ((Debug & DEBUG_CONVERSIONS) != 0) + System.out.println("Convert " + i); + i |= Nodave.USByte(b, pos + 3); + if ((Debug & DEBUG_CONVERSIONS) != 0) + System.out.println("Converte " + i); + float f = Float.intBitsToFloat(i); + if ((Debug & DEBUG_CONVERSIONS) != 0) + System.out.println("Converted " + f); + return (f); + } + + public static String areaName(int area) { + switch (area) { + case DB: + return "DB"; + case INPUTS: + return "E"; + case OUTPUTS: + return "A"; + case FLAGS: + return "M"; + default: + return "unknown area!"; + } + } + + public static String strerror(int code) { + switch (code) { + case RESULT_OK: + return "ok"; + case RESULT_MULTIPLE_BITS_NOT_SUPPORTED: + return "the CPU does not support reading a bit block of length<>1"; + case RESULT_ITEM_NOT_AVAILABLE: + return "the desired item is not available in the PLC"; + case RESULT_ITEM_NOT_AVAILABLE200: + return "the desired item is not available in the PLC (200 family)"; + case RESULT_ADDRESS_OUT_OF_RANGE: + return "the desired address is beyond limit for this PLC"; + case RESULT_CPU_RETURNED_NO_DATA: + return "the PLC returned a packet with no result data"; + case Nodave.RESULT_UNKNOWN_ERROR: + return "the PLC returned an error code not understood by this library"; + case Nodave.RESULT_EMPTY_RESULT_ERROR: + return "this result contains no data"; + case Nodave.RESULT_EMPTY_RESULT_SET_ERROR: + return "cannot work with an undefined result set"; + case Nodave.RESULT_CANNOT_EVALUATE_PDU: + return "cannot evaluate the received PDU"; + case Nodave.RESULT_WRITE_DATA_SIZE_MISMATCH: + return "Write data size error"; + case Nodave.RESULT_NO_PERIPHERAL_AT_ADDRESS: + return "No data from I/O module"; + case Nodave.RESULT_UNEXPECTED_FUNC: + return "Unexpected function code in answer"; + case Nodave.RESULT_UNKNOWN_DATA_UNIT_SIZE: + return "PLC responds wit an unknown data type"; + case Nodave.RESULT_SHORT_PACKET: + return "Short packet from PLC"; + case Nodave.RESULT_TIMEOUT: + return "Timeout when waiting for PLC response"; + case 0x8000: + return "function already occupied."; + case 0x8001: + return "not allowed in current operating status."; + case 0x8101: + return "hardware fault."; + case 0x8103: + return "object access not allowed."; + case 0x8104: + return "context is not supported."; + case 0x8105: + return "invalid address."; + case 0x8106: + return "data type not supported."; + case 0x8107: + return "data type not consistent."; + case 0x810A: + return "object does not exist."; + case 0x8500: + return "incorrect PDU size."; + case 0x8702: + return "address invalid."; + case 0xd201: + return "block name syntax error."; + case 0xd202: + return "syntax error function parameter."; + case 0xd203: + return "syntax error block type."; + case 0xd204: + return "no linked block in storage medium."; + case 0xd205: + return "object already exists."; + case 0xd206: + return "object already exists."; + case 0xd207: + return "block exists in EPROM."; + case 0xd209: + return "block does not exist."; + case 0xd20e: + return "no block does not exist."; + case 0xd210: + return "block number too big."; + case 0xd240: + return "unfinished block transfer in progress?"; + case 0xd241: + return "protected by password."; + default: + return "no message defined for code: " + code + "!"; + } + } + + ///×Ö·û´® ת»» + public static StringBuffer SBEString30(byte[] b, int pos) { + StringBuffer sbu = new StringBuffer(); + sbu.append((char) b[pos]); + sbu.append((char) b[pos + 1]); + sbu.append((char) b[pos + 2]); + sbu.append((char) b[pos + 3]); + sbu.append((char) b[pos + 4]); + sbu.append((char) b[pos + 5]); + sbu.append((char) b[pos + 6]); + sbu.append((char) b[pos + 7]); + sbu.append((char) b[pos + 8]); + sbu.append((char) b[pos + 9]); + sbu.append((char) b[pos + 10]); + sbu.append((char) b[pos + 11]); + sbu.append((char) b[pos + 12]); + sbu.append((char) b[pos + 13]); + sbu.append((char) b[pos + 14]); + sbu.append((char) b[pos + 15]); + sbu.append((char) b[pos + 16]); + sbu.append((char) b[pos + 17]); + sbu.append((char) b[pos + 18]); + sbu.append((char) b[pos + 19]); + sbu.append((char) b[pos + 20]); + + + + return sbu; + } + +} \ No newline at end of file diff --git a/src/org/libnodave/PDU.java b/src/org/libnodave/PDU.java new file mode 100644 index 0000000..0a689e3 --- /dev/null +++ b/src/org/libnodave/PDU.java @@ -0,0 +1,520 @@ +/* + Part of Libnodave, a free communication libray for Siemens S7 300/400 via + the MPI adapter 6ES7 972-0CA22-0XAC + or MPI adapter 6ES7 972-0CA33-0XAC + or MPI adapter 6ES7 972-0CA11-0XAC. + + (C) Thomas Hergenhahn (thomas.hergenhahn@web.de) 2002. + + Libnodave is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + Libnodave is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +package org.libnodave; +public class PDU { + /* + typedef struct { + uc P; // allways 0x32 + uc type; // a type? type 2 and 3 headers are two bytes longer. + uc a,b; // currently unknown + us number; // Number, can be used to identify answers corresponding to requests + us plen; // length of parameters which follow this header + us dlen; // length of data which follows the parameters + uc x[2]; // only present in type 2 and 3 headers. This may contain error information. + } PDUHeader; + */ + /** + * return the number of the PDU + */ + public int getNumber() { + return Nodave.USBEWord(mem, header + 4); + } + /** + * set the number of the PDU + */ + public void setNumber(int n) { + Nodave.setUSBEWord(mem, header + 4, n); + } + /** + * return the function code of the PDU + */ + public int getFunc() { + return Nodave.USByte(mem, param + 0); + } + /** + * known function codes + */ + public final static byte FUNC_READ = 4; + public final static byte FUNC_WRITE = 5; + + int header; // the position of the header; + public int param; // ²ÎÊýλÖÃ; + byte[] mem;//±¨ÎÄÊý×é + int hlen;//Õû¸ö±¨Îij¤¶È ¼õÈ¥ £¨±¨ÎÄÍ·+²ÎÊý³¤¶È£© µÄ½á¹ûÖµ + public int plen;//²ÎÊý³¤¶È + int dlen;//ÓÃÀ´¶¨ÒåÆäËû³¤¶ÈÖµ + public int udlen;//DB¿éÊý¾Ý³¤¶È + public int data;//±¨ÎÄʵ¼Ê³¤¶È + public int udata;//¶ÁDB¿éÊý¾ÝλÖà + /** + * set up the PDU information + */ + public PDU(byte[] mem, int pos) { + this.mem = mem; + this.header = pos; + } + + public int addVarToReadRequest(int area, int DBnum, int start, int len) { + byte[] pa = { 0x12, 0x0a, 0x10, 0x02, 0x00, 0x1A, + // insert length in bytes here + 0x00, 0x0B, // insert DB number here + (byte) 0x84, // change this to real area code + 0x00, 0x00, (byte) 0xC0 // insert start address in bits + }; + + if ((area == Nodave.ANALOGINPUTS200) + || (area == Nodave.ANALOGOUTPUTS200)) { + pa[3] = 4; + start *= 8; /* bits */ + } else if ( + (area == Nodave.TIMER) + || (area == Nodave.COUNTER) + || (area == Nodave.TIMER200) + || (area == Nodave.COUNTER200)) { + pa[3] = (byte) area; + } else { + start *= 8; /* bits */ + } + + Nodave.setUSBEWord(pa, 4, len); + Nodave.setUSBEWord(pa, 6, DBnum); + Nodave.setUSBELong(pa, 8, start); + Nodave.setUSByte(pa, 8, area); + + mem[param + 1]++; + System.arraycopy(pa, 0, mem, param + plen, pa.length); + plen += pa.length; + Nodave.setUSBEWord(mem, header + 6, plen); + /** + * TODO calc length of result. Do not add variable if it would exceed max. result length. + */ + return 0; + } + + public int addBitVarToReadRequest( + int area, + int DBnum, + int start, + int len) { + byte pa[] = { 0x12, 0x0a, 0x10, 0x01, /* single bits */ + 0x00, 0x1A, /* insert length in bytes here */ + 0x00, 0x0B, /* insert DB number here */ + (byte) 0x84, /* change this to real area code */ + 0x00, 0x00, (byte) 0xC0 /* insert start address in bits */ + }; + Nodave.setUSBEWord(pa, 4, len); + Nodave.setUSBEWord(pa, 6, DBnum); + Nodave.setUSBELong(pa, 8, start); + Nodave.setUSByte(pa, 8, area); + + mem[param + 1]++; + System.arraycopy(pa, 0, mem, param + plen, pa.length); + plen += pa.length; + Nodave.setUSBEWord(mem, header + 6, plen); + return 0; + + } + + /** + * prepare a read request with no item. + */ + public void prepareReadRequest() { + byte pa[] = new byte[2]; + pa[0] = PDU.FUNC_READ; + pa[1] = (byte) 0x00; + initHeader(1); + addParam(pa); + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) { + dump(); + } + } + + /** + * prepare a write request with no item. + */ + public void prepareWriteRequest() { + byte pa[] = new byte[2]; + pa[0] = PDU.FUNC_WRITE; + pa[1] = (byte) 0x00; + initHeader(1); + addParam(pa); + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) { + dump(); + } + } + + /** + * construct a write request for a single item in PLC memory. + */ +/* + void constructWriteRequest( + int area, + int DBnum, + int start, + int len, + byte[] buffer) { + byte pa[] = new byte[14]; + byte da[] = { 0, 4, 0, 0 }; + pa[0] = PDU.FUNC_WRITE; + pa[1] = (byte) 0x01; + pa[2] = (byte) 0x12; + pa[3] = (byte) 0x0a; + pa[4] = (byte) 0x10; + pa[5] = (byte) 0x02; + + Nodave.setUSBEWord(pa, 6, len); + Nodave.setUSBEWord(pa, 8, DBnum); + Nodave.setUSBELong(pa, 10, 8 * start); // the bit address + Nodave.setUSByte(pa, 10, area); + initHeader(1); + addParam(pa); + addData(da); + addValue(buffer); + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) { + dump(); + } + } +*/ + /** + * display information about a PDU + */ + public void dump() { + Nodave.dump("PDU header ", mem, header, hlen); + System.out.println("plen: " + plen + " dlen: " + dlen); + Nodave.dump("Parameter", mem, param, plen); + if (dlen > 0) + Nodave.dump("Data ", mem, data, dlen); + if (udlen > 0) + Nodave.dump("result Data ", mem, udata, udlen); + } + /** + * reserve space for the header of a new PDU + */ + public void initHeader(int type) { + if (type == 2 || type == 3) + hlen = 12; + else + hlen = 10; + for (int i = 0; i < hlen; i++) { + mem[header + i] = 0; + } + param = header + hlen; + mem[header] = (byte) 0x32; + mem[header + 1] = (byte) type; + dlen = 0; + plen = 0; + udlen = 0; + data = 0; + udata = 0; + } + + public void addParam(byte[] pa) { + plen = pa.length; + System.arraycopy(pa, 0, mem, param, plen); + Nodave.setUSBEWord(mem, header + 6, plen);//¶¨Òå×Ö·ûÊý×émemÖеĵÚheader+6¼°header+7 Õâ¸öÓÃÀ´´æ·ÅplenµÄ³¤¶ÈÖµ + // mem[header + 6] = (byte) (pa.length / 256); + // mem[header + 7] = (byte) (pa.length % 256); + data = param + plen; + dlen = 0; + } + /** + Add data after parameters, set dlen as needed. + Needs valid header and parameters + */ + void addData(byte[] newData) { + int appPos = data + dlen; //append to this position + dlen += newData.length; + System.arraycopy(newData, 0, mem, appPos, newData.length); + Nodave.setUSBEWord(mem, header + 8, dlen); + } + /** + Add len bytes of len after parameters from a maybe longer block of bytes. + Set dlen as needed. + Needs valid header and parameters + */ + public void addData(byte[] newData, int len) { + int appPos = data + dlen; //append to this position + dlen += len; + System.arraycopy(newData, 0, mem, appPos, len); + Nodave.setUSBEWord(mem, header + 8, dlen); + } + /** + Add values after value header in data, adjust dlen and data count. + Needs valid header,parameters,data,dlen + */ + void addValue(byte[] values) { + int valCount = 0x100 * mem[data + 2] + mem[data + 3]; + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) + System.out.println("valCount: " + valCount); + if (mem[data + 1] == 4) { // bit data, length is in bits + valCount += 8 * values.length; + } else if (mem[data + 1] == 9) { // byte data, length is in bytes + valCount += values.length; + } else { + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) + System.out.println( + "unknown data type/length: " + mem[data + 1]); + } + if (udata == 0) + udata = data + 4; + udlen += values.length; + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) + System.out.println("valCount: " + valCount); + Nodave.setUSBEWord(mem, data + 2, valCount); + addData(values); + } + + int error; + + public int getError() { + return error; + } + /** + Setup a PDU instance to reflect the structure of data present in + the memory area given to initHeader. + Needs valid header. + */ + + public int setupReceivedPDU() { + int res = Nodave.RESULT_CANNOT_EVALUATE_PDU; // just assume the worst + if (mem[header + 1] == 2 || mem[header + 1] == 3) { + hlen = 12; + res = Nodave.USBEWord(mem, header + 10); + } else { + error = 0; + hlen = 10; + res = 0; + } + param = header + hlen; + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) + Nodave.dump("PDU header", mem, header, hlen); + plen = Nodave.USBEWord(mem, header + 6); + data = param + plen; + dlen = Nodave.USBEWord(mem, header + 8); + udlen = 0; + udata = 0; + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) + dump(); + return res; + } + + /* + + */ + int testResultData() { + int res = Nodave.RESULT_CANNOT_EVALUATE_PDU; // just assume the worst + if ((mem[data] == (byte)255) && (dlen > 4)) { + res = Nodave.RESULT_OK; + udata = data + 4; + // udlen=data[2]*0x100+data[3]; + udlen = Nodave.USBEWord(mem, data + 2); + if (mem[data + 1] == 4) { + udlen >>= 3; /* len is in bits, adjust */ + } else if (mem[data + 1] == 9) { + /* len is already in bytes, ok */ + } else if (mem[data + 1] == 3) { + /* len is in bits, but there is a byte per result bit, ok */ + } else { + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) + System.out.println( + "fixme: what to do with data type " + mem[data + 1]); + res = Nodave.RESULT_UNKNOWN_DATA_UNIT_SIZE; + } + } else { + res = mem[data]; + } + return res; + } + + int testReadResult() { + if (mem[param] != FUNC_READ) + return Nodave.RESULT_UNEXPECTED_FUNC; + return testResultData(); + } + + public int testPGReadResult() { + if (mem[param] != 0) + return Nodave.RESULT_UNEXPECTED_FUNC; + return testResultData(); + } + + int testWriteResult() { + int res = Nodave.RESULT_CANNOT_EVALUATE_PDU; + if (mem[param] != FUNC_WRITE) + return Nodave.RESULT_UNEXPECTED_FUNC; + if ((mem[data] == 255)) { + res = Nodave.RESULT_OK; + } else + res = mem[data]; + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) { + dump(); + } + return res; + } + + /* + add data in user data. Add a user data header, if not yet present. + */ + public void addUserData(byte[] da) { + byte udh[] = {(byte) 0xff, 9, 0, 0 }; + if (dlen == 0) { + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) + System.out.println("adding user data header."); + addData(udh); + } + addValue(da); + }; + + public void initReadRequest() { + byte pa[] = new byte[2]; + pa[0] = PDU.FUNC_READ; + pa[1] = (byte) 0x00; + initHeader(1); + addParam(pa); + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) { + dump(); + } + } + + public void addVarToWriteRequest( + int area, + int DBnum, + int start, + int byteCount, + byte[] buffer) { + byte da[] = { 0, 4, 0, 0, }; + byte pa[] = { 0x12, 0x0a, 0x10, 0x02, + /* unit (for count?, for consistency?) byte */ + 0, 0, /* length in bytes */ + 0, 0, /* DB number */ + 0, /* area code */ + 0, 0, 0 /* start address in bits */ + }; + if ((area == Nodave.TIMER) + || (area == Nodave.COUNTER) + || (area == Nodave.TIMER200) + || (area == Nodave.COUNTER200)) { + pa[3] = (byte) area; + pa[4] = (byte) (((byteCount + 1) / 2) / 0x100); + pa[5] = (byte) (((byteCount + 1) / 2) & 0xff); + } else if ( + (area == Nodave.ANALOGINPUTS200) + || (area == Nodave.ANALOGOUTPUTS200)) { + pa[3] = 4; + pa[4] = (byte) (((byteCount + 1) / 2) / 0x100); + pa[5] = (byte) (((byteCount + 1) / 2) & 0xff); + } else { + pa[4] = (byte) (byteCount / 0x100); + pa[5] = (byte) (byteCount & 0xff); + } + pa[6] = (byte) (DBnum / 256); + pa[7] = (byte) (DBnum & 0xff); + pa[8] = (byte) (area); + start *= 8; /* number of bits */ + pa[11] = (byte) (start & 0xff); + pa[10] = (byte) ((start / 0x100) & 0xff); + pa[9] = (byte) (start / 0x10000); + if ((dlen % 2) != 0) { + addData(da, 1); + } + mem[param + 1]++; + if (dlen > 0) { + byte[] saveData = new byte[dlen]; + System.arraycopy(mem, data, saveData, 0, dlen); + System.arraycopy(saveData, 0, mem, data + pa.length, dlen); + } + System.arraycopy(pa, 0, mem, param + plen, pa.length); + plen += pa.length; + Nodave.setUSBEWord(mem, header + 6, plen); + data = param + plen; + addData(da); + addValue(buffer); + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) { + dump(); + } + } + + public void addBitVarToWriteRequest( + int area, + int DBnum, + int start, + int byteCount, + byte[] buffer) { + byte da[] = { 0, 3, 0, 0, }; + byte pa[] = { 0x12, 0x0a, 0x10, 0x01, /* single bit */ + 0, 0, /* insert length in bytes here */ + 0, 0, /* insert DB number here */ + 0, /* change this to real area code */ + 0, 0, 0 /* insert start address in bits */ + }; + if ((area == Nodave.TIMER) + || (area == Nodave.COUNTER) + || (area == Nodave.TIMER200) + || (area == Nodave.COUNTER200)) { + pa[3] = (byte) area; + pa[4] = (byte) (((byteCount + 1) / 2) / 0x100); + pa[5] = (byte) (((byteCount + 1) / 2) & 0xff); + } else if ( + (area == Nodave.ANALOGINPUTS200) + || (area == Nodave.ANALOGOUTPUTS200)) { + pa[3] = 4; + pa[4] = (byte) (((byteCount + 1) / 2) / 0x100); + pa[5] = (byte) (((byteCount + 1) / 2) & 0xff); + } else { + pa[4] = (byte) (byteCount / 0x100); + pa[5] = (byte) (byteCount & 0xff); + } + pa[6] = (byte) (DBnum / 256); + pa[7] = (byte) (DBnum & 0xff); + pa[8] = (byte) area; + pa[11] = (byte) (start & 0xff); + pa[10] = (byte) ((start / 0x100) & 0xff); + pa[9] = (byte) (start / 0x10000); + + if ((dlen % 2) != 0) { + addData(da, 1); + } + + mem[param + 1]++; + if (dlen > 0) { + byte[] saveData = new byte[dlen]; + System.arraycopy(mem, data, saveData, 0, dlen); + System.arraycopy(saveData, 0, mem, data + pa.length, dlen); + } + System.arraycopy(pa, 0, mem, param + plen, pa.length); + plen += pa.length; + Nodave.setUSBEWord(mem, header + 6, plen); + data = param + plen; + + addData(da); + addValue(buffer); + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) { + dump(); + } + + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) { + dump(); + } + } + +} diff --git a/src/org/libnodave/PLCinterface.java b/src/org/libnodave/PLCinterface.java new file mode 100644 index 0000000..3f5446c --- /dev/null +++ b/src/org/libnodave/PLCinterface.java @@ -0,0 +1,108 @@ +package org.libnodave; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class PLCinterface { + int localMPI; // the adapter's MPI address + String name; + int timeout; // Timeout in milliseconds used in transort. + int protocol; // The kind of transport used on this interface. + OutputStream out; + InputStream in; + public boolean isConnect=false; + int wp, rp; + + public PLCinterface( + OutputStream out, + InputStream in, + String name, + int localMPI, + int protocol) { + init(out, in, name, localMPI, protocol); + } + + public PLCinterface() { + } + + public void init( + OutputStream oStream, + InputStream iStream, + String name, + int localMPI, + int protocol) { + this.out = oStream; + this.in = iStream; + this.name = name; + this.localMPI = localMPI; + this.protocol = protocol; + timeout=50000;//timeout/100ºÁÃë + switch (protocol) { + case Nodave.PROTOCOL_ISOTCP:timeout=50000; break; + case Nodave.PROTOCOL_ISOTCP243:timeout=50000; break; + } + } + + public void write(byte[] b, int start, int len) { + if ((Nodave.Debug & Nodave.DEBUG_IFACE) != 0) + Nodave.dump("Interface.write", b, start, len); + try { + out.write(b, start, len); + } catch (IOException e) { + isConnect = false; + System.err.println("Interface.write: " + e); + } + } + public int read(byte[] b, int start, int len) { + int res; + int ilen = len; + if ((Nodave.Debug & Nodave.DEBUG_IFACE) != 0) + System.out.println("Interface.read"); + try { + int retry = 0; + while ((in.available() <= 0) && (retry < 50)) { + try { + if(retry>0)Thread.sleep(timeout / 2000); + retry++; + if ((Nodave.Debug & Nodave.DEBUG_IFACE) != 0) + System.out.println("Interface.read delayed"); + } catch (InterruptedException e) { + System.out.println(e); + } + } + res=0; + if(len<0){//YAO 2017-09-23 + len = 256+len; + } + while ((in.available() > 0) && (len > 0)) { + res = in.read(b, start, len); + start+=res; + len-=res; + } + if ((Nodave.Debug & Nodave.DEBUG_IFACE) != 0) + System.out.println("got "+res+"bytes"); + if ((Nodave.Debug & Nodave.DEBUG_IFACE) != 0) { + Nodave.dump("Interface.read", b, start, ilen); + } + return res; + } catch (IOException e) { + isConnect = false; + System.out.println(e); + return 0; + } + } + public int initAdapter() { + return 0; + } + public int disconnectAdapter() { + return 0; + } + public void finalize() throws Throwable{ + //System.out.println("this is finalize"); + disconnectAdapter(); + } + public static void main(String arg[]){ + Nodave.Debug = 0x00;//²»µ÷ʽ + System.out.println((Nodave.Debug & Nodave.DEBUG_IFACE) != 0); + } +} diff --git a/src/org/libnodave/Result.java b/src/org/libnodave/Result.java new file mode 100644 index 0000000..0bafc0f --- /dev/null +++ b/src/org/libnodave/Result.java @@ -0,0 +1,35 @@ +/* + Part of Libnodave, a free communication libray for Siemens S7 300/400 via + the MPI adapter 6ES7 972-0CA22-0XAC + or MPI adapter 6ES7 972-0CA33-0XAC + or MPI adapter 6ES7 972-0CA11-0XAC. + + (C) Thomas Hergenhahn (thomas.hergenhahn@web.de) 2002. + + Libnodave is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + Libnodave is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +package org.libnodave; + +/** + * @author Thomas Hergenhahn + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class Result { +public int error; +public int length; +public int bufferStart; +} diff --git a/src/org/libnodave/ResultSet.java b/src/org/libnodave/ResultSet.java new file mode 100644 index 0000000..8495858 --- /dev/null +++ b/src/org/libnodave/ResultSet.java @@ -0,0 +1,47 @@ +/* + Part of Libnodave, a free communication libray for Siemens S7 300/400 via + the MPI adapter 6ES7 972-0CA22-0XAC + or MPI adapter 6ES7 972-0CA33-0XAC + or MPI adapter 6ES7 972-0CA11-0XAC. + + (C) Thomas Hergenhahn (thomas.hergenhahn@web.de) 2002. + + Libnodave is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + Libnodave is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +package org.libnodave; + +/** + * @author Thomas Hergenhahn + * + */ +public class ResultSet { + private int errorState, numResults; + public Result[] results; + public void setErrorState(int error) { + errorState = error; + } + + public int getErrorState() { + return errorState; + }; + + public void setNumResults(int nr) { + numResults = nr; + } + + public int getNumResults() { + return numResults; + }; +} diff --git a/src/org/libnodave/S7Connection.java b/src/org/libnodave/S7Connection.java new file mode 100644 index 0000000..c310d6d --- /dev/null +++ b/src/org/libnodave/S7Connection.java @@ -0,0 +1,590 @@ +/* + Part of Libnodave, a free communication libray for Siemens S7 300/400 via + the MPI adapter 6ES7 972-0CA22-0XAC + or MPI adapter 6ES7 972-0CA33-0XAC + or MPI adapter 6ES7 972-0CA11-0XAC. + + (C) Thomas Hergenhahn (thomas.hergenhahn@web.de) 2002. + + Libnodave is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + Libnodave is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +package org.libnodave; + +/** + * + * @author Thomas Hergenhahn + * + * This class comprises the variables and methods common to connections to an S7 PLC + * regardless of the type of transport. + */ +public abstract class S7Connection { + PLCinterface iface; // pointer to used interface + int answLen; // length of last message + PDU rcvdPDU; + public byte[] msgIn; + public byte[] msgOut; + /** + * position in result data, incremented when variables are extracted without position + */ + int dataPointer; + /** + * absolut begin of result data + */ + int udata; + public int packetNumber = 0; // packetNumber in transport layer + public byte messageNumber = 0; + + static int tmo_normal = 150; + public int PDUstartIn; + public int PDUstartOut; + public Semaphore semaphore; + public int maxPDUlength;//ºÏ×÷»ï°éÌṩµÄPDUµÄ³¤¶È + + private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5','6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + private static final char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5','6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + + public S7Connection(PLCinterface ifa) { + iface = ifa; + msgIn = new byte[Nodave.MAX_RAW_LEN]; + msgOut = new byte[Nodave.MAX_RAW_LEN]; + PDUstartIn = 0; + PDUstartOut = 0; + semaphore = new Semaphore(1); + } + public int getUdata(){ + return udata; + } + public byte[] getMsgIn(){ + return msgIn; + } + /** + * get a float value from the current position in result bytes + */ + public float getFloat() { + dataPointer += 4; + return Nodave.BEFloat(msgIn, dataPointer - 4); + } + /* + * The following methods are here to give Siemens users their usual data types: + */ + /** + * get a float value from the specified position in result bytes + */ + public float getFloat(int pos) { + // System.out.println("getFloat pos " + pos); + return Nodave.BEFloat(msgIn, udata + pos); + } + /** + * get an unsigned 32bit value from the specified position in result bytes + */ + public long getDWORD(int pos) { + // System.out.println("getDWORD pos " + pos); + return Nodave.USBELong(msgIn, udata + pos); + } + /** + * get an unsigned 32bit value from the current position in result bytes + */ + public long getU32() { + dataPointer += 4; + return Nodave.USBELong(msgIn, dataPointer - 4); + } + /** + * get an signed 32bit value from the current position in result bytes + */ + public long getDINT() { + dataPointer += 4; + return Nodave.SBELong(msgIn, dataPointer - 4); + } + /** + * get an signed 32bit value from the specified position in result bytes + */ + public long getDINT(int pos) { + return Nodave.SBELong(msgIn, udata + pos); + } + /** + * get an unsigned 16bit value from the specified position in result bytes + */ + public int getWORD(int pos) { + return Nodave.USBEWord(msgIn, udata + pos); + } + /** + * get an unsigned 16bit value from the current position in result bytes + */ + public int getWORD() { + dataPointer += 2; + return Nodave.USBEWord(msgIn, dataPointer - 2); + } + + public int getINT(int pos) { + return Nodave.SBEWord(msgIn, udata + pos); + } + + public int getINT() { + dataPointer += 2; + return Nodave.SBEWord(msgIn, dataPointer - 2); + } + + public int getBYTE(int pos) { + return Nodave.SByte(msgIn, udata + pos); + } + + public int getBYTE() { + dataPointer += 1; + return Nodave.SByte(msgIn, dataPointer - 1); + } + public int getCHAR(int pos) { + return Nodave.SByte(msgIn, udata + pos); + } + + public int getCHAR() { + dataPointer += 1; + return Nodave.SByte(msgIn, dataPointer - 1); + } + + public long getUS32(int pos) { + return Nodave.USBELong(msgIn, udata + pos); + } + + public long getS32(int pos) { + return Nodave.SBELong(msgIn, udata + pos); + } + + public int getUS16(int pos) { + return Nodave.USBEWord(msgIn, udata + pos); + } + + public int getS16(int pos) { + return Nodave.SBEWord(msgIn, udata + pos); + } + + public int getUS8(int pos) { + return Nodave.USByte(msgIn, udata + pos); + } + public int getS8(int pos) { + return Nodave.SByte(msgIn, udata + pos); + } + /** + * ½«×Ö½ÚÊý×éת»»ÎªÊ®Áù½øÖÆ×Ö·ûÊý×é + * @param data byte[] + * @return Ê®Áù½øÖÆchar[] + */ + public char[] encodeHex(byte[] data) { + return encodeHex(data, true); + } + /** + * ½«×Ö½ÚÊý×éת»»ÎªÊ®Áù½øÖÆ×Ö·ûÊý×é + * @param data byte[] + * @param toLowerCase true ´«»»³ÉСд¸ñʽ £¬ false ´«»»³É´óд¸ñʽ + * @return Ê®Áù½øÖÆchar[] + */ + public char[] encodeHex(byte[] data, boolean toLowerCase) { + return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER); + } + /** + * ½«×Ö½ÚÊý×éת»»ÎªÊ®Áù½øÖÆ×Ö·ûÊý×é + * @param data byte[] + * @param toDigits ÓÃÓÚ¿ØÖÆÊä³öµÄchar[] + * @return Ê®Áù½øÖÆchar[] + */ + protected char[] encodeHex(byte[] data, char[] toDigits) { + int l = data.length; + char[] out = new char[l << 1]; + for (int i = 0, j = 0; i < l; i++) { + out[j++] = toDigits[(0xF0 & data[i]) >>> 4]; + out[j++] = toDigits[0x0F & data[i]]; + } + return out; + } + /** + * ½«×Ö½ÚÊý×éת»»ÎªÊ®Áù½øÖÆ×Ö·û´® + * @param data byte[] + * @return Ê®Áù½øÖÆString + */ + public String encodeHexStr(byte[] data) { + return encodeHexStr(data, true); + } + /** + * ½«×Ö½ÚÊý×éת»»ÎªÊ®Áù½øÖÆ×Ö·û´® + * @param data byte[] + * @param toLowerCase true ´«»»³ÉСд¸ñʽ £¬ false ´«»»³É´óд¸ñʽ + * @return Ê®Áù½øÖÆString + */ + public String encodeHexStr(byte[] data, boolean toLowerCase) { + return encodeHexStr(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER); + } + /** + * ½«×Ö½ÚÊý×éת»»ÎªÊ®Áù½øÖÆ×Ö·û´® + * @param data byte[] + * @param toDigits ÓÃÓÚ¿ØÖÆÊä³öµÄchar[] + * @return Ê®Áù½øÖÆString + */ + protected String encodeHexStr(byte[] data, char[] toDigits) { + return new String(encodeHex(data, toDigits)); + } + /** + * ½«Ê®Áù½øÖÆ×Ö·ûÊý×éת»»Îª×Ö½ÚÊý×é + * @param data Ê®Áù½øÖÆchar[] + * @return byte[] + * @throws RuntimeException Èç¹ûÔ´Ê®Áù½øÖÆ×Ö·ûÊý×éÊÇÒ»¸öÆæ¹ÖµÄ³¤¶È£¬½«Å׳öÔËÐÐʱÒì³£ + */ + public byte[] decodeHex(char[] data) { + int len = data.length; + if ((len & 0x01) != 0) { + throw new RuntimeException("Odd number of characters."); + } + byte[] out = new byte[len >> 1]; + for (int i = 0, j = 0; j < len; i++) { + int f = toDigit(data[j], j) << 4; + j++; + f = f | toDigit(data[j], j); + j++; + out[i] = (byte) (f & 0xFF); + } + return out; + } + /** + * ½«Ê®Áù½øÖÆ×Ö·ûת»»³ÉÒ»¸öÕûÊý + * @param chÊ®Áù½øÖÆchar + * @param indexÊ®Áù½øÖÆ×Ö·ûÔÚ×Ö·ûÊý×éÖеÄλÖà + * @return Ò»¸öÕûÊý + * @throws RuntimeException µ±ch²»ÊÇÒ»¸öºÏ·¨µÄÊ®Áù½øÖÆ×Ö·ûʱ£¬Å׳öÔËÐÐʱÒì³£ + */ + protected int toDigit(char ch, int index) { + int digit = Character.digit(ch, 16); + if (digit == -1) { + throw new RuntimeException("Illegal hexadecimal character " + ch + + " at index " + index); + } + return digit; + } + /** + * ½«byteת»»ÎªÒ»¸ö³¤¶ÈΪ8µÄbyteÊý×飬Êý×éÿ¸öÖµ´ú±íbit + * @param b + * @return + */ + public byte[] getBooleanArray_high_low(byte b) { + byte[] array = new byte[8]; + for (int i = 7; i >= 0; i--) { + array[i] = (byte) (b & 1); + b = (byte) (b >> 1); + } + return array; + } + public byte[] getBooleanArray_low_high(byte b) { + byte[] array = new byte[8]; + for (int i = 0; i <=7 ; i++) { + array[i] = (byte) (b & 1); + b = (byte) (b >> 1); + } + return array; + } + /** + * °ÑbyteתΪ×Ö·û´®µÄbit + * @param b + * @return + */ + public String byteToBit(byte b) { + return "" + (byte) ((b >> 7) & 0x1) + (byte) ((b >> 6) & 0x1) + + (byte) ((b >> 5) & 0x1) + (byte) ((b >> 4) & 0x1) + + (byte) ((b >> 3) & 0x1) + (byte) ((b >> 2) & 0x1) + + (byte) ((b >> 1) & 0x1) + (byte) ((b >> 0) & 0x1); + + } + public String bytesToHexString(byte[] src) { + StringBuilder stringBuilder = new StringBuilder(""); + if (src == null || src.length <= 0) { + return null; + } + for (int i = 0; i < src.length; i++) { + int v = src[i] & 0xFF; + String hv = Integer.toHexString(v); + if (hv.length() < 2) { + stringBuilder.append(0); + } + stringBuilder.append(hv); + } + return stringBuilder.toString(); + } + abstract public int exchange(PDU p1); + //¶ÁÈ¡³¤¶Èlen ×ֻÄÜ256¸ö×Ö½Ú + public int readBytes( + int area, + int DBnum, + int start, + int len, + byte[] buffer) { + int res = 0; + semaphore.enter(); + PDU p1 = new PDU(msgOut, PDUstartOut); + p1.initReadRequest(); + p1.addVarToReadRequest(area, DBnum, start, len); + + res = exchange(p1); + if (res != Nodave.RESULT_OK) { + semaphore.leave(); + return res; + } + PDU p2 = new PDU(msgIn, PDUstartIn); + res = p2.setupReceivedPDU(); + if ((Nodave.Debug & Nodave.DEBUG_CONN) != 0) + System.out.println( + "setupReceivedPDU() returned: " + res + Nodave.strerror(res)); + if (res != Nodave.RESULT_OK) { + semaphore.leave(); + return res; + } + + res = p2.testReadResult(); + if ((Nodave.Debug & Nodave.DEBUG_CONN) != 0) + System.out.println( + "testReadResult() returned: " + res + Nodave.strerror(res)); + if (res != Nodave.RESULT_OK) { + semaphore.leave(); + return res; + } + if (p2.udlen == 0) { + semaphore.leave(); + return Nodave.RESULT_CPU_RETURNED_NO_DATA; + } + if (buffer != null) + System.arraycopy(p2.mem, p2.udata, buffer, 0, p2.udlen); + + dataPointer = p2.udata; + udata = p2.udata; + answLen = p2.udlen; + semaphore.leave(); + return res; + } + + public PDU prepareReadRequest() { + int errorState = 0; + semaphore.enter(); + PDU p1 = new PDU(msgOut, PDUstartOut); + p1.prepareReadRequest(); + return p1; + } + + /* + Write len bytes to PLC memory area "area", data block DBnum. + */ + public int writeBytes( + int area, + int DBnum, + int start, + int len, + byte[] buffer) { + int errorState = 0; + semaphore.enter(); + PDU p1 = new PDU(msgOut, PDUstartOut); + p1.prepareWriteRequest(); + p1.addVarToWriteRequest(area, DBnum, start, len, buffer); + + errorState = exchange(p1); + + if (errorState == 0) { + PDU p2 = new PDU(msgIn, PDUstartIn); + p2.setupReceivedPDU(); + + if (p2.mem[p2.param + 0] == PDU.FUNC_WRITE) { + if (p2.mem[p2.data + 0] == (byte) 0xFF) { + if ((Nodave.Debug & Nodave.DEBUG_CONN) != 0) + System.out.println("writeBytes: success"); + semaphore.leave(); + return 0; + } + } else { + errorState |= 4096; + } + } + semaphore.leave(); + return errorState; + } + + /* + public int readByteBlock(int area, int areaNumber, int start, int len) { + return readBytes(area, areaNumber, start, len, null); + } + */ + public int disconnectPLC() { + return 0; + } + public int connectPLC() { + return 0; + } + + public class Semaphore { + private int value; + + public Semaphore(int value) { + this.value = value; + } + + public synchronized void enter() { + --value; + if (value < 0) { + try { + wait(); + } catch (Exception e) { + } + } + } + + public synchronized void leave() { + ++value; + notify(); + } + } + /* + public void sendYOURTURN() { + } + */ + public int getResponse() { + return 0; + } + + public int getPPIresponse() { + return 0; + } + + public int sendMsg(PDU p) { + return 0; + } + public void sendRequestData(int alt) { + } + + // int numResults; + /* + class Result { + int error; + byte[] data; + } + */ + /* + Read a predefined set of values from the PLC. + Return ok or an error state + If a buffer pointer is provided, data will be copied into this buffer. + If it's NULL you can get your data from the resultPointer in daveConnection long + as you do not send further requests. + */ + public ResultSet execReadRequest(PDU p) { + PDU p2; + int errorState; + errorState = exchange(p); + + p2 = new PDU(msgIn, PDUstartIn); + p2.setupReceivedPDU(); + /* + if (p2.udlen == 0) { + dataPointer = 0; + answLen = 0; + return Nodave.RESULT_CPU_RETURNED_NO_DATA; + } + */ + ResultSet rs = new ResultSet(); + if (p2.mem[p2.param + 0] == PDU.FUNC_READ) { + int numResults = p2.mem[p2.param + 1]; + // System.out.println("Results " + numResults); + rs.results = new Result[numResults]; + int pos = p2.data; + for (int i = 0; i < numResults; i++) { + Result r = new Result(); + r.error = Nodave.USByte(p2.mem, pos); + if (r.error == 255) { + + int type = Nodave.USByte(p2.mem, pos + 1); + int len = Nodave.USBEWord(p2.mem, pos + 2); + r.error = 0; + // System.out.println("Raw length " + len); + if (type == 4) + len /= 8; + else if (type == 3); //length is ok + + // System.out.println("Byte length " + len); + // r.data = new byte[len]; + + // System.arraycopy(p2.mem, pos + 4, r.data, 0, len); + // Nodave.dump("Result " + i + ":", r.data, 0, len); + r.bufferStart = pos + 4; + pos += len; + if ((len % 2) == 1) + pos++; + } else { + System.out.println("Error " + r.error); + } + pos += 4; + rs.results[i] = r; + } + numResults = p2.mem[p2.param + 1]; + rs.setNumResults(numResults); + dataPointer = p2.udata; + answLen = p2.udlen; + // } + } else { + errorState |= 2048; + } + semaphore.leave(); + rs.setErrorState(errorState); + return rs; + } + + public int useResult(ResultSet rs, int number) { + System.out.println( + "rs.getNumResults: " + rs.getNumResults() + " number: " + number); + if (rs.getNumResults() > number) { + dataPointer = rs.results[number].bufferStart; + return 0; + // udata=rs.results[number].bufferStart; + } + return -33; + }; + + /* + build the PDU for a PDU length negotiation + */ + public int negPDUlengthRequest() { + int res; + PDU p = new PDU(msgOut, PDUstartOut); + byte pa[] = + {(byte) 0xF0, 0, 0x00, 0x01, 0x00, 0x01, 0x03, (byte) 0xC0, }; + p.initHeader(1); + p.addParam(pa); + if ((Nodave.Debug & Nodave.DEBUG_PDU) != 0) { + p.dump(); + } + res = exchange(p); + if (res != 0) + return res; + PDU p2 = new PDU(msgIn, PDUstartIn); + res = p2.setupReceivedPDU(); + if (res != 0) + return res; + maxPDUlength = Nodave.USBEWord(msgIn, p2.param + 6); + if ((Nodave.Debug & Nodave.DEBUG_CONNECT) != 0) { + System.out.println( + "*** Partner offered PDU length: " + maxPDUlength); + } + return res; + } + /* + build the PDU for a PDU length negotiation + */ + + public void finalize() throws Throwable { + //System.out.println("this is finalize S7Connection"); + disconnectPLC(); + iface.finalize(); + } + +} diff --git a/src/org/libnodave/TCPConnection.java b/src/org/libnodave/TCPConnection.java new file mode 100644 index 0000000..7e7cbbe --- /dev/null +++ b/src/org/libnodave/TCPConnection.java @@ -0,0 +1,108 @@ +/* + Part of Libnodave, a free communication libray for Siemens S7 300/400 via + the MPI adapter 6ES7 972-0CA22-0XAC + or MPI adapter 6ES7 972-0CA33-0XAC + or MPI adapter 6ES7 972-0CA11-0XAC. + + (C) Thomas Hergenhahn (thomas.hergenhahn@web.de) 2002. + + Libnodave is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + Libnodave is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +package org.libnodave; +public class TCPConnection extends S7Connection { + int rack; + int slot; + + public TCPConnection(PLCinterface ifa, int rack, int slot) { + super(ifa); + this.rack=rack; + this.slot=slot; + PDUstartIn = 7; + PDUstartOut = 7; + } + + protected int readISOPacket() { + int res = iface.read(msgIn, 0, 4); + if (res == 4) { + int len = 0x100 * msgIn[2] + msgIn[3]; + res += iface.read(msgIn, 4, len); + } else return 0; + return res; + } + protected int sendISOPacket(int size) { + size += 4; + msgOut[0] = (byte)0x03; + msgOut[1] = (byte)0x0; + msgOut[2] = (byte) (size / 0x100); + msgOut[3] = (byte) (size % 0x100); + iface.write(msgOut, 0, size); + return 0; + } + public static void main(String arg[]){ + System.out.println(0x100); + } + public int exchange(PDU p1) { + int res; + PDU p2; + if ((Nodave.Debug & Nodave.DEBUG_EXCHANGE) != 0) { + System.out.println(" enter TCP.Exchange"); + } + msgOut[4] = (byte)0x02; + msgOut[5] = (byte)0xf0; + msgOut[6] = (byte)0x80; + sendISOPacket(3 + p1.hlen + p1.plen + p1.dlen); + res = readISOPacket(); + return 0; + } + /** + * We have our own connectPLC(), but no disconnect() + * Open connection to a PLC. This assumes that dc is initialized by + * daveNewConnection and is not yet used. + * (or reused for the same PLC ?) + */ + public int connectPLC() { + int res; + byte[] b4 ={ + (byte)0x11, + (byte)0xE0, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x01, + (byte)0x00, + (byte)0xC1, + (byte)0x02, + (byte)0x01, + (byte)0x00, + (byte)0xC2, + (byte)0x02, + (byte)0x01, + (byte)0x02, + (byte)0xC0, + (byte)0x01, + (byte)0x09 }; + + if ((Nodave.Debug & Nodave.DEBUG_CONNECT) != 0) + System.out.println("daveConnectPLC() step 1. rack:"+rack+" slot:"+slot); + System.arraycopy(b4, 0, msgOut, 4, b4.length); + msgOut[17]=(byte)(rack+1); + msgOut[18]=(byte)slot; + sendISOPacket(b4.length); + readISOPacket(); + if ((Nodave.Debug & Nodave.DEBUG_CONNECT) != 0) + System.out.println("daveConnectPLC() step 1."); + return negPDUlengthRequest(); + } +} diff --git a/src/org/libnodave/tests/PlcTcpClient.java b/src/org/libnodave/tests/PlcTcpClient.java new file mode 100644 index 0000000..e37ba45 --- /dev/null +++ b/src/org/libnodave/tests/PlcTcpClient.java @@ -0,0 +1,83 @@ +package org.libnodave.tests; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.libnodave.Nodave; +import org.libnodave.PLCinterface; +import org.libnodave.TCPConnection; +public class PlcTcpClient { + int i, j; + long a, b, c; + float d, e, f; + byte buf1[]; + PLCinterface di; + TCPConnection dc; + Socket sock; + PlcTcpClient(String host) { + buf1 = new byte[Nodave.PartnerListSize]; + try { + sock = new Socket(host, 102); + } catch (IOException e) { + System.out.println(e); + } + } + void run() { + OutputStream oStream = null; + InputStream iStream = null; + byte[] by; + if (sock != null) { + try { + oStream = sock.getOutputStream(); + } catch (IOException e) { + } + try { + iStream = sock.getInputStream(); + } catch (IOException e) { + } + di = new PLCinterface( + oStream, + iStream, + "PLCName", + 0, + Nodave.PROTOCOL_ISOTCP); + dc = new TCPConnection(di, 0, slot); + int res = dc.connectPLC(); + if(di.isConnect){ + while(true){ + dc.readBytes(Nodave.DB, 102, 0, 50, null); + dc.getDINT(22); + System.out.println("111:"+dc.getDINT(22)); + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } else + System.out.println("Couldn't open connection"); + } + + static boolean doWrite = true; + static boolean doBenchmark = false; + static boolean doLentest = false; + static int useProtocol = Nodave.PROTOCOL_ISOTCP; + static int slot=1; + + public static void main(String[] args) { +// PlcTcpClient tp = new PlcTcpClient("192.168.8.102"); +// tp.run(); + Date t = new Date(); + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dqsj; + dqsj= "2019-10-19 22:01:48";//df.format(t); + long longstr1 = Long.valueOf(dqsj.replaceAll("[-\\s:]","")); + System.out.println(longstr1); + System.out.println(longstr1+4043); + System.out.println(dqsj); + } +} \ No newline at end of file diff --git a/src/org/libnodave/tests/TestISOTCP2.java b/src/org/libnodave/tests/TestISOTCP2.java new file mode 100644 index 0000000..3946e8b --- /dev/null +++ b/src/org/libnodave/tests/TestISOTCP2.java @@ -0,0 +1,269 @@ +/* + Test and demo program for Libnodave, a free communication libray for Siemens S7. + + ********************************************************************** + * WARNING: This and other test programs overwrite data in your PLC. * + * DO NOT use it on PLC's when anything is connected to their outputs.* + * This is alpha software. Use entirely on your own risk. * + ********************************************************************** + + (C) Thomas Hergenhahn (thomas.hergenhahn@web.de) 2002, 2004. + + This is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with Visual; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +package org.libnodave.tests; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.util.Date; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.libnodave.Nodave; +import org.libnodave.PLCinterface; +import org.libnodave.TCPConnection; +import org.s7.standard.ynuo.WriteDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface.groupPlcObj; + +import com.wms.dss.ats.customs.abb.utils.Tools; +import com.wms.dss.common.server.form.Logger; +//YAO-2017-09-06 ²âÊÔͨ¹ýÀà +public class TestISOTCP2 { + int i, j; + long a, b, c; + float d, e, f; + byte buf1[]; + String strIp=""; + int iPort = 102; + PLCinterface di; + TCPConnection dc; + Socket sock; + OutputStream oStream = null; + InputStream iStream = null; + protected byte btid = 1; //¶Ñ¶â»úºÅ + public Hashtable writePlcHs = null; + TestISOTCP2(String strIp,int iPort) { + buf1 = new byte[Nodave.PartnerListSize]; + this.strIp = strIp; + this.iPort = iPort; + } + public void setIsConnect(boolean bflag){ + if(di!=null){ + di.isConnect = bflag; + } + } + public boolean IsConnect(){ + if(di!=null){ + return di.isConnect; + }else{ + return false; + } + } + void ConnectServer(){ + try { + System.out.println(new Date()+"********¿ªÊ¼ÓëIP:"+strIp+" ¶Ë¿Ú:"+iPort+"½¨Á¢socketÁ¬½Ó¿ªÊ¼!************************************"); + sock = new Socket(strIp, iPort); + sock.setSoTimeout(6000); //ÉèÖó¬Ê±Ê±¼ä6Ãë + System.out.println(new Date()+"********¿ªÊ¼ÓëIP:"+strIp+" ¶Ë¿Ú:"+iPort+"½¨Á¢socketÁ¬½Ó³É¹¦!************************************"); + oStream = sock.getOutputStream(); + iStream = sock.getInputStream(); + System.out.println(new Date()+"********¿ªÊ¼ÓëIP:"+strIp+" ¶Ë¿Ú:"+iPort+"½¨Á¢-Êý¾ÝÁ÷-Á¬½Ó³É¹¦!************************************"); + di = new PLCinterface( + oStream, + iStream, + "PLCName", + 0, + Nodave.PROTOCOL_ISOTCP); + dc = new TCPConnection(di, 0, slot); + int res = dc.connectPLC(); + if (0 == res) { + setIsConnect(true); + System.out.println(new Date()+"½¨Á¢TCPConnectionÊý¾ÝÁ÷³É¹¦! "); + }else{ + System.out.println(new Date()+"½¨Á¢TCPConnectionÊý¾ÝÁ÷ʧ°Ü! "); + } + } catch (IOException ioex) { + System.out.println(new Date()+"Á¬½Óʧ°Ü "+ioex.getMessage()); + } catch (Exception ex) { + System.out.println(new Date()+"Á¬½ÓÒì³£ "+ex.getMessage()); + } + } + void closeServer(){ + try + { + setIsConnect(false); + if (iStream != null){ + System.out.println(new Date()+"ÊäÈëÁ÷¹Ø±Õ¿ªÊ¼ "); + iStream.close(); + iStream = null; + System.out.println(new Date()+"ÊäÈëÁ÷¹Ø±Õ½áÊø "); + } + }catch (IOException e){ + System.out.println(new Date()+"ÊäÈëÁ÷¹Ø±ÕÒì³£ "+e.getMessage()); + } + try + { + if (oStream != null) + { + System.out.println(new Date()+"Êä³öÁ÷¹Ø±Õ¿ªÊ¼ "); + oStream.close(); + oStream = null; + System.out.println(new Date()+"Êä³öÁ÷¹Ø±Õ½áÊø "); + } + }catch (IOException e){ + System.out.println(new Date()+"Êä³öÁ÷¹Ø±ÕÒì³£ "+e.getMessage()); + } + try + { + if(sock != null) + { + System.out.println(new Date()+"socket¿Í»§¶Ë¹Ø±Õ¿ªÊ¼"); + sock.close(); + sock = null; + System.out.println(new Date()+"socket¿Í»§¶Ë¹Ø±Õ½áÊø"); + } + }catch (IOException e){ + System.out.println(new Date()+"socket¿Í»§¶Ë¹Ø±ÕÒì³£ "+e.getMessage()); + } + } + void reConnect(){ + closeServer(); + ConnectServer(); + } + public int sendtoCrane(byte btid,int new_cmd, Hashtable hsSysParam) throws Exception + { + //super(hsSysParam); + try{ + + //m_hsSysParam = hsSysParam; + Hashtable hsComParam1 = (Hashtable)hsSysParam.get("hsComParam"); + Hashtable writePlcHs = (Hashtable)hsSysParam.get("writePlcHs"); + WriteDotPlcInterface ddjcmd = (WriteDotPlcInterface)writePlcHs.get("11-1"); + if(btid == 1){ + + /*JSONArray orderEntitys = new JSONArray(); + orderEntitys.add(JsonTool.updateJson(WritePlcCmd.XMCJ2_QQDQ, 1)); + return ddjcmd.Analysis(orderEntitys.toString());*/ + } + }catch(Exception ex){ + Logger.error("Ïò¶Ñ¶â»ú·¢ËÍÖ¸ÁîÒì³£"+ex.getMessage()); + } + return -1; + } + void run() { + long t1 = 0,t2 = 0; + //List groups = {0,1,1,1,[1,1]}; + List groups = null; + WriteDotPlcInterface.groupPlcObj group = null; + WriteDotPlcInterface plcWVar = null; + Iterator iterW = null; + Map.Entry entry = null; + // + while(true){ + try{ + if(IsConnect()){ + //257-25= + //¶ÁÈ¡DB¿é510µÄËùÓÐÎļþ + t1 = System.currentTimeMillis(); + dc.readBytes(Nodave.DB, 101, 0, 40, null); + if(IsConnect()){ + System.out.println(dc.getINT(20)); + System.out.println(dc.getDINT(22)); + }else{ + continue; + } + //¶ÁÈ¡DB¿é511µÄËùÓÐÎļþ + //protected byte btid = 0; //¶Ñ¶â»úºÅ + +// dc.readBytes(Nodave.DB, 301, 0, 2, null); +// if(IsConnect()){ +// System.out.println(dc.getINT(0)); +// }else{ +// continue; +// } + //дÈëDB¿é301 + Hashtable hsComParam = new Hashtable();//ͨѶ²ÎÊý + Hashtable writePlcHs = new Hashtable(); + WriteDotPlcInterface ddjcmd1 = new WriteDotPlcInterface("11",1+"");//11Ϊ¶Ñ¶â»úÖ¸ÁîÀàÐÍ + writePlcHs.put(ddjcmd1.cmdtype+"-"+ddjcmd1.cmdvalue, ddjcmd1); + hsComParam.put("writePlcHs", writePlcHs); + + + int iSend = sendtoCrane(btid, 1,hsComParam); + + + iterW = writePlcHs.entrySet().iterator(); + if(iterW != null){ + while (iterW.hasNext()) { + entry = (Map.Entry) iterW.next(); + plcWVar = (WriteDotPlcInterface)entry.getValue(); + groups = plcWVar.lsWriteGroupPlc; + for(i=0;itrue ´«»»³ÉСд¸ñʽ £¬ false ´«»»³É´óд¸ñʽ + * @return Ê®Áù½øÖÆchar[] + */ + public char[] encodeHex(byte[] data, boolean toLowerCase) { + return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER); + } + + /** + * ½«×Ö½ÚÊý×éת»»ÎªÊ®Áù½øÖÆ×Ö·ûÊý×é + * @param data byte[] + * @param toDigits ÓÃÓÚ¿ØÖÆÊä³öµÄchar[] + * @return Ê®Áù½øÖÆchar[] + */ + protected char[] encodeHex(byte[] data, char[] toDigits) { + int l = data.length; + char[] out = new char[l << 1]; + for (int i = 0, j = 0; i < l; i++) { + out[j++] = toDigits[(0xF0 & data[i]) >>> 4]; + out[j++] = toDigits[0x0F & data[i]]; + } + return out; + } + + /** + * ½«×Ö½ÚÊý×éת»»ÎªÊ®Áù½øÖÆ×Ö·û´® + * @param data byte[] + * @return Ê®Áù½øÖÆString + */ + public String encodeHexStr(byte[] data) { + return encodeHexStr(data, true); + } + + /** + * ½«×Ö½ÚÊý×éת»»ÎªÊ®Áù½øÖÆ×Ö·û´® + * @param data byte[] + * @param toLowerCase true ´«»»³ÉСд¸ñʽ £¬ false ´«»»³É´óд¸ñʽ + * @return Ê®Áù½øÖÆString + */ + public String encodeHexStr(byte[] data, boolean toLowerCase) { + return encodeHexStr(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER); + } + + /** + * ½«×Ö½ÚÊý×éת»»ÎªÊ®Áù½øÖÆ×Ö·û´® + * @param data byte[] + * @param toDigits ÓÃÓÚ¿ØÖÆÊä³öµÄchar[] + * @return Ê®Áù½øÖÆString + */ + protected String encodeHexStr(byte[] data, char[] toDigits) { + return new String(encodeHex(data, toDigits)); + } + + /** + * ½«Ê®Áù½øÖÆ×Ö·ûÊý×éת»»Îª×Ö½ÚÊý×é + * @param data Ê®Áù½øÖÆchar[] + * @return byte[] + * @throws RuntimeException Èç¹ûÔ´Ê®Áù½øÖÆ×Ö·ûÊý×éÊÇÒ»¸öÆæ¹ÖµÄ³¤¶È£¬½«Å׳öÔËÐÐʱÒì³£ + */ + public byte[] decodeHex(char[] data) { + int len = data.length; + if ((len & 0x01) != 0) { + throw new RuntimeException("Odd number of characters."); + } + byte[] out = new byte[len >> 1]; + for (int i = 0, j = 0; j < len; i++) { + int f = toDigit(data[j], j) << 4; + j++; + f = f | toDigit(data[j], j); + j++; + out[i] = (byte) (f & 0xFF); + } + return out; + } + + /** + * ½«Ê®Áù½øÖÆ×Ö·ûת»»³ÉÒ»¸öÕûÊý + * @param chÊ®Áù½øÖÆchar + * @param indexÊ®Áù½øÖÆ×Ö·ûÔÚ×Ö·ûÊý×éÖеÄλÖà + * @return Ò»¸öÕûÊý + * @throws RuntimeException µ±ch²»ÊÇÒ»¸öºÏ·¨µÄÊ®Áù½øÖÆ×Ö·ûʱ£¬Å׳öÔËÐÐʱÒì³£ + */ + protected int toDigit(char ch, int index) { + int digit = Character.digit(ch, 16); + if (digit == -1) { + throw new RuntimeException("Illegal hexadecimal character " + ch + + " at index " + index); + } + return digit; + } + + /** + * ½«byteת»»ÎªÒ»¸ö³¤¶ÈΪ8µÄbyteÊý×飬Êý×éÿ¸öÖµ´ú±íbit + * @param b + * @return + */ + public byte[] getBooleanArray_high_low(byte b) { + byte[] array = new byte[8]; + for (int i = 7; i >= 0; i--) { + array[i] = (byte) (b & 1); + b = (byte) (b >> 1); + } + return array; + } + + public byte[] getBooleanArray_low_high(byte b) { + byte[] array = new byte[8]; + for (int i = 0; i <=7 ; i++) { + array[i] = (byte) (b & 1); + b = (byte) (b >> 1); + } + return array; + } + + /** + * °ÑbyteתΪ×Ö·û´®µÄbit + * @param b + * @return + */ + public String byteToBit(byte b) { + return "" + (byte) ((b >> 7) & 0x1) + (byte) ((b >> 6) & 0x1) + + (byte) ((b >> 5) & 0x1) + (byte) ((b >> 4) & 0x1) + + (byte) ((b >> 3) & 0x1) + (byte) ((b >> 2) & 0x1) + + (byte) ((b >> 1) & 0x1) + (byte) ((b >> 0) & 0x1); + + } + + public String bytesToHexString(byte[] src) { + StringBuilder stringBuilder = new StringBuilder(""); + if (src == null || src.length <= 0) { + return null; + } + for (int i = 0; i < src.length; i++) { + int v = src[i] & 0xFF; + String hv = Integer.toHexString(v); + if (hv.length() < 2) { + stringBuilder.append(0); + } + stringBuilder.append(hv); + } + return stringBuilder.toString(); + } + + + //ÏäÂë²É¼¯ + public abstract void analysisDb50_1(); + public abstract void analysisDb50_2(); + public abstract void analysisDb50_3(); + public abstract void analysisDb50_4(); + public abstract void analysisDb50_5(); + public abstract void analysisDb50_6(); + public abstract void analysisDb50_7(); + public abstract void analysisDb50_8(); + public abstract void analysisDb50_9(); + public abstract void analysisDb50_10(); + public abstract void analysisDb50_11(); + public abstract void analysisDb50_12(); + public abstract void analysisDb50_13(); + public abstract void analysisDb50_14(); + public abstract void analysisDb50_15(); + public abstract void analysisDb50_16(); + + public abstract void analysisDb49_1(); + public abstract void analysisDb49_2(); + public abstract void analysisDb49_3(); + public abstract void analysisDb49_4(); + public abstract void analysisDb49_5(); + public abstract void analysisDb49_6(); + public abstract void analysisDb49_7(); + public abstract void analysisDb49_8(); + public abstract void analysisDb49_9(); + public abstract void analysisDb49_10(); + public abstract void analysisDb49_11(); + public abstract void analysisDb49_12(); + public abstract void analysisDb49_13(); + public abstract void analysisDb49_14(); + public abstract void analysisDb49_15(); + public abstract void analysisDb49_16(); + + + + public abstract void analysisDb48_1(); + public abstract void analysisDb48_2(); + public abstract void analysisDb48_3(); + public abstract void analysisDb48_4(); + public abstract void analysisDb48_5(); + public abstract void analysisDb48_6(); + public abstract void analysisDb48_7(); + public abstract void analysisDb48_8(); + public abstract void analysisDb48_9(); + public abstract void analysisDb48_10(); + public abstract void analysisDb48_11(); + public abstract void analysisDb48_12(); + public abstract void analysisDb48_13(); + public abstract void analysisDb48_14(); + public abstract void analysisDb48_15(); + public abstract void analysisDb48_16(); + + + public abstract void analysisDb47_1(); + public abstract void analysisDb47_2(); + public abstract void analysisDb47_3(); + public abstract void analysisDb47_4(); + public abstract void analysisDb47_5(); + public abstract void analysisDb47_6(); + public abstract void analysisDb47_7(); + public abstract void analysisDb47_8(); + public abstract void analysisDb47_9(); + public abstract void analysisDb47_10(); + public abstract void analysisDb47_11(); + public abstract void analysisDb47_12(); + public abstract void analysisDb47_13(); + public abstract void analysisDb47_14(); + public abstract void analysisDb47_15(); + public abstract void analysisDb47_16(); + + + + public abstract void analysisDb46_1(); + public abstract void analysisDb46_2(); + public abstract void analysisDb46_3(); + public abstract void analysisDb46_4(); + public abstract void analysisDb46_5(); + public abstract void analysisDb46_6(); + public abstract void analysisDb46_7(); + public abstract void analysisDb46_8(); + public abstract void analysisDb46_9(); + public abstract void analysisDb46_10(); + public abstract void analysisDb46_11(); + public abstract void analysisDb46_12(); + public abstract void analysisDb46_13(); + public abstract void analysisDb46_14(); + public abstract void analysisDb46_15(); + public abstract void analysisDb46_16(); + + + public abstract void analysisDb45_1(); + public abstract void analysisDb45_2(); + public abstract void analysisDb45_3(); + public abstract void analysisDb45_4(); + public abstract void analysisDb45_5(); + public abstract void analysisDb45_6(); + public abstract void analysisDb45_7(); + public abstract void analysisDb45_8(); + public abstract void analysisDb45_9(); + public abstract void analysisDb45_10(); + public abstract void analysisDb45_11(); + public abstract void analysisDb45_12(); + public abstract void analysisDb45_13(); + public abstract void analysisDb45_14(); + public abstract void analysisDb45_15(); + public abstract void analysisDb45_16(); + + + public abstract void analysisDb44_1(); + public abstract void analysisDb44_2(); + public abstract void analysisDb44_3(); + public abstract void analysisDb44_4(); + public abstract void analysisDb44_5(); + public abstract void analysisDb44_6(); + public abstract void analysisDb44_7(); + public abstract void analysisDb44_8(); + public abstract void analysisDb44_9(); + public abstract void analysisDb44_10(); + public abstract void analysisDb44_11(); + public abstract void analysisDb44_12(); + public abstract void analysisDb44_13(); + public abstract void analysisDb44_14(); + public abstract void analysisDb44_15(); + public abstract void analysisDb44_16(); + + public abstract void analysisDb43_1(); + public abstract void analysisDb43_2(); + public abstract void analysisDb43_3(); + public abstract void analysisDb43_4(); + public abstract void analysisDb43_5(); + public abstract void analysisDb43_6(); + public abstract void analysisDb43_7(); + public abstract void analysisDb43_8(); + public abstract void analysisDb43_9(); + public abstract void analysisDb43_10(); + public abstract void analysisDb43_11(); + public abstract void analysisDb43_12(); + public abstract void analysisDb43_13(); + public abstract void analysisDb43_14(); + public abstract void analysisDb43_15(); + public abstract void analysisDb43_16(); + + + public abstract void analysisDb42_1(); + public abstract void analysisDb42_2(); + public abstract void analysisDb42_3(); + public abstract void analysisDb42_4(); + public abstract void analysisDb42_5(); + public abstract void analysisDb42_6(); + public abstract void analysisDb42_7(); + public abstract void analysisDb42_8(); + public abstract void analysisDb42_9(); + public abstract void analysisDb42_10(); + public abstract void analysisDb42_11(); + public abstract void analysisDb42_12(); + public abstract void analysisDb42_13(); + public abstract void analysisDb42_14(); + public abstract void analysisDb42_15(); + public abstract void analysisDb42_16(); + + + public abstract void analysisDb41_1(); + public abstract void analysisDb41_2(); + public abstract void analysisDb41_3(); + public abstract void analysisDb41_4(); + public abstract void analysisDb41_5(); + public abstract void analysisDb41_6(); + public abstract void analysisDb41_7(); + public abstract void analysisDb41_8(); + public abstract void analysisDb41_9(); + public abstract void analysisDb41_10(); + public abstract void analysisDb41_11(); + public abstract void analysisDb41_12(); + public abstract void analysisDb41_13(); + public abstract void analysisDb41_14(); + public abstract void analysisDb41_15(); + public abstract void analysisDb41_16(); + + + + + + + public String getSTRING30(int pos) { + return Nodave.SBEString30(msgIn, udata + pos).toString(); + } + +} diff --git a/src/org/s7/standard/ynuo/ReadDotPlcInterface.java b/src/org/s7/standard/ynuo/ReadDotPlcInterface.java new file mode 100644 index 0000000..117787b --- /dev/null +++ b/src/org/s7/standard/ynuo/ReadDotPlcInterface.java @@ -0,0 +1,49 @@ +package org.s7.standard.ynuo; +import java.util.ArrayList; +import java.util.List; +import org.libnodave.Nodave; +/** + * ¶ÁÈ¡db¿éµãÒµÎñ±ê×¼Àà + * @author yao + */ +public abstract class ReadDotPlcInterface implements PlcInterface{ + public List lsReadGroupPlc = new ArrayList(); + /*½«¶ÁÈ¡PLCµÄdb¿éÊý¾ÝÍùÊý¾Ý¿âÖÐдÈë*/ + public abstract void analysisDb(); + public class groupPlcObj { + /*Öµ*/ + public Object obj = null; + /*DB*/ + private int DB=Nodave.DB; + /*¶ÁÈ¡DBµØÖ·*/ + private int DBnum=0; + /*¶ÁÈ¡DBÆðʼλÖà */ + private int start=0; + /*¶ÁÈ¡Êý¾ÝÀàÐÍ*/ + private int dtype = BYTE; + public groupPlcObj(int DB,int DBnum,int start,int dtype){ + this.DB = DB; + this.DBnum = DBnum; + this.start = start; + this.dtype = dtype; + } + public String key(){ + return DB+"-"+DBnum+"-"+start+"-"+dtype; + } + public Object getObj() { + return obj; + } + public int getDB() { + return DB; + } + public int getDBnum() { + return DBnum; + } + public int getStart() { + return start; + } + public int getDtype() { + return dtype; + } + } +} diff --git a/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer101.java b/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer101.java new file mode 100644 index 0000000..26c5bc2 --- /dev/null +++ b/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer101.java @@ -0,0 +1,248 @@ +package org.s7.standard.ynuo; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; +import org.s7.standard.ynuo.client.IsoTcpClient101; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.common.server.config.DSSTabSel; + +/** + * ¸ÃÏ߳̽«´Ó¡¶¶Á»º´æÇø¡·£¨´Óplc¶ÁÈ¡µ½µÄÊý¾Ý´æ·ÅµÄλÖã©¶¨Ê±Ð´µ½Êý¾Ý¿âÖÐ + * + * @author admin + * + */ +public class ReadPlcDBAnalyServer101 implements Runnable { + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable readAreaPlcHsMD101 = null; + public Hashtable readAreaPlcHsMD102 = null; + public Hashtable readAreaPlcHsMD103 = null; + public Hashtable readAreaPlcHsMD104 = null; + public Hashtable readAreaPlcHsMD105 = null; + public Hashtable readAreaPlcHsMD106 = null; + public Hashtable readAreaPlcHsMD107 = null; + public Hashtable readAreaPlcHsMD108 = null; + public Hashtable readAreaPlcHsMD109 = null; + public Hashtable readAreaPlcHsMD110 = null; +// public Hashtable readAreaPlcHs2 = null; +// public Hashtable readAreaPlcHs3 = null; +// public Hashtable readAreaPlcHs4 = null; +// public Hashtable readAreaPlcHs5 = null; + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable readDotPlcHs = null; + Hashtable hsSysParam = null; + Hashtable hsComParam = null; + IsoTcpClient101 client = null; + + public EntityDAO dao; + + public ReadPlcDBAnalyServer101(Hashtable hsComParam, IsoTcpClient101 client) { + this.hsComParam = hsComParam; + this.hsSysParam = client.hsSysParam; + this.readAreaPlcHsMD101 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_101"); + this.readAreaPlcHsMD102 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_102"); + this.readAreaPlcHsMD103 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_103"); + this.readAreaPlcHsMD104 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_104"); + this.readAreaPlcHsMD105 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_105"); + this.readAreaPlcHsMD106 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_106"); + this.readAreaPlcHsMD107 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_107"); + this.readAreaPlcHsMD108 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_108"); + this.readAreaPlcHsMD109 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_109"); + this.readAreaPlcHsMD110 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_110"); +// this.readAreaPlcHs2 = (Hashtable) hsComParam.get("readAreaPlcHs1_2"); +// this.readAreaPlcHs3 = (Hashtable) hsComParam.get("readAreaPlcHs1_3"); +// this.readAreaPlcHs4 = (Hashtable) hsComParam.get("readAreaPlcHs1_4"); +// this.readAreaPlcHs5 = (Hashtable) hsComParam.get("readAreaPlcHs1_5"); + this.client = client; + } + + public void run() { + Iterator iterobj; + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + ((DSSTabSel) (((ArrayList) hsSysParam.get("DSSTabSel")).get(0))).jTextArea.setCaretPosition( + ((DSSTabSel) (((ArrayList) hsSysParam.get("DSSTabSel")).get(0))).jTextArea.getText().length() + - 20); + try { + + if (readAreaPlcHsMD101 != null) { + iterobj = readAreaPlcHsMD101.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + plcVar.analysisDb101_MD(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + if (readAreaPlcHsMD102 != null) { + iterobj = readAreaPlcHsMD102.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + plcVar.analysisDb102_MD(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + if (readAreaPlcHsMD103 != null) { + iterobj = readAreaPlcHsMD103.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + plcVar.analysisDb103_MD(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + if (readAreaPlcHsMD104 != null) { + iterobj = readAreaPlcHsMD104.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + plcVar.analysisDb104_MD(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + if (readAreaPlcHsMD105 != null) { + iterobj = readAreaPlcHsMD105.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + plcVar.analysisDb105_MD(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + if (readAreaPlcHsMD106 != null) { + iterobj = readAreaPlcHsMD106.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + plcVar.analysisDb106_MD(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + if (readAreaPlcHsMD107 != null) { + iterobj = readAreaPlcHsMD107.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + plcVar.analysisDb107_MD(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + if (readAreaPlcHsMD108 != null) { + iterobj = readAreaPlcHsMD108.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb108_MD(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHsMD109 != null) { + iterobj = readAreaPlcHsMD109.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + plcVar.analysisDb109_MD(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHsMD110 != null) { + iterobj = readAreaPlcHsMD110.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + plcVar.analysisDb110_MD(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } +} diff --git a/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer102.java b/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer102.java new file mode 100644 index 0000000..6cc60f6 --- /dev/null +++ b/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer102.java @@ -0,0 +1,247 @@ +package org.s7.standard.ynuo; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; + +import org.s7.standard.ynuo.client.IsoTcpClient102; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.common.server.config.DSSTabSel; + +/** + * ¸ÃÏ߳̽«´Ó¡¶¶Á»º´æÇø¡·£¨´Óplc¶ÁÈ¡µ½µÄÊý¾Ý´æ·ÅµÄλÖã©¶¨Ê±Ð´µ½Êý¾Ý¿âÖÐ + * + * @author admin + * + */ +public class ReadPlcDBAnalyServer102 implements Runnable { + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable readAreaPlcHs101 = null; + public Hashtable readAreaPlcHs102 = null; + public Hashtable readAreaPlcHs104 = null; + public Hashtable readAreaPlcHs105 = null; + public Hashtable readAreaPlcHs106 = null; + public Hashtable readAreaPlcHs107 = null; + public Hashtable readAreaPlcHs103 = null; + public Hashtable readAreaPlcHs105_2 = null; + public Hashtable readAreaPlcHs151 = null; + + public Hashtable readAreaPlcHs108 = null; + + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable readDotPlcHs = null; + Hashtable hsSysParam = null; + Hashtable hsComParam = null; + IsoTcpClient102 client = null; + + public EntityDAO dao; + + public ReadPlcDBAnalyServer102(Hashtable hsComParam, IsoTcpClient102 tp2) { + this.hsComParam = hsComParam; + this.hsSysParam = tp2.hsSysParam; + this.readAreaPlcHs101 = (Hashtable) hsComParam.get("readAreaPlcHsDB101"); + this.readAreaPlcHs102 = (Hashtable) hsComParam.get("readAreaPlcHsDB102"); + this.readAreaPlcHs104 = (Hashtable) hsComParam.get("readAreaPlcHsDB104"); + this.readAreaPlcHs105 = (Hashtable) hsComParam.get("readAreaPlcHsDB105"); + this.readAreaPlcHs106 = (Hashtable) hsComParam.get("readAreaPlcHsDB106"); + this.readAreaPlcHs107 = (Hashtable) hsComParam.get("readAreaPlcHsDB107"); + this.readAreaPlcHs103 = (Hashtable) hsComParam.get("readAreaPlcHsDB103"); + this.readAreaPlcHs105_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB105_2"); + this.readAreaPlcHs151 = (Hashtable) hsComParam.get("readAreaPlcHsDB151"); + + + this.readAreaPlcHs108 = (Hashtable) hsComParam.get("readAreaPlcHsDB108"); + this.client = tp2; + } + + public void run() { + + Iterator iterobj; + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + ((DSSTabSel) (((ArrayList) hsSysParam.get("DSSTabSel")).get(0))).jTextArea.setCaretPosition( + ((DSSTabSel) (((ArrayList) hsSysParam.get("DSSTabSel")).get(0))).jTextArea.getText().length() + - 20); + try { + + if (readAreaPlcHs101 != null) { + iterobj = readAreaPlcHs101.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb101(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs102 != null) { + iterobj = readAreaPlcHs102.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + plcVar.analysisDb102(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs104 != null) { + iterobj = readAreaPlcHs104.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb104(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs105 != null) { + iterobj = readAreaPlcHs105.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb105(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs105_2 != null) { + iterobj = readAreaPlcHs105_2.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb105_2(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs106 != null) { + iterobj = readAreaPlcHs106.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb106(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs107 != null) { + iterobj = readAreaPlcHs107.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb107(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs103 != null) { + iterobj = readAreaPlcHs103.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb103(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs151 != null) { + iterobj = readAreaPlcHs151.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb151(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + //2021-2-10 + if (readAreaPlcHs108 != null) { + iterobj = readAreaPlcHs108.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb108(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } +} diff --git a/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer103.java b/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer103.java new file mode 100644 index 0000000..e7cc15e --- /dev/null +++ b/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer103.java @@ -0,0 +1,76 @@ +package org.s7.standard.ynuo; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; + +import org.s7.standard.ynuo.client.IsoTcpClient103; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.common.server.config.DSSTabSel; + +/** + * ¸ÃÏ߳̽«´Ó¡¶¶Á»º´æÇø¡·£¨´Óplc¶ÁÈ¡µ½µÄÊý¾Ý´æ·ÅµÄλÖã©¶¨Ê±Ð´µ½Êý¾Ý¿âÖÐ + * + * @author admin + * + */ +public class ReadPlcDBAnalyServer103 implements Runnable { + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + //public Hashtable readAreaPlcHs = null; + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + //public Hashtable readDotPlcHs = null; + Hashtable hsSysParam = null; + Hashtable hsComParam = null; + IsoTcpClient103 client = null; + + public EntityDAO dao; + + public ReadPlcDBAnalyServer103(Hashtable hsComParam, IsoTcpClient103 client) { + this.hsComParam = hsComParam; + this.hsSysParam = client.hsSysParam; + //this.readAreaPlcHs = (Hashtable) hsComParam.get("readAreaPlcHs3"); + this.client = client; + } + + public void run() { + Iterator iterobj; + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + ((DSSTabSel) (((ArrayList) hsSysParam.get("DSSTabSel")).get(0))).jTextArea.setCaretPosition( + ((DSSTabSel) (((ArrayList) hsSysParam.get("DSSTabSel")).get(0))).jTextArea.getText().length() + - 20); + try { + + for (int i = 201, x = 1; i <= 215; i++,x++) { + Hashtable readAreaPlcHs = null; + readAreaPlcHs = (Hashtable) hsComParam.get("readAreaPlcHsDB"+i); + if (readAreaPlcHs != null) { + iterobj = readAreaPlcHs.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + String key = (String) entry.getKey(); + if (client != null && client.IsConnect()) { + try { + plcVar.analysisDbDDJ("21-"+x); + } catch (Exception ex) { + } + } else { + break; + } + } + } + } + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } +} diff --git a/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer104.java b/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer104.java new file mode 100644 index 0000000..76285bc --- /dev/null +++ b/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer104.java @@ -0,0 +1,425 @@ +package org.s7.standard.ynuo; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; + +import org.s7.standard.ynuo.client.IsoTcpClient104; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.common.server.config.DSSTabSel; + +/** + * ¸ÃÏ߳̽«´Ó¡¶¶Á»º´æÇø¡·£¨´Óplc¶ÁÈ¡µ½µÄÊý¾Ý´æ·ÅµÄλÖã©¶¨Ê±Ð´µ½Êý¾Ý¿âÖÐ + * + * @author admin + * + */ +public class ReadPlcDBAnalyServer104 implements Runnable { + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable readAreaPlcHs1 = null; + public Hashtable readAreaPlcHs2 = null; + public Hashtable readAreaPlcHs2s = null; + public Hashtable readAreaPlcHs3 = null; + public Hashtable readAreaPlcHs4 = null; + public Hashtable readAreaPlcHs5 = null; + public Hashtable readAreaPlcHs6 = null; + public Hashtable readAreaPlcHs7 = null; + public Hashtable readAreaPlcHs8 = null; + public Hashtable readAreaPlcHs9 = null; + public Hashtable readAreaPlcHs10 = null; + public Hashtable readAreaPlcHs11 = null; + public Hashtable readAreaPlcHs12 = null; + public Hashtable readAreaPlcHs13 = null; + public Hashtable readAreaPlcHs14 = null; + public Hashtable readAreaPlcHs15 = null; + public Hashtable readAreaPlcHs16 = null; + public Hashtable readAreaPlcHs17 = null; + public Hashtable readAreaPlcHs18 = null; + public Hashtable readAreaPlcHs19 = null; + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable readDotPlcHs = null; + Hashtable hsSysParam = null; + Hashtable hsComParam = null; + IsoTcpClient104 client = null; + + public EntityDAO dao; + + public ReadPlcDBAnalyServer104(Hashtable hsComParam, IsoTcpClient104 tp2) { + this.hsComParam = hsComParam; + this.hsSysParam = tp2.hsSysParam; + this.readAreaPlcHs1 = (Hashtable) hsComParam.get("readAreaPlcHs4_1"); + this.readAreaPlcHs2 = (Hashtable) hsComParam.get("readAreaPlcHs4_2"); + this.readAreaPlcHs2s = (Hashtable) hsComParam.get("readAreaPlcHs4_2s"); + this.readAreaPlcHs3 = (Hashtable) hsComParam.get("readAreaPlcHs4_3"); + this.readAreaPlcHs4 = (Hashtable) hsComParam.get("readAreaPlcHs4_4"); + this.readAreaPlcHs5 = (Hashtable) hsComParam.get("readAreaPlcHs4_5"); + this.readAreaPlcHs6 = (Hashtable) hsComParam.get("readAreaPlcHs4_6"); + this.readAreaPlcHs7 = (Hashtable) hsComParam.get("readAreaPlcHs4_7"); + this.readAreaPlcHs8 = (Hashtable) hsComParam.get("readAreaPlcHs4_8"); + this.readAreaPlcHs9 = (Hashtable) hsComParam.get("readAreaPlcHs4_9"); + this.readAreaPlcHs10 = (Hashtable) hsComParam.get("readAreaPlcHs4_10"); + this.readAreaPlcHs11 = (Hashtable) hsComParam.get("readAreaPlcHs4_11"); + this.readAreaPlcHs12 = (Hashtable) hsComParam.get("readAreaPlcHs4_12"); + this.readAreaPlcHs13 = (Hashtable) hsComParam.get("readAreaPlcHs4_13"); + this.readAreaPlcHs14 = (Hashtable) hsComParam.get("readAreaPlcHs4_14"); + this.readAreaPlcHs15 = (Hashtable) hsComParam.get("readAreaPlcHs4_15"); + this.readAreaPlcHs16 = (Hashtable) hsComParam.get("readAreaPlcHs4_16"); + this.readAreaPlcHs17 = (Hashtable) hsComParam.get("readAreaPlcHs4_17"); + this.readAreaPlcHs18 = (Hashtable) hsComParam.get("readAreaPlcHs4_18"); + this.readAreaPlcHs19 = (Hashtable) hsComParam.get("readAreaPlcHs4_19"); + this.client = tp2; + } + + public void run() { + Iterator iterobj; + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + ((DSSTabSel) (((ArrayList) hsSysParam.get("DSSTabSel")).get(0))).jTextArea.setCaretPosition( + ((DSSTabSel) (((ArrayList) hsSysParam.get("DSSTabSel")).get(0))).jTextArea.getText().length() + - 20); + try { + + if (readAreaPlcHs1 != null) { + iterobj = readAreaPlcHs1.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + //System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_1(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs2 != null) { + iterobj = readAreaPlcHs2.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + //System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_2(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs2s != null) { + iterobj = readAreaPlcHs2s.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + //System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_2s(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs3 != null) { + iterobj = readAreaPlcHs3.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + // System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_3(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs4 != null) { + iterobj = readAreaPlcHs4.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + //System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_4(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs5 != null) { + iterobj = readAreaPlcHs5.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + //System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_5(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs6 != null) { + iterobj = readAreaPlcHs6.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + // System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_6(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs7 != null) { + iterobj = readAreaPlcHs7.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + //System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_7(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs8 != null) { + iterobj = readAreaPlcHs8.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + //System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_8(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs9 != null) { + iterobj = readAreaPlcHs9.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + //System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_9(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs10 != null) { + iterobj = readAreaPlcHs10.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + // System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_10(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + //ÒÔÏÂΪ»ñÈ¡²ð¶â»úÐÅÏ¢ + if (readAreaPlcHs11 != null) { + iterobj = readAreaPlcHs11.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + // System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_11(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs12 != null) { + iterobj = readAreaPlcHs12.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + // System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_12(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs13 != null) { + iterobj = readAreaPlcHs13.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + // System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_13(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs14 != null) { + iterobj = readAreaPlcHs14.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + // System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_14(); + } catch (Exception ex) { + } + } else { + break; + } + } + }if (readAreaPlcHs15 != null) { + iterobj = readAreaPlcHs15.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + // System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_15(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs16 != null) { + iterobj = readAreaPlcHs16.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + // System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_16(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs17 != null) { + iterobj = readAreaPlcHs17.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + // System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_17(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs18 != null) { + iterobj = readAreaPlcHs18.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + // System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_18(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs19 != null) { + iterobj = readAreaPlcHs19.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + // System.out.println("------------------·Ö¸îÏß-------------------"); + plcVar.analysisDb4_19(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + // + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } +} diff --git a/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer171.java b/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer171.java new file mode 100644 index 0000000..34c6120 --- /dev/null +++ b/src/org/s7/standard/ynuo/ReadPlcDBAnalyServer171.java @@ -0,0 +1,3054 @@ +package org.s7.standard.ynuo; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; + +import org.s7.standard.ynuo.client.IsoTcpClient171; + +import com.ricosoft.common.dao.dataSource.EntityDAO; +import com.wms.dss.common.server.config.DSSTabSel; + +/** + * ¸ÃÏ߳̽«´Ó¡¶¶Á»º´æÇø¡·£¨´Óplc¶ÁÈ¡µ½µÄÊý¾Ý´æ·ÅµÄλÖã©¶¨Ê±Ð´µ½Êý¾Ý¿âÖÐ + * + * @author admin + * + */ +public class ReadPlcDBAnalyServer171 implements Runnable { + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + + public Hashtable readAreaPlcHs50_1 = null; + public Hashtable readAreaPlcHs50_2 = null; + public Hashtable readAreaPlcHs50_3 = null; + public Hashtable readAreaPlcHs50_4 = null; + public Hashtable readAreaPlcHs50_5 = null; + public Hashtable readAreaPlcHs50_6 = null; + public Hashtable readAreaPlcHs50_7 = null; + public Hashtable readAreaPlcHs50_8 = null; + public Hashtable readAreaPlcHs50_9 = null; + public Hashtable readAreaPlcHs50_10 = null; + public Hashtable readAreaPlcHs50_11 = null; + public Hashtable readAreaPlcHs50_12 = null; + public Hashtable readAreaPlcHs50_13 = null; + public Hashtable readAreaPlcHs50_14 = null; + public Hashtable readAreaPlcHs50_15 = null; + public Hashtable readAreaPlcHs50_16 = null; + + public Hashtable readAreaPlcHs49_1 = null; + public Hashtable readAreaPlcHs49_2 = null; + public Hashtable readAreaPlcHs49_3 = null; + public Hashtable readAreaPlcHs49_4 = null; + public Hashtable readAreaPlcHs49_5 = null; + public Hashtable readAreaPlcHs49_6 = null; + public Hashtable readAreaPlcHs49_7 = null; + public Hashtable readAreaPlcHs49_8 = null; + public Hashtable readAreaPlcHs49_9 = null; + public Hashtable readAreaPlcHs49_10 = null; + public Hashtable readAreaPlcHs49_11 = null; + public Hashtable readAreaPlcHs49_12 = null; + public Hashtable readAreaPlcHs49_13 = null; + public Hashtable readAreaPlcHs49_14 = null; + public Hashtable readAreaPlcHs49_15 = null; + public Hashtable readAreaPlcHs49_16 = null; + + + public Hashtable readAreaPlcHs48_1 = null; + public Hashtable readAreaPlcHs48_2 = null; + public Hashtable readAreaPlcHs48_3 = null; + public Hashtable readAreaPlcHs48_4 = null; + public Hashtable readAreaPlcHs48_5 = null; + public Hashtable readAreaPlcHs48_6 = null; + public Hashtable readAreaPlcHs48_7 = null; + public Hashtable readAreaPlcHs48_8 = null; + public Hashtable readAreaPlcHs48_9 = null; + public Hashtable readAreaPlcHs48_10 = null; + public Hashtable readAreaPlcHs48_11 = null; + public Hashtable readAreaPlcHs48_12 = null; + public Hashtable readAreaPlcHs48_13 = null; + public Hashtable readAreaPlcHs48_14 = null; + public Hashtable readAreaPlcHs48_15 = null; + public Hashtable readAreaPlcHs48_16 = null; + + + + public Hashtable readAreaPlcHs47_1 = null; + public Hashtable readAreaPlcHs47_2 = null; + public Hashtable readAreaPlcHs47_3 = null; + public Hashtable readAreaPlcHs47_4 = null; + public Hashtable readAreaPlcHs47_5 = null; + public Hashtable readAreaPlcHs47_6 = null; + public Hashtable readAreaPlcHs47_7 = null; + public Hashtable readAreaPlcHs47_8 = null; + public Hashtable readAreaPlcHs47_9 = null; + public Hashtable readAreaPlcHs47_10 = null; + public Hashtable readAreaPlcHs47_11 = null; + public Hashtable readAreaPlcHs47_12 = null; + public Hashtable readAreaPlcHs47_13 = null; + public Hashtable readAreaPlcHs47_14 = null; + public Hashtable readAreaPlcHs47_15 = null; + public Hashtable readAreaPlcHs47_16 = null; + + public Hashtable readAreaPlcHs46_1 = null; + public Hashtable readAreaPlcHs46_2 = null; + public Hashtable readAreaPlcHs46_3 = null; + public Hashtable readAreaPlcHs46_4 = null; + public Hashtable readAreaPlcHs46_5 = null; + public Hashtable readAreaPlcHs46_6 = null; + public Hashtable readAreaPlcHs46_7 = null; + public Hashtable readAreaPlcHs46_8 = null; + public Hashtable readAreaPlcHs46_9 = null; + public Hashtable readAreaPlcHs46_10 = null; + public Hashtable readAreaPlcHs46_11 = null; + public Hashtable readAreaPlcHs46_12 = null; + public Hashtable readAreaPlcHs46_13 = null; + public Hashtable readAreaPlcHs46_14 = null; + public Hashtable readAreaPlcHs46_15 = null; + public Hashtable readAreaPlcHs46_16 = null; + + + public Hashtable readAreaPlcHs45_1 = null; + public Hashtable readAreaPlcHs45_2 = null; + public Hashtable readAreaPlcHs45_3 = null; + public Hashtable readAreaPlcHs45_4 = null; + public Hashtable readAreaPlcHs45_5 = null; + public Hashtable readAreaPlcHs45_6 = null; + public Hashtable readAreaPlcHs45_7 = null; + public Hashtable readAreaPlcHs45_8 = null; + public Hashtable readAreaPlcHs45_9 = null; + public Hashtable readAreaPlcHs45_10 = null; + public Hashtable readAreaPlcHs45_11 = null; + public Hashtable readAreaPlcHs45_12 = null; + public Hashtable readAreaPlcHs45_13 = null; + public Hashtable readAreaPlcHs45_14 = null; + public Hashtable readAreaPlcHs45_15 = null; + public Hashtable readAreaPlcHs45_16 = null; + + public Hashtable readAreaPlcHs44_1 = null; + public Hashtable readAreaPlcHs44_2 = null; + public Hashtable readAreaPlcHs44_3 = null; + public Hashtable readAreaPlcHs44_4 = null; + public Hashtable readAreaPlcHs44_5 = null; + public Hashtable readAreaPlcHs44_6 = null; + public Hashtable readAreaPlcHs44_7 = null; + public Hashtable readAreaPlcHs44_8 = null; + public Hashtable readAreaPlcHs44_9 = null; + public Hashtable readAreaPlcHs44_10 = null; + public Hashtable readAreaPlcHs44_11 = null; + public Hashtable readAreaPlcHs44_12 = null; + public Hashtable readAreaPlcHs44_13 = null; + public Hashtable readAreaPlcHs44_14 = null; + public Hashtable readAreaPlcHs44_15 = null; + public Hashtable readAreaPlcHs44_16 = null; + + public Hashtable readAreaPlcHs43_1 = null; + public Hashtable readAreaPlcHs43_2 = null; + public Hashtable readAreaPlcHs43_3 = null; + public Hashtable readAreaPlcHs43_4 = null; + public Hashtable readAreaPlcHs43_5 = null; + public Hashtable readAreaPlcHs43_6 = null; + public Hashtable readAreaPlcHs43_7 = null; + public Hashtable readAreaPlcHs43_8 = null; + public Hashtable readAreaPlcHs43_9 = null; + public Hashtable readAreaPlcHs43_10 = null; + public Hashtable readAreaPlcHs43_11 = null; + public Hashtable readAreaPlcHs43_12 = null; + public Hashtable readAreaPlcHs43_13 = null; + public Hashtable readAreaPlcHs43_14 = null; + public Hashtable readAreaPlcHs43_15 = null; + public Hashtable readAreaPlcHs43_16 = null; + + + public Hashtable readAreaPlcHs42_1 = null; + public Hashtable readAreaPlcHs42_2 = null; + public Hashtable readAreaPlcHs42_3 = null; + public Hashtable readAreaPlcHs42_4 = null; + public Hashtable readAreaPlcHs42_5 = null; + public Hashtable readAreaPlcHs42_6 = null; + public Hashtable readAreaPlcHs42_7 = null; + public Hashtable readAreaPlcHs42_8 = null; + public Hashtable readAreaPlcHs42_9 = null; + public Hashtable readAreaPlcHs42_10 = null; + public Hashtable readAreaPlcHs42_11 = null; + public Hashtable readAreaPlcHs42_12 = null; + public Hashtable readAreaPlcHs42_13 = null; + public Hashtable readAreaPlcHs42_14 = null; + public Hashtable readAreaPlcHs42_15 = null; + public Hashtable readAreaPlcHs42_16 = null; + + + public Hashtable readAreaPlcHs41_1 = null; + public Hashtable readAreaPlcHs41_2 = null; + public Hashtable readAreaPlcHs41_3 = null; + public Hashtable readAreaPlcHs41_4 = null; + public Hashtable readAreaPlcHs41_5 = null; + public Hashtable readAreaPlcHs41_6 = null; + public Hashtable readAreaPlcHs41_7 = null; + public Hashtable readAreaPlcHs41_8 = null; + public Hashtable readAreaPlcHs41_9 = null; + public Hashtable readAreaPlcHs41_10 = null; + public Hashtable readAreaPlcHs41_11 = null; + public Hashtable readAreaPlcHs41_12 = null; + public Hashtable readAreaPlcHs41_13 = null; + public Hashtable readAreaPlcHs41_14 = null; + public Hashtable readAreaPlcHs41_15 = null; + public Hashtable readAreaPlcHs41_16 = null; + + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable readDotPlcHs = null; + Hashtable hsSysParam = null; + Hashtable hsComParam = null; + IsoTcpClient171 client = null; + + public EntityDAO dao; + + public ReadPlcDBAnalyServer171(Hashtable hsComParam, IsoTcpClient171 tp) { + this.hsComParam = hsComParam; + this.hsSysParam = tp.hsSysParam; + + this.readAreaPlcHs50_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_1"); + this.readAreaPlcHs50_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_2"); + this.readAreaPlcHs50_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_3"); + this.readAreaPlcHs50_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_4"); + this.readAreaPlcHs50_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_5"); + this.readAreaPlcHs50_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_6"); + this.readAreaPlcHs50_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_7"); + this.readAreaPlcHs50_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_8"); + this.readAreaPlcHs50_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_9"); + this.readAreaPlcHs50_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_10"); + this.readAreaPlcHs50_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_11"); + this.readAreaPlcHs50_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_12"); + this.readAreaPlcHs50_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_13"); + this.readAreaPlcHs50_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_14"); + this.readAreaPlcHs50_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_15"); + this.readAreaPlcHs50_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_16"); + + this.readAreaPlcHs49_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_1"); + this.readAreaPlcHs49_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_2"); + this.readAreaPlcHs49_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_3"); + this.readAreaPlcHs49_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_4"); + this.readAreaPlcHs49_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_5"); + this.readAreaPlcHs49_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_6"); + this.readAreaPlcHs49_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_7"); + this.readAreaPlcHs49_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_8"); + this.readAreaPlcHs49_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_9"); + this.readAreaPlcHs49_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_10"); + this.readAreaPlcHs49_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_11"); + this.readAreaPlcHs49_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_12"); + this.readAreaPlcHs49_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_13"); + this.readAreaPlcHs49_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_14"); + this.readAreaPlcHs49_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_15"); + this.readAreaPlcHs49_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_16"); + + this.readAreaPlcHs48_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_1"); + this.readAreaPlcHs48_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_2"); + this.readAreaPlcHs48_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_3"); + this.readAreaPlcHs48_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_4"); + this.readAreaPlcHs48_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_5"); + this.readAreaPlcHs48_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_6"); + this.readAreaPlcHs48_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_7"); + this.readAreaPlcHs48_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_8"); + this.readAreaPlcHs48_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_9"); + this.readAreaPlcHs48_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_10"); + this.readAreaPlcHs48_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_11"); + this.readAreaPlcHs48_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_12"); + this.readAreaPlcHs48_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_13"); + this.readAreaPlcHs48_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_14"); + this.readAreaPlcHs48_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_15"); + this.readAreaPlcHs48_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_16"); + + this.readAreaPlcHs47_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_1"); + this.readAreaPlcHs47_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_2"); + this.readAreaPlcHs47_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_3"); + this.readAreaPlcHs47_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_4"); + this.readAreaPlcHs47_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_5"); + this.readAreaPlcHs47_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_6"); + this.readAreaPlcHs47_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_7"); + this.readAreaPlcHs47_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_8"); + this.readAreaPlcHs47_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_9"); + this.readAreaPlcHs47_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_10"); + this.readAreaPlcHs47_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_11"); + this.readAreaPlcHs47_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_12"); + this.readAreaPlcHs47_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_13"); + this.readAreaPlcHs47_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_14"); + this.readAreaPlcHs47_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_15"); + this.readAreaPlcHs47_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_16"); + + + + this.readAreaPlcHs46_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_1"); + this.readAreaPlcHs46_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_2"); + this.readAreaPlcHs46_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_3"); + this.readAreaPlcHs46_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_4"); + this.readAreaPlcHs46_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_5"); + this.readAreaPlcHs46_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_6"); + this.readAreaPlcHs46_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_7"); + this.readAreaPlcHs46_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_8"); + this.readAreaPlcHs46_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_9"); + this.readAreaPlcHs46_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_10"); + this.readAreaPlcHs46_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_11"); + this.readAreaPlcHs46_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_12"); + this.readAreaPlcHs46_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_13"); + this.readAreaPlcHs46_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_14"); + this.readAreaPlcHs46_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_15"); + this.readAreaPlcHs46_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_16"); + + + this.readAreaPlcHs45_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_1"); + this.readAreaPlcHs45_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_2"); + this.readAreaPlcHs45_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_3"); + this.readAreaPlcHs45_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_4"); + this.readAreaPlcHs45_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_5"); + this.readAreaPlcHs45_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_6"); + this.readAreaPlcHs45_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_7"); + this.readAreaPlcHs45_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_8"); + this.readAreaPlcHs45_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_9"); + this.readAreaPlcHs45_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_10"); + this.readAreaPlcHs45_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_11"); + this.readAreaPlcHs45_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_12"); + this.readAreaPlcHs45_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_13"); + this.readAreaPlcHs45_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_14"); + this.readAreaPlcHs45_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_15"); + this.readAreaPlcHs45_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_16"); + + this.readAreaPlcHs44_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_1"); + this.readAreaPlcHs44_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_2"); + this.readAreaPlcHs44_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_3"); + this.readAreaPlcHs44_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_4"); + this.readAreaPlcHs44_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_5"); + this.readAreaPlcHs44_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_6"); + this.readAreaPlcHs44_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_7"); + this.readAreaPlcHs44_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_8"); + this.readAreaPlcHs44_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_9"); + this.readAreaPlcHs44_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_10"); + this.readAreaPlcHs44_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_11"); + this.readAreaPlcHs44_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_12"); + this.readAreaPlcHs44_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_13"); + this.readAreaPlcHs44_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_14"); + this.readAreaPlcHs44_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_15"); + this.readAreaPlcHs44_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_16"); + + + this.readAreaPlcHs43_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_1"); + this.readAreaPlcHs43_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_2"); + this.readAreaPlcHs43_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_3"); + this.readAreaPlcHs43_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_4"); + this.readAreaPlcHs43_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_5"); + this.readAreaPlcHs43_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_6"); + this.readAreaPlcHs43_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_7"); + this.readAreaPlcHs43_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_8"); + this.readAreaPlcHs43_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_9"); + this.readAreaPlcHs43_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_10"); + this.readAreaPlcHs43_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_11"); + this.readAreaPlcHs43_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_12"); + this.readAreaPlcHs43_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_13"); + this.readAreaPlcHs43_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_14"); + this.readAreaPlcHs43_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_15"); + this.readAreaPlcHs43_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_16"); + + + this.readAreaPlcHs42_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_1"); + this.readAreaPlcHs42_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_2"); + this.readAreaPlcHs42_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_3"); + this.readAreaPlcHs42_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_4"); + this.readAreaPlcHs42_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_5"); + this.readAreaPlcHs42_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_6"); + this.readAreaPlcHs42_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_7"); + this.readAreaPlcHs42_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_8"); + this.readAreaPlcHs42_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_9"); + this.readAreaPlcHs42_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_10"); + this.readAreaPlcHs42_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_11"); + this.readAreaPlcHs42_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_12"); + this.readAreaPlcHs42_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_13"); + this.readAreaPlcHs42_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_14"); + this.readAreaPlcHs42_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_15"); + this.readAreaPlcHs42_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_16"); + + this.readAreaPlcHs41_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_1"); + this.readAreaPlcHs41_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_2"); + this.readAreaPlcHs41_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_3"); + this.readAreaPlcHs41_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_4"); + this.readAreaPlcHs41_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_5"); + this.readAreaPlcHs41_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_6"); + this.readAreaPlcHs41_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_7"); + this.readAreaPlcHs41_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_8"); + this.readAreaPlcHs41_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_9"); + this.readAreaPlcHs41_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_10"); + this.readAreaPlcHs41_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_11"); + this.readAreaPlcHs41_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_12"); + this.readAreaPlcHs41_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_13"); + this.readAreaPlcHs41_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_14"); + this.readAreaPlcHs41_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_15"); + this.readAreaPlcHs41_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_16"); + + this.client = tp; + } + + public void run() { + + Iterator iterobj; + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + ((DSSTabSel) (((ArrayList) hsSysParam.get("DSSTabSel")).get(0))).jTextArea.setCaretPosition( + ((DSSTabSel) (((ArrayList) hsSysParam.get("DSSTabSel")).get(0))).jTextArea.getText().length() + - 20); + try { + + if (readAreaPlcHs50_1 != null) { + iterobj = readAreaPlcHs50_1.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_1(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs50_2 != null) { + iterobj = readAreaPlcHs50_2.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_2(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs50_3 != null) { + iterobj = readAreaPlcHs50_3.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_3(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs50_4 != null) { + iterobj = readAreaPlcHs50_4.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_4(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs50_5 != null) { + iterobj = readAreaPlcHs50_5.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_5(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs50_6 != null) { + iterobj = readAreaPlcHs50_6.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_6(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs50_7 != null) { + iterobj = readAreaPlcHs50_7.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_7(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs50_8 != null) { + iterobj = readAreaPlcHs50_8.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_8(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs50_9 != null) { + iterobj = readAreaPlcHs50_9.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_9(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs50_10 != null) { + iterobj = readAreaPlcHs50_10.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_10(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs50_11 != null) { + iterobj = readAreaPlcHs50_11.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_11(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs50_12 != null) { + iterobj = readAreaPlcHs50_12.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_12(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs50_13 != null) { + iterobj = readAreaPlcHs50_13.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_13(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs50_14 != null) { + iterobj = readAreaPlcHs50_14.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_14(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs50_15 != null) { + iterobj = readAreaPlcHs50_15.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_15(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs50_16 != null) { + iterobj = readAreaPlcHs50_16.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb50_16(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + //---------------------------------------- + if (readAreaPlcHs49_1 != null) { + iterobj = readAreaPlcHs49_1.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_1(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs49_2 != null) { + iterobj = readAreaPlcHs49_2.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_2(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs49_3 != null) { + iterobj = readAreaPlcHs49_3.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_3(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs49_4 != null) { + iterobj = readAreaPlcHs49_4.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_4(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs49_5 != null) { + iterobj = readAreaPlcHs49_5.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_5(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs49_6 != null) { + iterobj = readAreaPlcHs49_6.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_6(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs49_7 != null) { + iterobj = readAreaPlcHs49_7.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_7(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs49_8 != null) { + iterobj = readAreaPlcHs49_8.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_8(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs49_9 != null) { + iterobj = readAreaPlcHs49_9.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_9(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs49_10 != null) { + iterobj = readAreaPlcHs49_10.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_10(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs49_11 != null) { + iterobj = readAreaPlcHs49_11.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_11(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs49_12 != null) { + iterobj = readAreaPlcHs49_12.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_12(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs49_13 != null) { + iterobj = readAreaPlcHs49_13.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_13(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs49_14 != null) { + iterobj = readAreaPlcHs49_14.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_14(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs49_15 != null) { + iterobj = readAreaPlcHs49_15.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_15(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs49_16 != null) { + iterobj = readAreaPlcHs49_16.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb49_16(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + //=========================================================== + if (readAreaPlcHs48_1 != null) { + iterobj = readAreaPlcHs48_1.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_1(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs48_2 != null) { + iterobj = readAreaPlcHs48_2.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_2(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs48_3 != null) { + iterobj = readAreaPlcHs48_3.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_3(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs48_4 != null) { + iterobj = readAreaPlcHs48_4.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_4(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs48_5 != null) { + iterobj = readAreaPlcHs48_5.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_5(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs48_6 != null) { + iterobj = readAreaPlcHs48_6.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_6(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs48_7 != null) { + iterobj = readAreaPlcHs48_7.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_7(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs48_8 != null) { + iterobj = readAreaPlcHs48_8.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_8(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs48_9 != null) { + iterobj = readAreaPlcHs48_9.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_9(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs48_10 != null) { + iterobj = readAreaPlcHs48_10.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_10(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs48_11 != null) { + iterobj = readAreaPlcHs48_11.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_11(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs48_12 != null) { + iterobj = readAreaPlcHs48_12.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_12(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs48_13 != null) { + iterobj = readAreaPlcHs48_13.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_13(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs48_14 != null) { + iterobj = readAreaPlcHs48_14.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_14(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs48_15 != null) { + iterobj = readAreaPlcHs48_15.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_15(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs48_16 != null) { + iterobj = readAreaPlcHs48_16.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb48_16(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + + //=========================================================== + if (readAreaPlcHs47_1 != null) { + iterobj = readAreaPlcHs47_1.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_1(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs47_2 != null) { + iterobj = readAreaPlcHs47_2.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_2(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs47_3 != null) { + iterobj = readAreaPlcHs47_3.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_3(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs47_4 != null) { + iterobj = readAreaPlcHs47_4.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_4(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs47_5 != null) { + iterobj = readAreaPlcHs47_5.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_5(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs47_6 != null) { + iterobj = readAreaPlcHs47_6.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_6(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs47_7 != null) { + iterobj = readAreaPlcHs47_7.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_7(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs47_8 != null) { + iterobj = readAreaPlcHs47_8.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_8(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs47_9 != null) { + iterobj = readAreaPlcHs47_9.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_9(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs47_10 != null) { + iterobj = readAreaPlcHs47_10.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_10(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs47_11 != null) { + iterobj = readAreaPlcHs47_11.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_11(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs47_12 != null) { + iterobj = readAreaPlcHs47_12.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_12(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs47_13 != null) { + iterobj = readAreaPlcHs47_13.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_13(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs47_14 != null) { + iterobj = readAreaPlcHs47_14.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_14(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs47_15 != null) { + iterobj = readAreaPlcHs47_15.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_15(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs47_16 != null) { + iterobj = readAreaPlcHs47_16.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb47_16(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + //=========================================================== + if (readAreaPlcHs46_1 != null) { + iterobj = readAreaPlcHs46_1.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_1(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs46_2 != null) { + iterobj = readAreaPlcHs46_2.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_2(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs46_3 != null) { + iterobj = readAreaPlcHs46_3.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_3(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs46_4 != null) { + iterobj = readAreaPlcHs46_4.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_4(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs46_5 != null) { + iterobj = readAreaPlcHs46_5.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_5(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs46_6 != null) { + iterobj = readAreaPlcHs46_6.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_6(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs46_7 != null) { + iterobj = readAreaPlcHs46_7.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_7(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs46_8 != null) { + iterobj = readAreaPlcHs46_8.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_8(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs46_9 != null) { + iterobj = readAreaPlcHs46_9.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_9(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs46_10 != null) { + iterobj = readAreaPlcHs46_10.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_10(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs46_11 != null) { + iterobj = readAreaPlcHs46_11.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_11(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs46_12 != null) { + iterobj = readAreaPlcHs46_12.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_12(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs46_13 != null) { + iterobj = readAreaPlcHs46_13.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_13(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs46_14 != null) { + iterobj = readAreaPlcHs46_14.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_14(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs46_15 != null) { + iterobj = readAreaPlcHs46_15.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_15(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs46_16 != null) { + iterobj = readAreaPlcHs46_16.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb46_16(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + + + + //=========================================================== + if (readAreaPlcHs45_1 != null) { + iterobj = readAreaPlcHs45_1.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_1(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs45_2 != null) { + iterobj = readAreaPlcHs45_2.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_2(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs45_3 != null) { + iterobj = readAreaPlcHs45_3.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_3(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs45_4 != null) { + iterobj = readAreaPlcHs45_4.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_4(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs45_5 != null) { + iterobj = readAreaPlcHs45_5.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_5(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs45_6 != null) { + iterobj = readAreaPlcHs45_6.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_6(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs45_7 != null) { + iterobj = readAreaPlcHs45_7.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_7(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs45_8 != null) { + iterobj = readAreaPlcHs45_8.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_8(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs45_9 != null) { + iterobj = readAreaPlcHs45_9.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_9(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs45_10 != null) { + iterobj = readAreaPlcHs45_10.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_10(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs45_11 != null) { + iterobj = readAreaPlcHs45_11.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_11(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs45_12 != null) { + iterobj = readAreaPlcHs45_12.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_12(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs45_13 != null) { + iterobj = readAreaPlcHs45_13.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_13(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs45_14 != null) { + iterobj = readAreaPlcHs45_14.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_14(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs45_15 != null) { + iterobj = readAreaPlcHs45_15.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_15(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs45_16 != null) { + iterobj = readAreaPlcHs45_16.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb45_16(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + + + //=========================================================== + if (readAreaPlcHs44_1 != null) { + iterobj = readAreaPlcHs44_1.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_1(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs44_2 != null) { + iterobj = readAreaPlcHs44_2.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_2(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs44_3 != null) { + iterobj = readAreaPlcHs44_3.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_3(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs44_4 != null) { + iterobj = readAreaPlcHs44_4.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_4(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs44_5 != null) { + iterobj = readAreaPlcHs44_5.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_5(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs44_6 != null) { + iterobj = readAreaPlcHs44_6.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_6(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs44_7 != null) { + iterobj = readAreaPlcHs44_7.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_7(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs44_8 != null) { + iterobj = readAreaPlcHs44_8.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_8(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs44_9 != null) { + iterobj = readAreaPlcHs44_9.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_9(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs44_10 != null) { + iterobj = readAreaPlcHs44_10.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_10(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs44_11 != null) { + iterobj = readAreaPlcHs44_11.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_11(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs44_12 != null) { + iterobj = readAreaPlcHs44_12.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_12(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs44_13 != null) { + iterobj = readAreaPlcHs44_13.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_13(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs44_14 != null) { + iterobj = readAreaPlcHs44_14.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_14(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs44_15 != null) { + iterobj = readAreaPlcHs44_15.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_15(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs44_16 != null) { + iterobj = readAreaPlcHs44_16.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb44_16(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + + + + //=========================================================== + if (readAreaPlcHs43_1 != null) { + iterobj = readAreaPlcHs43_1.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_1(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs43_2 != null) { + iterobj = readAreaPlcHs43_2.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_2(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs43_3 != null) { + iterobj = readAreaPlcHs43_3.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_3(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs43_4 != null) { + iterobj = readAreaPlcHs43_4.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_4(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs43_5 != null) { + iterobj = readAreaPlcHs43_5.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_5(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs43_6 != null) { + iterobj = readAreaPlcHs43_6.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_6(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs43_7 != null) { + iterobj = readAreaPlcHs43_7.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_7(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs43_8 != null) { + iterobj = readAreaPlcHs43_8.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_8(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs43_9 != null) { + iterobj = readAreaPlcHs43_9.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_9(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs43_10 != null) { + iterobj = readAreaPlcHs43_10.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_10(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs43_11 != null) { + iterobj = readAreaPlcHs43_11.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_11(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs43_12 != null) { + iterobj = readAreaPlcHs43_12.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_12(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs43_13 != null) { + iterobj = readAreaPlcHs43_13.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_13(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs43_14 != null) { + iterobj = readAreaPlcHs43_14.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_14(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs43_15 != null) { + iterobj = readAreaPlcHs43_15.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_15(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs43_16 != null) { + iterobj = readAreaPlcHs43_16.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb43_16(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + //=========================================================== + if (readAreaPlcHs42_1 != null) { + iterobj = readAreaPlcHs42_1.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_1(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs42_2 != null) { + iterobj = readAreaPlcHs42_2.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_2(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs42_3 != null) { + iterobj = readAreaPlcHs42_3.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_3(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs42_4 != null) { + iterobj = readAreaPlcHs42_4.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_4(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs42_5 != null) { + iterobj = readAreaPlcHs42_5.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_5(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs42_6 != null) { + iterobj = readAreaPlcHs42_6.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_6(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs42_7 != null) { + iterobj = readAreaPlcHs42_7.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_7(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs42_8 != null) { + iterobj = readAreaPlcHs42_8.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_8(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs42_9 != null) { + iterobj = readAreaPlcHs42_9.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_9(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs42_10 != null) { + iterobj = readAreaPlcHs42_10.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_10(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs42_11 != null) { + iterobj = readAreaPlcHs42_11.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_11(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs42_12 != null) { + iterobj = readAreaPlcHs42_12.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_12(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs42_13 != null) { + iterobj = readAreaPlcHs42_13.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_13(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs42_14 != null) { + iterobj = readAreaPlcHs42_14.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_14(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs42_15 != null) { + iterobj = readAreaPlcHs42_15.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_15(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs42_16 != null) { + iterobj = readAreaPlcHs42_16.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb42_16(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + //=========================================================== + if (readAreaPlcHs41_1 != null) { + iterobj = readAreaPlcHs41_1.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_1(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs41_2 != null) { + iterobj = readAreaPlcHs41_2.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_2(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs41_3 != null) { + iterobj = readAreaPlcHs41_3.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_3(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs41_4 != null) { + iterobj = readAreaPlcHs41_4.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_4(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs41_5 != null) { + iterobj = readAreaPlcHs41_5.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_5(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs41_6 != null) { + iterobj = readAreaPlcHs41_6.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_6(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs41_7 != null) { + iterobj = readAreaPlcHs41_7.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_7(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs41_8 != null) { + iterobj = readAreaPlcHs41_8.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_8(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs41_9 != null) { + iterobj = readAreaPlcHs41_9.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_9(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs41_10 != null) { + iterobj = readAreaPlcHs41_10.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_10(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs41_11 != null) { + iterobj = readAreaPlcHs41_11.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_11(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs41_12 != null) { + iterobj = readAreaPlcHs41_12.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_12(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs41_13 != null) { + iterobj = readAreaPlcHs41_13.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_13(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs41_14 != null) { + iterobj = readAreaPlcHs41_14.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_14(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + if (readAreaPlcHs41_15 != null) { + iterobj = readAreaPlcHs41_15.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_15(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + if (readAreaPlcHs41_16 != null) { + iterobj = readAreaPlcHs41_16.entrySet().iterator(); + while (iterobj.hasNext()) { + Map.Entry entry = (Map.Entry) iterobj.next(); + ReadAreaPlcInterface plcVar = (ReadAreaPlcInterface) entry.getValue(); + if (client != null && client.IsConnect()) { + try { + + plcVar.analysisDb41_16(); + } catch (Exception ex) { + } + } else { + break; + } + } + } + + + + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } +} diff --git a/src/org/s7/standard/ynuo/WriteDotPlcInterface.java b/src/org/s7/standard/ynuo/WriteDotPlcInterface.java new file mode 100644 index 0000000..94fd9ba --- /dev/null +++ b/src/org/s7/standard/ynuo/WriteDotPlcInterface.java @@ -0,0 +1,155 @@ +package org.s7.standard.ynuo; + +import java.util.ArrayList; +import java.util.List; +import org.libnodave.Nodave; +import com.ricosoft.common.logger.Logger; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + * ½«Êý¾ÝдÈëµ½PLC»º´æÖÐ £¨±ê×¼Àࣩ + * + * @author admin + */ +public class WriteDotPlcInterface implements PlcInterface { + /* ×¢£ºÖ¸ÁîÀàÐÍ+ÀàÐÍÖµ ÊÇΨһµÄ */ + /* Ö¸ÁîÀàÐÍ */ + public String cmdtype = ""; + /* ÀàÐÍÖµ */ + public String cmdvalue = ""; + /* дÈëÍê³É±êʶ */ + public volatile boolean bflag = false; + + /* ½«Êý¾Ý¿âÖеÄÊý¾Ý¶ÁÈ¡µ½Ð´ÈëlsWriteGroupPlcÖÐ Ö»Óе±lsWriteGroupPlc.size()Ϊ0ʱ£¬²ÅÐèÒª´ÓÊý¾Ý¿âÖжÁÈ¡ */ + public List lsWriteGroupPlc = new ArrayList(); + + public WriteDotPlcInterface(String cmdtype, String cmdvalue) { + this.cmdtype = cmdtype; + this.cmdvalue = cmdvalue; + } + + public WriteDotPlcInterface() { + super(); + } + + /* ´ÓÊý¾Ý¿âÖжÁÈ¡Ïà¹ØµÄÖ¸ÁÉú³ÉPLC¿Éʶ±ðµÄÖ¸ÁWritePlcInterface.groupPlcObj£© */ + public int Analysis(String json) { + int back_msg = -1; + if (lsWriteGroupPlc != null && lsWriteGroupPlc.size() < 1) { + try { + JSONArray content = JSONArray.fromObject(json); + if (content != null && content.size() > 0) {// ½âÎöÊý¾ÝÌå + bflag = false;// дÈ뿪ʼ + for (int i = 0; i < content.size(); i++) { + JSONObject jo = content.getJSONObject(i); + WriteDotPlcInterface.groupPlcObj group = new WriteDotPlcInterface.groupPlcObj(); + group.DBnum = jo.getInt("DBnum"); + group.dtype = jo.getInt("dtype"); + group.len = jo.getInt("len"); + group.start = jo.getInt("start"); + group.value = jo.get("value"); + group.buffer = group.getBuffer(group.value, group.dtype, group.len); + lsWriteGroupPlc.add(group); + } + } + back_msg = 1;// ÍÆËͳɹ¦ + } catch (Exception e) { + Logger.error("дÈëÖ¸Áî" + json + "Òì³£" + e.getMessage()); + } finally { + bflag = true;// дÈëÍê³É + } + } + return back_msg; + } + + public class groupPlcObj { + int area = Nodave.DB; + /* DBºÅ */ + public int DBnum; + /* ¿ªÊ¼Î»Öà */ + public int start; + /* ×Ö½Ú³¤¶È */ + public int len; + /* Öµ */ + public Object value; + /* ÊýÖµÀàÐÍ */ + public int dtype; + /* ±äÁ¿Ãû³Æ */ + public String name; + /* ֵתΪ×Ö½Ú */ + public byte[] buffer; + + public groupPlcObj() { + } + + public groupPlcObj(int DBnum, int dtype, int len, int start, Object value) { + this.DBnum = DBnum; + this.dtype = dtype; + this.len = len; + this.start = start; + this.value = value; + this.buffer = getBuffer(value, dtype, len); + } + + public int getArea() { + return area; + } + + public int getDBnum() { + return DBnum; + } + + public int getStart() { + return start; + } + + public int getLen() { + return len; + } + + public Object getValue() { + return value; + } + + public int getDtype() { + return dtype; + } + + public String getName() { + return name; + } + + public byte[] getBuffer() { + return buffer; + } + + /** + * @param value + * ת»»Öµ + * @param dtype + * ÀàÐÍ + * @param len + * ×Ö½ÚÊý + * @return byte[] + */ + public byte[] getBuffer(Object value, int dtype, int len) { + + byte[] buffer = null; + if (dtype == BYTE) { + buffer = Nodave.bswap_8(Byte.parseByte(value.toString())); + } else if (dtype == FLOAT) { + buffer = Nodave.toPLCfloat(Float.parseFloat(value.toString())); + } else if (dtype == INT) { + buffer = Nodave.bswap_16(Integer.parseInt(value.toString())); + } else if (dtype == DINT) { + buffer = Nodave.bswap_32(Integer.parseInt(value.toString())); + } else if (dtype == CHAR) { + buffer = Nodave.bswap_8(Byte.parseByte(value.toString())); + } else if (dtype == STRING) { + buffer = Nodave.bswap_64(Long.parseLong(value.toString())); + } + return buffer; + } + } +} diff --git a/src/org/s7/standard/ynuo/client/IsoTcpClient100.java b/src/org/s7/standard/ynuo/client/IsoTcpClient100.java new file mode 100644 index 0000000..a6ae3f0 --- /dev/null +++ b/src/org/s7/standard/ynuo/client/IsoTcpClient100.java @@ -0,0 +1,800 @@ +package org.s7.standard.ynuo.client; + +import com.ricosoft.common.logger.Logger; +import org.libnodave.Nodave; +import org.libnodave.PLCinterface; +import org.libnodave.TCPConnection; +import org.s7.standard.ynuo.ReadAreaPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface.groupPlcObj; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.*; + +public class IsoTcpClient100 extends Thread { + /* ʱ¼ä´Á */ + long t1, t2; + /* ipµØÖ· */ + String strIp = ""; + /* ¶Ë¿ÚºÅ */ + int iPort = 102; + /* ²Û¿ÚºÅ */ + int slot = 1; + PLCinterface di; + TCPConnection dc; + /* socket¿Í»§¶Ë */ + Socket sock; + /* Êä³öÁ÷ */ + OutputStream oStream = null; + /* ÊäÈëÁ÷ */ + InputStream iStream = null; + /* дÈ뻺´æÊý¾Ý */ + byte[] by; + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable readAreaPlcHsMD101 = null; + public Hashtable readAreaPlcHsMD102 = null; + public Hashtable readAreaPlcHsMD103 = null; + public Hashtable readAreaPlcHsMD104 = null; + public Hashtable readAreaPlcHsMD105 = null; + public Hashtable readAreaPlcHsMD106 = null; + public Hashtable readAreaPlcHsMD107 = null; + public Hashtable readAreaPlcHsMD108 = null; + public Hashtable readAreaPlcHsMD109 = null; + public Hashtable readAreaPlcHsMD110 = null; +// public Hashtable readAreaPlcHs2 = null; +// public Hashtable readAreaPlcHs3 = null; +// public Hashtable readAreaPlcHs4 = null; +// public Hashtable readAreaPlcHs5 = null; + + /* ´æ·ÅдÈëµÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable writePlcHs = null; + public Hashtable hsSysParam = null; + public Hashtable hsComParam = null; + + public IsoTcpClient100(Hashtable hsComParam, Hashtable hsSysParam) { + this.hsComParam = hsComParam; + this.hsSysParam = hsSysParam; + this.readAreaPlcHsMD101 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_101"); + this.readAreaPlcHsMD102 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_102"); + this.readAreaPlcHsMD103 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_103"); + this.readAreaPlcHsMD104 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_104"); + this.readAreaPlcHsMD105 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_105"); + this.readAreaPlcHsMD106 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_106"); + this.readAreaPlcHsMD107 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_107"); + this.readAreaPlcHsMD108 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_108"); + this.readAreaPlcHsMD109 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_109"); + this.readAreaPlcHsMD110 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_110"); +// this.readAreaPlcHs2 = (Hashtable) hsComParam.get("readAreaPlcHs1_2"); +// this.readAreaPlcHs3 = (Hashtable) hsComParam.get("readAreaPlcHs1_3"); +// this.readAreaPlcHs4 = (Hashtable) hsComParam.get("readAreaPlcHs1_4"); +// this.readAreaPlcHs5 = (Hashtable) hsComParam.get("readAreaPlcHs1_5"); + this.writePlcHs = (Hashtable) hsComParam.get("writePlcHs1"); + this.strIp = (String) hsComParam.get("strIp1"); + this.iPort = (Integer) hsComParam.get("iPort1"); + this.slot = (Integer) hsComParam.get("slot1"); + + } + + void ConnectServer() { + try { + sock = new Socket(strIp, iPort); + sock.setSoTimeout(6000); // ÉèÖó¬Ê±Ê±¼ä6Ãë + oStream = sock.getOutputStream(); + iStream = sock.getInputStream(); + + Nodave.Debug = 0x00;// ²»µ÷ʽ + di = new PLCinterface(oStream, iStream, "PLCName", 0, Nodave.PROTOCOL_ISOTCP); + dc = new TCPConnection(di, 0, slot); + + int res = dc.connectPLC(); + if (0 == res) { + setIsConnect(true); + } else { + } + } catch (IOException ioex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½Óʧ°Ü " + ioex.getMessage()); + } catch (Exception ex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½ÓÒì³£ " + ex.getMessage()); + } + } + + public void setIsConnect(boolean bflag) { + if (di != null) { + di.isConnect = bflag; + } + } + + public boolean IsConnect() { + if (di != null) { + return di.isConnect; + } + return false; + } + + void closeServer() { + try { + setIsConnect(false); + clearReadDB(); + if (iStream != null) { + iStream.close(); + iStream = null; + } + } catch (IOException e) { + Logger.info("ÊäÈëÁ÷¹Ø±ÕÒì³£ " + e.getMessage() + strIp + " ¶Ë¿Ú£º" + iPort); + } + try { + if (oStream != null) { + oStream.close(); + oStream = null; + } + } catch (IOException e) { + Logger.error("Êä³öÁ÷¹Ø±ÕÒì³£ IP£º" + strIp + " ¶Ë¿Ú£º" + iPort + " " + e.getMessage()); + } + try { + if (sock != null) { + sock.close(); + sock = null; + } + + } catch (IOException e) { + Logger.error("socket¿Í»§¶Ë¹Ø±ÕÒì³£ IP£º" + strIp + " ¶Ë¿Ú£º" + iPort + e.getMessage()); + } + } + + void clearReadDB() { + if (readAreaPlcHsMD101 != null) { + Iterator iterR = readAreaPlcHsMD101.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD102 != null) { + Iterator iterR = readAreaPlcHsMD102.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD103 != null) { + Iterator iterR = readAreaPlcHsMD103.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD104 != null) { + Iterator iterR = readAreaPlcHsMD104.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD105 != null) { + Iterator iterR = readAreaPlcHsMD105.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD106 != null) { + Iterator iterR = readAreaPlcHsMD106.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD107 != null) { + Iterator iterR = readAreaPlcHsMD107.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD108 != null) { + Iterator iterR = readAreaPlcHsMD108.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD109 != null) { + Iterator iterR = readAreaPlcHsMD109.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHsMD110 != null) { + Iterator iterR = readAreaPlcHsMD110.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + } + + void reConnect() { + closeServer(); + ConnectServer(); + } + + public void run() { + Iterator iterR = null; + Iterator iterW = null; + List groups = null; + groupPlcObj group = null; + WriteDotPlcInterface plcWVar = null; + ReadAreaPlcInterface plcRVar = null; + Map.Entry entry = null; + int i = 0; + int iPrintcount = 5;// 5´Î½øÐдòÓ¡ + int currDecRun = 0;// µ±Ç°Ö´ÐдÎÊý + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + try { + if (IsConnect()) { + // ¶ÁÈ¡DB101¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ + ///Thread.sleep(100); + Date t = new Date(); + SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd hh:mm:ss.SSS"); + //System.out.println("101:----" + df.format(t)); + + try { + if (readAreaPlcHsMD101 != null) { + iterR = readAreaPlcHsMD101.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + //System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try{ + if (readAreaPlcHsMD102 != null) { + iterR = readAreaPlcHsMD102.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + // System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD103 != null) { + iterR = readAreaPlcHsMD103.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + //System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD104 != null) { + iterR = readAreaPlcHsMD104.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + //System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD105 != null) { + iterR = readAreaPlcHsMD105.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + // System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD106 != null) { + iterR = readAreaPlcHsMD106.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + //System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD107 != null) { + iterR = readAreaPlcHsMD107.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + //System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD108 != null) { + iterR = readAreaPlcHsMD108.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + //System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD109 != null) { + iterR = readAreaPlcHsMD109.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + + } catch (Exception ex) { + reConnect(); + //ex.printStackTrace(); + } + + try{ + if (readAreaPlcHsMD110 != null) { + iterR = readAreaPlcHsMD110.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + + } catch (Exception ex) { + reConnect(); + //ex.printStackTrace(); + } + + + // дÈëµ½DB¿éÖÐÖ¸¶¨µÄλÖà + try { + if (IsConnect()) { + if (writePlcHs != null) { + t1 = System.currentTimeMillis(); + iterW = writePlcHs.entrySet().iterator(); + if (iterW != null) { + while (iterW.hasNext()) { + entry = (Map.Entry) iterW.next(); + plcWVar = (WriteDotPlcInterface) entry.getValue(); + groups = plcWVar.lsWriteGroupPlc; + for (i = 0; i < groups.size(); i++) { + group = groups.get(i); + dc.writeBytes(group.getArea(), group.getDBnum(), group.getStart(), + group.getLen(), group.getBuffer()); + Logger.info(" DB" + group.getDBnum() + ":¿ªÊ¼-" + group.getStart() + " ³¤¶È-" + + group.getLen() + " Ï·¢Öµ-" + group.getValue()); + if (IsConnect()) { + plcWVar.lsWriteGroupPlc.remove(i); + i--; + } else { + Logger.error("дÈëµ½DB101¿éÖÐÖ¸¶¨µÄλÖà ÖжÏ"); + break; + } + } + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + + } else { + reConnect(); + } + Thread.sleep(1000); + } catch (Exception ex) { + reConnect(); + } + // ÿ´ÎÑ­»·´ò¿ª¹Ø±ÕÁ´½Ó + //reConnect(); + } + closeServer(); + } + + // ½«Ö¸¶¨byteÊý×éÒÔ16½øÖƵÄÐÎʽ´òÓ¡µ½¿ØÖÆÌ¨ + public static String printHexString(byte[] b, int length) { + String re = ""; + for (int i = 0; i < length; i++) { + String hex = Integer.toHexString(b[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + re += hex.toUpperCase() + " "; + } + return re; + } + + public static void main(String arg[]) { + byte[] ss = new byte[5]; + ss[0] = 1; + ss[1] = 0; + ss[2] = 16; + ss[3] = 0; + ss[4] = 0; + int length = ss.length; + for (int i = ss.length - 1; i > 0; i--) { + if (ss[i] != 0) { + length = i + 1; + break; + } + } + + // ¶ÁÈ¡Á÷03 00 00 2B 02 F0 80 32 03 00 00 00 00 00 02 00 16 00 00 04 01 FF + // 04 00 90 + // 89 02 00 80 37 01 02 37 01 00 18 5E 03 78 05 02 03 + byte[] ssz = Nodave.bswap_16(6238);// 18 5E ÈÎÎñºÅ + System.out.println(printHexString(ssz, ssz.length)); + byte[] msgIn = new byte[90]; + msgIn[10] = (byte) 0x18; // µÚ36 + msgIn[11] = (byte) 0x5E; // µÚ37 + System.out.println(Nodave.SBEWord(msgIn, 10)); + } +} \ No newline at end of file diff --git a/src/org/s7/standard/ynuo/client/IsoTcpClient101.java b/src/org/s7/standard/ynuo/client/IsoTcpClient101.java new file mode 100644 index 0000000..16724f7 --- /dev/null +++ b/src/org/s7/standard/ynuo/client/IsoTcpClient101.java @@ -0,0 +1,804 @@ +package org.s7.standard.ynuo.client; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import org.libnodave.Nodave; +import org.libnodave.PLCinterface; +import org.libnodave.TCPConnection; +import org.s7.standard.ynuo.ReadAreaPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface.groupPlcObj; + +import com.ricosoft.common.logger.Logger; + +public class IsoTcpClient101 extends Thread { + /* ʱ¼ä´Á */ + long t1, t2; + /* ipµØÖ· */ + String strIp = ""; + /* ¶Ë¿ÚºÅ */ + int iPort = 102; + /* ²Û¿ÚºÅ */ + int slot = 1; + PLCinterface di; + TCPConnection dc; + /* socket¿Í»§¶Ë */ + Socket sock; + /* Êä³öÁ÷ */ + OutputStream oStream = null; + /* ÊäÈëÁ÷ */ + InputStream iStream = null; + /* дÈ뻺´æÊý¾Ý */ + byte[] by; + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable readAreaPlcHsMD101 = null; + public Hashtable readAreaPlcHsMD102 = null; + public Hashtable readAreaPlcHsMD103 = null; + public Hashtable readAreaPlcHsMD104 = null; + public Hashtable readAreaPlcHsMD105 = null; + public Hashtable readAreaPlcHsMD106 = null; + public Hashtable readAreaPlcHsMD107 = null; + public Hashtable readAreaPlcHsMD108 = null; + public Hashtable readAreaPlcHsMD109 = null; + public Hashtable readAreaPlcHsMD110 = null; +// public Hashtable readAreaPlcHs2 = null; +// public Hashtable readAreaPlcHs3 = null; +// public Hashtable readAreaPlcHs4 = null; +// public Hashtable readAreaPlcHs5 = null; + + /* ´æ·ÅдÈëµÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable writePlcHs = null; + public Hashtable hsSysParam = null; + public Hashtable hsComParam = null; + + public IsoTcpClient101(Hashtable hsComParam, Hashtable hsSysParam) { + this.hsComParam = hsComParam; + this.hsSysParam = hsSysParam; + this.readAreaPlcHsMD101 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_101"); + this.readAreaPlcHsMD102 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_102"); + this.readAreaPlcHsMD103 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_103"); + this.readAreaPlcHsMD104 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_104"); + this.readAreaPlcHsMD105 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_105"); + this.readAreaPlcHsMD106 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_106"); + this.readAreaPlcHsMD107 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_107"); + this.readAreaPlcHsMD108 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_108"); + this.readAreaPlcHsMD109 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_109"); + this.readAreaPlcHsMD110 = (Hashtable) hsComParam.get("readAreaPlcHs1MD_110"); +// this.readAreaPlcHs2 = (Hashtable) hsComParam.get("readAreaPlcHs1_2"); +// this.readAreaPlcHs3 = (Hashtable) hsComParam.get("readAreaPlcHs1_3"); +// this.readAreaPlcHs4 = (Hashtable) hsComParam.get("readAreaPlcHs1_4"); +// this.readAreaPlcHs5 = (Hashtable) hsComParam.get("readAreaPlcHs1_5"); + this.writePlcHs = (Hashtable) hsComParam.get("writePlcHs1"); + this.strIp = (String) hsComParam.get("strIp1"); + this.iPort = (Integer) hsComParam.get("iPort1"); + this.slot = (Integer) hsComParam.get("slot1"); + + } + + void ConnectServer() { + try { + sock = new Socket(strIp, iPort); + sock.setSoTimeout(6000); // ÉèÖó¬Ê±Ê±¼ä6Ãë + oStream = sock.getOutputStream(); + iStream = sock.getInputStream(); + + Nodave.Debug = 0x00;// ²»µ÷ʽ + di = new PLCinterface(oStream, iStream, "PLCName", 0, Nodave.PROTOCOL_ISOTCP); + dc = new TCPConnection(di, 0, slot); + + int res = dc.connectPLC(); + if (0 == res) { + setIsConnect(true); + } else { + } + } catch (IOException ioex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½Óʧ°Ü " + ioex.getMessage()); + } catch (Exception ex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½ÓÒì³£ " + ex.getMessage()); + } + } + + public void setIsConnect(boolean bflag) { + if (di != null) { + di.isConnect = bflag; + } + } + + public boolean IsConnect() { + if (di != null) { + return di.isConnect; + } + return false; + } + + void closeServer() { + try { + setIsConnect(false); + clearReadDB(); + if (iStream != null) { + iStream.close(); + iStream = null; + } + } catch (IOException e) { + Logger.info("ÊäÈëÁ÷¹Ø±ÕÒì³£ " + e.getMessage() + strIp + " ¶Ë¿Ú£º" + iPort); + } + try { + if (oStream != null) { + oStream.close(); + oStream = null; + } + } catch (IOException e) { + Logger.error("Êä³öÁ÷¹Ø±ÕÒì³£ IP£º" + strIp + " ¶Ë¿Ú£º" + iPort + " " + e.getMessage()); + } + try { + if (sock != null) { + sock.close(); + sock = null; + } + + } catch (IOException e) { + Logger.error("socket¿Í»§¶Ë¹Ø±ÕÒì³£ IP£º" + strIp + " ¶Ë¿Ú£º" + iPort + e.getMessage()); + } + } + + void clearReadDB() { + if (readAreaPlcHsMD101 != null) { + Iterator iterR = readAreaPlcHsMD101.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD102 != null) { + Iterator iterR = readAreaPlcHsMD102.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD103 != null) { + Iterator iterR = readAreaPlcHsMD103.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD104 != null) { + Iterator iterR = readAreaPlcHsMD104.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD105 != null) { + Iterator iterR = readAreaPlcHsMD105.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD106 != null) { + Iterator iterR = readAreaPlcHsMD106.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD107 != null) { + Iterator iterR = readAreaPlcHsMD107.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD108 != null) { + Iterator iterR = readAreaPlcHsMD108.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHsMD109 != null) { + Iterator iterR = readAreaPlcHsMD109.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHsMD110 != null) { + Iterator iterR = readAreaPlcHsMD110.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + } + + void reConnect() { + closeServer(); + ConnectServer(); + } + + public void run() { + Iterator iterR = null; + Iterator iterW = null; + List groups = null; + WriteDotPlcInterface.groupPlcObj group = null; + WriteDotPlcInterface plcWVar = null; + ReadAreaPlcInterface plcRVar = null; + Map.Entry entry = null; + int i = 0; + int iPrintcount = 5;// 5´Î½øÐдòÓ¡ + int currDecRun = 0;// µ±Ç°Ö´ÐдÎÊý + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + try { + if (IsConnect()) { + // ¶ÁÈ¡DB101¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ + ///Thread.sleep(100); + Date t = new Date(); + SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd hh:mm:ss.SSS"); + //System.out.println("101:----" + df.format(t)); + + try { + if (readAreaPlcHsMD101 != null) { + iterR = readAreaPlcHsMD101.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + //System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try{ + if (readAreaPlcHsMD102 != null) { + iterR = readAreaPlcHsMD102.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + // System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD103 != null) { + iterR = readAreaPlcHsMD103.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + //System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD104 != null) { + iterR = readAreaPlcHsMD104.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + //System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD105 != null) { + iterR = readAreaPlcHsMD105.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + // System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD106 != null) { + iterR = readAreaPlcHsMD106.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + //System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD107 != null) { + iterR = readAreaPlcHsMD107.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + //System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD108 != null) { + iterR = readAreaPlcHsMD108.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + //System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try{ + if (readAreaPlcHsMD109 != null) { + iterR = readAreaPlcHsMD109.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + + } catch (Exception ex) { + reConnect(); + //ex.printStackTrace(); + } + + try{ + if (readAreaPlcHsMD110 != null) { + iterR = readAreaPlcHsMD110.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + + } catch (Exception ex) { + reConnect(); + //ex.printStackTrace(); + } + + + // дÈëµ½DB¿éÖÐÖ¸¶¨µÄλÖà + try { + if (IsConnect()) { + if (writePlcHs != null) { + t1 = System.currentTimeMillis(); + iterW = writePlcHs.entrySet().iterator(); + if (iterW != null) { + while (iterW.hasNext()) { + entry = (Map.Entry) iterW.next(); + plcWVar = (WriteDotPlcInterface) entry.getValue(); + groups = plcWVar.lsWriteGroupPlc; + for (i = 0; i < groups.size(); i++) { + group = groups.get(i); + dc.writeBytes(group.getArea(), group.getDBnum(), group.getStart(), + group.getLen(), group.getBuffer()); + Logger.info(" DB" + group.getDBnum() + ":¿ªÊ¼-" + group.getStart() + " ³¤¶È-" + + group.getLen() + " Ï·¢Öµ-" + group.getValue()); + if (IsConnect()) { + plcWVar.lsWriteGroupPlc.remove(i); + i--; + } else { + Logger.error("дÈëµ½DB101¿éÖÐÖ¸¶¨µÄλÖà ÖжÏ"); + break; + } + } + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + + } else { + reConnect(); + } + Thread.sleep(1000); + } catch (Exception ex) { + reConnect(); + } + // ÿ´ÎÑ­»·´ò¿ª¹Ø±ÕÁ´½Ó + //reConnect(); + } + closeServer(); + } + + // ½«Ö¸¶¨byteÊý×éÒÔ16½øÖƵÄÐÎʽ´òÓ¡µ½¿ØÖÆÌ¨ + public static String printHexString(byte[] b, int length) { + String re = ""; + for (int i = 0; i < length; i++) { + String hex = Integer.toHexString(b[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + re += hex.toUpperCase() + " "; + } + return re; + } + + public static void main(String arg[]) { + byte[] ss = new byte[5]; + ss[0] = 1; + ss[1] = 0; + ss[2] = 16; + ss[3] = 0; + ss[4] = 0; + int length = ss.length; + for (int i = ss.length - 1; i > 0; i--) { + if (ss[i] != 0) { + length = i + 1; + break; + } + } + + // ¶ÁÈ¡Á÷03 00 00 2B 02 F0 80 32 03 00 00 00 00 00 02 00 16 00 00 04 01 FF + // 04 00 90 + // 89 02 00 80 37 01 02 37 01 00 18 5E 03 78 05 02 03 + byte[] ssz = Nodave.bswap_16(6238);// 18 5E ÈÎÎñºÅ + System.out.println(printHexString(ssz, ssz.length)); + byte[] msgIn = new byte[90]; + msgIn[10] = (byte) 0x18; // µÚ36 + msgIn[11] = (byte) 0x5E; // µÚ37 + System.out.println(Nodave.SBEWord(msgIn, 10)); + } +} \ No newline at end of file diff --git a/src/org/s7/standard/ynuo/client/IsoTcpClient102.java b/src/org/s7/standard/ynuo/client/IsoTcpClient102.java new file mode 100644 index 0000000..ee440e3 --- /dev/null +++ b/src/org/s7/standard/ynuo/client/IsoTcpClient102.java @@ -0,0 +1,860 @@ +/* + Test and demo program for Libnodave, a free communication libray for Siemens S7. + + ********************************************************************** + * WARNING: This and other test programs overwrite data in your PLC. * + * DO NOT use it on PLC's when anything is connected to their outputs.* + * This is alpha software. Use entirely on your own risk. * + ********************************************************************** + + (C) Thomas Hergenhahn (thomas.hergenhahn@web.de) 2002, 2004. + + This is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with Visual; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +package org.s7.standard.ynuo.client; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import org.libnodave.Nodave; +import org.libnodave.PLCinterface; +import org.libnodave.TCPConnection; +import org.s7.standard.ynuo.ReadAreaPlcInterface; +import org.s7.standard.ynuo.ReadDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface.groupPlcObj; + +import com.ricosoft.common.logger.Logger; + +public class IsoTcpClient102 extends Thread { + /* ʱ¼ä´Á */ + long t1, t2; + /* ipµØÖ· */ + String strIp = ""; + // String strIp2 = ""; + /* ¶Ë¿ÚºÅ */ + int iPort = 102; + // int iPort2 = 102; + /* ²Û¿ÚºÅ */ + int slot = 1; + // int slot2 = 1; + PLCinterface di; + // PLCinterface di2; + TCPConnection dc; + // TCPConnection dc2; + /* socket¿Í»§¶Ë */ + Socket sock; + // Socket sock2; + /* Êä³öÁ÷ */ + OutputStream oStream = null; + // OutputStream oStream2 = null; + /* ÊäÈëÁ÷ */ + InputStream iStream = null; + // InputStream iStream2 = null; + /* дÈ뻺´æÊý¾Ý */ + byte[] by; + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable readAreaPlcHs101 = null; + public Hashtable readAreaPlcHs102 = null; + public Hashtable readAreaPlcHs104 = null; + public Hashtable readAreaPlcHs105 = null; + public Hashtable readAreaPlcHs106 = null; + public Hashtable readAreaPlcHs107 = null; + public Hashtable readAreaPlcHs103 = null; + public Hashtable readAreaPlcHs105_2 = null; + public Hashtable readAreaPlcHs151 = null; + + public Hashtable readAreaPlcHs108 = null; + /* ´æ·Å¶ÁÈ¡µÄDBÉ¢×Ö½ÚÐÅÏ¢ */ + + /* ´æ·ÅдÈëµÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable writePlcHs = null; + public Hashtable hsSysParam = null; + public Hashtable hsComParam = null; + + public IsoTcpClient102(Hashtable hsComParam, Hashtable hsSysParam) { + this.hsComParam = hsComParam; + this.hsSysParam = hsSysParam; + + this.readAreaPlcHs104 = (Hashtable) hsComParam.get("readAreaPlcHsDB104"); + this.readAreaPlcHs102 = (Hashtable) hsComParam.get("readAreaPlcHsDB102"); + this.readAreaPlcHs101 = (Hashtable) hsComParam.get("readAreaPlcHsDB101"); + + this.readAreaPlcHs106 = (Hashtable) hsComParam.get("readAreaPlcHsDB106"); + this.readAreaPlcHs107 = (Hashtable) hsComParam.get("readAreaPlcHsDB107"); + this.readAreaPlcHs103 = (Hashtable) hsComParam.get("readAreaPlcHsDB103"); + this.readAreaPlcHs105 = (Hashtable) hsComParam.get("readAreaPlcHsDB105"); + this.readAreaPlcHs105_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB105_2"); + + this.readAreaPlcHs151 = (Hashtable) hsComParam.get("readAreaPlcHsDB151"); + + this.readAreaPlcHs108 = (Hashtable) hsComParam.get("readAreaPlcHsDB108"); + + this.writePlcHs = (Hashtable) hsComParam.get("writePlcHs2"); + this.strIp = (String) hsComParam.get("strIp2"); + this.iPort = (Integer) hsComParam.get("iPort2"); + this.slot = (Integer) hsComParam.get("slot2"); + + + } + + void ConnectServer() { + try { + sock = new Socket(strIp, iPort); + sock.setSoTimeout(6000); // ÉèÖó¬Ê±Ê±¼ä6Ãë + oStream = sock.getOutputStream(); + iStream = sock.getInputStream(); + + Nodave.Debug = 0x00;// ²»µ÷ʽ + di = new PLCinterface(oStream, iStream, "PLCName", 0, Nodave.PROTOCOL_ISOTCP); + dc = new TCPConnection(di, 0, slot); + + int res = dc.connectPLC(); + if (0 == res) { + setIsConnect(true); + } else { + } + } catch (IOException ioex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½Óʧ°Ü " + ioex.getMessage()); + } catch (Exception ex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½ÓÒì³£ " + ex.getMessage()); + } + } + + public void setIsConnect(boolean bflag) { + if (di != null) { + di.isConnect = bflag; + } + } + + public boolean IsConnect() { + if (di != null) { + return di.isConnect; + } + return false; + } + + void closeServer() { + try { + setIsConnect(false); + clearReadDB(); + if (iStream != null) { + iStream.close(); + iStream = null; + } + } catch (IOException e) { + Logger.info("ÊäÈëÁ÷¹Ø±ÕÒì³£ " + e.getMessage() + strIp + " ¶Ë¿Ú£º" + iPort); + } + try { + if (oStream != null) { + oStream.close(); + oStream = null; + } + } catch (IOException e) { + Logger.error("Êä³öÁ÷¹Ø±ÕÒì³£ IP£º" + strIp + " ¶Ë¿Ú£º" + iPort + " " + e.getMessage()); + } + try { + if (sock != null) { + sock.close(); + sock = null; + } + + } catch (IOException e) { + Logger.error("socket¿Í»§¶Ë¹Ø±ÕÒì³£ IP£º" + strIp + " ¶Ë¿Ú£º" + iPort + e.getMessage()); + } + } + + @SuppressWarnings("rawtypes") + void clearReadDB() { + + if (readAreaPlcHs101 != null) { + Iterator iterR = readAreaPlcHs101.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs102 != null) { + Iterator iterR = readAreaPlcHs102.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs104 != null) { + + Iterator iterR = readAreaPlcHs104.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs105 != null) { + Iterator iterR = readAreaPlcHs105.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs106 != null) { + Iterator iterR = readAreaPlcHs106.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs107 != null) { + Iterator iterR = readAreaPlcHs107.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs105_2 != null) { + Iterator iterR = readAreaPlcHs105_2.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs103 != null) { + Iterator iterR = readAreaPlcHs103.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs151 != null) { + Iterator iterR = readAreaPlcHs151.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + + //2021-2-10 + if (readAreaPlcHs108 != null) { + Iterator iterR = readAreaPlcHs108.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + } + + void reConnect() { + closeServer(); + ConnectServer(); + } + + public void run() { + Iterator iterR = null; + Iterator iterW = null; + List groups = null; + WriteDotPlcInterface.groupPlcObj group = null; + WriteDotPlcInterface plcWVar = null; + ReadAreaPlcInterface plcRVar = null; + ReadDotPlcInterface plcRDotVar = null; + Map.Entry entry = null; + int i = 0, j = 0; + boolean ReConn = false; + int iPrintcount = 5;// 5´Î½øÐдòÓ¡ + int currDecRun = 0;// µ±Ç°Ö´ÐдÎÊý + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + try { + if (IsConnect()) { + //Thread.sleep(200); + + + Date t = new Date(); + SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss.SSS"); + //System.out.println("102:----" + df.format(t)); + // ¶ÁÈ¡DB101¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ + + try{ + if (readAreaPlcHs105_2 != null) { + iterR = readAreaPlcHs105_2.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + try{ + if (readAreaPlcHs107 != null) { + iterR = readAreaPlcHs107.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + try{ + if (readAreaPlcHs103 != null) { + iterR = readAreaPlcHs103.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + try{ + if (readAreaPlcHs106 != null) { + iterR = readAreaPlcHs106.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + try{ + if (readAreaPlcHs101 != null) { + iterR = readAreaPlcHs101.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + try{ + if (readAreaPlcHs102 != null) { + iterR = readAreaPlcHs102.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + try{ + if (readAreaPlcHs104 != null) { + iterR = readAreaPlcHs104.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + try{ + if (readAreaPlcHs105 != null) { + iterR = readAreaPlcHs105.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + try{ + if (readAreaPlcHs105_2 != null) { + iterR = readAreaPlcHs105_2.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + try{ + if (readAreaPlcHs151 != null) { + iterR = readAreaPlcHs151.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + + } catch (Exception ex) { + reConnect(); + } + + try { + if (IsConnect()) { + if (writePlcHs != null) { + iterW = writePlcHs.entrySet().iterator(); + if (iterW != null) { + while (iterW.hasNext()) { + entry = (Map.Entry) iterW.next(); + plcWVar = (WriteDotPlcInterface) entry.getValue(); + groups = plcWVar.lsWriteGroupPlc; + for (i = 0; i < groups.size(); i++) { + group = groups.get(i); + dc.writeBytes(group.getArea(), group.getDBnum(), group.getStart(), + group.getLen(), group.getBuffer()); + Logger.info(" DB" + group.getDBnum() + ":¿ªÊ¼-" + group.getStart() + " ³¤¶È-" + + group.getLen() + " Ï·¢Öµ-" + group.getValue()); + if (IsConnect()) { + plcWVar.lsWriteGroupPlc.remove(i); + i--; + } else { + Logger.error("дÈëµ½DB"+group.getDBnum()+"¿éÖÐÖ¸¶¨µÄλÖà ÖжÏ"); + break; + } + } + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + + //2021-2-10 + try{ + if (readAreaPlcHs108 != null) { + iterR = readAreaPlcHs108.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + + + + + } else { + reConnect(); + } + Thread.sleep(1000); + } catch (Exception ex) { + reConnect(); + } + //reConnect(); + } + closeServer(); + } + + // ½«Ö¸¶¨byteÊý×éÒÔ16½øÖƵÄÐÎʽ´òÓ¡µ½¿ØÖÆÌ¨ + public static String printHexString(byte[] b, int length) { + String re = ""; + for (int i = 0; i < length; i++) { + String hex = Integer.toHexString(b[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + re += hex.toUpperCase() + " "; + } + return re; + } + + public static void main(String arg[]) { + byte[] ss = new byte[5]; + ss[0] = 1; + ss[1] = 0; + ss[2] = 16; + ss[3] = 0; + ss[4] = 0; + int length = ss.length; + for (int i = ss.length - 1; i > 0; i--) { + if (ss[i] != 0) { + length = i + 1; + break; + } + } + + // ¶ÁÈ¡Á÷03 00 00 2B 02 F0 80 32 03 00 00 00 00 00 02 00 16 00 00 04 01 FF + // 04 00 90 + // 89 02 00 80 37 01 02 37 01 00 18 5E 03 78 05 02 03 + byte[] ssz = Nodave.bswap_16(6238);// 18 5E ÈÎÎñºÅ + System.out.println(printHexString(ssz, ssz.length)); + byte[] msgIn = new byte[90]; + msgIn[10] = (byte) 0x18; // µÚ36 + msgIn[11] = (byte) 0x5E; // µÚ37 + System.out.println(Nodave.SBEWord(msgIn, 10)); + } +} \ No newline at end of file diff --git a/src/org/s7/standard/ynuo/client/IsoTcpClient103.java b/src/org/s7/standard/ynuo/client/IsoTcpClient103.java new file mode 100644 index 0000000..b9d0f63 --- /dev/null +++ b/src/org/s7/standard/ynuo/client/IsoTcpClient103.java @@ -0,0 +1,371 @@ +/* + Test and demo program for Libnodave, a free communication libray for Siemens S7. + + ********************************************************************** + * WARNING: This and other test programs overwrite data in your PLC. * + * DO NOT use it on PLC's when anything is connected to their outputs.* + * This is alpha software. Use entirely on your own risk. * + ********************************************************************** + + (C) Thomas Hergenhahn (thomas.hergenhahn@web.de) 2002, 2004. + + This is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with Visual; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +package org.s7.standard.ynuo.client; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import org.libnodave.Nodave; +import org.libnodave.PLCinterface; +import org.libnodave.TCPConnection; +import org.s7.standard.ynuo.PlcBus; +import org.s7.standard.ynuo.ReadAreaPlcInterface; +import org.s7.standard.ynuo.ReadDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface.groupPlcObj; + +import com.ricosoft.common.logger.Logger; + +public class IsoTcpClient103 extends Thread { + /* ʱ¼ä´Á */ + long t1, t2; + /* ipµØÖ· */ + String strIp = ""; + /* ¶Ë¿ÚºÅ */ + int iPort = 102; + /* ²Û¿ÚºÅ */ + int slot = 1; + PLCinterface di; + TCPConnection dc; + /* socket¿Í»§¶Ë */ + Socket sock; + /* Êä³öÁ÷ */ + OutputStream oStream = null; + /* ÊäÈëÁ÷ */ + InputStream iStream = null; + /* дÈ뻺´æÊý¾Ý */ + byte[] by; + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable readAreaPlcHs201 = null; + public Hashtable readAreaPlcHs202 = null; + public Hashtable readAreaPlcHs203 = null; + public Hashtable readAreaPlcHs204 = null; + public Hashtable readAreaPlcHs205 = null; + public Hashtable readAreaPlcHs206 = null; + public Hashtable readAreaPlcHs207 = null; + public Hashtable readAreaPlcHs208 = null; + public Hashtable readAreaPlcHs209 = null; + public Hashtable readAreaPlcHs210 = null; + public Hashtable readAreaPlcHs211 = null; + public Hashtable readAreaPlcHs212 = null; + public Hashtable readAreaPlcHs213 = null; + public Hashtable readAreaPlcHs214 = null; + public Hashtable readAreaPlcHs215 = null; + + /* ´æ·ÅдÈëµÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable writePlcHs = null; + // public Hashtable writePlcHs2 = null; + public Hashtable hsSysParam = null; + public Hashtable hsComParam = null; + + @SuppressWarnings("unchecked") + public IsoTcpClient103(Hashtable hsComParam, Hashtable hsSysParam) { + this.hsComParam = hsComParam; + this.hsSysParam = hsSysParam; + this.readAreaPlcHs201 = (Hashtable) hsComParam.get("readAreaPlcHsDB201"); + this.readAreaPlcHs202 = (Hashtable) hsComParam.get("readAreaPlcHsDB202"); + this.readAreaPlcHs203 = (Hashtable) hsComParam.get("readAreaPlcHsDB203"); + this.readAreaPlcHs204 = (Hashtable) hsComParam.get("readAreaPlcHsDB204"); + this.readAreaPlcHs205 = (Hashtable) hsComParam.get("readAreaPlcHsDB205"); + this.readAreaPlcHs206 = (Hashtable) hsComParam.get("readAreaPlcHsDB206"); + this.readAreaPlcHs207 = (Hashtable) hsComParam.get("readAreaPlcHsDB207"); + this.readAreaPlcHs208 = (Hashtable) hsComParam.get("readAreaPlcHsDB208"); + this.readAreaPlcHs209 = (Hashtable) hsComParam.get("readAreaPlcHsDB209"); + this.readAreaPlcHs210 = (Hashtable) hsComParam.get("readAreaPlcHsDB210"); + this.readAreaPlcHs211 = (Hashtable) hsComParam.get("readAreaPlcHsDB211"); + this.readAreaPlcHs212 = (Hashtable) hsComParam.get("readAreaPlcHsDB212"); + this.readAreaPlcHs213 = (Hashtable) hsComParam.get("readAreaPlcHsDB213"); + this.readAreaPlcHs214 = (Hashtable) hsComParam.get("readAreaPlcHsDB214"); + this.readAreaPlcHs215 = (Hashtable) hsComParam.get("readAreaPlcHsDB215"); + this.writePlcHs = (Hashtable) hsComParam.get("writePlcHs3"); + this.strIp = (String) hsComParam.get("strIp3"); + this.iPort = (Integer) hsComParam.get("iPort3"); + this.slot = (Integer) hsComParam.get("slot3"); + + } + + void ConnectServer() { + try { + sock = new Socket(strIp, iPort); + sock.setSoTimeout(6000); // ÉèÖó¬Ê±Ê±¼ä6Ãë + oStream = sock.getOutputStream(); + iStream = sock.getInputStream(); + + Nodave.Debug = 0x00;// ²»µ÷ʽ + di = new PLCinterface(oStream, iStream, "PLCName", 0, Nodave.PROTOCOL_ISOTCP); + dc = new TCPConnection(di, 0, slot); + + int res = dc.connectPLC(); + if (0 == res) { + setIsConnect(true); + } else { + } + } catch (IOException ioex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½Óʧ°Ü " + ioex.getMessage()); + } catch (Exception ex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½ÓÒì³£ " + ex.getMessage()); + } + } + + public void setIsConnect(boolean bflag) { + if (di != null) { + di.isConnect = bflag; + } + } + + public boolean IsConnect() { + if (di != null) { + return di.isConnect; + } + return false; + } + + void closeServer() { + try { + setIsConnect(false); + clearReadDB(); + if (iStream != null) { + iStream.close(); + iStream = null; + } + } catch (IOException e) { + Logger.info("ÊäÈëÁ÷¹Ø±ÕÒì³£ " + e.getMessage() + strIp + " ¶Ë¿Ú£º" + iPort); + } + try { + if (oStream != null) { + oStream.close(); + oStream = null; + } + } catch (IOException e) { + Logger.error("Êä³öÁ÷¹Ø±ÕÒì³£ IP£º" + strIp + " ¶Ë¿Ú£º" + iPort + " " + e.getMessage()); + } + try { + if (sock != null) { + sock.close(); + sock = null; + } + + } catch (IOException e) { + Logger.error("socket¿Í»§¶Ë¹Ø±ÕÒì³£ IP£º" + strIp + " ¶Ë¿Ú£º" + iPort + e.getMessage()); + } + } + + void clearReadDB() { + + for (int i = 201; i <= 215; i++) { + Hashtable readAreaPlcHs = null; + readAreaPlcHs = (Hashtable) hsComParam.get("readAreaPlcHsDB"+i); + if (readAreaPlcHs != null) { + Iterator iterR = readAreaPlcHs.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + } + + + } + + void reConnect() { + closeServer(); + ConnectServer(); + } + + public void run() { + Iterator iterR = null; + Iterator iterW = null; + List groups = null; + WriteDotPlcInterface.groupPlcObj group = null; + WriteDotPlcInterface plcWVar = null; + ReadAreaPlcInterface plcRVar = null; + ReadDotPlcInterface plcRDotVar = null; + Map.Entry entry = null; + int i = 0, j = 0; + boolean ReConn = false; + int iPrintcount = 5;// 5´Î½øÐдòÓ¡ + int currDecRun = 0;// µ±Ç°Ö´ÐдÎÊý + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + try { + if (IsConnect()) { + //Thread.sleep(300); + + + Date t = new Date(); + SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss.SSS"); + //System.out.println("103:----" + df.format(t)); + // ¶ÁÈ¡DB101¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ + try { + for (int dbk =201; dbk <=215; dbk++) { + Hashtable readAreaPlcHs = null; + readAreaPlcHs = (Hashtable) hsComParam.get("readAreaPlcHsDB"+dbk); + try{ + if (readAreaPlcHs != null) { + iterR = readAreaPlcHs.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + // Logger.info("¶ÁÈ¡DB" + + // plcRVar.DBnum + ",start" + + // plcRVar.start + ",len" + // + plcRVar.len + "\n¶ÁÈ¡Á÷" + + // printHexString(dc.getMsgIn(), + // length)); + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + } + } catch (Exception ex) { + reConnect(); + } + + // дÈëµ½DB¿éÖÐÖ¸¶¨µÄλÖà + try { + if (IsConnect()) { + if (writePlcHs != null) { + t1 = System.currentTimeMillis(); + iterW = writePlcHs.entrySet().iterator(); + if (iterW != null) { + while (iterW.hasNext()) { + entry = (Map.Entry) iterW.next(); + plcWVar = (WriteDotPlcInterface) entry.getValue(); + groups = plcWVar.lsWriteGroupPlc; + for (i = 0; i < groups.size(); i++) { + group = groups.get(i); + dc.writeBytes(group.getArea(), group.getDBnum(), group.getStart(), + group.getLen(), group.getBuffer()); + Logger.info(" DB" + group.getDBnum() + ":¿ªÊ¼-" + group.getStart() + " ³¤¶È-" + + group.getLen() + " Ï·¢Öµ-" + group.getValue()); + if (IsConnect()) { + plcWVar.lsWriteGroupPlc.remove(i); + i--; + } else { + Logger.error("дÈëµ½"+ group.getDBnum() +"¿éÖÐÖ¸¶¨µÄλÖà ÖжÏ"); + break; + } + } + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + + } else { + reConnect(); + } + Thread.sleep(1000); + } catch (Exception ex) { + reConnect(); + } + // ÿ´ÎÑ­»·´ò¿ª¹Ø±ÕÁ´½Ó + //reConnect(); + } + closeServer(); + } + + // ½«Ö¸¶¨byteÊý×éÒÔ16½øÖƵÄÐÎʽ´òÓ¡µ½¿ØÖÆÌ¨ + public static String printHexString(byte[] b, int length) { + String re = ""; + for (int i = 0; i < length; i++) { + String hex = Integer.toHexString(b[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + re += hex.toUpperCase() + " "; + } + return re; + } + + public static void main(String arg[]) { + byte[] ss = new byte[5]; + ss[0] = 1; + ss[1] = 0; + ss[2] = 16; + ss[3] = 0; + ss[4] = 0; + int length = ss.length; + for (int i = ss.length - 1; i > 0; i--) { + if (ss[i] != 0) { + length = i + 1; + break; + } + } + + // ¶ÁÈ¡Á÷03 00 00 2B 02 F0 80 32 03 00 00 00 00 00 02 00 16 00 00 04 01 FF + // 04 00 90 + // 89 02 00 80 37 01 02 37 01 00 18 5E 03 78 05 02 03 + byte[] ssz = Nodave.bswap_16(6238);// 18 5E ÈÎÎñºÅ + System.out.println(printHexString(ssz, ssz.length)); + byte[] msgIn = new byte[90]; + msgIn[10] = (byte) 0x18; // µÚ36 + msgIn[11] = (byte) 0x5E; // µÚ37 + System.out.println(Nodave.SBEWord(msgIn, 10)); + } +} \ No newline at end of file diff --git a/src/org/s7/standard/ynuo/client/IsoTcpClient104.java b/src/org/s7/standard/ynuo/client/IsoTcpClient104.java new file mode 100644 index 0000000..3da3a75 --- /dev/null +++ b/src/org/s7/standard/ynuo/client/IsoTcpClient104.java @@ -0,0 +1,1371 @@ +/* + Test and demo program for Libnodave, a free communication libray for Siemens S7. + + ********************************************************************** + * WARNING: This and other test programs overwrite data in your PLC. * + * DO NOT use it on PLC's when anything is connected to their outputs.* + * This is alpha software. Use entirely on your own risk. * + ********************************************************************** + + (C) Thomas Hergenhahn (thomas.hergenhahn@web.de) 2002, 2004. + + This is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with Visual; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +package org.s7.standard.ynuo.client; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.libnodave.Nodave; +import org.libnodave.PLCinterface; +import org.libnodave.TCPConnection; +import org.s7.standard.ynuo.ReadAreaPlcInterface; +import org.s7.standard.ynuo.ReadDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface.groupPlcObj; + +import com.ricosoft.common.logger.Logger; + +public class IsoTcpClient104 extends Thread { + /* ʱ¼ä´Á */ + long t1, t2; + /* ipµØÖ· */ + String strIp = ""; + /* ¶Ë¿ÚºÅ */ + int iPort = 102; + /* ²Û¿ÚºÅ */ + int slot = 1; + PLCinterface di; + TCPConnection dc; + /* socket¿Í»§¶Ë */ + Socket sock; + // Socket sock2; + /* Êä³öÁ÷ */ + OutputStream oStream = null; + /* ÊäÈëÁ÷ */ + InputStream iStream = null; + /* дÈ뻺´æÊý¾Ý */ + byte[] by; + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable readAreaPlcHs1 = null; + public Hashtable readAreaPlcHs2 = null; + public Hashtable readAreaPlcHs2s = null; + public Hashtable readAreaPlcHs3 = null; + public Hashtable readAreaPlcHs4 = null; + public Hashtable readAreaPlcHs5 = null; + public Hashtable readAreaPlcHs6 = null; + public Hashtable readAreaPlcHs7 = null; + public Hashtable readAreaPlcHs8 = null; + public Hashtable readAreaPlcHs9 = null; + public Hashtable readAreaPlcHs10 = null; + + public Hashtable readAreaPlcHs11 = null; + public Hashtable readAreaPlcHs12 = null; + public Hashtable readAreaPlcHs13 = null; + public Hashtable readAreaPlcHs14 = null; + public Hashtable readAreaPlcHs15 = null; + public Hashtable readAreaPlcHs16 = null; + public Hashtable readAreaPlcHs17 = null; + public Hashtable readAreaPlcHs18 = null; + public Hashtable readAreaPlcHs19 = null; + + /* ´æ·ÅдÈëµÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable writePlcHs = null; + public Hashtable hsSysParam = null; + public Hashtable hsComParam = null; + + public IsoTcpClient104(Hashtable hsComParam, Hashtable hsSysParam) { + this.hsComParam = hsComParam; + this.hsSysParam = hsSysParam; + this.readAreaPlcHs1 = (Hashtable) hsComParam.get("readAreaPlcHs4_1"); + this.readAreaPlcHs2 = (Hashtable) hsComParam.get("readAreaPlcHs4_2"); + this.readAreaPlcHs2s = (Hashtable) hsComParam.get("readAreaPlcHs4_2s"); + this.readAreaPlcHs3 = (Hashtable) hsComParam.get("readAreaPlcHs4_3"); + this.readAreaPlcHs4 = (Hashtable) hsComParam.get("readAreaPlcHs4_4"); + this.readAreaPlcHs5 = (Hashtable) hsComParam.get("readAreaPlcHs4_5"); + this.readAreaPlcHs6 = (Hashtable) hsComParam.get("readAreaPlcHs4_6"); + this.readAreaPlcHs7 = (Hashtable) hsComParam.get("readAreaPlcHs4_7"); + this.readAreaPlcHs8 = (Hashtable) hsComParam.get("readAreaPlcHs4_8"); + this.readAreaPlcHs9 = (Hashtable) hsComParam.get("readAreaPlcHs4_9"); + this.readAreaPlcHs10 = (Hashtable) hsComParam.get("readAreaPlcHs4_10"); + this.readAreaPlcHs11 = (Hashtable) hsComParam.get("readAreaPlcHs4_11"); + this.readAreaPlcHs12 = (Hashtable) hsComParam.get("readAreaPlcHs4_12"); + this.readAreaPlcHs13 = (Hashtable) hsComParam.get("readAreaPlcHs4_13"); + this.readAreaPlcHs14 = (Hashtable) hsComParam.get("readAreaPlcHs4_14"); + this.readAreaPlcHs15 = (Hashtable) hsComParam.get("readAreaPlcHs4_15"); + this.readAreaPlcHs16 = (Hashtable) hsComParam.get("readAreaPlcHs4_16"); + this.readAreaPlcHs17 = (Hashtable) hsComParam.get("readAreaPlcHs4_17"); + this.readAreaPlcHs18 = (Hashtable) hsComParam.get("readAreaPlcHs4_18"); + this.readAreaPlcHs19= (Hashtable) hsComParam.get("readAreaPlcHs4_19"); + this.writePlcHs = (Hashtable) hsComParam.get("writePlcHs4"); + this.strIp = (String) hsComParam.get("strIp4"); + this.iPort = (Integer) hsComParam.get("iPort4"); + this.slot = (Integer) hsComParam.get("slot4"); + + } + + void ConnectServer() { + try { + sock = new Socket(strIp, iPort); + sock.setSoTimeout(6000); // ÉèÖó¬Ê±Ê±¼ä6Ãë + oStream = sock.getOutputStream(); + iStream = sock.getInputStream(); + + Nodave.Debug = 0x00;// ²»µ÷ʽ + di = new PLCinterface(oStream, iStream, "PLCName", 0, Nodave.PROTOCOL_ISOTCP); + dc = new TCPConnection(di, 0, slot); + + int res = dc.connectPLC(); + if (0 == res) { + setIsConnect(true); + } else { + } + } catch (IOException ioex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½Óʧ°Ü " + ioex.getMessage()); + } catch (Exception ex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½ÓÒì³£ " + ex.getMessage()); + } + } + + public void setIsConnect(boolean bflag) { + if (di != null) { + di.isConnect = bflag; + } + } + + public boolean IsConnect() { + if (di != null) { + return di.isConnect; + } + return false; + } + + void closeServer() { + try { + setIsConnect(false); + clearReadDB(); + if (iStream != null) { + iStream.close(); + iStream = null; + } + } catch (IOException e) { + Logger.info("ÊäÈëÁ÷¹Ø±ÕÒì³£ " + e.getMessage() + strIp + " ¶Ë¿Ú£º" + iPort); + } + try { + if (oStream != null) { + oStream.close(); + oStream = null; + } + } catch (IOException e) { + Logger.error("Êä³öÁ÷¹Ø±ÕÒì³£ IP£º" + strIp + " ¶Ë¿Ú£º" + iPort + " " + e.getMessage()); + } + try { + if (sock != null) { + sock.close(); + sock = null; + } + + } catch (IOException e) { + Logger.error("socket¿Í»§¶Ë¹Ø±ÕÒì³£ IP£º" + strIp + " ¶Ë¿Ú£º" + iPort + e.getMessage()); + } + } + + void clearReadDB() { + + if (readAreaPlcHs1 != null) { + Iterator iterR = readAreaPlcHs1.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs2 != null) { + Iterator iterR = readAreaPlcHs2.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs2s != null) { + Iterator iterR = readAreaPlcHs2s.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs3 != null) { + Iterator iterR = readAreaPlcHs3.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs4 != null) { + Iterator iterR = readAreaPlcHs4.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs5 != null) { + Iterator iterR = readAreaPlcHs5.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs6 != null) { + Iterator iterR = readAreaPlcHs6.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs7 != null) { + Iterator iterR = readAreaPlcHs7.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs8 != null) { + Iterator iterR = readAreaPlcHs8.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs9 != null) { + Iterator iterR = readAreaPlcHs9.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs10 != null) { + Iterator iterR = readAreaPlcHs10.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + /// + if (readAreaPlcHs11 != null) { + Iterator iterR = readAreaPlcHs11.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs12 != null) { + Iterator iterR = readAreaPlcHs12.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs13 != null) { + Iterator iterR = readAreaPlcHs13.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs14 != null) { + Iterator iterR = readAreaPlcHs14.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs15 != null) { + Iterator iterR = readAreaPlcHs15.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs16 != null) { + Iterator iterR = readAreaPlcHs16.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs17 != null) { + Iterator iterR = readAreaPlcHs17.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs18 != null) { + Iterator iterR = readAreaPlcHs18.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs19 != null) { + Iterator iterR = readAreaPlcHs19.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + /// + } + + void reConnect() { +// Date t = new Date(); +// SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss.SSS"); +// System.out.println("104:Òì³£---------------reConnect-----------------------------------" + df.format(t)); + closeServer(); + ConnectServer(); + } + + public void run() { + Iterator iterR = null; + Iterator iterW = null; + List groups = null; + WriteDotPlcInterface.groupPlcObj group = null; + WriteDotPlcInterface plcWVar = null; + ReadAreaPlcInterface plcRVar = null; + ReadDotPlcInterface plcRDotVar = null; + Map.Entry entry = null; + int i = 0, j = 0; + boolean ReConn = false; + int iPrintcount = 5;// 5´Î½øÐдòÓ¡ + int currDecRun = 0;// µ±Ç°Ö´ÐдÎÊý + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + try { + if (IsConnect()) { + //Thread.sleep(400); + + Date t = new Date(); + SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss.SSS"); + //System.out.println("104:----" + df.format(t)); + try { + if (readAreaPlcHs1 != null) { + iterR = readAreaPlcHs1.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs2 != null) { + iterR = readAreaPlcHs2.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs2-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try { + if (readAreaPlcHs2s != null) { + iterR = readAreaPlcHs2s.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs2s-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + try { + if (readAreaPlcHs3 != null) { + iterR = readAreaPlcHs3.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs3-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs4 != null) { + iterR = readAreaPlcHs4.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs4-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs5 != null) { + iterR = readAreaPlcHs5.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs5-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs6 != null) { + iterR = readAreaPlcHs6.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs6-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + + } + + try { + if (readAreaPlcHs7 != null) { + iterR = readAreaPlcHs7.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs7-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs8 != null) { + iterR = readAreaPlcHs8.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs8-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs9 != null) { + iterR = readAreaPlcHs9.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs9-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs10 != null) { + iterR = readAreaPlcHs10.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£-------10----------------------------------------------" + df.format(t)); + reConnect(); + } + //¶ÁÈ¡²ð¶â»úÐÅÏ¢ + try { + if (readAreaPlcHs11 != null) { + iterR = readAreaPlcHs11.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£-------11----------------------------------------------" + df.format(t)); + reConnect(); + } + try { + if (readAreaPlcHs12 != null) { + iterR = readAreaPlcHs12.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£-------12----------------------------------------------" + df.format(t)); + reConnect(); + } + try { + if (readAreaPlcHs13 != null) { + iterR = readAreaPlcHs13.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£-------13----------------------------------------------" + df.format(t)); + reConnect(); + } + try { + if (readAreaPlcHs14 != null) { + iterR = readAreaPlcHs14.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£-------14----------------------------------------------" + df.format(t)); + reConnect(); + } + try { + if (readAreaPlcHs15 != null) { + iterR = readAreaPlcHs15.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£-------15----------------------------------------------" + df.format(t)); + reConnect(); + } + try { + if (readAreaPlcHs16 != null) { + iterR = readAreaPlcHs16.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£-------16----------------------------------------------" + df.format(t)); + reConnect(); + } + try { + if (readAreaPlcHs17 != null) { + iterR = readAreaPlcHs17.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£-------17----------------------------------------------" + df.format(t)); + reConnect(); + } + try { + if (readAreaPlcHs18 != null) { + iterR = readAreaPlcHs18.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£-------18----------------------------------------------" + df.format(t)); + reConnect(); + } + // + try { + if (readAreaPlcHs19 != null) { + iterR = readAreaPlcHs19.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£-------18----------------------------------------------" + df.format(t)); + reConnect(); + } + // + try { + if (IsConnect()) { + if (writePlcHs != null) { + t1 = System.currentTimeMillis(); + iterW = writePlcHs.entrySet().iterator(); + if (iterW != null) { + while (iterW.hasNext()) { + entry = (Map.Entry) iterW.next(); + plcWVar = (WriteDotPlcInterface) entry.getValue(); + groups = plcWVar.lsWriteGroupPlc; + for (i = 0; i < groups.size(); i++) { + group = groups.get(i); + dc.writeBytes(group.getArea(), group.getDBnum(), group.getStart(), + group.getLen(), group.getBuffer()); + Logger.info(" DB" + group.getDBnum() + ":¿ªÊ¼-" + group.getStart() + " ³¤¶È-" + + group.getLen() + " Ï·¢Öµ-" + group.getValue()); + if (IsConnect()) { + plcWVar.lsWriteGroupPlc.remove(i); + i--; + } else { + Logger.error("дÈëµ½DB1¿éÖÐÖ¸¶¨µÄλÖà ÖжÏ"); + break; + } + } + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------writePlcHs-----------------------------------" + df.format(t)); + reConnect(); + } + } else { + reConnect(); + } + Thread.sleep(1000); + } catch (Exception ex) { + reConnect(); + } + //reConnect(); + } + closeServer(); + } + + // ½«Ö¸¶¨byteÊý×éÒÔ16½øÖƵÄÐÎʽ´òÓ¡µ½¿ØÖÆÌ¨ + public static String printHexString(byte[] b, int length) { + String re = ""; + for (int i = 0; i < length; i++) { + String hex = Integer.toHexString(b[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + re += hex.toUpperCase() + " "; + } + return re; + } + + public static void main(String arg[]) { + byte[] ss = new byte[5]; + ss[0] = 1; + ss[1] = 0; + ss[2] = 16; + ss[3] = 0; + ss[4] = 0; + int length = ss.length; + for (int i = ss.length - 1; i > 0; i--) { + if (ss[i] != 0) { + length = i + 1; + break; + } + } + + // ¶ÁÈ¡Á÷03 00 00 2B 02 F0 80 32 03 00 00 00 00 00 02 00 16 00 00 04 01 FF + // 04 00 90 + // 89 02 00 80 37 01 02 37 01 00 18 5E 03 78 05 02 03 + byte[] ssz = Nodave.bswap_16(6238);// 18 5E ÈÎÎñºÅ + System.out.println(printHexString(ssz, ssz.length)); + byte[] msgIn = new byte[90]; + msgIn[10] = (byte) 0x18; // µÚ36 + msgIn[11] = (byte) 0x5E; // µÚ37 + System.out.println(Nodave.SBEWord(msgIn, 10)); + } +} \ No newline at end of file diff --git a/src/org/s7/standard/ynuo/client/IsoTcpClient171.java b/src/org/s7/standard/ynuo/client/IsoTcpClient171.java new file mode 100644 index 0000000..5d6e92d --- /dev/null +++ b/src/org/s7/standard/ynuo/client/IsoTcpClient171.java @@ -0,0 +1,9204 @@ +/* + Test and demo program for Libnodave, a free communication libray for Siemens S7. + + ********************************************************************** + * WARNING: This and other test programs overwrite data in your PLC. * + * DO NOT use it on PLC's when anything is connected to their outputs.* + * This is alpha software. Use entirely on your own risk. * + ********************************************************************** + + (C) Thomas Hergenhahn (thomas.hergenhahn@web.de) 2002, 2004. + + This is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with Visual; see the file COPYING. If not, write to + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +package org.s7.standard.ynuo.client; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.libnodave.Nodave; +import org.libnodave.PLCinterface; +import org.libnodave.TCPConnection; +import org.s7.standard.ynuo.ReadAreaPlcInterface; +import org.s7.standard.ynuo.ReadDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface; +import org.s7.standard.ynuo.WriteDotPlcInterface.groupPlcObj; + +import com.ricosoft.common.logger.Logger; + +public class IsoTcpClient171 extends Thread { + /* ʱ¼ä´Á */ + long t1, t2; + /* ipµØÖ· */ + String strIp = ""; + /* ¶Ë¿ÚºÅ */ + int iPort = 102; + /* ²Û¿ÚºÅ */ + int slot = 1; + PLCinterface di; + TCPConnection dc; + /* socket¿Í»§¶Ë */ + Socket sock; + // Socket sock2; + /* Êä³öÁ÷ */ + OutputStream oStream = null; + /* ÊäÈëÁ÷ */ + InputStream iStream = null; + /* дÈ뻺´æÊý¾Ý */ + byte[] by; + /* ´æ·Å¶ÁÈ¡µÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable readAreaPlcHs50_1 = null; + public Hashtable readAreaPlcHs50_2 = null; + public Hashtable readAreaPlcHs50_3 = null; + public Hashtable readAreaPlcHs50_4 = null; + public Hashtable readAreaPlcHs50_5 = null; + public Hashtable readAreaPlcHs50_6 = null; + public Hashtable readAreaPlcHs50_7 = null; + public Hashtable readAreaPlcHs50_8 = null; + public Hashtable readAreaPlcHs50_9 = null; + public Hashtable readAreaPlcHs50_10 = null; + public Hashtable readAreaPlcHs50_11 = null; + public Hashtable readAreaPlcHs50_12 = null; + public Hashtable readAreaPlcHs50_13 = null; + public Hashtable readAreaPlcHs50_14 = null; + public Hashtable readAreaPlcHs50_15 = null; + public Hashtable readAreaPlcHs50_16 = null; + + public Hashtable readAreaPlcHs49_1 = null; + public Hashtable readAreaPlcHs49_2 = null; + public Hashtable readAreaPlcHs49_3 = null; + public Hashtable readAreaPlcHs49_4 = null; + public Hashtable readAreaPlcHs49_5 = null; + public Hashtable readAreaPlcHs49_6 = null; + public Hashtable readAreaPlcHs49_7 = null; + public Hashtable readAreaPlcHs49_8 = null; + public Hashtable readAreaPlcHs49_9 = null; + public Hashtable readAreaPlcHs49_10 = null; + public Hashtable readAreaPlcHs49_11 = null; + public Hashtable readAreaPlcHs49_12 = null; + public Hashtable readAreaPlcHs49_13 = null; + public Hashtable readAreaPlcHs49_14 = null; + public Hashtable readAreaPlcHs49_15 = null; + public Hashtable readAreaPlcHs49_16 = null; + + + + public Hashtable readAreaPlcHs48_1 = null; + public Hashtable readAreaPlcHs48_2 = null; + public Hashtable readAreaPlcHs48_3 = null; + public Hashtable readAreaPlcHs48_4 = null; + public Hashtable readAreaPlcHs48_5 = null; + public Hashtable readAreaPlcHs48_6 = null; + public Hashtable readAreaPlcHs48_7 = null; + public Hashtable readAreaPlcHs48_8 = null; + public Hashtable readAreaPlcHs48_9 = null; + public Hashtable readAreaPlcHs48_10 = null; + public Hashtable readAreaPlcHs48_11 = null; + public Hashtable readAreaPlcHs48_12 = null; + public Hashtable readAreaPlcHs48_13 = null; + public Hashtable readAreaPlcHs48_14 = null; + public Hashtable readAreaPlcHs48_15 = null; + public Hashtable readAreaPlcHs48_16 = null; + + + + + public Hashtable readAreaPlcHs47_1 = null; + public Hashtable readAreaPlcHs47_2 = null; + public Hashtable readAreaPlcHs47_3 = null; + public Hashtable readAreaPlcHs47_4 = null; + public Hashtable readAreaPlcHs47_5 = null; + public Hashtable readAreaPlcHs47_6 = null; + public Hashtable readAreaPlcHs47_7 = null; + public Hashtable readAreaPlcHs47_8 = null; + public Hashtable readAreaPlcHs47_9 = null; + public Hashtable readAreaPlcHs47_10 = null; + public Hashtable readAreaPlcHs47_11 = null; + public Hashtable readAreaPlcHs47_12 = null; + public Hashtable readAreaPlcHs47_13 = null; + public Hashtable readAreaPlcHs47_14 = null; + public Hashtable readAreaPlcHs47_15 = null; + public Hashtable readAreaPlcHs47_16 = null; + + + + public Hashtable readAreaPlcHs46_1 = null; + public Hashtable readAreaPlcHs46_2 = null; + public Hashtable readAreaPlcHs46_3 = null; + public Hashtable readAreaPlcHs46_4 = null; + public Hashtable readAreaPlcHs46_5 = null; + public Hashtable readAreaPlcHs46_6 = null; + public Hashtable readAreaPlcHs46_7 = null; + public Hashtable readAreaPlcHs46_8 = null; + public Hashtable readAreaPlcHs46_9 = null; + public Hashtable readAreaPlcHs46_10 = null; + public Hashtable readAreaPlcHs46_11 = null; + public Hashtable readAreaPlcHs46_12 = null; + public Hashtable readAreaPlcHs46_13 = null; + public Hashtable readAreaPlcHs46_14 = null; + public Hashtable readAreaPlcHs46_15 = null; + public Hashtable readAreaPlcHs46_16 = null; + + + + public Hashtable readAreaPlcHs45_1 = null; + public Hashtable readAreaPlcHs45_2 = null; + public Hashtable readAreaPlcHs45_3 = null; + public Hashtable readAreaPlcHs45_4 = null; + public Hashtable readAreaPlcHs45_5 = null; + public Hashtable readAreaPlcHs45_6 = null; + public Hashtable readAreaPlcHs45_7 = null; + public Hashtable readAreaPlcHs45_8 = null; + public Hashtable readAreaPlcHs45_9 = null; + public Hashtable readAreaPlcHs45_10 = null; + public Hashtable readAreaPlcHs45_11 = null; + public Hashtable readAreaPlcHs45_12 = null; + public Hashtable readAreaPlcHs45_13 = null; + public Hashtable readAreaPlcHs45_14 = null; + public Hashtable readAreaPlcHs45_15 = null; + public Hashtable readAreaPlcHs45_16 = null; + + + + + public Hashtable readAreaPlcHs44_1 = null; + public Hashtable readAreaPlcHs44_2 = null; + public Hashtable readAreaPlcHs44_3 = null; + public Hashtable readAreaPlcHs44_4 = null; + public Hashtable readAreaPlcHs44_5 = null; + public Hashtable readAreaPlcHs44_6 = null; + public Hashtable readAreaPlcHs44_7 = null; + public Hashtable readAreaPlcHs44_8 = null; + public Hashtable readAreaPlcHs44_9 = null; + public Hashtable readAreaPlcHs44_10 = null; + public Hashtable readAreaPlcHs44_11 = null; + public Hashtable readAreaPlcHs44_12 = null; + public Hashtable readAreaPlcHs44_13 = null; + public Hashtable readAreaPlcHs44_14 = null; + public Hashtable readAreaPlcHs44_15 = null; + public Hashtable readAreaPlcHs44_16 = null; + + + + public Hashtable readAreaPlcHs43_1 = null; + public Hashtable readAreaPlcHs43_2 = null; + public Hashtable readAreaPlcHs43_3 = null; + public Hashtable readAreaPlcHs43_4 = null; + public Hashtable readAreaPlcHs43_5 = null; + public Hashtable readAreaPlcHs43_6 = null; + public Hashtable readAreaPlcHs43_7 = null; + public Hashtable readAreaPlcHs43_8 = null; + public Hashtable readAreaPlcHs43_9 = null; + public Hashtable readAreaPlcHs43_10 = null; + public Hashtable readAreaPlcHs43_11 = null; + public Hashtable readAreaPlcHs43_12 = null; + public Hashtable readAreaPlcHs43_13 = null; + public Hashtable readAreaPlcHs43_14 = null; + public Hashtable readAreaPlcHs43_15 = null; + public Hashtable readAreaPlcHs43_16 = null; + + + + public Hashtable readAreaPlcHs42_1 = null; + public Hashtable readAreaPlcHs42_2 = null; + public Hashtable readAreaPlcHs42_3 = null; + public Hashtable readAreaPlcHs42_4 = null; + public Hashtable readAreaPlcHs42_5 = null; + public Hashtable readAreaPlcHs42_6 = null; + public Hashtable readAreaPlcHs42_7 = null; + public Hashtable readAreaPlcHs42_8 = null; + public Hashtable readAreaPlcHs42_9 = null; + public Hashtable readAreaPlcHs42_10 = null; + public Hashtable readAreaPlcHs42_11 = null; + public Hashtable readAreaPlcHs42_12 = null; + public Hashtable readAreaPlcHs42_13 = null; + public Hashtable readAreaPlcHs42_14 = null; + public Hashtable readAreaPlcHs42_15 = null; + public Hashtable readAreaPlcHs42_16 = null; + + + + public Hashtable readAreaPlcHs41_1 = null; + public Hashtable readAreaPlcHs41_2 = null; + public Hashtable readAreaPlcHs41_3 = null; + public Hashtable readAreaPlcHs41_4 = null; + public Hashtable readAreaPlcHs41_5 = null; + public Hashtable readAreaPlcHs41_6 = null; + public Hashtable readAreaPlcHs41_7 = null; + public Hashtable readAreaPlcHs41_8 = null; + public Hashtable readAreaPlcHs41_9 = null; + public Hashtable readAreaPlcHs41_10 = null; + public Hashtable readAreaPlcHs41_11 = null; + public Hashtable readAreaPlcHs41_12 = null; + public Hashtable readAreaPlcHs41_13 = null; + public Hashtable readAreaPlcHs41_14 = null; + public Hashtable readAreaPlcHs41_15 = null; + public Hashtable readAreaPlcHs41_16 = null; + + + + + /* ´æ·ÅдÈëµÄDB×Ö½ÚÐÅÏ¢ */ + public Hashtable writePlcHs = null; + public Hashtable hsSysParam = null; + public Hashtable hsComParam = null; + + public IsoTcpClient171(Hashtable hsComParam, Hashtable hsSysParam) { + this.hsComParam = hsComParam; + this.hsSysParam = hsSysParam; + + this.readAreaPlcHs50_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_1"); + this.readAreaPlcHs50_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_2"); + this.readAreaPlcHs50_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_3"); + this.readAreaPlcHs50_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_4"); + this.readAreaPlcHs50_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_5"); + this.readAreaPlcHs50_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_6"); + this.readAreaPlcHs50_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_7"); + this.readAreaPlcHs50_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_8"); + this.readAreaPlcHs50_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_9"); + this.readAreaPlcHs50_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_10"); + this.readAreaPlcHs50_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_11"); + this.readAreaPlcHs50_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_12"); + this.readAreaPlcHs50_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_13"); + this.readAreaPlcHs50_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_14"); + this.readAreaPlcHs50_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_15"); + this.readAreaPlcHs50_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB50_16"); + + this.readAreaPlcHs49_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_1"); + this.readAreaPlcHs49_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_2"); + this.readAreaPlcHs49_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_3"); + this.readAreaPlcHs49_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_4"); + this.readAreaPlcHs49_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_5"); + this.readAreaPlcHs49_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_6"); + this.readAreaPlcHs49_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_7"); + this.readAreaPlcHs49_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_8"); + this.readAreaPlcHs49_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_9"); + this.readAreaPlcHs49_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_10"); + this.readAreaPlcHs49_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_11"); + this.readAreaPlcHs49_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_12"); + this.readAreaPlcHs49_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_13"); + this.readAreaPlcHs49_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_14"); + this.readAreaPlcHs49_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_15"); + this.readAreaPlcHs49_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB49_16"); + + this.readAreaPlcHs48_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_1"); + this.readAreaPlcHs48_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_2"); + this.readAreaPlcHs48_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_3"); + this.readAreaPlcHs48_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_4"); + this.readAreaPlcHs48_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_5"); + this.readAreaPlcHs48_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_6"); + this.readAreaPlcHs48_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_7"); + this.readAreaPlcHs48_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_8"); + this.readAreaPlcHs48_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_9"); + this.readAreaPlcHs48_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_10"); + this.readAreaPlcHs48_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_11"); + this.readAreaPlcHs48_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_12"); + this.readAreaPlcHs48_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_13"); + this.readAreaPlcHs48_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_14"); + this.readAreaPlcHs48_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_15"); + this.readAreaPlcHs48_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB48_16"); + + this.readAreaPlcHs47_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_1"); + this.readAreaPlcHs47_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_2"); + this.readAreaPlcHs47_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_3"); + this.readAreaPlcHs47_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_4"); + this.readAreaPlcHs47_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_5"); + this.readAreaPlcHs47_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_6"); + this.readAreaPlcHs47_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_7"); + this.readAreaPlcHs47_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_8"); + this.readAreaPlcHs47_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_9"); + this.readAreaPlcHs47_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_10"); + this.readAreaPlcHs47_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_11"); + this.readAreaPlcHs47_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_12"); + this.readAreaPlcHs47_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_13"); + this.readAreaPlcHs47_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_14"); + this.readAreaPlcHs47_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_15"); + this.readAreaPlcHs47_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB47_16"); + + this.readAreaPlcHs46_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_1"); + this.readAreaPlcHs46_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_2"); + this.readAreaPlcHs46_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_3"); + this.readAreaPlcHs46_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_4"); + this.readAreaPlcHs46_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_5"); + this.readAreaPlcHs46_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_6"); + this.readAreaPlcHs46_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_7"); + this.readAreaPlcHs46_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_8"); + this.readAreaPlcHs46_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_9"); + this.readAreaPlcHs46_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_10"); + this.readAreaPlcHs46_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_11"); + this.readAreaPlcHs46_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_12"); + this.readAreaPlcHs46_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_13"); + this.readAreaPlcHs46_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_14"); + this.readAreaPlcHs46_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_15"); + this.readAreaPlcHs46_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB46_16"); + + this.readAreaPlcHs45_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_1"); + this.readAreaPlcHs45_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_2"); + this.readAreaPlcHs45_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_3"); + this.readAreaPlcHs45_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_4"); + this.readAreaPlcHs45_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_5"); + this.readAreaPlcHs45_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_6"); + this.readAreaPlcHs45_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_7"); + this.readAreaPlcHs45_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_8"); + this.readAreaPlcHs45_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_9"); + this.readAreaPlcHs45_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_10"); + this.readAreaPlcHs45_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_11"); + this.readAreaPlcHs45_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_12"); + this.readAreaPlcHs45_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_13"); + this.readAreaPlcHs45_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_14"); + this.readAreaPlcHs45_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_15"); + this.readAreaPlcHs45_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB45_16"); + + this.readAreaPlcHs44_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_1"); + this.readAreaPlcHs44_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_2"); + this.readAreaPlcHs44_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_3"); + this.readAreaPlcHs44_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_4"); + this.readAreaPlcHs44_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_5"); + this.readAreaPlcHs44_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_6"); + this.readAreaPlcHs44_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_7"); + this.readAreaPlcHs44_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_8"); + this.readAreaPlcHs44_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_9"); + this.readAreaPlcHs44_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_10"); + this.readAreaPlcHs44_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_11"); + this.readAreaPlcHs44_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_12"); + this.readAreaPlcHs44_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_13"); + this.readAreaPlcHs44_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_14"); + this.readAreaPlcHs44_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_15"); + this.readAreaPlcHs44_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB44_16"); + + this.readAreaPlcHs43_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_1"); + this.readAreaPlcHs43_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_2"); + this.readAreaPlcHs43_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_3"); + this.readAreaPlcHs43_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_4"); + this.readAreaPlcHs43_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_5"); + this.readAreaPlcHs43_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_6"); + this.readAreaPlcHs43_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_7"); + this.readAreaPlcHs43_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_8"); + this.readAreaPlcHs43_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_9"); + this.readAreaPlcHs43_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_10"); + this.readAreaPlcHs43_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_11"); + this.readAreaPlcHs43_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_12"); + this.readAreaPlcHs43_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_13"); + this.readAreaPlcHs43_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_14"); + this.readAreaPlcHs43_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_15"); + this.readAreaPlcHs43_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB43_16"); + + this.readAreaPlcHs42_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_1"); + this.readAreaPlcHs42_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_2"); + this.readAreaPlcHs42_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_3"); + this.readAreaPlcHs42_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_4"); + this.readAreaPlcHs42_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_5"); + this.readAreaPlcHs42_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_6"); + this.readAreaPlcHs42_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_7"); + this.readAreaPlcHs42_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_8"); + this.readAreaPlcHs42_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_9"); + this.readAreaPlcHs42_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_10"); + this.readAreaPlcHs42_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_11"); + this.readAreaPlcHs42_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_12"); + this.readAreaPlcHs42_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_13"); + this.readAreaPlcHs42_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_14"); + this.readAreaPlcHs42_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_15"); + this.readAreaPlcHs42_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB42_16"); + + + this.readAreaPlcHs41_1 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_1"); + this.readAreaPlcHs41_2 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_2"); + this.readAreaPlcHs41_3 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_3"); + this.readAreaPlcHs41_4 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_4"); + this.readAreaPlcHs41_5 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_5"); + this.readAreaPlcHs41_6 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_6"); + this.readAreaPlcHs41_7 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_7"); + this.readAreaPlcHs41_8 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_8"); + this.readAreaPlcHs41_9 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_9"); + this.readAreaPlcHs41_10 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_10"); + this.readAreaPlcHs41_11 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_11"); + this.readAreaPlcHs41_12 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_12"); + this.readAreaPlcHs41_13 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_13"); + this.readAreaPlcHs41_14 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_14"); + this.readAreaPlcHs41_15 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_15"); + this.readAreaPlcHs41_16 = (Hashtable) hsComParam.get("readAreaPlcHsDB41_16"); + + + + + this.writePlcHs = (Hashtable) hsComParam.get("writePlcHs5"); + this.strIp = (String) hsComParam.get("strIp5"); + this.iPort = (Integer) hsComParam.get("iPort5"); + this.slot = (Integer) hsComParam.get("slot5"); + + } + + void ConnectServer() { + try { + sock = new Socket(strIp, iPort); + sock.setSoTimeout(6000); // ÉèÖó¬Ê±Ê±¼ä6Ãë + oStream = sock.getOutputStream(); + iStream = sock.getInputStream(); + + Nodave.Debug = 0x00;// ²»µ÷ʽ + di = new PLCinterface(oStream, iStream, "PLCName", 0, Nodave.PROTOCOL_ISOTCP); + dc = new TCPConnection(di, 0, slot); + + int res = dc.connectPLC(); + if (0 == res) { + setIsConnect(true); + } else { + } + } catch (IOException ioex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½Óʧ°Ü " + ioex.getMessage()); + } catch (Exception ex) { + Logger.info("********IP:" + strIp + " ¶Ë¿Ú:" + iPort + "Á¬½ÓÒì³£ " + ex.getMessage()); + } + } + + public void setIsConnect(boolean bflag) { + if (di != null) { + di.isConnect = bflag; + } + } + + public boolean IsConnect() { + if (di != null) { + return di.isConnect; + } + return false; + } + + void closeServer() { + try { + setIsConnect(false); + clearReadDB(); + if (iStream != null) { + iStream.close(); + iStream = null; + } + } catch (IOException e) { + Logger.info("ÊäÈëÁ÷¹Ø±ÕÒì³£ " + e.getMessage() + strIp + " ¶Ë¿Ú£º" + iPort); + } + try { + if (oStream != null) { + oStream.close(); + oStream = null; + } + } catch (IOException e) { + Logger.error("Êä³öÁ÷¹Ø±ÕÒì³£ IP£º" + strIp + " ¶Ë¿Ú£º" + iPort + " " + e.getMessage()); + } + try { + if (sock != null) { + sock.close(); + sock = null; + } + + } catch (IOException e) { + Logger.error("socket¿Í»§¶Ë¹Ø±ÕÒì³£ IP£º" + strIp + " ¶Ë¿Ú£º" + iPort + e.getMessage()); + } + } + + void clearReadDB() { + + if (readAreaPlcHs49_1 != null) { + Iterator iterR = readAreaPlcHs49_1.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs49_2 != null) { + Iterator iterR = readAreaPlcHs49_2.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs49_3 != null) { + Iterator iterR = readAreaPlcHs49_3.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs49_4 != null) { + Iterator iterR = readAreaPlcHs49_4.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs49_5 != null) { + Iterator iterR = readAreaPlcHs49_5.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs49_6 != null) { + Iterator iterR = readAreaPlcHs49_6.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs49_7 != null) { + Iterator iterR = readAreaPlcHs49_7.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs49_8 != null) { + Iterator iterR = readAreaPlcHs49_8.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs49_9 != null) { + Iterator iterR = readAreaPlcHs49_9.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs49_10 != null) { + Iterator iterR = readAreaPlcHs49_10.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs49_11 != null) { + Iterator iterR = readAreaPlcHs49_11.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs49_12 != null) { + Iterator iterR = readAreaPlcHs49_12.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs49_13 != null) { + Iterator iterR = readAreaPlcHs49_13.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs49_14 != null) { + Iterator iterR = readAreaPlcHs49_14.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs49_15 != null) { + Iterator iterR = readAreaPlcHs49_15.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs49_16 != null) { + Iterator iterR = readAreaPlcHs49_16.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + //========================================================================== + + if (readAreaPlcHs48_1 != null) { + Iterator iterR = readAreaPlcHs48_1.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs48_2 != null) { + Iterator iterR = readAreaPlcHs48_2.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs48_3 != null) { + Iterator iterR = readAreaPlcHs48_3.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs48_4 != null) { + Iterator iterR = readAreaPlcHs48_4.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs48_5 != null) { + Iterator iterR = readAreaPlcHs48_5.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs48_6 != null) { + Iterator iterR = readAreaPlcHs48_6.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs48_7 != null) { + Iterator iterR = readAreaPlcHs48_7.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs48_8 != null) { + Iterator iterR = readAreaPlcHs48_8.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs48_9 != null) { + Iterator iterR = readAreaPlcHs48_9.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs48_10 != null) { + Iterator iterR = readAreaPlcHs48_10.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs48_11 != null) { + Iterator iterR = readAreaPlcHs48_11.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs48_12 != null) { + Iterator iterR = readAreaPlcHs48_12.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs48_13 != null) { + Iterator iterR = readAreaPlcHs48_13.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs48_14 != null) { + Iterator iterR = readAreaPlcHs48_14.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs48_15 != null) { + Iterator iterR = readAreaPlcHs48_15.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs48_16 != null) { + Iterator iterR = readAreaPlcHs48_16.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + + + //========================================================================== + if (readAreaPlcHs47_1 != null) { + Iterator iterR = readAreaPlcHs47_1.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs47_2 != null) { + Iterator iterR = readAreaPlcHs47_2.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs47_3 != null) { + Iterator iterR = readAreaPlcHs47_3.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs47_4 != null) { + Iterator iterR = readAreaPlcHs47_4.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs47_5 != null) { + Iterator iterR = readAreaPlcHs47_5.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs47_6 != null) { + Iterator iterR = readAreaPlcHs47_6.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs47_7 != null) { + Iterator iterR = readAreaPlcHs47_7.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs47_8 != null) { + Iterator iterR = readAreaPlcHs47_8.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs47_9 != null) { + Iterator iterR = readAreaPlcHs47_9.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs47_10 != null) { + Iterator iterR = readAreaPlcHs47_10.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs47_11 != null) { + Iterator iterR = readAreaPlcHs47_11.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs47_12 != null) { + Iterator iterR = readAreaPlcHs47_12.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs47_13 != null) { + Iterator iterR = readAreaPlcHs47_13.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs47_14 != null) { + Iterator iterR = readAreaPlcHs47_14.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs47_15 != null) { + Iterator iterR = readAreaPlcHs47_15.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs47_16 != null) { + Iterator iterR = readAreaPlcHs47_16.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + + //========================================================================== + if (readAreaPlcHs46_1 != null) { + Iterator iterR = readAreaPlcHs46_1.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs46_2 != null) { + Iterator iterR = readAreaPlcHs46_2.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs46_3 != null) { + Iterator iterR = readAreaPlcHs46_3.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs46_4 != null) { + Iterator iterR = readAreaPlcHs46_4.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs46_5 != null) { + Iterator iterR = readAreaPlcHs46_5.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs46_6 != null) { + Iterator iterR = readAreaPlcHs46_6.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs46_7 != null) { + Iterator iterR = readAreaPlcHs46_7.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs46_8 != null) { + Iterator iterR = readAreaPlcHs46_8.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs46_9 != null) { + Iterator iterR = readAreaPlcHs46_9.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs46_10 != null) { + Iterator iterR = readAreaPlcHs46_10.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs46_11 != null) { + Iterator iterR = readAreaPlcHs46_11.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs46_12 != null) { + Iterator iterR = readAreaPlcHs46_12.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs46_13 != null) { + Iterator iterR = readAreaPlcHs46_13.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs46_14 != null) { + Iterator iterR = readAreaPlcHs46_14.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs46_15 != null) { + Iterator iterR = readAreaPlcHs46_15.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs46_16 != null) { + Iterator iterR = readAreaPlcHs46_16.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + + + //========================================================================== + if (readAreaPlcHs45_1 != null) { + Iterator iterR = readAreaPlcHs45_1.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs45_2 != null) { + Iterator iterR = readAreaPlcHs45_2.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs45_3 != null) { + Iterator iterR = readAreaPlcHs45_3.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs45_4 != null) { + Iterator iterR = readAreaPlcHs45_4.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs45_5 != null) { + Iterator iterR = readAreaPlcHs45_5.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs45_6 != null) { + Iterator iterR = readAreaPlcHs45_6.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs45_7 != null) { + Iterator iterR = readAreaPlcHs45_7.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs45_8 != null) { + Iterator iterR = readAreaPlcHs45_8.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs45_9 != null) { + Iterator iterR = readAreaPlcHs45_9.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs45_10 != null) { + Iterator iterR = readAreaPlcHs45_10.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs45_11 != null) { + Iterator iterR = readAreaPlcHs45_11.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs45_12 != null) { + Iterator iterR = readAreaPlcHs45_12.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs45_13 != null) { + Iterator iterR = readAreaPlcHs45_13.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs45_14 != null) { + Iterator iterR = readAreaPlcHs45_14.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs45_15 != null) { + Iterator iterR = readAreaPlcHs45_15.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs45_16 != null) { + Iterator iterR = readAreaPlcHs45_16.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + + //========================================================================== + if (readAreaPlcHs44_1 != null) { + Iterator iterR = readAreaPlcHs44_1.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs44_2 != null) { + Iterator iterR = readAreaPlcHs44_2.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs44_3 != null) { + Iterator iterR = readAreaPlcHs44_3.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs44_4 != null) { + Iterator iterR = readAreaPlcHs44_4.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs44_5 != null) { + Iterator iterR = readAreaPlcHs44_5.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs44_6 != null) { + Iterator iterR = readAreaPlcHs44_6.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs44_7 != null) { + Iterator iterR = readAreaPlcHs44_7.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs44_8 != null) { + Iterator iterR = readAreaPlcHs44_8.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs44_9 != null) { + Iterator iterR = readAreaPlcHs44_9.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs44_10 != null) { + Iterator iterR = readAreaPlcHs44_10.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs44_11 != null) { + Iterator iterR = readAreaPlcHs44_11.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs44_12 != null) { + Iterator iterR = readAreaPlcHs44_12.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs44_13 != null) { + Iterator iterR = readAreaPlcHs44_13.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs44_14 != null) { + Iterator iterR = readAreaPlcHs44_14.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs44_15 != null) { + Iterator iterR = readAreaPlcHs44_15.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs44_16 != null) { + Iterator iterR = readAreaPlcHs44_16.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + + + + + //========================================================================== + if (readAreaPlcHs43_1 != null) { + Iterator iterR = readAreaPlcHs43_1.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs43_2 != null) { + Iterator iterR = readAreaPlcHs43_2.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs43_3 != null) { + Iterator iterR = readAreaPlcHs43_3.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs43_4 != null) { + Iterator iterR = readAreaPlcHs43_4.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs43_5 != null) { + Iterator iterR = readAreaPlcHs43_5.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs43_6 != null) { + Iterator iterR = readAreaPlcHs43_6.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs43_7 != null) { + Iterator iterR = readAreaPlcHs43_7.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs43_8 != null) { + Iterator iterR = readAreaPlcHs43_8.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs43_9 != null) { + Iterator iterR = readAreaPlcHs43_9.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs43_10 != null) { + Iterator iterR = readAreaPlcHs43_10.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs43_11 != null) { + Iterator iterR = readAreaPlcHs43_11.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs43_12 != null) { + Iterator iterR = readAreaPlcHs43_12.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs43_13 != null) { + Iterator iterR = readAreaPlcHs43_13.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs43_14 != null) { + Iterator iterR = readAreaPlcHs43_14.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs43_15 != null) { + Iterator iterR = readAreaPlcHs43_15.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs43_16 != null) { + Iterator iterR = readAreaPlcHs43_16.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + + + //========================================================================== + if (readAreaPlcHs42_1 != null) { + Iterator iterR = readAreaPlcHs42_1.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs42_2 != null) { + Iterator iterR = readAreaPlcHs42_2.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs42_3 != null) { + Iterator iterR = readAreaPlcHs42_3.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs42_4 != null) { + Iterator iterR = readAreaPlcHs42_4.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs42_5 != null) { + Iterator iterR = readAreaPlcHs42_5.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs42_6 != null) { + Iterator iterR = readAreaPlcHs42_6.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs42_7 != null) { + Iterator iterR = readAreaPlcHs42_7.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs42_8 != null) { + Iterator iterR = readAreaPlcHs42_8.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs42_9 != null) { + Iterator iterR = readAreaPlcHs42_9.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs42_10 != null) { + Iterator iterR = readAreaPlcHs42_10.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs42_11 != null) { + Iterator iterR = readAreaPlcHs42_11.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs42_12 != null) { + Iterator iterR = readAreaPlcHs42_12.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs42_13 != null) { + Iterator iterR = readAreaPlcHs42_13.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs42_14 != null) { + Iterator iterR = readAreaPlcHs42_14.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs42_15 != null) { + Iterator iterR = readAreaPlcHs42_15.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs42_16 != null) { + Iterator iterR = readAreaPlcHs42_16.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + + //========================================================================== + if (readAreaPlcHs41_1 != null) { + Iterator iterR = readAreaPlcHs41_1.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs41_2 != null) { + Iterator iterR = readAreaPlcHs41_2.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs41_3 != null) { + Iterator iterR = readAreaPlcHs41_3.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs41_4 != null) { + Iterator iterR = readAreaPlcHs41_4.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + if (readAreaPlcHs41_5 != null) { + Iterator iterR = readAreaPlcHs41_5.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs41_6 != null) { + Iterator iterR = readAreaPlcHs41_6.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs41_7 != null) { + Iterator iterR = readAreaPlcHs41_7.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs41_8 != null) { + Iterator iterR = readAreaPlcHs41_8.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs41_9 != null) { + Iterator iterR = readAreaPlcHs41_9.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs41_10 != null) { + Iterator iterR = readAreaPlcHs41_10.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs41_11 != null) { + Iterator iterR = readAreaPlcHs41_11.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs41_12 != null) { + Iterator iterR = readAreaPlcHs41_12.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs41_13 != null) { + Iterator iterR = readAreaPlcHs41_13.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs41_14 != null) { + Iterator iterR = readAreaPlcHs41_14.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs41_15 != null) { + Iterator iterR = readAreaPlcHs41_15.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + if (readAreaPlcHs41_16 != null) { + Iterator iterR = readAreaPlcHs41_16.entrySet().iterator(); + Map.Entry entry = null; + ReadAreaPlcInterface plcRVar = null; + if (iterR != null) { + byte[] nByte = new byte[2048]; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + plcRVar.udata = 0; + System.arraycopy(nByte, 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + } + } + } + + + } + + void reConnect() { +// Date t = new Date(); +// SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss.SSS"); +// System.out.println("104:Òì³£---------------reConnect-----------------------------------" + df.format(t)); + closeServer(); + ConnectServer(); + } + + public void run() { + Iterator iterR = null; + Iterator iterW = null; + List groups = null; + WriteDotPlcInterface.groupPlcObj group = null; + WriteDotPlcInterface plcWVar = null; + ReadAreaPlcInterface plcRVar = null; + ReadDotPlcInterface plcRDotVar = null; + Map.Entry entry = null; + int i = 0, j = 0; + boolean ReConn = false; + int iPrintcount = 5;// 5´Î½øÐдòÓ¡ + int currDecRun = 0;// µ±Ç°Ö´ÐдÎÊý + while (!Boolean.valueOf((String) hsSysParam.get("bStopFlag"))) { + try { + if (IsConnect()) { + //Thread.sleep(400); + + Date t = new Date(); + SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss.SSS"); + System.out.println("171:----" + df.format(t)); + + + //System.out.println(currDecRun); + //============================================================= + try { + if (readAreaPlcHs50_1 != null) { + iterR = readAreaPlcHs50_1.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs50_2 != null) { + iterR = readAreaPlcHs50_2.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs50_3 != null) { + iterR = readAreaPlcHs50_3.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs50_4 != null) { + iterR = readAreaPlcHs50_4.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs50_5 != null) { + iterR = readAreaPlcHs50_5.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs50_6 != null) { + iterR = readAreaPlcHs50_6.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + try { + if (readAreaPlcHs50_7 != null) { + iterR = readAreaPlcHs50_7.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs50_8 != null) { + iterR = readAreaPlcHs50_8.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs50_9 != null) { + iterR = readAreaPlcHs50_9.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs50_10 != null) { + iterR = readAreaPlcHs50_10.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs50_11 != null) { + iterR = readAreaPlcHs50_11.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs50_12 != null) { + iterR = readAreaPlcHs50_12.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs50_13 != null) { + iterR = readAreaPlcHs50_13.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs50_14 != null) { + iterR = readAreaPlcHs50_14.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs50_15 != null) { + iterR = readAreaPlcHs50_15.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs50_16 != null) { + iterR = readAreaPlcHs50_16.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + //------------ + try { + if (readAreaPlcHs49_1 != null) { + iterR = readAreaPlcHs49_1.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs49_2 != null) { + iterR = readAreaPlcHs49_2.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs49_3 != null) { + iterR = readAreaPlcHs49_3.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs49_4 != null) { + iterR = readAreaPlcHs49_4.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs49_5 != null) { + iterR = readAreaPlcHs49_5.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs49_6 != null) { + iterR = readAreaPlcHs49_6.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + try { + if (readAreaPlcHs49_7 != null) { + iterR = readAreaPlcHs49_7.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs49_8 != null) { + iterR = readAreaPlcHs49_8.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs49_9 != null) { + iterR = readAreaPlcHs49_9.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs49_10 != null) { + iterR = readAreaPlcHs49_10.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs49_11 != null) { + iterR = readAreaPlcHs49_11.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs49_12 != null) { + iterR = readAreaPlcHs49_12.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs49_13 != null) { + iterR = readAreaPlcHs49_13.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs49_14 != null) { + iterR = readAreaPlcHs49_14.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs49_15 != null) { + iterR = readAreaPlcHs49_15.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs49_16 != null) { + iterR = readAreaPlcHs49_16.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + + + //============================================================= + try { + if (readAreaPlcHs48_1 != null) { + iterR = readAreaPlcHs48_1.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs48_2 != null) { + iterR = readAreaPlcHs48_2.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs48_3 != null) { + iterR = readAreaPlcHs48_3.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs48_4 != null) { + iterR = readAreaPlcHs48_4.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs48_5 != null) { + iterR = readAreaPlcHs48_5.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs48_6 != null) { + iterR = readAreaPlcHs48_6.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + try { + if (readAreaPlcHs48_7 != null) { + iterR = readAreaPlcHs48_7.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs48_8 != null) { + iterR = readAreaPlcHs48_8.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs48_9 != null) { + iterR = readAreaPlcHs48_9.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs48_10 != null) { + iterR = readAreaPlcHs48_10.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs48_11 != null) { + iterR = readAreaPlcHs48_11.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs48_12 != null) { + iterR = readAreaPlcHs48_12.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs48_13 != null) { + iterR = readAreaPlcHs48_13.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs48_14 != null) { + iterR = readAreaPlcHs48_14.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs48_15 != null) { + iterR = readAreaPlcHs48_15.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs48_16 != null) { + iterR = readAreaPlcHs48_16.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + + + //============================================================= + try { + if (readAreaPlcHs47_1 != null) { + iterR = readAreaPlcHs47_1.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs47_2 != null) { + iterR = readAreaPlcHs47_2.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs47_3 != null) { + iterR = readAreaPlcHs47_3.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs47_4 != null) { + iterR = readAreaPlcHs47_4.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs47_5 != null) { + iterR = readAreaPlcHs47_5.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs47_6 != null) { + iterR = readAreaPlcHs47_6.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + try { + if (readAreaPlcHs47_7 != null) { + iterR = readAreaPlcHs47_7.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs47_8 != null) { + iterR = readAreaPlcHs47_8.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs47_9 != null) { + iterR = readAreaPlcHs47_9.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs47_10 != null) { + iterR = readAreaPlcHs47_10.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs47_11 != null) { + iterR = readAreaPlcHs47_11.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs47_12 != null) { + iterR = readAreaPlcHs47_12.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs47_13 != null) { + iterR = readAreaPlcHs47_13.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs47_14 != null) { + iterR = readAreaPlcHs47_14.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs47_15 != null) { + iterR = readAreaPlcHs47_15.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs47_16 != null) { + iterR = readAreaPlcHs47_16.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + + + + + //============================================================= + try { + if (readAreaPlcHs46_1 != null) { + iterR = readAreaPlcHs46_1.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs46_2 != null) { + iterR = readAreaPlcHs46_2.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs46_3 != null) { + iterR = readAreaPlcHs46_3.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs46_4 != null) { + iterR = readAreaPlcHs46_4.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs46_5 != null) { + iterR = readAreaPlcHs46_5.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs46_6 != null) { + iterR = readAreaPlcHs46_6.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + try { + if (readAreaPlcHs46_7 != null) { + iterR = readAreaPlcHs46_7.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs46_8 != null) { + iterR = readAreaPlcHs46_8.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs46_9 != null) { + iterR = readAreaPlcHs46_9.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs46_10 != null) { + iterR = readAreaPlcHs46_10.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs46_11 != null) { + iterR = readAreaPlcHs46_11.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs46_12 != null) { + iterR = readAreaPlcHs46_12.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs46_13 != null) { + iterR = readAreaPlcHs46_13.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs46_14 != null) { + iterR = readAreaPlcHs46_14.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs46_15 != null) { + iterR = readAreaPlcHs46_15.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs46_16 != null) { + iterR = readAreaPlcHs46_16.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + + + + //============================================================= + try { + if (readAreaPlcHs45_1 != null) { + iterR = readAreaPlcHs45_1.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs45_2 != null) { + iterR = readAreaPlcHs45_2.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs45_3 != null) { + iterR = readAreaPlcHs45_3.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs45_4 != null) { + iterR = readAreaPlcHs45_4.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs45_5 != null) { + iterR = readAreaPlcHs45_5.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs45_6 != null) { + iterR = readAreaPlcHs45_6.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + try { + if (readAreaPlcHs45_7 != null) { + iterR = readAreaPlcHs45_7.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs45_8 != null) { + iterR = readAreaPlcHs45_8.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs45_9 != null) { + iterR = readAreaPlcHs45_9.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs45_10 != null) { + iterR = readAreaPlcHs45_10.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs45_11 != null) { + iterR = readAreaPlcHs45_11.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs45_12 != null) { + iterR = readAreaPlcHs45_12.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs45_13 != null) { + iterR = readAreaPlcHs45_13.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs45_14 != null) { + iterR = readAreaPlcHs45_14.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs45_15 != null) { + iterR = readAreaPlcHs45_15.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs45_16 != null) { + iterR = readAreaPlcHs45_16.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + + + //============================================================= + try { + if (readAreaPlcHs44_1 != null) { + iterR = readAreaPlcHs44_1.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs44_2 != null) { + iterR = readAreaPlcHs44_2.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs44_3 != null) { + iterR = readAreaPlcHs44_3.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs44_4 != null) { + iterR = readAreaPlcHs44_4.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs44_5 != null) { + iterR = readAreaPlcHs44_5.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs44_6 != null) { + iterR = readAreaPlcHs44_6.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + try { + if (readAreaPlcHs44_7 != null) { + iterR = readAreaPlcHs44_7.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs44_8 != null) { + iterR = readAreaPlcHs44_8.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs44_9 != null) { + iterR = readAreaPlcHs44_9.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs44_10 != null) { + iterR = readAreaPlcHs44_10.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs44_11 != null) { + iterR = readAreaPlcHs44_11.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs44_12 != null) { + iterR = readAreaPlcHs44_12.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs44_13 != null) { + iterR = readAreaPlcHs44_13.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs44_14 != null) { + iterR = readAreaPlcHs44_14.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs44_15 != null) { + iterR = readAreaPlcHs44_15.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs44_16 != null) { + iterR = readAreaPlcHs44_16.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + + + + //============================================================= + try { + if (readAreaPlcHs43_1 != null) { + iterR = readAreaPlcHs43_1.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs43_2 != null) { + iterR = readAreaPlcHs43_2.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs43_3 != null) { + iterR = readAreaPlcHs43_3.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs43_4 != null) { + iterR = readAreaPlcHs43_4.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs43_5 != null) { + iterR = readAreaPlcHs43_5.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs43_6 != null) { + iterR = readAreaPlcHs43_6.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + try { + if (readAreaPlcHs43_7 != null) { + iterR = readAreaPlcHs43_7.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs43_8 != null) { + iterR = readAreaPlcHs43_8.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs43_9 != null) { + iterR = readAreaPlcHs43_9.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs43_10 != null) { + iterR = readAreaPlcHs43_10.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs43_11 != null) { + iterR = readAreaPlcHs43_11.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs43_12 != null) { + iterR = readAreaPlcHs43_12.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs43_13 != null) { + iterR = readAreaPlcHs43_13.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs43_14 != null) { + iterR = readAreaPlcHs43_14.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs43_15 != null) { + iterR = readAreaPlcHs43_15.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs43_16 != null) { + iterR = readAreaPlcHs43_16.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + + + + + //============================================================= + try { + if (readAreaPlcHs42_1 != null) { + iterR = readAreaPlcHs42_1.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs42_2 != null) { + iterR = readAreaPlcHs42_2.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs42_3 != null) { + iterR = readAreaPlcHs42_3.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs42_4 != null) { + iterR = readAreaPlcHs42_4.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs42_5 != null) { + iterR = readAreaPlcHs42_5.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs42_6 != null) { + iterR = readAreaPlcHs42_6.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + try { + if (readAreaPlcHs42_7 != null) { + iterR = readAreaPlcHs42_7.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs42_8 != null) { + iterR = readAreaPlcHs42_8.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs42_9 != null) { + iterR = readAreaPlcHs42_9.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs42_10 != null) { + iterR = readAreaPlcHs42_10.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs42_11 != null) { + iterR = readAreaPlcHs42_11.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs42_12 != null) { + iterR = readAreaPlcHs42_12.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs42_13 != null) { + iterR = readAreaPlcHs42_13.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs42_14 != null) { + iterR = readAreaPlcHs42_14.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs42_15 != null) { + iterR = readAreaPlcHs42_15.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs42_16 != null) { + iterR = readAreaPlcHs42_16.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + + + + + //============================================================= + try { + if (readAreaPlcHs41_1 != null) { + iterR = readAreaPlcHs41_1.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs41_2 != null) { + iterR = readAreaPlcHs41_2.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs41_3 != null) { + iterR = readAreaPlcHs41_3.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs41_4 != null) { + iterR = readAreaPlcHs41_4.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs41_5 != null) { + iterR = readAreaPlcHs41_5.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs41_6 != null) { + iterR = readAreaPlcHs41_6.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + + try { + if (readAreaPlcHs41_7 != null) { + iterR = readAreaPlcHs41_7.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs41_8 != null) { + iterR = readAreaPlcHs41_8.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs41_9 != null) { + iterR = readAreaPlcHs41_9.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs41_10 != null) { + iterR = readAreaPlcHs41_10.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs41_11 != null) { + iterR = readAreaPlcHs41_11.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + + try { + if (readAreaPlcHs41_12 != null) { + iterR = readAreaPlcHs41_12.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs41_13 != null) { + iterR = readAreaPlcHs41_13.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs41_14 != null) { + iterR = readAreaPlcHs41_14.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs41_15 != null) { + iterR = readAreaPlcHs41_15.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + try { + if (readAreaPlcHs41_16 != null) { + iterR = readAreaPlcHs41_16.entrySet().iterator(); + if (iterR != null) { + boolean isprint = false; + currDecRun = currDecRun % iPrintcount; + if (currDecRun == 0) { + isprint = true; + } + currDecRun++; + while (iterR.hasNext()) { + entry = (Map.Entry) iterR.next(); + plcRVar = (ReadAreaPlcInterface) entry.getValue(); + dc.readBytes(plcRVar.DB, plcRVar.DBnum, plcRVar.start, plcRVar.len, null); + if (IsConnect()) { + plcRVar.udata = dc.getUdata(); + System.arraycopy(dc.getMsgIn(), 0, plcRVar.msgIn, 0, plcRVar.msgIn.length); + if (isprint) { + int length = plcRVar.msgIn.length; + for (int k = plcRVar.msgIn.length - 1; k > 0; k--) { + if (plcRVar.msgIn[k] != 0) { + length = k + 1; + break; + } + } + } + } else { + Logger.error("¶ÁÈ¡DB¿éÖÐÁ¬ÐøÇøÓòÐÅÏ¢ ÖжÏ"); + break; + } + } + } + } + } catch (Exception ex) { + System.out.println("104:Òì³£---------------readAreaPlcHs1-----------------------------------" + df.format(t)); + + //ex.printStackTrace(); + reConnect(); + } + + // дÈëµ½DB¿éÖÐÖ¸¶¨µÄλÖà + try { + if (IsConnect()) { + if (writePlcHs != null) { + t1 = System.currentTimeMillis(); + iterW = writePlcHs.entrySet().iterator(); + if (iterW != null) { + while (iterW.hasNext()) { + entry = (Map.Entry) iterW.next(); + plcWVar = (WriteDotPlcInterface) entry.getValue(); + groups = plcWVar.lsWriteGroupPlc; + for (i = 0; i < groups.size(); i++) { + group = groups.get(i); + dc.writeBytes(group.getArea(), group.getDBnum(), group.getStart(), + group.getLen(), group.getBuffer()); + Logger.info(" DB" + group.getDBnum() + ":¿ªÊ¼-" + group.getStart() + " ³¤¶È-" + + group.getLen() + " Ï·¢Öµ-" + group.getValue()); + if (IsConnect()) { + plcWVar.lsWriteGroupPlc.remove(i); + i--; + } else { + Logger.error("дÈëµ½DB101¿éÖÐÖ¸¶¨µÄλÖà ÖжÏ"); + break; + } + } + } + } + } + } + } catch (Exception ex) { + reConnect(); + } + + } else { + reConnect(); + } + Thread.sleep(1000); + } catch (Exception ex) { + reConnect(); + } + //reConnect(); + } + closeServer(); + } + + // ½«Ö¸¶¨byteÊý×éÒÔ16½øÖƵÄÐÎʽ´òÓ¡µ½¿ØÖÆÌ¨ + public static String printHexString(byte[] b, int length) { + String re = ""; + for (int i = 0; i < length; i++) { + String hex = Integer.toHexString(b[i] & 0xFF); + if (hex.length() == 1) { + hex = '0' + hex; + } + re += hex.toUpperCase() + " "; + } + return re; + } + + public static void main(String arg[]) { + byte[] ss = new byte[5]; + ss[0] = 1; + ss[1] = 0; + ss[2] = 16; + ss[3] = 0; + ss[4] = 0; + int length = ss.length; + for (int i = ss.length - 1; i > 0; i--) { + if (ss[i] != 0) { + length = i + 1; + break; + } + } + + // ¶ÁÈ¡Á÷03 00 00 2B 02 F0 80 32 03 00 00 00 00 00 02 00 16 00 00 04 01 FF + // 04 00 90 + // 89 02 00 80 37 01 02 37 01 00 18 5E 03 78 05 02 03 + byte[] ssz = Nodave.bswap_16(6238);// 18 5E ÈÎÎñºÅ + System.out.println(printHexString(ssz, ssz.length)); + byte[] msgIn = new byte[90]; + msgIn[10] = (byte) 0x18; // µÚ36 + msgIn[11] = (byte) 0x5E; // µÚ37 + System.out.println(Nodave.SBEWord(msgIn, 10)); + } +} \ No newline at end of file diff --git a/wcs.iml b/wcs.iml new file mode 100644 index 0000000..33e36bd --- /dev/null +++ b/wcs.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wmsdssconfig/abb/actionRelation.xml b/wmsdssconfig/abb/actionRelation.xml new file mode 100644 index 0000000..fc6e50c --- /dev/null +++ b/wmsdssconfig/abb/actionRelation.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/wmsdssconfig/abb/carcommand31.dat b/wmsdssconfig/abb/carcommand31.dat new file mode 100644 index 0000000000000000000000000000000000000000..fafc4f3b042ef346d262a267ce84ed591d917112 GIT binary patch literal 5 McmZ4UmVvbZ00)l(4*&oF literal 0 HcmV?d00001 diff --git a/wmsdssconfig/abb/cranecommand1.dat b/wmsdssconfig/abb/cranecommand1.dat new file mode 100644 index 0000000000000000000000000000000000000000..fafc4f3b042ef346d262a267ce84ed591d917112 GIT binary patch literal 5 McmZ4UmVvbZ00)l(4*&oF literal 0 HcmV?d00001 diff --git a/wmsdssconfig/abb/cranecommand2.dat b/wmsdssconfig/abb/cranecommand2.dat new file mode 100644 index 0000000000000000000000000000000000000000..fafc4f3b042ef346d262a267ce84ed591d917112 GIT binary patch literal 5 McmZ4UmVvbZ00)l(4*&oF literal 0 HcmV?d00001 diff --git a/wmsdssconfig/abb/exectask1.dat b/wmsdssconfig/abb/exectask1.dat new file mode 100644 index 0000000000000000000000000000000000000000..0581a716ab9760f69fd8a0a0c336ee70510fd3c1 GIT binary patch literal 84 zcmZ4UmVvdnh(S0ju`E%qv?Mb}&m*xoqa-mYCslYizpA3wlO4 + + + + + + + + + com.mysql.cj.jdbc.Driver + jdbc:mysql://172.16.2.170:3306/ft503 + root + Flrd0914. + 10 + + false + true + 50 + + + + + + + + + + + diff --git a/wmsdssconfig/abb/opcItemconfig.xml b/wmsdssconfig/abb/opcItemconfig.xml new file mode 100644 index 0000000..a3ba846 --- /dev/null +++ b/wmsdssconfig/abb/opcItemconfig.xml @@ -0,0 +1,442 @@ + + + + + + + + + + Yld.yldDevice.XC1.fromcar.RWH + Yld.yldDevice.XC1.fromcar.CZFS + Yld.yldDevice.XC1.fromcar.DQZT + Yld.yldDevice.XC1.fromcar.JDBZ + Yld.yldDevice.XC1.fromcar.ZYFS + Yld.yldDevice.XC1.fromcar.DQLH + Yld.yldDevice.XC1.fromcar.SSDJCS + Yld.yldDevice.XC1.fromcar.SSDJ + Yld.yldDevice.XC1.fromcar.WXBJ + + Yld.yldDevice.XC1.fromcar.CJCW + Yld.yldDevice.XC1.fromcar.YXJPCW + Yld.yldDevice.XC1.fromcar.YXBPBJ + Yld.yldDevice.XC1.fromcar.YXCS + Yld.yldDevice.XC1.fromcar.YXCJ + Yld.yldDevice.XC1.fromcar.SSBPBJ + Yld.yldDevice.XC1.fromcar.SSCS + Yld.yldDevice.XC1.fromcar.KGYW + Yld.yldDevice.XC1.fromcar.WXBJ + Yld.yldDevice.XC1.fromcar.QCCBJ + Yld.yldDevice.XC1.fromcar.HCCBJ + Yld.yldDevice.XC1.fromcar.CGBJ + Yld.yldDevice.XC1.fromcar.ZCKBJ + Yld.yldDevice.XC1.fromcar.YCKBJ + Yld.yldDevice.XC1.fromcar.QHWBWH + Yld.yldDevice.XC1.fromcar.FHWBYH + Yld.yldDevice.XC1.fromcar.SDCX + + + Yld.yldDevice.XC1.tocar.XCRWH + Yld.yldDevice.XC1.tocar.XCZLGS + Yld.yldDevice.XC1.tocar.XCYLH + Yld.yldDevice.XC1.tocar.XCMLH + Yld.yldDevice.XC1.tocar.XCZLXDBZ + Yld.yldDevice.XC1.tocar.XCJYM + + + + + + + + + Yld.yldDevice.DDJ1.fromddj.RWH + Yld.yldDevice.DDJ1.fromddj.CZFS + Yld.yldDevice.DDJ1.fromddj.DQZT + Yld.yldDevice.DDJ1.fromddj.JDBZ + Yld.yldDevice.DDJ1.fromddj.ZYFS + Yld.yldDevice.DDJ1.fromddj.DQPH + Yld.yldDevice.DDJ1.fromddj.DQLH + Yld.yldDevice.DDJ1.fromddj.DQCH + Yld.yldDevice.DDJ1.fromddj.QHWH + Yld.yldDevice.DDJ1.fromddj.FHYH + + Yld.yldDevice.DDJ1.fromddj.YXCJCW + Yld.yldDevice.DDJ1.fromddj.YXJPCW + Yld.yldDevice.DDJ1.fromddj.YXBPBJ + Yld.yldDevice.DDJ1.fromddj.YXCSBJ + Yld.yldDevice.DDJ1.fromddj.YXCJBJ + Yld.yldDevice.DDJ1.fromddj.QSCJCW + Yld.yldDevice.DDJ1.fromddj.QSJPCW + Yld.yldDevice.DDJ1.fromddj.QSBPBJ + Yld.yldDevice.DDJ1.fromddj.QSCSBJ + Yld.yldDevice.DDJ1.fromddj.QSCJBJ + Yld.yldDevice.DDJ1.fromddj.HCBMCW + Yld.yldDevice.DDJ1.fromddj.HCXHYW + Yld.yldDevice.DDJ1.fromddj.HCBPBJ + Yld.yldDevice.DDJ1.fromddj.HCCSBJ + Yld.yldDevice.DDJ1.fromddj.HCBZZW + Yld.yldDevice.DDJ1.fromddj.HWWXBJ + Yld.yldDevice.DDJ1.fromddj.FWWBYH + Yld.yldDevice.DDJ1.fromddj.QHWBWH + Yld.yldDevice.DDJ1.fromddj.SSGZ + + + Yld.yldDevice.DDJ1.toddj.DDJ01RWH + Yld.yldDevice.DDJ1.toddj.DDJ01ZLGS + Yld.yldDevice.DDJ1.toddj.DDJ01MBP + Yld.yldDevice.DDJ1.toddj.DDJ01MBL + Yld.yldDevice.DDJ1.toddj.DDJ01MBC + Yld.yldDevice.DDJ1.toddj.DDJ01ZLXDBZ + Yld.yldDevice.DDJ1.toddj.DDJ01JYM + + + + + Yld.yldDevice.DDJ2.fromddj.RWH + Yld.yldDevice.DDJ2.fromddj.CZFS + Yld.yldDevice.DDJ2.fromddj.DQZT + Yld.yldDevice.DDJ2.fromddj.JDBZ + Yld.yldDevice.DDJ2.fromddj.ZYFS + Yld.yldDevice.DDJ2.fromddj.DQPH + Yld.yldDevice.DDJ2.fromddj.DQLH + Yld.yldDevice.DDJ2.fromddj.DQCH + Yld.yldDevice.DDJ2.fromddj.QHWH + Yld.yldDevice.DDJ2.fromddj.FHYH + + Yld.yldDevice.DDJ2.fromddj.YXCJCW + Yld.yldDevice.DDJ2.fromddj.YXJPCW + Yld.yldDevice.DDJ2.fromddj.YXBPBJ + Yld.yldDevice.DDJ2.fromddj.YXCSBJ + Yld.yldDevice.DDJ2.fromddj.YXCJBJ + Yld.yldDevice.DDJ2.fromddj.QSCJCW + Yld.yldDevice.DDJ2.fromddj.QSJPCW + Yld.yldDevice.DDJ2.fromddj.QSBPBJ + Yld.yldDevice.DDJ2.fromddj.QSCSBJ + Yld.yldDevice.DDJ2.fromddj.QSCJBJ + Yld.yldDevice.DDJ2.fromddj.HCBMCW + Yld.yldDevice.DDJ2.fromddj.HCXHYW + Yld.yldDevice.DDJ2.fromddj.HCBPBJ + Yld.yldDevice.DDJ2.fromddj.HCCSBJ + Yld.yldDevice.DDJ2.fromddj.HCBZZW + Yld.yldDevice.DDJ2.fromddj.HWWXBJ + Yld.yldDevice.DDJ2.fromddj.FWWBYH + Yld.yldDevice.DDJ2.fromddj.QHWBWH + Yld.yldDevice.DDJ2.fromddj.SSGZ + + + Yld.yldDevice.DDJ2.toddj.DDJ02RWH + Yld.yldDevice.DDJ2.toddj.DDJ02ZLGS + Yld.yldDevice.DDJ2.toddj.DDJ02MBP + Yld.yldDevice.DDJ2.toddj.DDJ02MBL + Yld.yldDevice.DDJ2.toddj.DDJ02MBC + Yld.yldDevice.DDJ2.toddj.DDJ02ZLXDBZ + Yld.yldDevice.DDJ2.toddj.DDJ02JYM + + + + + + + + + Yld.yldDevice.SSJ.SSJI.SS1RKDW + Yld.yldDevice.SSJ.SSJI.SS1KXBZ + Yld.yldDevice.SSJ.SSJI.SS1TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS2RKDW + Yld.yldDevice.SSJ.SSJI.SS2KXBZ + Yld.yldDevice.SSJ.SSJI.SS2TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS3RKDW + Yld.yldDevice.SSJ.SSJI.SS3KXBZ + Yld.yldDevice.SSJ.SSJI.SS3TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS4RKDW + Yld.yldDevice.SSJ.SSJI.SS4KXBZ + Yld.yldDevice.SSJ.SSJI.SS4TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS5RKDW + Yld.yldDevice.SSJ.SSJI.SS5KXBZ + Yld.yldDevice.SSJ.SSJI.SS5TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS6RKDW + Yld.yldDevice.SSJ.SSJI.SS6KXBZ + Yld.yldDevice.SSJ.SSJI.SS6TASK + + + + + + + Yld.yldDevice.SSJ.SSJI.SS16DDBZ + Yld.yldDevice.SSJ.SSJI.SS16TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS18DDBZ + Yld.yldDevice.SSJ.SSJI.SS18TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS20DDBZ + Yld.yldDevice.SSJ.SSJI.SS20TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS22DDBZ + Yld.yldDevice.SSJ.SSJI.SS22TASK + + + + + + + Yld.yldDevice.SSJ.SSJI.SS24DDBZ + Yld.yldDevice.SSJ.SSJI.SS24TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS26DDBZ + Yld.yldDevice.SSJ.SSJI.SS26TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS28DDBZ + Yld.yldDevice.SSJ.SSJI.SS28TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS30DDBZ + Yld.yldDevice.SSJ.SSJI.SS30TASK + + + + + + + Yld.yldDevice.SSJ.SSJI.SS9RKDW + Yld.yldDevice.SSJ.SSJI.SS9TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS13RKDW + Yld.yldDevice.SSJ.SSJI.SS13TASK + + + + + + + Yld.yldDevice.SSJ.SSJI.SS15RKDW + Yld.yldDevice.SSJ.SSJI.SS15TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS17RKDW + Yld.yldDevice.SSJ.SSJI.SS17TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS19RKDW + Yld.yldDevice.SSJ.SSJI.SS19TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS21RKDW + Yld.yldDevice.SSJ.SSJI.SS21TASK + + + + + + + Yld.yldDevice.SSJ.SSJI.SS23RKDW + Yld.yldDevice.SSJ.SSJI.SS23TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS25RKDW + Yld.yldDevice.SSJ.SSJI.SS25TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS27RKDW + Yld.yldDevice.SSJ.SSJI.SS27TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS29RKDW + Yld.yldDevice.SSJ.SSJI.SS29TASK + + + + + + + Yld.yldDevice.SSJ.SSJI.SS10KXBZ + + + + + Yld.yldDevice.SSJ.SSJI.SS14KXBZ + + + + + + + Yld.yldDevice.SSJ.SSJI.SS7KXBZ + + + + + Yld.yldDevice.SSJ.SSJI.SS11KXBZ + + + + + + + Yld.yldDevice.SSJ.SSJI.SS15KXBZ + + + + + Yld.yldDevice.SSJ.SSJI.SS19KXBZ + + + + + + + Yld.yldDevice.SSJ.SSJI.SS23KXBZ + + + + + Yld.yldDevice.SSJ.SSJI.SS27KXBZ + + + + + + + Yld.yldDevice.SSJ.SSJI.SS8CKDW + Yld.yldDevice.SSJ.SSJI.SS8TASK + + + + + Yld.yldDevice.SSJ.SSJI.SS12CKDW + Yld.yldDevice.SSJ.SSJI.SS12TASK + + + + + + + Yld.yldDevice.XC1.tocar.JSSWQCSSDJ + + + + + + + Yld.yldDevice.SSJ.SSJI.SS16RWH + Yld.yldDevice.SSJ.SSJI.SS16XFBZ + Yld.yldDevice.SSJ.SSJI.SS16CRC + + + + + Yld.yldDevice.SSJ.SSJI.SS18RWH + Yld.yldDevice.SSJ.SSJI.SS18XFBZ + Yld.yldDevice.SSJ.SSJI.SS18CRC + + + + + Yld.yldDevice.SSJ.SSJI.SS20RWH + Yld.yldDevice.SSJ.SSJI.SS20XFBZ + Yld.yldDevice.SSJ.SSJI.SS20CRC + + + + + Yld.yldDevice.SSJ.SSJI.SS22RWH + Yld.yldDevice.SSJ.SSJI.SS22XFBZ + Yld.yldDevice.SSJ.SSJI.SS22CRC + + + + + + + Yld.yldDevice.SSJ.SSJI.SS24RWH + Yld.yldDevice.SSJ.SSJI.SS24XFBZ + Yld.yldDevice.SSJ.SSJI.SS24CRC + + + + + Yld.yldDevice.SSJ.SSJI.SS26RWH + Yld.yldDevice.SSJ.SSJI.SS26XFBZ + Yld.yldDevice.SSJ.SSJI.SS26CRC + + + + + Yld.yldDevice.SSJ.SSJI.SS28RWH + Yld.yldDevice.SSJ.SSJI.SS28XFBZ + Yld.yldDevice.SSJ.SSJI.SS28CRC + + + + + Yld.yldDevice.SSJ.SSJI.SS30RWH + Yld.yldDevice.SSJ.SSJI.SS30XFBZ + Yld.yldDevice.SSJ.SSJI.SS30CRC + + + + + + + diff --git a/wmsdssconfig/abb/ssxcommand1.dat b/wmsdssconfig/abb/ssxcommand1.dat new file mode 100644 index 0000000000000000000000000000000000000000..fafc4f3b042ef346d262a267ce84ed591d917112 GIT binary patch literal 5 McmZ4UmVvbZ00)l(4*&oF literal 0 HcmV?d00001 diff --git a/wmsdssconfig/abb/ssxcommand2.dat b/wmsdssconfig/abb/ssxcommand2.dat new file mode 100644 index 0000000000000000000000000000000000000000..0581a716ab9760f69fd8a0a0c336ee70510fd3c1 GIT binary patch literal 84 zcmZ4UmVvdnh(S0ju`E%qv?Mb}&m*xoqa-mYCslYizpA3wlO4 + + + + + + hzDsTest3 + + + + hzDs1 + + oracle.jdbc.driver.OracleDriver + jdbc:oracle:thin:@ + 192.168.8.172 + 1521 + orcl + zsjr + root + 50 + 5000 + select sysdate from dual + + + + + hzDs2 + + com.microsoft.sqlserver.jdbc.SQLServerDriver + jdbc:sqlserver:// + 192.168.10.180 + + 1433 + + DatabaseName=FT321 + sa + 123456 + 10 + 9000 + + + + + + hzDs99 + + com.microsoft.jdbc.sqlserver.SQLServerDriver + jdbc:microsoft:sqlserver:// + localhost + 1433 + DatabaseName=FT321 + sa + root + 30 + 9000 + select 1 + + + + + + hzDs3 + + com.microsoft.jdbc.sqlserver.SQLServerDriver + jdbc:microsoft:sqlserver:// + 172.16.2.170 + 1433 + DatabaseName=FT460 + sa + Flrd0914. + 30 + 9000 + select 1 + + + + + hzDsTest3 + + com.mysql.cj.jdbc.Driver + jdbc:mysql:// + localhost + 3306 + ft503 + root + root@123 + 30 + 9000 + SELECT 1 + + + + + + + hzDs8 + + com.microsoft.jdbc.sqlserver.SQLServerDriver + jdbc:microsoft:sqlserver:// + 127.0.0.1 + 1433 + DatabaseName=work + sa + 123456 + 30 + 9000 + select 1 + + + + + hzDs4 + + oracle.jdbc.driver.OracleDriver + jdbc:oracle:thin:@ + 192.168.8.26 + 1521 + zsjr2 + zsjr + zsjr123456 + 50 + 5000 + select sysdate from dual + + + + + hzDs5 + + oracle.jdbc.driver.OracleDriver + jdbc:oracle:thin:@ + 127.0.0.1 + 1521 + orcl + system + 123456 + 50 + 5000 + select sysdate from dual + + + + + + actionRelation.xml + opcItemconfig.xml + + + + + 9003 + 50 + 5 + 20 + 50 + 6000 + + + + + 172.20.21.201 + 102 + 1 + + + + + + WORKÉ豸ͨÐŵ÷¶Èϵͳ + images\\1.gif + 850 + 600 +

+ + É豸ͨÐÅ + 1 + + 16 + + Æô¡¡¡¡¶¯ + 1 + + 12 + 0 + com.wms.dss.ats.customs.abb.form.StartCorrespond + com.wms.dss.ats.customs.abb.plc.PLCCorrespondService + + + ·Ö¸ôÏß + + + + 1 + + + + Í£¡¡¡¡Ö¹ + 0 + + 14 + 0 + com.wms.dss.ats.customs.yld.form.StopCorrespond + + + + É豸µ÷¶È + 1 + + 16 + + Æô¡¡¡¡¶¯ + 1 + + 12 + 0 + com.wms.dss.common.server.form.StartSchedule + com.wms.dss.ats.customs.abb.schedule.ABBThreadSchedule + + + ·Ö¸ôÏß + + + + 1 + + + + Í£¡¡¡¡Ö¹ + 0 + + 14 + 0 + com.wms.dss.common.server.form.StopSchedule + + + + + + + ÊäËÍ»úͨÐÅÈÕÖ¾ + 16 + images\\now.gif + ÊäËÍ»úͨÐÅÈÕÖ¾ + 0 + + + ÊäËÍ»úµ÷¶ÈÈÕÖ¾ + 16 + images\\now.gif + ÊäËÍ»úµ÷¶ÈÈÕÖ¾ + 2 + + + + diff --git a/wmsdssconfig/dssconfig.properties b/wmsdssconfig/dssconfig.properties new file mode 100644 index 0000000..720aa3f --- /dev/null +++ b/wmsdssconfig/dssconfig.properties @@ -0,0 +1,4 @@ +#Copyright (c) ricosoft +#2011-04-19 +wmsdssconfig=abb +wmsdssconfigxml=wmsdssconfig.xml