11"""Modbus RTU frame implementation."""
22from __future__ import annotations
33
4+ from collections import namedtuple
5+
46from pymodbus .framer .base import FramerBase
57from pymodbus .logging import Log
68
@@ -15,7 +17,7 @@ class FramerRTU(FramerBase):
1517 neither when receiving nor when sending.
1618
1719 Decoding is a complicated process because the RTU frame does not have a fixed prefix
18- only suffix, therefore it is nessecary to decode the content (PDU) to get length etc.
20+ only suffix, therefore it is necessary to decode the content (PDU) to get length etc.
1921
2022 There are some restraints however that help the detection.
2123
@@ -43,16 +45,19 @@ class FramerRTU(FramerBase):
4345 - data in frame garbled (wrong CRC)
4446 decoding assumes the frame is sound, and if not enters a hunting mode.
4547
46- The 3.5 byte wait betwen frames is 31ms at 1.200Bps and 1ms at 38.600bps,
47- so the decoder will wait 50ms for more data if not the transmission is
48+ The 3.5 byte wait 31ms at 1.200Bps and 1ms at 38.600bps,
49+ so the decoder will wait for more data a number of milliseconds, if not the transmission is
4850 considered complete
4951 """
5052
5153 MIN_SIZE = 5
5254
55+ FC_LEN = namedtuple ("FC_LEN" , "req_len req_bytepos resp_len resp_bytepos" )
56+
5357 def __init__ (self ) -> None :
5458 """Initialize a ADU instance."""
5559 super ().__init__ ()
60+ self .fc_len : dict [int , FramerRTU .FC_LEN ] = {}
5661
5762
5863 @classmethod
@@ -74,6 +79,14 @@ def generate_crc16_table(cls) -> list[int]:
7479 return result
7580 crc16_table : list [int ] = [0 ]
7681
82+
83+ def setup_fc_len (self , _fc : int ,
84+ _req_len : int , _req_byte_pos : int ,
85+ _resp_len : int , _resp_byte_pos : int
86+ ):
87+ """Define request/response lengths pr function code."""
88+ return
89+
7790 def decode (self , data : bytes ) -> tuple [int , int , int , bytes ]:
7891 """Decode ADU."""
7992 if (buf_len := len (data )) < self .MIN_SIZE :
0 commit comments