PISerial setBreak

This commit is contained in:
Andrey
2021-09-16 12:18:17 +03:00
parent 0d119502a8
commit ece3fb1536
2 changed files with 29 additions and 0 deletions

View File

@@ -289,6 +289,29 @@ bool PISerial::isRNG() const {return isBit(TIOCM_RNG, "RNG");}
bool PISerial::isDSR() const {return isBit(TIOCM_DSR, "DSR");} bool PISerial::isDSR() const {return isBit(TIOCM_DSR, "DSR");}
bool PISerial::setBreak(bool enabled) {
if (fd < 0) {
piCoutObj << "sendBreak error: \"" << path() << "\" is not opened!";
return false;
}
#ifdef WINDOWS
if (enabled) {
if (!SetCommBreak(PRIVATE->hCom)) return false;
} else {
if (!ClearCommBreak(PRIVATE->hCom)) return false;
}
#else
if (::ioctl(descriptor, enabled ? TIOCSBRK : TIOCCBRK) < 0) {
piCoutObj << "setBreak error: " << errorString();
return false;
} else {
return true;
}
#endif
return false;
}
bool PISerial::setBit(int bit, bool on, const PIString & bname) { bool PISerial::setBit(int bit, bool on, const PIString & bname) {
if (fd < 0) { if (fd < 0) {
piCoutObj << "setBit" << bname << " error: \"" << path() << "\" is not opened!"; piCoutObj << "setBit" << bname << " error: \"" << path() << "\" is not opened!";

View File

@@ -159,6 +159,12 @@ public:
bool isRNG() const; bool isRNG() const;
bool isDSR() const; bool isDSR() const;
//! Switch transmission line in break if enabled.
//! i.e. sends a continuous stream of zero bits.
//! If successful, returns true; otherwise returns false.
//! The serial port has to be open before trying to send a break duration; otherwise returns false
bool setBreak(bool enabled);
void setVTime(int t) {vtime = t; applySettings();} void setVTime(int t) {vtime = t; applySettings();}
//! Returns device name //! Returns device name