Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - O_DSYNC option on serial port : (3 Items)
   
O_DSYNC option on serial port  
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;
}

Re: O_DSYNC option on serial port  
On Wed, Apr 16, 2008 at 05:43:02PM -0400, Zhenwang Yao wrote:
> 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?

I'm not sure if it's a bug or not that O_DSYNC wasn't supported, but check
out the tcdrain() function - it'll do what you wanted.

-- 
Brian Stecher (bstecher@qnx.com)        QNX Software Systems
phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
       +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8
Re: O_DSYNC option on serial port  
Thanks Brian,

That seems exactly what we want.


> 
> I'm not sure if it's a bug or not that O_DSYNC wasn't supported, but check
> out the tcdrain() function - it'll do what you wanted.
> 
> -- 
> Brian Stecher (bstecher@qnx.com)        QNX Software Systems
> phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
>        +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8