You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I have found strange behavior when I was reading a long data flow. If the data size more than readBufferSize_B_ (default value is 256) it will not receive other part of the data.
There are two ways to resolve it:
Using a cycle. For example:
voidSerialPort::Read(std::string& data) {
PortIsOpened(__PRETTY_FUNCTION__);
// Read from file// We provide the underlying raw array from the readBuffer_ vector to this C api.// This will work because we do not delete/resize the vector while this method// is calledwhile (ssize_t n = read(fileDesc_, &readBuffer_[0], readBufferSize_B_)){
// Error Handlingif(n < 0) {
// Read was unsuccessfulthrowstd::system_error(EFAULT, std::system_category());
}
elseif(n == 0) {
// n == 0 means EOS, but also returned on device disconnection. We try to get termios2 to distinguish two these two statesstructtermios2 term2;
int rv = ioctl(fileDesc_, TCGETS2, &term2);
if(rv != 0) {
throwstd::system_error(EFAULT, std::system_category());
}
}
elseif(n > 0) {
data += std::string(&readBuffer_[0], n);
}
}
// If code reaches here, read must of been successful
}
Return 'n'. User will be responsible for cycling reading.
Hello! I have found strange behavior when I was reading a long data flow. If the data size more than readBufferSize_B_ (default value is 256) it will not receive other part of the data.
There are two ways to resolve it:
What do you think about it?