Esempio n. 1
0
        /// <summary>
        /// 小盒子
        /// </summary>
        /// <returns></returns>
        public byte[] ToArray2()
        {
            List <byte> data = new List <byte>();

            data.Add(this.ChannnelNum);
            data.Add((byte)(this.SampleRate & 0xff));
            data.Add((byte)(((this.State & 0x01) << 7) | ((this.SampleRate >> 8) & 0xff)));
            data.Add(this.ChannelType);
            //时间
            data.Add((byte)(this.Time.Year - 2000));
            data.Add((byte)(this.Time.Month));
            data.Add((byte)(this.Time.Day));

            //名字
            byte nameLen = 0;

            byte[] name = null;
            if (string.IsNullOrEmpty(this.Person) == false)
            {
                name    = ASCIIEncoding.UTF8.GetBytes(this.Person);
                nameLen = (byte)name.Length;
                if (nameLen > 8)
                {
                    nameLen = 8;
                }
            }
            data.Add(nameLen);
            for (int i = 0; i < 8; i++)
            {
                if (name != null && name.Length > i)
                {
                    data.Add(name[i]);
                }
                else
                {
                    data.Add(0);
                }
            }

            //校准参数

            for (int i = 0; i < 21; i++)
            {
                if (calList.Count > i)
                {
                    data.AddRange(calList[i].ToArray3());
                }
                else
                {
                    data.AddRange(CalcItem.NULLData3);
                }
            }

            //
            for (int i = 0; i < 2; i++)
            {
                data.Add(0);
            }


            byte[] dat = data.ToArray();

            UInt16 crc = CRC16.ComputeCRC16(dat, 1, dat.Length - 1);


            data.Add((byte)(crc & 0xff));
            data.Add((byte)(crc >> 8));

            return(data.ToArray());
        }
Esempio n. 2
0
        public byte[] ToArray()
        {
            List <byte> data = new List <byte>();

            data.Add(this.ChannnelNum);
            data.Add((byte)(this.SampleRate & 0xff));
            data.Add((byte)(((this.State & 0x01) << 7) | ((this.SampleRate >> 8) & 0xff)));
            data.Add(this.ChannelType);
            //时间
            data.Add((byte)(this.Time.Year - 2000));
            data.Add((byte)(this.Time.Month));
            data.Add((byte)(this.Time.Day));

            //名字
            byte nameLen = 0;

            byte[] name = null;
            if (string.IsNullOrEmpty(this.Person) == false)
            {
                name    = ASCIIEncoding.UTF8.GetBytes(this.Person);
                nameLen = (byte)name.Length;
                if (nameLen > 7)
                {
                    nameLen = 7;
                }
            }
            data.Add(nameLen);
            for (int i = 0; i < 7; i++)
            {
                if (name != null && name.Length > i)
                {
                    data.Add(name[i]);
                }
                else
                {
                    data.Add(0);
                }
            }

            //校准参数
            AddZLCalcparam(data, 0, 0);
            AddJLCalcparam(data, 25, 0);
            AddJLCalcparam(data, 50, 0);
            AddJLCalcparam(data, 100, 0);
            AddJLCalcparam(data, 200, 0);
            AddJLCalcparam(data, 550, 0);
            AddJLCalcparam(data, 650, 0);
            AddJLCalcparam(data, 750, 0);
            AddJLCalcparam(data, 850, 0);
            AddJLCalcparam(data, 1700, 0);
            AddJLCalcparam(data, 2000, 0);
            AddJLCalcparam(data, 2300, 0);
            AddJLCalcparam(data, 2600, 0);

            AddZLCalcparam(data, 0, 1);
            AddJLCalcparam(data, 25, 1);
            AddJLCalcparam(data, 50, 1);
            AddJLCalcparam(data, 100, 1);
            AddJLCalcparam(data, 200, 1);
            AddJLCalcparam(data, 550, 1);
            AddJLCalcparam(data, 650, 1);
            AddJLCalcparam(data, 750, 1);
            AddJLCalcparam(data, 850, 1);
            AddJLCalcparam(data, 1700, 1);
            AddJLCalcparam(data, 2000, 1);
            AddJLCalcparam(data, 2300, 1);
            AddJLCalcparam(data, 2600, 1);

            AddZLCalcparam(data, 0, 2);
            AddJLCalcparam(data, 25, 2);
            AddJLCalcparam(data, 50, 2);
            AddJLCalcparam(data, 100, 2);
            AddJLCalcparam(data, 200, 2);
            AddJLCalcparam(data, 550, 2);
            AddJLCalcparam(data, 650, 2);
            AddJLCalcparam(data, 750, 2);
            AddJLCalcparam(data, 850, 2);
            AddJLCalcparam(data, 1700, 2);
            AddJLCalcparam(data, 2000, 2);
            AddJLCalcparam(data, 2300, 2);
            AddJLCalcparam(data, 2600, 2);

            AddZLCalcparam(data, 0, 3);
            AddJLCalcparam(data, 25, 3);
            AddJLCalcparam(data, 50, 3);
            AddJLCalcparam(data, 100, 3);
            AddJLCalcparam(data, 200, 3);
            AddJLCalcparam(data, 550, 3);
            AddJLCalcparam(data, 650, 3);
            AddJLCalcparam(data, 750, 3);
            AddJLCalcparam(data, 850, 3);
            AddJLCalcparam(data, 1700, 3);
            AddJLCalcparam(data, 2000, 3);
            AddJLCalcparam(data, 2300, 3);
            AddJLCalcparam(data, 2600, 3);


            byte[] dat = data.ToArray();

            UInt16 crc = CRC16.ComputeCRC16(dat, 1, dat.Length - 1);


            data.Add((byte)(crc & 0xff));
            data.Add((byte)(crc >> 8));

            return(data.ToArray());
        }
