close all
clear all
%First we need to create the RMCLinkServer COM Object
srv = 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,'134.89.12.240');

%Establish the connection
rmc.Connect;

%Read floating-point values from the RMC (REAL data type in RMC)
%The returned values are single-precision.
%returnValue = instance.ReadFFile(file, element, count)
data = rmc.ReadFFile(8,8,2);             %Read Axis 0 Act Pos and Act Vel
disp(['Axis 0 Pos = ' num2str(data(1))]);
disp(['Axis 0 Vel = ' num2str(data(2))]);
disp(' ');

%Read a signed integer value from the RMC (DINT data type in RMC)
%The returned value is a 32-bit integer.
%returnValue = instance.ReadLFile(file, element, count)
data = rmc.ReadLFile(8,12,1);            %Read Axis 0 Raw Counts
disp(['Axis 0 Raw Counts = ' num2str(data)]);
disp(' ');

%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);
disp(data);
disp(' ');

%Write one floating-point value (REAL data type in RMC). The data is automatically 
%converted to single precision.
%instance.WriteFFile(file, element, count, data)
rmc.WriteFFile(56,10,1,2.3)
data = rmc.ReadFFile(56,10,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


