UserLimitDigitalInputAction.cpp
#include "rsi.h" // Import our RapidCode Library.
#include "HelperFunctions.h" // Import our SampleApp helper functions.
void UserLimitDigitalInputActionMain()
{
using namespace RSI::RapidCode;
const int IO_NODE_NUMBER = 1;// which SqNode to use for I/O?
const int AXIS_NUMBER = 3;// which Axis number to abort?
const int USER_LIMIT = 0;// which user limit to use?
const int CONDITION = 0;// which condition to use (0 or 1)
const int INPUT_BIT_NUMBER = 7;// which input bit?
// RapidCode interface classes
IO *io;
IOPoint *digitalInput;
// Initialize MotionController class.
SampleAppsCPP::HelperFunctions::CheckErrors(controller);
try
{
SampleAppsCPP::HelperFunctions::StartTheNetwork(controller); // [Helper Function] Initialize the network.
// initialize the I/O class
io = controller->IOGet(IO_NODE_NUMBER);
SampleAppsCPP::HelperFunctions::CheckErrors(io);
digitalInput = IOPoint::CreateDigitalInput(io, INPUT_BIT_NUMBER);
// configure user limit to evaluate input bit
controller->UserLimitConditionSet(USER_LIMIT,
CONDITION,
digitalInput->AddressGet(),
digitalInput->MaskGet(),
digitalInput->MaskGet());
// enable the user limit, generate ESTOP_ABORT action when input is turned on
printf("Waiting for the input bit to go high...\n");
printf("\nPress Any Key To Exit.\n");
// wait for user limit to trigger
while (controller->OS->KeyGet((int32_t)RSIWait::RSIWaitPOLL) < 0)
{
printf("User Limit state is %d\r", controller->UserLimitStateGet(USER_LIMIT));
controller->OS->Sleep(1);
}
// disable User Limit
controller->UserLimitDisable(USER_LIMIT);
}
catch (RsiError const& rsiError)
{
printf("Text: %s\n", rsiError.text);
}
controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
system("pause"); // Allow time to read Console.
}