APIs, concepts, guides, and more
HelloRapidCode.py
1
14
15
16
17import os
18import sys
19
20import RapidCodeHelpers as helpers # The check_errors() and check_errors() helpers provided on our API SampleApp documentation pages
21
22rapidcode_dir = helpers.find_rapid_code_directory()
23
24#Import the ntx.dll from INtime
25os.add_dll_directory("c:\\Program Files (x86)\\INtime\\bin")#ntx.dll
26
27#Import the RapidCode.py file (Path to your rapidcode install directory)
28sys.path.append(rapidcode_dir)
29
30import RapidCode # The RapidCode.py wrapper located in your RMP install directory
31
32
33def print_topology(controller:RapidCode.MotionController):
34 stringBuilder = []
35 overview = "EtherCAT: {} Nodes, {} {}".format(controller.NetworkNodeCountGet(), controller.NetworkTypeGet(), controller.NetworkStateGet())
36 stringBuilder.append(overview)
37
38 Nodes = []
39 for i in range(controller.NetworkNodeCountGet()):
40 io = controller.IOGet(i)
41 helpers.check_errors(io)
42 if(io.NetworkNode.Exists()):
43 Nodes.append(io.NetworkNode)
44
45
46 for node in Nodes:
47 stringBuilder.append("") # for spacing
48 stringBuilder.append("Node[{}] - {} ______________________________________________".format(node.NumberGet(), node.NameGet()))
49 stringBuilder.append(" Vendor: {} ".format(node.VendorNameGet() + "Product: {}".format(node.ProductNameGet())))
50 stringBuilder.append(" VendorID: 0x{:08X} ProductCode: 0x{:08X}".format(node.VendorIdGet(), node.ProductCodeGet()))
51 stringBuilder.append(" HardwareRev: 0x{:08X} SerialNumber: {}".format(node.RevisionGet(), node.SerialNumberGet()))
52 stringBuilder.append(" StationAlias: 0x{:08X} AxisCount: {}".format(node.StationAliasGet(), node.AxisCountGet()))
53 stringBuilder.append(" SegmentCount: {}".format(node.SegmentCountGet()))
54 stringBuilder.append(" DI: {} DO: {} AI: {} AO: {}".format(node.DigitalInCountGet(), node.DigitalOutCountGet(), node.AnalogInCountGet(), node.AnalogOutCountGet()))
55
56 stringBuilder.append("") # spacing
57 pdoInputs = controller.NetworkInputCountGet()
58 stringBuilder.append("NetworkInputs count: {} _________________________________".format(pdoInputs))
59 for i in range(pdoInputs):
60 stringBuilder.append(" [{}] - {} Bits: {}".format(i, controller.NetworkInputNameGet(i).ljust(70), controller.NetworkInputBitSizeGet(i)))
61
62 pdoOutputs = controller.NetworkOutputCountGet()
63 stringBuilder.append("NetworkOutputs count: {} _________________________________".format(pdoOutputs))
64 for i in range(pdoOutputs):
65 stringBuilder.append(" [{}] - {} Bits: {}".format(i, controller.NetworkOutputNameGet(i).ljust(70), controller.NetworkOutputBitSizeGet(i)))
66
67 print("\n".join(stringBuilder))
68
69
70
71def main():
72 print("Hello, RapidCode.")
73
74 motionController:RapidCode.MotionController = RapidCode.MotionController.CreateFromSoftware(rapidcode_dir)
75 print("This object is a "+str(type(motionController)))#When creating your RapidCode objects (Axis, MultiAxis, MotionController,ect) we recommend specifying the type with my_object_name:RapidCode.*** (MotionController,Axis, Ect.) so that your IDE can autocomplete class member names.
76
77 #motionController=RapidCode.RapidCodeObject(motionController)
78 print("MotionController creation error count: ", motionController.ErrorLogCountGet())
79 helpers.check_errors(motionController)
80
81 print("RapidCode Version: ", motionController.VersionGet())
82 print("Serial Number: ", motionController.SerialNumberGet())
83 print("Axis Count: ", motionController.AxisCountGet())
84
85 if motionController.NetworkStateGet() == RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL:
86 print_topology(motionController)
87
89
90
91if __name__ == '__main__':
92 main()