How to: Send RMC70 Commands |
One common task when controlling an RMC70 through the RMCLink component is to issue commands to one or more axes (see the help in RMCTools for details on what commands are available and what they do).
Commands are issued by writing to the Small Command Area (also referred to as just the Command area), which is located in floating-point file sixteen (%MD16). This area consists of six (6) registers per axis. Therefore %MD16.0-5 hold the command for axis 0, %MD16.6-11 hold the command for axis 1, and so on. The first register for each axis is the command number, and the next five registers are Command Parameters 1-5. The meaning of the command parameters vary depending on the command selected by the first register. In order to issue commands that require more than 5 parameters, see the Large CommandArea section below.
When an outside source writes to the Command Area, each axis written to will run the command sent to it immediately. Notice that it is important that all axes that are to run their commands simultaneously must be written to in the same write. Therefore, to issue commands to axes 0 and 1 at the same time, write 12 registers starting at %MD16.0.
Notice that a special command of NoOp (0) can be issued to have the axis ignore the command written to it. Therefore, to issue commands simultaneously to axes 0 and 2 at the same time, write 18 registers starting at %MD16.0, but make sure that the value written to %MD16.6 is zero (0) so that only commands 0 and 2 act on their commands.
The following steps should be used to write a command to one or more axes in the RMC70:
Declare an array of float (Single in Visual Basic) values. The length of the array should be rmc70CmdRegsPerAxis (6) times the number of axes you want to write to.
Initialize all values in the array. Set the first array element for that axis (element 0, 6, 12, or 18 for axes 0, 1, 2, and 3) to the number of the command (e.g. Move Absolute is command number 20). Set the five elements following to the five command parameters for that command. If the command uses less than all five command parameters, set the array element for that the extra parameters to zero (0).
For axes that you do not want to receive a command on this write, just use command number zero (0), and set all the command parameters for that command to zero (0) as well.
Call the WriteFFile method. The file parameters should be fn70CommandArea (16). The element parameter should be rmc70CmdRegsPerAxis (6) times the number of the first axis you want to write to. The count parameter should match the length of the data array declared above. The data parameter should be the array declared above.
Refer to the examples below.
Reading from the Command Area is not meaningful; zeros will simply be returned for each register.
The Command Request and Acknowledge bits works as they normally do when used via RMCLink.
The Command Request and Command Acknowledge bits provide synchronization of commands and status information between the host controller and RMC. These bits are always available, but using these bits is optional. For many applications, they are very important. When reading status bits and status registers, these bits let the host controller know that the data being requested is valid. For example, after a Move command is issued, the In Position status bit is not valid until the RMC has informed the host controller that it received the command. The RMC does this by matching the Command Acknowledge bit to the Command Request bit.
See the Command Request and Acknowledge Bits topic in the RMCTools help for more details.
The Small Command Area located in file 16 can be used to issue commands with up to 5 parameters. To issue commands with up to 9 parameters, use the Large Command Area. This area is located in file 25. The large command area contains ten registers for each axis; one for the command and nine for the parameters.
Use the Large Command area in the same manner as the Small Command Area (file 16), except that the number of registers is 10. The following constants are intended for use with the Large Command Area:
fn70LrgCommandArea = 25
rmc70LrgCmdRegsPerAxis = 10
The following code example illustrates sending commands to an RMC70.
Visual Basic 6 / VBA |
Option Explicit
Public Sub Sample()
' Declare and create the RMCLinkServer COM object.
Dim srv As New RMCLinkServer
' Use our RMCLinkServer to create the correct type of RMCLink object.
Dim rmc As RMCLink
Set rmc = srv.CreateEthernetLink(dtRMC70, "192.168.0.22")
' Establish the connection.
rmc.Connect
' Issue a Move Absolute command to Axis 0 (registers %MD16:0-5).
Dim data(5) As Single
data(0) = 20 ' Move Absolute (20)
data(1) = 10.5 ' Requested Position (10.5 in)
data(2) = 12.5 ' Requested Speed (12.5 in/s)
data(3) = 100 ' Acceleration Rate (100 in/s/s)
data(4) = 100 ' Deceleration Rate (100 in/s/s)
data(5) = 0 ' Direction (0=nearest)
rmc.WriteFFile fn70CommandArea, 0, rmc70CmdRegsPerAxis, data
' Close the connection.
rmc.Disconnect
End Sub
|
Visual Basic .NET |
Imports RMCLinkNET
Module Example
Sub Main()
' Create the object itself.
Dim rmc As RMCLink = RMCLink.CreateEthernetLink(DeviceType.RMC70, "192.168.0.10")
' Connect to the controller.
rmc.Connect()
' Issue a Move Absolute (20) command to Axis 0 (registers %MD16:0-5).
Dim cmd() As Single = new Single(5) {}
cmd(0) = 20 ' Move Absolute (20)
cmd(1) = 10.5 ' Requested Position (10.5 in)
cmd(2) = 12.5 ' Requested Speed (12.5 in/s)
cmd(3) = 100.0 ' Acceleration Rate (100 in/s/s)
cmd(4) = 100.0 ' Deceleration Rate (100 in/s/s)
cmd(5) = 0 ' Direction (0=Nearest)
rmc.WriteFFile(FileNumber70.fn70CommandArea,0,cmd,0, _
Constants70.rmc70CmdRegsPerAxis);
' Disconnect from the controller.
rmc.Disconnect()
End Sub
End Module
|
C# |
using System;
using RMCLinkNET;
namespace Example
{
public class Program
{
static void Main()
{
// Create the object itself.
RMCLink rmc = RMCLink.CreateEthernetLink(DeviceType.RMC70, "192.168.0.10");
// Connect to the controller.
rmc.Connect();
// Issue a Move Absolute (20) command to Axis 0 (registers %MD16:0-5).
float[] cmd = new float[6];
cmd[0] = 20; // Move Absolute (20)
cmd[1] = 10.5; // Requested Position (10.5 in)
cmd[2] = 12.5; // Requested Speed (12.5 in/s)
cmd[3] = 100.0; // Acceleration Rate (100 in/s/s)
cmd[4] = 100.0; // Deceleration Rate (100 in/s/s)
cmd[5] = 0; // Direction (0=Nearest)
rmc.WriteFFile(FileNumber70.fn70CommandArea,0,cmd,0,
Constants70.rmc70CmdRegsPerAxis);
// Disconnect from the controller.
rmc.Disconnect();
}
}
}
|
C++ |
#include <windows.h>
#include <stdio.h>
#include "RMCLink.h"
void main()
{
// In order to create COM objects, we must initialize the COM sub-system.
::CoInitialize(0);
// Create a new RMCLink object.
CRMCLink* pRMC = CRMCLink::CreateEthernetLink(CRMCLink::dtRMC70, _T("192.168.0.22"));
if ( pRMC != NULL )
{
// Establish the connection.
HRESULT hr = pRMC->Connect();
if ( SUCCEEDED(hr) )
{
// Issue a Move Absolute command to Axis 0 (registers %MD16:0-5).
float afCmd[6];
afCmd[0] = 20; // Move Absolute (20)
afCmd[1] = 10.5; // Requested Position (10.5 in)
afCmd[2] = 12.5; // Requested Speed (12.5 in/s)
afCmd[3] = 100; // Acceleration Rate (100 in/s/s)
afCmd[4] = 100; // Deceleration Rate (100 in/s/s)
afCmd[5] = 0; // Direction (0=nearest)
hr = pRMC->WriteFFile(CRMCLink::fn70CommandArea, 0,
CRMCLink::rmc70CmdRegsPerAxis, afCmd);
if ( SUCCEEDED(hr) )
printf("Command successfully written.");
// Close the connection.
pRMC->Disconnect();
}
// Free the RMCLink object we created.
delete pRMC;
}
// Release the COM sub-system.
::CoUninitialize();
}
|
C++/CLI |
using namespace System;
using namespace RMCLinkNET;
int main()
{
// Create the object itself.
RMCLink^ rmc = RMCLink::CreateEthernetLink(DeviceType::RMC70, "192.168.0.10");
// Connect to the controller.
rmc->Connect();
// Issue a Move Absolute command to Axis 0 (registers %MD16:0-5).
array<float>^ cmd = gcnew array<float>^(6);
cmd[0] = 20; // Move Absolute (20)
cmd[1] = 10.5; // Requested Position (10.5 in)
cmd[2] = 12.5; // Requested Speed (12.5 in/s)
cmd[3] = 100.0; // Acceleration Rate (100 in/s/s)
cmd[4] = 100.0; // Deceleration Rate (100 in/s/s)
cmd[5] = 0; // Direction (0=Nearest)
rmc.WriteFFile(FileNumber70::fn70CommandArea,0,cmd,0,
Constants70::rmc70CmdRegsPerAxis);
// Disconnect from the controller.
rmc->Disconnect();
return 0;
}
|
VBScript |
Option Explicit
Dim srv, rmc
' First we need to create the RMCLinkServer COM object.
Set srv = CreateObject("RMCLink.RMCLinkServer")
' Use our RMCLinkServer to create the correct type of RMCLink object.
' NOTE: VBScript does not support enumerations, so we use the literal value (dtRMC70=2).
Set rmc = srv.CreateEthernetLink(2, "192.168.0.22")
' Establish the connection.
rmc.Connect
' Issue a Move Absolute command to Axis 0 (registers %MD16:0-5).
Dim data(5)
data(0) = 20 ' Move Absolute (20)
data(1) = 10.5 ' Requested Position (10.5 in)
data(2) = 12.5 ' Requested Speed (12.5 in/s)
data(3) = 100 ' Acceleration Rate (100 in/s/s)
data(4) = 100 ' Deceleration Rate (100 in/s/s)
data(5) = 0 ' Direction (0=nearest)
rmc.WriteFFile 16,0,6,data
' Close the connection.
rmc.Disconnect
|
JScript |
// First we need to create the RMCLinkServer COM object.
var srv = new ActiveXObject("RMCLink.RMCLinkServer");
// Use our RMCLinkServer to create the correct type of RMCLink object.
// NOTE: JScript does not support enumerations, so we use the literal value (dtRMC70=2).
var rmc = srv.CreateEthernetLink(2, "192.168.0.22");
// Establish the connection.
rmc.Connect();
// Issue a Move Absolute command to Axis 0 (registers %MD16:0-5).
var data = new Array(6);
data[0] = 20; // Move Absolute (20)
data[1] = 10.5; // Requested Position (10.5 in)
data[2] = 12.5; // Requested Speed (12.5 in/s)
data[3] = 100; // Acceleration Rate (100 in/s/s)
data[4] = 100; // Deceleration Rate (100 in/s/s)
data[5] = 0; // Direction (0=nearest)
rmc.WriteFFile(16,0,6,data);
// Close the connection.
rmc.Disconnect();
|
See Also
How Do I Overview | RMCLink Component
Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion