public static void Send(CustomProtocol command) { String com = command.GetStringCommand(); serial.WriteLine(com); if (command.HasData()) { serial.Write(command.Data, 0, command.Data.Length); } }
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); }