Results 1 to 6 of 6

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #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

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
  •  
Qt is a trademark of The Qt Company.