コード例 #1
0
        public static UInt32 AppendInt16Data(ref byte[] buffer, UInt32 bufferLength, Int16 s16Data)
        {
            var ktls = buffer.ToList();

            ktls.AddRange(BytesConvertHelper.ConvertInt16ToByteArray(s16Data));
            buffer = ktls.ToArray();

            return(2);
        }
コード例 #2
0
        public static byte[] PacketTestWorkGraphDataPackage(byte slaveId)
        {
            const byte periodPointCount = 135;

            var buffer = new byte[0];

            // Zigbee短地址,即Modbus设备地址
            AppendByte(ref buffer, slaveId);
            //功能码
            AppendByte(ref buffer, MB_FUNC_SLAVE_WORKGRAPH_DATA);
            //RTU设备编号
            AppendBytes(ref buffer, BytesConvertHelper.ConvertInt32ToByteArray(0x13FFFF00 + slaveId));
            //长度,先占位,后面填充
            AppendBytes(ref buffer, BytesConvertHelper.ConvertInt16ToByteArray(11 + 135 * 4));
            //采样点数 PointCount
            AppendByte(ref buffer, periodPointCount);
            //采样间隔 SampleInterval*100
            AppendBytes(ref buffer, BytesConvertHelper.ConvertInt16ToByteArray((short)(1562)));

            ////以下为数据部分
            //////////////////////////////////////////////////////////////////
            //以数据填充开始
            //////////////////////////////////////////////////////////////////

            for (var i = 0; i < periodPointCount; i++)
            {
                AppendBytes(ref buffer, BytesConvertHelper.ConvertInt16ToByteArray(ForceBuffer[i]));
            }
            for (var i = 0; i < periodPointCount; i++)
            {
                AppendBytes(ref buffer, BytesConvertHelper.ConvertInt16ToByteArray(ForceBuffer[i]));
            }

            //////////////////////////////////////////////////////////////////
            //数据填充结束
            //////////////////////////////////////////////////////////////////

            ////数据部分结束

            ////以下为包尾固定部分
            //计算并保存CRC
            AppendBytes(ref buffer, buffer.CRC16());

            //包头标志
            InsertByte(ref buffer, 0, Pack_SYN_C);
            InsertByte(ref buffer, 0, Pack_SYN_B);
            InsertByte(ref buffer, 0, Pack_SYN_A);

            //包尾标志
            AppendByte(ref buffer, Pack_STOP_A);
            AppendByte(ref buffer, Pack_STOP_B);
            AppendByte(ref buffer, Pack_STOP_C);

            return(buffer);
        }