Can I have VisSim evaluate expressions in my custom block parameter screen?
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?
Answers
-
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); }
0