KMtronic Modbus LAN TCP/IP to Modbus RS485 RTU Serial Converter: testing MODBUS LED Display

Spread the love

 

Python examples KMtronic Modbus LAN TCP/IP to Modbus RS485 RTU Serial Converter: testing MODBUS LED Display

 

Python examples KMtronic Modbus LAN TCP/IP to Modbus RS485 RTU Serial Converter: testing MODBUS LED Display
Python examples KMtronic Modbus LAN TCP/IP to Modbus RS485 RTU Serial Converter: testing MODBUS LED Display

 

Pymodbus is a full Modbus protocol implementation using twisted for its asynchronous communications core.

 

import struct

from struct import *
from pymodbus.client.sync import ModbusTcpClient
# from pymodbus.client.sync import ModbusSerialClient as ModbusClient

import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)

// IP KMtronic Modbus LAN TCP/IP to Modbus RS485 RTU Serial Converter
host = '192.168.1.199'
port = 502

client = ModbusTcpClient(host, port)
# client = ModbusClient(method='rtu', port='/dev/ttyUSB0', timeout=1)
client.connect()


# First digital input address
address = 0
# Written value
value = 1221

# It will send '1221' to the output 
client.write_register(address, value, unit=1)

print "-----------------------------"

 

Output

kr@ubuntu-server:/var/www/html/python-test$ python ModBus-LED-Display.py
DEBUG:pymodbus.transaction:Current transaction state - IDLE
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:SEND: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x6 0x0 0x0 0x4 0xc5
DEBUG:pymodbus.client.sync:New Transaction state 'SENDING'
DEBUG:pymodbus.transaction:Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
DEBUG:pymodbus.transaction:Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
DEBUG:pymodbus.transaction:RECV: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x6 0x0 0x0 0x4 0xc5
DEBUG:pymodbus.framer.socket_framer:Processing: 0x0 0x1 0x0 0x0 0x0 0x6 0x1 0x6 0x0 0x0 0x4 0xc5
DEBUG:pymodbus.factory:Factory Response[WriteSingleRegisterResponse: 6]
DEBUG:pymodbus.transaction:Adding transaction 1
DEBUG:pymodbus.transaction:Getting transaction 1
DEBUG:pymodbus.transaction:Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
-----------------------------
kr@ubuntu-server:/var/www/html/python-test$

 

Python examples KMtronic Modbus LAN TCP/IP to Modbus RS485 RTU Serial Converter: testing MODBUS LED Display
Python examples KMtronic Modbus LAN TCP/IP to Modbus RS485 RTU Serial Converter: testing MODBUS LED Display

 

505total visits,5visits today