private void HandleCommandFailure(string failure) { ET232Command failed_command = last_command; last_command = null; string command_text = Encoding.ASCII.GetString(failed_command.Format()); bool should_retry = failed_command.Retry; string details; if (should_retry) { command_retries++; if (command_retries > command_retry_limit) { command_retries = 0; should_retry = false; details = "Command abandoned"; } else { details = "Retrying command"; CommandQueue.Insert(0, failed_command); } } else { details = "Command aborted"; } ErrorCallback(this, failure, details + ": " + command_text, false); lock (_thread_interlock) _state = State.ready; }
private void TransmitCommand() { ET232Command command = null; lock (_thread_interlock) { if (CommandQueue.Count > 0) { command = CommandQueue.First(); CommandQueue.RemoveAt(0); } } if (command != null) { if (command.IsWrite()) { if (command.Address == AddressByte.Pot_A) { lock (_thread_interlock) command.Data = Governor.RegulateA(command.Data); } if (command.Address == AddressByte.Pot_B) { lock (_thread_interlock) command.Data = Governor.RegulateB(command.Data); } } byte[] data = command.Format(); last_command = command; last_command_time = UnixTime.Current(); lock (_thread_interlock) { DeviceStream.Write(data, 0, data.Length); _state = State.command; } } }