serialmain.cpp

00001 /**********************************************************************
00002  * C/C++ Source: main.cc
00003  *
00004  * Test harness for the serialecho class
00005  *
00006  * @author:  Gary Lawrence Murphy <garym@teledyn.com>
00007  * Copyright:  2000 TeleDynamics Communications Inc (www.teledyn.com)
00008  ********************************************************************
00009 */
00010 // Copyright (C) 1999-2000 Teledynamics Communications Inc.
00011 //
00012 // This program is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU General Public License as published by
00014 // the Free Software Foundation; either version 2 of the License, or
00015 // (at your option) any later version.
00016 //
00017 // This program is distributed in the hope that it will be useful,
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU General Public License
00023 // along with this program; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00025 //
00026 // Created 2000/10/14 10:56:35 EDT by garym@teledyn.com
00027 
00028 #include "serialecho.h"
00029 #ifndef WIN32
00030 #include <cstdlib>
00031 #endif
00032 
00033 int main(int argc, char **argv)
00034 {
00035   cout << "Serial Echo to TCP Sessions" << endl;
00036   SerialEcho *modem = NULL;
00037   try {
00038         modem = new SerialEcho("/dev/modem2");
00039   } catch (SerialEcho::xError *e) {
00040         cout << "Modem Error; aborting" << endl;
00041         ::exit(1);
00042   } catch (Serial *e) {
00043         cout << "Serial Error: "
00044                  << modem->getErrorString()
00045                  << "; aborting"
00046                  << endl;
00047         ::exit(1);
00048   }
00049 
00050   char* b = new char[modem->getBufferSize()];
00051 
00052   cout << "Modem code:" << modem->start() << endl;
00053 
00054   while (cin >> b, b[0]) {
00055 
00056         *modem << b << "\r" << endl;
00057 
00058         cout << "sent: " << b << endl;
00059         memset( b, 0, sizeof(b));
00060 
00061   }
00062   cout << "fin" << endl;
00063 
00064   delete [] b;
00065 
00066   return 0;
00067 }
00068 

Generated on Sun Mar 21 21:39:51 2010 for GNU CommonC++ by  doxygen 1.4.7