184 Chapter 15 Script SDK
testapi.cpp
This example demonstrates the following functions of the API:
• Sending commands and getting responses back
•Pause()
• Multi-line response
• Operators “=” and “+=”
• QDLcd associated API commands: InputInteger(), InputFloat(), and
WaitForButtonPress()
• GetUIntResponse()
• GetIntResponse()
• GetDoubleResponse()
• GetBoolResponse()
• Detecting an invalid command
#include <QDScriptContext.h>
#include <stdio.h>
bool Script_testapi( QDScriptContext& sc )
{
// =========================================================
// Demonstration of sending command and getting response back
// =========================================================
// one way to execute a command/query
sc.Exec("CIOY"); // enable printf to serial terminal
// another way to execute a command/query
sc.SetCmdName("VERF?"); // query generator firmware version
sc.Exec(); // execute the command
printf("The return value of command \"%s\" is %s\n", sc.GetCmdName(),
sc.GetResponse());
// =========================================================
// Demonstration of Pause()
// =========================================================
printf("Pause for 5 seconds\n");
sc.Pause( 5000 );
if (sc.Canceled()) {
return true;
}
printf("\nWake up from Pause(5000)\n");
sc.SetCmdName("VERG?"); // query generator gateware versions
sc.Exec(); // execute the command
if (sc.Succeed()) { // was previous command successful?
printf("\nThe return value of command \"%s\" is %s\n",
sc.GetCmdName(), sc.GetResponse());
}