Example #1
0
        /// <summary>
        /// 端口监听,解析数据并触发相应事件
        /// </summary>
        public void ReadPort()
        {
            double Cfc110TLNum = 0;
            double Cfc110MVNum = 0;


            while (_isReading)
            {
                try
                {
                    this._devComm.ClearComBuffer(_CommHandle);
                    // 读累计量
                    SendMsg("TL");
                    //   byte[] d = new byte[10];

                    byte[] d        = this._devComm.Read(_CommHandle, 19);
                    string result   = "";
                    int    resultTL = 0;
                    // Byte[] TLNum = new Byte[9];
                    if (d.Length == 19)
                    {
                        ////检查LRC校验码
                        //byte[] LrcResult = new byte[] { 0 };
                        //LrcResult = this._devComm.LrcCheck(d);
                        //if (d[d.Length - 4] == LrcResult[0] && d[d.Length - 3] == LrcResult[1])
                        //{
                        for (int i = 0; i < 8; i++)
                        {
                            if (d[i + 8].ToString().Length == 1)
                            {
                                result += "0" + Convert.ToString(d[i + 8], 10);
                            }
                            else
                            {
                                result += Convert.ToString(d[i + 8], 16);
                            }
                        }

                        //解析成BST-100仪表数据
                        // string Cfc110ResultStr = "";
                        try
                        {
                            string strTemp  = "";
                            string strTemp1 = "";
                            for (int i = 0; i < 8; i++)
                            {
                                strTemp1 = (Convert.ToInt32(result.Substring(i * 2, 2)) - 30).ToString();
                                switch (strTemp1)    //2014.02.21 吴锐家增
                                {
                                case "11":
                                    strTemp1 = "A";
                                    break;

                                case "12":
                                    strTemp1 = "B";
                                    break;

                                case "13":
                                    strTemp1 = "C";
                                    break;

                                case "14":
                                    strTemp1 = "D";
                                    break;

                                case "15":
                                    strTemp1 = "E";
                                    break;

                                case "16":
                                    strTemp1 = "F";
                                    break;
                                }


                                strTemp = strTemp + strTemp1;
                            }
                            resultTL    = Convert.ToInt32(strTemp, 16);
                            Cfc110TLNum = Convert.ToDouble(resultTL) / 1000;
                        }
                        catch (Exception ex)
                        {
                            WriteLog("读累计量" + ex.Message);
                        }
                    }


                    //}
                    this._devComm.ClearComBuffer(_CommHandle);
                    // 读瞬时量
                    SendMsg("PV");
                    string reulstPV = "";
                    int    ResultPV = 0;

                    byte[] PV = this._devComm.Read(_CommHandle, 19);
                    if (PV.Length == 19)
                    {
                        for (int i = 0; i < 8; i++)
                        {
                            if (PV[i + 8].ToString().Length == 1)
                            {
                                reulstPV += "0" + Convert.ToString(PV[i + 8], 16);
                            }
                            else
                            {
                                reulstPV += Convert.ToString(PV[i + 8], 16);
                            }
                        }

                        //解析成CFC110仪表数据
                        // string Cfc110ResultStr = "";
                        try
                        {
                            string strTemp  = "";
                            string strTemp1 = "";
                            for (int i = 0; i < 8; i++)
                            {
                                strTemp1 = (Convert.ToInt32(reulstPV.Substring(i * 2, 2)) - 30).ToString();
                                switch (strTemp1)    //2014.02.21 吴锐家增
                                {
                                case "11":
                                    strTemp1 = "A";
                                    break;

                                case "12":
                                    strTemp1 = "B";
                                    break;

                                case "13":
                                    strTemp1 = "C";
                                    break;

                                case "14":
                                    strTemp1 = "D";
                                    break;

                                case "15":
                                    strTemp1 = "E";
                                    break;

                                case "16":
                                    strTemp1 = "F";
                                    break;
                                }


                                strTemp = strTemp + strTemp1;
                            }
                            ResultPV    = Convert.ToInt32(strTemp, 16);
                            Cfc110MVNum = Convert.ToDouble(ResultPV) / 1000;
                        }
                        catch (Exception ex)
                        {
                            WriteLog("读累计量" + ex.Message);
                        }


                        //string Cfc110ResultStr = "";
                        //try
                        //{
                        //    Cfc110ResultStr = System.Text.Encoding.ASCII.GetString(PV);
                        //    string MvNum = (Convert.ToInt32(Cfc110ResultStr.Substring(7, 8), 16)).ToString().Remove(0, 2);
                        //    Cfc110MVNum = (Convert.ToDouble(MvNum)) / 100000.0;
                        //}
                        //catch (Exception ex)
                        //{
                        //    WriteLog("读瞬时量出错" + ex.Message);
                        //}
                    }
                    // 触发事件
                    if (CfcNumReceived != null)
                    {
                        Cfc110NumReceivedEventArgs e = new Cfc110NumReceivedEventArgs(Cfc110TLNum.ToString("0.00"), Cfc110MVNum.ToString("0.00"));
                        CfcNumReceived(null, e);
                    }
                }
                catch (Exception ex)
                {
                    WriteLog("端口监听的线程出错" + ex.Message);
                }
            }
        }
