IOPointInterrupts.cs
Generate interrupts based on I/O points
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using RSI.RapidCode.SynqNet.dotNET;
using RSI.RapidCode.SynqNet.dotNET.Enums;
namespace SampleApplications
{
[TestFixture]
public class IOPointInterrupts
{
private const int PHANTOM_AXIS_NUMBER = 0;
const int BIT_NUMBER = 0;
const int TIMEOUT_MILLISECONDS = 10000;
private const RSIEventType BIT_ON = RSIEventType.RSIEventTypeLIMIT_USER0;
private const RSIEventType BIT_OFF = RSIEventType.RSIEventTypeLIMIT_USER1;
private void ConfigureUserLimit(IOPoint point, Axis axis, RSIEventType userLimit, bool triggerState)
{
int limitValue = point.MaskGet();
if (triggerState == false)
{
limitValue = 0;
}
axis.UserLimitConditionSet(userLimit, 0, RSIXmpLimitType.RSIXmpLimitTypeBIT_CMP,
point.AddressGet(), point.MaskGet(), limitValue);
axis.UserLimitConfigSet(userLimit, RSIXmpStatus.RSIXmpStatusLIMIT, RSIXmpLogic.RSIXmpLogicSINGLE, 0.0);
}
[Test]
public void Main()
{
try
{
MotionController controller = MotionController.Create();
IOPoint bit = IOPoint.CreateDigitalOutput(controller, BIT_NUMBER);
Axis phantom = controller.AxisGet(PHANTOM_AXIS_NUMBER);
bool done = false;
phantom.ClearFaults();
Assert.That(phantom.StateGet(), Is.EqualTo(RSIState.RSIStateIDLE));
ConfigureUserLimit(bit, phantom, BIT_ON, true);
ConfigureUserLimit(bit, phantom, BIT_OFF, false);
phantom.InterruptEnableSet(true);
controller.InterruptEnableSet(true);
while (!done)
{
RSIEventType interrupt = controller.InterruptWait(TIMEOUT_MILLISECONDS);
switch (interrupt)
{
case RSIEventType.RSIEventTypeTIMEOUT:
done = true;
Console.WriteLine("Timeout!");
break;
case BIT_ON:
Console.WriteLine("Bit turned on.");
break;
case BIT_OFF:
Console.WriteLine("Bit turned off.");
break;
default:
break;
}
}
phantom.UserLimitDisable(BIT_ON);
phantom.UserLimitDisable(BIT_OFF);
controller.InterruptEnableSet(false);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}