4.06.2013 - Version 0.3.4 - PIOBJECT() macro, ethernet improvement, documentation based on Doxygen
This commit is contained in:
34
piserial.cpp
34
piserial.cpp
@@ -67,14 +67,14 @@ bool PISerial::setPin(int number, bool on) {
|
||||
case 3: return setST(on); break;
|
||||
case 4: return setDTR(on); break;
|
||||
case 5:
|
||||
piCout << "[PISerial] Pin number 5 is ground" << endl;
|
||||
piCout << "[PISerial] Pin number 5 is ground";
|
||||
return false;
|
||||
case 6: return setDSR(on); break;
|
||||
case 7: return setRTS(on); break;
|
||||
case 8: return setCTS(on); break;
|
||||
case 9: return setRNG(on); break;
|
||||
default:
|
||||
piCout << "[PISerial] Pin number " << number << " doesn`t exists!" << endl;
|
||||
piCout << "[PISerial] Pin number " << number << " doesn`t exists!";
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@@ -93,7 +93,7 @@ bool PISerial::isPin(int number) const {
|
||||
case 8: return isCTS(); break;
|
||||
case 9: return isRNG(); break;
|
||||
default:
|
||||
piCout << "[PISerial] Pin number " << number << " doesn`t exists!" << endl;
|
||||
piCout << "[PISerial] Pin number " << number << " doesn`t exists!";
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@@ -103,7 +103,7 @@ bool PISerial::isPin(int number) const {
|
||||
bool PISerial::setBit(int bit, bool on, const PIString & bname) {
|
||||
#ifndef WINDOWS
|
||||
if (fd < 0) {
|
||||
piCout << "[PISerial] set" << bname << " error: \"" << path_ << "\" is not opened!" << endl;
|
||||
piCout << "[PISerial] set" << bname << " error: \"" << path_ << "\" is not opened!";
|
||||
return false;
|
||||
}
|
||||
if (ioctl(fd, on ? TIOCMBIS : TIOCMBIC, &bit) < 0) {
|
||||
@@ -112,7 +112,7 @@ bool PISerial::setBit(int bit, bool on, const PIString & bname) {
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
piCout << "[PISerial] set" << bname << " doesn`t implemented on Windows, sorry :-(" << endl;
|
||||
piCout << "[PISerial] set" << bname << " doesn`t implemented on Windows, sorry :-(";
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
@@ -121,7 +121,7 @@ bool PISerial::setBit(int bit, bool on, const PIString & bname) {
|
||||
bool PISerial::isBit(int bit, const PIString & bname) const {
|
||||
#ifndef WINDOWS
|
||||
if (fd < 0) {
|
||||
piCout << "[PISerial] is" << bname << " error: \"" << path_ << "\" is not opened!" << endl;
|
||||
piCout << "[PISerial] is" << bname << " error: \"" << path_ << "\" is not opened!";
|
||||
return false;
|
||||
}
|
||||
int ret = 0;
|
||||
@@ -129,7 +129,7 @@ bool PISerial::isBit(int bit, const PIString & bname) const {
|
||||
piCout << "[PISerial] is" << bname << " error: " << errorString();
|
||||
return ret & bit;
|
||||
#else
|
||||
piCout << "[PISerial] set" << bname << " doesn`t implemented on Windows, sorry :-(" << endl;
|
||||
piCout << "[PISerial] set" << bname << " doesn`t implemented on Windows, sorry :-(";
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
@@ -301,7 +301,7 @@ bool PISerial::openDevice() {
|
||||
if (isWriteable()) {ds |= GENERIC_WRITE; sm |= FILE_SHARE_WRITE;}
|
||||
hCom = CreateFileA(path_.data(), ds, sm, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, 0);
|
||||
if(hCom == INVALID_HANDLE_VALUE) {
|
||||
piCout << "[PISerial] Unable to open \"" << path_ << "\"" << endl;
|
||||
piCout << "[PISerial] Unable to open \"" << path_ << "\"";
|
||||
return false;
|
||||
}
|
||||
fd = 0;
|
||||
@@ -312,7 +312,7 @@ bool PISerial::openDevice() {
|
||||
times.WriteTotalTimeoutConstant = 1;
|
||||
times.WriteTotalTimeoutMultiplier = 0;
|
||||
if (SetCommTimeouts(hCom, ×) == -1) {
|
||||
piCout << "[PISerial] Unable to set timeouts for \"" << path_ << "\"" << endl;
|
||||
piCout << "[PISerial] Unable to set timeouts for \"" << path_ << "\"";
|
||||
CloseHandle(hCom);
|
||||
fd = -1;
|
||||
return false;
|
||||
@@ -330,7 +330,7 @@ bool PISerial::openDevice() {
|
||||
}
|
||||
desc.StopBits = params[PISerial::TwoStopBits] ? TWOSTOPBITS : ONESTOPBIT;
|
||||
if (SetCommState(hCom, &desc) == -1) {
|
||||
piCout << "[PISerial] Unable to set comm state for \"" << path_ << "\"" << endl;
|
||||
piCout << "[PISerial] Unable to set comm state for \"" << path_ << "\"";
|
||||
CloseHandle(hCom);
|
||||
fd = -1;
|
||||
return false;
|
||||
@@ -345,7 +345,7 @@ bool PISerial::openDevice() {
|
||||
//cout << "init ser " << path_ << " mode " << om << " param " << params << endl;
|
||||
fd = ::open(path_.data(), O_NOCTTY | om);
|
||||
if(fd == -1) {
|
||||
piCout << "[PISerial] Unable to open \"" << path_ << "\"" << endl;
|
||||
piCout << "[PISerial] Unable to open \"" << path_ << "\"";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -371,20 +371,20 @@ bool PISerial::openDevice() {
|
||||
fcntl(fd, F_SETFL, 0);
|
||||
|
||||
if(tcsetattr(fd, TCSANOW, &desc) < 0) {
|
||||
piCout << "[PISerial] Can`t set attributes for \"" << path_ << "\"" << endl;
|
||||
piCout << "[PISerial] Can`t set attributes for \"" << path_ << "\"";
|
||||
::close(fd);
|
||||
return false;
|
||||
}
|
||||
//piCout << "[PISerial] Initialized " << path_ << endl;
|
||||
//piCout << "[PISerial] Initialized " << path_;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int PISerial::write(const void * data, int max_size, bool wait) {
|
||||
//piCout << "[PISerial] send " << max_size << ": " << PIString((char*)data, max_size) << endl;
|
||||
//piCout << "[PISerial] send " << max_size << ": " << PIString((char*)data, max_size);
|
||||
if (fd == -1 || !canWrite()) {
|
||||
//piCout << "[PISerial] Can`t write to uninitialized COM" << endl;
|
||||
//piCout << "[PISerial] Can`t write to uninitialized COM";
|
||||
return -1;
|
||||
}
|
||||
#ifdef WINDOWS
|
||||
@@ -402,6 +402,6 @@ int PISerial::write(const void * data, int max_size, bool wait) {
|
||||
if (wait) tcdrain(fd);
|
||||
#endif
|
||||
return (int)wrote;
|
||||
//piCout << "[PISerial] Error while sending" << endl;
|
||||
//piCout << "[PISerial] Wrote " << wrote << " bytes in " << path_ << endl;
|
||||
//piCout << "[PISerial] Error while sending";
|
||||
//piCout << "[PISerial] Wrote " << wrote << " bytes in " << path_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user