Attempts to verify if the reader/writer is running on this port
| 447 | |
| 448 | // Attempts to verify if the reader/writer is running on this port |
| 449 | DiagnosticResponse ArduinoInterface::internalOpenPort(const std::wstring& portName, bool enableCTSflowcontrol, bool triggerReset, std::string& versionString, SerialIO& port) { |
| 450 | switch (port.openPort(portName)) { |
| 451 | case SerialIO::Response::rInUse:return DiagnosticResponse::drPortInUse; |
| 452 | case SerialIO::Response::rNotFound:return DiagnosticResponse::drPortNotFound; |
| 453 | case SerialIO::Response::rOK: break; |
| 454 | default: return DiagnosticResponse::drPortError; |
| 455 | } |
| 456 | |
| 457 | // Configure the port |
| 458 | SerialIO::Configuration config; |
| 459 | config.baudRate = 2000000; |
| 460 | config.ctsFlowControl = enableCTSflowcontrol; |
| 461 | |
| 462 | if (port.configurePort(config) != SerialIO::Response::rOK) |
| 463 | { |
| 464 | port.closePort(); |
| 465 | return DiagnosticResponse::drPortError; |
| 466 | } |
| 467 | |
| 468 | port.setBufferSizes(16, 16); |
| 469 | port.setReadTimeouts(10, 250); |
| 470 | port.setWriteTimeouts(2000, 200); |
| 471 | |
| 472 | // Try to get the version |
| 473 | DiagnosticResponse response = attemptToSync(versionString, port); |
| 474 | if (response != DiagnosticResponse::drOK) { |
| 475 | // It failed. Issue a reset if we're allowed and try again |
| 476 | if (triggerReset) { |
| 477 | port.setDTR(false); |
| 478 | port.setRTS(false); |
| 479 | std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 480 | port.setDTR(true); |
| 481 | port.setRTS(true); |
| 482 | std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 483 | port.closePort(); |
| 484 | std::this_thread::sleep_for(std::chrono::milliseconds(150)); |
| 485 | |
| 486 | // Now re-connect and try again |
| 487 | if (port.openPort(portName) != SerialIO::Response::rOK) return DiagnosticResponse::drPortError; |
| 488 | |
| 489 | response = attemptToSync(versionString, port); |
| 490 | if (response != DiagnosticResponse::drOK) { |
| 491 | port.closePort(); |
| 492 | return response; |
| 493 | } |
| 494 | } |
| 495 | else { |
| 496 | port.closePort(); |
| 497 | return response; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | return response; |
| 502 | } |
| 503 | |
| 504 | // Attempts to open the reader running on the COM port number provided. Port MUST support 2M baud |
| 505 | DiagnosticResponse ArduinoInterface::openPort(const std::wstring& portName, bool enableCTSflowcontrol) { |
nothing calls this directly
no test coverage detected