Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcdc!hpfinote!pej From: pej@hpfinote.HP.COM (Phil Jensen) Newsgroups: comp.sys.hp Subject: Re: Need help setting up RS-232 port Message-ID: <15480004@hpfinote.HP.COM> Date: 3 Jun 89 12:57:55 GMT References: <8490001@weycord.WEYCO.COM> Organization: Hewlett Packard CICD Lines: 66 > I have what is probably a simple question but have not been > able to find a simple answer to it. I have an HP9000/370 with > the HP-UX 6.5 operating system. I simply need to open an > RS-232 port and send/receive ASCII data. Nothing complicated. I'm > just going to use the port to talk with an analog mux. I've got the > RS-232 expander cards to do the job on the system. I just need to > figure out how to do the job from a software standpoint. Any assistance > would be welcome. Thanks in advance. ---------- The following should do what you need . Hope it helps . ************************************************************************* #include #include #include #define BUFFER_SIZE 256 extern int errno; main() { int tty; unsigned char buffer[BUFFER_SIZE]; struct termio term; /* open device as read / write see mknod to make /dev/tty */ /* mknod /dev/tty c 1 0xscpp04 */ /* sc = select code */ /* pp = port number for mux (98642) 00 for others */ if((tty = open("/dev/tty",O_RDWR)) < 1){ fprintf(stderr,"Could not open /dev/tty ERRNO: %d\n",errno); exit(1); } /* set up appropriate values for baud rate etc */ /* execute "man termio" for details */ term.c_oflag = OPOST; term.c_iflag = IGNBRK; term.c_lflag = 0; term.c_cflag = B2400|CSIZE|CS8|CREAD|CLOCAL; if(ioctl(tty,TCSETA,&term) == -1) { fprintf(stderr,"could not set /dev/tty\n"); close(tty); exit(0); } /* get BUFFER_SIZE bytes in character(byte) buffer */ read(tty,buffer,BUFFER_SIZE); /* write buffer to device */ write(tty,buffer,BUFFER_SIZE); /* close device */ close(tty); }