« Close

Datasheets and User Guides

App Notes

Software & Driver

 

LJSocket (Experimental)

LJSocket provides a socket interface to a USB LabJack. It’s one of many ways to communicate with a USB LabJack over Ethernet or WiFi. Using LJSocket, anything that you could write to a LabJack over USB, you can now write over a TCP socket. This allows, for example, to send Modbus TCP packets to a U3 or U6. (The UE9 natively supports Modbus TCP over its Ethernet interface.)

Even without using Modbus, LJSocket is useful because a socket interface is easier than a USB interface. Any software or programming language that can communicate using sockets (e.g., LabVIEW or Python) can communicate with a LabJack without any drivers or knowledge about USB.

Because it uses TCP sockets, network transparency is built into LJSocket. You can plug a LabJack into a remote computer and access it from another.

In this picture, a Chumby is running LJSocket, and making the U3 available over the WiFi network.

LabJack U3 connected to Chumby

The source code for LJSocket is available on GitHub. If you use Windows there is an executable attached to the bottom of this page.

If you use Python to talk to LJSocket, start LJSocket on one computer (IP address 192.168.1.2 in this example) connect a U3, and on another computer on the local network, run this code:

  
>>> import u3
>>> d = u3.U3(LJSocket = "192.168.1.2:6000")
>>> d.configU3()

and it would be just like your U3 was connected locally.

Requirements

  • A U3, U6, or UE9 over USB with the latest firmware. At minimum for Modbus support, the U3 requires firmware 1.26; the U6 requires firmware 1.15; and the UE9 requires Control firmware 2.13 and Comm firmware 1.5.
  • On Windows, the LabJackUD library. On Linux and Mac OS X, the Exodriver.
  • On Windows, you have the option to run LJSocket as a Windows service. This is further discussed in the "Running LJSocket as a Windows Service" section.
  • On Windows, Mac OS X and Linux, to run the LJSocket source code in Python, you will need the following Python software installed: Python 2.6 or 2.7, LabJackPython release 5-26-2015 or older, and Twisted. To run LJSocket, refer to the LJSocket source code's README file or the "Running LJSocket on Ubuntu 10.04" section

Running LJSocket as a Windows Service

Download the Double-clickable LJSocket executable for Windows and extract the ZIP file. Inside you’ll find four icons:

Open the installLJSocket.bat program to install LJSocket as a service. For Windows Vista and 7 users, open the installLJSocket.bat program as administrator. The program will start LJSocket and will configure it to start automatically after a reboot. To manually start and stop the LJSocket, use the Control Panel > Administrative Tools > Services application:

Here’s how to find the Services application. (It took me a few tries.)

Modbus port

The LJSocket source code defines the MODBUS_PORT in LJSocket.py (near the top) as 502x so that it can be run on Linux and Mac OS X without administrator privileges. So for a single device, the port number will typically be 5021.

SCADA applications

ScadaMobile Lite

We have successfully connected LJSocket with ScadaMobile Lite for the iPhone. Here is a screenshot viewing the state of FIO6 on a U3:

Here is the CSV file loaded to ScadaMobile Lite to configure the application to connect to FIO6:

  
FIO6,INT,HR6007,"ord:=412; section:=""INT HOLDING REGISTER"" ; write_access=9;"

Reading carefully, note that the CSV file defines holding register 6007 (HR6007). From the LabJack Modbus map the digital I/O states start at Modbus port 6000, so FIO6 is at 6006. ScadaMobile Lite starts numbering at 1 instead of 0, so the CSV file adds one to get 6007.

Wonderware

We have also had a report from a customer that Wonderware can be made to work, but it requires some configuration. To read a float from AIN0 on a U3-HV, the customer read register 40001. The LabJack Modbus map states the address should be 0. The 40000 is to tell Wonderware to read a holding register. The 1 is the same off-by-one problem as ScadaMobile Lite. Also, the response from LJSocket is a float in big-endian format; Wonderware expects little-endian bytes by default.

Mango

Based on a customer suggestion we also successfully connected Mango to LJSocket. In our brief experience with Mango, it was easy to setup and the most flexible in terms of Modbus TCP options. Here is a screenshot configuring LJSocket as a data source:

