Device: Pull out communication close on open error

We don't want to close before calling the extension hooks.
pull/35/head
Paul Hollinsky 2021-04-27 21:07:36 -04:00
parent 8e2883bca9
commit 65a6fadd1d
1 changed files with 4 additions and 9 deletions

View File

@ -184,11 +184,13 @@ bool Device::open() {
return true; return true;
}); });
if(!tryAgain) { if(!tryAgain) {
com->close();
report(attemptErr, APIEvent::Severity::Error); report(attemptErr, APIEvent::Severity::Error);
return false; // Extensions couldn't save us return false; // Extensions couldn't save us
} }
attemptErr = attemptToBeginCommunication(); attemptErr = attemptToBeginCommunication();
if(attemptErr != APIEvent::Type::NoErrorFound) { if(attemptErr != APIEvent::Type::NoErrorFound) {
com->close();
report(attemptErr, APIEvent::Severity::Error); report(attemptErr, APIEvent::Severity::Error);
return false; return false;
} }
@ -267,7 +269,6 @@ APIEvent::Type Device::attemptToBeginCommunication() {
if(!afterCommunicationOpen()) { if(!afterCommunicationOpen()) {
// Very unlikely, at the time of writing this only fails if rawWrite does. // Very unlikely, at the time of writing this only fails if rawWrite does.
// If you're looking for this error, you're probably looking for if(!serial) below. // If you're looking for this error, you're probably looking for if(!serial) below.
com->close();
// "Communication could not be established with the device. Perhaps it is not powered with 12 volts?" // "Communication could not be established with the device. Perhaps it is not powered with 12 volts?"
return APIEvent::Type::NoSerialNumber; return APIEvent::Type::NoSerialNumber;
} }
@ -279,18 +280,12 @@ APIEvent::Type Device::attemptToBeginCommunication() {
if(i++ > 5) if(i++ > 5)
break; break;
} }
if(!serial) { if(!serial) // "Communication could not be established with the device. Perhaps it is not powered with 12 volts?"
com->close();
// "Communication could not be established with the device. Perhaps it is not powered with 12 volts?"
return APIEvent::Type::NoSerialNumber; return APIEvent::Type::NoSerialNumber;
}
std::string currentSerial = getNeoDevice().serial; std::string currentSerial = getNeoDevice().serial;
if(currentSerial != serial->deviceSerial) { if(currentSerial != serial->deviceSerial)
com->close();
return APIEvent::Type::IncorrectSerialNumber; return APIEvent::Type::IncorrectSerialNumber;
}
return APIEvent::Type::NoErrorFound; return APIEvent::Type::NoErrorFound;
} }