/* userLimit.cpp Copyright(c) 1998-2009 by Robotic Systems Integration, Inc. All rights reserved. This software contains proprietary and confidential information of Robotic Systems Integration, Inc. (RSI) and its suppliers. Except as may be set forth in the license agreement under which this software is supplied, disclosure, reproduction, or use with controls other than those provided by RSI or suppliers for RSI is strictly prohibited without the prior express written consent of Robotic Systems Integration. This sample code shows how to configure the XMP controller's User Limits to compare an input bit to a specific pattern. If the pattern matches, then the specified output bit is activated and a User Event is generated to the host. For any questions regarding this sample code please visit our documentation at www.roboticsys.com. Warning! This is a sample program to assist in the integration of your motion controller with your application. It may not contain all of the logic and safety features that your application requires. */ #include "rsi.h" using namespace RSI::RapidCode::SynqNet; // which controller to use? (0 is first PCI controller) #define CONTROLLER_NUMBER 0 // which axis to use? #define AXIS_NUMBER 0 // which user limit to use? #define USER_LIMIT RSIEventTypeLIMIT_USER0 // which condition to use (0 or 1) #define CONDITION 0 void userLimitMain() { MotionController *controller; Axis *axis; // which input bit? IOPoint *inputBit; // which output bit? IOPoint *outputBit; try { // initialize MotionController class controller = MotionController::CreateFromBoard(CONTROLLER_NUMBER); // initialize Axis class axis = controller->AxisGet(AXIS_NUMBER); // we will use Interrupts axis->InterruptEnableSet(true); inputBit->CreateDigitalInput(axis,RSIMotorGeneralIo::RSIMotorGeneralIo2); // XCVR_C outputBit->CreateDigitalOutput(axis, RSIMotorGeneralIo::RSIMotorGeneralIo0); // XCVR_A // configure user limit to evaluate input bit axis->UserLimitConditionSet(USER_LIMIT, CONDITION, RSIXmpLimitTypeBIT_CMP, inputBit->AddressGet(), inputBit->MaskGet() , inputBit->MaskGet()); // configure user limit to set OUTPUT_BIT_MASK high when limit is true axis->UserLimitOutputSet(USER_LIMIT, 0xFFFFFFFF, outputBit->MaskGet(), outputBit->AddressGet(), true); // alternatively, if you wanted to clear the bit (turn it off), use this code instead: //axis->UserLimitOutputSet(USER_LIMIT, // ~(outputBit->MaskGet()), // 0, // outputBit->AddressGet(), // true); // enable the user limit axis->UserLimitConfigSet(USER_LIMIT, RSIXmpStatusLIMIT, RSIXmpLogicSINGLE , 0.0); printf("Waiting for the input bit to go high...\n"); // wait for user limit to trigger while(axis->InterruptWait(RSIWaitFOREVER) != USER_LIMIT) { } printf("Input triggered!\n"); // disable User Limit axis->UserLimitConfigSet(USER_LIMIT, RSIXmpStatusLIMIT, RSIXmpLogicNEVER , 0.0); // set output low outputBit->Set(false); } catch (RsiError *rsiError) { printf("Text: %s\n", rsiError->text); } return ; }