1 |
#ifndef _MSC_VER //linux |
#ifndef _MSC_VER //linux |
2 |
#include <sys/types.h> |
#include <sys/types.h> |
3 |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
|
|
4 |
#include <unistd.h> |
#include <unistd.h> |
5 |
#include <errno.h> |
#include <errno.h> |
6 |
#include <termios.h> |
#include <termios.h> |
7 |
#include <fcntl.h> |
#include <fcntl.h> |
8 |
#endif |
#endif |
9 |
|
|
|
#include "stdafx.h" |
|
|
#include "Serial.h" |
|
10 |
|
|
11 |
#include <stdexcept> |
#include <stdexcept> |
12 |
#include <string> |
#include <string> |
17 |
#include <iomanip> |
#include <iomanip> |
18 |
#endif |
#endif |
19 |
|
|
20 |
#define _POSIX_SOURCE 1 /* POSIX compliant source */ |
#include "stdafx.h" |
21 |
#define BAUDRATE B9600 |
#include "Serial.h" |
22 |
|
|
|
#ifndef _MSC_VER // ugly hack, else will gcc not accept this constant in openLinux() |
|
|
const int flags = O_RDWR | O_NOCTTY | O_NONBLOCK; |
|
|
#endif |
|
23 |
|
|
24 |
std::string writeLastError() |
std::string writeLastError() |
25 |
{ |
{ |
34 |
NULL); |
NULL); |
35 |
|
|
36 |
std::ostringstream out; |
std::ostringstream out; |
37 |
out << "Error" << lpMsgBuf; |
out << "Error " << lpMsgBuf; |
38 |
return out.str(); |
return out.str(); |
39 |
#else //linux |
#else //linux |
40 |
return std::string( strerror(errno) ); |
return std::string( strerror(errno) ); |
128 |
{ |
{ |
129 |
termios newtio; |
termios newtio; |
130 |
|
|
131 |
mFiledescriptor = ::open(mPortstr, flags); |
mFiledescriptor = ::open(mPortstr, O_RDWR | O_NOCTTY | O_NONBLOCK); |
132 |
if (mFiledescriptor < 0) |
if (mFiledescriptor < 0) |
133 |
throw std::runtime_error( writeLastError() ); |
throw std::runtime_error( writeLastError() ); |
134 |
|
|