Main Page | Modules | Class Hierarchy | Class List | File List | Class Members

di194_commands.cpp

00001 /***************************************************************************
00002                           di194_commands.cpp  -  Commands that can be sent
00003                                                  to a DI-194 device.
00004                              -------------------
00005     begin                : Thu Jun 3 2004
00006     author               : Ioan S. Popescu
00007 
00008 Copyright (C) 2004 DATAQ Instruments, Inc. <develop@dataq.com>
00009 
00010 This program is free software; you can redistribute it and/or 
00011 modify it under the terms of the GNU General Public License 
00012 as published by the Free Software Foundation; either 
00013 version 2 of the License, or (at your option) any later 
00014 version.
00015 
00016 This program is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 GNU General Public License for more details.
00020 
00021 You should have received a copy of the GNU General Public License
00022 along with this program; if not, write to the Free Software
00023 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  ***************************************************************************/
00025 #include "di194_commands.h"
00026 #include <unistd.h>
00027 
00028 /* file di194_commands.cpp
00029 * Special commands for the DI-194RS. All commands return true on success,
00030 * false otherwise.
00031 */
00032 
00043 const bool Ncmd(di_serial_io &conn, char *sn)
00044 {
00045   u_int8_t data[3] = {0, 'N', 'Z'};  // data to send
00046   for(int i = 0; i < DI194_SN_LENGTH; i++)
00047     sn[i] = 0;  // will hold serial number, blank for now
00048   u_int16_t amount = 3;
00049 
00050   if(conn.di_send(&data[0], amount)) // send data
00051     return false; // error in send
00052   amount = DI194_SN_LENGTH;
00053   // read serial number
00054   if(conn.di_read(reinterpret_cast<u_int8_t *>(sn), amount, 0))
00055     return false; // error in read
00056 
00057   return true; // no error in read
00058 }
00059 
00079 const bool Ccmd(di_serial_io &conn, const u_int8_t code)
00080 {
00081   u_int8_t data[3] = {0, 'C'};
00082   data[2] = code; // data to send
00083   if(data[2] > 0xF)   // bounds check
00084     data[2] = 0;
00085   u_int16_t amount = 3;
00086 
00087   if(conn.di_send(&data[0], amount)) // send data
00088     return false; // error in send
00089 
00090   return true;
00091 }
00092 
00104 const bool Dcmd(di_serial_io &conn, const u_int8_t code)
00105 {
00106   u_int8_t data[3] = {0, 'D'};
00107   data[2] = code+48; // data to send
00108   if(data[2] != '1' && data[2] != '0')  // bounds check
00109     data[2] = '1';
00110   u_int16_t amount = 3;
00111 
00112   if(conn.di_send(&data[0], amount)) // send data
00113     return false; // error in send
00114 
00115   return true;
00116 }
00117 
00129 const bool Scmd(di_serial_io &conn, const u_int8_t code)
00130 {
00131   u_int8_t data[3] = {0, 'S'};
00132   data[2] = code+48; // data to send
00133   if(data[2] != '1' && data[2] != '0')  // bounds check
00134     data[2] = '0';
00135   u_int16_t amount = 3;
00136 
00137   if(data[2] == '1')
00138   {
00139     // make sure device starts
00140     if(conn.di_send(&data[0], amount, 2, 1))
00141     {
00142       if(my_errno == EBADRSVP)
00143       {
00144         // didn't work first time, stop and try again
00145         data[2] = '0';
00146         if(conn.di_send(&data[0], amount, 2, 1))
00147         {
00148           // must be an error
00149           return false;
00150         }
00151         data[2] = code + 48;
00152         if(conn.di_send(&data[0], amount, 2, 1))
00153         { // must be an error
00154           return false;
00155         }
00156       }
00157       else
00158       {
00159         return false;
00160       }
00161     }
00162   }
00163   else
00164   {
00165     // get device to stop first
00166     if(!conn.di_send(&data[0], amount, 2, 1))
00167       return true;
00168 
00169     // send command again
00170     if(conn.di_send(&data[0], amount, 2))
00171       return false;
00172   }
00173 
00174   return true;
00175 }

Generated on Mon Aug 2 09:44:49 2004 for DataqSDK by doxygen 1.3.6