Esempio n. 1
0
        /// <summary>
        /// read MD command
        /// </summary>
        /// <param name="get_command">received command</param>
        /// <param name="time_stamp">timestamp data</param>
        /// <param name="distances">distance data</param>
        /// <returns>is successful</returns>
        public static bool MD(string get_command, ref long time_stamp, ref List <long> distances)
        {
            //distances.Clear();
            string[] split_command = get_command.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            if (!split_command[0].StartsWith("MD"))
            {
                return(false);
            }

            if (split_command[1].StartsWith("00"))
            {
                return(true);
            }
            else if (split_command[1].StartsWith("99"))
            {
                time_stamp = SCIP_Reader.decode(split_command[2], 4);
                distance_data(split_command, 3, ref distances);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// read distance data
        /// </summary>
        /// <param name="lines"></param>
        /// <param name="start_line"></param>
        /// <returns></returns>
        public static bool distance_data(string[] lines, int start_line, ref List <long> distances)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = start_line; i < lines.Length; ++i)
            {
                sb.Append(lines[i].Substring(0, lines[i].Length - 1));
            }
            return(SCIP_Reader.decode_array(sb.ToString(), 3, ref distances));
        }
Esempio n. 3
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);
            }
        }