Results 1 to 6 of 6

Thread: Qt4/C++ - QProcess output to QList<uint>

  1. #1
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Qt4/C++ - QProcess output to QList<uint>

    linux - Qt 4.8.2

    Hello,

    I've managed to use QProcess to get data from an eeprom and convert to a QList<uint>.
    Just seems unnecessarily complex, is it just me (trying to learn) or is there an easier way?
    Thanks for reading.

    Regards
    Qt Code:
    1. QString p_stdOut;
    2. QString p_stdErr;
    3. QList<uint> pages = QList<uint>() << 128 << 256 << 512 << 1024 << 2048 << 4096;
    4. QList<uint> data = QList<uint>();
    5.  
    6. //eeprog-tear -xf /dev/i2c-1 0x50 -x -16 -r 0x8160:0x20 - read last 32 bytes of eeprom
    7. cmd = "eeprog-tear -xf /dev/i2c-1 0x50 -x -16 -r 0x" + (QString::number((pages[i] - 1) * 32)) + ":0x20";
    8. process->start(cmd);
    9. process->waitForFinished(-1);
    10.  
    11. p_stdOut = process->readAllStandardOutput();
    12. qDebug() << "1 - " << p_stdOut;
    13.  
    14. p_stdOut = p_stdOut.right(p_stdOut.length() - ((p_stdOut.indexOf("|")) + 1)); //get rid of first address
    15. qDebug() << "2 - " << p_stdOut;
    16.  
    17. p_stdOut.replace((p_stdOut.indexOf("|") - 5), 6, ""); //get rid of second sddress
    18. qDebug() << "3 - " << p_stdOut;
    19.  
    20. p_stdOut.replace((p_stdOut.indexOf("\n") ), 1, ""); //get rid of linefeed
    21. qDebug() << "4 - " << p_stdOut;
    22.  
    23. p_stdOut = p_stdOut.simplified().replace(" ", ","); //get rid of extra spaces, add commas
    24. qDebug() << "5 - " << p_stdOut;
    25.  
    26. QRegExp rx(",");
    27. list = p_stdOut.split(rx, QString::SkipEmptyParts);
    28. qDebug() << "6 list - " << list;
    29.  
    30. for (int j = 0; j < list.length() - 1; j++) data << list[j].toUInt(&ok, 16);
    31. qDebug() << "7 uint - " << data;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. Output
    2. ******
    3. 1 - "
    4. 4064| 64 6d e8 02 00 01 00 20 00 00 00 62 02 00 00 00
    5. 4074| 00 00 00 80 00 00 00 a1 00 00 00 00 00 00 00 00
    6.  
    7. "
    8. 2 - " 64 6d e8 02 00 01 00 20 00 00 00 62 02 00 00 00
    9. 4074| 00 00 00 80 00 00 00 a1 00 00 00 00 00 00 00 00
    10.  
    11. "
    12. 3 - " 64 6d e8 02 00 01 00 20 00 00 00 62 02 00 00 00
    13. 00 00 00 80 00 00 00 a1 00 00 00 00 00 00 00 00
    14.  
    15. "
    16. 4 - " 64 6d e8 02 00 01 00 20 00 00 00 62 02 00 00 00 00 00 00 80 00 00 00 a1 00 00 00 00 00 00 00 00
    17.  
    18. "
    19. 5 - "64,6d,e8,02,00,01,00,20,00,00,00,62,02,00,00,00,00,00,00,80,00,00,00,a1,00,00,00,00,00,00,00,00"
    20. 6 list - ("64", "6d", "e8", "02", "00", "01", "00", "20", "00", "00", "00", "62", "02", "00", "00", "00", "00", "00", "00", "80", "00", "00", "00", "a1", "00", "00", "00", "00", "00", "00", "00", "00")
    21. 7 uint - (100, 109, 232, 2, 0, 1, 0, 32, 0, 0, 0, 98, 2, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 161, 0, 0, 0, 0, 0, 0, 0)
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Qt4/C++ - Qprocess and piping values of a QList<uint>

    Hello,

    I'm writing data to an eeprom. Piping data from the date command. OK
    Qt Code:
    1. process = new QProcess(this);
    2. process->start("bash", QStringList() << "-c" << "date | eeprog-tear -f -16 -w 0x00 -t 5 /dev/i2c-1 0x50");
    3. process->waitForFinished(-1);
    4. p_stdOut = process->readAllStandardOutput();
    5. qDebug() << "22 - " << p_stdOut;
    6. p_stdErr = process->readAllStandardError();
    7. qDebug() << "33 - " << p_stdErr << "\n\n";
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. ***Output***
    2. 22 - ""
    3. 33 - "eeprog 0.7.6-tear12, a 24Cxx EEPROM reader/writer
    4. Copyright (c) 2003-2004 by Stefano Barbato - All rights reserved.
    5. Copyright (c) 2011 by Kris Rusocki - All rights reserved.
    6. Bus: /dev/i2c-1, Address: 0x50, Mode: 16bit
    7. Operation: write at offset 0, Input file: <stdin>
    8. Write cycle time: 5 milliseconds
    9. Writing <stdin> starting at address 0x0
    10. .............................
    11.  
    12. "
    To copy to clipboard, switch view to plain text mode 
    What I would like to do is pipe the values from a QList<uint>.
    I could save the values to a file and write the file to the eeprom, I know how to do this.
    Is there a way to pipe the QList<uint> values directly?

    Regards

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt4/C++ - Qprocess and piping values of a QList<uint>

    If the eeprom writer program is expecting a raw stream of bytes on its stdin then you would be better off storing the data in a QByteArray and simply calling process.write() to send it.

  4. #4
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt4/C++ - Qprocess and piping values of a QList<uint>

    Hello ChrisW67

    Thanks, I'll have a play and see how far I get. (process.write())

    Regards

  5. #5
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt4/C++ - Qprocess and piping values of a QList<uint>

    Hello,

    I'm getting somewhere with QProcess.write, but.....

    I use 'i2cdump -y -f 1 0x50 c' to check the eeprom. I can write data to the eeprom,
    but nothing shows until a powerdown and boot, a soft reboot does not update.
    Qt Code:
    1. uint num = 0xac; //172;
    2. int8_t _bytes [1] {0x0A}; //line feed
    3.  
    4. process->start("eeprog-tear -f -16 -w 0xc2 -t 5 /dev/i2c-1 0x50");
    5.  
    6. process->write(QString::number(num).toLocal8Bit()); //writes 31 37 32
    7. process->write((char *)_bytes, 1); //line feed
    8.  
    9. fflush(stdout);
    10. process->waitForBytesWritten();
    11.  
    12. process->waitForFinished();
    13. p_stdOut = process->readAllStandardOutput();
    14. qDebug() << "99 - " << p_stdOut;
    15. p_stdErr = process->readAllStandardError();
    16. qDebug() << "100 - " << p_stdErr;
    17. process->close();//->terminate();
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. i2cdump -y -f 1 0x50 c
    2. 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    3. ...
    4. b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
    5. c0: ff ff 31 37 32 0a ff ff ff ff ff ff ff ff ff ff ..172?..........
    6. d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
    7. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. Output:-
    2. 99 - ""
    3. 100 - "eeprog 0.7.6-tear12, a 24Cxx EEPROM reader/writer
    4. Copyright (c) 2003-2004 by Stefano Barbato - All rights reserved.
    5. Copyright (c) 2011 by Kris Rusocki - All rights reserved.
    6. Bus: /dev/i2c-1, Address: 0x50, Mode: 16bit
    7. Operation: write at offset 194, Input file: <stdin>
    8. Write cycle time: 5 milliseconds
    9. Writing <stdin> starting at address 0xc2
    To copy to clipboard, switch view to plain text mode 

    The GUI I'm running from becomes un-responsive for about the same time as it would normally take to write the total eeprom.
    I'm guessing that I'm not appplying the line feed properly.

    Any suggestions would be greatly appreciated.

    Regards
    Last edited by jimbo; 6th September 2015 at 20:07.

  6. #6
    Join Date
    Oct 2006
    Posts
    105
    Thanks
    13
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt4/C++ - Qprocess and piping values of a QList<uint>

    Hello,

    I've solved the line feed problem.
    Qt Code:
    1. uint num = 0xad; //172;
    2. stringstream strs;
    3. strs << num;
    4. string tmp = strs.str();
    5. char * pchar = new char[tmp.size() + 1]; //reserve space for line feed
    6. strcpy(pchar, tmp.c_str());
    7.  
    8. process->start("eeprog-tear -f -16 -w 0xa0 -t 5 /dev/i2c-1 0x50");
    9.  
    10. process->write(pchar); //writes 31 37 32
    11. delete(pchar);
    To copy to clipboard, switch view to plain text mode 
    Just the problem of not showing, until shutdown & boot.

    Regards

Similar Threads

  1. Replies: 10
    Last Post: 29th August 2014, 10:02
  2. why can't QProcess read all output?
    By Raul in forum Qt Programming
    Replies: 32
    Last Post: 15th June 2013, 13:17
  3. QProcess Standard Output
    By Decessus in forum Qt Programming
    Replies: 4
    Last Post: 15th August 2012, 18:10
  4. Can't get QProcess output
    By croscato in forum Qt Programming
    Replies: 6
    Last Post: 18th November 2010, 16:56
  5. QT4 debug mode output / QList: Out of memory
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2007, 10:53

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.