diff --git a/doc/API/type.rst b/doc/API/type.rst new file mode 100644 index 00000000..77bc3232 --- /dev/null +++ b/doc/API/type.rst @@ -0,0 +1,5 @@ +Types +===== + +.. automodule:: snap7.type + :members: diff --git a/doc/index.rst b/doc/index.rst index 2c56c48a..73f4ff8d 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -19,6 +19,7 @@ Contents: API/server API/partner API/logo + API/type API/util diff --git a/snap7/type.py b/snap7/type.py index 069a4c9c..2738e0d8 100755 --- a/snap7/type.py +++ b/snap7/type.py @@ -45,7 +45,10 @@ class Parameter(IntEnum): - # // PARAMS LIST + """ + The snap7 parameter types + """ + LocalPort = 1 RemotePort = 2 PingTimeout = 3 @@ -87,6 +90,10 @@ def ctype(self) -> CDataType: # Area ID # Word Length class WordLen(IntEnum): + """ + The snap7 word length types + """ + Bit = 0x01 Byte = 0x02 Char = 0x03 @@ -113,6 +120,10 @@ def ctype(self) -> CDataType: class Area(IntEnum): + """ + The snap7 area types + """ + PE = 0x81 PA = 0x82 MK = 0x83 @@ -134,6 +145,8 @@ def wordlen(self) -> WordLen: class SrvArea(IntEnum): """ + The snap7 server area types + NOTE: these values are DIFFERENT from the normal area IDs. """ @@ -146,6 +159,10 @@ class SrvArea(IntEnum): class Block(IntEnum): + """ + The snap7 block type + """ + OB = 0x38 DB = 0x41 SDB = 0x42 @@ -173,6 +190,10 @@ def ctype(self) -> c_int: class SrvEvent(Structure): + """ + The snap7 server event structure + """ + _fields_ = [ ("EvtTime", time_t), ("EvtSender", c_int), @@ -193,6 +214,10 @@ def __str__(self) -> str: class BlocksList(Structure): + """ + The snap7 block list structure + """ + _fields_ = [ ("OBCount", c_int32), ("FBCount", c_int32), @@ -250,6 +275,8 @@ def __str__(self) -> str: class S7DataItem(Structure): + """ """ + _pack_ = 1 _fields_ = [ ("Area", c_int32), diff --git a/snap7/util/getters.py b/snap7/util/getters.py index a4a8d49e..4c35c225 100644 --- a/snap7/util/getters.py +++ b/snap7/util/getters.py @@ -493,25 +493,24 @@ def get_lint(bytearray_: bytearray, byte_index: int) -> int: def get_lreal(bytearray_: bytearray, byte_index: int) -> float: """Get the long real - Notes: - Datatype `lreal` (long real) consists in 8 bytes in the PLC. - Negative Range: -1.7976931348623158e+308 to -2.2250738585072014e-308 - Positive Range: +2.2250738585072014e-308 to +1.7976931348623158e+308 - Zero: ±0 + Datatype `lreal` (long real) consists in 8 bytes in the PLC. + Negative Range: -1.7976931348623158e+308 to -2.2250738585072014e-308 + Positive Range: +2.2250738585072014e-308 to +1.7976931348623158e+308 + Zero: ±0 Args: bytearray_: buffer to read from. byte_index: byte index from where to start reading. Returns: - Value read. + The real value. Examples: read lreal value (here as example 12345.12345) from DB1.10 of a PLC >>> from snap7 import Client >>> data = Client().db_read(db_number=1, start=10, size=8) >>> get_lreal(data, 0) - 12345.12345 + 12345.12345 """ return float(struct.unpack_from(">d", bytearray_, offset=byte_index)[0]) @@ -637,7 +636,7 @@ def get_char(bytearray_: bytearray, byte_index: int) -> str: >>> from snap7 import Client >>> data = Client().db_read(db_number=1, start=10, size=1) >>> get_char(data, 0) - 'C' + C """ char = chr(bytearray_[byte_index]) return char @@ -646,9 +645,7 @@ def get_char(bytearray_: bytearray, byte_index: int) -> str: def get_wchar(bytearray_: bytearray, byte_index: int) -> str: """Get wchar value from bytearray. - Notes: - Datatype `wchar` in the PLC is represented in 2 bytes. It has to be in utf-16-be format. - + Datatype `wchar` in the PLC is represented in 2 bytes. It has to be in utf-16-be format. Args: bytearray_: buffer to read from. @@ -662,7 +659,7 @@ def get_wchar(bytearray_: bytearray, byte_index: int) -> str: >>> from snap7 import Client >>> data = Client().db_read(db_number=1, start=10, size=2) >>> get_wchar(data, 0) - 'C' + C """ if bytearray_[byte_index] == 0: return chr(bytearray_[1])