LLC2_API
example1.cpp
Go to the documentation of this file.
00001 /* ------------------------------------------------------------------------- */
00002 /* file example1.cpp                                                                 */
00003 /* ------------------------------------------------------------------------- */
00004 /*   Copyright (C) 2011 Peter Milne, D-TACQ Solutions Ltd
00005  *                      <Peter dot Milne at D hyphen TACQ dot com>
00006  *  Created on: Sep 14, 2011
00007  *      Author: pgm
00008 
00009     http://www.d-tacq.com
00010 
00011     This program is free software; you can redistribute it and/or modify
00012     it under the terms of Version 2 of the GNU General Public License
00013     as published by the Free Software Foundation;
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU General Public License for more details.
00019 
00020     You should have received a copy of the GNU General Public License
00021     along with this program; if not, write to the Free Software
00022     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
00023 /* ------------------------------------------------------------------------- */
00024 
00025 /** @file example1.cpp simple 2 card example.
00026  *
00027  * @verbatim
00028 
00029  Minimal "real control system":
00030 
00031 
00032    @endverbatim
00033  */
00034 #include <stdio.h>
00035 #include <sys/types.h>
00036 #include <sys/stat.h>
00037 #include <unistd.h>
00038 #include <stdlib.h>
00039 #include <errno.h>
00040 #include <assert.h>
00041 
00042 #include "ll2.h"
00043 #include "testharness.h"
00044 
00045 
00046 int getenvint(const char* key, int idefault)
00047 {
00048         const char* value = getenv(key);
00049         if (value){
00050                 return atoi(value);
00051         }else{
00052                 return idefault;
00053         }
00054 }
00055 
00056 int main(int argc, const char* argv[])
00057 {
00058         LL_ControlSystem& the_system = LL_ControlSystem::create("example1");
00059 #define SAMPLES (the_system.getSamples())
00060 
00061         const int ACQ196_SLOT = getenvint("MB", 2);
00062         const int AO32_SLOT = getenvint("S1", 4);
00063 
00064         the_system.addCard(new ACQ196(ACQ196_SLOT));
00065         the_system.addCard(new AO32(AO32_SLOT));
00066         the_system.init(argc, argv);
00067 
00068         Outputs outputs(the_system.getAO_count(), the_system.getDO_count());
00069         Inputs inputs(SAMPLES,
00070                         the_system.getAI_count(), the_system.getDI_count(), the_system.getStatus_count());
00071 
00072         the_system.Arm(outputs.getAO(0), outputs.getDO(0));
00073 
00074         for (int ii = 0; ii < SAMPLES; ++ii){
00075                 int rc = the_system.IO(
00076                                 outputs.getAO(ii), outputs.getDO(ii),
00077                                 inputs.getAI(ii), inputs.getDI(ii), inputs.getStatus(ii));
00078         }
00079 
00080         the_system.Stop();
00081         LL_ControlSystem::closedown(the_system);
00082 }