Skip to content

Commit

Permalink
CInterface: add Close function
Browse files Browse the repository at this point in the history
  • Loading branch information
willeccles committed Nov 14, 2024
1 parent e3a2b35 commit 984be6f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/bci/abs/CInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ int AbsScpiClient_OpenSerial(AbsScpiClientHandle handle, const char* com_port,
int AbsScpiClient_OpenUdpMulticast(AbsScpiClientHandle handle,
const char* interface_ip);

/**
* @brief Close the client connection.
*
* @param[in] handle SCPI client
*
* @return 0 on success or a negative error code.
*/
int AbsScpiClient_Close(AbsScpiClientHandle handle);

/**
* @brief Set the target device ID for communication. Only applies to RS-485
* connections.
Expand Down
14 changes: 14 additions & 0 deletions src/CInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,20 @@ int AbsScpiClient_OpenUdpMulticast(AbsScpiClientHandle handle,
return static_cast<int>(ec::kUnexpectedException);
}

int AbsScpiClient_Close(AbsScpiClientHandle handle) try {
if (!handle) {
return static_cast<int>(ec::kInvalidArgument);
}

GetClient(handle).SetDriver(nullptr);

return static_cast<int>(ec::kSuccess);
} catch (const std::bad_alloc&) {
return static_cast<int>(ec::kAllocationFailed);
} catch (...) {
return static_cast<int>(ec::kUnexpectedException);
}

int AbsScpiClient_SetTargetDeviceId(AbsScpiClientHandle handle,
unsigned int device_id) try {
if (!handle) {
Expand Down

0 comments on commit 984be6f

Please sign in to comment.