Learn how to work with Input/Output operations in C#.
- 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: General Purpose
Learn how to access General Purpose IO 📖 on EtherCAT network nodes. Shows how to read and write digital and analog inputs/outputs using NetworkNode methods.
bool dIn = node.DigitalInGet(digitalInNumber: 0);
bool dOut = node.DigitalOutGet(digitalOutNumber: 0);
node.DigitalOutSet(digitalOutNumber: 0, state: dOut);
int aIn = node.AnalogInGet(analogChannel: 0);
int aOut = node.AnalogOutGet(analogChannel: 0);
node.AnalogOutSet(analogChannel: 0, analogValue: aOut);
Source: io-general-purpose.cs
📜 IO: Dedicated
Learn how to access Dedicated IO 📖 on an axis. Shows how to read hardware limits, home switch, amp fault, and amp enable signals using both generic and specific methods.
Console.WriteLine("RSIMotorDedicatedInLIMIT_HW_NEG: {0} and {1}",
Console.WriteLine("RSIMotorDedicatedInLIMIT_HW_POS: {0} and {1}",
Console.WriteLine("RSIMotorDedicatedInHOME: {0} and {1}",
Console.WriteLine("RSIMotorDedicatedInAMP_FAULT: {0} and {1}",
Console.WriteLine("RSIMotorDedicatedInAMP_ACTIVE: {0} and {1}",
Source: io-dedicated.cs
📜 IO: Network PDOs and SDOs
Learn how to read network inputs and outputs PDO vs. SDO 📖 . Shows how to enumerate through all network inputs/outputs and read their properties including size, offset, name, and value.
Console.WriteLine($"Network Input Count: {inputCount}");
for (int i = 0; i < inputCount; i++)
{
Console.WriteLine($"Input {i}: {name}, Size: {size}, Offset: {offset}, Value: {value}");
}
Console.WriteLine($"Network Output Count: {outputCount}");
for (int i = 0; i < outputCount; i++)
{
Console.WriteLine($"Output {i}: {name}, Size: {size}, Offset: {offset}, Value: {value}");
}
Source: io-network-pdo-sdo.cs
📜 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.
const int NODE_INDEX = 0;
const int OUTPUT_INDEX = 0;
Console.WriteLine($"Output {OUTPUT_INDEX} set to: false");
bool outputValue = output0.
Get();
Console.WriteLine($"Output {OUTPUT_INDEX} value: {outputValue}");
Console.WriteLine($"Output {OUTPUT_INDEX} set to: true");
outputValue = output0.
Get();
Console.WriteLine($"Output {OUTPUT_INDEX} value: {outputValue}");
Source: io-iopoint.cs
📜 IO: IOPoint User Buffer
Learn how to create simulated IOPoint 📖 objects using user buffer memory. Shows how to create IOPoint objects from base memory addresses and test their functionality without actual hardware.
const int INPUT_INDEX = 0;
const int OUTPUT_INDEX = 1;
bool outVal = output0.
Get();
Console.WriteLine($"Output 0 value: {outVal}");
bool inVal = input0.
Get();
Console.WriteLine($"Input 0 memory set to 1, value: {inVal}");
Console.WriteLine($"Input 0 memory set to 0, value: {inVal}");
Source: io-iopoint-user-buffer.cs
📜 IO: Sync Outputs
Learn how to set up Sync Outputs for Streaming Motion Sync Outputs 📖 . Shows how to configure outputs to trigger at specific motion element IDs during streaming motion.
const int TOTAL_POINTS = 4;
const int EMPTY_CT = -1;
const int OUTPUT_INDEX = 0;
const int NODE_INDEX = 0;
double[] positions = [1.0, 2.0, 3.0, 4.0];
double[] times = [0.5, 0.1, 0.2, 0.4];
int outputEnableID = 2;
int outputDisableID = 3;
Console.WriteLine($"Starting streaming motion with {TOTAL_POINTS} points");
Console.WriteLine($"Output will go HIGH at element ID {outputEnableID}");
Console.WriteLine($"Output will go LOW at element ID {outputDisableID}");
axis.
MovePT(
RSIMotionType.RSIMotionTypePT, positions, times, TOTAL_POINTS, EMPTY_CT,
false,
true);
{
bool outputState = output0.
Get();
Console.WriteLine($"Motion Element: {currentElement}, Output State: {outputState}");
Thread.Sleep(50);
}
Source: io-sync-outputs.cs