Results 1 to 12 of 12

Thread: qext-serial-port write problem.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Posts
    41
    Thanks
    12

    Default qext-serial-port write problem.

    hello every one.. i have a small problem here. I am communicating with a hardware on rs232 serial terminal.. I am able to send a start of frame and receive back a acknowledge-ment from the hardware device. i am sending a fixed string i.e 0xAC,0xCA,0x1F as the start of the frame which the hardware device sud check for and give a ackn. which is working fine . this is what i am doing i am writing the string AC CA 1F to the port this is done successfully.i get a acknowledgment from the hardware also.
    Qt Code:
    1. static const char mydata[] = { 0xAC,0xCA,0x1F};
    2. QByteArray data = QByteArray::fromRawData(mydata, sizeof(mydata));
    3. char i = port->write(mydata,sizeof(mydata));
    To copy to clipboard, switch view to plain text mode 

    Now the problem is when i try to send some configured hexa format data which i have
    in QByteArray hexadecimaldata; i am splitting the each byte in it and putting them into firstByte and secondByte. cause i have to send the configured data byte by byte and the data is never more then 2 bytes.

    Qt Code:
    1. firstByte = "0x"+hexadecimaldata.left(2);
    2. secondByte = "0x"+hexadecimaldata.mid(1, 2);
    3. char i = port->write(firstByte);
    4. char i = port->write(secondByte);
    To copy to clipboard, switch view to plain text mode 

    the configured hexadecimaldata is not wrting to the port..

    Pls tell me if i am going wrong some wer. ?

    thank you
    Last edited by rex; 1st March 2011 at 14:25.

  2. #2
    Join Date
    Nov 2007
    Posts
    55
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qext-serial-port write problem.

    have firstByte and secondByte been declared somewhere, and hexadecimaldata also been initialised?
    Try also qdebug() << firstByte << secondByte; to check your values before sending them to the port.

  3. The following user says thank you to alainstgt for this useful post:

    rex (1st March 2011)

  4. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qext-serial-port write problem.

    hi,

    your code
    Qt Code:
    1. firstByte = "0x"+hexadecimaldata.left(2);
    2. secondByte = "0x"+hexadecimaldata.mid(1, 2);
    To copy to clipboard, switch view to plain text mode 

    is strange.
    you are pre-pending the sequence "0x" to your binary data.
    this is what you want?

    pay attention that you extract 2 bytes from hexadecimaldata with left() and mid()
    A camel can go 14 days without drink,
    I can't!!!

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

    rex (1st March 2011)

Similar Threads

  1. Replies: 4
    Last Post: 10th July 2010, 17:34
  2. Serial Port Reading problem
    By sfabel in forum Qt Programming
    Replies: 12
    Last Post: 18th February 2010, 14:59
  3. Replies: 1
    Last Post: 16th June 2009, 09:09
  4. How to write bytes read from serial port to a QFile
    By shamik in forum Qt Programming
    Replies: 19
    Last Post: 25th June 2007, 14:12
  5. Serial Port
    By b1 in forum Qt Programming
    Replies: 2
    Last Post: 18th January 2007, 02:05

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.