using NUnit.Framework;
using System;
[TestFixture]
[Category("Software")]
class InputOutput : SampleAppTestBase
{
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void DedicatedIO()
{
Console.WriteLine("RSIMotorDedicatedInLIMIT_HW_NEG: {0} and {1}",
axis.NegativeLimitGet());
Console.WriteLine("RSIMotorDedicatedInLIMIT_HW_POS: {0} and {1}",
axis.PositiveLimitGet());
Console.WriteLine("RSIMotorDedicatedInHOME: {0} and {1}",
axis.HomeSwitchGet());
Console.WriteLine("RSIMotorDedicatedInAMP_FAULT: {0} and {1}",
axis.AmpFaultGet());
Console.WriteLine("RSIMotorDedicatedInAMP_ACTIVE: {0} and {1}",
axis.AmpEnableGet());
}
[Test, Timeout(Constants.MAX_TEST_TIME)]
public void NetworkInputsAndOutputs()
{
int inputCount = controller.NetworkInputCountGet();
for (int i = 0; i < inputCount; i++)
{
int size = controller.NetworkInputBitSizeGet(i);
int offset = controller.NetworkInputBitOffsetGet(i);
string name = controller.NetworkInputNameGet(i);
UInt64 value = controller.NetworkInputValueGet(i);
}
int outputCount = controller.NetworkOutputCountGet();
for (int i = 0; i < outputCount; i++)
{
int size = controller.NetworkOutputBitSizeGet(i);
int offset = controller.NetworkOutputBitOffsetGet(i);
string name = controller.NetworkOutputNameGet(i);
UInt64 value = controller.NetworkOutputSentValueGet(i);
controller.NetworkOutputOverrideValueSet(i, value);
}
}
[Test]
public void IOPoints()
{
const int NODE_INDEX = 0;
const int OUTPUT_INDEX = 0;
IOPoint output0 = IOPoint.CreateDigitalOutput(controller.IOGet(NODE_INDEX), OUTPUT_INDEX);
output0.Set(false);
controller.SampleWait(1);
Assert.False(output0.Get(), "The getter function should return a value equal to false");
}
[Test]
public void IOPointUserBuffer()
{
const int INPUT_INDEX = 0;
const int OUTPUT_INDEX = 1;
IOPoint input0 = IOPoint.CreateDigitalInput(controller, userBufferAddress, INPUT_INDEX);
IOPoint output0 = IOPoint.CreateDigitalOutput(controller, userBufferAddress, OUTPUT_INDEX);
output0.Set(false);
Assert.False(output0.Get(), "The getter function should return a value equal to false");
output0.Set(true);
Assert.True(output0.Get(), "The getter function should return a value equal to true");
controller.MemorySet(input0.AddressGet(), 0);
Assert.False(input0.Get(), "The getter function should return a value equal to false");
controller.MemorySet(input0.AddressGet(), 1);
Assert.True(input0.Get(), "The getter function should return a value equal to true");
}
[Test]
public void SingleAxisSyncOutputs()
{
const int TOTAL_POINTS = 4;
const int EMPTY_CT = -1;
const int OUTPUT_INDEX = 0;
const int NODE_INDEX = 0;
double[] positions = { 1.0, 2.0, 3.0, 4.0 };
double[] times = { 0.5, 0.1, 0.2, 0.4 };
int outputEnableID = 2;
int outputDisableID = 3;
IOPoint output0 = IOPoint.CreateDigitalOutput(controller.IOGet(NODE_INDEX), OUTPUT_INDEX);
output0.Set(false);
axis.StreamingOutputsEnableSet(true);
axis.StreamingOutputAdd(output0, true, outputEnableID);
axis.StreamingOutputAdd(output0, false, outputDisableID);
axis.MovePT(
RSIMotionType.RSIMotionTypePT, positions, times, TOTAL_POINTS, EMPTY_CT,
false,
true);
while (!axis.MotionDoneGet())
{
if (axis.MotionIdExecutingGet() > outputEnableID && axis.CommandPositionGet() < outputEnableID)
{
Assert.AreEqual(output0.Get(), true, "The output should be triggered");
}
else
{
Assert.AreEqual(output0.Get(), false, "The output should NOT be triggered");
}
}
axis.StreamingOutputsEnableSet(false);
axis.AmpEnableSet(false);
}
}