diff --git a/communication/communication.cpp b/communication/communication.cpp index 617f882..fb33744 100644 --- a/communication/communication.cpp +++ b/communication/communication.cpp @@ -21,7 +21,8 @@ int Communication::messageCallbackIDCounter = 1; Communication::~Communication() { if(redirectingRead) clearRedirectRead(); - close(); + if(isOpen()) + close(); } bool Communication::open() { diff --git a/device/device.cpp b/device/device.cpp index c587347..17864d1 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -78,7 +78,8 @@ bool Device::SerialStringIsNumeric(const std::string& serial) { Device::~Device() { if(isMessagePollingEnabled()) disableMessagePolling(); - close(); + if(isOpen()) + close(); } uint16_t Device::getTimestampResolution() const { diff --git a/include/icsneo/platform/windows/vcp.h b/include/icsneo/platform/windows/vcp.h index eedb736..612afb6 100644 --- a/include/icsneo/platform/windows/vcp.h +++ b/include/icsneo/platform/windows/vcp.h @@ -22,7 +22,7 @@ public: typedef void(*fn_boolCallback)(bool success); VCP(const device_eventhandler_t& err, neodevice_t& forDevice); - ~VCP() { close(); } + virtual ~VCP(); bool open() { return open(false); } void openAsync(fn_boolCallback callback); bool close(); diff --git a/platform/windows/vcp.cpp b/platform/windows/vcp.cpp index b5166bf..cc4650d 100644 --- a/platform/windows/vcp.cpp +++ b/platform/windows/vcp.cpp @@ -196,6 +196,11 @@ VCP::VCP(const device_eventhandler_t& err, neodevice_t& forDevice) : Driver(err) detail = std::make_shared(); } +VCP::~VCP() { + if(isOpen()) + close(); +} + bool VCP::IsHandleValid(neodevice_handle_t handle) { if(handle < 1) return false;