コード例 #1
0
 def setUp(self):
     self.mbap1 = modbus_tcp.TcpMbap()
     
     self.mbap1.transaction_id = 1
     self.mbap1.protocol_id = 2
     self.mbap1.length = 3
     self.mbap1.unit_id = 4
コード例 #2
0
 def testCheckIdsWrongUnitId(self):
     """Test that the check ids fails when the transaction id is not Ok"""
     mbap2 = modbus_tcp.TcpMbap()
     mbap2.transaction_id = 1
     mbap2.protocol_id = 2
     mbap2.length = 10
     mbap2.unit_id = 5
     
     self.assertRaises(modbus_tcp.ModbusInvalidMbapError, self.mbap1.check_response, mbap2, 2)
コード例 #3
0
 def testCheckIds(self):
     """Test that the check ids pass with correct mbap"""
     mbap2 = modbus_tcp.TcpMbap()
     mbap2.transaction_id = 1
     mbap2.protocol_id = 2
     mbap2.length = 10
     mbap2.unit_id = 4
     
     self.mbap1.check_response(mbap2, 3-1)
コード例 #4
0
 def testUnpack(self):
     """Test that unpacking a mbap give the expected result"""
     mbap2 = modbus_tcp.TcpMbap()
     mbap2.unpack(self.mbap1.pack())
     
     self.assertEqual(self.mbap1.transaction_id, mbap2.transaction_id)
     self.assertEqual(self.mbap1.protocol_id, mbap2.protocol_id)
     self.assertEqual(self.mbap1.length, mbap2.length)
     self.assertEqual(self.mbap1.unit_id, mbap2.unit_id)
     
     self.assertNotEqual(self.mbap1, mbap2)
コード例 #5
0
 def testClone(self):
     """test the clone function makes a copy of the object"""
     mbap2 = modbus_tcp.TcpMbap()
     
     mbap2.clone(self.mbap1)
     
     self.assertEqual(self.mbap1.transaction_id, mbap2.transaction_id)
     self.assertEqual(self.mbap1.protocol_id, mbap2.protocol_id)
     self.assertEqual(self.mbap1.length, mbap2.length)
     self.assertEqual(self.mbap1.unit_id, mbap2.unit_id)
     
     self.assertNotEqual(self.mbap1, mbap2)