[comp.unix.internals] Termio help -- Needed BADLY!

raisch@control.com (Robert Raisch) (12/04/90)

I have a BIG problem.

Scenerio:

	Sun Sparcstation 1+ (Sun/OS 4.1) is connected to an 
asynch device on /dev/ttyb at 9600bps 8N1.  

The asynch device understands simple ascii commands, 
like: 		PT		/* Get controllers attention */
			O3=1	/* Turn Digital Output # 3 on. */

The only strangeness here is that the controller/asynch 
device uses '\r' to end lines.

I have so far been able to talk to this device via tip, 
(at 9600bps 8N1), and desperately need to talk to it in a 
program.  Nothing I do seems to allow me to talk to the device.

Most Recent Hack to Solve Problem:

	I ran Tip in one window, and in another, as root, 
I opened the tty (readonly), and read the termios struct and 
the modem control lines.  

	I then set the termios and modem lines VERBATUM from what 
tip seems to set them to.

	Still no go!  What am I missing?

/********************BEGIN EXAMPLE CODE*********************/
#include <stdio.h>
#include <fcntl.h>
#include <termio.h>
#include <sys/ttycom.h>
#define MAXBUF 1024

main( argc, argv)
int argc; char **argv;
{

	int i;
	int fd;
	int flags;
	char buf[ 1024];
	struct termios Orig, Term;

	if( (fd = fopen( "/dev/ttyb", O_RDWR)) < 3) exit( -1);

	ioctl( fd, TCGETS, &Orig);

	Term = Orig;
	Term.c_iflag = 0x1420; 	/* From tip, (IXON | IXOFF | ISTRIP)
	Term.c_oflag = 0;
	Term.c_cflag = 0x4bd; 	/* From tip, (B9600 | HUPCL | CREAD | CS8) */
	Term.c_lflag = 0;
 	Term.c_cc[VMIN] = 1; 	/* From tip, the only difference. (VMIN) */
	Term.c_cc[VTIME] = 0;

	ioctl( fd, TCSETS, &Term);  /*** Set the new modes. ***/

	flags = 0x66; 			/* From tip, (CD | CTS | RTS | DTR ) */
	ioctl( fd, TIOCMSET, &flags);	/*** Set the modem control lines ***/

	strcpy( buf, "\n\n\n\nPT\n"); /*** Get the device's attention ***/
	printf("Write(%d)\n", toCntrlr( fd, buf));

	strcpy( buf, "\n\n\nO3=1\n"); /*** Turn Digital Output #3 on. ***/
	printf("Write(%d)\n", toCntrlr( fd, buf));

	ioctl( fd, TCFLSH, 2);

	ioctl( fd, TCSETS, &Orig); /*** Back to the way we found it. ***/
	flags = 0;		/* Tip seems to do this when he exits, so what the hell. */
	ioctl( fd, TIOCMSET, &flags);

	close( fd);

}

toCntrlr( fd, str)
char *str;
{
	return( write( fd, str, strlen( str)));
}

/********************END OF EXAMPLE**************************/

(NOTE: The writes return the proper number of characers each time.)

Query:

	What am I missing here?
	Is this the least documented and most confusing 
	of all of Unix?  Or is it just me?  <weak smile>

thanks for any help.  -RR