Results 1 to 6 of 6

Thread: How can I use QextSerialPort on two different serial ports in the same time?

  1. #1
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How can I use QextSerialPort on two different serial ports in the same time?

    In my program I want to communicate with two different com ports. From one of them I get alarm signals. This works Ok.
    But now I try to send and receive data to a GSM terminal for sending SMS messages. I am not able to get response from the terminal to my computer.
    Do you know if I can use QextSerialPort to communicate with several serial ports in the same program? I use QWidget as base.

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,530
    Thanked 281 Times in 276 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I use QextSerialPort on two different serial ports in the same time?

    Yes, You can create many instances of QExtSerialPort as You need.

  3. #3
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I use QextSerialPort on two different serial ports in the same time?

    I still do not get any answer from com port number two(GSMcomm). My code is like:
    The constructor:
    Qt Code:
    1. EikeTesten::EikeTesten(QWidget *parent) :
    2. QWidget(parent)
    3. { ....
    4. qDebug("Creating QextSerialPort instance");
    5. CommPort = new QextSerialPort();
    6. CommPort->setPortName(QString("/dev/ttyUSB0"));
    7. CommPort->setDataBits(DATA_8);
    8. CommPort->setParity(PAR_NONE);
    9. CommPort->setFlowControl(FLOW_OFF);
    10. CommPort->setStopBits(STOP_1);
    11. CommPort->setBaudRate(BAUD300);
    12. CommPort->open();
    13. QTimer *receiveTimer = new QTimer(this);
    14. connect(receiveTimer, SIGNAL(timeout()), SLOT(receiveMsg())); // receiveMsg get the message from ttyUSB0 and call saveData();
    15. receiveTimer->start(0);
    16. ..
    17. }
    To copy to clipboard, switch view to plain text mode 

    in saveData:
    Qt Code:
    1. { ....
    2. GSMcomm = new GSMkommunikasjon();
    3. GSMcomm -> sendAlarmSMS(text);
    4. ....}
    To copy to clipboard, switch view to plain text mode 

    in GSMkommunikasjon constructor:
    Qt Code:
    1. {/*create and init communications port*/
    2. qDebug("Creating SMSCommPort instance");
    3. SMSCommPort = new QextSerialPort();
    4. SMSCommPort->setPortName(QString("/dev/ttyUSB1"));
    5. SMSCommPort->setDataBits(DATA_8);
    6. SMSCommPort->setParity(PAR_NONE);
    7. SMSCommPort->setFlowControl(FLOW_OFF);
    8. SMSCommPort->setStopBits(STOP_1);
    9. SMSCommPort->setBaudRate(BAUD19200);
    10. SMSCommPort->open();
    11. SMSCommPort->setDtr(0);
    12. SMSCommPort->setDtr(1);
    13. //SMSCommPort->close();
    14. //sendAlarmSMS();
    15.  
    16. QTimer *receiveTimer2 = new QTimer(this);
    17. connect(receiveTimer2, SIGNAL(timeout()), SLOT(receiveFromSMS()));
    18. receiveTimer2->start(0);
    19. }
    20.  
    21. in receiveFromSMS()
    22. {
    23. int numBytes = SMSCommPort->bytesAvailable();
    24. if(numBytes > 0)
    25. {
    26. if (numBytes > 80) numBytes = 80;
    27. char buff[80];
    28. int i = SMSCommPort->readData(buff, numBytes);
    29. buff[numBytes] = '\0';
    30. QChar byte0 = buff[0];
    31. QChar byte1 = buff[1];
    32. }}
    33. ... // But the program never receive anything
    34. }
    To copy to clipboard, switch view to plain text mode 

    Can you please help me?
    Last edited by wysota; 11th August 2011 at 09:32. Reason: missing [code] tags

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

    Default Re: How can I use QextSerialPort on two different serial ports in the same time?

    Just the basic checks...
    - is the baudrate correct
    - if you have a scope or so, do you see the DTR line toggling when you open the port ?
    - try to connect something else to that port and see if that works
    - put a loopback wire on the port (connect RX and TXT) and then send something in your program. It should be received back

    Regards,
    Marc

  5. #5
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: How can I use QextSerialPort on two different serial ports in the same time?

    Hi,

    Maybe it's not the matter, but it seems to me that you start 2 timers with a 0 interval time.
    Is it correct? Your CPU should run at full charge, maybe that cause some trouble in the reception? Have you try with a reasonable time interval (250ms for instance)?

    Loopback the wire can tell you if you're wrong on the protocol/in the serial configuration or if it's a software problem.

  6. #6
    Join Date
    Aug 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I use QextSerialPort on two different serial ports in the same time?

    Thank you for your feedback. I have tried to change the GSM terminal with something other, and then I got some input. The baudrate is correct. So something in my code is a little tricky.
    I will check the timers

Similar Threads

  1. Replies: 1
    Last Post: 3rd May 2011, 16:13
  2. Finding available COM ports with QextSerialPort
    By Ferric in forum Qt Programming
    Replies: 7
    Last Post: 26th October 2010, 19:16
  3. Serial comms on Windows Pc (Qextserialport)
    By SteveH in forum Qt Programming
    Replies: 19
    Last Post: 10th June 2010, 23:05
  4. Replies: 1
    Last Post: 1st July 2009, 00:36
  5. QExtSerialPort with com ports above com9
    By mightymark in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2006, 08:16

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.