-
Notifications
You must be signed in to change notification settings - Fork 951
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f12b4e
commit e074114
Showing
8 changed files
with
82 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,17 @@ | ||
"""Framer start.""" | ||
# pylint: disable=missing-type-doc | ||
|
||
|
||
# Unit ID, Function Code | ||
BYTE_ORDER = ">" | ||
FRAME_HEADER = "BB" | ||
|
||
# Transaction Id, Protocol ID, Length, Unit ID, Function Code | ||
SOCKET_FRAME_HEADER = BYTE_ORDER + "HHH" + FRAME_HEADER | ||
|
||
# Function Code | ||
TLS_FRAME_HEADER = BYTE_ORDER + "B" | ||
|
||
|
||
class ModbusFramer: | ||
"""Base Framer class.""" | ||
|
||
name = "" | ||
|
||
def __init__(self, decoder, client=None): | ||
"""Initialize a new instance of the framer. | ||
:param decoder: The decoder implementation to use | ||
""" | ||
self.decoder = decoder | ||
self.client = client | ||
|
||
def _validate_slave_id(self, slaves, single): | ||
"""Validate if the received data is valid for the client. | ||
:param slaves: list of slave id for which the transaction is valid | ||
:param single: Set to true to treat this as a single context | ||
:return: | ||
""" | ||
if single: | ||
return True | ||
if 0 in slaves or 0xFF in slaves: | ||
# Handle Modbus TCP slave identifier (0x00 0r 0xFF) | ||
# in asynchronous requests | ||
return True | ||
return self._header["uid"] in slaves # pylint: disable=no-member | ||
|
||
def sendPacket(self, message): | ||
"""Send packets on the bus. | ||
With 3.5char delay between frames | ||
:param message: Message to be sent over the bus | ||
:return: | ||
""" | ||
return self.client.send(message) | ||
|
||
def recvPacket(self, size): | ||
"""Receive packet from the bus. | ||
With specified len | ||
:param size: Number of bytes to read | ||
:return: | ||
""" | ||
return self.client.recv(size) | ||
"""Framer""" | ||
|
||
__all__ = [ | ||
"ModbusFramer", | ||
"ModbusAsciiFramer", | ||
"ModbusBinaryFramer", | ||
"ModbusRtuFramer", | ||
"ModbusSocketFramer", | ||
"ModbusTlsFramer", | ||
] | ||
|
||
from pymodbus.framer.ascii_framer import ModbusAsciiFramer | ||
from pymodbus.framer.base import ModbusFramer | ||
from pymodbus.framer.binary_framer import ModbusBinaryFramer | ||
from pymodbus.framer.rtu_framer import ModbusRtuFramer | ||
from pymodbus.framer.socket_framer import ModbusSocketFramer | ||
from pymodbus.framer.tls_framer import ModbusTlsFramer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Framer start.""" | ||
# pylint: disable=missing-type-doc | ||
|
||
|
||
# Unit ID, Function Code | ||
BYTE_ORDER = ">" | ||
FRAME_HEADER = "BB" | ||
|
||
# Transaction Id, Protocol ID, Length, Unit ID, Function Code | ||
SOCKET_FRAME_HEADER = BYTE_ORDER + "HHH" + FRAME_HEADER | ||
|
||
# Function Code | ||
TLS_FRAME_HEADER = BYTE_ORDER + "B" | ||
|
||
|
||
class ModbusFramer: | ||
"""Base Framer class.""" | ||
|
||
name = "" | ||
|
||
def __init__(self, decoder, client=None): | ||
"""Initialize a new instance of the framer. | ||
:param decoder: The decoder implementation to use | ||
""" | ||
self.decoder = decoder | ||
self.client = client | ||
|
||
def _validate_slave_id(self, slaves, single): | ||
"""Validate if the received data is valid for the client. | ||
:param slaves: list of slave id for which the transaction is valid | ||
:param single: Set to true to treat this as a single context | ||
:return: | ||
""" | ||
if single: | ||
return True | ||
if 0 in slaves or 0xFF in slaves: | ||
# Handle Modbus TCP slave identifier (0x00 0r 0xFF) | ||
# in asynchronous requests | ||
return True | ||
return self._header["uid"] in slaves # pylint: disable=no-member | ||
|
||
def sendPacket(self, message): | ||
"""Send packets on the bus. | ||
With 3.5char delay between frames | ||
:param message: Message to be sent over the bus | ||
:return: | ||
""" | ||
return self.client.send(message) | ||
|
||
def recvPacket(self, size): | ||
"""Receive packet from the bus. | ||
With specified len | ||
:param size: Number of bytes to read | ||
:return: | ||
""" | ||
return self.client.recv(size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters