Controlling ActiveX from real-time simulink model

8 views (last 30 days)
Hello!
So I am trying to do something a little strange...
For a test my company needs to do, we want to do a hardware loop test to validate that our simulink model and sensor will respond as expected. We using a piezo controller that can be sent voltages through an activex session. I've written a function that takes the handle from the activexcontrol and a variable and sets the voltage. I want to have the simulink model run this function with the handle and the specified voltage at every step in the simulation.
The problem is that the function needs a handle, and I don't know how to get a handle into the simulink workspace, or the simulink data into the matlab workspace to run the function and send the data to the activex controls to set the voltage in the device. Is there any way to do this in real time while the simulation is running?
Thank you
  1 Comment
Tim Barrett
Tim Barrett on 3 Mar 2019
Nevermind, I figured out a dirty solution. I initialized the activex controls in the matlab workspace and made the activex handle a global variable. Then I had the simulink model pass the variable into a matlab function "test.m" which made another function "control_device" an extrinsic function and called it with the variable passed from the simulink model. The "control_device" function simply imported the activex handle using the global keyword and ran one of it's methods with the variable that was passed into it.
This is obviously not the most "optimized" solution, but it works for us.

Sign in to comment.

Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!