/// <summary> /// Sends the command via ehternet. /// </summary> public string SendCmdViaEhternet() { if (cbInterfaceType.Text == "ETHERNET") { try { // Назначаем сокет локальной конечной точке и слушаем входящие сокеты // Устанавливаем для сокета локальную конечную точку int port = 5024; // порт для приема входящих запросов string ip = txtIpHost.Text; // Создаем сокет Tcp/Ip IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(ip), port); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); PiezoParameters piezo = new PiezoParameters(); string msg = txtCommand.Text + '\n'; socket.Connect(ipPoint); byte[] data = Encoding.ASCII.GetBytes(msg); socket.Send(data); // получаем ответ System.Threading.Thread.Sleep(400); data = new byte[70]; // буфер для ответа StringBuilder builder = new StringBuilder(); int bytes = 0; // количество полученных байт do { bytes = socket.Receive(data, data.Length, 0); builder.Append(Encoding.ASCII.GetString(data, 0, bytes)); }while (socket.Available > 0); //int gg = data.Count(); //MessageBox.Show(gg.ToString()); //Console.WriteLine("ответ сервера: " + builder.ToString()); //int uu = socket.Receive(data); //MessageBox.Show(uu.ToString()); byte[] data2 = new byte[70]; for (int i = 6; i < data.Count(); i++) { data2[i - 6] = data[i]; } // закрываем сокет socket.Shutdown(SocketShutdown.Both); socket.Close(); string ss = Encoding.ASCII.GetString(data2); txtAnswer.Text = ss; Regex reg = new Regex(@"^[-+][0-9][.][0-9]{5}[E][-+][0-9]{2}[,][-+][0-9][.][0-9]{5}[E][-+][0-9]{2}[,][-+][0-9]{1}"); if (reg.IsMatch(ss)) { MessageBox.Show("Ok"); ParseStringTab PS = new ParseStringTab(); PS.AddMeasStringAgilent4980(ss); txtAnswer.Text = PS.ElementAt(1); } else { txtAnswer.Text = "no"; } txtAnswer.Text = ss; char splitchar = (char)'\n'; string[] sss = ss.Split(splitchar); string s1 = sss[2]; s1 = s1.Substring(12, 24); string sss1 = ss.Substring(0, 10); txtAnswer.AppendText(Environment.NewLine + sss1); return(ss); } catch (Exception ex) { MessageBox.Show(ex.ToString()); Console.WriteLine(ex.ToString()); return(ex.ToString()); } } else { return(""); } //"SCPI> 4980A SCPI parser.\r\n\r\nSCPI> ??\u0001??\u0003-1.27856E-08,-3.91647E-0\0\0\0\0\0\0" }
/// <summary> /// Dnons the rnon import. /// </summary> /// <param name="OpenFileDNON">The open file dnon.</param> /// <param name="view">The view.</param> public void DNON_RNON_Import(string OpenFileDNON, DataGridView view) { int cst = 0; DataTable dt = new DataTable(); string fileN1 = OpenFileDNON; string fileN2 = OpenFileDNON.Substring(0, OpenFileDNON.Length - 8) + "RNON.txt"; DataRow row; FileJob FJ = new FileJob(); string[] s; try { s = FJ.ReadF(OpenFileDNON); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } for (int i = 0; i < s.GetLength(0); i++) { ParseStringTab p = new ParseStringTab(); ParseStringTab p1 = new ParseStringTab(); p.AddString(s[i]); //создание заголовков таблицы if (i == 0) { p.AddString(s[i]); IEnumerable <string> pdis = p.Distinct(); cst = pdis.Count(); foreach (string st in pdis) { p1.Add(st); } for (int j = 0; j < p1.Count; j++) { p1[j] = FJ.CorrectHead(p1[j]); dt.Columns.Add(p1[j]); } } else { //цикл для сортировки int x = 0; row = dt.NewRow(); for (int j = 0; j < p.Count(); j++) { try { row[x] = p[j]; ++x; if (x == cst) { dt.Rows.Add(row); row = dt.NewRow(); x = 0; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } p.Clear(); } try { s = FJ.ReadF(fileN2); } catch (Exception ex) { ex.ToString(); } for (int i = 1; i < s.GetLength(0); i++) { ParseStringTab p = new ParseStringTab(); ParseStringTab p1 = new ParseStringTab(); p.AddString(s[i]); int x = 0; row = dt.NewRow(); for (int j = 0; j < p.Count(); j++) { try { row[x] = p[j]; ++x; if (x == cst) { dt.Rows.Add(row); row = dt.NewRow(); x = 0; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } p.Clear(); } view.DataSource = dt; }