コード例 #1
0
 private void rtnData(string data)
 {
     if (data.Length > 0)
     {
         if ((bt[0] == 129) && (bt[dataLen + 5] == 129))
         {
             List <byte[]> dataList = new List <byte[]>();
             byte[]        databt   = new byte[10];
             int           ind      = 0;
             for (int i = 0; i < dataLen + 4; i++)
             {
                 if (i > 3)
                 {
                     databt[ind] = bt[i];
                     if (ind == 9)
                     {
                         dataList.Add(databt);
                         ind    = -1;
                         databt = new byte[10];
                     }
                     ind++;
                 }
             }
             if (dataList.Count > 0)
             {
                 for (int i = 0; i < dataList.Count; i++)
                 {
                     string num = "", item = "", checkValue = "", unit = "", datetime = "", error = "";
                     num  = dataList[i][0].ToString();
                     item = "农药残留(国)";
                     double value = (double)(dataList[i][8] + dataList[i][9] * 256);
                     checkValue = (value / 100).ToString("F2");
                     unit       = "%";
                     datetime   = "20" + dataList[i][3] + "-" + dataList[i][4] + "-" + dataList[i][5] + " "
                                  + dataList[i][6] + ":" + dataList[i][7] + ":00";
                     error = "否";
                     AddNewHistoricData(num, item, checkValue, unit, datetime, error);
                 }
                 m_RecordCount         = 0;
                 m_RecordStartPosition = 0;
                 m_RecordEndPosition   = 0;
                 m_DataReadByteCount   = 0;
                 m_DataRead            = string.Empty;
                 m_LatterDataByteCount = 0;
                 if (MessageNotification.GetInstance() != null)
                 {
                     MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadDY3000DYData, "");
                 }
             }
         }
     }
 }
コード例 #2
0
        protected override void OnRxChar(byte c)
        {
            string rec = c.ToString("X2");

            strShow += rec;

            if (strShow.Length > 16 && strShow.Substring(0, 2) == "7E")
            {
                //读取数据
                if (strShow.Substring(0, 4) == "7E11")
                {
                    //找到帧头、帧尾
                    if (strShow.Length == 52 && strShow.Substring(50, 2) == "AA")
                    {
                        //crc校验
                        byte crcsum = crc8(clsStringUtil.HexString2ByteArray(strShow.Substring(2, 46)));
                        //确定本次读取的数据总条数
                        int value = Convert.ToInt32(strShow.Substring(6, 4), 16);
                        Records = Records + 1;
                        if (crcsum.ToString("X2") == strShow.Substring(48, 2))
                        {
                            ParseDataFromDevice(strShow);
                            strShow = string.Empty;
                            if (Records == value)//读完当天所有记录才发送消息读下一天
                            {
                                Records = 0;
                                if (MessageNotification.GetInstance() != null)
                                {
                                    MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadLZ4000TData, "");
                                }
                            }
                        }
                        else if (Records == value)
                        {
                            //校验数据不对就清空,返回
                            strShow = "";
                            if (MessageNotification.GetInstance() != null)
                            {
                                MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadLZ4000TData, "");
                            }
                        }
                        else
                        {
                            //校验数据不对就清空
                            strShow = "";
                        }
                    }
                }
                else if (strShow.Substring(0, 4) == "7E01") //通信测试
                {
                    if (strShow.Length == 18 && strShow.Substring(16, 2) == "AA")
                    {
                        intRec  = 0;
                        strShow = string.Empty;
                        if (MessageNotification.GetInstance() != null)
                        {
                            MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadLZ4000TData, "tongxin");
                        }
                    }
                }
                else if (strShow.Substring(0, 4) == "7E13")                                                             //读取记录条数
                {
                    if (strShow.Length == 22 && strShow.Substring(14, 4) == "0000" && strShow.Substring(20, 2) == "AA") //没有记录
                    {
                        if (MessageNotification.GetInstance() != null)
                        {
                            strShow = "";
                            MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadLZ4000TData, "NoRecord");
                        }
                    }
                    else if (strShow.Length == 22 && strShow.Substring(20, 2) == "AA")
                    {
                        if (MessageNotification.GetInstance() != null)//有记录
                        {
                            strShow = "";
                            MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadLZ4000TData, "Record");
                        }
                    }
                }
            }
            else if (strShow.Substring(0, 2) != "7E")//第一个字节不是7E,截取7E开始的字符串
            {
                if (Global.communicatType == "读数据")
                {
                    if (rec == "7E")
                    {
                        iscom = true;
                    }
                    if (iscom == true)
                    {
                        GetRD += rec;
                        if (GetRD.Length > 6)
                        {
                            if (GetRD.Substring(0, 4) == "7E7E")
                            {
                                GetRD = strShow.Substring(2, GetRD.Length - 2);//取最后两个7E
                            }
                        }
                    }
                    if (GetRD.Length > 50)
                    {
                        if (GetRD.Substring(0, 4) == "7E11" && GetRD.Length == 52 && rec == "AA")
                        {
                            //crc校验
                            byte crcsum = crc8(clsStringUtil.HexString2ByteArray(GetRD.Substring(2, 46)));
                            //确定本次读取的数据总条数
                            int value = Convert.ToInt32(GetRD.Substring(6, 4), 16);
                            Records = Records + 1;
                            if (crcsum.ToString("X2") == GetRD.Substring(48, 2))
                            {
                                ParseDataFromDevice(GetRD);
                                GetRD = string.Empty;
                                if (Records == value)//读完当天所有记录才发送消息读下一天
                                {
                                    Records = 0;
                                    iscom   = false;
                                    if (MessageNotification.GetInstance() != null)
                                    {
                                        MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadLZ4000TData, "");
                                    }
                                }
                            }
                            else if (Records == value)
                            {
                                //校验数据不对就清空,丢掉本条记录
                                GetRD = "";
                                if (MessageNotification.GetInstance() != null)
                                {
                                    MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadLZ4000TData, "");
                                }
                            }
                            else
                            {
                                //校验数据不对就清空,丢掉本条记录
                                GetRD = "";
                            }
                        }
                    }
                }
                else if (Global.communicatType == "通信测试")
                {
                    if (rec == "7E")
                    {
                        iscom = true;
                    }
                    if (iscom == true)
                    {
                        GetRD += rec;
                        if (GetRD.Length > 6)
                        {
                            if (GetRD.Substring(0, 4) == "7E7E")
                            {
                                GetRD = GetRD.Substring(2, GetRD.Length - 2);//取最后两个7E
                            }
                        }
                    }
                    if (GetRD.Length > 16)
                    {
                        if (GetRD.Substring(0, 4) == "7E01" && GetRD.Length == 18 && GetRD.Substring(16, 2) == "AA")
                        {
                            intRec = 0;
                            GetRD  = string.Empty;
                            iscom  = false;
                            if (MessageNotification.GetInstance() != null)
                            {
                                MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadLZ4000TData, "tongxin");
                            }
                        }
                    }
                }
                else if (Global.communicatType == "读记录")
                {
                    if (rec == "7E")
                    {
                        iscom = true;
                    }
                    if (iscom == true)
                    {
                        GetRD += rec;
                        if (GetRD.Length > 6)
                        {
                            if (GetRD.Substring(0, 4) == "7E7E")
                            {
                                GetRD = GetRD.Substring(2, GetRD.Length - 2);//取最后两个7E
                            }
                        }
                    }
                    if (GetRD.Length > 16)
                    {
                        if (GetRD.Length == 22 && GetRD.Substring(0, 4) == "7E13" && GetRD.Substring(14, 4) == "0000" && GetRD.Substring(20, 2) == "AA")
                        {
                            intRec = 0;
                            GetRD  = string.Empty;
                            iscom  = false;
                            if (MessageNotification.GetInstance() != null)
                            {
                                MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadLZ4000TData, "NoRecord");
                            }
                        }
                        else if (GetRD.Length == 22 && GetRD.Substring(0, 4) == "7E13" && GetRD.Substring(20, 2) == "AA")
                        {
                            if (MessageNotification.GetInstance() != null)//有记录
                            {
                                strShow = "";
                                GetRD   = string.Empty;
                                iscom   = false;
                                MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadLZ4000TData, "Record");
                            }
                        }
                    }
                }
            }

            //strShow += rec;
            ////确定本次读取的数据总条数
            //if (strShow.Length > 8 && strShow.Length <= 12)
            //{
            //    if (strShow.Length == 10)
            //        intRec = c;
            //    else
            //        intRec += c * 256;
            //}
            ////通信测试
            //if (strShow.Length > 5)
            //{
            //    if (strShow.Substring(0, 4) == "7E01")
            //    {
            //        if (strShow.Length == 18 && strShow.Substring(16, 2) == "AA")
            //        {
            //            intRec = 0;
            //            strShow = string.Empty;
            //            if (MessageNotification.GetInstance() != null)
            //            {
            //                MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadLZ4000TData, "tongxin");
            //            }
            //        }
            //    }
            //}
            ////查询读取日期是否有检测记录
            //if (strShow.Length > 6)
            //{
            //    if (strShow.Substring(0, 4) == "7E13")
            //    {
            //        if (strShow.Length == 22)
            //        {
            //            if (strShow.Substring(14, 4) == "0000" && strShow.Substring(20, 2) == "AA")//没有记录
            //            {
            //                if (MessageNotification.GetInstance() != null)
            //                {
            //                    strShow = "";
            //                    MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadLZ4000TData, "NoRecord");
            //                }
            //            }
            //            else
            //            {
            //                if (MessageNotification.GetInstance() != null)//有记录
            //                {
            //                    strShow = "";
            //                    MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadLZ4000TData, "Record");
            //                }
            //            }
            //        }
            //    }
            //}

            //if (strShow.Length == intRec * 52 && intRec > 0)
            //{
            //    ParseDataFromDevice(strShow);
            //    intRec = 0;
            //    strShow = string.Empty;
            //}
            // m_DataRead = string.Empty;
        }
