APIs, concepts, guides, and more
IO: Input & Output

Learn how to work with Input/Output operations in Python.

Warning
This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.

The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.


In this page:


📜 IO: IOPoint Objects

Learn how to use IOPoint 📖 objects to read and write network data. Shows how to create IOPoint objects for digital outputs and use them to control IO.

""" This sample demonstrates how to use IOPoint objects to read and write network data.
Shows how to create IOPoint objects for digital outputs and use them to control IO.
Requires an EtherCAT network with nodes that have digital outputs.
"""
import sys
from _imports import RapidCode, helpers, constants
print("⬤ IO: IOPoint Objects")
exit_code = 0
# get/create the motion controller
creation_params: RapidCode.CreationParameters = helpers.get_creation_parameters()
controller: RapidCode.MotionController = RapidCode.MotionController.Create(creation_params)
try:
helpers.check_errors(controller)
NODE_INDEX = 0 # the EtherCAT Node we will be communicating with
OUTPUT_INDEX = 0 # the PDO Index in that Node
# Create IOPoint for digital output. Either simulate IO with a user buffer on the controller...
userBufferAddress = controller.AddressGet(RapidCode.RSIControllerAddressType_RSIControllerAddressTypeUSER_BUFFER, 0)
output0 = RapidCode.IOPoint.CreateDigitalOutput(controller, userBufferAddress, OUTPUT_INDEX)
# ...or use the following lines to create the IOPoint from NetworkNode IO instead (must have actual hardware)
# if (controller.NetworkStateGet() != RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL):
# raise Exception("Must have OPERATIONAL network to use NetworkNode IOPoints.")
# network_node = controller.NetworkNodeGet(NODE_INDEX)
# helpers.check_errors(network_node)
# output0 = RapidCode.IOPoint.CreateDigitalOutput(network_node, OUTPUT_INDEX)
# set the output to false
output0.Set(False)
print(f"Output {OUTPUT_INDEX} set to: False")
# wait one sample for the change to take effect
controller.SampleWait(1)
# read back the value
output_value = output0.Get()
print(f"Output {OUTPUT_INDEX} value: {output_value}")
# set the output to true
output0.Set(True)
print(f"Output {OUTPUT_INDEX} set to: True")
controller.SampleWait(1)
output_value = output0.Get()
print(f"Output {OUTPUT_INDEX} value: {output_value}")
exit_code = constants.EXIT_SUCCESS
except Exception as e:
print(f"❌ Error: {e}")
exit_code = constants.EXIT_FAILURE
finally:
controller.Delete()
sys.exit(exit_code)