Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public byte[] CreateSatateBytes(byte i)
        {
            log.Info("进入函数CreateSatateBytes");
            byte[] packBytes = new byte[7];
            packBytes[0] = 0xfe;
            packBytes[1] = 0xef;
            Array.Copy(
                BitConverter.GetBytes(Convert.ToInt16(ProjectInfoDic.GetInstance().GetProjectInfo().ProjectCode)),
                0,
                packBytes,
                2,
                2);
            packBytes[4] = i;
            byte[] crc16 = CheckModeResult.GetCheckResult(packBytes, 0, 3, CheckType.CRC16HighByteFirst);
            packBytes[5] = crc16[0];
            packBytes[6] = crc16[1];

            StringBuilder temp = new StringBuilder();

            for (int j = 0; j < 7; j++)
            {
                temp.Append(packBytes[j]);
            }
            log.Info("离开函数CreateSatateBytes:" + temp.ToString());
            return(packBytes);
        }
Пример #2
0
 public byte[] CreateSatateBytes(byte i, string dtuid)
 {
     byte[] packBytes = new byte[7];
     packBytes[0] = 0xfe;
     packBytes[1] = 0xef;
     // Array.Copy(,0,packBytes,2,2);
     packBytes[4] = i;
     byte[] crc16 = CheckModeResult.GetCheckResult(packBytes, 0, 3, CheckType.CRC16HighByteFirst);
     packBytes[5] = crc16[0];
     packBytes[6] = crc16[1];
     return(packBytes);
 }
        public byte[][] MakeDataTransportPacket(Data data, int structureId)
        {
            int num = data.DataSet.Count / MaxFloatcount;

            if (data.DataSet.Count % MaxFloatcount != 0)
            {
                num += 1;
            }

            byte[][] packet = new byte[num][];

            int i = 0;
            int j = 0;

            while (i < packet.Length)
            {
                var list = new List <byte> {
                    0xfe, 0xef
                };
                list.AddRange(BitConverter.GetBytes((short)data.ProjectCode));
                list.Add((byte)data.SafeTypeId);
                list.Add(00);
                list.Add(00);
                list.AddRange(BitConverter.GetBytes(Convert.ToInt16(data.MoudleNo)));
                list.Add((byte)data.ChannelId);
                list.Add((byte)num);
                list.Add((byte)i);
                list.AddRange(BitConverter.GetBytes(Convert.ToSingle(data.OFlag)));
                if (data.Reserve == null)
                {
                    list.Add(0x00);
                }
                else
                {
                    list.Add(Convert.ToByte(data.Reserve));
                }
                list.Add(0);
                list.AddRange(BitConverter.GetBytes(structureId));
                list.AddRange(BitConverter.GetBytes(data.CollectTime.Ticks));
                for (; j < data.DataSet.Count; j++)
                {
                    if (list.Count + 7 < 1024)
                    {
                        list.AddRange(BitConverter.GetBytes((float)data.DataSet[j]));
                    }
                    else
                    {
                        break;
                    }
                }
                list.AddRange(new byte[] { 0, 0 });
                list.Add(0x0d);
                packet[i] = list.ToArray();
                Array.Copy(BitConverter.GetBytes((short)packet[i].Length), 0, packet[i], 5, 2);
                byte[] crc16 = CheckModeResult.GetCheckResult(packet[i], 0, 4, CheckType.CRC16HighByteFirst);
                packet[i][packet[i].Length - 3] = crc16[0];
                packet[i][packet[i].Length - 2] = crc16[1];
                i++;
            }

            return(packet);
        }