How can I click on “OK” or “Apply” button programmatically

Since I did not get any respond regarding updating CAN Pack/Unpack modules, now I am thinking on a way to click on “OK” or “Apply” button of “Function Block Parameters: CAN Pack” programmatically. I can open and close it by open_system and close_system. The name of CAN message on CAN Pack model will be updated but the signals (ports) do not change. Any idea would be greatly appreciated. Thanks

Antworten (2)

Swarooph
Swarooph am 8 Jul. 2016
Any Simulink block can be programmatically set using the set_param function. Look here for documentation. The catch is you need to know exactly what that parameter is called for your particular block. You can do this using the following steps:
  1. Interactively select that particular block in your model
  2. Execute the following command on the MATLAB command prompt
>> get_param(gcb,'DialogParameters') %Before executing this command, the 'CAN Pack' block was selected
ans =
DataFormat: [1x1 struct]
CANdbFile: [1x1 struct]
MsgList: [1x1 struct]
MsgName: [1x1 struct]
MsgIDType: [1x1 struct]
MsgIdentifier: [1x1 struct]
MsgLength: [1x1 struct]
SignalInfo: [1x1 struct]
NSignals: [1x1 struct]
StartBits: [1x1 struct]
SignalSizes: [1x1 struct]
ByteOrders: [1x1 struct]
DataTypes: [1x1 struct]
MultiplexTypes: [1x1 struct]
MultiplexValues: [1x1 struct]
Factors: [1x1 struct]
Offsets: [1x1 struct]
Minimums: [1x1 struct]
Maximums: [1x1 struct]
Remote: [1x1 struct]
In your case the property name is MsgName. To set this using set_param, you would use the following syntax for example:
set_param('myModel/CAN Pack','MsgName','myMessage')
Again, refer to the documentation (linked above) for the full syntax or how it applies to other parameters. Note also that, when you do this, you don't have to worry about clicking 'OK' or 'Apply'.

6 Kommentare

Thank you for your quick answer Swarooph. Actually I have already done what I needed by set_param. The name of corresponding message is changed by :
set_param(Sys,'MsgList', 'RcDemoMsg');
Also when I click on the CAN Pack block, on the “Function Block Parameters: CAN Pack” all signals are also updated as excepted. BUT the main problem is that the ports on CAN PAck model are not updated unless you click on “OK” or “Apply” button. This is actually the main problem I have.
Saeed Soltani
Saeed Soltani am 8 Jul. 2016
Bearbeitet: Saeed Soltani am 8 Jul. 2016
Here is also the link of my problem from last month.
This seems like a block/toolbox specific issue as noted by the the question here . Please contact technical support so that they can investigate this for you.
Actually I have sent Email several times but I‘ve got no respond. It is an emergency case for me and I don’t know what to do!
Is the answer you got from Swarooph helpful?
If not, please let us know why what you are missing.
Have you created an actual help request yet? - I mean here: http://www.mathworks.com/support/contact_us/
Cheers Christoph
Hi Christoph, The answer of Swarooph was not helpful, because as I have mentioned in the previous comment, I had already done this process but didn’t get expected answer. I will try to contact support team with the link you have given.
Thanks.

Melden Sie sich an, um zu kommentieren.

Alberto Guiggiani
Alberto Guiggiani am 10 Jan. 2017
Bearbeitet: Alberto Guiggiani am 10 Jan. 2017
I've implemented a workaround for this problem. It's quite ugly, but it's the only way that I found so far to programmatically work with CAN Pack / Unpack blocks.
The trick is to use Java to emulate keypresses on the dialog box to change anything in it enabling the OK/Apply to refresh the signal list. For example (assuming that the "block_path" variable contains the path of the CAN block):
robot = java.awt.Robot;
open_system(block_path)
robot.keyPress(java.awt.event.KeyEvent.VK_TAB);
robot.keyRelease(java.awt.event.KeyEvent.VK_TAB);
robot.keyPress(java.awt.event.KeyEvent.VK_TAB);
robot.keyRelease(java.awt.event.KeyEvent.VK_TAB);
robot.keyPress(java.awt.event.KeyEvent.VK_RIGHT);
robot.keyRelease(java.awt.event.KeyEvent.VK_RIGHT);
robot.keyPress(java.awt.event.KeyEvent.VK_BACK_SPACE);
robot.keyRelease(java.awt.event.KeyEvent.VK_BACK_SPACE);
robot.keyPress(java.awt.event.KeyEvent.VK_C);
robot.keyRelease(java.awt.event.KeyEvent.VK_C);
robot.keyPress(java.awt.event.KeyEvent.VK_ENTER);
robot.keyRelease(java.awt.event.KeyEvent.VK_ENTER);
pause(0.1)
What it does is pressing TAB key twice to highlight the CANdb file textbox (assuming that you configured the block to "CANdb specified signals"), then deleting and writing again the "c" at the end of .dbc. This is detected as a dialog box update and causes a refresh of the signal list.
The above key sequence is just an example and can be replaced to something else that still causes the "Apply" button to become clickable. A full list of the key names can be found here .

1 Kommentar

I was persist to handle the problem and thanks to your ugly response I overcame. Whether it is ugly or not, it works and appreciated with you. We do not always follow optimum solutions as you know.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by