本文整理汇总了Python中snap7.common.check_error函数的典型用法代码示例。如果您正苦于以下问题:Python check_error函数的具体用法?Python check_error怎么用?Python check_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list_blocks_of_type
def list_blocks_of_type(self, blocktype, size):
"""This function returns the AG list of a specified block type."""
blocktype = snap7.snap7types.block_types.get(blocktype)
if not blocktype:
raise Snap7Exception("The blocktype parameter was invalid")
logger.debug("listing blocks of type: %s size: %s" %
(blocktype, size))
if (size == 0):
return 0
data = (c_uint16 * size)()
count = c_int(size)
result = self.library.Cli_ListBlocksOfType(
self.pointer, blocktype,
byref(data),
byref(count))
logger.debug("number of items found: %s" % count)
check_error(result, context="client")
return data
示例2: get_last_error
def get_last_error(self):
"""
Returns the last job result.
"""
error = ctypes.c_int32()
result = self.library.Par_GetLastError(self.pointer, ctypes.byref(error))
check_error(result, "partner")
return error
示例3: get_cpu_info
def get_cpu_info(self):
"""
Retrieves CPU info from client
"""
info = snap7.snap7types.S7CpuInfo()
result = self.library.Cli_GetCpuInfo(self.pointer, byref(info))
check_error(result, context="client")
return info
示例4: get_mask
def get_mask(self, kind):
"""Reads the specified filter mask.
"""
logger.debug("retrieving mask kind %s" % kind)
mask = longword()
code = self.library.Srv_GetMask(self.pointer, kind, ctypes.byref(mask))
check_error(code)
return mask
示例5: disconnect
def disconnect(self):
"""
disconnect a client.
"""
logger.info("disconnecting snap7 client")
result = self.library.Cli_Disconnect(self.pointer)
check_error(result, context="client")
return result
示例6: get_status
def get_status(self):
"""
Returns the Partner status.
"""
status = ctypes.c_int32()
result = self.library.Par_GetStatus(self.pointer, ctypes.byref(status))
check_error(result, "partner")
return status
示例7: read
def read(self, vm_address):
"""
Reads from VM addresses of Siemens Logo. Examples: read("V40") / read("VW64") / read("V10.2")
:param vm_address: of Logo memory (e.g. V30.1, VW32, V24)
:returns: integer
"""
area = snap7types.S7AreaDB
db_number = 1
size = 1
start = 0
wordlen = 0
logger.debug("read, vm_address:%s" % (vm_address))
if re.match("V[0-9]{1,4}\.[0-7]{1}", vm_address):
## bit value
logger.info("read, Bit address: " + vm_address)
address = vm_address[1:].split(".")
# transform string to int
address_byte = int(address[0])
address_bit = int(address[1])
start = (address_byte*8)+address_bit
wordlen = snap7types.S7WLBit
elif re.match("V[0-9]+", vm_address):
## byte value
logger.info("Byte address: " + vm_address)
start = int(vm_address[1:])
wordlen = snap7types.S7WLByte
elif re.match("VW[0-9]+", vm_address):
## byte value
logger.info("Word address: " + vm_address)
start = int(vm_address[2:])
wordlen = snap7types.S7WLWord
elif re.match("VD[0-9]+", vm_address):
## byte value
logger.info("DWord address: " + vm_address)
start = int(vm_address[2:])
wordlen = snap7types.S7WLDWord
else:
logger.info("Unknown address format")
return 0
type_ = snap7.snap7types.wordlen_to_ctypes[wordlen]
data = (type_ * size)()
logger.debug("start:%s, wordlen:%s, data-length:%s" % (start, wordlen, len(data)) )
result = self.library.Cli_ReadArea(self.pointer, area, db_number, start,
size, wordlen, byref(data))
check_error(result, context="client")
# transform result to int value
if wordlen == snap7types.S7WLBit:
return(data)[0]
if wordlen == snap7types.S7WLByte:
return struct.unpack_from(">B", data)[0]
if wordlen == snap7types.S7WLWord:
return struct.unpack_from(">h", data)[0]
if wordlen == snap7types.S7WLDWord:
return struct.unpack_from(">l", data)[0]
示例8: db_get
def db_get(self, db_number):
"""Uploads a DB from AG.
"""
logging.debug("db_get db_number: %s" % db_number)
_buffer = buffer_type()
result = self.library.Cli_DBGet(self.pointer, db_number, byref(_buffer),
byref(c_int(buffer_size)))
check_error(result, context="client")
return bytearray(_buffer)
示例9: db_get
def db_get(self, db_number):
"""Uploads a DB from AG.
"""
logging.debug("db_get db_number: %s" % db_number)
buffer_ = buffer_type()
result = clib.Cli_DBGet(self.pointer, db_number, byref(buffer_),
byref(c_int(buffer_size)))
check_error(result, client=True)
return bytearray(buffer_)
示例10: get_param
def get_param(self, number):
"""Reads an internal Server object parameter.
"""
logger.debug("retreiving param number %s" % number)
value = ctypes.c_int()
code = self.library.Srv_GetParam(self.pointer, number,
ctypes.byref(value))
check_error(code)
return value.value
示例11: read_multi_vars
def read_multi_vars(self, items):
"""This function read multiple variables from the PLC.
:param items: list of S7DataItem objects
:returns: a tuple with the return code and a list of data items
"""
result = self.library.Cli_ReadMultiVars(self.pointer, byref(items),
c_int32(len(items)))
check_error(result, context="client")
return result, items
示例12: get_connected
def get_connected(self):
"""
Returns the connection status
:returns: a boolean that indicates if connected.
"""
connected = c_int32()
result = self.library.Cli_GetConnected(self.pointer, byref(connected))
check_error(result, context="client")
return bool(connected)
示例13: get_param
def get_param(self, number):
"""Reads an internal Client object parameter.
"""
logger.debug("retreiving param number %s" % number)
type_ = param_types[number]
value = type_()
code = self.library.Cli_GetParam(self.pointer, c_int(number),
byref(value))
check_error(code)
return value.value
示例14: get_times
def get_times(self):
"""
Returns the last send and recv jobs execution time in milliseconds.
"""
send_time = ctypes.c_int32()
recv_time = ctypes.c_int32()
result = self.library.Par_GetTimes(self.pointer, ctypes.byref(send_time),
ctypes.byref(recv_time))
check_error(result, "partner")
return send_time, recv_time
示例15: get_param
def get_param(self, number):
"""
Reads an internal Partner object parameter.
"""
logger.debug("retreiving param number %s" % number)
type_ = snap7.snap7types.param_types[number]
value = type_()
code = self.library.Par_GetParam(self.pointer, ctypes.c_int(number),
ctypes.byref(value))
check_error(code)
return value.value