public static void TestMode() { const int GET_NUM = 10; const int start_step = 0; const int end_step = 1080; try { string ip_address = LRF_IP_ADDR; int port_number = LRF_PORT; //get_connect_information(out ip_address, out port_number); TcpClient urg = new TcpClient(); urg.Connect(ip_address, port_number); NetworkStream stream = urg.GetStream(); write(stream, SCIP_Writer.SCIP2()); read_line(stream); // ignore echo back write(stream, SCIP_Writer.MD(start_step, end_step)); read_line(stream); // ignore echo back List <double> distances = new List <double>(); long time_stamp = 0; for (int i = 0; i < GET_NUM; ++i) { string receive_data = read_line(stream); if (!SCIP_Reader.MD(receive_data, ref time_stamp, ref distances)) { Console.WriteLine(receive_data); break; } if (distances.Count == 0) { Console.WriteLine(receive_data); continue; } // show distance data Console.WriteLine("time stamp: " + time_stamp.ToString() + " distance[100] : " + distances[100].ToString()); } write(stream, SCIP_Writer.QT()); // stop measurement mode read_line(stream); // ignore echo back stream.Close(); urg.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } finally { Console.WriteLine("Press any key."); //Console.ReadKey(); } }
/// <summary> /// IP モードでオープン /// </summary> /// <param name="LRFip">ip addr</param> /// <param name="LRFport">ip port</param> /// <returns></returns> public bool IpOpen(string LRFip = LRF_IP_ADDR, int LRFport = LRF_PORT) { try { urg = new TcpClient(); urg.NoDelay = true; urg.Connect(LRFip, LRFport); stream = urg.GetStream(); if (null != stream) { // SCIP Ver2 Command write(stream, SCIP_Writer.SCIP2()); read_line(stream); // ignore echo back return(true); } return(false); } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } }