Jump to content
Sign in to follow this  
VisSim Forum Archives

Can I have VisSim evaluate expressions in my custom block parameter screen?

Recommended Posts

Submitted by Joe on Fri, 02/15/2013 - 21:37

 

Hi, I've written some custom blocks in VisSim and they work great. I can simulate and generate code and it shows off our trajectory generation in a motion servo loop really well. My only problem now is that I would like to enter expressions that use variable names from the VisSim diagram in my parameter setup dialog box instead of just numeric constants. Can I do that? If so, how?

Share this post


Link to post
Share on other sites

Submitted by pete on Fri, 02/15/2013 - 21:54.

 

Sure, no problem. VisSim has an exported entry point, double C_expression(const char *s), that takes a text string argument and produces a floating point result. VisSim also supplies a vissimRequest message to retrieve any error message that may have resulted from expression evaluation, like "Undefined variable 'foo'". Normally you would evaluate the expression at simulation start time (in the "SS" function). Here is some sample code:

 

#include "vsuser.h" // VisSim custom block programming interface definitions
static char errBuf[4096];

...
char *myStr = "10*maxFreq/(2*pi)"
double val = C_expression(myStr));
if (vissimRequest(VR_GET_EXPRESSION_ERROR, (long)errBuf, sizeof(errBuf)))
    {
      setBlockErr();  // Flag block in red
      debMsg("Error: '%s' in user value '%s'", errBuf, myStr);
    }

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...