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
6import sys
7from _imports import RapidCode, helpers, constants
8
9print("⬤ IO: IOPoint Objects")
10
11exit_code = 0
12
13
14creation_params: RapidCode.CreationParameters = helpers.get_creation_parameters()
15controller: RapidCode.MotionController = RapidCode.MotionController.Create(creation_params)
16
17try:
18 helpers.check_errors(controller)
19
20 NODE_INDEX = 0
21 OUTPUT_INDEX = 0
22
23
24 userBufferAddress = controller.AddressGet(RapidCode.RSIControllerAddressType_RSIControllerAddressTypeUSER_BUFFER, 0)
25 output0 = RapidCode.IOPoint.CreateDigitalOutput(controller, userBufferAddress, OUTPUT_INDEX)
26
27
28
29
30
31
32
33
34 output0.Set(False)
35 print(f"Output {OUTPUT_INDEX} set to: False")
36
37
38 controller.SampleWait(1)
39
40
41 output_value = output0.Get()
42 print(f"Output {OUTPUT_INDEX} value: {output_value}")
43
44
45 output0.Set(True)
46 print(f"Output {OUTPUT_INDEX} set to: True")
47
48 controller.SampleWait(1)
49 output_value = output0.Get()
50 print(f"Output {OUTPUT_INDEX} value: {output_value}")
51
52 exit_code = constants.EXIT_SUCCESS
53except Exception as e:
54 print(f"❌ Error: {e}")
55 exit_code = constants.EXIT_FAILURE
56finally:
57 controller.Delete()
58
59sys.exit(exit_code)