forked from canopen-python/canopen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_nmt.py
More file actions
64 lines (51 loc) · 2.26 KB
/
test_nmt.py
File metadata and controls
64 lines (51 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import time
import unittest
import canopen
from .util import EDS_PATH
class TestNmtSlave(unittest.TestCase):
def setUp(self):
self.network1 = canopen.Network()
self.network1.connect("test", interface="virtual")
self.remote_node = self.network1.add_node(2, EDS_PATH)
self.network2 = canopen.Network()
self.network2.connect("test", interface="virtual")
self.local_node = self.network2.create_node(2, EDS_PATH)
self.remote_node2 = self.network1.add_node(3, EDS_PATH)
self.local_node2 = self.network2.create_node(3, EDS_PATH)
def tearDown(self):
self.network1.disconnect()
self.network2.disconnect()
def test_start_two_remote_nodes(self):
self.remote_node.nmt.state = "OPERATIONAL"
# Line below is just so that we are sure the client have received the command
# before we do the check
time.sleep(0.1)
slave_state = self.local_node.nmt.state
self.assertEqual(slave_state, "OPERATIONAL")
self.remote_node2.nmt.state = "OPERATIONAL"
# Line below is just so that we are sure the client have received the command
# before we do the check
time.sleep(0.1)
slave_state = self.local_node2.nmt.state
self.assertEqual(slave_state, "OPERATIONAL")
def test_stop_two_remote_nodes_using_broadcast(self):
# This is a NMT broadcast "Stop remote node"
# ie. set the node in STOPPED state
self.network1.send_message(0, [2, 0])
# Line below is just so that we are sure the slaves have received the command
# before we do the check
time.sleep(0.1)
slave_state = self.local_node.nmt.state
self.assertEqual(slave_state, "STOPPED")
slave_state = self.local_node2.nmt.state
self.assertEqual(slave_state, "STOPPED")
def test_heartbeat(self):
self.assertEqual(self.remote_node.nmt.state, "INITIALISING")
self.assertEqual(self.local_node.nmt.state, "INITIALISING")
self.local_node.nmt.state = "OPERATIONAL"
self.local_node.sdo[0x1017].raw = 100
time.sleep(0.2)
self.assertEqual(self.remote_node.nmt.state, "OPERATIONAL")
self.local_node.nmt.stop_heartbeat()
if __name__ == "__main__":
unittest.main()