context — Modbus Server Contexts

API Documentation

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

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

__init__(*args, **kwargs)[source]

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__()[source]

Returns a string representation of the context

Returns:A string representation of the context
reset()[source]

Resets all the datastores to their default values

validate(fx, address, count=1)[source]

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

getValues(fx, address, count=1)[source]

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

setValues(fx, address, values)[source]

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
class pymodbus.datastore.context.ModbusServerContext(slaves=None, single=True)[source]

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.

__init__(slaves=None, single=True)[source]

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__()[source]

Iterater over the current collection of slave contexts.

Returns:An iterator over the slave contexts
__contains__(slave)[source]

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
__setitem__(slave, context)[source]

Used to set a new slave context

Parameters:
  • slave – The slave context to set
  • context – The new context to set for this slave
__delitem__(slave)[source]

Wrapper used to access the slave context

Parameters:slave – The slave context to remove
__getitem__(slave)[source]

Used to get access to a slave context

Parameters:slave – The slave context to get
Returns:The requested slave context