@@ -113,11 +113,11 @@ The :code:`n` is the PDO index (normally 1 to 4). The second form of access is f
113
113
# network.connect(bustype='nican', channel='CAN0', bitrate=250000)
114
114
115
115
# Read a variable using SDO
116
- device_name = node.sdo[' Manufacturer device name' ].raw
117
- vendor_id = node.sdo[0x 1018 ][1 ].raw
116
+ device_name = node.sdo[' Manufacturer device name' ].get_raw()
117
+ vendor_id = node.sdo[0x 1018 ][1 ].get_raw()
118
118
119
119
# Write a variable using SDO
120
- node.sdo[' Producer heartbeat time' ].raw = 1000
120
+ node.sdo[' Producer heartbeat time' ].set_raw( 1000 )
121
121
122
122
# Read PDO configuration from node
123
123
node.tpdo.read()
@@ -141,8 +141,8 @@ The :code:`n` is the PDO index (normally 1 to 4). The second form of access is f
141
141
142
142
# Read a value from TPDO[1]
143
143
node.tpdo[1 ].wait_for_reception()
144
- speed = node.tpdo[1 ][' Velocity actual value' ].phys
145
- val = node.tpdo[' Some group.Some subindex' ].raw
144
+ speed = node.tpdo[1 ][' Velocity actual value' ].get_phys()
145
+ val = node.tpdo[' Some group.Some subindex' ].get_raw()
146
146
147
147
# Disconnect from CAN bus
148
148
network.sync.stop()
@@ -195,17 +195,15 @@ This library can be used with asyncio.
195
195
196
196
async def main ():
197
197
198
- # Open CAN bus
198
+ # Start with creating a network representing one CAN bus
199
+ network = canopen.Network()
200
+
201
+ # Connect to the CAN bus
199
202
# Arguments are passed to python-can's can.Bus() constructor
200
203
# (see https://python-can.readthedocs.io/en/latest/bus.html).
201
- bus = can.BUS(interface = ' pcan' , bitrate = 1000000 )
202
-
203
- # Create a network representing one CAN bus
204
- network = canopen.Network(bus)
205
-
206
- # Start the notifier to enable canopen to respond to incoming CAN message
204
+ # Note the loop parameter to enable asyncio operation
207
205
loop = asyncio.get_event_loop()
208
- network.notifier = can.Notifier(bus, network.listeners, 1 , loop = loop)
206
+ network.connect( interface = ' pcan ' , bitrate = 1000000 , loop = loop)
209
207
210
208
# Create two independent tasks for two nodes 51 and 52 which will run concurrently
211
209
task1 = asyncio.create_task(my_node(network, 51 , ' /path/to/object_dictionary.eds' ))
0 commit comments