APIs, concepts, guides, and more
controller-create.py
Note
See Controller: Create 📜 for a detailed explanation of this sample code.
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.
1""" Sample application that creates an RMP Motion Controller object and prints its information.
2"""
3
4from _imports import RapidCode, helpers
5
6
7# METHODS
8def print_topology(controller:RapidCode.MotionController):
9 stringBuilder = []
10 overview = "EtherCAT: {} Nodes, {} {}".format(controller.NetworkNodeCountGet(), controller.NetworkTypeGet(), controller.NetworkStateGet())
11 stringBuilder.append(overview)
12
13 Nodes = []
14 for i in range(controller.NetworkNodeCountGet()):
15 io = controller.IOGet(i)
16 helpers.check_errors(io)
17 if(io.NetworkNode.Exists()):
18 Nodes.append(io.NetworkNode)
19
20 for node in Nodes:
21 stringBuilder.append("") # for spacing
22 stringBuilder.append("Node[{}] - {} ______________________________________________".format(node.NumberGet(), node.NameGet()))
23 stringBuilder.append(" Vendor: {} ".format(node.VendorNameGet() + "Product: {}".format(node.ProductNameGet())))
24 stringBuilder.append(" VendorID: 0x{:08X} ProductCode: 0x{:08X}".format(node.VendorIdGet(), node.ProductCodeGet()))
25 stringBuilder.append(" HardwareRev: 0x{:08X} SerialNumber: {}".format(node.RevisionGet(), node.SerialNumberGet()))
26 stringBuilder.append(" StationAlias: 0x{:08X} AxisCount: {}".format(node.StationAliasGet(), node.AxisCountGet()))
27 stringBuilder.append(" SegmentCount: {}".format(node.SegmentCountGet()))
28 stringBuilder.append(" DI: {} DO: {} AI: {} AO: {}".format(node.DigitalInCountGet(), node.DigitalOutCountGet(), node.AnalogInCountGet(), node.AnalogOutCountGet()))
29
30 stringBuilder.append("") # spacing
31 pdoInputs = controller.NetworkInputCountGet()
32 stringBuilder.append("NetworkInputs count: {} _________________________________".format(pdoInputs))
33 for i in range(pdoInputs):
34 stringBuilder.append(" [{}] - {} Bits: {}".format(i, controller.NetworkInputNameGet(i).ljust(70), controller.NetworkInputBitSizeGet(i)))
35
36 pdoOutputs = controller.NetworkOutputCountGet()
37 stringBuilder.append("NetworkOutputs count: {} _________________________________".format(pdoOutputs))
38 for i in range(pdoOutputs):
39 stringBuilder.append(" [{}] - {} Bits: {}".format(i, controller.NetworkOutputNameGet(i).ljust(70), controller.NetworkOutputBitSizeGet(i)))
40
41 print("\n".join(stringBuilder))
42
43
44# MAIN
45print("⬤ Controller Create")
46
47creation_params: RapidCode.CreationParameters = helpers.get_creation_parameters()
48controller: RapidCode.MotionController = RapidCode.MotionController.Create(creation_params)
49helpers.check_errors(controller)
50
51# type hints enable IDE autocomplete for RapidCode objects
52print(f"This object is a {type(controller)}")
53
54# print some controller info
55print(f"RapidCode Version: {controller.VersionGet()}")
56print(f"Serial Number: {controller.SerialNumberGet()}")
57print(f"Axis Count: {controller.AxisCountGet()}")
58
59# print network topology
60if controller.NetworkStateGet() == RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL:
61 print_topology(controller)
62
63# clean up
64controller.Delete()