labjack / LabJackPython

The official Python modules and classes for interacting with the LabJack U3, U6, UE9 and U12
https://labjack.com/support/software/examples/ud/labjackpython
MIT License
117 stars 79 forks source link

handling multiple labjacks on the same computer #126

Closed geniusled closed 1 year ago

geniusled commented 1 year ago

Hello All, i have been using labjack more and more recently due to convenience, i own 2 (u6 usb model) of them and would like use them at the same time with different scripts doing different things.

when using the examples, it seems that only one unit at the time can be handled. when launching a second script it will cause the first one to crash.

ive tried using the openallu6 function to get the list of serial numbers in order to choose a device but as the name states it already opens the ports so i cannot only choose one .

are there any examples of listing and selecting a specific device? thanks!

sjarman28 commented 1 year ago

I do not think we have any examples in the repo that demonstrates this.

The open function has parameters that can be specified to open a device by a unique identifier. Usually you would specify either the serial number or local ID (which can be configured with the configU6 function.) You also need to specify firstFound=False or it will still automatically open the first found U6.

You can pass any parameters you want to open a device to the U6 device constructor If the input parameter autoOpen=True. It is set to True by default. Here is an example:

import u6
u6Serial1 = 360000000 # Serial number 1 here
d1 = u6.U6(firstFound=False, serial=u6Serial1)

u6Serial2 = 360000001 # Serial number 2 here
d2 = u6.U6(firstFound=False, serial=u6Serial2)
geniusled commented 1 year ago

Thank you for the return.

So i see there would be no way of enumerating the connected devices without opening the connections first? Listing the serial numbers would partially open the device, interrupting amy other scripts using it?

sjarman28 commented 1 year ago

LabJack devices such as the U6 are not set up to return the serial number in the device descriptor, you would have to temporarily open the device connection to get the serial number. You cannot do that if the connection is already claimed in another process. You can only claim a U6 USB connection in one process at a time.

There is a listAll function that will provide information about devices that do not have their connections claimed. This would not have any effect on devices that are already claimed in a process, you just would not get information about claimed devices: https://github.com/labjack/LabJackPython/blob/master/src/LabJackPython.py#L1061