Thread Tools
Posts: 49 | Thanked: 9 times | Joined on Oct 2010 @ Borneo

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");


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


{ fclose(rfcomm); // all accumulated data is transmitted after i call this routine
delete ui;
Posts: 466 | Thanked: 661 times | Joined on Jan 2009
I'm not much of a c++ guy, but i believe the issue is related to file buffering in the fopen call.

See here:

The Following User Says Thank You to jackburton For This Useful Post:
djdas's Avatar
Posts: 77 | Thanked: 49 times | Joined on Apr 2010 @ Italy
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.

The Following User Says Thank You to djdas For This Useful Post:

Thread Tools

Forum Jump

All times are GMT. The time now is 19:21.