Example #1
0
        public bool MakeScan()
        {
            bool status = true;

            try
            {
                if (urg.IsOpen)
                {
                    CloseConnection();
                }
                PreparePort(port, baudrate);
                urg.Write(SCIP_Writer.SCIP2());
                urg.ReadLine(); // ignore echo back
                urg.Write(SCIP_Writer.MD(start_step, end_step));
                urg.ReadLine(); // ignore echo back

                distances = new List <long> [one_pos_scans];

                for (int i = 0; i < one_pos_scans; i++)
                {
                    distances[i] = new List <long>();


                    time_stamp = 0;

                    string receive_data = urg.ReadLine();
                    if (!SCIP_Reader.MD(receive_data, ref time_stamp, ref distances[i]))
                    {
                        Console.WriteLine(receive_data);
                        Console.WriteLine("----------------");
                        status = false;
                    }
                    if (distances[i].Count == 0 && status == true)
                    {
                        Console.WriteLine(receive_data);
                        Console.WriteLine("----------------");
                        status = false;
                    }
                    // show distance data

                    //for (int j = 0; j < distances[i].Count; j++)
                    //{
                    //    Console.WriteLine("time stamp: " + time_stamp.ToString() + " distance " + j + " is: " + distances[i][j].ToString());
                    //}
                }

                urg.Write(SCIP_Writer.QT()); // stop measurement mode
                urg.ReadLine();              // ignore echo back

                CloseConnection();

                if (status)
                {
                    CalculateDistances();
                }

                return(status);
            }
            catch (Exception ex)
            {
                excpt = ex.ToString();
                return(false);
            }
        }