test-Serial.C

Go to the documentation of this file.
00001 /*!@file AppDevices/test-Serial.C Send raw data and recive data */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Lior Elazary <elazary@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppDevices/test-Serial.C $
00035 // $Id: test-Serial.C 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #include "Component/ModelManager.H"
00039 #include "Devices/Serial.H"
00040 #include "Util/Types.H"
00041 #include "Util/log.H"
00042 #include <unistd.h>
00043 #include <stdio.h>
00044 #include <signal.h>
00045 
00046 int main(int argc, const char **argv)
00047 {
00048         std::string USBDEV = "/dev/ttyUSB0";
00049 
00050   // Instantiate a ModelManager:
00051   ModelManager manager("Test Serial");
00052 
00053   nub::soft_ref<Serial> serial(new Serial(manager));
00054   manager.addSubComponent(serial);
00055 
00056 
00057   // Parse command-line:
00058   if (manager.parseCommandLine(argc, argv, "Serial Data", 0, 40) == false) return(1);
00059 
00060 //  serial->configure (USBDEV.c_str(), 115200, "8N1", false, false, 0);
00061   serial->configure("/dev/ttyUSB0", 115200);
00062 
00063   // let's get all our ModelComponent instances started:
00064   manager.start();
00065   usleep(1000);
00066 
00067   int numChar = manager.numExtraArgs();
00068   unsigned char buff[1024];
00069   for(int i=0; i<numChar; i++)
00070     buff[i] = manager.getExtraArgAs<int>(i);
00071 
00072   printf("Sending: ");
00073   for(int i=0; i<numChar; i++)
00074     printf("%i ", buff[i]);
00075   printf("\n");
00076 
00077 
00078 //  std::vector<unsigned char> frame = serial->readFrame(buff, numChar);
00079 //
00080 //  printf("Got Result: ");
00081 //  for(unsigned int i=0; i<frame.size(); i++)
00082 //    printf("%d ", frame.at(i));
00083 //  printf("\n");
00084 
00085   serial->write(buff, numChar);
00086   sleep(1);
00087 
00088   int ret= serial->read(buff, 1024);
00089         printf("Got Result From %s\n", USBDEV.c_str());
00090   printf("Got %i: ", ret);
00091   for(int i=0; i<ret; i++)
00092     printf(" %3d  ", buff[i]);
00093   printf("\n");
00094 
00095   printf("Hex %i: ", ret);
00096   for(int i=0; i<ret; i++)
00097     printf(" %3x  ", buff[i]);
00098   printf("\n");
00099 
00100   printf("Str %i: ", ret);
00101   for(int i=0; i<ret; i++)
00102     printf("[%3c] ", buff[i]);
00103   printf("\n");
00104 
00105   // stop all our ModelComponents
00106   manager.stop();
00107 
00108   // all done!
00109   return 0;
00110 }
Generated on Sun May 8 08:40:07 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3