本文整理汇总了Python中modbus_tk.LOGGER.info方法的典型用法代码示例。如果您正苦于以下问题:Python LOGGER.info方法的具体用法?Python LOGGER.info怎么用?Python LOGGER.info使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modbus_tk.LOGGER
的用法示例。
在下文中一共展示了LOGGER.info方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from modbus_tk import LOGGER [as 别名]
# 或者: from modbus_tk.LOGGER import info [as 别名]
def __init__(self, serial, interchar_multiplier=1.5, interframe_multiplier=3.5):
"""Constructor. Pass the pyserial.Serial object"""
self._serial = serial
LOGGER.info("RtuMaster %s is %s", self._serial.portstr, "opened" if self._serial.isOpen() else "closed")
super(RtuMaster, self).__init__(self._serial.timeout)
self._t0 = utils.calculate_rtu_inter_char(self._serial.baudrate)
self._serial.interCharTimeout = interchar_multiplier * self._t0
self.set_timeout(interframe_multiplier * self._t0)
示例2: _run_server
# 需要导入模块: from modbus_tk import LOGGER [as 别名]
# 或者: from modbus_tk.LOGGER import info [as 别名]
def _run_server(self):
"""main function of the main thread"""
try:
self._do_init()
while self._go.isSet():
self._do_run()
LOGGER.info("%s has stopped", self.__class__)
self._do_exit()
except Exception, excpt:
LOGGER.error("server error: %s", str(excpt))
示例3: __init__
# 需要导入模块: from modbus_tk import LOGGER [as 别名]
# 或者: from modbus_tk.LOGGER import info [as 别名]
def __init__(self, serial, interchar_multiplier=1.5, interframe_multiplier=3.5, t0=None):
"""Constructor. Pass the pyserial.Serial object"""
self._serial = serial
self.use_sw_timeout = False
LOGGER.info("RtuMaster %s is %s", self._serial.name, "opened" if self._serial.is_open else "closed")
super(RtuMaster, self).__init__(self._serial.timeout)
if t0:
self._t0 = t0
else:
self._t0 = utils.calculate_rtu_inter_char(self._serial.baudrate)
self._serial.inter_byte_timeout = interchar_multiplier * self._t0
self.set_timeout(interframe_multiplier * self._t0)
# For some RS-485 adapters, the sent data(echo data) appears before modbus response.
# So read echo data and discard it. By [email protected]
self.handle_local_echo = False
示例4: _do_run
# 需要导入模块: from modbus_tk import LOGGER [as 别名]
# 或者: from modbus_tk.LOGGER import info [as 别名]
def _do_run(self):
"""called in a almost-for-ever loop by the server"""
# check the status of every socket
inputready = select.select(self._sockets, [], [], 1.0)[0]
# handle data on each a socket
for sock in inputready:
try:
if sock == self._sock:
# handle the server socket
client, address = self._sock.accept()
client.setblocking(0)
LOGGER.info("%s is connected with socket %d...", str(address), client.fileno())
self._sockets.append(client)
call_hooks("modbus_tcp.TcpServer.on_connect", (self, client, address))
else:
if len(sock.recv(1, socket.MSG_PEEK)) == 0:
# socket is disconnected
LOGGER.info("%d is disconnected" % (sock.fileno()))
call_hooks("modbus_tcp.TcpServer.on_disconnect", (self, sock))
sock.close()
self._sockets.remove(sock)
break
# handle all other sockets
sock.settimeout(1.0)
request = to_data("")
is_ok = True
# read the 7 bytes of the mbap
while (len(request) < 7) and is_ok:
new_byte = sock.recv(1)
if len(new_byte) == 0:
is_ok = False
else:
request += new_byte
retval = call_hooks("modbus_tcp.TcpServer.after_recv", (self, sock, request))
if retval is not None:
request = retval
if is_ok:
# read the rest of the request
length = self._get_request_length(request)
while (len(request) < (length + 6)) and is_ok:
new_byte = sock.recv(1)
if len(new_byte) == 0:
is_ok = False
else:
request += new_byte
if is_ok:
response = ""
# parse the request
try:
response = self._handle(request)
except Exception as msg:
LOGGER.error("Error while handling a request, Exception occurred: %s", msg)
# send back the response
if response:
try:
retval = call_hooks("modbus_tcp.TcpServer.before_send", (self, sock, response))
if retval is not None:
response = retval
sock.send(response)
call_hooks("modbus_tcp.TcpServer.after_send", (self, sock, response))
except Exception as msg:
is_ok = False
LOGGER.error(
"Error while sending on socket %d, Exception occurred: %s", sock.fileno(), msg
)
except Exception as excpt:
LOGGER.warning("Error while processing data on socket %d: %s", sock.fileno(), excpt)
call_hooks("modbus_tcp.TcpServer.on_error", (self, sock, excpt))
sock.close()
self._sockets.remove(sock)