Results 1 to 9 of 9

Thread: [Linux] /dev/ttySAC0 - how can I read that file?

  1. #1
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default [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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: [Linux] /dev/ttySAC0 - how can I read that file?

    What have you tried so far?
    You mention that your program hangs.

  3. #3
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [Linux] /dev/ttySAC0 - how can I read that file?

    I've tried something like this:

    Qt Code:
    1. QFile file("/dev/ttySAC2");
    2.  
    3. int len = 0;
    4. char buffer[100];
    5.  
    6.  
    7. if (!file.open(QIODevice::ReadOnly)) {
    8. printf("error!");
    9. } else {
    10. int pending = file.bytesAvailable();
    11. out << QString::number(pending) << endl;
    12.  
    13. if ( pending > 0 ) {
    14. len = file.read(buffer, sizeof buffer - 1);
    15. }
    16.  
    17. if (len > 0) {
    18. [...]
    19. }
    To copy to clipboard, switch view to plain text mode 

    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

  4. #4
    Join Date
    Jan 2009
    Location
    Russia
    Posts
    309
    Thanks
    2
    Thanked 43 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  5. The following user says thank you to kuzulis for this useful post:

    Tomasz (7th November 2010)

  6. #5
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [Linux] /dev/ttySAC0 - how can I read that file?

    Use QLocalSocket and optionally QSocketNotifier.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    Tomasz (7th November 2010)

  9. #7
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [Linux] /dev/ttySAC0 - how can I read that file?

    Quote Originally Posted by wysota View Post
    Use QLocalSocket and optionally QSocketNotifier.
    How can I use QLocalSocket with file?

    thanks in advance
    best regards
    Tomasz

  10. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [Linux] /dev/ttySAC0 - how can I read that file?

    How about:

    Qt Code:
    1. int fd = open("/dev/ttySAC0", O_RDONLY|O_NONBLOCK);
    2. QSocketNotifier *socNotify = new QSocketNotifier(fd, QSocketNotifier::Read, this);
    3. connect(socNotify, SIGNAL(activated(int)), this, SLOT(your_read_function(int)));
    To copy to clipboard, switch view to plain text mode 

  11. The following user says thank you to squidge for this useful post:

    Tomasz (8th November 2010)

  12. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [Linux] /dev/ttySAC0 - how can I read that file?

    Quote Originally Posted by Tomasz View Post
    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. The following user says thank you to wysota for this useful post:

    Tomasz (8th November 2010)

Similar Threads

  1. Read from a file
    By matulik in forum Newbie
    Replies: 4
    Last Post: 26th April 2010, 19:02
  2. Read the file into
    By offline in forum Qt Programming
    Replies: 7
    Last Post: 12th April 2010, 12:11
  3. is qt phonon can read realmedia file and divx file
    By fayssalqt in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2009, 15:42
  4. Replies: 1
    Last Post: 20th June 2008, 18:43
  5. Read An Xml File
    By Alienxs in forum Qt Programming
    Replies: 3
    Last Post: 5th January 2007, 00:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.