예제 #1
0
 public byte[] ToArray()
 {
     using (ByteArrayBuilder builder = new ByteArrayBuilder())
     {
         builder.Append(CRCCaluData);
         byte[] _crcValue = ByteHelper.ToBytes(CRCBuilder.Calu16MODBUS(CRCCaluData), false);
         builder.Append(_crcValue);
         return(builder.ToArray());
     }
 }
예제 #2
0
 public void Create16MODBUSTest()
 {
     byte[] _testData = new byte[16] {
         0x05, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x86, 0x80, 0x00, 0x02, 0xFF, 0xFF
     };
     byte[] _expect = new byte[2] {
         0x3C, 0xA4
     };
     byte[] _actual = ByteHelper.ToBytes(CRCBuilder.Calu16MODBUS(_testData), false);
     CollectionAssert.AreEqual(_expect, _actual);
 }
예제 #3
0
        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);
            }
        }
        public byte[] GetCaluCrcValue(byte[] buffer)
        {
            ushort _crcValue = CRCBuilder.Calu16MODBUS(buffer);

            return(ByteHelper.ToBytes(_crcValue, false));
        }