Hello,
I try to link FreeMASTER and Matlab. The aim is to have a model of the realistic world inside Matlab/Simulink that gets controlled on a Kinetis Tower Board.
So far I execute in a m-file the command:
e = actxserver ('MCB.PCM')
as an answer I get:
e =
COM.MCB_PCM
If I execute for example:
e.get
I get the whole list of ActiveX commands:
LastResult: NaN | |
LastRetMsg: NaN | |
LastVariable_vValue: NaN | |
LastVariable_tValue: NaN | |
LastMemory_hexstr: NaN | |
LastMemory_data: NaN | |
LastRecorder_data: NaN | |
LastRecorder_serieNames: NaN | |
LastRecorder_timeBaseSec: NaN | |
LastRecorder_state: NaN | |
LastLocalFile_string: NaN |
But always marked as: NaN - which I do not understand
If I execute one of the commands I get for example:
e.GetLastResult('var16')
??? No method 'GetLastResult' with matching signature found for class
'COM.MCB_PCM'.
Has anyone successful integrated FreeMASTER and Matlab or can give me a hint what I did wrong?
Best Regards
Markus
Hello Markus,
try following example:
% create FreeMASTER ActiveX object
fmstr = actxserver ('MCB.PCM');
% write 0x10 value into "var16" variable defined in FreeMASTER project
bSucc = fmstr.WriteVariable('var16inc', 16);
var16inc = 0;
bSucc = fmstr.ReadVariable('!var16inc'); %"!" immediate performs the command
if bSucc
var16inc = fmstr.LastVariable_vValue;
end
% show the value
var16inc;
% configure matlab to accept safe array as single dimension
feature('COM_SafeArraySingleDim', 1) ;
% write 4 bytes to memory 0x20. WriteMemory function expects SafeArray as input data
bSucc = fmstr.WriteMemory(32, 4, {11;22;33;44})
% reads 4 bytes from memory at address of var32inc variable
bSucc = fmstr.ReadMemory('var32inc', 4);
if bSucc
% reads data of last call the ReadMemory()function.
readMemResult = fmstr.LastMemory_data
end
% write to memory at pointer. The value of "var8" represents the pointer, 0x02 is offset.
% this is only demonstration !!Beware that wrong value of var8 may cause memory corruption!!
array = [11;22;33;44];
bSucc = fmstr.WriteUIntArray('valueof(var8) + 0x02', 4, 1, {array});
We are preparing FreeMASTER tool 1.3.16 where are included more examples in User Manual (javascript in html, VBA script in html and Excel and this matlab example)
Best Regards,
Jaroslav