pyModbusTCP server problem with DataBank.set_input_registries

126 views Asked by At

I am trying to set up a simple Modbus Server that generates random values to store in an input register. However, I continue to get the error "TypeError: DataBank.set_input_registers() missing 1 required positional argument: 'word_list'

I have managed to get random values to print using DataBank.set_words, but I'm not sure where these are writing to and I ultimately want to set up a separate pyModbusTCP client to read the register values. The pyModbusTCP documentation uses set_input_registers and get_input_registers. If it makes any difference, it would be fine for me to use the holding registers instead.

from pyModbusTCP.server import ModbusServer, DataBank import random import time

Initialize Modbus Server

server = ModbusServer("localhost", port=502, no_block=True)

try: print("Starting Modbus Server...") server.start() while True: # Generate a random number between 0 and 100 random_number = random.randint(0, 100)

    # Store the random number in the Modbus input register at address 0
    DataBank.set_input_registers(0, [random_number])

    # Read the value from the input register at address 0
    input_register_value = DataBank.get_input_registers(0)
    print("Register 1 value: " +str(input_register_value)) 

    time.sleep(1)  # Wait for 1 second before generating the next random number

except KeyboardInterrupt: print("Modbus Server Stopped.") server.stop()

0

There are 0 answers