« Close

Datasheets and User Guides

App Notes

Software & Driver

 

2.1.3 - Close

Closing a handle will remove the associated device connection from the LJM library, free the device to be opened again, and free allocated system resources.

Syntax

LJM_ERROR_RETURN LJM_Close(int Handle)

Parameters

Handle [in]
A device handle. The handle is a connection ID for an active device. Generate a handle with LJM_Open, or LJM_OpenS.

Returns

LJM errorcode or 0 for no error.

Remarks

LJM_Close is useful when multiple LabJack device connections are open and only a single connection needs to be closed. Use LJM_CloseAll to close every device in a single function call.

Examples

[C#] Closing one device

int LJMError;
//handle from LJM_Open()
LJMError = LabJack.LJM.Close(handle);

[C/C++] Closing one device

int LJMError;
//handle from LJM_Open()
LJMError = LJM_Close(handle);

4 comments

Does the library have functionality (low or high-level) to check handle validity and so avoid the error mentioned above?

When you say "handle validity" what is it that you are referring to? 

Once created, the handle represents a connection ID(to the device specified in the LJM_Open call), and some memory that gets allocated for that device.  The handle will remain active until LJM_Close, or LJM_CloseAll is called.  To clarify, the device's physical connection to the network, or USB port is not something that is continuously monitored by the driver.  Thus, the only way to know if the device is still accessible is to send out some form of communication, and see if there is a response.  If there is no response, the LJM driver will keep the handle there, and continue to attempt to communicate with that device so long as the specified timeout has not expired(handle healing).  Please let us know if you would like more detailed information handle healing, or device communication timeouts.

I was referring to one of the remarks:  Note that Handle must be valid in order to avoid an error.

Thanks for the description however, it clarifies things nicely.  As you rightly supposed, by interest was in determining device accessibility.  I would be interested in any further information regarding handle healing, if available.

 

For more information on the handle healing / auto reconnect functionality, see the LJM_AUTO_RECONNECT_STICKY_CONNECTION and LJM_AUTO_RECONNECT_STICKY_SERIAL configs. Basically, LJM will by default reconnect to the same device as the handle originally referred to, as determined by serial number and connection type (that is, the connection type that was used to connect to the device, rather than the ConnectionType parameter that was passed to the Open call).

If there's anything that's not answered or anything that needs the slightest bit of clarification, please let us know!