public bool sendCommand(SerialCommand cmd) { if (comPort.IsOpen) { if (cmd != null) { cmdPending.Enqueue(cmd); } } return(false); }
public void performCommandSend() { SerialCommand scomand; while (true) { if (comPortClosing) { comPortClosing = false; return; } if (pendingCommand != null) { if (pendingCommand.commandTimeout()) { pendingCommand = null; } } if (comPort != null && comPort.IsOpen && comPort.CtsHolding && pendingCommand == null) { if (cmdPending.Count > 0) { scomand = cmdPending.Dequeue(); //Console.WriteLine("IDE VEN:"+cmd); string[] command = scomand.cmd.Split(';'); if (command.Length > 0) { //; try { comPort.WriteLine(scomand.cmd); scomand.commandSend(); pendingCommand = scomand; cmdOut.Add(command[0]); } catch (TimeoutException e) { this.writeTimeOut = true; } catch (Exception e) { } } } } Thread.Sleep(100); } }
public void recieveData(string input) { inputLine += input; //Console.WriteLine("Data:"+inputLine); string[] lines = inputLine.Split( new[] { "*\r\n" }, //, "\r", "\n", "\n\r" StringSplitOptions.None ); inputLine = lines[lines.Length - 1]; if (lines.Length > 1) { var regex = new Regex(@"\[([0-9]+)\]"); for (int i = 0; i < lines.Length - 1; i++) { string l = lines[i]; string[] subPars = l.Split( new[] { "\r\n" }, //, "\r", "\n", "\n\r" StringSplitOptions.None ); Console.WriteLine("L:" + l); if (subPars[0].Length > 0) { if (regex.IsMatch(subPars[0])) { Console.WriteLine("Data:" + l); dataIn.Add(l); } else { /* if(l[l.Length-1] == '*') * {*/ if (pendingCommand != null) { if (pendingCommand.checkResponse(l)) { pendingCommand = null; } } // cmdIn.Add(); Console.WriteLine("CMD:" + l); //} } } } } processCommands(); processData(); /* * * * * if (inputLine.Contains('\n')) * { * int pos = inputLine.IndexOf('\n'); * string cmd = inputLine.Substring(0, pos); * string rest = inputLine.Substring(pos, inputLine.Length - cmd.Length-1); * inputLine = rest; * Console.WriteLine("CMD IN:"+cmd); * * }*/ }