Attempts to open the reader running on the COM port provided (or blank for auto-detect)
| 127 | |
| 128 | // Attempts to open the reader running on the COM port provided (or blank for auto-detect) |
| 129 | GWResponse GreaseWeazleInterface::openPort(const std::string& comPort, DriveSelection drive) { |
| 130 | closePort(); |
| 131 | |
| 132 | m_motorIsEnabled = false; |
| 133 | |
| 134 | m_inHDMode = false; |
| 135 | |
| 136 | std::wstring wComPort; |
| 137 | quicka2w(comPort, wComPort); |
| 138 | |
| 139 | // Find and detect the port |
| 140 | std::wstring gwPortNumber = wComPort.length() ? wComPort : findPortNumber(); |
| 141 | |
| 142 | // If no device detected? |
| 143 | if (gwPortNumber.empty()) return GWResponse::drPortNotFound; |
| 144 | |
| 145 | switch (m_comPort.openPort(gwPortNumber)) { |
| 146 | case SerialIO::Response::rInUse:return GWResponse::drPortInUse; |
| 147 | case SerialIO::Response::rNotFound:return GWResponse::drPortNotFound; |
| 148 | case SerialIO::Response::rOK: break; |
| 149 | default: return GWResponse::drPortError; |
| 150 | } |
| 151 | |
| 152 | // Configure the port |
| 153 | SerialIO::Configuration config; |
| 154 | config.baudRate = 9600; |
| 155 | config.ctsFlowControl = false; |
| 156 | |
| 157 | if (m_comPort.configurePort(config) != SerialIO::Response::rOK) return GWResponse::drPortError; |
| 158 | |
| 159 | applyCommTimeouts(false); |
| 160 | |
| 161 | m_comPort.purgeBuffers(); |
| 162 | |
| 163 | // Lets ask GW it's firmware version |
| 164 | Ack response = Ack::Okay; |
| 165 | if (!sendCommand(Cmd::GetInfo, (unsigned char)GetInfo::Firmware, response)) { |
| 166 | m_comPort.purgeBuffers(); |
| 167 | |
| 168 | if (!sendCommand(Cmd::GetInfo, (unsigned char)GetInfo::Firmware, response)) { |
| 169 | closePort(); |
| 170 | return GWResponse::drErrorMalformedVersion; |
| 171 | } |
| 172 | }; |
| 173 | unsigned long read = m_comPort.read(&m_gwVersionInformation, sizeof(m_gwVersionInformation)); |
| 174 | if (read != 32) { |
| 175 | closePort(); |
| 176 | return GWResponse::drErrorMalformedVersion; |
| 177 | } |
| 178 | if ((m_gwVersionInformation.major == 0) && (m_gwVersionInformation.minor < 27)) { |
| 179 | closePort(); |
| 180 | return GWResponse::drOldFirmware; |
| 181 | } |
| 182 | if (m_gwVersionInformation.is_main_firmware == 0) { |
| 183 | closePort(); |
| 184 | return GWResponse::drInUpdateMode; |
| 185 | } |
| 186 |
nothing calls this directly
no test coverage detected