OpenQNX :: The QNX Community Portal

Jul 19, 2008 - 03:30 PM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 39 unlogged users and 1 registered user online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
zhenwang
Post subject: O_DSYNC option on serial port  PostPosted: Apr 16, 2008 - 09:37 PM
New Member


Joined: Apr 16, 2008
Posts: 3

I was writing a program communicating via COMM with read/write, and thinking of setting the comm to synchronous mode, such that write() function won't return until all data in the buffer has been sent. So, I tried to set the O_DSYNC flag by calling fcntl() function. But apparently it doesn't work, fcntl function call return with errorno:22 (/* Invalid argument*/).

Anyone has any idea? I guess qnx does't support O_DSYNC flag for serial port, is that right?

Any idea how to walk around this: how to write() comm in a synchronous mode?

Attached is the code I used.

Thanks.


//*************** Code ***************************

#include <iostream>
#include <fstream>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <pthread.h>
#include <fcntl.h>
#include <stdarg.h>
#include <termios.h>
#include <time.h>
#include <errno.h>

using namespace std;

int main (int argc, char **argv)
{
int serf = open("/dev/ser1", O_RDWR );
if (serf == -1)
{
cout << "Fail to open COM." << endl;
exit(1);
}

int retval = fcntl(serf, F_SETFL, O_DSYNC );
if( retval == -1 ) {
printf( "error setting stdout flags, with errorno=%d\n", errno);
return EXIT_FAILURE;
}


ifstream iFile;

char* iFileName = "/etc/printers/epijs.cfg";
iFile.open(iFileName, ios::binary);
if(!iFile.is_open())
{
cout << "Error opening input file named: " << iFileName << endl;
exit (1);
}

int wcount;
while(!iFile.eof())
{
char buffer[132];
iFile.read(buffer, 132);
wcount=iFile.gcount();
if (write(serf, buffer, wcount) != wcount)
{
cout << "Write error!" << endl;
exit (1);
};
}

iFile.close();
close(serf);

return EXIT_SUCCESS;
}
 
 View user's profile Send private message  
Reply with quote Back to top
ysinitsky
Post subject: RE: O_DSYNC option on serial port  PostPosted: Apr 17, 2008 - 05:32 PM
Active Member


Joined: Dec 14, 2005
Posts: 89

Hello Zhenwang,
Please try

int serf = open("/dev/ser1", O_RDWR | O_DSYNC );
or
int serf = open("/dev/ser1", O_RDWR | O_SYNC );

instead of fcntl.

Thanks,
Yuriy
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.