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 "Serial.H" 00039 #include <unistd.h> 00040 #include <stdio.h> 00041 #include <signal.h> 00042 #include <cstdlib> 00043 int main(int argc, const char **argv) 00044 { 00045 std::string USBDEV = "/dev/ttyUSB0"; 00046 00047 // Instantiate a ModelManager: 00048 //ModelManager manager("Test Serial"); 00049 00050 Serial *serial = new Serial(); 00051 00052 00053 // Parse command-line: 00054 // if (manager.parseCommandLine(argc, argv, "Serial Data", 0, 40) == false) return(1); 00055 00056 // serial->configure (USBDEV.c_str(), 115200, "8N1", false, false, 0); 00057 serial->configure("/dev/ttyUSB0", 115200); 00058 00059 // let's get all our ModelComponent instances started: 00060 serial->start(); 00061 usleep(1000); 00062 00063 // int numChar = manager.numExtraArgs(); 00064 unsigned char buff[1024]; 00065 int numChar = argc -1; 00066 unsigned char* test; 00067 for(int i=0; i<numChar; i++){ 00068 buff[i] = atoi(argv[i+1]); 00069 } 00070 00071 printf("Sending: "); 00072 for(int i=0; i<numChar; i++) 00073 printf("%i ", buff[i]); 00074 printf("\n"); 00075 00076 serial->write(buff,numChar); 00077 sleep(1); 00078 int ret= serial->read(buff, 1024); 00079 printf("Got Result From %s\n", USBDEV.c_str()); 00080 printf("Got %i: ", ret); 00081 for(int i=0; i<ret; i++){ 00082 printf(" %3d ", buff[i]); 00083 if(i%10==0) 00084 printf("\n"); 00085 } 00086 printf("\n"); 00087 00088 printf("Hex %i: ", ret); 00089 for(int i=0; i<ret; i++){ 00090 printf(" %3x ", buff[i]); 00091 if(i%10==0) 00092 printf("\n"); 00093 } 00094 printf("\n"); 00095 00096 printf("Str %i: ", ret); 00097 for(int i=0; i<ret; i++){ 00098 printf("[%3c] ", buff[i]); 00099 if(i%10==0) 00100 printf("\n"); 00101 } 00102 printf("\n"); 00103 00104 //Testing readFrame 00105 for(int i=0; i<numChar; i++){ 00106 buff[i] = atoi(argv[i+1]); 00107 } 00108 00109 printf("Sending: "); 00110 for(int i=0; i<numChar; i++) 00111 printf("%i ", buff[i]); 00112 printf("\n"); 00113 serial->write(buff,numChar); 00114 std::vector<unsigned char> frame = serial->readFrame(buff[0],255); 00115 printf("Got Result From %s with size[%d]\n", USBDEV.c_str(),frame.size()); 00116 for(int i=0;i<frame.size();i++) 00117 { 00118 printf(" %3d ", frame[i]); 00119 if(i%10==0) 00120 printf("\n"); 00121 } 00122 printf("\n"); 00123 00124 00125 // stop all our ModelComponents 00126 serial->stop(); 00127 00128 // all done! 00129 return 0; 00130 }