Multisim and Ultiboard

cancel
Showing results for 
Search instead for 
Did you mean: 

Automation API C++ Builder

Hi Steve -

 

The VARIANT returned by EnumComponents is actually an array of strings, not a string by itself.  In COM, arrays are stored in a type called SAFEARRAY that are a little cumbersome to work with.  In the variant's union of typed members, what you want is "varComponents.parray".  You should find that varComponents.vt (which tells you the variant type) is equal to VT_ARRAY | VT_BSTR, identifying it as an array of strings.  If you start using the simulation functions in the API, you'll need to manipulate SAFEARRAYs of floating point numbers, which have a type of VT_ARRAY | VT_R8.

 

Once you have the SAFEARRAY pointer, you need to call special SafeArray functions to access the data in the array.  Apparently C++ Builder does supply a wrapper class called TSafeArrayT that makes using SAFEARRAYs easier.  Here's a reference I found on using SAFEARRAYs in C++ Builder:

 

http://edn.embarcadero.com/article/22016

 

Alex.

 

Message 11 of 15
(1,433 Views)

One step closer!

 

SAFEARRAYs are pain to the extreme!  I now have access to all the reference designators!  Here is the code:

 

 

void __fastcall TForm1::btnGitComponentsClick(TObject *Sender)
{
if (mappMultisim->IsConnected)
{
TSafeArrayDim1 RefDesListDimension(100);
TSafeArrayBSTR1 sabstrComponents(RefDesListDimension);
VARIANT varComponents;
SAFEARRAY *saComponents;
WideString msg;
int iSafeArray_BoundsLength0;

ctComponentTypeFilter = 0;
varComponents = mcirSimulationCircuit->EnumComponents(ctComponentTypeFilter);
if (VarType(varComponents) != varNull)
{
sabstrComponents.Attach(varComponents.parray);
iSafeArray_BoundsLength0 = sabstrComponents.BoundsLength[0];
for (int iRefDes = 0; iRefDes < iSafeArray_BoundsLength0; iRefDes++)
msg = msg + WideString(sabstrComponents[iRefDes]) + WideString("\n");
ShowMessage(msg);
}
}
}

 

 

I probably need to pour over this code some more tomorrow to make sure I am not leaking memory and all that nonsense.  Here is a screen shot of the ShowMessage() (I consider it a trophy!):

 

19701i503580F274531078

Again, thanks, Alex!  I am not done, but you have certainly earned some Kudoz'es!

Steve.

 

 

 

 

 

 

 

 

 

 

 

 

 

0 Kudos
Message 12 of 15
(1,425 Views)

Alex,

 

So far I have managed to successfully use the three or four main Enum...() methods to get the reference designators and input and outputs, and I have managed to report the netlist, which was, of course, pretty easy.  I also managed to run a simulation with my code.  To test my code I have used two different .ms11 files.  One of the files I mentioned in an earlier post, the other file was something on which I have been working. 

I know both simulations run and do not have convergence issues.

 

Now then, the simple Up_down.ms11 simulation seems to run without an issue started from my code.  The other simulation, the design on which I have been working, seems to stop almost immediately based on the value of SimulationState.  According to Multisim help, to RunSimulation() you pass two parameters:  numSeconds as a double precision floating point value and pause as a boolean.  Below is my code:

 

 

void __fastcall TForm1::btnStartSimulationClick(TObject *Sender)
{
if (mappMultisim->IsConnected)
{
switch (mcirSimulationCircuit->SimulationState)
{
case 0: // SimulationStopped
{
btnStartSimulation->Caption = "STOP Simulation";
mcirSimulationCircuit->RunSimulation(10.000, false);
tmrSimulationStatus->Enabled = true;
break;
}
case 1: // SimulationRunning
{
mcirSimulationCircuit->StopSimulation();
btnStartSimulation->Caption = "START Simulation";
tmrSimulationStatus->Enabled = false;
break;
}
case 2: // SimulationPaused
{
break;
}
default:
break;
}
}
}
void __fastcall TForm1::tmrSimulationStatusTimer(TObject *Sender)
{
if (mappMultisim->IsConnected)
{
sbPlayWMultisimApp->Panels->Items[0]->Text = mcirSimulationCircuit->LastErrorMessage;
switch (mcirSimulationCircuit->SimulationState)
{
case 0: // SimulationStopped
{
shSimulationStatus->Brush->Color = clRed;
tmrSimulationStatus->Enabled = false;
btnStartSimulation->Caption = "START Simulation";
break;
}
case 1: // SimulationRunning
{
if (shSimulationStatus->Brush->Color == clLime)
shSimulationStatus->Brush->Color = clGreen;
else
shSimulationStatus->Brush->Color = clLime;
break;
}
case 2: // SimulationPaused
{
shSimulationStatus->Brush->Color = clYellow;
break;
}
default:
break;
}
}
}

 

As soon as the btnStartSimulation button is clicked, if the SimulationState is set to 0 (simulation stopped), a timer component (tmrSimulationStatus) is enabled and the RunSimulation() method is invoked.  I am assuming the way I have the RunSimulation() method invoked is correct.  The simulation should have continued until it reached 10.0 seconds and when it was done, the simulation should have stopped.  The tmrSimulationStatusTimer event fires off every 200mSec and changes the color of a circle on the form to different shades of green when the simulation is supposed to be active to emulate a flashing LED indicator.  When the simulation

 

 

The simple Up_Down simulation ran for ten seconds, whereas my more complicated simulation ran for 100 or 200 mSec, which makes no sense.  If you notice on the third line in my tmrSimulationStatusTimer event I set the text of the main form's status bar equal to the mcirSimulationCircuit->LastErrorMessage in the event some error occurred.  No error was registered, so I am even more confused.  Am I misinterpreting SimulationState?  Do I need to wait for some period of time (500 mSec?, 1 sec?) before SimulationState is set to something other than SimulationStopped?

 

 

Also, is it possible to access the value of the multimeter virtual intrument?

 

 

Thanks,

Steve.

 

 

 

 

0 Kudos
Message 13 of 15
(1,398 Views)

Hi Steve,

 

I just want to let you know that Alex is out of the office this week as he is attending business meetings in Austin. I am not sure if he will be reading this forum when he is away. We have a statutory holiday on Monday so, he'll be back back on Tuesday. Sorry to keep you in suspense, but we don't want you to be dissapointed in waiting either.

 

----------
Yi
Software Developer
National Instruments - Electronics Workbench Group
0 Kudos
Message 14 of 15
(1,386 Views)

Thanks for the heads up, yyao!

 

Steve.

0 Kudos
Message 15 of 15
(1,383 Views)