Hello NXP team,
I want to make a MATLAB script file that can access, monitor and control two FreeMaster instances. I read the section talking about this in the user guide but still have problems and the example attached was for one FreeMaster and didn't work with me for the two FreeMaster instances. The .m file that I am trying to build , is till now only opens the two files but can't write or read from them. It gives this error:
Dot indexing is not supported for variables of this type.
Error in SingleScriptControlling2FM (line 15)
bSucc = pcm1.ReadVariable('SpeedActRpm');
Does any one have a script for this purpose or can help with this error?
Thank you in advance.
Ahmed
Hello,
This Problem highlighted in red color was solved by initializing pcm as an object sothat I can use dot indexing with it. But now, the script can read and write in one FreeMaster not two. How can I use mult = actxserver('MCB.MULT'); to make it listen to two different FreeMaster instances with two boards on two COMs? does it need the ProgID as I read? if so, how can I obtain the ProgID of each board? Please, can any one help with this?
Ahmed
Hello Ahmed,
the MCB.MULT is an identifier of an object which helps you to manage multiple running instances of FreeMASTER. It only has one method GetAppObject, but this is quite versatile. Read User Manual section 6.9 for more information.
With the GetAppObject you can:
Steps to control two or more FreeMASTER instances:
Alternatively, you can save the projects to projectA.pcmx and projectB.pcmx. Make sure to check the "Save settings to project file" so the communication settings is saved. Then you can pass the name of each project as a 3rd argument of GetAppObject and it will take care about running the FreeMASTER and loading the project automatically along with communication settings.
Yet another alternative is to start instances A and B from Matlab as indicated above (without opening a project) and then orchestrate everything from script using StartComm and OpenProject methods executed on pcmA and pcmB objects.
Regards,
Michal
Thank you Michal for your response. I wrote these lines :
[]
Dot indexing is not supported for variables of this type.
Error in SingleScriptControlling2FM (line 9)
pcm1.WriteVariable('SPEED_CMD',700);
is there anything that I have missed?
Ahmed
Hello,
this must be some shortcoming of Matlab. It does not recognize the VARIANT value returned by GetAppObject is actually an IDispatch ActiveX interface.
In other scripting languages (e.g. VBA, VBScript, JScript) this approach works fine.
Let me investigate more. According to this page, Matlab shall handle it correctly. I do not have a solution right now.
Regards,
Michal
Ok, I am waiting for you to investigate this more. Thanks a lot for your effort.
I am trying to make it by Excel using Visual Basic and I started by this code :
Sub mmult_test()
Dim a As McbPcm
Dim b As McbPcm
Dim mult As McbMult
Set mult = New McbMult
Set a = mult.GetAppObject("A")
Set b = mult.GetAppObject("B")
Dim bSucc As Boolean
'ReadVariable uses FreeMASTER variable object from current project. Use
'ReadUIntVariable to access the memory directly using a symbol name.
Set bSucc = a.ReadVariable("SPEED_CMD", vValue, tValue, bsRetMsg)
If bSucc Then
sht.Range("B1").Value = vValue
End If
If b.ReadVariable("TrqCtrlSwitch", "B3") Then
MsgBox ("Variable from instance B " + t2)
Else
MsgBox ("Error reading from instance B: " + m2)
End If
End Sub
That I saw in the question here:https://community.nxp.com/t5/FreeMASTER/Multiple-instances-using-ActiveX-in-VB/td-p/1340033
but I got a compiler error at this line: Set bSucc = a.ReadVariable("SPEED_CMD", vValue, tValue, bsRetMsg) the error says: "Object Required" and when I removed "Set" it gives me : "Object variable or with block variable not set" I think it can't see the object returned by GetAppObject also. If you have tested it before to control two FreeMaster instances using Excell please help me in this.
Regards,
Ahmed
Hello Ahmed,
the script below works in my test Excel file. Make sure you have the objects referenced in VBA. Go to Tools/References menu and check both FreeMASTER and also mmaster object (you may need to browse for mmaster.dll in the FreeMASTER installation).
Dim mult As McbMult
Sub start_A()
If mult Is Nothing Then
Set mult = New McbMult
End If
Set a = mult.GetAppObject("A", 1)
End Sub
Sub start_B()
If mult Is Nothing Then
Set mult = New McbMult
End If
Set b = mult.GetAppObject("B", 1)
End Sub
Sub mmult_test()
If mult Is Nothing Then
Set mult = New McbMult
End If
Dim a As McbPcm
Dim b As McbPcm
Set a = mult.GetAppObject("A", 1)
Set b = mult.GetAppObject("B", 1)
If a.ReadVariable("var16", v1, t1, m1) Then
MsgBox ("Variable from instance A " + t1)
Else
MsgBox ("Error reading from instance A: " + m1)
End If
If b.ReadVariable("var16", v2, t2, m2) Then
MsgBox ("Variable from instance B " + t2)
Else
MsgBox ("Error reading from instance B: " + m2)
End If
End Sub
Hello Michal,
Thank you for your help. It opens two new FreeMaster files momentarily and then gives this error.
on this line:
I replaced "A" & "B" by the names of my files written like "SpdControl.pmp" and tried also to write the total pathes of files since I want to open these two files not to open two new instances. I had the objects referenced in VBA.
Can you try exactly my code? Just to compare the behaviors. Note that there may be difference in 32bit and 64bit version of Excel. I'm testing 64bit version.
You can also put breakpoint to examine a and b variables if they are indeed set to "Nothing".
Just to be fully sure the installation is correct, please run "register.bat" as administrator in the FreeMASTER installation folder (c:\NXP\FreeMASTER 3.2\FreeMASTER\register.bat)
Thanks,
Michal
Same error in the same line when I used exactly your code without any change.
Yes a & b are set to nothing.
When I run register.bat it gives black window momentarily and then disappears. I don't know what this means.
The Excel I use is 32 bit. It seems that this causes the difference.
Hello Ahmed,
I will retry with 32bit Excel, this will need some time.
Please try to do one more experiment and start the applications manually. Locate the pcmaster.exe file in the installation and run it from command line with an argument /sharex "A" and the other with /sharex "B". Then try the script with "A" and "B" names.
The question is if your Excel would locate the two running instances or if it will start another two new instances.
Thank you for you cooperation,
Michal
ok I will try this and wait for your try also.Thank you
Hello,
I have tested the Excel script on a PC with fresh Windows 11 and the latest Excel 32bit. All seem to work properly. Is it possible for you to test on another PC?
In the meanwhile, I have noticed that on some of our corporate PCs, the GetAppObject fails to start the FreeMASTER process due to a security policy. The failed start can be seen in the "Protection History" log in Windows Security panel (picture attached).
Anyway, if FreeMASTER is started manually with the proper "/sharex" option, then the VBA scripts runs normally - so this is must be a different issue from yours.
So far, no answer to your issue. Let's continue investigating. Please finish your experiment with manual start of the shared instances and also please try on a different PC.
Thank you,
Michal
Ok I will try on another PC.
I didn't understand this sentence: "Anyway, if FreeMASTER is started manually with the proper "/sharex" option, then the VBA scripts runs normally - so this is must be a different issue from yours."
and in this : Please try to do one more experiment and start the applications manually. Locate the pcmaster.exe file in the installation and run it from command line with an argument /sharex "A" and the other with /sharex "B". Then try the script with "A" and "B" names.
Do you mean to simply rename the instances by A& B or what ? I feel that I misunderstand something. How to use this /sharex ?
Thank you for your cooperation.
The /sharex is a command-line option which you can use as a parameter when running the FreeMASTER process (pcmaster.exe). You need to run it manually from command line prompt, or you can create a launcher icon with the parameter.
Steps to run it manually.
Regards,
Michal
When I write this command as shown, it opens a new FreeMaster project for moments and close it away. It doesn't open the already created project "SpdControl.pmp" why?