[Linux] /dev/ttySAC0 - how can I read that file?
Hello!
I want to read (only read) /dev/ttySAC0. I wrote simple program in C, and It works fine in console. Now I want to do the same using QT. But when I want to read from that file program hangs. Any ideas what can I do? Data in that file is refreshing in every 1 second and it comes by RS232 from another device.
thanks in advance
best regards
Tomasz
Re: [Linux] /dev/ttySAC0 - how can I read that file?
What have you tried so far?
You mention that your program hangs.
Re: [Linux] /dev/ttySAC0 - how can I read that file?
I've tried something like this:
Code:
QFile file("/dev/ttySAC2");
int len = 0;
char buffer[100];
printf("error!");
} else {
int pending = file.bytesAvailable();
out <<
QString::number(pending
) << endl;
if ( pending > 0 ) {
len = file.read(buffer, sizeof buffer - 1);
}
if (len > 0) {
[...]
}
And also something with QTextStream. Program hangs when it is trying to read from that file. In console program there was no problem.
thanks in advance
best regards
Tomasz
Re: [Linux] /dev/ttySAC0 - how can I read that file?
Tomasz,
try use library for serial programming in Qt4:
1. QSerialDevice (in gitorgious.org)
2. qextserialport (in google.com)
3. qserialport (in gitorgious.org)
and etc. analogs.
Choose yourself what you like.
Re: [Linux] /dev/ttySAC0 - how can I read that file?
But maybe someone have any idea how can i read from that file using standard classes?
thanks in advance
best regards
Tomasz
Re: [Linux] /dev/ttySAC0 - how can I read that file?
Re: [Linux] /dev/ttySAC0 - how can I read that file?
Quote:
Originally Posted by
wysota
How can I use QLocalSocket with file?
thanks in advance
best regards
Tomasz
Re: [Linux] /dev/ttySAC0 - how can I read that file?
How about:
Code:
int fd = open("/dev/ttySAC0", O_RDONLY|O_NONBLOCK);
connect(socNotify, SIGNAL(activated(int)), this, SLOT(your_read_function(int)));
Re: [Linux] /dev/ttySAC0 - how can I read that file?
Quote:
Originally Posted by
Tomasz
How can I use QLocalSocket with file?
/dev/ttySAC0 is not a file, it's a stream you can connect to using QLocalSocket. Or you can use QSocketNotifier with native stream handling (see the example squidge gave you).