/[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 46 by torben, Sun Feb 4 23:11:02 2007 UTC revision 47 by torben, Mon Feb 5 00:48:02 2007 UTC
# Line 19  Line 19 
19  #include <iomanip>  #include <iomanip>
20    
21  #define _POSIX_SOURCE 1 /* POSIX compliant source */  #define _POSIX_SOURCE 1 /* POSIX compliant source */
22  #define BAUDRATE B38400  #define BAUDRATE B9600
23    
24  #ifndef _WINDOWS // ugly hack, else will gcc not accept this constant in openLinux()  #ifndef _WINDOWS // ugly hack, else will gcc not accept this constant in openLinux()
25  const int flags = O_RDWR | O_NOCTTY | O_NONBLOCK;  const int flags = O_RDWR | O_NOCTTY ; //| O_NONBLOCK;
26  #endif  #endif
27    
28  std::string writeLastError()  std::string writeLastError()
# Line 148  void CSerial::openLinux() Line 148  void CSerial::openLinux()
148          newtio.c_lflag = 0;          newtio.c_lflag = 0;
149                                                    
150          newtio.c_cc[VTIME]    = 0;   /* inter-character timer unused */          newtio.c_cc[VTIME]    = 0;   /* inter-character timer unused */
151          newtio.c_cc[VMIN]     = 1;   /* blocking read until 1 chars received */          newtio.c_cc[VMIN]     = 0;   /* blocking read until 1 chars received */
152    
153            cfmakeraw(&newtio);
154            cfsetospeed(&newtio, BAUDRATE);
155            
156                                                                                    
157          tcflush(mFiledescriptor, TCIFLUSH);          tcflush(mFiledescriptor, TCIFLUSH);
158          tcsetattr(mFiledescriptor, TCSANOW, &newtio);          tcsetattr(mFiledescriptor, TCSANOW, &newtio);
# Line 177  void CSerial::close() Line 181  void CSerial::close()
181  }  }
182    
183    
184  unsigned char CSerial::readByte()  int CSerial::readByte()
185  {  {
186          unsigned char out;          unsigned char out;
187          unsigned long size;          unsigned long size;
# Line 194  unsigned char CSerial::readByte() Line 198  unsigned char CSerial::readByte()
198          }          }
199  #else //linux readByte()  #else //linux readByte()
200          size = read(mFiledescriptor, &out, 1);          size = read(mFiledescriptor, &out, 1);
201          if (size != 1)          if (size != 1)
202                  throw std::runtime_error( writeLastError() );          {
203                    std::cout << writeLastError() << std::endl;
204                    return -1;
205            }
206  #endif  #endif
207    
208          printByte("Read", out);          printByte("Read", out);
# Line 207  void CSerial::writeByte(unsigned char ou Line 214  void CSerial::writeByte(unsigned char ou
214  {  {
215          unsigned long size;          unsigned long size;
216    
217          //printByte("Write", out);          printByte("Write", out);
218          if (!mIsopen)          if (!mIsopen)
219                  throw std::runtime_error("Port not opened");                  throw std::runtime_error("Port not opened");
220    
# Line 223  void CSerial::writeByte(unsigned char ou Line 230  void CSerial::writeByte(unsigned char ou
230                  throw std::exception(error.c_str());                  throw std::exception(error.c_str());
231          }          }
232  #else //linux writeByte()  #else //linux writeByte()
233            //tcdrain(mFiledescriptor);
234          size = write(mFiledescriptor,&out,1);          size = write(mFiledescriptor,&out,1);
235            Sleep(50);
236            //tcdrain(mFiledescriptor);
237          if (size != 1)          if (size != 1)
238                  throw std::runtime_error(writeLastError() );                  throw std::runtime_error(writeLastError() );
239  #endif  #endif

Legend:
Removed from v.46  
changed lines
  Added in v.47

  ViewVC Help
Powered by ViewVC 1.1.20