Qt serial port: write and read data












0















I'm able to connect to my serial port, but I need to read data from it all the time.

It's working for about 39 minutes, but after it stops at line serial.flush().

When I stop Qt and start it again it also stops at serial.flush(). I need to restart my modem to let it work again...



I'm not sure I'm executing this properly...



// Open Serial connexion
QSerialPort serial;
serial.setPortName("usbserial-26214A");
serial.open(QIODevice::ReadWrite);
serial.setBaudRate(QSerialPort::Baud115200);
serial.setDataBits(QSerialPort::Data8);
serial.setParity(QSerialPort::NoParity);
serial.setStopBits(QSerialPort::OneStop);
serial.setFlowControl(QSerialPort::HardwareControl);

if (serial.isOpen() && serial.isWritable())
{
qDebug() << "Serial is open";

QByteArray output;
QByteArray input;

while(true)
{
output = "AT+CPMS="SM"r";
serial.write(output);
serial.flush();
serial.waitForBytesWritten(1000);
serial.waitForReadyRead(1000);
input = serial.readAll();
}
}


//EDIT



if deleting flush it's working, but code goes really fast. It don't wait for WaitFor...

After 2nd loop he doesn't has time to read data.



serial.isOpen() && serial.isWritable() always sends true in while loop.



Program stops at flush after 30 minutes!










share|improve this question

























  • If waitForBytesWritten() it should be safe to omit the flush(). I guess this won't solve the problem though. Is it possible to just run a soft-reset always before AT+CPMS Sequence? Not sure the connection problem is related to your application.

    – Sebastian Lange
    Oct 20 '14 at 6:46











  • If deleting flush line, loop goes really fast and don't seems to waitFor.... How to do a soft-reset?

    – gr3g
    Oct 20 '14 at 6:54











  • Does the application continue by simply powercycling the modem ? Or do you also have to restart the App ? In the first case I would assume that the modem got stuck. May be you should debug the state the modem is in and check if there are commands to revitalize it.

    – Oncaphillis
    Oct 20 '14 at 7:59











  • By powercycling the modem it works. I also have to restart the app because I can't find errors... serial.isOpen() || serial.isWritable()is true and serial.errorString is null

    – gr3g
    Oct 20 '14 at 10:24











  • Please see edits

    – gr3g
    Oct 20 '14 at 13:45
















0















I'm able to connect to my serial port, but I need to read data from it all the time.

It's working for about 39 minutes, but after it stops at line serial.flush().

When I stop Qt and start it again it also stops at serial.flush(). I need to restart my modem to let it work again...



I'm not sure I'm executing this properly...



// Open Serial connexion
QSerialPort serial;
serial.setPortName("usbserial-26214A");
serial.open(QIODevice::ReadWrite);
serial.setBaudRate(QSerialPort::Baud115200);
serial.setDataBits(QSerialPort::Data8);
serial.setParity(QSerialPort::NoParity);
serial.setStopBits(QSerialPort::OneStop);
serial.setFlowControl(QSerialPort::HardwareControl);

if (serial.isOpen() && serial.isWritable())
{
qDebug() << "Serial is open";

QByteArray output;
QByteArray input;

while(true)
{
output = "AT+CPMS="SM"r";
serial.write(output);
serial.flush();
serial.waitForBytesWritten(1000);
serial.waitForReadyRead(1000);
input = serial.readAll();
}
}


//EDIT



if deleting flush it's working, but code goes really fast. It don't wait for WaitFor...

After 2nd loop he doesn't has time to read data.



serial.isOpen() && serial.isWritable() always sends true in while loop.



Program stops at flush after 30 minutes!










share|improve this question

























  • If waitForBytesWritten() it should be safe to omit the flush(). I guess this won't solve the problem though. Is it possible to just run a soft-reset always before AT+CPMS Sequence? Not sure the connection problem is related to your application.

    – Sebastian Lange
    Oct 20 '14 at 6:46











  • If deleting flush line, loop goes really fast and don't seems to waitFor.... How to do a soft-reset?

    – gr3g
    Oct 20 '14 at 6:54











  • Does the application continue by simply powercycling the modem ? Or do you also have to restart the App ? In the first case I would assume that the modem got stuck. May be you should debug the state the modem is in and check if there are commands to revitalize it.

    – Oncaphillis
    Oct 20 '14 at 7:59











  • By powercycling the modem it works. I also have to restart the app because I can't find errors... serial.isOpen() || serial.isWritable()is true and serial.errorString is null

    – gr3g
    Oct 20 '14 at 10:24











  • Please see edits

    – gr3g
    Oct 20 '14 at 13:45














