Beispiel #1
0
        private void getData()
        {
            bool isOver = false;

            while (!isOver)
            {
                lock (port.Lockbuffer)
                {
                    if (port.DateList.Count < 1)
                    {
                        continue;
                    }
                    for (int i = 0; i < port.DateList.Count; i++)
                    {
                        byte[] data = port.DateList.Dequeue();
                        Trace.WriteLine(PLAASerialPort.byteToHexStr(data));
                        // 数据帧
                        if (data.Length == 19)
                        {
                            Equipment eqoo = mainList.Find(c => c.Address == data[1] && c.SensorType == (EM_HighType)data[2] && c.GasType == data[3]);
                            if (eqoo == null)
                            {
                                continue;
                            }

                            EquipmentData ed = new EquipmentData();

                            ed.AddTime = Parse.GetDateTime(data, 9);
                            //  DateTime format_dt;
                            //  DateTime.TryParse(ed.AddTime,out format_dt);
                            //  ed.AddTime = format_dt;
                            ed.Chroma      = (float)Math.Round(Parse.GetFloatValue(data, 5), eqoo.Point);
                            ed.EquipmentID = eqoo.ID;
                            ed.UnitType    = data[4];
                            if (!InputDataDal.AddOne(ed))
                            {
                                LogLib.Log.GetLogger(this).Warn("插入数据库错误");
                            }

                            this.Invoke(new Action <string>(addText), string.Format("{0},{1},浓度:{2},时间:{3}\r\n", eqoo.Name, eqoo.GasName, ed.Chroma, ed.AddTime));
                        }
                        else if (data.Length == 6) // 结束桢
                        {
                            isOver           = true;
                            port.IsInputData = false;
                            this.Invoke(new Action <string>(addText), "上传完成----------------------------------------------------");

                            this.Invoke(new Action <string>(c => simpleButton1.Text = c), "开始上传");
                            break;
                        }
                    }
                }

                Thread.Sleep(200);
            }
        }