From 65a6fadd1dbead5903a72c76264c48140ace4693 Mon Sep 17 00:00:00 2001 From: Paul Hollinsky Date: Tue, 27 Apr 2021 21:07:36 -0400 Subject: [PATCH] Device: Pull out communication close on open error We don't want to close before calling the extension hooks. --- device/device.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/device/device.cpp b/device/device.cpp index 2bed917..9142ed7 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -184,11 +184,13 @@ bool Device::open() { return true; }); if(!tryAgain) { + com->close(); report(attemptErr, APIEvent::Severity::Error); return false; // Extensions couldn't save us } attemptErr = attemptToBeginCommunication(); if(attemptErr != APIEvent::Type::NoErrorFound) { + com->close(); report(attemptErr, APIEvent::Severity::Error); return false; } @@ -267,7 +269,6 @@ APIEvent::Type Device::attemptToBeginCommunication() { if(!afterCommunicationOpen()) { // 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. - com->close(); // "Communication could not be established with the device. Perhaps it is not powered with 12 volts?" return APIEvent::Type::NoSerialNumber; } @@ -279,18 +280,12 @@ APIEvent::Type Device::attemptToBeginCommunication() { if(i++ > 5) break; } - if(!serial) { - com->close(); - // "Communication could not be established with the device. Perhaps it is not powered with 12 volts?" + if(!serial) // "Communication could not be established with the device. Perhaps it is not powered with 12 volts?" return APIEvent::Type::NoSerialNumber; - } std::string currentSerial = getNeoDevice().serial; - if(currentSerial != serial->deviceSerial) { - com->close(); + if(currentSerial != serial->deviceSerial) return APIEvent::Type::IncorrectSerialNumber; - } - return APIEvent::Type::NoErrorFound; }