« Close

Datasheets and User Guides

App Notes

Software & Driver

 

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.

13 comments

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.

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.

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?

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.

I'm using U3 and Programming with VB6

How can i get the status of labjack is connect or diconnected(usb attached or unattached)?

Currently the only way to tell if a U3 is connected or not using the driver is by communicating with it.  You can send a simple command (such as reading the serial number) and see if it succeeds or not.  The same handle will stay valid when the U3 is connected.

There might be also be a way to do this directly by reading a register.  If you'd like more info on that you can email us at [email protected].

Polling is currently the only way to do this.  If you try and send any command (such as reading an analog or digital state) you will get back a LJE_DEVICE_NOT_CONNECTED (error #1015) if the LabJack is no longer connected via USB.

I am trying

 OpenLabJack (LJ_dtU3, LJ_ctUSB, "1", FALSE, &lngHandle);    (From within Labview2013 vi)

 and I get " LabJack Error #1007:  LabJack not found occured at LJUD_OpenLabJackS.vi "

I am trying to make two executables and want to have my specific device locked to the 1st instance. I do not want to use 'Firstfound = true' because I do not want my 1st Exe to take my first device but always the 2nd. (Or report error that it's missing)

Can I make a call by using the serial number reference like '320055037' ? 

 

Yes, it is noted in Section 4.2.2 that Address can be a local ID or a serial number.  The error you are getting suggests that you do not have a U3 with local ID 1, or if you do it is currently held open by some other application.

I believe there is a bug in the serial number passing through. When using the serial number of the 1st device, the FirstDetected must be TRUE. If Firstdetected=False, I get error #1007.  When connecting to the 2nd serial number, the FirstDetected must be FALSE or it takes the 1st instance again. (Never reporting error #1007)

When working with serialNumbers, I presume the 'firstdetected'-bit should be ignored.

 

Another workaround I am looking at,

I do have two U3's connected to the pc. With the ListAll option I noticed my local ID's are both '1', the trick seems to be to change this factory shipped localID to 2 -Stated in another post below-.

with LJ_ioPUT_CONFIG + LJ_chLOCALID=2, I should be able to modify this parameter. This way, I would be able to use the Local ID instead of the serial number...

Yes, that is what it is showing at the end of the section above where it is opening 2 devices with local ID 2 & 3.  All devices ship with local ID 1, which you can change use LJControlPanel or programatically as you describe (from Section 4.3.2).

We will look at open by serial number and see if we see a problem.  You should always have FirstFound=FALSE if you are wanting to open a specific device by serial number or local ID.

Thanks, LJControlpanel works fine for changing the LocalID!

Unfortunatly I have the same problem with passing a LocalID.  The Firstfound must be True when passing LocalID=1 or I get Error #1007. 

--> LJcontrolpanel pointed me that I should update UD Driver version3.35, the available update resolved the problem with LocalID=1 & Firstfound=False.

But passing the serial number still gives me #1007 Error when the 1st device has Firstfound=false.

If setting FirstFound to true works but the serial number or localID doesn't than it is probably something with the way you are passing the serial number or local ID.  When FirstFound is set to true, the other values are ignored and it opens anyone it can find.  When you pass either a localId or serial number, it will look for that specific device.  Chances are there is an issue with how the LocalID or serial number are being passed which is causing the LabJackUD library to look for a different LabJack than you are specifying.  Are you using your own VIs or one of our examples? 

If you email us at [email protected] we can help you troubleshoot this further.