APIs, concepts, guides, and more
userlimit-digital-input-two-condition.cs
/* This sample demonstrates how to configure a user limit triggered by two digital inputs.
Uses AND logic - both inputs must be high for the output to activate.
The RMP controller's User Limits compare two different input bits to specific values (high=1 or low=0).
When both conditions match (using AND logic), the specified output bit is activated (turns high).
In this example:
- Two conditions are configured via UserLimitConditionSet() to monitor two separate inputs
- Both inputs must turn high (1) to trigger the user limit
- When triggered, UserLimitOutputSet() activates the output to high (1)
*/
using RSI.RapidCode; // RSI.RapidCode.dotNET;
Console.WriteLine("📜 User Limit: Digital Input Two Condition");
// get rmp objects
try
{
Helpers.CheckErrors(controller);
// configure user limits
controller.UserLimitCountSet(1); // set the amount of user limits to use
controller.InterruptEnableSet(true); // enable user limit interrupts
// create simulated io using user buffer memory
ulong userBufferAddress = controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSER_BUFFER, 0);
IOPoint input0 = IOPoint.CreateDigitalInput(controller, userBufferAddress, bitNumber: 0);
IOPoint input1 = IOPoint.CreateDigitalInput(controller, userBufferAddress, bitNumber: 1);
IOPoint output0 = IOPoint.CreateDigitalOutput(controller, userBufferAddress, bitNumber: 2);
Helpers.CheckErrors(output0);
// configure first input condition (condition 0)
number: 0,
conditionNumber: 0,
logic: RSIUserLimitLogic.RSIUserLimitLogicEQ,
addressOfUInt32: input0.AddressGet(),
userLimitMask: (uint)input0.MaskGet(),
limitValueUInt32: (uint)input0.MaskGet());
// configure second input condition (condition 1)
number: 0,
conditionNumber: 1,
logic: RSIUserLimitLogic.RSIUserLimitLogicEQ,
addressOfUInt32: input1.AddressGet(),
userLimitMask: (uint)input1.MaskGet(),
limitValueUInt32: (uint)input1.MaskGet());
// configure user limit settings (AND logic for both conditions)
controller.UserLimitConfigSet(
number: 0,
triggerType: RSIUserLimitTriggerType.RSIUserLimitTriggerTypeCONDITION_AND,
action: RSIAction.RSIActionNONE,
actionAxis: 0,
duration: 0);
// configure user limit output
controller.UserLimitOutputSet(
number: 0,
andMask: (uint)output0.MaskGet(),
orMask: (uint)output0.MaskGet(),
outputPtr: output0.AddressGet(),
enabled: true);
Console.WriteLine("Waiting for both inputs to trigger...");
// verify output is initially off
if (output0.Get())
throw new Exception("ERROR: Output should not be triggered yet");
// set first input high (bit 0 only) - AND condition not met
controller.MemorySet(input0.AddressGet(), 0b0001); // only bit 0 is high
if (output0.Get())
throw new Exception("ERROR: Output should not trigger with only one input");
// set BOTH inputs high (bits 0 and 1) - AND condition met
controller.MemorySet(input1.AddressGet(), 0b0011); // both bit 0 AND bit 1 are high
// wait for user limit interrupt to confirm trigger
if (controller.InterruptWait(1000) != RSIEventType.RSIEventTypeUSER_LIMIT)
throw new Exception("ERROR: User limit did not trigger when both inputs were high");
// verify output was activated
if (!output0.Get())
throw new Exception("ERROR: Output should be high after user limit triggered");
Console.WriteLine("✓ User limit triggered successfully - both inputs high, output activated");
// cleanup
controller.UserLimitDisable(0);
output0.Set(false);
Console.WriteLine("\nUser limit digital input two condition complete.");
}
// handle errors as needed
finally
{
controller.Delete(); // dispose
}
static void CheckErrors(RapidCodeObject rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
Definition _helpers.cs:15
Helpers class provides static methods for common tasks in RMP applications.
Definition _helpers.cs:5
uint64_t AddressGet()
Get the Host Address for the I/O point.
void Set(bool state)
Set the state of a Digital Output.
static IOPoint * CreateDigitalInput(Axis *axis, RSIMotorDedicatedIn motorDedicatedInNumber)
Create a Digital Input from an Axis' Dedicated Input bits.
static IOPoint * CreateDigitalOutput(Axis *axis, RSIMotorDedicatedOut motorDedicatedOutNumber)
Create a Digital Output from an Axis' Dedicated Output bits.
bool Get()
Get the state of Digital Input or Output.
int32_t MaskGet()
Get the bit mask for the I/O point.
Represents one specific point: Digital Output, Digital Input, Analog Output, or Analog Input....
Definition rsi.h:11549
void UserLimitDisable(int32_t number)
Disable the processing of a User Limit.
void UserLimitConditionSet(int32_t number, int32_t conditionNumber, RSIUserLimitLogic logic, uint64_t addressOfUInt32, uint32_t userLimitMask, uint32_t limitValueUInt32)
Set the conditions for a User Limit with a 32-bit integer trigger value.
void MemorySet(uint64_t address, int32_t data)
Write a value to controller memory.
static MotionController * Get()
Get an already running RMP EtherCAT controller.
uint64_t AddressGet(RSIControllerAddressType type)
Get the an address for some location on the MotionController.
void UserLimitOutputSet(int32_t number, uint32_t andMask, uint32_t orMask, uint64_t outputPtr, bool enabled)
Configure a User Limit Output block.
void UserLimitConfigSet(int32_t number, RSIUserLimitTriggerType triggerType, RSIAction action, int32_t actionAxis, double duration, bool singleShot)
Configure a User Limit.
void Delete(void)
Delete the MotionController and all its objects.
void UserLimitCountSet(int32_t userLimitCount)
Set the number of processed UserLimits in the MotionController.
void InterruptEnableSet(bool enable)
Control interrupts for this class.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:800
RSIEventType InterruptWait(int32_t milliseconds)
Suspend the current thread until an interrupt arrives from the controller.
RSIControllerAddressType
Used to get firmware address used in User Limits, Recorders, etc.
Definition rsienums.h:405
RSIEventType
Event Types or Status Bits.
Definition rsienums.h:966
RSIUserLimitLogic
Logic options for User Limits.
Definition rsienums.h:646
RSIAction
Action to perform on an Axis.
Definition rsienums.h:1115
RSIUserLimitTriggerType
Trigger types for UserLimits.
Definition rsienums.h:633