private UnPackageError CheckedPackageData(byte[] data, out SlaveReplyDataBase replyDataBase) { try { replyDataBase = null; switch (OrderCmd) { case 0x01: replyDataBase = new SlaveReadCoilsReplyData(SlaveID, OrderCmd, Data); break; case 0x02: replyDataBase = new SlaveReadDiscreteInputsReplyData(SlaveID, OrderCmd, Data); break; case 0x03: replyDataBase = new SlaveReadHoldingRegisterReplyData(SlaveID, OrderCmd, Data); break; case 0x04: replyDataBase = new SlaveReadInputRegistersReplyData(SlaveID, OrderCmd, Data); break; default: replyDataBase = new SlaveUnknownReplyData(SlaveID, OrderCmd, Data); break; } return(UnPackageError.Normal); } catch (Exception ex) { throw CreateUnPackageException("CheckedPackageData", ex, data); } }
private UnPackageError CheckedPackageData(byte[] data, out SlaveReplyDataBase replyDataBase) { try { replyDataBase = null; byte[] _expectCrc = ByteHelper.ToBytes(CRCBuilder.Calu16MODBUS(CrcCaluData), false); if (!ArrayHelper.CompletelyEqual(_expectCrc, CRC)) { return(UnPackageError.CRCError); } switch (OrderCmd) { case 0x01: replyDataBase = new SlaveReadCoilsReplyData(SlaveID, OrderCmd, Data); break; case 0x02: replyDataBase = new SlaveReadDiscreteInputsReplyData(SlaveID, OrderCmd, Data); break; case 0x03: replyDataBase = new SlaveReadHoldingRegisterReplyData(SlaveID, OrderCmd, Data); break; case 0x04: replyDataBase = new SlaveReadInputRegistersReplyData(SlaveID, OrderCmd, Data); break; default: replyDataBase = new SlaveUnknownReplyData(SlaveID, OrderCmd, Data); break; } return(UnPackageError.Normal); } catch (Exception ex) { throw CreateUnPackageException("CheckedPackageData", ex, data); } }