Hobbyist Toolkit

cancel
Showing results for 
Search instead for 
Did you mean: 

Linx & Raspberry Pi USB ports

Hi

I was wondering if Linx has the ability to utilise the USB ports on the Raspberry pi? I have had a play with Linx in LV2020 but didn't spot the vi or vis for communicating with devices via the pi usb ports - perhaps i missed it. We have previously used a labjack u6 coupled to a pi to log data using python scripts. Any examples or suggestions would be welcomed. Thanks

0 Kudos
Message 1 of 7
(4,189 Views)

Linx does not support USB at this time. And it will be not easy to add that.

 

USB is not a protocol but only really the lowest level of an interface definition and on top of that you have many device class types that all have their own protocol. If the USB device installs as Virtual Comm Port device then it will be picked up by the OS as a serial device and consequently also accessible in VISA as a serial port. Otherwise things get a lot more complicated. Basically you would have to interface to the libusb.so shared library using Call Library Nodes and implement the USB protocol on top of that. Unless you are intimately familiar with the device in question, that is very time intense and difficult process.

 

Even if someone does create the libusb bindings for LabVIEW (and I believe there have been several usually abandoned attempts for that), it's just the first step when wanting to communicate with USB devices. After that you have to implement the device class specific protocol on top of those bindings. For official device classes in the USB standard, that can vary from a small library of maybe 10 to 20 VIs for a simple device class, to a library of several 100 very complicated VIs for some device classes. And that only works if you have the full protocol specification. If it is a proprietary protocol it is usually almost impossible to get the necessary specifications without signing some heavy NDA.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 7
(4,144 Views)

Thanks Rolf for your insight on USB and Linx.

0 Kudos
Message 3 of 7
(4,121 Views)

@Diatom wrote:

We have previously used a labjack u6 coupled to a pi to log data using python scripts.


Since you already have a Python script that talks to your device on a Pi, you could modify the script and make it pass data to LabVIEW instead.

 

Anyway, do you know what communications protocol was used by the Python scripts? As Rolf said, USB comms is very low-level so I doubt that the Python scripts performed USB communications directly. Instead, I suspect that the Python scripts talk a higher-level protocol, and a separate driver converts the higher-level protocol to USB. For example, LabJack supports Modbus over USB (see https://labjack.com/support/software/api/modbus/ud-modbus) and Python/LabVIEW can talk Modbus quite easily.

 

There is one more challenge, however: LabVIEW for Linux LINX targets runs inside a "chroot jail" (see https://unix.stackexchange.com/questions/105/chroot-jail-what-is-it-and-how-do-i-use-it ) This effectively isolates LabVIEW from large chunks of the Raspberry Pi's system so you might also need to find a way to make your script or drivers accessible from inside the chroot jail.

Certified LabVIEW Developer
0 Kudos
Message 4 of 7
(4,115 Views)

Well LabJack uses a custom USB protocol for their devices. But they do provide the source code to their low level ExoDriver on their github account https://github.com/labjack/exodriver

 

It's most likely what was used to create a shared library (recompilation for the Pi is mandatory as you can't install an x86 desktop Linux precompiled shared lib on it) that your Python script then referenced, either directly or through a Python library providing higher level convinience functions on top of this ExoDriver.

 

It's absolutely possible to call this shared library from LabVIEW too through the Call Library Node and implement a similar VI library on top of it that implements equal functionality as your Python script. But it is some serious work if you want to do it in a nice way and not just a quick and dirty hack that only works when you touch your left ear with your right hand, and stand on one foot at the same time 😀

 

Getting the labjack exodriver to work even in the chroot environment shouldn't be very hard actually. It interfaces to libusb but I'm pretty sure that this can be installed from the opkg repository if it isn't already present by default.

 

And indeed, from inside the chroot (after entering it with "sudo schroot --run-session -c lv" on the Pi command line) you can install it:

 

opkg update
opkg install libusb-1.0-0

And if you want the development bits (required to compile the labjack driver):

opkg install libusb-1.0-dev

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 7
(4,087 Views)

Hi, 

Here is  link to a forum post that details how to install the driver on a Raspberry PI 3.  You would need to install the driver in the chroot.

 

https://labjack.com/forums/u6/labjack-u6-and-raspberry-pi-3-model-b-interaface

0 Kudos
Message 6 of 7
(4,067 Views)

There is the source code for a Windows LabVIEW driver here

 

https://labjack.com/support/software/examples/ud/labview

 

It calls the driver dll.  It could be changed to use the library on the Raspberry PI.

0 Kudos
Message 7 of 7
(4,062 Views)