Exemplo n.º 1
0
        /// <summary>
        /// 筛选显示
        /// </summary>
        /// <param name="internalFrame">将要筛选的帧目前只能筛选68</param>
        /// <returns></returns>
        private bool filtrate(InternalFrame internalFrame)
        {
            bool isShow = false;

            SerialPortFrame serialPortFrame = (SerialPortFrame)internalFrame;
            string          nodeMac         = serialPortFrame.NodeMac;
            string          concentratorMac = serialPortFrame.ConcentratorMac;


            if (nodeTextBox.Text.Equals("") && concentratorTextBox.Text.Equals(""))
            {
                return(true);
            }
            else //有一方是空
            {
                //筛选集中器
                if (nodeTextBox.Text.Equals("") && !(concentratorTextBox.Text.Equals("")))
                {
                    if (concentratorMac.Equals(concentratorTextBox.Text))
                    {
                        return(true);
                    }
                }    //筛选节点
                else if (!nodeTextBox.Text.Equals("") && (concentratorTextBox.Text.Equals("")))
                {
                    if (nodeMac.Equals(nodeTextBox.Text))
                    {
                        return(true);
                    }
                }
                else //筛选节点+集中器
                {
                    if (nodeMac.Equals(nodeTextBox.Text) && concentratorMac.Equals(concentratorTextBox.Text))
                    {
                        return(true);
                    }
                }
            }

            return(isShow);
        }
Exemplo n.º 2
0
            public readonly DateTime ReceiveTime;                                                      //接受时间

            public SerialFrameAnalysisEventArgs(SerialPortFrame serialPortFrame, DateTime receiveTime) //构造函数
            {
                this.SerialPortFrame = serialPortFrame;
                this.ReceiveTime     = receiveTime;
            }
Exemplo n.º 3
0
        //接收后的帧处理后显示
        void AnalysisProcess_ReceiveDataFrameEvent(AnalysisProcess.SerialFrameAnalysisEventArgs e)
        {
            SerialPortFrame serialPortFrame = e.SerialPortFrame;

            //判断真类型
            int FrameTypeSel = (int)serialPortFrame.FrameType;

            switch (FrameTypeSel)
            {
            case 0:
                Log(LogMsgType.DataFrame, "数据帧");
                DataFrameCount++;
                break;

            case 1:
                Log(LogMsgType.Commond, "命令帧");
                OrderFrameCount++;
                break;

            case 2:
                Log(LogMsgType.Response, "应答帧");
                ResponseFrameCount++;
                break;

            case 3:
                Log(LogMsgType.Warning, "告警帧");
                WarningFrameCount++;
                break;
            }

            //如果筛选合格,显示
            if (filtrate(serialPortFrame))
            {
                string receiveTime = e.ReceiveTime.ToString("HH:mm:ss:fff");
                string oneFrame    = Character.BytesToString(serialPortFrame.OneFrame, 0, serialPortFrame.OneFrame.Length - 1, true);

                int    FrameCommun = (int)serialPortFrame.CommunicationWay;
                string data        = Character.BytesToString(serialPortFrame.DataByte, 0, serialPortFrame.DataByte.Length - 1, true);

                switch (FrameTypeSel)
                {
                case 0:
                    Log(LogMsgType.DataFrame, "数据帧");
                    break;

                case 1:
                    Log(LogMsgType.Commond, "命令帧");
                    break;

                case 2:
                    Log(LogMsgType.Response, "应答帧");
                    break;

                case 3:
                    Log(LogMsgType.Warning, "告警帧");
                    break;
                }

                switch (FrameCommun)
                {
                case 0:
                    Log(LogMsgType.ReceiveTime, "[透  传]");
                    break;

                case 1:
                    Log(LogMsgType.ReceiveTime, "[非透传]");
                    break;

                case 2:
                    Log(LogMsgType.ReceiveTime, "  ");
                    break;

                case 3:
                    Log(LogMsgType.ReceiveTime, "  ");
                    break;
                }
                Log(LogMsgType.ReceiveTime, "\t" + receiveTime);

                Log(LogMsgType.ControlCodeNote, "\t" + oneFrame + "\n");

                Log(LogMsgType.ControlCodeNote, "节点地址:  " + serialPortFrame.NodeMac + "\t" + "集中器地址:  " + serialPortFrame.ConcentratorMac + "\t" + data + "\n");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 解析收到的帧
        /// </summary>
        /// <param name="receiveByte">接受到的帧字节</param>
        public static void FrameAnalysis(byte[] receiveByte)
        {
            #region 第一次提取负载  提取出69帧的负载
            byte[] receive;

            NetCommunicationFrame frame_first = new NetCommunicationFrame();
            frame_first.Receive(receiveByte);

            if (frame_first.CheckSumCorrect)
            {
                receive = frame_first.DataByte; //校验正确,提取出69帧的负载

                // 打印数据(测试用)
                string first_frame_lod = Character.BytesToString(receive, 0, receive.Length - 1, true);
                Console.WriteLine("第一次提取的负载: " + first_frame_lod);
            }
            else
            {
                Program.mainform.CheckFailedFrameCount++;//校验失败,增加窗口记录失败值
                return;
            }
            if (receive == null)                      //收到无负载的帧,暂不处理
            {
                Program.mainform.UnknownFrameCount++; //未知帧计数加一
                return;
            }

            #endregion

            #region 解析负载

            #region 解析串口68通信帧
            if (receive[0] == (byte)SerialPortFrame.FrameHeadAndTail.Head) //找帧头
            {
                SerialPortFrame fram68 = new SerialPortFrame();
                fram68.Receive(receive);

                if (fram68.CheckSumCorrect) //校验和正确
                {
                    // 打印数据(测试用)
                    string data = Character.BytesToString(fram68.DataByte, 0, fram68.DataByte.Length - 1, true);
                    Console.WriteLine("数据域" + data);

                    DateTime receiveTime = DateTime.Now;
                    /* 分析一帧完成的事件 */
                    SerialFrameAnalysisEventArgs e = new SerialFrameAnalysisEventArgs(fram68, receiveTime);

                    //发布事件
                    if (ReceiveDataFrameEvent != null) // 如果有对象注册
                    {
                        ReceiveDataFrameEvent(e);      // 调用所有注册对象的方法
                    }
                }
                else //校验错误
                {
                    Program.mainform.CheckFailedFrameCount++;// 校验失败,增加窗口记录失败值
                    Program.mainform.UnknownFrameCount++;//未知帧计数加一
                    return;
                }
            }

            #endregion

            #endregion
        }