[comp.unix.wizards] Through nfpipe

radigan@smu (09/27/87)

HELP HELP HELP

   The following program uses a null modem between
2 rs232 ports on a Sun 3.. All I want to do is
send charaters at a time but this does not work
The second write read will show that the second
char written is in wbuff[1] rather than wbuff[0].
I am in raw mode and there is no buffering ?
If I open and close fd1 and fd2 in between all is OK

    FOR 64 dollars .. do you see anything wrong here ?

P.S 
  I have several other versions that instantly crash
  a sun 3 ... its fun to watch for the whole family


#include "/usr/include/sys/file.h"
#include "/usr/include/sys/ioctl.h"
#include <stdio.h>
  struct sgttyb my_parms1, tmp_parms1, my_parms2, tmp_parms2;
void set_raw(fd)
{
  ioctl(fd,TIOCGETP, &my_parms1);
  my_parms1.sg_flags |= RAW;
  my_parms1.sg_flags |= LITOUT;
  my_parms1.sg_flags |= FLUSHO;
  my_parms1.sg_flags |= ~ECHO;
  ioctl(fd,TIOCSETP, &my_parms1);
}
main()
{
  int f = O_RDWR ,m= 0777;
  unsigned char buff[20];
  char *n1 = "/dev/ttya" ,*n2 = "/dev/ttyb";
  char c;
  int fd1,fd2,i;
  extern int errno;
  char wbuff[128];
  int cc;
	if((fd1 = open(n1,f,m)) == -1){
          return;
	}
        else{
          set_raw(fd1);
        }
         if( (fd2 = open(n2,f,m)) == -1){
           return;
	 }
         else{
           set_raw(fd2);
         }
         buff[0] = 0xFF;
         if ( write(fd1,buff,1 ) == 0){
           return;
	 }
         if( (cc = read(fd2,buff,1)) == 0){
           return;
	 }
         printf("\n read 1 --->%x<<< \n", buff[0]);
         printf(" %d\n",ioctl(fd1,TIOCFLUSH,0));
         wbuff[0] = 7;
         if ( write(fd2,wbuff,1 ) == 0){
           return;
	 }
         if( (cc = read(fd1,wbuff,1)) == 0){
           return;
	 }
         printf("\n read 2--------->%x %x %x %x<----\n",wbuff[0],wbuff[1],wbuff[2],wbuff[3]);
         exit(0);
}