How to: Send RMC200 Commands |
One common task when controlling an RMC200 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 Command Area, which is located in file 16. This area consists of 10 registers per axis. %MD16.0-9 hold the command for axis 0, %MD16.11-19 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-9. The meaning of the command parameters vary depending on the command selected by the first register.
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 20 registers starting at %MD16.0.
Notice that a special command of No-Op (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 30 registers starting at %MD16.0, but make sure that the value written to %MD16.10 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 RMC200:
Declare an array of float (Single in Visual Basic) values. The length of the array should be rmc200CmdRegsPerAxis (10) times the number of axes you want to write to.
If you are issuing a command to only one axis, the array length need only be the number of parameters the command has plus one (for the command number itself).
Initialize all values in the array. Set the first array element for that axis (element 0, 10, 20, 30, etc. for axes 0, 1, 2, 3, etc.) to the number of the command (e.g. Move Absolute is command number 20). Set the nine elements following to the command parameters for that command. If the command uses less than all nine 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 fn200CommandArea (16). The element parameter should be rmc200CmdRegsPerAxis (10) 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 example 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 following code example illustrates sending commands to an RMC200.
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(dtRMC200, "192.168.0.22")
' Establish the connection.
rmc.Connect
' Issue a Move Absolute command to Axis 0 (registers %MD16.0-9).
Dim data(9) 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)
data(6) = 0 ' unused
data(7) = 0 ' unused
data(8) = 0 ' unused
data(9) = 0 ' unused
rmc.WriteFFile fn200CommandArea, 0, rmc200CmdRegsPerAxis, 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.RMC200, "192.168.0.10")
' Connect to the controller.
rmc.Connect()
' Issue a Move Absolute (20) command to Axis 0 (registers %MD16.0-9).
Dim cmd() As Single = new Single(9) {}
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)
cmd(6) = 0 ' unused
cmd(7) = 0 ' unused
cmd(8) = 0 ' unused
cmd(9) = 0 ' unused
rmc.WriteFFile(FileNumber200.fn200CommandArea,0,cmd,0, _
Constants200.rmc200CmdRegsPerAxis);
' 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.RMC200, "192.168.0.10"); // Connect to the controller. rmc.Connect(); // Issue a Move Absolute (20) command to Axis 0 (registers %MD16.0-9). float[] cmd = new float[10]; 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) cmd[6] = 0; // unused cmd[7] = 0; // unused cmd[8] = 0; // unused cmd[9] = 0; // unused rmc.WriteFFile(FileNumber200.fn200CommandArea,0,cmd,0, Constants200.rmc200CmdRegsPerAxis); // 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::dtRMC200, _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-9).
float afCmd[10];
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)
afCmd[6] = 0; // unused
afCmd[7] = 0; // unused
afCmd[8] = 0; // unused
afCmd[9] = 0; // unused
hr = pRMC->WriteFFile(CRMCLink::fn200CommandArea, 0,
CRMCLink::rmc200CmdRegsPerAxis, 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::RMC200, "192.168.0.10");
// Connect to the controller.
rmc->Connect();
// Issue a Move Absolute command to Axis 0 (registers %MD16.0-9).
array<float>^ cmd = gcnew array<float>^(10);
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)
cmd[6] = 0; // unused
cmd[7] = 0; // unused
cmd[8] = 0; // unused
cmd[9] = 0; // unused
rmc.WriteFFile(FileNumber200::fn200CommandArea,0,cmd,0,
Constants200::rmc200CmdRegsPerAxis);
// 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 (dtRMC200=3).
Set rmc = srv.CreateEthernetLink(3, "192.168.0.22")
' Establish the connection.
rmc.Connect
' Issue a Move Absolute command to Axis 0 (registers %MD16.0-9).
Dim data(9)
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)
data(5) = 0 ' unused
data(7) = 0 ' unused
data(8) = 0 ' unused
data(9) = 0 ' unused
rmc.WriteFFile 16,0,10,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 (dtRMC200=3).
var rmc = srv.CreateEthernetLink(3, "192.168.0.22");
// Establish the connection.
rmc.Connect();
// Issue a Move Absolute command to Axis 0 (registers %MD16.0-9).
var data = new Array(10);
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)
data[6] = 0; // unused
data[7] = 0; // unused
data[8] = 0; // unused
data[9] = 0; // unused
rmc.WriteFFile(16,0,10,data);
// Close the connection.
rmc.Disconnect();
|
See Also
How Do I Overview | RMCLink Component
Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion