/[H7]/branches/linux-serial/Serial.cpp
ViewVC logotype

Diff of /branches/linux-serial/Serial.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 55 by torben, Mon Feb 5 10:11:47 2007 UTC revision 56 by torben, Mon Feb 5 10:24:24 2007 UTC
# Line 14  Line 14 
14  #include <stdexcept>  #include <stdexcept>
15  #include <string>  #include <string>
16  #include <sstream>  #include <sstream>
17    
18    #ifdef DEBUG
19  #include <iostream>  #include <iostream>
20  #include <iomanip>  #include <iomanip>
21    #endif
22    
23  #define _POSIX_SOURCE 1 /* POSIX compliant source */  #define _POSIX_SOURCE 1 /* POSIX compliant source */
24  #define BAUDRATE B9600  #define BAUDRATE B9600
# Line 131  void CSerial::openLinux() Line 134  void CSerial::openLinux()
134  {  {
135          termios newtio;          termios newtio;
136    
         std::cout << "opening port " << std::endl;        
137          mFiledescriptor = ::open(mPortstr, flags);          mFiledescriptor = ::open(mPortstr, flags);
138          if (mFiledescriptor < 0)          if (mFiledescriptor < 0)
139                  throw std::runtime_error( writeLastError() );                  throw std::runtime_error( writeLastError() );
140    
         std::cout << "port opened" << std::endl;  
141          bzero(&newtio, sizeof(newtio) );          bzero(&newtio, sizeof(newtio) );
142    
143          // use a std. 8N1 config          // use a std. 8N1 config
# Line 150  void CSerial::openLinux() Line 151  void CSerial::openLinux()
151          newtio.c_cc[VTIME]    = 0;   // inter-character timer unused          newtio.c_cc[VTIME]    = 0;   // inter-character timer unused
152          newtio.c_cc[VMIN]     = 0;   // blocking read until 1 chars received          newtio.c_cc[VMIN]     = 0;   // blocking read until 1 chars received
153                    
   
 /*      cfmakeraw(&newtio);  
         cfsetospeed(&newtio, B9600 );  
         cfsetispeed(&newtio, B9600 );  
 */        
154                                                                                    
155          tcflush(mFiledescriptor, TCIFLUSH);          tcflush(mFiledescriptor, TCIFLUSH);
156          tcsetattr(mFiledescriptor, TCSANOW, &newtio);          tcsetattr(mFiledescriptor, TCSANOW, &newtio);
157                    
         std::cout << "port configured " << std::endl;  
158          mIsopen = true;          mIsopen = true;
159  }  }
160  #endif  #endif
# Line 202  int CSerial::readByte() Line 197  int CSerial::readByte()
197          size = read(mFiledescriptor, &out, 1);          size = read(mFiledescriptor, &out, 1);
198          if (size != 1)          if (size != 1)
199          {          {
                 //std::cout << writeLastError() << std::endl;  
200                  return -1;                  return -1;
201          }          }
202  #endif  #endif
# Line 352  int CSerial::outQueueSize() const Line 346  int CSerial::outQueueSize() const
346  //  //
347  void CSerial::printByte(char* description, unsigned char byte)  void CSerial::printByte(char* description, unsigned char byte)
348  {  {
349    #ifdef DEBUG
350          std::cout << description << " : " <<  (int) byte << "/" << std::setw(2) << std::setfill('0') << std::hex << (int) byte << std::endl;          std::cout << description << " : " <<  (int) byte << "/" << std::setw(2) << std::setfill('0') << std::hex << (int) byte << std::endl;
351          std::cout << std::dec;          std::cout << std::dec;
352    #endif
353  }  }
354    
355    

Legend:
Removed from v.55  
changed lines
  Added in v.56

  ViewVC Help
Powered by ViewVC 1.1.20