Skip to main content
Skip table of contents

Opening and Closing [LJM User's Guide]

Open a LabJack device to communicate with it. Close it to allow other processes to open it.

Subsections

Opening

Either LJM_Open or LJM_OpenS must be used to open a LabJack. The LJM_Open and LJM_OpenS functions will detect a LabJack connected to the computer, and create a device handle. The device handle is then passed as an input to other functions.

  • LJM_Open - Open a device based on integer filter parameters.

  • LJM_OpenS - Open a device based on string filter parameters.

Use whichever is more convenient for you.

Use the Identifier parameter to open a specific device

The Identifier parameter of LJM_Open and LJM_OpenS optionally selects which device to open by serial number, IP address, or customizable device name. See Identifier Parameter for information.

USB connections are preferred

If ConnectionType is equal to LJM_ctANY (0), LJM_Open will attempt to open a USB connection before trying to open a TCP connection.

Device connections are claimed

Once a LabJack device connection is opened, other processes will not be able to open that same device using the same connection resources until the device connection is closed by using LJM_Close or LJM_CloseAll. One notable exception is when using Ethernet UDP. UDP is connectionless and does not claim any connection resources, so any number of devices could control the LabJack via Ethernet UDP. Also note that some LabJack devices support multiple simultaneous TCP connections. See the Ethernet section of the T-series datasheet for more information. For device sharing recommendations see Sharing a particular device among multiple processes or computers.

Subsequent calls may return the same handle

Once a device is opened, subsequent calls to LJM_Open/LJM_OpenS will return the handle to that device if the DeviceType, ConnectionType, and Identifier parameters describe that device. In this case, calling LJM_Open or LJM_OpenS is nearly instant because no device communication occurs. For example:

LJM_Open(LJM_dtANY, LJM_ctANY, LJM_idANY, ...) // If this returns a handle to a T7, with serial number 470010729, connected via USB...

LJM_Open(LJM_dtT7, LJM_ctUSB, "470010729", ...) // ...then this would return the same handle, without opening a new device connection

...and these would attempt to open a new device connection and return a different handle:

LJM_Open(LJM_dtANY, LJM_ctANY, "470010999", ...) // Different serial number

LJM_Open(LJM_dtANY, LJM_ctETHERNET, "470010729", ...) // Different connection type

Devices like the T7 may have multiple device connections at once. The following calls would each return a different device handle:

LJM_Open(LJM_dtT7, LJM_ctUSB, "470010729", ...)

LJM_Open(LJM_dtT7, LJM_ctETHERNET, "470010729", ...)

LJM_Open(LJM_dtT7, LJM_ctWIFI, "470010729", ...)

Reconnection is automatic

If LJM detects a broken connection, it will automatically attempt to reconnect. If the reconnect is unsuccessful, LJM will return the errorcode LJME_RECONNECT_FAILED. When this happens, many applications can simply retry calling the function that returned LJME_RECONNECT_FAILED with the same parameters. For more details, see the reconnection page.

Using an IP Address as the Identifier parameter is efficient

In order to open a TCP device with a specific serial number or name, LJM will communicate with all LabJack devices on the network, asking each for their serial number or name. In contrast, opening a TCP LabJack device by IP address will only send packets to that IP address, which is faster and more efficient. Setting up static IP addresses can be troublesome, so use what is appropriate for you application.

Specific IPs will be checked

Specific IP addresses may be defined, which LJM will try to open during every Ethernet- or WiFi-based Open or ListAll call.

Closing

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

  • LJM_Close - Close a specific device connection, based on the handle number.

  • LJM_CloseAll - Close any/all open device connections.

Devices are closed automatically when LJM is unloaded

When the LJM library (.dll, .dylib, or .so) is unloaded, it will automatically close all devices.

Device Not Found?

If a device isn't properly being found, some important debugging information can be found in our Device Not Found? App Note. If a network connection needs to be debugged, read through our Setup WiFi and Ethernet App Note as well.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.