public static void Send(CustomProtocol command) { String com = command.GetStringCommand(); serial.WriteLine(com); if (command.HasData()) { serial.Write(command.Data, 0, command.Data.Length); } }
private void Button2_Copy_Click(object sender, RoutedEventArgs e) { CustomProtocol cp = new CustomProtocol(Command.GetEnginePattern); cp.AddAttribute("Engine", comboBox.SelectedValue as String); UART.Send(cp); cp = UART.Receive(); if (cp.response == Response.Ok) { byteEditor2.Stream = new MemoryStream(cp.Data); } }
public static CustomProtocol Receive() { String com = serial.ReadLine(); //if (com.Equals("\r")) com = serial.ReadLine(); CustomProtocol cp = new CustomProtocol(); cp.ParseStringCommand(com); if (cp.HasData()) { int len = int.Parse(cp.GetAttribute("DataLength")); cp.Data = new byte[len]; System.Threading.Thread.Sleep(200); serial.Read(cp.Data, 0, len); } return(cp); }
private void ButtonSearch_Click(object sender, RoutedEventArgs e) { if (buttonListen.Content.ToString().Equals("Start Listen")) { buttonListen.Content = "Stop Listen"; labelStatus.Content = "Listening..."; if (once) { once = false; thread = new Thread(() => { while (true) { if (th_run) { CustomProtocol cp = UART.Receive(); Register reg = cp.GetRegister(); regList.Add(reg); RegListChanged("last", null); cp = new CustomProtocol(Command.ResponseReceived); UART.Send(cp); } } }); thread.Start(); } th_run = true; } else if (buttonListen.Content.ToString().Equals("Stop Listen")) { buttonListen.Content = "Start Listen"; labelStatus.Content = "Ready!"; //CustomProtocol cp = new CustomProtocol(Command.Exit); //UART.Send(cp); th_run = false; } }
private void Button2_Click(object sender, RoutedEventArgs e) { byte[] data = byteEditor2.GetAllBytes(); if (data.Length <= 0 || data == null) { labelStatus.Content = "Insert data!"; MessageBox.Show("Please type something!", "Warning!", MessageBoxButton.OK, MessageBoxImage.Information); return; } CustomProtocol cp = new CustomProtocol(Command.SetEnginePattern, data); cp.AddAttribute("DataLength", data.Length.ToString()); cp.AddAttribute("Engine", comboBox.SelectedValue as String); UART.Send(cp); cp = UART.Receive(); if (cp.response == Response.Ok) { labelStatus.Content = "Engine " + comboBox.SelectedValue + " set!"; } }
private void Button1_Click(object sender, RoutedEventArgs e) { CustomProtocol cp = new CustomProtocol(Command.Exit); UART.Send(cp); }