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 |
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 |
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 |
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 |
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 |
|
|