pymodbus.constants package
Constants For Modbus Server/Client.
This is the single location for storing default values for the servers and clients.
- class pymodbus.constants.Defaults(*args, **kwargs)
Bases:
pymodbus.interfaces.Singleton
A collection of modbus default values.
- Port
The default modbus tcp server port (502)
- TLSPort
The default modbus tcp over tls server port (802)
- Backoff
The default exponential backoff delay (0.3 seconds)
- Retries
The default number of times a client should retry the given request before failing (3)
- RetryOnEmpty
A flag indicating if a transaction should be retried in the case that an empty response is received. This is useful for slow clients that may need more time to process a request.
- RetryOnInvalid
A flag indicating if a transaction should be retried in the case that an invalid response is received.
- Timeout
The default amount of time a client should wait for a request to be processed (3 seconds)
- Reconnects
The default number of times a client should attempt to reconnect before deciding the server is down (0)
- TransactionId
The starting transaction identifier number (0)
- ProtocolId
The modbus protocol id. Currently this is set to 0 in all but proprietary implementations.
- Slave
The modbus slave address. Currently this is set to 0x00 which means this request should be broadcast to all the slave devices (really means that all the devices should respond).
- Baudrate
The speed at which the data is transmitted over the serial line. This defaults to 19200.
- Parity
The type of checksum to use to verify data integrity. This can be on of the following:
- (E)ven - 1 0 1 0 | P(0) - (O)dd - 1 0 1 0 | P(1) - (N)one - 1 0 1 0 | no parity
This defaults to (N)one.
- Bytesize
The number of bits in a byte of serial data. This can be one of 5, 6, 7, or 8. This defaults to 8.
- Stopbits
The number of bits sent after each character in a message to indicate the end of the byte. This defaults to 1.
- ZeroMode
Indicates if the slave datastore should use indexing at 0 or 1. More about this can be read in section 4.4 of the modbus specification.
- IgnoreMissingSlaves
In case a request is made to a missing slave, this defines if an error should be returned or simply ignored. This is useful for the case of a serial server emulater where a request to a non-existent slave on a bus will never respond. The client in this case will simply timeout.
- broadcast_enable
When False unit_id 0 will be treated as any other unit_id. When True and the unit_id is 0 the server will execute all requests on all server contexts and not respond and the client will skip trying to receive a response. Default value False does not conform to Modbus spec but maintains legacy behavior for existing pymodbus users.
- Backoff = 0.3
- Baudrate = 19200
- BroadcastEnable = False
- Bytesize = 8
- CloseCommOnError = False
- Count = 1
- HandleLocalEcho = False
- IgnoreMissingSlaves = False
- Parity = 'N'
- ProtocolId = 0
- ReadSize = 1024
- ReconnectDelay = 300000
- Reconnects = 0
- Retries = 3
- RetryOnEmpty = False
- RetryOnInvalid = False
- Slave = 0
- Stopbits = 1
- Strict = True
- TcpPort = 502
- Timeout = 3
- TlsPort = 802
- TransactionId = 0
- UdpPort = 502
- ZeroMode = False
- class pymodbus.constants.DeviceInformation(*args, **kwargs)
Bases:
pymodbus.interfaces.Singleton
Represents what type of device information to read.
- Basic
This is the basic (required) device information to be returned. This includes VendorName, ProductCode, and MajorMinorRevision code.
- Regular
In addition to basic data objects, the device provides additional and optional identification and description data objects. All of the objects of this category are defined in the standard but their implementation is optional.
- Extended
In addition to regular data objects, the device provides additional and optional identification and description private data about the physical device itself. All of these data are device dependent.
- Specific
Request to return a single data object.
- Basic = 1
- Extended = 3
- Regular = 2
- Specific = 4
- class pymodbus.constants.Endian(*args, **kwargs)
Bases:
pymodbus.interfaces.Singleton
An enumeration representing the various byte endianness.
- Auto
This indicates that the byte order is chosen by the current native environment.
- Big
This indicates that the bytes are in little endian format
- Little
This indicates that the bytes are in big endian format
Note
I am simply borrowing the format strings from the python struct module for my convenience.
- Auto = '@'
- Big = '>'
- Little = '<'
- class pymodbus.constants.ModbusPlusOperation(*args, **kwargs)
Bases:
pymodbus.interfaces.Singleton
Represents the type of modbus plus request.
- GetStatistics
Operation requesting that the current modbus plus statistics be returned in the response.
- ClearStatistics
Operation requesting that the current modbus plus statistics be cleared and not returned in the response.
- ClearStatistics = 4
- GetStatistics = 3
- class pymodbus.constants.ModbusStatus(*args, **kwargs)
Bases:
pymodbus.interfaces.Singleton
These represent various status codes in the modbus protocol.
- Waiting
This indicates that a modbus device is currently waiting for a given request to finish some running task.
- Ready
This indicates that a modbus device is currently free to perform the next request task.
- On
This indicates that the given modbus entity is on
- Off
This indicates that the given modbus entity is off
- SlaveOn
This indicates that the given modbus slave is running
- SlaveOff
This indicates that the given modbus slave is not running
- Off = 0
- On = 65280
- Ready = 0
- SlaveOff = 0
- SlaveOn = 255
- Waiting = 65535
- class pymodbus.constants.MoreData(*args, **kwargs)
Bases:
pymodbus.interfaces.Singleton
Represents the more follows condition.
- Nothing
This indicates that no more objects are going to be returned.
- KeepReading
This indicates that there are more objects to be returned.
- KeepReading = 255
- Nothing = 0