RecorderInterrupts.cs
Demonstrates receiving interrupts from the
MotionController when the Recorder's buffer is getting filled.
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 RecorderInterrupts
{
const int X = 0;
const int Y = 1;
const int RECORDER_PERIOD = 1000;
const int INTERRUPT_TIMEOUT = 2000;
MotionController controller;
Axis x;
Axis y;
public enum RecordingIndexes
{
XActualLsb = 0,
XActualMsb,
YActualLsb,
YActualMsb,
}
public class DataRecord
{
public Int64 ActualPositionX = 0;
public Int64 ActualPositionY = 0;
}
[Test]
public void Main()
{
try
{
controller = MotionController.Create();
x = controller.AxisGet(X);
y = controller.AxisGet(Y);
controller.RecorderStop();
controller.RecorderPeriodSet(RECORDER_PERIOD);
controller.RecorderDataCountSet( Enum.GetValues(typeof(RecordingIndexes)).Length);
controller.RecorderDataAddressSet((int)RecordingIndexes.XActualLsb, x.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeACTUAL_POSITION_LSB));
controller.RecorderDataAddressSet((int)RecordingIndexes.XActualMsb, x.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeACTUAL_POSITION_MSB));
controller.RecorderDataAddressSet((int)RecordingIndexes.YActualLsb, y.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeACTUAL_POSITION_LSB));
controller.RecorderDataAddressSet((int)RecordingIndexes.YActualMsb, y.AddressGet(RSIAxisAddressType.RSIAxisAddressTypeACTUAL_POSITION_MSB));
controller.RecorderBufferHighCountSet(1);
controller.InterruptEnableSet(true);
controller.RecorderStart();
bool done = false;
while (!done)
{
RSIEventType interruptType = controller.InterruptWait(INTERRUPT_TIMEOUT);
switch (interruptType)
{
case RSIEventType.RSIEventTypeTIMEOUT:
done = true;
break;
case RSIEventType.RSIEventTypeRECORDER_HIGH:
ReadRecordedData();
break;
default:
Console.WriteLine(controller.InterruptNameGet());
break;
}
}
controller.RecorderStop();
controller.InterruptEnableSet(false);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
public void ReadRecordedData()
{
while (controller.RecorderRecordCountGet() > 0)
{
controller.RecorderRecordDataRetrieve();
DataRecord record = new DataRecord();
record.ActualPositionX = ConvertRecordedPositionsTo64(controller.RecorderRecordDataValueGet((int)RecordingIndexes.XActualLsb), controller.RecorderRecordDataValueGet((int)RecordingIndexes.XActualMsb));
record.ActualPositionY = ConvertRecordedPositionsTo64(controller.RecorderRecordDataValueGet((int)RecordingIndexes.YActualLsb), controller.RecorderRecordDataValueGet((int)RecordingIndexes.YActualMsb));
Console.WriteLine("X: " + record.ActualPositionX + " Y: " + record.ActualPositionY.ToString());
}
}
public Int64 ConvertRecordedPositionsTo64(int lsb, int msb)
{
return (Int64)((((UInt64)msb) << 32) | (UInt32)lsb);
}
}
}