Setting and getting the value of a mono Switch via the Sigma Studio to Matlab activeX interface
Hi everybody,
I'm new here and really need some help.
I have an EVAL-ADDAU1466Z eval board and a little DSP program running on the 1466Z.
It works fine.
Now, from what I read, there is a possibility to change programm settings with Matlab using the active-X interface with the "Analog.SigmaStudioServer.SigmaStudioServer".
I was able to establish a connection between Matlab and Sigma Studio, where I e.g. link-downloaded a certain program successfully.
So far so good.
Now I would like to change the switch position of one of the mono switches in my project.
From the exported parameter-.h-file I got the following information for that particular switch:
/* Module Nx1-1 - Mono Switch Nx1*/
#define MOD_Mod1_NX1_1_COUNT 1
#define MOD_Mod1_NX1_1_DEVICE "IC1"
#define MOD_Mod1_NX1_1_MONOMUXSIGMA300NS1INDEX_ADDR 343
#define MOD_Mod1_NX1_1_MONOMUXSIGMA300NS1INDEX_FIXPT 0x00000001
#define MOD_Mod1_NX1_1_MONOMUXSIGMA300NS1INDEX_VALUE SIGMASTUDIOTYPE_INTEGER_CONVERT(1)
#define MOD_Mod1_NX1_1_MONOMUXSIGMA300NS1INDEX_TYPE SIGMASTUDIOTYPE_INTEGER
#define MOD_Mod1_NX1_1_MONOMUXSIGMA300NS1INDEX_MEMORYPAGE 0
And by using this command
switchState = ss_server.REGISTER_READ_ARRAY('IC 1',343,8);
I received the vectors
switchState =
1×4 uint8 row vector
0 0 0 1
and
switchState =
1×4 uint8 row vector
0 0 0 0
for the two switch states I manually set using the Sigma Studio GUI.
So reading this property seems to work.
But writing on the other hand does not:
I tried the commands
ss_server.REGISTER_WRITE_ARRAY('IC 1', 343, 4, uint8([0 0 0 1]'));
and
ss_server.REGISTER_WRITE_ARRAY('IC 1', 343, 4, uint8([0 0 0 0]'));
which did something, because reading of the states after each writing command revealed, that the state has been written correctly.
But neither does the Sigma Studio GUI show the intended effect (switch position toggles) nor is there the expected change in the output signal that the switch would create when actually switched.
What am I doing wring?
Can you help me?
Thank you!
Edit Notes
simplified naming
[edited by: KilianK at 10:10 AM (GMT -4) on 5 Nov 2021]
matlab
sigmastudio
SigmaDSP
I suspect the problem might be the discrepancy between COM and Matlab data formats. I know that this works for writing a single register:
writeVal = randi(2^31 -1, 'uint32');
errorCode = ss_server.REGISTER_WRITE( 'IC 1', address, 0x04, writeVal );
In other words, try concatenating the four bytes into a single uint32. I haven't used REGISTER_ARRAY_WRITE. I typically use REGISTER_WRITE in a loop. It's slower, but that might get you by.
Another option that isn't well documented is to use the .NET interface from Matlab rather than the COM interface. Matlab's support for .NET is much stronger. The .NET docs can be found here and the info on calling methods (functions) can be found here.
Set up the communication as follows.
try
theDir = dir('/Program Files/Analog Devices/**/Analog.SigmaStudioServer.dll');
if (isempty(theDir))
fprintf('ERROR: Cannot find Analog.SigmaStudioServer.dll\n');
return;
end
catch
fprintf('ERROR: Cannot find Analog.SigmaStudioServer.dll\n');
return;
end
theFile = fullfile(theDir(end).folder,'Analog.SigmaStudioServer.dll');
theAssembly = NET.addAssembly(theFile); % load assembly
SSclass = Analog.SigmaStudioServer.SigmaStudioServer; % handle to class
Then, you can query the DLL for the implemented methods with
methods SSclass
or, for a very nice table with arguments and return values, use
methodsview(SSclass)
Good luck,
Ken
Hi Ken,
thank you very much for your response and the detailed explanation.
I'm going to try it in the next couple of days and report what happened.
Hi Ken,
I finally found some time to try what you proposed.
At first I did some research about how to exactly determine the adress and state/value of my object, in that case a simple switch.
In Sigma Studio: "Action" --> "Export System Files" delivers several files, and, among other things, the header file "..._PARAM.h".
Within that file I found the definition of the switch I want to control:
/* Module MySwitch - Mono Switch Nx1*/
#define MOD_MySwitch_COUNT 1
#define MOD_MySwitch_DEVICE "IC1"
#define MOD_MySwitch_MONOMUXSIGMA300NS1INDEX_ADDR 334
#define MOD_MySwitch_MONOMUXSIGMA300NS1INDEX_FIXPT 0x00000000
#define MOD_MySwitch_MONOMUXSIGMA300NS1INDEX_VALUE SIGMASTUDIOTYPE_INTEGER_CONVERT(0)
#define MOD_MySwitch_MONOMUXSIGMA300NS1INDEX_TYPE SIGMASTUDIOTYPE_INTEGER
#define MOD_MySwitch_MONOMUXSIGMA300NS1INDEX_MEMORYPAGE 0
alternatively, and that is really helpful, one can use the "Capture Window",
which can be activated under "View" --> "Capture Window", to take a look at whats going on in the individual objects.
E.g. when changing the state of my switch in the Sigma Studio GUI,
I got detailed feedback about the properties of the object in this form:
Block Write
Time: 13:56:36 - 971ms
IC: IC 1
Cell Name: MOD_MySwitch
Param Name: monomuxSigma300ns1index
Param Address: 334
Param Value: 0 [1 after switching]
Bytes: 4
Param Data:
0x00, 0x00, 0x00, 0x00 [0x00, 0x00, 0x00, 0x01 after switching]
So at this point the address and the value range of the "Block" are known and can be used for the script call.
This information surely is not new to you, but some reader who is not familiar with these details might find it helpful to find a complete and simple example for the Matlab/.NET-usage here.
I then tried to change the switch value with the .NET interface you recommended, using the following code:
theAssembly = NET.addAssembly('C:\Program Files\Analog Devices\SigmaStudio 4.6\Analog.SigmaStudioServer.dll');
SSclass = Analog.SigmaStudioServer.SigmaStudioServer;
icName = 'IC 1';
objectAddress = int32(334); <--- here the adress from above comes in
numericFormat = int32([32,0]);
% Set object value to 1:
objectValue = 1; <--- here the two possible parameter values from above can be put in
SSclass.PARAMETER_WRITE(icName,objectAddress,numericFormat(1),numericFormat(2),objectValue);
% Wait a second to monitor the output signal on the scope
pause(1)
% Set object value to 0:
objectValue = 0;
SSclass.PARAMETER_WRITE(icName,objectAddress,numericFormat(1),numericFormat(2),objectValue);
And this works fine!
The only thing that does not work as I would have expected is, that the switch block in the Sigma Studio GUI does not change its appearance depending on the .NET transmitted switch value.
In other words: Using the mouse in the GUI to change the switch leads to the same result as using the .NET-call, but in the latter case the GUI does not show it.
Is this intended behaviour, or am I doing somehing wrong here?
Thanks again!
Wtaching the capture window when toggling the switch in the GUI and from the .NET interface,
I found out that the logged data differs:
A click on the switch in the GUI leads to this:
Block Write
Time: 15:36:38 - 365ms
IC: IC 1
Cell Name: mySwitch
Param Name: monomuxSigma300ns1index
Param Address: 345
Param Value: 1
Bytes: 4
Param Data:
0x00, 0x00, 0x00, 0x01
While using PARAMETER_WRITE from the .NET interface creates this text:
Block Write
Time: 15:39:35 - 251ms
IC: IC 1
Param Address: 345
Bytes: 4
Param Data:
0x00, 0x00, 0x00, 0x01
The "Param Value" seems to not be set using PARAMETER_WRITE.
Is it possible to set it using e.g. another command?
Please log in to reply.