maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Design (https://talk.maemo.org/forumdisplay.php?f=46)
-   -   Writin to RFCOMM (https://talk.maemo.org/showthread.php?t=75994)

didik.wahyono 2011-08-23 06:07

Writin to RFCOMM
 
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::on_pushButton_clicked()
{
fputc('H',rfcomm); // no data transmitted

}

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

jackburton 2011-08-24 12:07

Re: Writin to RFCOMM
 
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

djdas 2011-08-24 13:30

Re: Writin to RFCOMM
 
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!


All times are GMT. The time now is 04:28.

vBulletin® Version 3.8.8