Simulation |
v9 |
ATEasy simulation is a powerful debugging tool used to simulate instruments, test system, application code and the Unit under Test response.
You can use simulation to:
● Develop, Debug and Run, Test your application on your desktop with no hardware: Instruments or UUT.
● Change the procedure return value and parameters to test the application logic and flow control.
● Track procedures calls and parameters.
● Trace and analyze procedures performance.
The following is a list of features provided by ATEasy to perform simulation:
● Run your application with or without instruments or UUT.
● Run you application with or without interface (i.e. GPIB, VXI, LXI, USB, PXI, RS232, etc).
● Select the simulated driver(s), system or program procedures (or IOTables) at run-time.
● Redirect and override simulated procedures to an ATEasy module event (OnSimulate()).
● Get, set parameters and return values, callers and location within the test prograam of the simulated procedures calls.
● Call the original procedure from the simulation event code.
● Ability to turn on simulation mode at run-time, using the IDE command or using the application command line.
To Implement the simulation follow these steps
Set the project for simulation as the Active Project.
Add code to select the procedures or IO Tables that are simulated. Recommendation: Add a driver to your system that takes care of the simulation, In the Driver OnInit() event call the internal procedure SetSimulateProcedures() to select the simulation procedures at run-time when simulation is one. For example, the following OnInit() code ask the user weather to run in simulation, if yes, it turn on simulation for specific procedures:
if App.Simulate=False
if MsgBox("This example shows how to use ATEasy 9 Simulation.\r\n" \
"The example program uses Agilent 34401A DMM.\r\n" \
"When running with Simulate flag turn ON, set from ATEasty conditions menu, \r\n" \
"It will call the OnSimulate() event instead of calling the actual instrument driver calls.\r\n" \
"Missing hardware interfaces/instruments will not generate any errors.\r\n\r\n" \
"Do you want to turn On the simulation?\r\n", aMsgYesNo)=aIdYes
! turn on simulations, same as selecting Simulate from the Conditions menu
App.Simulate=True
endif
endif
! Select what to simulate
if App.Simulate
SetSimulateProcedures("DMM.IOTables") ! all DMM IO Tables
SetSimulateProcedures("DMM.Procedures") ! all DMM Procedures
SetSimulateProcedures("TestExec.User32.GetSystemMetrics") ! One DLL Procedure
SetSimulateProcedures("Language.Kernel32.Procedures") ! All the program DLL procedures
SetSimulateProcedures("Language.Procedures") ! All program Procedures
endif
Implement the OnSimulate() event to handle simulation. The simulation code can use the parameters passed to OnSimulate() event to determine the module and procedure that is being simulated. The following paragraph shows the OnSimulate() prototype:
Procedure OnSimulate(obModule, procCallee, penSimulateStatus): Variant Public
The OnSimulate parameters are defined as follows:
obModule: Val Object - AProgram, ASystem or ADriver where the simulated procedure is defined. You can get the name of the module shortuct using obModule.Name.
procCallee: Val Procedure - Procedure variable to hold the simulated function. You can get the name of the procedure by assigning it to a string: s=procCallee.
penSimulateStatus: Var enumSimulateStatus - Used to let the ATEasy run time know how to handle the simulation after the OnSimulate() is called, possible values are:
enSimulateDone - Simulation handled, return to caller
enSimulateCallNext - Simulation not done, call next handler, this will call the next OnSimulate() defined in the next module to be called
enSimulateCallSimulated - Simulation skipped, call original simulated callee
The following example code shows handling of simulation, It will return 6 for any measure function called, it will return 34401 for any calls to identify the DMM and will return 1024 for any calls to determine the desktop screen size:
Procedure OnSimulate(obModule, procCallee, penSimulateStatus): Variant Public---
obModule: Val Object
procCallee: Val Procedure
penSimulateStatus: Var Internal.enumSimulateStatus
lIndex: Long
sModule: String
p: Any
vrReturn: Variant
sProc: String
{
sModule=obModule.name
select sModule
case "DMM"
sProc=procCallee
select sProc
case "DMM.Measure"
p=GetSimulateParameter("pdResult")
p=6.0
case "DMM.GetSystemIdentification"
p=GetSimulateParameter("psID")
p="34401A"
endselect
trace sProc ! trace all DMM calls
penSimulateStatus=enSimulateDone
case "TestExec"
sProc=procCallee
select sProc
case "TestExec.User32.GetSystemMetrics"
p=GetSimulateParameter("lIndex")
lIndex=p
if lIndex=SM_CXFULLSCREEN or lIndex=SM_CYFULLSCREEN
vrReturn=1024
endif
trace sProc
penSimulateStatus=enSimulateDone
case else
! we do not want to simulate anything else, so call the original procedure
penSimulateStatus=enSimulateCallSimulated
trace sModule
endselect
return vrReturn
}
Use the GetSimulateParameter() internal function to retrieve the pointer to the simulated procedure parameters. This can be used to set the parameter for Var parameters.
Before returning from the OnSimulate() event set the penSimulateStatus parameter to let ATEasy what to do next.
Use the GetCallerName() to determine where the call was made from and what procedure called your simulated procedure.
Use the Program, Task and Test internal variables to determine the location of the call within your program. This will allows to return different values for different tests. You can define arrays of values if you need different values, You can also use the test requirements to calculate the results, for example TestResult=Test.Min+(Test.Max-Test.Min)/2.
To run your project is simulation mode use one of the following:
● Using the IDE Simulate command from the Debug menu.
● Run you EXE with /simulate in the command line.
● Use the app.Simulate property to check or to set simulation at run-time.
Simulate Property, SetSimulateProcedures Procedure, OnSimulate Event, enumASimulateStatus Enum, GetSimulateParameter Procedure, GetCallerName Procedure, Program Variable, Task Variable, Test Variable