Esempio n. 3
0
        /// <summary>
        /// 综合电压采集模块
        /// </summary>
        /// <param name="data"></param>
        /// <param name="offset"></param>
        public ChannelParam(byte[] data, int offset)
        {
            InitialMydictionary();
            UInt16 crc = CRC16.ComputeCRC16(data, offset + 1, 128 - 2);


            UInt16 crcCal = BitConverter.ToUInt16(data, offset + 1 + 128 - 2);


            if (crc != crcCal)
            {
                return;
            }

            this.ChannnelNum = data[0 + offset];
            this.State       = (byte)(data[2 + offset] >> 7);
            this.SampleRate  = data[1 + offset] + ((data[2 + offset] & 0x1f) << 8);

            this.ChannelType = data[3 + offset];
            //时间
            int year  = data[4 + offset] + 2000;
            int month = data[5 + offset];
            int day   = data[6 + offset];

            this.Time = new DateTime(year, month, day);

            //名字
            int num = data[7 + offset];

            if (num > 0)
            {
                num = num > 7 ? 7 : num;

                this.Person = ASCIIEncoding.UTF8.GetString(data, 8 + offset, num);
            }
            else
            {
                this.Person = "";
            }


            for (int i = 0; i < 52; i++)
            {
                if (i < 13)
                {
                    if (i == 0)
                    {
                        CalcItem calItm2 = new CalcItem(data, 15 + offset, 0, 0, true);
                        if (calItm2.IsValid)
                        {
                            calList.Add(calItm2);
                        }
                    }
                    else
                    {
                        CalcItem calItm = new CalcItem(data, 15 + (i - 1) * 2 + offset + 4, i, 0);
                        if (calItm.IsValid)
                        {
                            calList.Add(calItm);
                        }
                    }
                }
                else if (i < 26)
                {
                    if (i == 13)
                    {
                        CalcItem calItm2 = new CalcItem(data, 15 + 12 * 2 + 4 + offset, 0, 1, true);
                        if (calItm2.IsValid)
                        {
                            calList.Add(calItm2);
                        }
                    }
                    else
                    {
                        CalcItem calItm = new CalcItem(data, 15 + (i - 2) * 2 + offset + 8, i - 13, 1);
                        if (calItm.IsValid)
                        {
                            calList.Add(calItm);
                        }
                    }
                }
                else if (i < 39)
                {
                    if (i == 26)
                    {
                        CalcItem calItm2 = new CalcItem(data, 15 + 24 * 2 + offset + 8, 0, 2, true);
                        if (calItm2.IsValid)
                        {
                            calList.Add(calItm2);
                        }
                    }
                    else
                    {
                        CalcItem calItm = new CalcItem(data, 15 + (i - 3) * 2 + offset + 12, i - 26, 2);
                        if (calItm.IsValid)
                        {
                            calList.Add(calItm);
                        }
                    }
                }
                else if (i < 52)
                {
                    if (i == 39)
                    {
                        CalcItem calItm2 = new CalcItem(data, 15 + 36 * 2 + offset + 12, 0, 3, true);
                        if (calItm2.IsValid)
                        {
                            calList.Add(calItm2);
                        }
                    }
                    else
                    {
                        CalcItem calItm = new CalcItem(data, 15 + (i - 4) * 2 + offset + 16, i - 39, 3);
                        if (calItm.IsValid)
                        {
                            calList.Add(calItm);
                        }
                    }
                }
            }
        }