Module author: Galen Collins <bashwork@gmail.com>
Section author: Galen Collins <bashwork@gmail.com>
A collection of base classes that are used throughout the pymodbus library.
Singleton base class http://mail.python.org/pipermail/python-list/2007-July/450681.html
Modbus Decoder Base Class
This interface must be implemented by a modbus message decoder factory. These factories are responsible for abstracting away converting a raw packet into a request / response message object.
Wrapper to decode a given packet
Parameters: | message – The raw modbus request packet |
---|---|
Returns: | The decoded modbus message or None if error |
A framer strategy interface. The idea is that we abstract away all the detail about how to detect if a current message frame exists, decoding it, sending it, etc so that we can plug in a new Framer object (tcp, rtu, ascii)
Add the next message to the frame buffer
This should be used before the decoding while loop to add the received data to the buffer handle.
Parameters: | message – The most recent packet |
---|
Skip over the current framed message This allows us to skip over the current message after we have processed it or determined that it contains an error. It also has to reset the current frame header handle
Creates a ready to send modbus packet
The raw packet is built off of a fully populated modbus request / response message.
Parameters: | message – The request/response to send |
---|---|
Returns: | The built packet |
Check and decode the next frame
Returns: | True if we successful, False otherwise |
---|
Get the next frame from the buffer
Returns: | The frame data or ‘’ |
---|
Check if we should continue decode logic
This is meant to be used in a while loop in the decoding phase to let the decoder know that there is still data in the buffer.
Returns: | True if ready, False otherwise |
---|
Populates the modbus result with current frame header
We basically copy the data back over from the current header to the result header. This may not be needed for serial messages.
Parameters: | result – The response packet |
---|
The new packet processing pattern
This takes in a new request packet, adds it to the current packet stream, and performs framing on it. That is, checks for complete messages, and once found, will process all that exist. This handles the case when we read N + 1 or 1 / N messages at a time instead of 1.
The processed and decoded messages are pushed to the callback function to process and send.
Parameters: |
|
---|
Interface for a modbus slave data context
Validates the request to make sure it is in range
Parameters: |
|
---|---|
Returns: | The requested values from a:a+c |
Resets all the datastores to their default values
Sets the datastore with the supplied values
Parameters: |
|
---|
Validates the request to make sure it is in range
Parameters: |
|
---|---|
Returns: | True if the request in within range, False otherwise |