APIs, concepts, guides, and more
Hello RapidCode

Basics for getting up and running with RapidCode for Python.


📜 Hello RapidCode

import os
import sys
import RapidCodeHelpers as helpers # The check_errors() and check_errors() helpers provided on our API SampleApp documentation pages
rapidcode_dir = helpers.find_rapid_code_directory()
#Import the ntx.dll from INtime
os.add_dll_directory("c:\\Program Files (x86)\\INtime\\bin")#ntx.dll
#Import the RapidCode.py file (Path to your rapidcode install directory)
sys.path.append(rapidcode_dir)
import RapidCode # The RapidCode.py wrapper located in your RMP install directory
def print_topology(controller:RapidCode.MotionController):
stringBuilder = []
overview = "EtherCAT: {} Nodes, {} {}".format(controller.NetworkNodeCountGet(), controller.NetworkTypeGet(), controller.NetworkStateGet())
stringBuilder.append(overview)
Nodes = []
for i in range(controller.NetworkNodeCountGet()):
io = controller.IOGet(i)
helpers.check_errors(io)
if(io.NetworkNode.Exists()):
Nodes.append(io.NetworkNode)
for node in Nodes:
stringBuilder.append("") # for spacing
stringBuilder.append("Node[{}] - {} ______________________________________________".format(node.NumberGet(), node.NameGet()))
stringBuilder.append(" Vendor: {} ".format(node.VendorNameGet() + "Product: {}".format(node.ProductNameGet())))
stringBuilder.append(" VendorID: 0x{:08X} ProductCode: 0x{:08X}".format(node.VendorIdGet(), node.ProductCodeGet()))
stringBuilder.append(" HardwareRev: 0x{:08X} SerialNumber: {}".format(node.RevisionGet(), node.SerialNumberGet()))
stringBuilder.append(" StationAlias: 0x{:08X} AxisCount: {}".format(node.StationAliasGet(), node.AxisCountGet()))
stringBuilder.append(" SegmentCount: {}".format(node.SegmentCountGet()))
stringBuilder.append(" DI: {} DO: {} AI: {} AO: {}".format(node.DigitalInCountGet(), node.DigitalOutCountGet(), node.AnalogInCountGet(), node.AnalogOutCountGet()))
stringBuilder.append("") # spacing
pdoInputs = controller.NetworkInputCountGet()
stringBuilder.append("NetworkInputs count: {} _________________________________".format(pdoInputs))
for i in range(pdoInputs):
stringBuilder.append(" [{}] - {} Bits: {}".format(i, controller.NetworkInputNameGet(i).ljust(70), controller.NetworkInputBitSizeGet(i)))
pdoOutputs = controller.NetworkOutputCountGet()
stringBuilder.append("NetworkOutputs count: {} _________________________________".format(pdoOutputs))
for i in range(pdoOutputs):
stringBuilder.append(" [{}] - {} Bits: {}".format(i, controller.NetworkOutputNameGet(i).ljust(70), controller.NetworkOutputBitSizeGet(i)))
print("\n".join(stringBuilder))
def main():
print("Hello, RapidCode.")
motionController:RapidCode.MotionController = RapidCode.MotionController.CreateFromSoftware(rapidcode_dir)
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.
#motionController=RapidCode.RapidCodeObject(motionController)
print("MotionController creation error count: ", motionController.ErrorLogCountGet())
helpers.check_errors(motionController)
print("RapidCode Version: ", motionController.VersionGet())
print("Serial Number: ", motionController.SerialNumberGet())
print("Axis Count: ", motionController.AxisCountGet())
if motionController.NetworkStateGet() == RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL:
print_topology(motionController)