Beispiel #1
0
 /// <summary>
 /// 向设备查询Error Code的详细解释
 /// 通过该功能,主机可向设备查询每个Error Code的详细英文解释。
 /// !!!注意:一次请求只能查询一个error code的解释。
 /// </summary>
 /// <param name="destid"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static byte[] ExplainError(byte destid, ushort error)
 {
     byte []             donedata;
     byte[]              data   = GetData(error);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.GetErrorInfo;
     _frame.msgSubType = (byte)MSGEncoding.Other.GetErrorInfo;
     _frame.dataLen    = (ushort)data.Length;
     donedata          = PrepareData.MergeMsg(ref _frame, data);
     return(donedata);
 }
Beispiel #2
0
 /// <summary>
 /// LoopBack测试一般只会用在文件传输上,指定的文件的内容通过CRC校验可以确保是否一样
 /// 无须按字节对比,或者equal  还是字节对比快
 /// </summary>
 /// <param name="destid"></param>
 /// <param name="testlen"></param>
 /// <returns></returns>
 public static byte[] LoopTest(byte destid, ushort testlen)
 {
     byte[] donedata;
     byte[] data = GetData(testlen);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.ReadBuffer;
     _frame.msgSubType = (byte)MSGEncoding.ReadBuffer.ReadCO2Cache;
     _frame.dataLen    = (ushort)data.Length;
     donedata          = PrepareData.MergeMsg(ref _frame, data);
     return(donedata);
 }
Beispiel #3
0
 /// <summary>
 /// 上传升级文件到设备
 /// </summary>
 /// <param name="destid"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static byte[] UpGradeFile(byte destid, WriteFile.Parameter para)
 {
     byte[] donedata;
     byte[] tempdata            = GetData(para, (int)FileType.UpGradeFile);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.WriteFile;
     _frame.msgSubType = (byte)MSGEncoding.WriteFile.UpGradeFile;
     _frame.dataLen    = (ushort)tempdata.Length;
     donedata          = PrepareData.MergeMsg(ref _frame, tempdata);
     return(donedata);
 }
Beispiel #4
0
 /// <summary>
 /// 读取指定配置文件,从x位置开始的n个字节数据
 /// </summary>
 /// <param name="destid"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static byte[] ReadDataFile(byte destid, ReadFile.Parameter para)
 {
     byte[] donedata;
     byte[] data = GetData(para);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.ReadFile;
     _frame.msgSubType = (byte)MSGEncoding.ReadFile.ReadDataFile;
     _frame.dataLen    = (ushort)data.Length;
     donedata          = PrepareData.MergeMsg(ref _frame, data);
     return(donedata);
 }
Beispiel #5
0
 /// <summary>
 /// 查询设备状态
 /// </summary>
 /// <param name="destid"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static byte[] GetDevStatus(byte destid, ushort[] unit)
 {
     byte[] donedata;
     byte[] data = GetData(unit);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.ReadUnit;
     _frame.msgSubType = (byte)MSGEncoding.ReadUint.GetDevStatus;
     _frame.dataLen    = (ushort)data.Length;
     donedata          = PrepareData.MergeMsg(ref _frame, data);
     return(donedata);
 }
Beispiel #6
0
 //写数据
 public static byte[] WriteData(byte destid, Dictionary <string, string> datadict)
 {
     byte[] donedata;
     byte[] data = GetData(datadict);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.WriteUnit;
     _frame.msgSubType = (byte)MSGEncoding.WriteUint.WriteData;
     _frame.dataLen    = (ushort)data.Length;
     donedata          = PrepareData.MergeMsg(ref _frame, data);
     return(donedata);
 }
Beispiel #7
0
 //重载
 public static byte[] ControlDev(byte destid, Dictionary <ushort, object> datadict)
 {
     byte[] donedata;
     byte[] data = GetData(datadict);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.WriteUnit;
     _frame.msgSubType = (byte)MSGEncoding.WriteUint.ControlDev;
     _frame.dataLen    = (ushort)data.Length;
     //长短包的区分和数据组合在MergeMsg()方法中完成
     donedata = PrepareData.MergeMsg(ref _frame, data);
     return(donedata);
 }
