Python Modbus TCP
There are several Modbus TCP/UDP libraries available for python that have various dependencies. Below are a few that are worth trying.
PYMODBUS
Pymodbus is a library released under the BSD License that has been tested to be working with our Modbus TCP compatable devices. The project has some decent documentation and is capable of both Modbus TCP and Modbus UDP requests. It also has the capability of being called synchronously or asynchronously.
Included below is a code snippet for reading from AIN0.
#Import Files
from convert_data import *
from pymodbus.client.sync import ModbusTcpClient
#Open TCP Port
client = ModbusTcpClient('192.168.1.15')
#Read AIN0
result = client.read_input_registers(0,2)
print 'AIN0 val:', data_to_float32(result.registers)
#Close TCP Port
client.close()
Files
The File Attachment (.zip file) below includes 3 files:
convert_data.py: which is an example of how to convert data types in python
read_ain0.py: which is also displayed above. Register AIN0 is described below.
t7_test.py: which demonstrates using convert_data.py to read and write to all of the T7 or T4's Test registers described below.
Please note that you need to perform several steps to install this python library described on their websites. These examples won't run until you do.
LabJack_pymodbus_examples_2017_07_05.zip
Getting Started with Direct Modbus TCP
See the information and getting started guide in our Direct Modbus TCP documentation.