APIs, concepts, guides, and more
io-iopoint.py
1""" This sample demonstrates how to use IOPoint objects to read and write network data.
2 Shows how to create IOPoint objects for digital outputs and use them to control IO.
3 Requires an EtherCAT network with nodes that have digital outputs.
4"""
5
6from _imports import RapidCode, helpers
7
8print("⬤ IO: IOPoint Objects")
9
10# get/create the motion controller
11creation_params: RapidCode.CreationParameters = helpers.get_creation_parameters()
12controller: RapidCode.MotionController = RapidCode.MotionController.Create(creation_params)
13helpers.check_errors(controller)
14
15NODE_INDEX = 0 # the EtherCAT Node we will be communicating with
16OUTPUT_INDEX = 0 # the PDO Index in that Node
17
18# create IOPoint for digital output - automatically gets memory index of specified node and output index
19output0 = RapidCode.IOPoint.CreateDigitalOutput(controller.NetworkNodeGet(NODE_INDEX), OUTPUT_INDEX)
20
21# set the output to false
22output0.Set(False)
23print(f"Output {OUTPUT_INDEX} set to: False")
24
25# wait one sample for the change to take effect
26controller.SampleWait(1)
27
28# read back the value
29output_value = output0.Get()
30print(f"Output {OUTPUT_INDEX} value: {output_value}")
31
32# set the output to true
33output0.Set(True)
34print(f"Output {OUTPUT_INDEX} set to: True")
35
36controller.SampleWait(1)
37output_value = output0.Get()
38print(f"Output {OUTPUT_INDEX} value: {output_value}")
39
40controller.Delete()