RMCLink Component

How to: Use from MATLAB

MATLAB users use the RMCLink COM Component interface. Specifics on using this component from MATLAB are described below, including a complete example script. Example scripts are included as MATLAB .m files in the RMCLink example projects.

Creating an RMCLink Object

As is common for all languages, the first step is to create an instance of the RMCLink class. This is a two step process: first create an RMCLinkServer object, and then use that object to create the appropriate type of RMCLink object.

To create the RMCLinkServer object, use the following line in your MATLAB script:

srv = actxserver('RMCLink.RMCLinkServer');

You can now use the newly created srv variable to create the RMCLink object using one of RMCLinkServer's CreateEthernetLink, CreateSerialLink or CreateUSBLink methods. The following line creates a link for communicating with an RMC70 at IP address 192.168.0.22:

rmc = srv.CreateEthernetLink(2,'192.168.0.22');

Notice that as described below, MATLAB cannot use enumerations in a COM object, and therefore, although the CreateEthernetLink, CreateSerialLink and CreateUSBLink methods take a DeviceType parameter, the literal value for the desired enumeration must be used.

Use of Enumerations

MATLAB cannot use enumerations in a COM object. Therefore, although the CreateEthernetLink, CreateSerialLink and CreateUSBLink methods are specified to have the devType parameter be of type DeviceType, you must enter the literal value of the enumeration member you want to use. Similarly, for the IsConnected method's ping parameter, you will have to use the literal values in place of the PingType enumeration members. Each enumeration topic lists the literal values next to the named values (e.g. ptDoNotPing = 0).

Reading Data from the Controller

To read data from the controller, use the ReadFFile or ReadLFile methods.

data = rmc.ReadFFile(8,8,2);

Notice that the ReadBit and ReadBitField methods can be used as well.

Writing Data to the Controller

To write data to the controller, use the WriteFFile or WriteLFile methods. The array length must be equal to or greater than the count parameter.

The WriteFFile method must be passed an array of single or double data type values. The data will be automatically converted to single precision.

data = [6798 5341.23  16.666 17.777 -123.1 -0.0004];

rmc.WriteFFile(56,10,6,data);

The WriteLFile method must be passed an array of int32 data type values.

data = [int32(-1234567) int32(222)];

rmc.WriteLFile(56,5,2,data);

Example

The following code is an example of a MATLAB script. More example scripts are included as MATLAB projects in the RMCLink example projects.

MATLAB

                %First we need to create the RMCLinkServer COM Objectsrv = actxserver('RMCLink.RMCLinkServer'); %Use our RMCLinkServer to create the correct type of RMCLink object.%MATLAB does not support enumerations in COM objects, so we use the %literal value (dtRMC70=2).rmc = srv.CreateEthernetLink(2,'192.168.0.22'); %Establish the connectionrmc.Connect; %Read floating-point values from the RMC (REAL data type in RMC)%The returned values are single-precision.data = rmc.ReadFFile(8,8,2);             %Read Axis 0 Act Pos and Act Vel %Read a signed integer value from the RMC (DINT data type in RMC)%The returned value is a 32-bit integer.data = rmc.ReadLFile(8,12,1);            %Read Axis 0 Raw Counts %Read an unsigned integer value from the RMC (DWORD data type in RMC).%The returned value is signed and must be typecasted to an unsigned 32-bit integer.%Converting to hexadecimal will display the value as it appears in RMCTools.data = dec2hex(typecast(rmc.ReadLFile(8,0,1), 'uint32'),8); %Write one floating-point value (REAL data type in RMC). The data is automatically %converted to single precision.data = 2.2;rmc.WriteFFile(56,0,1,data); %Writing an array of floating-point values. The data is automatically %converted to single precision.data = [6798 5341.23  16.666 17.777 -123.1 -0.0004];rmc.WriteFFile(56,10,6,data);                %Data automatically converted to single %Writing signed 32-bit integers to DINT values. The data must be defined as 32-bit integers.data = [int32(-1234567) int32(222)];              rmc.WriteLFile(56,5,2,data);                 %Assumes variables 5 and 6 are DINTs %Writing unsigned 32-bit integers to DWORD values. The data must be%typecast to signed integers before being used in the WriteLFile method.data = uint32([12345 4294967295]);writedata = typecast(data,'int32');rmc.WriteLFile(56,20,2,writedata);           %Assumes variables 20 and 21 are DWORDs %Writing hexadecimal unsigned 32-bit integers to DWORD valuesdata = uint32([hex2dec('ffee12ab') hex2dec('0045012c')]);writedata = typecast(data,'int32');rmc.WriteLFile(56,22,2,writedata);           %Assumes variables 22 and 23 are DWORDs           

 

See Also

RMCLink COM Component | How Do I Overview | RMCLink Component


Send comments on this topic.

Copyright (c) 2024 Delta Computer Systems, Inc. dba Delta Motion