コード例 #3
0
        /// <summary>
        /// 接收返回数据
        /// </summary>
        /// 根据发送数据解析接收数据
        /// <param name="c"></param>
        protected override void OnRxChar(byte c)
        {
            arrl.Add(c);
            rd = rd + 1;
            string data = "";

            if (Global.SendToTYData == "1BBF")
            {
                //握手数据
                if (rd == 2)
                {
                    for (int i = 0; i < arrl.Count; i++)
                    {
                        data = data + arrl[i].ToString();
                    }
                    rd = 0;
                    arrl.Clear();
                    DataReadTable.Clear();
                    //发送消息给主界面
                    if (MessageNotification.GetInstance() != null)
                    {
                        MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadTY16, data);
                    }
                }
            }
            if (Global.SendToTYData == "1BB1")
            {
                //读取第一组数据
                if (rd == 75)
                {
                    byte[] tbytes = new byte[6];
                    tbytes[0] = Convert.ToByte(arrl[8]);
                    tbytes[1] = Convert.ToByte(arrl[6]);
                    tbytes[2] = Convert.ToByte(arrl[5]);
                    tbytes[3] = Convert.ToByte(arrl[4]);
                    tbytes[4] = Convert.ToByte(arrl[3]);
                    tbytes[5] = Convert.ToByte(arrl[2]);

                    int i1 = Int32.Parse(Convert.ToString(tbytes[0], 16), System.Globalization.NumberStyles.HexNumber);
                    int i2 = Int32.Parse(Convert.ToString(tbytes[1], 16), System.Globalization.NumberStyles.HexNumber);
                    int i3 = Int32.Parse(Convert.ToString(tbytes[2], 16), System.Globalization.NumberStyles.HexNumber);
                    int i4 = Int32.Parse(Convert.ToString(tbytes[3], 16), System.Globalization.NumberStyles.HexNumber);
                    int i5 = Int32.Parse(Convert.ToString(tbytes[4], 16), System.Globalization.NumberStyles.HexNumber);
                    int i6 = Int32.Parse(Convert.ToString(tbytes[5], 16), System.Globalization.NumberStyles.HexNumber);
                    //检测时间
                    SChkTime = "20" + i1.ToString() + "/" + i2.ToString() + "/" + i3.ToString() + " " + i4.ToString()
                               + ":" + i5.ToString() + ":" + i6.ToString();
                    //判断哪个通道
                    byte[] bt = new byte[1];
                    bt[0] = Convert.ToByte(arrl[9]);
                    string IstestNum = Convert.ToString(bt[0], 2);
                    //给二进制数补0
                    if (IstestNum.Length < 8)
                    {
                        for (int k = IstestNum.Length; k < 8; k++)
                        {
                            IstestNum = "0" + IstestNum;
                        }
                    }

                    int h = 0;

                    //for循环读取
                    for (int j = 15; j < 75; j++)
                    {
                        groundone = IsShiLiu(Convert.ToString(Convert.ToInt32(arrl[j].ToString()), 16)) + IsShiLiu(Convert.ToString(Convert.ToInt32(arrl[j + 1].ToString()), 16))
                                    + IsShiLiu(Convert.ToString(Convert.ToInt32(arrl[j + 2].ToString()), 16)) + IsShiLiu(Convert.ToString(Convert.ToInt32(arrl[j + 3].ToString()), 16));
                        string hole = IstestNum.Substring(h, 1);
                        h = h + 1;
                        if (hole == "1")
                        {
                            uint num = uint.Parse(groundone, System.Globalization.NumberStyles.AllowHexSpecifier);

                            byte[] floatVals = BitConverter.GetBytes(num);

                            float f = BitConverter.ToSingle(floatVals, 0);

                            double fd = Math.Round(f, 2);
                            DataToTable(Convert.ToString(fd), SChkTime, h.ToString());
                        }
                        j = j + 7;
                    }

                    ////1通道
                    //groundone = Convert.ToString(Convert.ToInt32(arrl[15].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[16].ToString()), 16)
                    //    + Convert.ToString(Convert.ToInt32(arrl[17].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[18].ToString()), 16);
                    //if (groundone != "0000")
                    //{

                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[15]);
                    //    bytes[1] = Convert.ToByte(arrl[16]);
                    //    bytes[2] = Convert.ToByte(arrl[17]);
                    //    bytes[3] = Convert.ToByte(arrl[18]);

                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double  fd= Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime, "1");

                    //}
                    ////2通道
                    //groundtwo = Convert.ToString(Convert.ToInt32(arrl[23].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[24].ToString()), 16)
                    //     + Convert.ToString(Convert.ToInt32(arrl[25].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[26].ToString()), 16);
                    //if (groundtwo != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[23]);
                    //    bytes[1] = Convert.ToByte(arrl[24]);
                    //    bytes[2] = Convert.ToByte(arrl[25]);
                    //    bytes[3] = Convert.ToByte(arrl[26]);

                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime,"2");
                    //}

                    ////3通道
                    //groundthree  = Convert.ToString(Convert.ToInt32(arrl[31].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[32].ToString()), 16)
                    //     + Convert.ToString(Convert.ToInt32(arrl[33].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[34].ToString()), 16);
                    //if (groundthree != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[31]);
                    //    bytes[1] = Convert.ToByte(arrl[32]);
                    //    bytes[2] = Convert.ToByte(arrl[33]);
                    //    bytes[3] = Convert.ToByte(arrl[34]);

                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime,"3");
                    //}
                    ////4通道
                    //groundfour  = Convert.ToString(Convert.ToInt32(arrl[39].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[40].ToString()), 16)
                    //    + Convert.ToString(Convert.ToInt32(arrl[41].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[42].ToString()), 16);
                    //if (groundfour != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[39]);
                    //    bytes[1] = Convert.ToByte(arrl[40]);
                    //    bytes[2] = Convert.ToByte(arrl[41]);
                    //    bytes[3] = Convert.ToByte(arrl[42]);

                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime,"4");
                    //}
                    ////5通道
                    //groundfire  = Convert.ToString(Convert.ToInt32(arrl[47].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[48].ToString()), 16)
                    //     + Convert.ToString(Convert.ToInt32(arrl[49].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[50].ToString()), 16);
                    //if (groundfire != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[47]);
                    //    bytes[1] = Convert.ToByte(arrl[48]);
                    //    bytes[2] = Convert.ToByte(arrl[49]);
                    //    bytes[3] = Convert.ToByte(arrl[50]);

                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime,"5");
                    //}
                    ////6通道
                    //groundsix = Convert.ToString(Convert.ToInt32(arrl[55].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[56].ToString()), 16)
                    //     + Convert.ToString(Convert.ToInt32(arrl[57].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[58].ToString()), 16);
                    //if (groundsix != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[55]);
                    //    bytes[1] = Convert.ToByte(arrl[56]);
                    //    bytes[2] = Convert.ToByte(arrl[57]);
                    //    bytes[3] = Convert.ToByte(arrl[58]);

                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);

                    //    DataToTable(Convert.ToString(fd), SChkTime,"6");
                    //}
                    ////7通道
                    //groundseven  = Convert.ToString(Convert.ToInt32(arrl[63].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[64].ToString()), 16)
                    //     + Convert.ToString(Convert.ToInt32(arrl[65].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[66].ToString()), 16);
                    //if (groundseven != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[63]);
                    //    bytes[1] = Convert.ToByte(arrl[64]);
                    //    bytes[2] = Convert.ToByte(arrl[65]);
                    //    bytes[3] = Convert.ToByte(arrl[66]);

                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime,"7");
                    //}
                    ////8通道
                    //groundeight = Convert.ToString(Convert.ToInt32(arrl[71].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[72].ToString()), 16)
                    //     + Convert.ToString(Convert.ToInt32(arrl[73].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[74].ToString()), 16);
                    //if (groundeight != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[71]);
                    //    bytes[1] = Convert.ToByte(arrl[72]);
                    //    bytes[2] = Convert.ToByte(arrl[73]);
                    //    bytes[3] = Convert.ToByte(arrl[74]);

                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime,"8");
                    //}
                    rd = 0;
                    arrl.Clear();
                    //读下一组数据
                    if (MessageNotification.GetInstance() != null)
                    {
                        MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadTY16, "JX");
                    }
                }
            }
            if (Global.SendToTYData == "24")
            {
                //读取第二组数据
                if (rd == 73)
                {
                    byte[] tbytes = new byte[6];
                    tbytes[0] = Convert.ToByte(arrl[6]);
                    tbytes[1] = Convert.ToByte(arrl[4]);
                    tbytes[2] = Convert.ToByte(arrl[3]);
                    tbytes[3] = Convert.ToByte(arrl[2]);
                    tbytes[4] = Convert.ToByte(arrl[1]);
                    tbytes[5] = Convert.ToByte(arrl[0]);

                    int i1 = Int32.Parse(Convert.ToString(tbytes[0], 16), System.Globalization.NumberStyles.HexNumber);
                    int i2 = Int32.Parse(Convert.ToString(tbytes[1], 16), System.Globalization.NumberStyles.HexNumber);
                    int i3 = Int32.Parse(Convert.ToString(tbytes[2], 16), System.Globalization.NumberStyles.HexNumber);
                    int i4 = Int32.Parse(Convert.ToString(tbytes[3], 16), System.Globalization.NumberStyles.HexNumber);
                    int i5 = Int32.Parse(Convert.ToString(tbytes[4], 16), System.Globalization.NumberStyles.HexNumber);
                    int i6 = Int32.Parse(Convert.ToString(tbytes[5], 16), System.Globalization.NumberStyles.HexNumber);
                    //检测时间
                    SChkTime = "20" + i1.ToString() + "/" + i2.ToString() + "/" + i3.ToString() + " " + i4.ToString()
                               + ":" + i5.ToString() + ":" + i6.ToString();
                    //判断哪个通道
                    byte[] bt = new byte[1];
                    bt[0] = Convert.ToByte(arrl[7]);
                    string IstestNum = Convert.ToString(bt[0], 2);
                    //给二进制数补0
                    if (IstestNum.Length < 8)
                    {
                        for (int k = IstestNum.Length; k < 8; k++)
                        {
                            IstestNum = "0" + IstestNum;
                        }
                    }

                    int h = 0;

                    //for循环读取
                    for (int j = 13; j < 73; j++)
                    {
                        groundone = IsShiLiu(Convert.ToString(Convert.ToInt32(arrl[j].ToString()), 16)) + IsShiLiu(Convert.ToString(Convert.ToInt32(arrl[j + 1].ToString()), 16))
                                    + IsShiLiu(Convert.ToString(Convert.ToInt32(arrl[j + 2].ToString()), 16)) + IsShiLiu(Convert.ToString(Convert.ToInt32(arrl[j + 3].ToString()), 16));
                        string hole = IstestNum.Substring(h, 1);
                        h = h + 1;
                        if (hole == "1")
                        {
                            uint num = uint.Parse(groundone, System.Globalization.NumberStyles.AllowHexSpecifier);

                            byte[] floatVals = BitConverter.GetBytes(num);

                            float f = BitConverter.ToSingle(floatVals, 0);

                            double fd = Math.Round(f, 2);
                            DataToTable(Convert.ToString(fd), SChkTime, h.ToString());
                        }
                        j = j + 7;
                    }

                    ////1通道
                    //groundone = Convert.ToString(Convert.ToInt32(arrl[13].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[14].ToString()), 16)
                    //    + Convert.ToString(Convert.ToInt32(arrl[15].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[16].ToString()), 16);

                    //if (groundone != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[13]);
                    //    bytes[1] = Convert.ToByte(arrl[14]);
                    //    bytes[2] = Convert.ToByte(arrl[15]);
                    //    bytes[3] = Convert.ToByte(arrl[16]);
                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime,"1");
                    //}
                    ////2通道
                    //groundtwo  = Convert.ToString(Convert.ToInt32(arrl[21].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[22].ToString()), 16)
                    //    + Convert.ToString(Convert.ToInt32(arrl[23].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[24].ToString()), 16);

                    //if (groundtwo != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[21]);
                    //    bytes[1] = Convert.ToByte(arrl[22]);
                    //    bytes[2] = Convert.ToByte(arrl[23]);
                    //    bytes[3] = Convert.ToByte(arrl[24]);
                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime,"2");
                    //}
                    ////3通道
                    //groundthree  = Convert.ToString(Convert.ToInt32(arrl[29].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[30].ToString()), 16)
                    //    + Convert.ToString(Convert.ToInt32(arrl[31].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[32].ToString()), 16);

                    //if (groundthree != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[29]);
                    //    bytes[1] = Convert.ToByte(arrl[30]);
                    //    bytes[2] = Convert.ToByte(arrl[31]);
                    //    bytes[3] = Convert.ToByte(arrl[32]);
                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime,"3");
                    //}
                    ////4通道
                    //groundfour = Convert.ToString(Convert.ToInt32(arrl[37].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[38].ToString()), 16)
                    //    + Convert.ToString(Convert.ToInt32(arrl[39].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[40].ToString()), 16);

                    //if (groundfour != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[37]);
                    //    bytes[1] = Convert.ToByte(arrl[38]);
                    //    bytes[2] = Convert.ToByte(arrl[39]);
                    //    bytes[3] = Convert.ToByte(arrl[40]);
                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);

                    //    DataToTable(Convert.ToString(fd), SChkTime,"4");
                    //}
                    ////5通道
                    //groundfire  = Convert.ToString(Convert.ToInt32(arrl[45].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[46].ToString()), 16)
                    //    + Convert.ToString(Convert.ToInt32(arrl[47].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[48].ToString()), 16);

                    //if (groundfire != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[45]);
                    //    bytes[1] = Convert.ToByte(arrl[46]);
                    //    bytes[2] = Convert.ToByte(arrl[47]);
                    //    bytes[3] = Convert.ToByte(arrl[48]);
                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime,"5");
                    //}
                    ////6通道
                    //groundsix = Convert.ToString(Convert.ToInt32(arrl[53].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[54].ToString()), 16)
                    //    + Convert.ToString(Convert.ToInt32(arrl[55].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[56].ToString()), 16);

                    //if (groundsix != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[53]);
                    //    bytes[1] = Convert.ToByte(arrl[54]);
                    //    bytes[2] = Convert.ToByte(arrl[55]);
                    //    bytes[3] = Convert.ToByte(arrl[56]);
                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime,"6");
                    //}
                    ////7通道
                    //groundseven  = Convert.ToString(Convert.ToInt32(arrl[61].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[62].ToString()), 16)
                    //    + Convert.ToString(Convert.ToInt32(arrl[63].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[64].ToString()), 16);

                    //if (groundseven != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[61]);
                    //    bytes[1] = Convert.ToByte(arrl[62]);
                    //    bytes[2] = Convert.ToByte(arrl[63]);
                    //    bytes[3] = Convert.ToByte(arrl[64]);
                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime,"7");
                    //}
                    ////8通道
                    //groundeight = Convert.ToString(Convert.ToInt32(arrl[69].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[70].ToString()), 16)
                    //    + Convert.ToString(Convert.ToInt32(arrl[71].ToString()), 16) + Convert.ToString(Convert.ToInt32(arrl[72].ToString()), 16);

                    //if (groundeight != "0000")
                    //{
                    //    byte[] bytes = new byte[4];
                    //    bytes[0] = Convert.ToByte(arrl[69]);
                    //    bytes[1] = Convert.ToByte(arrl[70]);
                    //    bytes[2] = Convert.ToByte(arrl[71]);
                    //    bytes[3] = Convert.ToByte(arrl[72]);
                    //    float f = BitConverter.ToSingle(bytes, 0);
                    //    double fd = Math.Round(f, 2);
                    //    DataToTable(Convert.ToString(fd), SChkTime, "8");
                    //}
                    rd = 0;
                    arrl.Clear();
                    //发送消息给主界面
                    if (MessageNotification.GetInstance() != null)
                    {
                        MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadTY16, "JX");
                    }
                }
                else if (rd == 2 && arrl[0].ToString() == "27" && arrl[1].ToString() == "254")
                {
                    //所有数据传送完成
                    rd = 0;
                    arrl.Clear();
                    //发送消息给主界面
                    if (MessageNotification.GetInstance() != null)
                    {
                        MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadTY16, "ReadOver");
                    }
                }
            }
        }
コード例 #4
0
        private void ParseDataFromDevice(string dataRead)
        {
            string command = dataRead.Substring(4, 2);
            string temp    = string.Empty;

            //湿化学
            #region
            if (command.Equals("42") || command.Equals("62") || command.Equals("72")) //如果是读取检测项目
            {
                Encoding gb2312 = Encoding.GetEncoding("gb2312");
                temp = dataRead.Substring(24, 32);
                byte[] itemHexArray    = clsStringUtil.HexString2ByteArray(clsStringUtil.HexStringTrim(temp));
                string chineseItemName = gb2312.GetString(itemHexArray);//项目名称
                temp = dataRead.Substring(56, 16);
                byte[] unitHexArray = clsStringUtil.HexString2ByteArray(clsStringUtil.HexStringTrim(temp));
                string chineseUnit  = gb2312.GetString(unitHexArray);//单位
                temp = dataRead.Substring(72, 2);
                int checkValue = Convert.ToByte(temp, 16);
                if (command.Equals("42") && DY660 == "022")
                {
                    m_ItemParts += "{" + "非试纸法-" + chineseItemName.Trim() + ":-1:" + checkValue.ToString() + ":" + chineseUnit.Trim() + "}";
                }
                if (command.Equals("62") && DY660 == "022")
                {
                    m_ItemParts += "{" + "金标法-" + chineseItemName.Trim() + ":-6:" + checkValue.ToString() + ":" + chineseUnit.Trim() + "}";
                }
                if (command.Equals("72") && DY660 == "022")
                {
                    m_ItemParts += "{" + "干化学法-" + chineseItemName.Trim() + ":-7:" + checkValue.ToString() + ":" + chineseUnit.Trim() + "}";
                }
                else if (command.Equals("42") && DY660 != "022")
                {
                    m_ItemParts += "{" + chineseItemName.Trim() + ":-1:" + checkValue.ToString() + ":" + chineseUnit.Trim() + "}";
                }
                if (dataRead.Length > 512)
                {
                    temp            = dataRead.Substring(280, 32);
                    itemHexArray    = clsStringUtil.HexString2ByteArray(clsStringUtil.HexStringTrim(temp));
                    chineseItemName = gb2312.GetString(itemHexArray);
                    temp            = dataRead.Substring(312, 16);
                    unitHexArray    = clsStringUtil.HexString2ByteArray(clsStringUtil.HexStringTrim(temp));
                    chineseUnit     = gb2312.GetString(unitHexArray);
                    temp            = dataRead.Substring(328, 2);
                    checkValue      = Convert.ToByte(temp, 16);
                    if (command.Equals("42") && DY660 == "022")
                    {
                        m_ItemParts += "{" + "非试纸法-" + chineseItemName.Trim() + ":-1:" + checkValue.ToString() + ":" + chineseUnit.Trim() + "}";
                    }
                    if (command.Equals("62") && DY660 == "022")
                    {
                        m_ItemParts += "{" + "金标法-" + chineseItemName.Trim() + ":-6:" + checkValue.ToString() + ":" + chineseUnit.Trim() + "}";
                    }
                    if (command.Equals("72") && DY660 == "022")
                    {
                        m_ItemParts += "{" + "干化学法-" + chineseItemName.Trim() + ":-7:" + checkValue.ToString() + ":" + chineseUnit.Trim() + "}";
                    }
                    else if (command.Equals("42") && DY660 != "022")
                    {
                        m_ItemParts += "{" + chineseItemName.Trim() + ":-1:" + checkValue.ToString() + ":" + chineseUnit.Trim() + "}";
                    }
                    if (command.Equals("42"))
                    {
                        m_ItemID++;
                        ReadItems(m_ItemID);
                    }
                    if (command.Equals("62"))
                    {
                        m_ItemID1++;
                        ReadItems1(m_ItemID1);
                    }
                    if (command.Equals("72"))
                    {
                        m_ItemID2++;
                        ReadItems2(m_ItemID2);
                    }
                }
                else //数据不完整
                {
                    m_DataReadByteCount   = 0;
                    m_DataRead            = string.Empty;
                    m_LatterDataByteCount = 0;

                    if (MessageNotification.GetInstance() != null)
                    {
                        MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadDY3000DYItem, m_ItemParts);
                    }
                }
            }
            else if (command.Equals("43") || command.Equals("63") || command.Equals("73")) //如果读记录条数,读取检测项目不需要用到此函数
            {
                string tempStr = dataRead.Substring(40, 4);
                int    i1      = 0;
                i1  = Convert.ToByte(tempStr.Substring(2, 2), 16) << 8;
                i1 += Convert.ToByte(tempStr.Substring(0, 2), 16);
                m_RecordStartPosition = i1;
                tempStr             = dataRead.Substring(44, 4);
                i1                  = Convert.ToByte(tempStr.Substring(2, 2), 16) << 8;
                i1                 += Convert.ToByte(tempStr.Substring(0, 2), 16);
                m_RecordEndPosition = i1;    //recordNum = 0;
                //根据记录条数,构造发送数据
                if (m_RecordStartPosition + 1 <= m_RecordEndPosition)
                {
                    if (N_DataTemp42 == "非试纸法")
                    {
                        ReadRecords(m_RecordStartPosition);
                    }
                    if (N_DataTemp62 == "金标卡法")
                    {
                        ReadRecords1(m_RecordStartPosition);
                    }
                    if (N_DataTemp72 == "干化学法")
                    {
                        ReadRecords2(m_RecordStartPosition);
                    }
                    if (string.IsNullOrEmpty(N_DataTemp72) && string.IsNullOrEmpty(N_DataTemp62) && string.IsNullOrEmpty(N_DataTemp42))
                    {
                        ReadRecords(m_RecordStartPosition);
                    }
                }
                else
                {
                    m_RecordCount         = 0;
                    m_RecordStartPosition = 0;
                    m_RecordEndPosition   = 0;
                    m_DataReadByteCount   = 0;
                    m_DataRead            = string.Empty;
                    m_LatterDataByteCount = 0;
                    if (MessageNotification.GetInstance() != null)
                    {
                        MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadDY3000DYData, "");
                    }
                }
            }
            else if (command.Equals("45") || command.Equals("65") || command.Equals("75")) //表明读的记录条数
            {
                string ON1 = dataRead.Substring(24, 2);
                if (!dataRead.Substring(24, 2).Equals("00"))
                {
                    int    itemID   = Convert.ToByte(dataRead.Substring(26, 2), 16); //仪器上的项目序号
                    string item     = string.Empty;
                    string ON2      = dataRead.Substring(26, 2);
                    string unit     = string.Empty;
                    string methodNO = string.Empty;//仪器内部检测方法编号
                    string datetime = string.Empty;
                    if (itemID >= 0 && itemID <= CheckItemsArray.GetLength(0) - 1)
                    {
                        if (command.Equals("45"))
                        {
                            item     = CheckItemsArray[itemID, 0];
                            unit     = CheckItemsArray[itemID, 3];
                            methodNO = CheckItemsArray[itemID, 2];
                        }
                        if (command.Equals("65"))
                        {
                            item     = CheckItemsArray62[itemID, 0];
                            unit     = CheckItemsArray62[itemID, 3];
                            methodNO = CheckItemsArray62[itemID, 2];
                        }
                        if (command.Equals("75"))
                        {
                            item     = CheckItemsArray72[itemID, 0];
                            unit     = CheckItemsArray72[itemID, 3];
                            methodNO = CheckItemsArray72[itemID, 2];
                        }
                    }
                    if (command.Equals("45"))
                    {
                        datetime = clsStringUtil.HexStr2DateTimeString(dataRead.Substring(32, 8));
                    }
                    if (command.Equals("65") || command.Equals("75"))
                    {
                        datetime = clsStringUtil.HexStr2DateTimeString(dataRead.Substring(28, 8));
                    }
                    string num         = string.Empty;
                    string checkValue  = string.Empty; //检测值
                    string error       = "否";          // 数据是否可疑
                    string partOutcome = string.Empty;
                    string tempStr     = dataRead.Substring(48);
                    int    byteCount   = 16; //数据串长度(8个字节)
                    int    recordCount = tempStr.Length / byteCount;
                    int    p           = 0;
                    int    channelNO   = 0;
                    if (command.Equals("45"))
                    {
                        for (int i = 0; i < recordCount; i++)
                        {
                            channelNO = Convert.ToByte(dataRead.Substring(40 + i * 16, 2), 16);
                            p         = Convert.ToByte(dataRead.Substring(42 + i * 16, 2), 16);
                            //if (p >= 128 && channelNO > 0)   // if ( ctrlChannel > 0) //p大于等于128表明有效,k=0表明是对照通道
                            if (channelNO > 0)
                            {
                                error = "否";
                                if (p >= 192)
                                {
                                    error = "是";       //说明数据可疑
                                }
                                num = channelNO.ToString();

                                if (methodNO.Equals("0")) //为抑制率法
                                {
                                    partOutcome = dataRead.Substring(48 + i * 16, 4).ToUpper();
                                    if (partOutcome.Equals("FF7F"))//无效数据
                                    {
                                        checkValue = "---.-";
                                    }
                                    else if (partOutcome.Equals("FE7F"))
                                    {
                                        checkValue = "NA";
                                    }
                                    else
                                    {
                                        checkValue = clsStringUtil.HexString2Float2String(partOutcome);
                                    }
                                }
                                else //其他方法
                                {
                                    partOutcome = dataRead.Substring(48 + i * 16, 8).ToUpper();
                                    if (partOutcome.Equals("FFFFFF7F") || partOutcome.Equals("FEFFFF7F") || partOutcome.Equals("FF7F0000") || partOutcome.Equals("2C420F00"))    //无效数据
                                    {
                                        checkValue = "-.---";
                                    }
                                    else if (partOutcome.Equals("FDFFFF7F") || partOutcome.Equals("FE7F0000"))    //可怀疑数据
                                    {
                                        checkValue = "NA";
                                    }
                                    else
                                    {
                                        checkValue = clsStringUtil.HexString2Float4String(partOutcome);
                                    }
                                }
                                if (!(checkValue.Equals("NA") || checkValue.Equals("-.---") || checkValue.Equals("---.-")))
                                {
                                    AddNewHistoricData(num, item, checkValue, unit, datetime, error);
                                }
                            }
                        }
                    }
                    if (command.Equals("65") || command.Equals("75"))
                    {
                        string OUTnum = dataRead.Substring(36, 4).ToUpper();
                        double NOE    = Convert.ToDouble(clsStringUtil.HexString2Float2String(OUTnum));
                        num = (NOE * 10).ToString();
                        byte[] TempArry = clsStringUtil.HexString2ByteArray(dataRead.Substring(24));
                        string o        = dataRead.Substring(24);
                        if (command.Equals("65"))
                        {
                            switch (TempArry[8] >> 6 & 0x03)
                            {  //高2位表示检测方法
                            case 0:
                            case 1: switch (TempArry[8] & 0x03)
                                {
                                case 1: checkValue = "阳性";
                                    break;

                                case 2: checkValue = "阴性";
                                    break;

                                case 3: checkValue = "NA";
                                    break;

                                default: checkValue = "NA";
                                    break;
                                }
                                break;

                            case 2:
                            case 3:
                                partOutcome = dataRead.Substring(42, 12).ToUpper();
                                checkValue  = clsStringUtil.HexString2Float4String(partOutcome);
                                break;
                            }
                        }
                        if (command.Equals("75"))
                        {
                            switch (TempArry[8] >> 6 & 0x03)
                            {  //高2位表示检测方法
                            case 0: switch (TempArry[8] & 0x03)
                                {
                                case 1: checkValue = "阳性";
                                    break;

                                case 2: checkValue = "阴性";
                                    break;

                                case 3: checkValue = "NA";
                                    break;

                                default: checkValue = "NA";
                                    break;
                                }
                                ; break;

                            case 2: partOutcome = dataRead.Substring(42, 12).ToUpper();
                                checkValue      = clsStringUtil.HexString2Float4String(partOutcome); break;
                            }
                        }
                        if (!(checkValue.Equals("NA") || checkValue.Equals("-.---") || checkValue.Equals("---.-")))
                        {
                            AddNewHistoricData(num, item, checkValue, unit, datetime, error);
                        }
                    }
                }
                m_RecordCount++;
                int endPosition = m_RecordStartPosition + m_RecordCount;
                if (endPosition >= m_RecordEndPosition)
                {
                    m_RecordCount         = 0;
                    m_RecordStartPosition = 0;
                    m_RecordEndPosition   = 0;
                    m_DataReadByteCount   = 0;
                    m_DataRead            = string.Empty;
                    m_LatterDataByteCount = 0;
                    if (MessageNotification.GetInstance() != null)
                    {
                        MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadDY3000DYData, "");
                    }
                }
                else
                {
                    if (command.Equals("45"))
                    {
                        ReadRecords(endPosition);
                    }
                    if (command.Equals("65"))
                    {
                        ReadRecords1(endPosition);
                    }
                    if (command.Equals("75"))
                    {
                        ReadRecords2(endPosition);
                    }
                }
            }
            #endregion
            //胶体金
        }
コード例 #5
0
        /// <summary>
        /// 串口返回数据
        /// </summary>
        /// <param name="bty"></param>
        protected override void OnRxChar(byte c)
        {
            if (m_DataRead.Equals("8104"))
            {
                dataLen = int.Parse(c.ToString(), 0);
            }
            string currentByte = c.ToString("X2");    //转换成2位的16进制

            m_DataRead += currentByte;
            bt[index]   = c;
            index++;
            if (dataLen > 0)
            {
                if (m_DataRead.Length == (dataLen + 6) * 2)
                {
                    rtnData(m_DataRead);
                }
            }
            else if (m_DataRead.Equals("810400000181"))
            {
                m_RecordCount         = 0;
                m_RecordStartPosition = 0;
                m_RecordEndPosition   = 0;
                m_DataReadByteCount   = 0;
                m_DataRead            = string.Empty;
                m_LatterDataByteCount = 0;
                if (MessageNotification.GetInstance() != null)
                {
                    MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadDY3000DYData, "");
                }
            }
            int len = m_DataRead.Length;

            if (m_DataReadByteCount == 0 && currentByte.Equals("FE") && len >= 4)
            {
                bool isEnd = m_DataRead.Substring(len - 4, 2).Equals("03");
                if (isEnd)
                {
                    m_DataReadByteCount = 1;
                }
            }
            if (m_DataReadByteCount > 0)
            {
                m_DataReadByteCount++;
                string checkSum = string.Empty;
                //再次判断获得参数是否正确,不正确清空,正确确定后续数据的长度
                if (m_DataReadByteCount == 11)
                {
                    m_DataRead = m_DataRead.Substring(len - 22, 22);
                    checkSum   = clsStringUtil.CheckDataSum(m_DataRead.Substring(0, 20));
                    if (currentByte.Equals(checkSum))
                    {
                        string tempStr = m_DataRead.Substring(16, 4);
                        int    i1      = Convert.ToByte(tempStr.Substring(2, 2), 16) << 8;
                        i1 += Convert.ToByte(tempStr.Substring(0, 2), 16);
                        m_LatterDataByteCount = i1;
                    }
                    else
                    {
                        m_DataReadByteCount   = 0;
                        m_DataRead            = string.Empty;
                        m_LatterDataByteCount = 0;
                    }
                }
                if (m_DataReadByteCount == 12 + m_LatterDataByteCount)
                {
                    if (m_LatterDataByteCount > 0)
                    {
                        checkSum = clsStringUtil.CheckDataSum(m_DataRead.Substring(24, m_LatterDataByteCount * 2));
                        if (m_DataRead.Substring(22, 2).Equals(checkSum))
                        {
                            ParseDataFromDevice(m_DataRead);
                        }
                    }
                    if (m_LatterDataByteCount == 0)//如果检测项目
                    {
                        int tlen = m_DataRead.Length;
                        if (tlen >= 6 && m_DataRead.Substring(4, 2).Equals("42")) //表明检测项目读完
                        {
                            if (MessageNotification.GetInstance() != null)
                            {
                                MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadDY3000DYItem, m_ItemParts);
                            }
                        }
                        if (tlen >= 6 && m_DataRead.Substring(4, 2).Equals("62")) //表明检测项目读完
                        {
                            if (MessageNotification.GetInstance() != null)
                            {
                                MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadDY3000DYItem, m_ItemParts);
                            }
                        }
                        if (tlen >= 6 && m_DataRead.Substring(4, 2).Equals("72")) //表明检测项目读完
                        {
                            if (MessageNotification.GetInstance() != null)
                            {
                                MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadDY3000DYItem, m_ItemParts);
                            }
                        }
                    }
                    m_DataReadByteCount   = 0;
                    m_DataRead            = string.Empty;
                    m_LatterDataByteCount = 0;
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// 接收串口返回的数据
        /// </summary>
        /// <param name="c"></param>
        protected override void OnRxChar(byte c)
        {
            RtnTemp = RtnTemp + c.ToString("X2");

            //Alist.Add(c.ToString("X2"));
            if (Global.communicatType == "通信测试" && RtnTemp == "7E020400FF021010F8AA")
            {
                RtnTemp = "";
                if (MessageNotification.GetInstance() != null)
                {
                    MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadTL310Data, "TLtongxin");
                }
            }
            else if (Global.communicatType == "数据读取" && RtnTemp.Length > 20)
            {
                string record = RtnTemp.Substring(12, 2);   //低位在前
                record = record + RtnTemp.Substring(10, 2); //高位在后
                int TotalRecord = Convert.ToInt16(record, 16);
                if (RtnTemp.Length == TotalRecord * 27 * 2)
                {
                    for (int i = 0; i < TotalRecord; i++)
                    {
                        string RecordNo = RtnTemp.Substring(16 + 54 * i, 2);
                        RecordNo = RecordNo + RtnTemp.Substring(14 + 54 * i, 2);                               //当前记录是第几条记录
                        string   holenum  = Convert.ToInt32(RtnTemp.Substring(18 + 54 * i, 2), 16).ToString(); //通道号
                        string   standard = RtnTemp.Substring(20 + 54 * i, 2);                                 //检测标准
                        string   y        = "20" + Convert.ToInt32(RtnTemp.Substring(22 + 54 * i, 2), 16).ToString();
                        int      year     = Int32.Parse(y);                                                    //检测时间年
                        int      Month    = Convert.ToInt32(RtnTemp.Substring(24 + 54 * i, 2), 16);            //检测时间月
                        int      Day      = Convert.ToInt32(RtnTemp.Substring(26 + 54 * i, 2), 16);            //检测时间日
                        int      hour     = Convert.ToInt32(RtnTemp.Substring(28 + 54 * i, 2), 16);            //检测时间时
                        int      Muni     = Convert.ToInt32(RtnTemp.Substring(30 + 54 * i, 2), 16);            //检测时间分
                        int      seconds  = Convert.ToInt32(RtnTemp.Substring(32 + 54 * i, 2), 16);            //检测时间秒
                        DateTime ChkTime  = new DateTime(year, Month, Day, hour, Muni, seconds);

                        //string xiguangdu = RtnTemp.Substring(38 + 54 * i, 4);//吸光度
                        int    CheckData   = Convert.ToInt32(RtnTemp.Substring(42 + 54 * i, 2), 16) + Convert.ToInt32(RtnTemp.Substring(44 + 54 * i, 2), 16) * 256;//检测结果 抑制率
                        double dd          = CheckData / 10;
                        double ww          = CheckData % 10;
                        string checkResult = dd.ToString() + "." + ww.ToString();
                        //double ss = double.Parse(rr);
                        //string checkResult = string.Format("{0:P1}", ss);
                        string conclusion = "";//结论
                        if (RtnTemp.Substring(46 + 54 * i, 2) == "02")
                        {
                            conclusion = "合格";
                        }
                        else if (RtnTemp.Substring(46 + 54 * i, 2) == "01")
                        {
                            conclusion = "超标";
                        }
                        if (CheckData == 32766)//NA 返回 7FFE
                        {
                            continue;
                        }
                        AddTableData(holenum, standard, checkResult, conclusion, ChkTime);
                    }

                    RtnTemp = "";
                    if (MessageNotification.GetInstance() != null)
                    {
                        MessageNotification.GetInstance().OnDataRead(MessageNotification.NotificationInfo.ReadTL310Data, "DataRecord");
                    }
                }
            }
        }