Beispiel #8
0
        /// <summary>
        /// 接收到返回包的处理方法
        /// </summary>
        /// <param name="error"></param>
        /// <param name="b_recvframe"></param>
        /// <returns></returns>
        public static Dictionary <long, ushort> MsgHandle(ref ushort error, byte[] b_recvframe)
        {
            Dictionary <long, ushort> retinfo = new Dictionary <long, ushort>();

            //如果是短帧,一定没有查找到文件,相反如果是长帧一定查询到文件
            switch (HandleData.TypeofFrame(b_recvframe).frametype)
            {
            //长帧(查询到文件)
            case 1:
            {
                //接收数据的拆分
                byte[] recvframeout = new byte[b_recvframe.Length - PrepareData.BUS_FRAME_MINLEN - 2];
                Array.Copy(b_recvframe, PrepareData.BUS_FRAME_MINLEN, recvframeout, 0,
                           b_recvframe.Length - PrepareData.BUS_FRAME_MINLEN - 2);
                //传入的字节数组只包括执行状态字和返回数据(除CRC外)
                TransInfo(recvframeout, retinfo);
            }
            break;

            //短帧(未查询到文件)
            //不存在符合要求的文件、查询出错、配置文件应该会有,设备出厂默认配置、查询错误返回错误代码
            case 0:
            {
                byte[] errortemp         = new byte[2];
                PrepareData.Msg_Bus temp = (PrepareData.Msg_Bus)ByteStruct.BytesToStruct(
                    b_recvframe,
                    typeof(PrepareData.Msg_Bus));
                //从原始数据中截取两个首字节,错误代码只有两个字节
                Array.Copy(temp.data, 0, errortemp, 0, 2);
                error   = BitConverter.ToUInt16(errortemp, 0);
                error   = (ushort)ByteStruct.BytesToStruct(errortemp, typeof(ushort));
                retinfo = null;
            }
            break;

            //错误
            default:
            {
                retinfo = null;
                //MessageBox.Show("获取文件信息的长短帧错误!");
            }
            break;
            }
            return(retinfo);
        }
Beispiel #9
0
        /// <summary>
        /// 取得配置文件名称(=最新更新时间)及文件大小
        /// </summary>
        /// <param name="destid"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static byte[] GetXFileByLately(byte destid, GetFileInfo.Parameter para)
        {
            byte[] donedata;
            byte   subtype = (byte)MSGEncoding.GetFileInfo.GetXFileByLately;

            byte[] data = GetFileInfo.GetData(para, subtype);
            PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
            _frame.flag       = PrepareData.BUS_FRAME_FLAG;
            _frame.srcID      = MSGEncoding.srcID;
            _frame.destID     = destid;
            _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
            _frame.msgVer     = MSGEncoding.msgVer;
            _frame.msgType    = (byte)MSGEncoding.MsgType.GetFileInfo;
            _frame.msgSubType = (byte)MSGEncoding.GetFileInfo.GetXFileByLately;
            _frame.dataLen    = (ushort)data.Length;
            donedata          = PrepareData.MergeMsg(ref _frame, data);
            return(donedata);
        }
Beispiel #10
0
 /// <summary>
 /// 上传数据文件到设备
 /// </summary>
 /// <param name="destid"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static byte[] UpcfgToDev(byte destid, WriteFile.Parameter para)
 {
     byte[] donedata;
     //由于结构体中普通文件和升级文件的名字都会给出,通过getdata的第二参数标定,为0为普通文件(数据和配置)
     //不再讨论文件类别,只给出编号,相应的文件以包装进类中
     //恢复文件类型标准,由于para和fileitem死循环产生
     byte[] tempdata            = GetData(para, (int)FileType.CfgOrDataFile);
     PrepareData.Msg_Bus _frame = new PrepareData.Msg_Bus();
     _frame.flag       = PrepareData.BUS_FRAME_FLAG;
     _frame.srcID      = MSGEncoding.srcID;
     _frame.destID     = destid;
     _frame.msgDir     = (byte)MSGEncoding.MsgDir.Request;
     _frame.msgVer     = MSGEncoding.msgVer;
     _frame.msgType    = (byte)MSGEncoding.MsgType.WriteFile;
     _frame.msgSubType = (byte)MSGEncoding.WriteFile.UpcfgToDev;
     _frame.dataLen    = (ushort)tempdata.Length;
     donedata          = PrepareData.MergeMsg(ref _frame, tempdata);
     return(donedata);
 }
