本文整理汇总了Python中pymodbus.client.sync.ModbusSerialClient._recv方法的典型用法代码示例。如果您正苦于以下问题:Python ModbusSerialClient._recv方法的具体用法?Python ModbusSerialClient._recv怎么用?Python ModbusSerialClient._recv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymodbus.client.sync.ModbusSerialClient
的用法示例。
在下文中一共展示了ModbusSerialClient._recv方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSerialClientRecv
# 需要导入模块: from pymodbus.client.sync import ModbusSerialClient [as 别名]
# 或者: from pymodbus.client.sync.ModbusSerialClient import _recv [as 别名]
def testSerialClientRecv(self):
''' Test the serial client receive method'''
client = ModbusSerialClient()
self.assertRaises(ConnectionException, lambda: client._recv(1024))
client.socket = mockSocket()
self.assertEqual('', client._recv(0))
self.assertEqual('\x00'*4, client._recv(4))
示例2: testSerialClientRecv
# 需要导入模块: from pymodbus.client.sync import ModbusSerialClient [as 别名]
# 或者: from pymodbus.client.sync.ModbusSerialClient import _recv [as 别名]
def testSerialClientRecv(self):
''' Test the serial client receive method'''
client = ModbusSerialClient()
self.assertRaises(ConnectionException, lambda: client._recv(1024))
client.socket = mockSocket()
self.assertEqual(b'', client._recv(0))
self.assertEqual(b'\x00' * 4, client._recv(4))
client.socket = MagicMock()
client.socket.read.return_value = b''
self.assertEqual(b'', client._recv(None))
client.socket.timeout = 0
self.assertEqual(b'', client._recv(0))
示例3: testBasicSyncSerialClient
# 需要导入模块: from pymodbus.client.sync import ModbusSerialClient [as 别名]
# 或者: from pymodbus.client.sync.ModbusSerialClient import _recv [as 别名]
def testBasicSyncSerialClient(self, mock_serial):
''' Test the basic methods for the serial sync client'''
# receive/send
mock_serial.in_waiting = 0
mock_serial.write = lambda x: len(x)
mock_serial.read = lambda size: b'\x00' * size
client = ModbusSerialClient()
client.socket = mock_serial
client.state = 0
self.assertEqual(0, client._send(None))
client.state = 0
self.assertEqual(1, client._send(b'\x00'))
self.assertEqual(b'\x00', client._recv(1))
# connect/disconnect
self.assertTrue(client.connect())
client.close()
# already closed socket
client.socket = False
client.close()
self.assertEqual('ModbusSerialClient(ascii baud[19200])', str(client))
示例4: testBasicSyncSerialClient
# 需要导入模块: from pymodbus.client.sync import ModbusSerialClient [as 别名]
# 或者: from pymodbus.client.sync.ModbusSerialClient import _recv [as 别名]
def testBasicSyncSerialClient(self):
''' Test the basic methods for the serial sync client'''
# receive/send
client = ModbusSerialClient()
client.socket = mockSocket()
self.assertEqual(0, client._send(None))
self.assertEqual(1, client._send('\x00'))
self.assertEqual('\x00', client._recv(1))
# connect/disconnect
self.assertTrue(client.connect())
client.close()
# already closed socket
client.socket = False
client.close()
self.assertEqual('ascii baud[19200]', str(client))