Created
June 6, 2013 08:01
-
-
Save aborilov/5720005 to your computer and use it in GitHub Desktop.
метод записи в порт
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void ConnectionManager::need2send(QByteArray b){ | |
| turn2Write(); | |
| int sended = write(fd, b.data(), b.size()); | |
| #ifdef QT_DEBUG | |
| if (sended != b.size()) | |
| QLOG_ERROR()<<"!!!!!!!!!!!!!NOT ALL SENDED!!!!ONLY: "<<sended; | |
| #endif | |
| tcflush(fd, TCOFLUSH); | |
| opt.c_cc[VMIN] = sended; /* Minimum bytes available */ | |
| tcsetattr (fd, TCSANOW, &opt); | |
| int readed = 0; | |
| char r[sended]; | |
| int count; | |
| count = 0; | |
| msleep(sended+2); | |
| while (count<100 && readed<sended){ | |
| count++; | |
| int c = read (fd, r, sended); | |
| if (c<0) | |
| perror("error while reading"); | |
| if (c>0){ | |
| readed += c; | |
| }else{ | |
| msleep(1); | |
| #ifdef QT_DEBUG | |
| QLOG_WARN()<<"SLEEP!!! read = "<<readed; | |
| #endif | |
| } | |
| } | |
| // msleep(1); | |
| startReading(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment