Пример #1
0
        public void GetInfo()
        {
            if (!IsGetNewData)
            {
                return;
            }

            if (string.IsNullOrEmpty(ReceiveString))
            {
                return;
            }

            if (ReceiveString.Length < 24)
            {
                TengDa.LogHelper.WriteError("测试仪传输的数据异常:" + ReceiveString);
                return;
            }

            this.Resistance = TengDa._Convert.StrToFloat(ReceiveString.Substring(6, 5), 0);
            this.Voltage    = Current.Option.ConstVoltage;
            this.TimeSpan   = Current.Option.ConstTimeSpan;

            if (this.Resistance == 0)
            {
                this.Resistance = 999;
            }

            InsulationData.Resistance = this.Resistance;
            InsulationData.Voltage    = this.Voltage;
            InsulationData.TimeSpan   = this.TimeSpan;

            this.RealtimeStatus = string.Format("获得电阻:{0}", Resistance);

            this.CollectorIsReadyCollect = true;


            Current.ShowResistanceData.Add(this.Resistance);
            Current.ShowResistanceData.RemoveAt(0);

            Current.AnimatedPlot();

            IsGetNewData = false;

            var t = new Thread(() =>
            {
                Thread.Sleep(1000);
                this.RealtimeStatus = "等待数据";
            });

            t.IsBackground = true;
            t.Start();
        }
Пример #2
0
        /// <summary>
        /// ComCallBack
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static void ComCallBack(object sender, SerialDataReceivedEventArgs e)
        {
            int x = 15, y = 17, len = 46;

            if (sender != null)
            {
                SerialPort sp     = (SerialPort)sender;
                string     InData = sp.ReadExisting();
                ReceiveString += InData;
            }
            ReceiveString = ReceiveString.Replace("\r", "*").Replace("\n", "*").Replace("\t", "*");
            if (ReceiveString.Length > len - 3)
            {
                ReceiveString = ReceiveString.Substring(ReceiveString.Length - (len - 3));
            }
            ScreenOutput(x, y + 0, "+-- Receive Buffer ---------------------------+");
            ScreenOutput(x, y + 1, "|"); ScreenOutput(x + len, y + 1, "|");
            ScreenOutput(x, y + 2, "|"); ScreenOutput(x + 2, y + 2, ReceiveString); ScreenOutput(x + len, y + 2, "|");
            ScreenOutput(x, y + 3, "|"); ScreenOutput(x + len, y + 3, "|");
            ScreenOutput(x, y + 4, "+---------------------------------------------+");
        }