Skip to Navigation

4.3.1 - Open

The initial step is to open the LabJack and get a handle that the driver uses for further interaction. The DeviceType for the U3 is:

LJ_dtU3

There is only one valid ConnectionType for the U3:
LJ_ctUSB

Following is example pseudocode to open a U3 over USB:
//Open the first found LabJack U3 over USB.
OpenLabJack (LJ_dtU3, LJ_ctUSB, "1", TRUE, &lngHandle);

The reason for the quotes around the address (“1”), is because the address parameter is a string in the OpenLabJack function.

The ampersand (&) in front of lngHandle is a C notation that means we are passing the address of that variable, rather than the value of that variable. In the definition of the OpenLabJack function, the handle parameter is defined with an asterisk (*) in front, meaning that the function expects a pointer, i.e. an address.

In general, a function parameter is passed as a pointer (address) rather than a value, when the parameter might need to output something. The parameter value passed to a function in C cannot be modified in the function, but the parameter can be an address that points to a value that can be changed. Pointers are also used when passing arrays, as rather than actually passing the array, an address to the first element in the array is passed.

Talking to multiple devices from a single application is no problem. Make multiple open calls to get a handle to each device and be sure to set FirstFound=FALSE:

//Open U3s with Local ID #2 and #3.
OpenLabJack (LJ_dtU3, LJ_ctUSB, "2", FALSE, &lngHandleA);
OpenLabJack (LJ_dtU3, LJ_ctUSB, "3", FALSE, &lngHandleB);

… then when making further calls use the handle for the desired device.

tags:

Comments

#1

Is there any way to get a serial number for the specific labjack that we connect to?

For example, I have three U3s attached to a PC and they are labeled, A, B, C. Each one is wired to specific signals. I cannot guarantee that the U3s will always be connected to the same USB port or hub. During a one time configuration step, I read each U3, one at a time, and save the serial numbers of A, B and C. Then when I run my app, I can use those serial numbers to open a specific U3

Note that I have similar cards from NI from from which I can read its unique ID.

 

 

 

#2

That's easy and is mentioned in the next section (Section 4.3.2).  You use the get_config iotype with special channel LJ_chSERIAL_NUMBER.  The trickier thing, is how to open the different unknown devices.  If you do a first found open it will keep opening the first device in Window's USB list.  If you only have 1 connected at a time it is straightforward, but if all 3 are connected at the same time you need to do something different.  I would suggest you make FirstFound=FALSE, and pass Address=1 to open the device with LocalID=1.  They all ship from the factory with LocalID=1.  After you open one, change its LocalID, then reset it, and do another open with LocalID=1 to get a different U3.

#3

When I write a value to localID is that value written to some type of non-volatile memory in the U3?

Instead of writing my own value to local ID, could I rely on the serial number?

For example, if I read the serial number of each U3, and then save the SN of each device to a file:

A is SN123

B is SN567

C is SN890

Then, whenever I start my app and I want to talk to "B", could I open all the devices looking for the device that has the SN567?

 

 

 

#4

Yes, LocalID is stored in NV memory.  Yes, you can open a specific device by specifying a specific serial number, but the problem is that when you initially connect all 3 devices you do not know the serial numbers and if you repeatedly call OpenLabJack with FirstFound=TRUE it will keep giving you a handle to the same device.  That reminds me, though, that an easier solution than changing the LocalID is to use the ListAll function to get the serial numbers of everything connected.