SUMMARY: Sending break on serial port

From: Mike Galuza (mgaluza@dejarnette.com)
Date: Thu Aug 21 1997 - 09:10:25 CDT


Thanks to the following for thier replies:

Moshe Meirzadeh
Matthew Stier
Stephen Harris
(One other responder whose message I accidentally deleted)

Here is my original question:
>
> Otherwise, here is my question. First of all I am using Solaris 2.5.1
> for x86. I am writing a program to do some communications over a serial
> port with a particular device. That device requires that I send a break
> for at least 1.5 seconds. The function tcsendbreak() (and the TCSBRK
> ioctl) only sends a break for 0.25 to 0.5 seconds. Any suggestions on
> how to send a break for 1.5 seconds? I've tried the something similar to
> the following (with and without the usleep):
>
> for (x=0;x<8;++x) {
> tcsendbreak();
> usleep(200000);
> }
>
> This didn't seem to work, but of course there could be something else
> wrong. I'm just wondering if this is the correct approach or if there
> is some other approach to try.
>

A couple of people suggested I make use of a parameter that can be
passed to tcsendbreak(), called duration. If you carefully read the
man page for tcsendbreak you will see that the only valid value for
duration is 0 (which sets the break for .25 to .5 secs), other
values cause tcsendbreak() to act like tcflush().

The best answer to my question was the following. I did not find
this information in any man pages. Sun must have stopped documenting
this feature after it adopted the POSIX compliant tcsendbreak()
function. Here is the response:

> Checkout the ioctl arguments TIOCSBRK and TIOCCBRK.
>
> Here is a segment of code I nabbed from a Sunsolve bugreport
>
> *** sample program ***
>
> /*
> * RS232C test pro
> */
>
> #include <stdio.h>
> #include <errno.h>
> #include <sys/termio.h>
> #include <sys/termios.h>
> #include <sys/ttold.h>
> #include <unistd.h>
> #include <fcntl.h>
> #include <unistd.h>
> #include <fcntl.h>
> #include <stropts.h>
>
> int
> main( argc, argv )
> int argc;
> char *argv[];
> {
>
> int nCid;
>
> printf( "open start (/dev/term/a) \n" );
> if ( -1 == ( nCid = open( "/dev/term/a", O_RDWR | O_NDELAY))) {
> fprintf( stderr, "open err errno[%d]\n", errno );
>
> printf( "open start (/dev/term/b) \n" );
> if ( -1 == ( nCid = open( "/dev/term/b", O_RDWR | O_NDELAY))) {
> fprintf( stderr, "open err errno[%d]\n", errno );
> exit(1);
> }
> }
>
> printf( "ioctl TIOCSBRK start \n" );
> ioctl(nCid, TIOCSBRK, 0);
> printf( "ioctl TIOCSBRK end \n" );
>
> sleep( 3 );
>
> printf( "ioctl TIOCCBRK start\n" );
> ioctl(nCid, TIOCCBRK, 0);
> printf( "ioctl TIOCCBRK end\n" );
>
> printf( "close start \n" );
> if ( -1 == close( nCid )) {
> fprintf( stderr, "close err errno[%d]\n", errno );
> exit(1);
> }
> }

Thanks again,
Mike

----------------------------------------------------------------------
Michael Galuza
DeJarnette Research Systems mgaluza@dejarnette.com
401 Washington Ave Suite 700 Voice: +1(410)583-0680 x691
Towson, MD 21204 Fax: +1(410)583-0696
----------------------------------------------------------------------



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:12:00 CDT