Main Page | Namespace List | Class Hierarchy | Data Structures | File List | Data Fields | Globals | Related Pages

acq2xx_api_test.cpp

Go to the documentation of this file.
00001 /* ------------------------------------------------------------------------- */
00002 /* file acq2xx_api_test.cpp                                                  */
00003 /* ------------------------------------------------------------------------- */
00004 /*   Copyright (C) 2006 Peter Milne, D-TACQ Solutions Ltd
00005  *                      <Peter dot Milne at D hyphen TACQ dot com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of Version 2 of the GNU General Public License
00009     as published by the Free Software Foundation;
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
00019 /* ------------------------------------------------------------------------- */
00020 
00021 /** @file acq2xx_api_test.cpp Example test harness for functional API
00022  *
00023  * Demonstrates use of high level function acq2xx__AcqControlTransaction()
00024  * 
00025  *
00026  * - Usage
00027  *  - acq2xx_api_test SOFT_TRANSIENT  : run a SOFT_TRANSIENT capture
00028  *  - acq2xx_api_test TRIGGERED_CONTINUOUS : run a TRIGGERED CONTINUOUS capture
00029  *      with external clock and event0 set.
00030  *  - acq2xx_api_test LOOP_TEST : runs example test loop application
00031  *  - acq2xx_api_test getVoltsRange : retrieves calibration data
00032  */
00033 
00034 
00035 #include "soapH.h"
00036 #include "acq2xx.nsmap"
00037 
00038 using namespace std;
00039 #include <iostream>
00040 #include <vector>
00041 
00042 #include "local.h"
00043 #include <stdio.h>
00044 #include <string.h>
00045 
00046 
00047 #include "acq2xx_client_api.h"
00048 
00049 
00050 
00051 extern int verbose;
00052 
00053 
00054 
00055 static int runTransaction(soap* soap, char *URL, acq2xx__Transaction* transaction)
00056 {
00057 
00058         if (verbose){
00059                 cout << "BEFORE:" << endl;
00060                 transaction->print();
00061         }
00062 
00063         acq2xx__acq2scriptResponse response;
00064         int rc = soap_call_acq2xx__acq2script(
00065                 soap, URL, "", transaction, response);
00066 
00067         if (rc != SOAP_OK){
00068                 cout << "ERROR " << rc << endl;
00069                 return rc;
00070         }
00071         if (verbose){
00072                 cout << "AFTER:" << endl;
00073                 if (response.out != 0){
00074                         response.out->print();
00075                 }else{
00076                         return -1;
00077                 }
00078         }
00079         return 0;
00080 }
00081 
00082 
00083 int reportVoltsRange(char* URL)
00084 /** print the current volts ranges
00085  * @param URL server URL eg "http://acq196_002:66666"
00086  */
00087 {
00088         soap* soap = soap_new();
00089         acq2xx__GetVRangeTransaction request;
00090         acq2xx__acq2scriptResponse response;
00091 
00092         int rc = soap_call_acq2xx__acq2script(
00093                         soap, URL, "", &request, response);
00094 
00095         if (rc != 0){
00096                 return rc;
00097         }
00098 
00099         acq2xx__GetVRangeTransaction* ranges = 
00100                 (acq2xx__GetVRangeTransaction*)response.out;                   
00101         
00102         printf("SUCCESS: AI=%d\n", ranges->channels->AI);
00103 
00104         for (int ch = 1; ch <= ranges->channels->AI; ++ch){
00105                 const VRange& ch_range = ranges->getVRange(ch);
00106                 printf("%2d min:%7.4f V  max:%7.4f V\n", ch, 
00107                         ch_range.min, ch_range.max);
00108         }
00109 
00110         return 0;
00111 }
00112 int configureSoftTransient(char *URL)
00113 /** set up a SOFT_TRANSIENT capture.
00114  * @param URL server URL eg "http://acq196_002:66666"
00115  */
00116 {
00117         acq2xx__Transaction * t = new acq2xx__AcqControlTransaction(
00118                 new acq2xx__ModeSetTransaction( MODE_SOFT_TRANSIENT, 0, 12345),
00119                 new acq2xx__InternalClockSetTransaction(250000),
00120                 new acq2xx__SignalSetTransaction("trig", DI_NONE),
00121                 0
00122         );
00123         return runTransaction(soap_new(), URL, t);
00124 }
00125 
00126 int configureTriggeredContinuous(char *URL)
00127 /** set up a TriggeredContinuous mode capture.
00128  * @param URL server URL eg "http://acq196_002:66666"
00129  */
00130 {
00131         acq2xx__Transaction *t = new acq2xx__AcqControlTransaction(
00132                 new acq2xx__ModeSetTransaction(
00133                                 MODE_TRIGGERED_CONTINUOUS, 10000, 100000),
00134                 new acq2xx__ExternalClockSetTransaction(DI0, 1, DO1),
00135                 0,
00136                 new acq2xx__SignalSetTransaction("event0", DI3, EDGE_FALLING)
00137                 );
00138         return runTransaction(soap_new(), URL, t);
00139 }
00140 
00141 
00142 
00143 static void dierr(int rc, acq2xx__Transaction& t)
00144 {
00145         if (rc != 0){
00146                 cout <<  "ERROR:" << rc << endl;
00147                 t.print();
00148                 exit(rc);       
00149         }
00150 }
00151 
00152 static void dierr(int rc, const char* str)
00153 {
00154         if (rc != 0){
00155                 cout <<  "ERROR:" << rc << " " << str << endl;
00156                 exit(rc);       
00157         }
00158 }
00159 
00160 
00161 int loop_test(char *URL)
00162 /** highly artificial test case - capture 100 shots, with incrementing sample count.
00163  *  best way to view this test is to run an dt100rc concurrently, allow dt100rc to sit
00164  *  in the "Control" page polling status.
00165  * @param URL server URL eg "http://acq196_002:66666"
00166  */
00167 {
00168         soap* soap = soap_new();
00169         int post1 = 100000;
00170         int increment = 1000;
00171 
00172         int maxshots = 100;
00173         if (getenv("MAXSHOTS")){
00174                 maxshots = atoi(getenv("MAXSHOTS"));
00175         }
00176         if (getenv("POST1")){
00177                 post1 = atoi(getenv("POST1"));
00178         }
00179         if (getenv("INCREMENT")){
00180                 increment = atoi(getenv("INCREMENT"));
00181         }
00182 
00183         acq2xx__InternalClockSetTransaction clockSet(250000);
00184         acq2xx__SignalSetTransaction trigSet("trig", DI_NONE);
00185 
00186 
00187         int rc;
00188 
00189         for (int shot = 0; shot < maxshots; ++shot, post1 += increment){
00190                 acq2xx__ModeSetTransaction modeSet(
00191                                 MODE_SOFT_TRANSIENT, 0, post1);
00192                 acq2xx__AcqControlTransaction acqControl(
00193                                 &modeSet, &clockSet, &trigSet, 0);
00194                 acq2xx__AcqStatus status;
00195         
00196                 rc = runTransaction(soap, URL, &acqControl);
00197                 dierr(rc, acqControl);
00198 
00199                 rc = soap_call_acq2xx__setArm(soap, URL, "", 0, status);
00200                 dierr(rc, "setArm");
00201 
00202                 do {
00203                         rc = soap_call_acq2xx__waitStop(
00204                                         soap, URL, "", 10, status);
00205                         dierr(rc, "waitStop");
00206                 } 
00207                 while(status.state != ST_STOP);
00208                 
00209                 cout << "shot:" << shot << " numsamples:" << 
00210                                 status.postlen <<  endl;
00211         }
00212 
00213         soap_destroy(soap);
00214         soap_end(soap);
00215         soap_done(soap);
00216         return 0;
00217 }
00218 
00219 
00220 
00221 
00222 #ifdef WIN32
00223 int acq2xx_main(int argc, char* argv[])
00224 #else
00225         int main(int argc, char* argv[]) 
00226 #endif
00227 {
00228         static char *URL = "http://islay:66666";
00229 
00230         if (getenv("ACQ2XX_WS_URL")){
00231                 URL = getenv("ACQ2XX_WS_URL");
00232         }
00233         if (getenv("ACQ2XX_WS_VERBOSE")){
00234                 verbose = atoi(getenv("ACQ2XX_WS_VERBOSE"));
00235         }
00236 
00237         const char *action = argc > 1? argv[1]: "SOFT_TRANSIENT";
00238 
00239         if (strcmp(action, "LOOP_TEST") == 0){
00240                 return loop_test(URL);
00241         }else if (strcmp(action, "getVoltsRange") == 0){
00242                 return reportVoltsRange(URL);   
00243         }else if (strcmp(action, "TRIGGERED_CONTINUOUS") == 0){
00244                 return configureTriggeredContinuous(URL);
00245         }else{
00246                 return configureSoftTransient(URL);
00247         }
00248 
00249 }
00250 
00251 

Generated on Mon Aug 21 12:39:57 2006 for ACQ2XXWebServices by  doxygen 1.4.4