Exemplo n.º 1
0
        /// <summary>
        /// 直流
        /// </summary>
        /// <returns></returns>

        public byte[] ToArray2()
        {
            //byte[] data = new byte[4];
            List <byte> data = new List <byte>();

            //int freq = Array.IndexOf(FrequencyArray, this.Freq);
            //byte freqval = (byte)freq;
            //byte freqtmp = (byte)(freqval << 4);
            //byte gearval = this.Gear;
            //byte xx = (byte)(freqtmp + gearval);

            //data[0] = (byte)((freqval << 4) + gearval);
            //data[0] = freqval;
            Int16 tmp = HalfFloat.ToInt16(this.CoeffK);

            data.Add((byte)(tmp & 0xff));
            data.Add((byte)((tmp >> 8) & 0xff));
            //if(freqval == 0)
            //{
            tmp = HalfFloat.ToInt16(this.CoeffB);
            data.Add((byte)(tmp & 0xff));
            data.Add((byte)((tmp >> 8) & 0xff));
            //}
            return(data.ToArray());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 交流
        /// </summary>
        /// <returns></returns>
        ///
        public byte[] ToArray()
        {
            List <byte> data = new List <byte>();

            Int16 tmp = HalfFloat.ToInt16(this.CoeffK);

            data.Add((byte)(tmp & 0xff));
            data.Add((byte)((tmp >> 8) & 0xff));
            //tmp = HalfFloat.ToInt16(this.CoeffB);
            //data.Add((byte)(tmp & 0xff));
            //data.Add((byte)((tmp >> 8) & 0xff));
            ////}
            return(data.ToArray());
        }
Exemplo n.º 3
0
        /// <summary>
        /// 综合电压采集模块直流电压
        /// </summary>
        /// <param name="data"></param>
        /// <param name="offset"></param>
        /// <param name="flag"></param>
        public CalcItem(byte[] data, int offset, int freqindex, int gearindex, bool flag)
        {
            this.IsValid = false;
            if (data[offset] == 0xff)
            {
                return;
            }

            //byte freqindex = (byte)(data[offset]>>4);
            //byte gearval = (byte)(data[offset]&0x0F);
            this.Freq = FrequencyArray[freqindex];
            this.Gear = (byte)gearindex;

            this.CoeffK = HalfFloat.ToSingle(BitConverter.ToInt16(data, offset));
            this.CoeffB = HalfFloat.ToSingle(BitConverter.ToInt16(data, offset + 2));

            this.IsValid = true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 小盒子
        /// </summary>
        /// <returns></returns>
        public byte[] ToArray3()
        {
            byte[] data = new byte[5];

            int  freq    = Array.IndexOf(FrequencyArray, this.Freq);
            byte freqval = (byte)freq;
            //byte freqtmp = (byte)(freqval << 4);
            byte gearval = this.Gear;

            //byte xx = (byte)(freqtmp + gearval);

            data[0] = (byte)((freqval << 4) + gearval);
            Int16 tmp = HalfFloat.ToInt16(this.CoeffK);

            data[1] = (byte)(tmp & 0xff);
            data[2] = (byte)((tmp >> 8) & 0xff);

            tmp     = HalfFloat.ToInt16(this.CoeffB);
            data[3] = (byte)(tmp & 0xff);
            data[4] = (byte)((tmp >> 8) & 0xff);

            return(data);
        }