9.10.2011 - stable backup commit
This commit is contained in:
28
piserial.cpp
28
piserial.cpp
@@ -8,9 +8,8 @@ PISerial::PISerial(PIString name, void * data_, SerialFunc slot): PIThread() {
|
||||
fd = -1;
|
||||
dataSize = headerSize = 0;
|
||||
headerPtr = 0;
|
||||
hbuffer = pbuffer = 0;
|
||||
ret_func = slot;
|
||||
//buffer = new char[BUFFER_SIZE];
|
||||
//sbuffer = new char[BUFFER_SIZE];
|
||||
#ifdef WINDOWS
|
||||
hCom = 0;
|
||||
#endif
|
||||
@@ -20,10 +19,6 @@ PISerial::PISerial(PIString name, void * data_, SerialFunc slot): PIThread() {
|
||||
|
||||
PISerial::~PISerial() {
|
||||
terminate();
|
||||
/*if (buffer != 0) delete buffer;
|
||||
buffer = 0;
|
||||
if (sbuffer != 0) delete sbuffer;
|
||||
sbuffer = 0;*/
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +26,7 @@ void PISerial::terminate() {
|
||||
if (!initialized()) return;
|
||||
if (isRunning()) {
|
||||
stop();
|
||||
pthread_cancel(thread);
|
||||
PIThread::terminate();
|
||||
}
|
||||
#ifdef WINDOWS
|
||||
if (fd != -1) {
|
||||
@@ -174,8 +169,14 @@ void PISerial::run() {
|
||||
|
||||
void PISerial::end() {
|
||||
terminate();
|
||||
delete pbuffer;
|
||||
delete hbuffer;
|
||||
if (pbuffer != 0) {
|
||||
delete pbuffer;
|
||||
pbuffer = 0;
|
||||
}
|
||||
if (hbuffer != 0) {
|
||||
delete hbuffer;
|
||||
hbuffer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +207,10 @@ bool PISerial::init() {
|
||||
desc.DCBlength = sizeof(desc);
|
||||
desc.BaudRate = convertSpeed(ispeed);
|
||||
desc.ByteSize = 8;
|
||||
desc.fParity = params[PISerial::IgnoreParityControl] ? 0 : 1;
|
||||
if (params[PISerial::ParityControl]) {
|
||||
desc.fParity = 1;
|
||||
desc.Parity = params[PISerial::ParityOdd] ? 1 : 2;
|
||||
}
|
||||
desc.StopBits = params[PISerial::TwoStopBits] ? TWOSTOPBITS : ONESTOPBIT;
|
||||
if (SetCommState(hCom, &desc) == -1) {
|
||||
cout << "[PISerial] Unable to set comm state for \"" << devName << "\"" << endl;
|
||||
@@ -227,10 +231,10 @@ bool PISerial::init() {
|
||||
desc.c_iflag = desc.c_oflag = desc.c_lflag = 0;
|
||||
desc.c_cflag = CLOCAL | CREAD | CSIZE;
|
||||
if (params[PISerial::TwoStopBits]) desc.c_cflag |= CSTOPB;
|
||||
if (!params[PISerial::ParityControl]) {
|
||||
if (params[PISerial::ParityControl]) {
|
||||
desc.c_iflag |= INPCK;
|
||||
desc.c_cflag |= PARENB;
|
||||
if (!params[PISerial::ParityOdd]) desc.c_cflag |= PARODD;
|
||||
if (params[PISerial::ParityOdd]) desc.c_cflag |= PARODD;
|
||||
}
|
||||
desc.c_cc[VMIN] = 0;
|
||||
desc.c_cc[VTIME] = 1;
|
||||
|
||||
Reference in New Issue
Block a user