context — Modbus Server Contexts

API Documentation

class pymodbus.datastore.context.ModbusSlaveContext(*args, **kwargs)

This creates a modbus data model with each data access stored in its own personal block

__init__(*args, **kwargs)

Initializes the datastores, defaults to fully populated sequential data blocks if none are passed in.

Parameters:kwargs

Each element is a ModbusDataBlock

‘di’ - Discrete Inputs initializer ‘co’ - Coils initializer ‘hr’ - Holding Register initializer ‘ir’ - Input Registers iniatializer

__str__()

Returns a string representation of the context

Returns:A string representation of the context
getValues(fx, address, count=1)

Validates the request to make sure it is in range

Parameters:
  • fx – The function we are working with
  • address – The starting address
  • count – The number of values to retrieve
Returns:

The requested values from a:a+c

reset()

Resets all the datastores to their default values

setValues(fx, address, values)

Sets the datastore with the supplied values

Parameters:
  • fx – The function we are working with
  • address – The starting address
  • values – The new values to be set
validate(fx, address, count=1)

Validates the request to make sure it is in range

Parameters:
  • fx – The function we are working with
  • address – The starting address
  • count – The number of values to test
Returns:

True if the request in within range, False otherwise

class pymodbus.datastore.context.ModbusServerContext(slaves=None, single=True)

This represents a master collection of slave contexts. If single is set to true, it will be treated as a single context so every unit-id returns the same context. If single is set to false, it will be interpreted as a collection of slave contexts.

__contains__(slave)

Check if the given slave is in this list

Parameters:slave – slave The slave to check for existance
Returns:True if the slave exists, False otherwise
__delitem__(slave)

Wrapper used to access the slave context

Parameters:slave – The slave context to remove
__getitem__(slave)

Used to get access to a slave context

Parameters:slave – The slave context to get
Returns:The requested slave context
__init__(slaves=None, single=True)

Initializes a new instance of a modbus server context.

Parameters:
  • slaves – A dictionary of client contexts
  • single – Set to true to treat this as a single context
__iter__()

Iterater over the current collection of slave contexts.

Returns:An iterator over the slave contexts
__setitem__(slave, context)

Used to set a new slave context

Parameters:
  • slave – The slave context to set
  • context – The new context to set for this slave