Example #1
0
        /// <summary>
        /// 发送0个参数0字节泵站命令
        ///
        /// 0x00启泵
        /// 0x01停泵
        /// 0x0D清除水量运行记录
        /// 0x0E清除打卡记录
        /// 0x0F清除水量总水量
        /// 0x10清除已用时间
        /// 0x12读取泵站当前状态
        /// 0x13读取剩余水量
        /// 0x14读取总水量
        /// 0x15读取已用水量
        /// 0x16读取流量
        /// 0x17读取效率
        /// 0x19读取泵站强启状态
        /// 0x1A读取实时数据
        /// 0x1B读取振动传感器状态
        /// 0x1C读取总用水记录条数
        /// 0x1D读取最后一条用水记录的位置
        /// 0x1E读取管理卡密码
        /// 0x1F读取启亭卡密码
        /// 0x20读取数据卡密码
        /// 0x27读取泵站最后一次动作时的记录资料
        /// 0x29读取总打卡记录条数
        /// 0x2A读取最后一条打卡记录的位置
        /// 0x2C读取供电状态
        /// 0x2E读取接触器状态
        /// </summary>
        public byte[] MakeCommandHelp(int ComAdr, byte function)
        {
            byte[] outByte    = new byte[9];
            byte[] outByteVal = new byte[7];

            outByte[0]    = 0x21;
            outByteVal[0] = outByte[0];
            outByte[1]    = 0x58;
            outByteVal[1] = outByte[1];
            outByte[2]    = 0x44;
            outByteVal[2] = outByte[2];
            outByte[3]    = (byte)ComAdr;
            outByteVal[3] = outByte[3];
            //outByte[4] = 0xA1;
            outByte[4]    = PumpDefine.DEV_TYPE.FirstByte;
            outByteVal[4] = outByte[4];
            outByte[5]    = function;
            outByteVal[5] = outByte[5];
            outByte[6]    = 0x0;
            outByteVal[6] = outByte[6];
            //**************************
            crc        = CRC.CRC16(outByteVal);
            outByte[7] = crc[0];
            outByte[8] = crc[1];
            return(outByte);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="comAdr"></param>
        /// <param name="recordIdx"></param>
        /// <returns></returns>
        public byte[] MakeRecordCmd(int comAdr, int recordIdx)
        {
            byte[] outByte    = new byte[10];
            byte[] outByteVal = new byte[8];

            outByte[0]    = 0x40;
            outByteVal[0] = outByte[0];
            outByte[1]    = 0x58;
            outByteVal[1] = outByte[1];
            outByte[2]    = 0x44;
            outByteVal[2] = outByte[2];
            outByte[3]    = (byte)comAdr;
            outByteVal[3] = outByte[3];
            outByte[4]    = 0x0B;
            outByteVal[4] = outByte[4];
            outByte[5]    = 0x25;
            outByteVal[5] = outByte[5];
            outByte[6]    = 0x09;
            outByteVal[6] = outByte[6];
            outByte[7]    = (byte)recordIdx;
            outByteVal[7] = outByte[7];
            //**************************
            crc        = CRC.CRC16(outByteVal);
            outByte[8] = crc[0];
            outByte[9] = crc[1];
            return(outByte);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="dataLength"></param>
        /// <param name="refValue"></param>
        public PumpProcessor(byte[] data, int Len, ref object oPars)
        {
            //进行校验
            //
            if (Len <= 2)
            {
                oPars     = null;
                _dataFlag = DataFlag.LENGTH_ERROR;
                return;
            }

            //进行校验
            byte[] DataVal = new byte[Len - 2];
            for (int i = 0; i < Len - 2; i++)
            {
                DataVal[i] = data[i];
            }
            crc = CRC.CRC16(DataVal);

            //分析数据
            if (data[Len - 2] == crc[0] && data[Len - 1] == crc[1])
            {
                address = (int)data[3];//得到站号
                switch (data[5])
                {
                //实时数据
                case PumpDefine.FCDefine.FC_READREAL:
                {
                    // 正常数据长度应该为46
                    // 有可能上传长度为28且CRC校验正确的数据
                    //
                    if (data.Length == 46)
                    {
                        //Read_Rlt(data, ref refValue);
                        PumpRealData prd = ParseRealData(data);
                        oPars = prd;
                    }
                    else
                    {
                        _dataFlag = DataFlag.LENGTH_ERROR;
                        oPars     = null;
                        return;
                    }
                }
                break;
                }
                this._dataFlag = DataFlag.OK;
            }
            else
            {
                this._dataFlag = DataFlag.CRC_ERROR;
                oPars          = null;
            }
        }
Example #4
0
        /// <summary>
        /// 解析来自口门测控仪数据
        /// </summary>
        /// <param name="data">用户数据</param>
        /// <param name="dataLength"></param>
        /// <param name="refValue">返回结果</param>
        public GateReader(byte[] data, ref object oPars)
        {
            int dataLength = 0;

            if (data != null)
            {
                dataLength = data.Length;
            }

            //TODO: len < 2, 2007-06-25 Added
            //
            //进行校验
            if (dataLength <= 2)
            {
                oPars     = null;
                _dataFlag = DataFlag.LENGTH_ERROR;
                return;
            }

            byte[] dataValue = new byte[dataLength - 2];
            for (int i = 0; i < dataLength - 2; i++)
            {
                dataValue[i] = data[i];
            }
            crc = CRC.CRC16(dataValue);

            //分析数据(带校验)
            //
            // crc success
            //
            if (data[dataLength - 2] == crc[0] && data[dataLength - 1] == crc[1])
            {
                //得到站号
                comAdr = (int)data[3];

                // data[5] - Function code
                //
                switch (data[5])
                {
                //参数数据
                case 0x23:
                    Read_Par(data, ref oPars);
                    break;

                //实时数据
                case 0x24:
                    Read_Rlt(data, ref oPars);
                    break;

                //历史记录
                case 0x25:
                {
                    if (!Read_His(data, ref oPars))
                    {
                        _dataFlag = DataFlag.DATA_ERROR;
                        oPars     = null;
                        return;
                    }
                    break;
                }

                //输入水量记录
                //
                case 0x37:
                    Read_InWater(data, ref oPars);
                    break;

                //最后一条记录
                //
                case 0x3C:
                    if (!Read_His(data, ref oPars))
                    {
                        _dataFlag = DataFlag.DATA_ERROR;
                        oPars     = null;
                        return;
                    }
                    break;

                //读取状态量
                //
                default:
                    Read_Sts(data, ref oPars);
                    break;
                }
                _dataFlag = DataFlag.OK;
            }
            else
            {
                _dataFlag = DataFlag.CRC_ERROR;
                oPars     = null;
            }
        }