0












0








0


0






I'm able to connect to my serial port, but I need to read data from it all the time.

It's working for about 39 minutes, but after it stops at line serial.flush().

When I stop Qt and start it again it also stops at serial.flush(). I need to restart my modem to let it work again...



I'm not sure I'm executing this properly...



// Open Serial connexion
QSerialPort serial;
serial.setPortName("usbserial-26214A");
serial.open(QIODevice::ReadWrite);
serial.setBaudRate(QSerialPort::Baud115200);
serial.setDataBits(QSerialPort::Data8);
serial.setParity(QSerialPort::NoParity);
serial.setStopBits(QSerialPort::OneStop);
serial.setFlowControl(QSerialPort::HardwareControl);

if (serial.isOpen() && serial.isWritable())
{
qDebug() << "Serial is open";

QByteArray output;
QByteArray input;

while(true)
{
output = "AT+CPMS="SM"r";
serial.write(output);
serial.flush();
serial.waitForBytesWritten(1000);
serial.waitForReadyRead(1000);
input = serial.readAll();
}
}


//EDIT



if deleting flush it's working, but code goes really fast. It don't wait for WaitFor...

After 2nd loop he doesn't has time to read data.



serial.isOpen() && serial.isWritable() always sends true in while loop.



Program stops at flush after 30 minutes!










share|improve this question
















I'm able to connect to my serial port, but I need to read data from it all the time.

It's working for about 39 minutes, but after it stops at line serial.flush().

When I stop Qt and start it again it also stops at serial.flush(). I need to restart my modem to let it work again...



I'm not sure I'm executing this properly...



// Open Serial connexion
QSerialPort serial;
serial.setPortName("usbserial-26214A");
serial.open(QIODevice::ReadWrite);
serial.setBaudRate(QSerialPort::Baud115200);
serial.setDataBits(QSerialPort::Data8);
serial.setParity(QSerialPort::NoParity);
serial.setStopBits(QSerialPort::OneStop);
serial.setFlowControl(QSerialPort::HardwareControl);

if (serial.isOpen() && serial.isWritable())
{
qDebug() << "Serial is open";

QByteArray output;
QByteArray input;

while(true)
{
output = "AT+CPMS="SM"r";
serial.write(output);
serial.flush();
serial.waitForBytesWritten(1000);
serial.waitForReadyRead(1000);
input = serial.readAll();
}
}


//EDIT



if deleting flush it's working, but code goes really fast. It don't wait for WaitFor...

After 2nd loop he doesn't has time to read data.



serial.isOpen() && serial.isWritable() always sends true in while loop.



Program stops at flush after 30 minutes!







c++ qt serial-port qtcore qtserialport






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 20 '14 at 13:53









lpapp

42.1k1376102




42.1k1376102










asked Oct 20 '14 at 6:41









gr3ggr3g

1,64121228




1,64121228













  • If waitForBytesWritten() it should be safe to omit the flush(). I guess this won't solve the problem though. Is it possible to just run a soft-reset always before AT+CPMS Sequence? Not sure the connection problem is related to your application.

    – Sebastian Lange
    Oct 20 '14 at 6:46











  • If deleting flush line, loop goes really fast and don't seems to waitFor.... How to do a soft-reset?

    – gr3g
    Oct 20 '14 at 6:54











  • Does the application continue by simply powercycling the modem ? Or do you also have to restart the App ? In the first case I would assume that the modem got stuck. May be you should debug the state the modem is in and check if there are commands to revitalize it.

    – Oncaphillis
    Oct 20 '14 at 7:59











  • By powercycling the modem it works. I also have to restart the app because I can't find errors... serial.isOpen() || serial.isWritable()is true and serial.errorString is null

    – gr3g
    Oct 20 '14 at 10:24











  • Please see edits

    – gr3g
    Oct 20 '14 at 13:45



















  • If waitForBytesWritten() it should be safe to omit the flush(). I guess this won't solve the problem though. Is it possible to just run a soft-reset always before AT+CPMS Sequence? Not sure the connection problem is related to your application.

    – Sebastian Lange
    Oct 20 '14 at 6:46











  • If deleting flush line, loop goes really fast and don't seems to waitFor.... How to do a soft-reset?

    – gr3g
    Oct 20 '14 at 6:54











  • Does the application continue by simply powercycling the modem ? Or do you also have to restart the App ? In the first case I would assume that the modem got stuck. May be you should debug the state the modem is in and check if there are commands to revitalize it.

    – Oncaphillis
    Oct 20 '14 at 7:59











  • By powercycling the modem it works. I also have to restart the app because I can't find errors... serial.isOpen() || serial.isWritable()is true and serial.errorString is null

    – gr3g
    Oct 20 '14 at 10:24











  • Please see edits

    – gr3g
    Oct 20 '14 at 13:45

















