Results 1 to 3 of 3

Thread: bytesAvailable() allways returning 0

  1. #1
    Join Date
    Oct 2012
    Posts
    2
    Platforms
    MacOS X Unix/X11

    Default bytesAvailable() allways returning 0

    ok here is the background, Im trying to open /dev/dvb/adapter0/demux0 for read/write. I know the write (ioctl) is successful as I can see it setup in my kernel logs. but no matter what I try bytesAvailable() always returns 0.

    Qt Code:
    1. dmx_fd = new QFile("/dev/dvb/adapter0/demux0");
    2. if (!dmx_fd->open(QIODevice::ReadWrite))
    3. cout << "open() failed" << endl;
    4.  
    5. struct dmx_sct_filter_params sctfilter;
    6. memset(&sctfilter, 0, sizeof(struct dmx_sct_filter_params));
    7. sctfilter.pid = 0x11;
    8. sctfilter.timeout = 5000;
    9. sctfilter.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC;
    10.  
    11. if (ioctl(dmx_fd->handle(), DMX_SET_FILTER, &sctfilter) == -1)
    12. cout << "DEMUX: DMX_SET_FILTER" << endl;
    13.  
    14. cout << "isSequential() = " << dmx_fd->isSequential() << endl;
    15. cout << "isReadable() = " << dmx_fd->isReadable() << endl;
    16. cout << "bytesAvailable() = " << dmx_fd->bytesAvailable() << endl;
    17.  
    18. dmx_fd->waitForReadyRead(5000);
    19. sleep(5);
    20.  
    21. cout << "isReadable() = " << dmx_fd->isReadable() << endl;
    22. cout << "bytesAvailable() = " << dmx_fd->bytesAvailable() << endl;
    23.  
    24. buffer.clear();
    25. buffer = dmx_fd->read(dmx_fd->bytesAvailable());
    26. cout << "Length read: " << buffer.size() << endl;
    27.  
    28. ioctl(dmx_fd->handle(), DMX_STOP);
    29. dmx_fd->close();
    To copy to clipboard, switch view to plain text mode 

    outputs

    Qt Code:
    1. Starting /home/updatelee/src/untitled/untitled...
    2. isSequential() = 1
    3. isReadable() = 1
    4. bytesAvailable() = 0
    5. isReadable() = 1
    6. bytesAvailable() = 0
    7. Length read: 0
    8. /home/updatelee/src/untitled/untitled exited with code 0
    To copy to clipboard, switch view to plain text mode 

    Ive got the adapter tuned by another app if anyone was wondering. The demux is ready to accept pids as I can use my C app on it just fine, as well as my b*stardized qt app with :pen() calls.

    QMake version 2.01a
    Using Qt version 4.8.3 in /usr/lib/x86_64-linux-gnu
    Qt Creator 2.5.2

    Any idea's ?
    Attached Files Attached Files

  2. #2
    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: bytesAvailable() allways returning 0

    @updatelee

    Because /dev/dvb/adapter0/demux0 is device, not file, and bytesAvailable() should be wrapper for ioctl().
    Therefore QFile::bytesAvailable() will not work, because this implementation specific for the file system only.

    You should be make custom class for "demux" device, inherited from QIODevice and implement all necessary methods,
    include open(), close(), bytesAvailable() and so forth.

  3. #3
    Join Date
    Oct 2012
    Posts
    2
    Platforms
    MacOS X Unix/X11

    Default Re: bytesAvailable() allways returning 0

    Its just odd that I can write to it using QFile but not read.

    the packet im receiving is 131 bytes long. (in this case, its not a constant depending on the signal Ive tuned, just in this case I know its 131 bytes long)

    Qt Code:
    1. int BUFFY = 10*188*1024;
    2. char buf[BUFFY];
    3. memset(buf, 0, BUFFY);
    4. int len = read(dmx_fd->handle(), buf, BUFFY);
    5. cout << "Length read: " << len << endl;
    To copy to clipboard, switch view to plain text mode 

    outputs

    Qt Code:
    1. Length read: 131
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. int BUFFY = 10*188*1024;
    2. buffer.clear();
    3. buffer = dmx_fd->read(BUFFY);
    4. cout << "Length read: " << buffer.size() << endl;
    To copy to clipboard, switch view to plain text mode 
    application locks up on the read()

    Qt Code:
    1. buffer.clear();
    2. buffer = dmx_fd->read(131);
    3. cout << "Length read: " << buffer.size() << endl;
    To copy to clipboard, switch view to plain text mode 
    application locks up on the read()

    Qt Code:
    1. buffer.clear();
    2. buffer = dmx_fd->read(1);
    3. cout << "Length read: " << buffer.size() << endl;
    To copy to clipboard, switch view to plain text mode 
    application locks up on the read()

    I just cant read anything from it. readAll() does the same. How can I write to it but not read from it ? lol just seems so odd that it wont work.

    UDL

Similar Threads

  1. QTreView::isExpanded ( index ) allways false ?
    By jpujolf in forum Qt Programming
    Replies: 3
    Last Post: 24th September 2010, 10:23
  2. Does bytesAvailable() decrease when read() is called?
    By ShaChris23 in forum Qt Programming
    Replies: 2
    Last Post: 9th July 2010, 21:16
  3. QUdpSocket and bytesAvailable
    By babu198649 in forum Newbie
    Replies: 0
    Last Post: 10th December 2008, 10:49
  4. Replies: 9
    Last Post: 4th June 2008, 12:29
  5. QIODevice::bytesAvailable() always returning 0
    By quickNitin in forum Newbie
    Replies: 6
    Last Post: 14th June 2006, 13:04

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
  •  
Qt is a trademark of The Qt Company.