Note how we set the host and port (192.168.1.103 and 5020 on Mac OS X) to where LJSocket is running. After defining LJSocket (“My U3”) as the data source, we add two data points. AIN0 is a holding register, with 4-byte float as its Modbus data type, and an offset of 0. It is not settable. As shown in the screenshot above, FIO6 is a holding register, with 2-byte signed integer as its Modbus data type, and an offset of 6006. (In a moment of rare SCADA-software sanity, the offset is zero-based.) It is settable.

After defining the data points, activate them and collect data. Below is a screenshot of AIN0 floating (unconnected to a signal), then briefly connected to VS (5 V) and GND (0 V):

DAQFactory

AzeoTech’s free QuickMod application can also connect to LJSocket and collect data. QuickMod users with a DAQFactory license can further customize its behavior.

Launch QuickMod, select “Modbus TCP over Ethernet”, and click “Configure”. Add LJSocket’s IP address and port in the dialog box as shown in this example:

To read AIN0, change ID 1’s Type to “Float” and set “# pts” to 1. Leave the Function as “Holding Register” and the “Tag #” at 0. The value of AIN0 will show in the list and plot below:

In our experience, QuickMod sets the current record for “shortest time from download to looking at data” via LJSocket.

ModScan32

A customer in our forum has tried this software with the UE9. As we noted in the forum topic, the software has a one-based offset instead of a zero-based offset, so subtract 1 from the address to read.

Modbus Doctor

We were able to get Modbus Doctor to work with a UE9. As we describe in the forum post, we needed to check the “swap words” checkbox.

Running LJSocket on Ubuntu 10.04

LJSocket requires LabJackPython and the Exodriver on Linux systems. We posted a short write-up on how to install them on 5/7/2010 titled Up and running with LabJackPython and the Exodriver on Ubuntu 10.04. Once you have verified that those steps succeeded and you can open your LabJack in Python, installing LJSocket is easy.

LJSocket depends on Twisted, so install it using apt; then checkout the LJSocket code and run it:

  
sudo apt-get install python-twisted
git clone git://github.com/labjack/LJSocket.git
cd LJSocket/
twistd -ny ljsocketServiceTac.py 
 

To verify that it worked, plug in a LabJack, open a new terminal window, and start a Python session:

  
python
>>> import u3
>>> d = u3.U3(LJSocket = "localhost:6000")
>>> d.configU3()
 

This Python code opens the U3 over a TCP/IP socket, not its USB interface. Run this code on another computer on the same network (and substitute the Ubuntu computer’s IP address for “localhost”) to utilize LJSocket’s network transparency.

3 comments

How do you forward port 6000 through SSH tunnel? Here's my command :-

ssh remote-server -R60001:localhost:6000

While on the remote-server, here's what I did to connect :-

d = u3.U3( LJSocket = 'localhost:60001' )

but it didn't work. Here's the error output :-

 

>>> d = u3.U3( LJSocket = 'localhost:60001' )

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/usr/lib/python2.5/site-packages/u3.py", line 81, in __init__

    self.open(**kargs)

  File "/usr/lib/python2.5/site-packages/u3.py", line 116, in open

    Device.open(self, 3, firstFound = firstFound, serial = serial, localId = localId, devNumber = devNumber, handleOnly = handleOnly, LJSocket = LJSocket )

  File "/usr/lib/python2.5/site-packages/LabJackPython.py", line 572, in open

    d = openLabJack(devType, ct, handleOnly = handleOnly, LJSocket = LJSocket)

  File "/usr/lib/python2.5/site-packages/LabJackPython.py", line 1395, in openLabJack

    handle = _openLabJackUsingLJSocket(deviceType, firstFound, pAddress, LJSocket, handleOnly )

  File "/usr/lib/python2.5/site-packages/LabJackPython.py", line 1225, in _openLabJackUsingLJSocket

    handle = LJSocketHandle(ip, port, deviceType, firstFound, pAddress)

  File "/usr/lib/python2.5/site-packages/LabJackPython.py", line 2841, in __init__

    raise LabJackException(ec = LJE_LABJACK_NOT_FOUND, errorString = "Couldn't connect to a LabJack at %s:%s. The error was: %s" % (ipAddress, port, str(e)))

LabJackPython.LabJackException: Couldn't connect to a LabJack at localhost:60001. The error was: (111, 'Connection refused')

 

 

Please see our answer in the LabJack Forums.

Hi,

I am tring to use LJSocket with U3 and I want to use the socket programming with C#. Is this possible. I have little knowledge on sockets. Can you please give me sample code to achieve this. I want to read and write digital I/O.