private static void ValidateSendBlockResult(Response response) { if (response.Command != PrimaryResponseCommand.BlockReceived) { throw new InvalidDataException(string.Format("Expected response of {0} but received {1}.", PrimaryResponseCommand.BlockReceived, response.Command)); } var status = ProgrammingStatus.Parse(response.Data); switch (status.OperationStatus) { case ProgrammingOperationStatus.MemoryFull: throw new InvalidOperationException("The terminal's memory is full! Cannot proceed with programming."); case ProgrammingOperationStatus.TableAlreadyExists: throw new InvalidOperationException("The table already exists. If you want to replace the table, set replace=true."); case ProgrammingOperationStatus.BlockReceivedAndBeingStored: // A slower terminal might report this. Sleep to give it time to commit. Thread.Sleep(20); return; case ProgrammingOperationStatus.BlockReceivedAndStored: return; } throw new InvalidOperationException(string.Format("Unknown return status '{0}'.", (char)status.OperationStatus)); }
/// <summary> /// Returns an awaitable task that directs the terminal to terminate programming mode and proceed to the normal operation mode. /// </summary> public async Task <ProgrammingStatus> RunAsync() { var response = await _client.SendAndReceiveAsync(RequestCommand.Run, null, 3, ACK); ValidateAcknowledgment(response); // programming status info might not be present if (string.IsNullOrEmpty(response.Data)) { return(new ProgrammingStatus()); } return(ProgrammingStatus.Parse(response.Data)); }
/// <summary> /// Returns an awaitable task that directs the terminal to terminate the normal operation mode and proceed to programming mode. /// </summary> public async Task <ProgrammingStatus> HaltAsync() { var response = await _client.SendAndReceiveAsync(RequestCommand.Halt, null, 3, ACK); ValidateAcknowledgment(response); // A delay here is required, or some operations will fail. await TaskEx.Delay(200); // programming status info might not be present if (string.IsNullOrEmpty(response.Data)) { return(new ProgrammingStatus()); } return(ProgrammingStatus.Parse(response.Data)); }
/// <summary> /// Directs the terminal to terminate the normal operation mode and proceed to programming mode. /// </summary> public ProgrammingStatus Halt() { var response = _client.SendAndReceive(RequestCommand.Halt, null, 3, ACK); ValidateAcknowledgment(response); // A delay here is required, or some operations will fail. Thread.Sleep(200); // programming status info might not be present if (string.IsNullOrEmpty(response.Data)) { return(new ProgrammingStatus()); } return(ProgrammingStatus.Parse(response.Data)); }
private static void ValidateDeleteTableResult(Response response) { if (response.Command != PrimaryResponseCommand.BlockReceived) { throw new InvalidDataException(string.Format("Expected response of {0} but received {1}.", PrimaryResponseCommand.BlockReceived, response.Command)); } var status = ProgrammingStatus.Parse(response.Data); switch (status.OperationStatus) { case ProgrammingOperationStatus.BlockReceivedAndStored: case ProgrammingOperationStatus.BlockReceivedAndBeingStored: // TODO? should we do anything special for this case? return; // OK } throw new InvalidOperationException(string.Format("Unknown return status '{0}'.", (char)status.OperationStatus)); }