APIs, concepts, guides, and more
InputOutput.cs
1
54using RSI.RapidCode.dotNET; // Import our RapidCode Library.
55using NUnit.Framework;
56using System;
57
58#if DOXYGEN // RSI internal documentation use only
59using RSI.RapidCode;
60#endif
61
63[TestFixture]
64[Category("Software")]
65class InputOutput : SampleAppTestBase
66 {
67 [Test, Timeout(Constants.MAX_TEST_TIME)]
68 public void DedicatedIO()
69 {
71 // Retrieve dedicated inputs with generic and specific function.
72 Console.WriteLine("RSIMotorDedicatedInLIMIT_HW_NEG: {0} and {1}",
73 axis.DedicatedInGet(RSIMotorDedicatedIn.RSIMotorDedicatedInLIMIT_HW_NEG),
74 axis.NegativeLimitGet());
75
76 Console.WriteLine("RSIMotorDedicatedInLIMIT_HW_POS: {0} and {1}",
77 axis.DedicatedInGet(RSIMotorDedicatedIn.RSIMotorDedicatedInLIMIT_HW_POS),
78 axis.PositiveLimitGet());
79
80 Console.WriteLine("RSIMotorDedicatedInHOME: {0} and {1}",
81 axis.DedicatedInGet(RSIMotorDedicatedIn.RSIMotorDedicatedInHOME),
82 axis.HomeSwitchGet());
83
84 Console.WriteLine("RSIMotorDedicatedInAMP_FAULT: {0} and {1}",
85 axis.DedicatedInGet(RSIMotorDedicatedIn.RSIMotorDedicatedInAMP_FAULT),
86 axis.AmpFaultGet());
87
88 Console.WriteLine("RSIMotorDedicatedInAMP_ACTIVE: {0} and {1}",
89 axis.DedicatedInGet(RSIMotorDedicatedIn.RSIMotorDedicatedInAMP_ACTIVE),
90 axis.AmpEnableGet());
92 }
93
94 [Test, Timeout(Constants.MAX_TEST_TIME)]
95 public void NetworkInputsAndOutputs()
96 {
98 // Get Input Values
99 int inputCount = controller.NetworkInputCountGet(); // Get number of Network Inputs (PDOs)
100
101 for (int i = 0; i < inputCount; i++)
102 {
103 int size = controller.NetworkInputBitSizeGet(i); // Read Input BitSize
104 int offset = controller.NetworkInputBitOffsetGet(i); // Read Input BitOffset
105 string name = controller.NetworkInputNameGet(i); // Read Input Name
106 UInt64 value = controller.NetworkInputValueGet(i); // Read Input Value
107 }
108
109 // Get Output Values
110 int outputCount = controller.NetworkOutputCountGet(); // Get number of Network Outputs (SDOs)
111
112 for (int i = 0; i < outputCount; i++)
113 {
114 int size = controller.NetworkOutputBitSizeGet(i); // Read Output BitSize
115 int offset = controller.NetworkOutputBitOffsetGet(i); // Read Output BitOffset
116 string name = controller.NetworkOutputNameGet(i); // Read Output Name
117 UInt64 value = controller.NetworkOutputSentValueGet(i); // Read Output Value
118 controller.NetworkOutputOverrideValueSet(i, value);
119 }
121 }
122
123
124 //TODO expand examples once iopoint is expanded.
125 [Test]
126 public void IOPoints()
127 {
130 const int NODE_INDEX = 0; // The EtherCAT Node we will be communicating with
131 //const int INPUT_INDEX = 0; // The PDO Index in that Node
132 const int OUTPUT_INDEX = 0; // The PDO Index in that Node
133
134 IOPoint output0 = IOPoint.CreateDigitalOutput(controller.NetworkNodeGet(NODE_INDEX), OUTPUT_INDEX); // Automatically gets the memory index of a specified node and input index
135
137 output0.Set(false);
138
140 controller.SampleWait(1);
141 Assert.That(output0.Get(), Is.False, "The getter function should return a value equal to false");
143 }
144
145 //TODO expand examples once iopoint is expanded.
146 [Test]
147 public void IOPointUserBuffer()
148 {
151 const int INPUT_INDEX = 0;
152 const int OUTPUT_INDEX = 1; // The PDO Index in that Node
153
154 UInt64 userBufferAddress = controller.AddressGet(RSIControllerAddressType.RSIControllerAddressTypeUSER_BUFFER, 0); // Grabing an memory address to store a simulated IO point.
155
156 IOPoint input0 = IOPoint.CreateDigitalInput(controller, userBufferAddress, INPUT_INDEX); // Automatically gets the memory index of a specified node and input index
157 IOPoint output0 = IOPoint.CreateDigitalOutput(controller, userBufferAddress, OUTPUT_INDEX); // Automatically gets the memory index of a specified node and input index
158
159 //---ACT/ASSERT---
160 output0.Set(false);
161 Assert.That(output0.Get(), Is.False, "The getter function should return a value equal to false");
162 output0.Set(true);
163 Assert.That(output0.Get(), Is.True, "The getter function should return a value equal to true");
164 controller.MemorySet(input0.AddressGet(), 0);
165 Assert.That(input0.Get(), Is.False, "The getter function should return a value equal to false");
166 controller.MemorySet(input0.AddressGet(), 1);
167 Assert.That(input0.Get(), Is.True, "The getter function should return a value equal to true");
169 }
170
171 [Test]
172 public void SingleAxisSyncOutputs()
173 {
175 const int TOTAL_POINTS = 4; // total number of points
176 const int EMPTY_CT = -1; // Number of points that remains in the buffer before an e-stop
177 const int OUTPUT_INDEX = 0; // This is the index of the digital output that will go active when the user limit triggers.
178 const int NODE_INDEX = 0; // The EtherCAT Node we will be communicating with
179
180 double[] positions = { 1.0, 2.0, 3.0, 4.0 }; // These will be the streaming motion 5 positions.
181 double[] times = { 0.5, 0.1, 0.2, 0.4 }; // These will be the streaming motion 5 positions' time.
182 int outputEnableID = 2; // The motion element ID at which to set the output
183 int outputDisableID = 3; // The motion element ID at which to set the output
184
185 // Set up the inputs
186 // IOPoint output0 = IOPoint.CreateDigitalOutput(axis, RSIMotorGeneralIo.RSIMotorGeneralIo16); // Retrieve DOUT 1, Method 1: requires you know the io adress in memory, slightly faster
187 IOPoint output0 = IOPoint.CreateDigitalOutput(controller.NetworkNodeGet(NODE_INDEX), OUTPUT_INDEX); // Retrieve DOUT 1 Method 2: only need to know node index
188 output0.Set(false); // Set the output low
189
190 // Set up Sync Outputs
191 axis.StreamingOutputsEnableSet(true); // Enable streaming output.
192
193 // ENABLE the Sync Output(s)
194 axis.StreamingOutputAdd(output0, true, outputEnableID); // This will turn DOUT1 High when the streaming motion reaches its 3rd motion point.
195 axis.StreamingOutputAdd(output0, false, outputDisableID); // This will turn DOUT1 Low when the streaming motion reaches its 4th motion point.
196
197 // DISABLE the Sync Output(s)
198 // axis.StreamingOutputAdd(output0, false, outPutEnableID);
199
200 axis.MovePT(RSIMotionType.RSIMotionTypePT, positions, times, TOTAL_POINTS, EMPTY_CT, false, true); // Start Streaming Motion
201
202 while (!axis.MotionDoneGet())
203 {
204 if (axis.MotionIdExecutingGet() > outputEnableID && axis.CommandPositionGet() < outputEnableID)
205 {
206 Assert.That(output0.Get(), Is.EqualTo(true), "The output should be triggered");
207 }
208 else
209 {
210 Assert.That(output0.Get(), Is.EqualTo(false), "The output should NOT be triggered");
211 }
212 }
213
214 axis.StreamingOutputsEnableSet(false); // Disable Sync Outputs.
215 axis.AmpEnableSet(false); // Disable the motor.
217 }
218 }
double CommandPositionGet()
Get the current command position.
bool AmpEnableGet()
Get the state of the Amp Enable Output.
bool HomeSwitchGet()
Get the current state of the Home switch input.
bool PositiveLimitGet()
Get the state of the Hardware Positive Limit input.
uint16_t MotionIdExecutingGet()
bool NegativeLimitGet()
Get the state of the Hardware Negative Limit input.
bool AmpFaultGet()
Get the current state of the Amp Fault input.
bool DedicatedInGet(RSIMotorDedicatedIn motorDedicatedInNumber)
Read a digital input.
uint64_t AddressGet()
Get the Host Address for the I/O point.
void Set(bool state)
Set the state of a Digital Output.
static IOPoint * CreateDigitalInput(Axis *axis, RSIMotorDedicatedIn motorDedicatedInNumber)
Create a Digital Input from an Axis' Dedicated Input bits.
static IOPoint * CreateDigitalOutput(Axis *axis, RSIMotorDedicatedOut motorDedicatedOutNumber)
Create a Digital Output from an Axis' Dedicated Output bits.
bool Get()
Get the state of Digital Input or Output.
Represents one specific point: Digital Output, Digital Input, Analog Output, or Analog Input....
Definition rsi.h:10964
NetworkNode * NetworkNodeGet(int32_t nodeNumber)
NetworkNodeGet returns a pointer to a RapidCodeNetworkNode object using its node number and initializ...
void NetworkOutputOverrideValueSet(int32_t index, uint64_t outputValue)
Sets a PDO output directly.
int32_t NetworkInputBitOffsetGet(int32_t index)
void MemorySet(uint64_t address, int32_t data)
Write a value to controller memory.
uint64_t AddressGet(RSIControllerAddressType type)
Get the an address for some location on the MotionController.
uint64_t NetworkInputValueGet(int32_t index)
uint64_t NetworkOutputSentValueGet(int32_t index)
Gets the value sent out over EtherCAT.
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
const char *const NetworkOutputNameGet(int32_t index)
Get the name of a PDO output.
int32_t NetworkOutputBitSizeGet(int32_t index)
Get the size (in bits) of a PDO output.
int32_t NetworkOutputBitOffsetGet(int32_t index)
Get the raw PDO offset for an output.
int32_t NetworkInputCountGet()
Get the number of PDO inputs found on the network.
int32_t NetworkInputBitSizeGet(int32_t index)
Get the size (in bits) of a network input.
const char *const NetworkInputNameGet(int32_t index)
Get the name of a PDO network input.
void AmpEnableSet(bool enable)
Enable all amplifiers.
void StreamingOutputAdd(int32_t onMask, int32_t offMask, uint64_t address)
void StreamingOutputsEnableSet(bool enable)
Sets whether Streaming Output is enabled (true) or disabled (false).
void MovePT(RSIMotionType type, const double *const position, const double *const time, int32_t pointCount, int32_t emptyCount, bool retain, bool final)
A move commanded by a list of position and time points.
bool MotionDoneGet()
Check to see if motion is done and settled.
RSIControllerAddressType
Used to get firmware address used in User Limits, Recorders, etc.
Definition rsienums.h:404
RSIMotionType
PT and PVT streaming motion types.
Definition rsienums.h:998
RSIMotorDedicatedIn
Dedicated Input bits per motor.
Definition rsienums.h:849