Attempts to open the reader running on the COM port number provided. Port MUST support 2M baud
| 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) { |
| 506 | m_lastCommand = LastCommand::lcOpenPort; |
| 507 | closePort(); |
| 508 | |
| 509 | // Quickly force streaming to be aborted |
| 510 | m_abortStreaming = true; |
| 511 | |
| 512 | std::string versionString; |
| 513 | m_lastError = internalOpenPort(portName, enableCTSflowcontrol, true, versionString, m_comPort); |
| 514 | if (m_lastError != DiagnosticResponse::drOK) return m_lastError; |
| 515 | |
| 516 | // it's possible there's still redundant data in the buffer |
| 517 | char buffer[2]; |
| 518 | int counter = 0; |
| 519 | while (m_comPort.getBytesWaiting()) { |
| 520 | unsigned long size = m_comPort.read(buffer, 1); |
| 521 | if (size < 1) |
| 522 | if (counter++ >= 5) break; |
| 523 | } |
| 524 | |
| 525 | // Possibly a bit overkill |
| 526 | m_comPort.setBufferSizes(RAW_TRACKDATA_LENGTH_DD * 2, RAW_TRACKDATA_LENGTH_DD); |
| 527 | |
| 528 | m_version.major = versionString[1] - '0'; |
| 529 | m_version.minor = versionString[3] - '0'; |
| 530 | m_version.fullControlMod = versionString[2] == ','; |
| 531 | |
| 532 | // Check features |
| 533 | m_version.deviceFlags1 = 0; |
| 534 | m_version.deviceFlags2 = 0; |
| 535 | m_version.buildNumber = 0; |
| 536 | |
| 537 | if ((m_version.major > 1) || ((m_version.major == 1) && (m_version.minor >= 9))) { |
| 538 | m_lastError = runCommand(COMMAND_CHECK_FEATURES); |
| 539 | if (m_lastError != DiagnosticResponse::drOK) return m_lastError; |
| 540 | if (!deviceRead(&m_version.deviceFlags1, 1)) { |
| 541 | m_lastError = DiagnosticResponse::drErrorReadingVersion; |
| 542 | return m_lastError; |
| 543 | } |
| 544 | if (!deviceRead(&m_version.deviceFlags2, 1)) { |
| 545 | m_lastError = DiagnosticResponse::drErrorReadingVersion; |
| 546 | return m_lastError; |
| 547 | } |
| 548 | if (!deviceRead(&m_version.buildNumber, 1)) { |
| 549 | m_lastError = DiagnosticResponse::drErrorReadingVersion; |
| 550 | return m_lastError; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | // Switch to normal timeouts |
| 555 | applyCommTimeouts(false); |
| 556 | |
| 557 | // Ok, success |
| 558 | return m_lastError; |
| 559 | } |
| 560 | |
| 561 | // Apply and change the timeouts on the com port |
| 562 | void ArduinoInterface::applyCommTimeouts(bool shortTimeouts) { |
no test coverage detected