Question about Qserialport



  • 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.^_^


  • Lifetime Qt Champion

    Hi,

    You need to set the port.

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



  • 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~^_^


  • Lifetime Qt Champion

    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.



  • 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]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.