-
Notifications
You must be signed in to change notification settings - Fork 986
Virtual Slave Modbus RTU #2649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
slaves cannot have id=0 that is reserved for broadcast. Apart from that the code looks ok, after just a short glance. As you can see in our examples the sequential data block is tested with the value 17 (more details in the test harness) so I am not sure why you get zeroes back, did you try with just one slave? |
Thanks for the note! Just to clarify, I'm not actually using slave id=0—that’s what’s puzzling me. I also tried running the test with just a single slave, but I'm still getting all zeroes in return. I’ll double-check again in case I missed something subtle, but at this point it seems like there might be something else going on. Appreciate any further suggestions you might have! |
if you look at the examples: server_async.py, you will find it defines a sequential datastore that contains
and in client_async.py you will find:
so you see there are examples that controls that data get back, these examples are run as part of every pull request (with a single slave), so I am quite sure that works. your code contains |
Did you solve your problem? |
Yes, I solved it, thank a lot My final code: from pymodbus.server import StartSerialServer import logging def run_single_port_multi_slave_server():
if name == "main": |
I'm trying to simulate a Modbus RTU slave through a COM port using a USB/RS485 converter. The problem is that the slave only sends zeros instead of the simulated data.
**# Code
from pymodbus.server import StartSerialServer
from pymodbus.datastore import ModbusSequentialDataBlock, ModbusSlaveContext, ModbusServerContext
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
def run_single_port_multi_slave_server():
slaves = {}
for i in range(0, 17): # Crear 16 esclavos con IDs del 1 al 16
slave_id = i
# Inicializar los registros 40001-40008 para cada esclavo
initial_values = [slave_id * 10 + j for j in range(10)]
store = ModbusSlaveContext(
hr=ModbusSequentialDataBlock(0, initial_values)
)
slaves[slave_id] = store
if name == "main":
run_single_port_multi_slave_server()**
Output:
DEBUG:asyncio:Using proactor: IocpProactor
DEBUG:pymodbus.logging:Awaiting connections server_listener
INFO:pymodbus.logging:Server listening.
DEBUG:pymodbus.logging:Connected to server
DEBUG:pymodbus.logging:recv: 0x1 0x3 0x0 0x0 0x0 0x8 0x44 0xc old_data: addr=None
DEBUG:pymodbus.logging:Processing: 0x1 0x3 0x0 0x0 0x0 0x8 0x44 0xc
DEBUG:pymodbus.logging:decoded PDU function_code(3 sub -1) -> ReadHoldingRegistersRequest(dev_id=0, transaction_id=0, address=0, count=8, bits=[], registers=[], status=1)
DEBUG:pymodbus.logging:Frame advanced, resetting header!!
DEBUG:pymodbus.logging:getValues: fc-[3] address-1: count-8
DEBUG:pymodbus.logging:send: 0x1 0x3 0x10 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0xe4 0x59
DEBUG:pymodbus.logging:recv: 0x2 0x3 0x0 0x0 0x0 0x8 0x44 0x3f old_data: addr=None
DEBUG:pymodbus.logging:Processing: 0x2 0x3 0x0 0x0 0x0 0x8 0x44 0x3f
DEBUG:pymodbus.logging:decoded PDU function_code(3 sub -1) -> ReadHoldingRegistersRequest(dev_id=0, transaction_id=0, address=0, count=8, bits=[], registers=[], status=1)
DEBUG:pymodbus.logging:Frame advanced, resetting header!!
DEBUG:pymodbus.logging:getValues: fc-[3] address-1: count-8
DEBUG:pymodbus.logging:send: 0x2 0x3 0x10 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0xa0 0x1d
pymodbus
Version: 3.9.2
Windows 10 Pro
The text was updated successfully, but these errors were encountered: