'm using modbus_tk library to use as a Modbus RTU slave. I have an off the shelf Modbus RTU master simulator running on another PC through a usb to 485 converter. I cannot see my holding register in the Master.
I have verified that the serial link is good because I can send strings to the slave using a serial program. I have tried setting up the Master for 16 and 32 bit ints the response is always 83 04. I have tried using a few different masters with staring address of 0, this one happens to default to first register 40001. Baud rates and serial port setting match. The slave is being run on a Raspberry Pi board.
Below is the code.
import modbus_tk
import modbus_tk.defines as cst
from modbus_tk import modbus_rtu
import serial
import time
modbusServ = modbus_rtu.RtuServer(serial.Serial('/dev/ttyS0'),baudrate= 9600,
bytesize=8, parity='N', stopbits=1, xonxoff=0)
print("start")
modbusServ.start()
slave_1 = modbus_tk.modbus.Slave(1)
slave_1.add_block("BlockName", modbus_tk.defines.HOLDING_REGISTERS, 40001, 10)
aa= (1,2,3,4,5,6,7,8,9,10) # data in the register
while True:
slave_1.set_values ("BlockName", 40001, aa)
time.sleep(0.5)
import modbus_tkimport modbus_tk.defines as cst
from modbus_tk import modbus_rtu
import serial
import time
modbusServ = modbus_rtu.RtuServer(serial.Serial('/dev/ttyS0'),baudrate= 9600,
bytesize=8, parity='N', stopbits=1, xonxoff=0)
print("start")
modbusServ.start()
slave_1 = modbusServ.add_slave(1)
slave_1.add_block("BlockName", modbus_tk.defines.HOLDING_REGISTERS, 0, 10)
aa= (1,2,3,8,5,6,9,8,9,10) # data in the register
# neede to create another handle to set values
slave = modbusServ.get_slave(1)
slave.set_values ("BlockName", 0, aa)
while True:
print("Modbus Server Waiting for client querires..")
time.sleep(0.5)
--
You received this message because you are subscribed to the Google Groups "modbus-tk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modbus-tk+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modbus-tk/4EBBCB57-50A4-442D-87A5-DA2322112E55%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
four_bytes = struct.pack(‘>f', 3.14)two_registers = struct.unpack(‘>HH', four_bytes)
To view this discussion on the web visit https://groups.google.com/d/msgid/modbus-tk/CA%2BW2f75oRFWTyeJP2VXPnj2iNo-TyuF7jfmX%3Db7ap9ARccExrw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modbus-tk/416E5487-7387-41BF-8C14-FAFFBA1C6060%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
slave add_block("ReadBlock", define HOLDING_REGISTERS, 11, 10)create a 2 register variable
slave.set_values("ReadBlock", 11, 2, values)
To view this discussion on the web visit https://groups.google.com/d/msgid/modbus-tk/CA%2BW2f772eOQq360KvLRpRSgD0E1Z-8E_ta_-Jro94DgYsiDtxg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modbus-tk/B951B580-6259-41CC-9485-C130A7C334AB%40gmail.com.