ACQ2XX_API
api_test.cpp
Go to the documentation of this file.
00001 /* ------------------------------------------------------------------------- */
00002 /* file api_test.cpp                                                         */
00003 /* ------------------------------------------------------------------------- */
00004 /*   Copyright (C) 2008 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 api_test.cpp implementation of api_test using API.
00022  * exercise the methods of Acq2xx, first by setting properties,
00023  * then run a capture.
00024  * Then you can use acqread to look at the data
00025  *
00026 <pre>
00027   opts:
00028   -T : use hard trigger 
00029   --trigger-type lemo-master : set.route in lemo out fpga pxi : chassis master
00030   --trigger-type pxi-slave   : set.route in pxi out fpga      : chassis slave
00031                                default: front panel lemo-standalone
00032 </pre>
00033  */
00034 
00035 #include <popt.h>
00036 
00037 #include "local.h"
00038 #include "acq2xx_api.h"
00039 #include "acq_transport.h"
00040 
00041 int acq200_debug;
00042 int timeout;
00043 char* device;
00044 int do_shell;
00045 
00046 #define RETERR(cmd) if (STATUS_ERR(rc = cmd)) {         \
00047         err("failed: \"%s\" code:%d", #cmd, rc);        \
00048         return rc;      \
00049 }
00050 
00051 
00052 #define POST 1024000
00053 
00054 
00055 const char *trigger_type = "lemo-standalone";
00056 
00057 int main(int argc, const char** argv)
00058 {
00059         struct poptOption opt_table[] = {
00060                 { "device",     'f', POPT_ARG_STRING, &device,          'f' },
00061                 { "board",      'b', POPT_ARG_STRING, &device,          'b' },
00062                 { "shell",      's', POPT_ARG_STRING, &device,          's' },
00063                 { "verbose",    'v', POPT_ARG_INT,    &acq200_debug,    0   },
00064                 { "version",    0,   POPT_ARG_NONE,   0,                'V' },
00065                 { "trigger",    'T', POPT_ARG_NONE,   0,                'T' },
00066                 { "trigger-type", 0, POPT_ARG_STRING, &trigger_type,    0 },
00067                 { "timeout",    't', POPT_ARG_INT,    &timeout,         't',
00068                   "timeout in seconds"},
00069                 POPT_AUTOHELP
00070                 POPT_TABLEEND           
00071         };
00072         int rc;
00073         poptContext opt_context = 
00074                 poptGetContext(argv[0], argc, argv, opt_table, 0);
00075         int soft_trigger = 1;
00076 
00077         while ( (rc = poptGetNextOpt(opt_context)) > 0 ){
00078                 switch(rc){
00079                 case 's':
00080                         do_shell = 1;
00081                         break;  
00082                 case 'T':
00083                         soft_trigger = 0;
00084                         break;
00085                 }
00086         }       
00087 
00088         if (device == 0){
00089                 err("usage api_test -f DEVICE command ...");
00090                 return -1;
00091         }
00092         Transport *t = Transport::getTransport(device); 
00093         Acq2xx card(t);
00094         int channels;
00095 
00096         printf("Test starts here:");
00097 
00098         printf("getAvailableChannels\n");
00099         RETERR(card.getAvailableChannels(channels));
00100         printf("getAvailableChannels: %d\n", channels);
00101 
00102         int iclock = 250000;
00103         printf("setInternalClock(%d)\n", iclock);
00104         RETERR(card.setInternalClock(iclock));  
00105         iclock = -1234;
00106         RETERR(card.getInternalClock(iclock));
00107         printf("getInternalClock value %d\n", iclock);
00108 
00109         printf("setChannelMask\n");
00110         //                   12345678901234567890123456789012
00111         char* channelMask = new char[96];
00112         strcpy(channelMask, "11111111111111111111111111111111");
00113 
00114         RETERR(card.selectChannels(channelMask));
00115 
00116 
00117         RETERR(card.getSelectedChannels(channelMask, &channels));
00118         printf("getChannelMask %s number of channels %d\n", 
00119                         channelMask, channels);
00120 
00121 
00122         if (soft_trigger){
00123                 RETERR(card.setSoftTriggeredMode(POST));
00124         }else{
00125                 if (strcmp(trigger_type, "lemo-master") == 0){
00126                         // lemo master
00127                         RETERR(card.setRoute(D3, R_LEMO, R_FPGA, R_PXI));
00128                 }else if (strcmp(trigger_type, "pxi-slave") == 0){
00129                         // slave card in same chassis
00130                         RETERR(card.setRoute(D3, R_PXI, R_FPGA));
00131                 }else{
00132                         // standalone lemo trg
00133                         RETERR(card.setRoute(D3, R_LEMO, R_FPGA));
00134                 }
00135                 dbg(1, "now set the mode");
00136                 RETERR(card.setTriggeredPostMode(POST));
00137         }
00138 
00139         RETERR(card.setArm());
00140         
00141         enum STATE s;
00142         int post;
00143         do {
00144                 sleep(1);
00145                 RETERR(card.getState(s));
00146                 RETERR(card.getNumSamples(&post));
00147                 printf("getState:%s total:%d\n", toString(s), post);
00148         } while(s != ST_STOP);
00149 
00150         
00151         delete [] channelMask;
00152         return 0;
00153 }