View Full Version : [Linux] /dev/ttySAC0 - how can I read that file?
Tomasz
5th November 2010, 15:48
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
tbscope
5th November 2010, 16:38
What have you tried so far?
You mention that your program hangs.
Tomasz
6th November 2010, 00:05
I've tried something like this:
QFile file("/dev/ttySAC2");
int len = 0;
char buffer[100];
if (!file.open(QIODevice::ReadOnly)) {
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
kuzulis
6th November 2010, 13:37
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.
Tomasz
7th November 2010, 13:43
But maybe someone have any idea how can i read from that file using standard classes?
thanks in advance
best regards
Tomasz
wysota
7th November 2010, 13:47
Use QLocalSocket and optionally QSocketNotifier.
Tomasz
7th November 2010, 14:41
Use QLocalSocket and optionally QSocketNotifier.
How can I use QLocalSocket with file?
thanks in advance
best regards
Tomasz
squidge
7th November 2010, 15:39
How about:
int fd = open("/dev/ttySAC0", O_RDONLY|O_NONBLOCK);
QSocketNotifier *socNotify = new QSocketNotifier(fd, QSocketNotifier::Read, this);
connect(socNotify, SIGNAL(activated(int)), this, SLOT(your_read_function(int)));
wysota
7th November 2010, 15:48
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).
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.