Example #2
0
        private void NumResult(object sender, Cfc110NumReceivedEventArgs e)
        {
            //double RealTimeData = e.CfcMVNum;
            //if (RealTimeData > 10)//有重量
            //{
            //    if (m_dPreData <= 10 && m_State == "2" && btnKS.Enabled == true)//启动
            //    {
            //        // axDbgNet1.DbgOUT("111111111\n");
            //        //皮带重量由小于5到大于5时启动自动保存一次计量
            //        this.StrapStart();
            //        //if (System.IO.File.Exists(PublicComponent.Constant.RunPath + "\\ding.wav"))
            //        //    PlaySound(PublicComponent.Constant.RunPath + "\\ding.wav");//播放启动声音
            //    }
            //}
            //else
            //{
            //    // axDbgNet1.DbgOUT("22222222222\n");
            //    if (m_dPreData > 10 && m_State == "2" && btnWC.Enabled == true)//启动
            //    {
            //        //皮带重量由大于5到小于5时启动自动保存二次计量
            //        this.StrapComplete();
            //        //if (System.IO.File.Exists(PublicComponent.Constant.RunPath + "\\stop.wav"))
            //        //    PlaySound(PublicComponent.Constant.RunPath + "\\stop.wav");//播放停止声音
            //    }
            //}

            //m_dPreData = RealTimeData;
            //this.tbLJLL.Text = e.CfcTLNum;
            //this.tbSSLL.Text = e.CfcMVNum;
            //if (m_State == "0")
            //    m_State = "2";
        }
