Results 1 to 5 of 5

Thread: read output data

  1. #1
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default read output data

    Hi guys, im here with a pure C++ question. Im working with String message passing. Here is a sample code:

    Qt Code:
    1. strcpy (comando, "Æ" FS "2");
    2. printf ("Comando: %s\n", comando);
    3. MandaPaqueteFiscal (handler, comando);
    4. UltimaRespuesta (handler, buffer);
    5. printf ("Respuesta: %s %s", buffer);
    To copy to clipboard, switch view to plain text mode 

    FS is the value to sepparate the fields: (It is used in an example howto of the printer)

    #define FS "\x1c"
    The documentation says that "UltimaRespuesta" stores in buffer a 50 byte word like this:
    • Status of the printer (4 bytes)
    • Field Separator {FS} (1 byte)
    • Status Fiscal (4 bytes)
    • FS (1 byte)
    • Text (40bytes)


    An example answer for the first 3 fields could be (as the documentation explains): C080 FS 0600.. that meaning it uses hexa values for the answer.
    The thing is that when i look at the application output i recieve the following text:

    Comando: Æ2
    Respuesta: 
    if i run it in debug mode
    or:
    Comando: Æ2
    Respuesta: 0S?
    if I just run the program....

    So my question is, how can i read the "0S?" in a way i can interpret it?

    I appreciate all the help thank u all in advance

  2. #2
    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: read output data

    Assuming proper byte ordering and length of integer as 32 bits:
    Qt Code:
    1. unsigned char message[50]; // your message here
    2. int status;
    3. int statusFiscal;
    4. char text[41];
    5. memcpy(&status, message, 4);
    6. memcpy(&statusFiscal, message+5);
    7. memcpy(text, message+10, 40);
    8. text[40] = '\0';
    9. printf("status: %d\nfiscal: %d\ntext:%s\n", status, statusFiscal, text);
    To copy to clipboard, switch view to plain text mode 
    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.


  3. #3
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: read output data

    I think your answer to my "problem" is correct, the thing is that i`m working with an emulator of a printer so that might be the problem of "extrange output". I`m receiving the warning: too many arguments for format while trying to execute:

    printf ("Respuesta: %s", buffer);
    this is something i should ignore?

  4. #4
    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: read output data

    The code seems correct. At least if you're using a regular compiler. What is the type of "buffer"? Is this your actual code? In your first post you have two %s marks in the line concerning "buffer".
    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.


  5. #5
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: read output data

    Yes i had two separators, i was just trying to test what happened. The code posted is a method of a class. As private variables I have:
    Qt Code:
    1. int handler;
    2. char buffer[512];
    3. char comando[512];
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. why can't QProcess read all output?
    By Raul in forum Qt Programming
    Replies: 32
    Last Post: 15th June 2013, 12:17
  2. Read most recent output from QProcess's stdout
    By Lawand in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2010, 22:29
  3. Help on QProcess - Output Read
    By augusbas in forum Qt Programming
    Replies: 5
    Last Post: 24th September 2009, 11:54
  4. can`t read a binary data!
    By blm in forum Qt Programming
    Replies: 8
    Last Post: 18th September 2008, 16:56
  5. How can I read binary data to QString?
    By zolookas in forum Newbie
    Replies: 2
    Last Post: 29th July 2008, 20:03

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.