Snap7 Client Used For
Snap7 Client Used For
import re
import struct
import logging
from ctypes import byref
logger = logging.getLogger(__name__)
[docs]
class Logo(Client):
"""
A snap7 Siemens Logo client:
There are two main comfort functions available :func:`Logo.read`
and :func:`Logo.write`.
This function offers high-level access to the VM addresses of the Siemens Logo
just use the form:
Notes:
V10.3 for bit values
V10 for the complete byte
VW12 for a word (used for analog values)
For more information see examples for Siemens Logo 7 and 8
"""
[docs]
Notes:
Howto setup Logo communication configuration see:
https://snap7.sourceforge.net/logo.html
Args:
ip_address: IP ip_address of server
tsap_snap7: TSAP SNAP7 Client (e.g. 10.00 = 0x1000)
tsap_logo: TSAP Logo Server (e.g. 20.00 = 0x2000)
tcp_port: TCP port of server
Returns:
The snap7 Logo instance
"""
logger.info(f"connecting to {ip_address}:{tcp_port} tsap_snap7 {tsap_snap7}
tsap_logo {tsap_logo}")
self.set_param(Parameter.RemotePort, tcp_port)
self.set_connection_params(ip_address, tsap_snap7, tsap_logo)
check_error(self._lib.Cli_Connect(self._s7_client))
return self
[docs]
Args:
vm_address: of Logo memory (e.g. V30.1, VW32, V24)
Returns:
integer
"""
area = Area.DB
db_number = 1
size = 1
logger.debug(f"read, vm_address:{vm_address}")
start, wordlen = parse_address(vm_address)
type_ = wordlen.ctype
data = (type_ * size)()
[docs]
Args:
vm_address: write offset
value: integer
Examples:
>>> Logo().write("VW10", 200) or Logo().write("V10.3", 1)
"""
area = Area.DB
db_number = 1
size = 1
start, wordlen = parse_address(vm_address)
type_ = wordlen.ctype
if wordlen == WordLen.Bit:
type_ = WordLen.Byte.ctype
if value > 0:
data = bytearray([1])
else:
data = bytearray([0])
elif wordlen == WordLen.Byte:
data = bytearray(struct.pack(">B", value))
elif wordlen == WordLen.Word:
data = bytearray(struct.pack(">h", value))
elif wordlen == WordLen.DWord:
data = bytearray(struct.pack(">l", value))
else:
raise ValueError(f"Unknown wordlen {wordlen}")