Example #3
0
        /// <summary>
        /// 端口监听,解析数据并触发相应事件
        /// </summary>
        public void ReadPort()
        {
            double Cfc110TLNum = 0;
            double Cfc110MVNum = 0;

            while (_isReading)
            {
                try
                {
                    this._devComm.ClearComBuffer(_CommHandle);
                    // 读累计量
                    SendMsg("TL");
                 //   byte[] d = new byte[10];

                    byte[] d = this._devComm.Read(_CommHandle, 19);
                    string result = "";
                    int resultTL=0;
                   // Byte[] TLNum = new Byte[9];
                    if (d.Length == 19)
                    {
                        ////检查LRC校验码
                        //byte[] LrcResult = new byte[] { 0 };
                        //LrcResult = this._devComm.LrcCheck(d);
                        //if (d[d.Length - 4] == LrcResult[0] && d[d.Length - 3] == LrcResult[1])
                        //{
                            for (int i = 0; i < 8; i++)
                            {
                                if (d[i + 8].ToString().Length == 1)
                                    result += "0" + Convert.ToString(d[i + 8], 10);
                                else
                                    result += Convert.ToString(d[i + 8], 16);
                            }

                            //解析成BST-100仪表数据
                            // string Cfc110ResultStr = "";
                            try
                            {
                                string strTemp = "";
                                string strTemp1 = "";
                                for (int i = 0; i < 8; i++)
                                {
                                    strTemp1 = (Convert.ToInt32(result.Substring(i * 2, 2)) - 30).ToString();
                                    switch (strTemp1)//2014.02.21 吴锐家增
                                    {
                                        case "11":
                                            strTemp1 = "A";
                                            break;
                                        case "12":
                                            strTemp1 = "B";
                                            break;
                                        case "13":
                                            strTemp1 = "C";
                                            break;
                                        case "14":
                                            strTemp1 = "D";
                                            break;
                                        case "15":
                                            strTemp1 = "E";
                                            break;
                                        case "16":
                                            strTemp1 = "F";
                                            break;
                                    }

                                    strTemp = strTemp + strTemp1;
                                }
                                resultTL = Convert.ToInt32(strTemp, 16);
                                Cfc110TLNum =Convert.ToDouble( resultTL)/1000;
                            }
                            catch (Exception ex)
                            {
                                WriteLog("读累计量" + ex.Message);
                            }
                        }

                    //}
                    this._devComm.ClearComBuffer(_CommHandle);
                    // 读瞬时量
                    SendMsg("PV");
                    string reulstPV="";
                    int ResultPV = 0;

                    byte[] PV = this._devComm.Read(_CommHandle, 19);
                    if (PV.Length == 19)
                    {

                            for (int i = 0; i < 8; i++)
                            {
                                if (PV[i + 8].ToString().Length == 1)
                                    reulstPV += "0" + Convert.ToString(PV[i + 8], 16);
                                else
                                    reulstPV += Convert.ToString(PV[i + 8], 16);
                            }

                            //解析成CFC110仪表数据
                            // string Cfc110ResultStr = "";
                            try
                            {
                                string strTemp = "";
                                string strTemp1 = "";
                                for (int i = 0; i < 8; i++)
                                {
                                    strTemp1 = (Convert.ToInt32(reulstPV.Substring(i * 2, 2)) - 30).ToString();
                                    switch (strTemp1)//2014.02.21 吴锐家增
                                    {
                                        case "11":
                                            strTemp1 = "A";
                                            break;
                                        case "12":
                                            strTemp1 = "B";
                                            break;
                                        case "13":
                                            strTemp1 = "C";
                                            break;
                                        case "14":
                                            strTemp1 = "D";
                                            break;
                                        case "15":
                                            strTemp1 = "E";
                                            break;
                                        case "16":
                                            strTemp1 = "F";
                                            break;
                                    }

                                    strTemp = strTemp + strTemp1;
                                }
                                ResultPV = Convert.ToInt32(strTemp, 16);
                                Cfc110MVNum =Convert.ToDouble( ResultPV)/1000 ;
                            }
                            catch (Exception ex)
                            {
                                WriteLog("读累计量" + ex.Message);
                            }

                        //string Cfc110ResultStr = "";
                        //try
                        //{
                        //    Cfc110ResultStr = System.Text.Encoding.ASCII.GetString(PV);
                        //    string MvNum = (Convert.ToInt32(Cfc110ResultStr.Substring(7, 8), 16)).ToString().Remove(0, 2);
                        //    Cfc110MVNum = (Convert.ToDouble(MvNum)) / 100000.0;
                        //}
                        //catch (Exception ex)
                        //{
                        //    WriteLog("读瞬时量出错" + ex.Message);
                        //}

                    }
                    // 触发事件
                    if (CfcNumReceived != null)
                    {
                        Cfc110NumReceivedEventArgs e = new Cfc110NumReceivedEventArgs(Cfc110TLNum.ToString("0.00"), Cfc110MVNum.ToString("0.00"));
                        CfcNumReceived(null, e);
                    }
                }
                catch (Exception ex)
                {
                    WriteLog("端口监听的线程出错" + ex.Message);
                }

            }
        }
Example #4
0
        private void serialsCFCLib_NumReceived(object sender, Cfc110NumReceivedEventArgs e)
        {
            this.Invoke(new EventHandler(delegate
            {
                double RealTimeData = Double.Parse(e.CfcMVNum);
                if (RealTimeData > 10)//有重量
                {
                    if (m_dPreData <= 10 && m_State == "2" && btnKS.Enabled == true)//启动
                    {
                        // axDbgNet1.DbgOUT("111111111\n");
                        //皮带重量由小于5到大于5时启动自动保存一次计量
                        this.StrapStart();
                        //if (System.IO.File.Exists(PublicComponent.Constant.RunPath + "\\ding.wav"))
                        //    PlaySound(PublicComponent.Constant.RunPath + "\\ding.wav");//播放启动声音
                    }
                }
                else
                {
                    // axDbgNet1.DbgOUT("22222222222\n");
                    if (m_dPreData > 10 && m_State == "2" && btnWC.Enabled == true)//启动
                    {
                        //皮带重量由大于5到小于5时启动自动保存二次计量
                        this.StrapComplete();
                        //if (System.IO.File.Exists(PublicComponent.Constant.RunPath + "\\stop.wav"))
                        //    PlaySound(PublicComponent.Constant.RunPath + "\\stop.wav");//播放停止声音
                    }
                }

                m_dPreData = RealTimeData;
                this.tbLJLL.Text = e.CfcTLNum;
                this.tbSSLL.Text = e.CfcMVNum;
                if (m_State == "0")
                    m_State = "2";

            }));
        }