Results 1 to 2 of 2

Thread: Communication via SerialPort

  1. #1
    Join Date
    Jun 2009
    Location
    Krakow, Poland
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Communication via SerialPort

    Hi.
    I need to write application that will communicate with electronic device via serial port. I was thinking to use QExtSerialPort library but I have some doubts.
    In QExtSerialPort library port is being read after signal readyRead(). In my application computer will ask electronic device about his status in loop. And then base of status send to device next commands. I need to have something like this:
    Qt Code:
    1. while(keepAsking)
    2. {
    3. QByteArray status = serialPort->checkStatus();
    4. if(status == something[]) //<- this is only example i know it's wrong :)
    5. {
    6. serialPort->DoA();
    7. }
    8. if(status == something2[])
    9. {
    10. serialPort->DoB();
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    What is best approach for this logic? I thing QExtSerialPort with read port on signal will not work in this situation. How would you solve this issue?

  2. #2
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Communication via SerialPort

    Hi,
    Instead of a loop, you should use a timer to get the device status every xxx milliseconds.

    To ask the device about its status, you probably need to send it a command like "give me your status". This command can be sent in the code activated by the timer (let's call this the timer event).

    The device will send a reply. You could use the ReadyRead() event to process the data as it is received.

    Another way is to check in the timer event if data is already sent by the device. The code in the timer event must never wait until data is received. It should only check if data is available, and if so process the data. If no data or unsufficient data is available, it should just exit. Typically you use some sort of "state machine" code for the timer event.

    Hope this helps,
    Regards,
    Marc

Similar Threads

  1. Communication with USB
    By prasenjit in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2010, 01:19
  2. Qt and .Net communication
    By soniaerm in forum Qt Programming
    Replies: 0
    Last Post: 22nd April 2010, 07:37
  3. accessing the GSM modem using serialport in windows OS
    By jjbabu in forum Qt Programming
    Replies: 11
    Last Post: 31st December 2007, 12:38
  4. qt4 serialport
    By nmn in forum Qt Programming
    Replies: 3
    Last Post: 27th November 2006, 04:55
  5. Communication Help Pls
    By munna in forum Newbie
    Replies: 1
    Last Post: 25th May 2006, 14:22

Tags for this Thread

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.