Skip to Navigation

4.2.2 - OpenLabJack()

Call OpenLabJack() before communicating with a device. This function can be called multiple times, however, once a LabJack is open, it remains open until your application ends (or the DLL is unloaded). If OpenLabJack is called repeatedly with the same parameters, thus requesting the same type of connection to the same LabJack, the driver will simply return the same LJ_HANDLE every time. Internally, nothing else happens. This includes when the device is reset, or disconnected. Once the device is reconnected, the driver will maintain the same handle. If an open call is made for USB, and then Ethernet, a different handle will be returned for each connection type and both connections will be open.

OpenLabJackS() is a special version of open where DeviceType and ConnectionType are strings rather than longs. This is useful for passing string constants in languages that cannot include the header file. The strings should contain the constant name as indicated in the header file (such as “LJ_dtU3” and ”LJ_ctUSB”). The declaration for the S version of open is the same as below except for (const char *pDeviceType, const char *pConnectionType, …).

Declaration:


LJ_ERROR _stdcall OpenLabJack (  long DeviceType,
                                 long ConnectionType,
                                 const char *pAddress,
                                 long FirstFound,
                                 LJ_HANDLE *pHandle)

Parameter Description:
Returns: LabJack errorcodes or 0 for no error.
Inputs:

  • DeviceType – The type of LabJack to open. Constants are in the labjackud.h file.
  • ConnectionType – Enter the constant for the type of connection. USB only for the U3.
  • pAddress – Pass the local ID or serial number of the desired LabJack. If FirstFound is true, Address is ignored.
  • FirstFound – If true, then the Address and ConnectionType parameters are ignored and the driver opens the first LabJack found with the specified DeviceType. Generally only recommended when a single LabJack is connected.

Outputs:

  • pHandle – A pointer to a handle for a LabJack.
tags:

Comments

#1

Hi

I saw a close() function in the library but I don't now the function inputs or how to make it work, can you help me?

#2

The close() function is called without any inputs or return values, simply:

close();

It will destroy/release all the handles to all devices when called.  Basically, it will put the driver back into the state of when the program was first loaded.  Thus, you will have to reopen a device before further communicating with it.

#3

Is there a CloseLabJack() method?  I can't see it in the list.  I have accidentally called OpenLabJack in a loop and nothing bad happened.

#4

There is a function that is defined as:

Close()

Which will close all open devices/handles and reset the driver to a fresh state.  It's undocumented because it shouldn't be needed.  As you've shown, the open call can be called repeatedly and will return the LJHandle to the already open device.  Once a device is opened that handle should always be valid (as long as the device is connected).

 

#5

We find that we can't use the labjack software without closing all of LabView. Will the use of the close() function allow this?Also as a point of clarification, what variables does close() use?  

#6

Because of how Windows controls handles for USB devices using the WinUSB driver, only one program can have one of those USB devices open for communicating at a time.  That is why LabView must be closed before another application can speak to the device.  The same would be true for any two programs (or even two copies of the same program).

The close function should allow you to get around that, but it shouldn't be necessary.

Generally, if you need more than one application to communicate with the LabJack, we recommend that you create a 3rd program that handles all the communication (and is always open) and then have the other two programs communicate with that one to pass data back and forth.

You don't need to pass anything to the close() function.

#7

I believe that there is a typo in the documentation: "pHandle – A pointer to a handle for a LabJack" should be listed in the Outputs section instead of the Inputs section because this handle is the result of the OpenLabJack call. I guess pHandle got listed in the Inputs section because memory should be pre-allocated for this pointer before the OpenLabJack call?

#8

It was actually in the textile source, but was not rendering properly on the web page.  Fixed now.

#9

If you are adding more than 1 Labjack, can you do that. If you can how would the function call for OpenLabJack would look.

#10

You make 1 call for each device to get a handle for each device.  See Section 4.3.1.