コード例 #7
0
        private void ucDY6600_Load(object sender, EventArgs e)
        {
            string err = string.Empty;

            string[] Port = SerialPort.GetPortNames();
            if (Port.Length == 0)
            {
                cmbCOMbox.Items.Add("没有COM口");
            }
            foreach (string c in SerialPort.GetPortNames())
            {
                cmbCOMbox.Items.Add(c);
            }
            cmbCOMbox.SelectedIndex = 0;
            //其他信息输入
            cmbAdd.Visible = false;
            //cmbAdd.Items.Add("请选择...");
            cmbAdd.Items.Add("输入");
            cmbAdd.Items.Add("以下相同");
            cmbAdd.Items.Add("删除");
            cmbAdd.KeyUp += cmbAdd_KeyUp;
            cmbAdd.SelectedIndexChanged += cmbAdd_SelectedIndexChanged;
            CheckDatas.Controls.Add(cmbAdd);

            //检测项目
            cmbChkItem.Visible = false;
            //cmbChkItem.Items.Add("请选择...");
            cmbChkItem.Items.Add("以下相同");
            cmbChkItem.Items.Add("删除");
            cmbChkItem.DropDownStyle = ComboBoxStyle.DropDownList;
            //cmbChkItem.SelectedIndex = 0;
            cmbChkItem.KeyUp += cmbChkItem_KeyUp;
            cmbChkItem.SelectedIndexChanged += cmbChkItem_SelectedIndexChanged;
            CheckDatas.Controls.Add(cmbChkItem);

            //样品名称
            cmbSample.Visible = false;
            //cmbSample.Items.Add("请选择...");
            cmbSample.Items.Add("以下相同");
            cmbSample.Items.Add("删除");
            //cmbSample.DropDownStyle = ComboBoxStyle.DropDownList;
            //cmbSample.SelectedIndex = 0;
            cmbSample.MouseClick           += cmbSample_MouseClick;
            cmbSample.KeyUp                += cmbSample_KeyUp;
            cmbSample.SelectedIndexChanged += cmbSample_SelectedIndexChanged;
            CheckDatas.Controls.Add(cmbSample);

            //检测单位
            cmbChkUnit.Items.Add("以下相同");
            cmbChkUnit.Items.Add("删除");
            cmbChkUnit.Visible = false;
            cmbChkUnit.SelectedIndexChanged += cmbChkUnit_SelectedIndexChanged;
            //cmbChkUnit.MouseClick += cmbChkUnit_MouseClick;
            cmbChkUnit.KeyUp += cmbChkUnit_KeyUp;
            CheckDatas.Controls.Add(cmbChkUnit);
            //被检单位
            cmbDetectUnit.Items.Add("以下相同");
            cmbDetectUnit.Items.Add("删除");
            cmbDetectUnit.Visible = false;
            cmbDetectUnit.SelectedIndexChanged += cmbDetectUnit_SelectedIndexChanged;
            //cmbDetectUnit.MouseClick += cmbDetectUnit_MouseClick;
            cmbDetectUnit.KeyUp += cmbDetectUnit_KeyUp;
            CheckDatas.Controls.Add(cmbDetectUnit);
            //采样地址
            cmbGetSampleAddr.Items.Add("以下相同");
            cmbGetSampleAddr.Items.Add("删除");
            cmbGetSampleAddr.Visible = false;
            cmbGetSampleAddr.SelectedIndexChanged += cmbGetSampleAddr_SelectedIndexChanged;
            //cmbGetSampleAddr.MouseClick += cmbGetSampleAddr_MouseClick;
            cmbGetSampleAddr.KeyUp += cmbGetSampleAddr_KeyUp;
            CheckDatas.Controls.Add(cmbGetSampleAddr);
            //检测员
            cmbChker.Items.Add("以下相同");
            cmbChker.Items.Add("删除");
            cmbChker.Visible               = false;
            cmbChker.MouseClick           += cmbChker_MouseClick;
            cmbChker.SelectedIndexChanged += cmbChker_SelectedIndexChanged;
            cmbChker.KeyUp += cmbChker_KeyUp;
            CheckDatas.Controls.Add(cmbChker);

            if (Global.ChkManchine != "")
            {
                try
                {
                    strWhere.Clear();
                    strWhere.Append("WHERE Name='");
                    strWhere.Append(Global.ChkManchine);
                    strWhere.Append("'");
                    DataTable dt = sqlSet.GetIntrument(strWhere.ToString(), out err);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        itemcode = dt.Rows[0]["ChkStdCode"].ToString();
                        //WorkstationDAL.Model.clsShareOption.ComPort = dt.Rows[0][2].ToString();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
            }
            try
            {
                cdt = sqlSet.GetInformation("", "", out err);
                if (cdt != null)
                {
                    if (cdt.Rows.Count > 0)
                    {
                        for (int n = 0; n < cdt.Rows.Count; n++)
                        {
                            if (cdt.Rows[n][9].ToString() == "是")
                            {
                                unitInfo[0, 0] = cdt.Rows[n][0].ToString();//检测单位
                                unitInfo[0, 1] = cdt.Rows[n][2].ToString();
                                unitInfo[0, 2] = cdt.Rows[n][3].ToString();
                                unitInfo[0, 3] = cdt.Rows[n][8].ToString();
                            }
                            cmbChkUnit.Items.Add(cdt.Rows[n][0].ToString());       //检测单位
                            cmbDetectUnit.Items.Add(cdt.Rows[n][2].ToString());    //被检单位
                            cmbGetSampleAddr.Items.Add(cdt.Rows[n][3].ToString()); //采样地址
                            cmbChker.Items.Add(cdt.Rows[n][8].ToString());         //检测员
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }

            BindCheckItem();
            MessageNotification.GetInstance().DataRead += NotificationEventHandler;
        }
コード例 #8
0
        private void ucTTNJ16_Load(object sender, EventArgs e)
        {
            LbTitle.Text = "TTNJ-16农残快速测定仪";
            string err = string.Empty;

            string[] Port = SerialPort.GetPortNames();

            if (Port.Length == 0)
            {
                cmbCOMbox.Items.Add("没有COM口");
            }
            foreach (string c in SerialPort.GetPortNames())
            {
                cmbCOMbox.Items.Add(c);
            }
            cmbCOMbox.SelectedIndex = 0;

            cmbAdd.Visible = false;
            //cmbAdd.Items.Add("请选择...");
            cmbAdd.Items.Add("输入");
            cmbAdd.Items.Add("以下相同");
            cmbAdd.Items.Add("删除");
            cmbAdd.KeyUp += cmbAdd_KeyUp;
            cmbAdd.SelectedIndexChanged += cmbAdd_SelectedIndexChanged;
            CheckDatas.Controls.Add(cmbAdd);

            //检测项目
            cmbChkItem.Visible = false;
            //cmbChkItem.Items.Add("请选择...");
            cmbChkItem.Items.Add("以下相同");
            cmbChkItem.Items.Add("删除");
            //cmbChkItem.DropDownStyle = ComboBoxStyle.DropDownList;
            //cmbChkItem.SelectedIndex = 0;
            cmbChkItem.KeyUp += cmbChkItem_KeyUp;
            cmbChkItem.SelectedIndexChanged += cmbChkItem_SelectedIndexChanged;
            CheckDatas.Controls.Add(cmbChkItem);

            //样品名称
            cmbSample.Visible = false;
            //cmbSample.Items.Add("请选择...");
            cmbSample.Items.Add("以下相同");
            cmbSample.Items.Add("删除");
            //cmbSample.DropDownStyle = ComboBoxStyle.DropDownList;
            //cmbSample.SelectedIndex = 0;
            cmbSample.MouseClick           += cmbSample_MouseClick;
            cmbSample.KeyUp                += cmbSample_KeyUp;
            cmbSample.SelectedIndexChanged += cmbSample_SelectedIndexChanged;
            CheckDatas.Controls.Add(cmbSample);
            //检测单位
            cmbChkUnit.Items.Add("以下相同");
            cmbChkUnit.Items.Add("删除");
            cmbChkUnit.Visible = false;
            cmbChkUnit.SelectedIndexChanged += cmbChkUnit_SelectedIndexChanged;
            //cmbChkUnit.MouseClick += cmbChkUnit_MouseClick;
            cmbChkUnit.KeyUp += cmbChkUnit_KeyUp;
            CheckDatas.Controls.Add(cmbChkUnit);
            //被检单位
            cmbDetectUnit.Items.Add("以下相同");
            cmbDetectUnit.Items.Add("删除");
            cmbDetectUnit.Visible = false;
            cmbDetectUnit.SelectedIndexChanged += cmbDetectUnit_SelectedIndexChanged;
            //cmbDetectUnit.MouseClick += cmbDetectUnit_MouseClick;
            cmbDetectUnit.KeyUp += cmbDetectUnit_KeyUp;
            CheckDatas.Controls.Add(cmbDetectUnit);
            //采样地址
            cmbGetSampleAddr.Items.Add("以下相同");
            cmbGetSampleAddr.Items.Add("删除");
            cmbGetSampleAddr.Visible = false;
            cmbGetSampleAddr.SelectedIndexChanged += cmbGetSampleAddr_SelectedIndexChanged;
            //cmbGetSampleAddr.MouseClick += cmbGetSampleAddr_MouseClick;
            cmbGetSampleAddr.KeyUp += cmbGetSampleAddr_KeyUp;
            CheckDatas.Controls.Add(cmbGetSampleAddr);
            //检测员
            cmbChker.Items.Add("以下相同");
            cmbChker.Items.Add("删除");
            cmbChker.Visible               = false;
            cmbChker.MouseClick           += cmbChker_MouseClick;
            cmbChker.SelectedIndexChanged += cmbChker_SelectedIndexChanged;
            cmbChker.KeyUp += cmbChker_KeyUp;
            CheckDatas.Controls.Add(cmbChker);

            MessageNotification.GetInstance().DataRead += NotificationEventHandler;
            clsUpdateMessage.LabelUpdated += clsUpdateMessage_LabelUpdated;

            CheckDatas.DataSource = clsTY16.DataReadTable;
        }