Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Question about Qserialport
Qt 6.11 is out! See what's new in the release blog

Question about Qserialport

Scheduled Pinned Locked Moved Qt Creator and other tools
5 Posts 2 Posters 4.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    csCATER
    wrote on last edited by
    #1

    I have come into contact with qt just for a short time.
    & I’ m doing a project which needs reading serial ports.
    I 've got MSP430(Texas Instruments), transmitting data to my macbook.
    There is nothing wrong with MSP430,driven normally, and my Mac can read data with other softwares.
    Here's the serial port information from the Qserialportinfo of sample program:

    Port: uart-1CFF49ABB1C3252A
    
Location: /dev/cu.uart-1CFF49ABB1C3252A
    
Description: Texas Instruments MSP-FET430UIF
    
Manufacturer: Texas Instruments
Vendor
    Identifier: 451
Product Identifier: f432
    
Busy: No

    & I want to read data from it.
    that is how i initialize the serial port.
    @QSerialPort *serial=new QSerialPort;
    serial->open(QIODevice::ReadOnly);
    serial->setBaudRate(serial->Baud4800);@

    and then i dont know how to set the port
    (cuz there are other serial mouth, bluetooth etc. )
    What should I do then?
    other Info:
    OS 10.8.4
    Qt creater 2.7.2
    based on Qt 5.1.0(64bit)
    ………………
    looking forward to some advice.
    thanks alot.^_^

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You need to set the port.

      Have a look a the example/documentation to see how to get the available serial ports.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        csCATER
        wrote on last edited by
        #3

        Hey SGaist!~
        Thanks for your help so much!
        I read the code in examples carefully and changed my code.
        Here's the code:
        @QSerialPort *serial=new QSerialPort;
        serial->setPort(serialPortInfo);
        if (!serial->open(QIODevice::ReadWrite))
        out<<"Can't open" <<serial->portName()<<", error code"<<serial->error()<<endl;
        if (!serial->setBaudRate(QSerialPort::Baud4800))
        out<<"Can't set baud to "<<serial->portName()<<", error code"<<serial->error()<<endl;
        if (!serial->setDataBits(QSerialPort::Data8))
        out<<"Can't set 8 databits to "<<serial->portName()<<", error code"<<serial->error()<<endl;
        if (!serial->setParity(QSerialPort::NoParity))
        out<<"Can't set Parity to "<<serial->portName()<<", error code"<<serial->error()<<endl;
        if (!serial->setStopBits(QSerialPort::OneStop))
        out<<"Can't set 1 stopbits to "<<serial->portName()<<", error code"<<serial->error()<<endl;
        if (!serial->setFlowControl(QSerialPort::NoFlowControl))
        out<<"Can't set NFControl to "<<serial->portName()<<", error code"<<serial->error()<<endl;
        QString buffer=serial->readAll();
        out<<buffer;
        serial->close();
        delete serial;@
        however... When I push the button on the MSP430 and then run the program,it reads nothing, but it returns no error, either. It means the port is set properly and it was opened successfully...
        So..I must ignore something important...Could you point it out for me?~
        Thank you very-very-very much~^_^

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You are opening the port, reading something and then closing and deleting the port. You won't have the time to get anything from your device (or you are lucky)

          You have to keep your serial port open and use the readyRead signal. This signal will tell you that new data have arrived and then you can read them.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • C Offline
            C Offline
            csCATER
            wrote on last edited by
            #5

            Thanks for your help so much...It's still supporting me till now....
            It's so kind of you~
            [quote author="SGaist" date="1373353934"]You are opening the port, reading something and then closing and deleting the port. You won't have the time to get anything from your device (or you are lucky)

            You have to keep your serial port open and use the readyRead signal. This signal will tell you that new data have arrived and then you can read them.[/quote]

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved