void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {
     //Debug.WriteLine("serialPort_DataReceived");
     try
     {
         string resp = serialPort.ReadLine();
         //Debug.WriteLine("OK: resp='" + resp + "'");
         string[] parts = resp.Split(new char[] { '|' });
         if (parts.Length == 4 && parts[0].StartsWith("*"))
         {
             int count;
             if (int.TryParse(parts[1], out count) && count < 250 && count > 150)
             {
                 string[] sVals = parts[3].Split(new char[] { ' ' });
                 if (sVals.Length > 150)
                 {
                     List <int> values = new List <int>();
                     foreach (string s in sVals)
                     {
                         if ("0123456789".IndexOf(s[0]) >= 0)
                         {
                             int val = int.Parse(s);
                             values.Add(val == 0 ? 4000 : val);
                         }
                     }
                     //Debug.WriteLine("OK: resp parsed to " + values.Count + " readings");
                     if (count == values.Count)
                     {
                         //Debug.WriteLine("OK: good readings");
                         if (DataReceivedEvent != null)
                         {
                             LaserDataSerializable data = new LaserDataSerializable()
                             {
                                 TimeStamp = DateTime.Now.Ticks, DistanceMeasurements = values.ToArray()
                             };
                             DataReceivedEvent(this, data);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception exc)
     {
         Debug.WriteLine("Error: serialPort_DataReceived - exception " + exc);
     }
 }
Пример #2
0
 private void SetCurrentLaserData(LaserDataSerializable data)
 {
     this.LidarViewControl.CurrentLaserData = data;
 }
Пример #3
0
 void lidarLiteProcessor_DataReceived(object sender, LaserDataSerializable data)
 {
     Debug.WriteLine("OK: lidarLiteProcessor_DataReceived");
     Dispatcher.Invoke(new Action <LaserDataSerializable>(SetCurrentLaserData), data);
 }