Notices


Reply
Thread Tools
Posts: 49 | Thanked: 9 times | Joined on Oct 2010 @ Borneo
#1
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;
}
 
Posts: 462 | Thanked: 647 times | Joined on Jan 2009
#2
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
 

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

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

Thread Tools

 
Forum Jump


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