Beispiel #11
0
        /// <summary>
        /// 接收到消息的处理,返回解析响应中下位机写入的字节数,用于外边判断是否继续传输(判断报错)
        /// </summary>
        /// <returns></returns>
        public static ushort MsgHandle(byte[] b_recvframe, ref ushort errorcode)
        {
            ushort thisdown = 0;

            //返回帧情况:如果为数据或配置文件只能是短暂;如果是升级文件,只能是长帧(文件名就16字节)
            //注意:这里统一数据配置和升级文件的交互方法,响应包应该全是短包
            //FileItem fi = (FileItem)filepool[hdtr.packetnum];
            PrepareData.Msg_Bus temp = (PrepareData.Msg_Bus)ByteStruct.BytesToStruct(b_recvframe,
                                                                                     typeof(PrepareData.Msg_Bus));
            //包含执行状态字
            byte[] rawdata = temp.data;
            ushort datalen = (ushort)(temp.dataLen - 2);

            //终端没有接收到字节: 出错或者是文件传送完成握手响应
            if (0 == datalen)
            {
                byte[] _errorcode = new byte[2];
                Array.Copy(rawdata, _errorcode, 2);
                errorcode = BitConverter.ToUInt16(_errorcode, 0);
                thisdown  = 0;
            }
            //终端接收到一定的数据
            else
            {
                byte[] _errorcode = new byte[2];
                byte[] _thisdonw  = new byte[2];
                Array.Copy(rawdata, _errorcode, 2);
                Array.Copy(rawdata, 2, _thisdonw, 0, 2);
                errorcode = BitConverter.ToUInt16(_errorcode, 0);
                thisdown  = BitConverter.ToUInt16(_thisdonw, 0);
            }
            return(thisdown);

            #region  区别数据、配置文件和升级文件
            //如果为数据文件或者配置文件

            /*if (!fi.IsUpgradeFile)
             * {
             *  PrepareData.Msg_Bus temp = (PrepareData.Msg_Bus)ByteStruct.BytesToStruct(b_recvframe,
             *                                                                           typeof(PrepareData.Msg_Bus));
             *  //包含执行状态字
             *  byte[] rawdata = temp.data;
             *  ushort datalen = (ushort)(temp.dataLen - 2);
             *  //终端没有接收到字节: 出错或者是文件传送完成握手响应
             *  if (0 == datalen)
             *  {
             *      byte[] _errorcode = new byte[2];
             *      Array.Copy(rawdata, _errorcode, 2);
             *      errorcode = BitConverter.ToUInt16(_errorcode, 0);
             *      thisdown = 0;
             *  }
             *  //终端接收到一定的数据
             *  else
             *  {
             *      byte[] _errorcode = new byte[2];
             *      byte[] _thisdonw = new byte[2];
             *      Array.Copy(rawdata, _errorcode, 2);
             *      Array.Copy(rawdata, 2, _thisdonw, 0, 2);
             *      errorcode = BitConverter.ToUInt16(_errorcode, 0);
             *      thisdown = BitConverter.ToUInt16(_thisdonw, 0);
             *  }
             * }
             * //如果为升级文件
             * else
             * {
             *  byte 数据分割
             * }
             * */
            #endregion
            //错误代码      数据域        含义
            //   0            0         服务器发送文件写结束帧后下位机的正常响应
            //   0          != 0       正常响应下位机接收到服务器的文件数据并写入的正常响应
            // != 0         null       有错误发生时的响应帧
        }