Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    Writin to RFCOMM

    Reply
    didik.wahyono | # 1 | 2011-08-23, 06:07 | Report

    Gents,

    I faced a problem when implementing bluetooth serial port to my N900. I managed to bind the serial port to rfcomm0, but when i open and write something, the data is physically transmitted after i close the file. Any idea how to send the data directly as soon as possible? Thanks in advance.


    here is my code.

    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    rfcomm = fopen("/dev/rfcomm0","a");
    ui->setupUi(this);

    }

    void MainWindow:n_pushButton_clicked()
    {
    fputc('H',rfcomm); // no data transmitted

    }

    MainWindow::~MainWindow()
    { fclose(rfcomm); // all accumulated data is transmitted after i call this routine
    delete ui;
    }

    Edit | Forward | Quote | Quick Reply | Thanks

     
    jackburton | # 2 | 2011-08-24, 12:07 | Report

    I'm not much of a c++ guy, but i believe the issue is related to file buffering in the fopen call.

    See here:
    http://stackoverflow.com/questions/2...ile-descriptor

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to jackburton For This Useful Post:
    don_falcone

     
    djdas | # 3 | 2011-08-24, 13:30 | Report

    Well, I think opening a file in the window constructor and closing in the destructor could result in bad behavior. I would prefer to open, write and close all-in-one to maintain an "atomicity" for the operation.
    But it's my opinion
    Maybe you could use fflush() after writing (i.e. just after the fputc call) to flush the buffer and see the data written, but I don't know how it is implemented by the bluetooth protocol and if it works as expected.
    Bye!

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to djdas For This Useful Post:
    don_falcone

     
vBulletin® Version 3.8.8
Normal Logout