If waitForBytesWritten() it should be safe to omit the flush(). I guess this won't solve the problem though. Is it possible to just run a soft-reset always before AT+CPMS Sequence? Not sure the connection problem is related to your application.

– Sebastian Lange
Oct 20 '14 at 6:46





If waitForBytesWritten() it should be safe to omit the flush(). I guess this won't solve the problem though. Is it possible to just run a soft-reset always before AT+CPMS Sequence? Not sure the connection problem is related to your application.

– Sebastian Lange
Oct 20 '14 at 6:46













If deleting flush line, loop goes really fast and don't seems to waitFor.... How to do a soft-reset?

– gr3g
Oct 20 '14 at 6:54





If deleting flush line, loop goes really fast and don't seems to waitFor.... How to do a soft-reset?

– gr3g
Oct 20 '14 at 6:54













Does the application continue by simply powercycling the modem ? Or do you also have to restart the App ? In the first case I would assume that the modem got stuck. May be you should debug the state the modem is in and check if there are commands to revitalize it.

– Oncaphillis
Oct 20 '14 at 7:59





Does the application continue by simply powercycling the modem ? Or do you also have to restart the App ? In the first case I would assume that the modem got stuck. May be you should debug the state the modem is in and check if there are commands to revitalize it.

– Oncaphillis
Oct 20 '14 at 7:59













By powercycling the modem it works. I also have to restart the app because I can't find errors... serial.isOpen() || serial.isWritable()is true and serial.errorString is null

– gr3g
Oct 20 '14 at 10:24





By powercycling the modem it works. I also have to restart the app because I can't find errors... serial.isOpen() || serial.isWritable()is true and serial.errorString is null

– gr3g
Oct 20 '14 at 10:24













Please see edits

– gr3g
Oct 20 '14 at 13:45





Please see edits

– gr3g
Oct 20 '14 at 13:45












1 Answer
1






active

oldest

votes


















0














If serial.isOpen() && serial.isWritable() is true in while loop, but you can't access it could come from you preferences on your computer.



On OSX: System preferences -> network -> select serial -> advanced -> PPP:

able: Ask to stay connected every 10 minutes,

disable: disconnect at close of session,

disable: disconnect when changing of user






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26459788%2fqt-serial-port-write-and-read-data%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    If serial.isOpen() && serial.isWritable() is true in while loop, but you can't access it could come from you preferences on your computer.



    On OSX: System preferences -> network -> select serial -> advanced -> PPP:

    able: Ask to stay connected every 10 minutes,

    disable: disconnect at close of session,

    disable: disconnect when changing of user






    share|improve this answer




























      0














      If serial.isOpen() && serial.isWritable() is true in while loop, but you can't access it could come from you preferences on your computer.



      On OSX: System preferences -> network -> select serial -> advanced -> PPP:

      able: Ask to stay connected every 10 minutes,

      disable: disconnect at close of session,

      disable: disconnect when changing of user






      share|improve this answer


























        0












        0








        0







        If serial.isOpen() && serial.isWritable() is true in while loop, but you can't access it could come from you preferences on your computer.



        On OSX: System preferences -> network -> select serial -> advanced -> PPP:

        able: Ask to stay connected every 10 minutes,

        disable: disconnect at close of session,

        disable: disconnect when changing of user






        share|improve this answer













        If serial.isOpen() && serial.isWritable() is true in while loop, but you can't access it could come from you preferences on your computer.



        On OSX: System preferences -> network -> select serial -> advanced -> PPP:

        able: Ask to stay connected every 10 minutes,

        disable: disconnect at close of session,

        disable: disconnect when changing of user







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 21 '14 at 11:40









        gr3ggr3g

        1,64121228




        1,64121228






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26459788%2fqt-serial-port-write-and-read-data%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Create new schema in PostgreSQL using DBeaver

            Deepest pit of an array with Javascript: test on Codility

            Costa Masnaga