Skip to content

Instantly share code, notes, and snippets.

@aborilov
Created June 6, 2013 08:01
Show Gist options
  • Select an option

  • Save aborilov/5720005 to your computer and use it in GitHub Desktop.

Select an option

Save aborilov/5720005 to your computer and use it in GitHub Desktop.
метод записи в порт
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