« Close

Datasheets and User Guides

App Notes

Software & Driver

 

Python

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()

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.



T7 & T4 Test Registers

Test Registers

Name Start Address Type Access Default
TEST 55100 UINT32 R 1122867
TEST_UINT16 55110 UINT16 R/W 17
TEST_UINT32 55120 UINT32 R/W 1122867
TEST_INT32 55122 INT32 R/W -2003195205
TEST_FLOAT32 55124 FLOAT32 R/W -9999.0

TEST

A read of this test register should always return 0x00112233 or d1122867. If your software has the word swap quirk, you will incorrectly read 0x22330011 or 573767697. If your software has the address-1 quirk, a UINT16 (1-register) read from 55101 will incorrectly return 0x0011 (should read 0x2233).

TEST_UINT16

Write a value and read back to test UINT16 operation. Default is 0x0011 or d17.

TEST_UINT32

Write a value and read back to test UINT32 operation. Default is 0x00112233 or d1122867. If your software has the word swap quirk, the default will incorrectly read 0x22330011 or 573767697.

TEST_INT32

Write a value and read back to test INT32 operation. Default is 0x8899AABB or d-2003195205. If your software has the word swap quirk, the default will incorrectly read 0xAABB8899 or -1430550375.

TEST_FLOAT32

Write a value and read back to test FLOAT32 operation. Default is 0xC61C3C00 or -9999.0. If your software has the word swap quirk, the default will incorrectly read 0x3C00C61C or 0.00786.

The File Attachment (.zip file) below also has a .vi that reads AIN0, AIN1, and AIN2 for convenience

AIN0

Other known Modbus TCP libraries, not tested