[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: serial and baud rate
On Sun, 13 Dec 1998, Omer Zak wrote:
> How about running setserial and strace together to see what IOCTLs does
> setserial use?
better to read manual :)
> > now i want to change baud rates, how do i do that ?
> > how do i set it to non standard baud rates (like 115200/4=28800)
> > i do not want to use an external util (like setserial) but do it
> > via system calls or ioctl.
here is part of code which I use in prog which read data from
mini phone station
#define DEVICE "/dev/ttyS7"
int main(int argc,char *argv[])
{
int fd,fdlog,n,pid;
struct termios tc;
speed_t baud = B1200;
long i = -1;
char *buf = (char*)malloc(BUFSIZE);
fd=open(DEVICE, O_RDWR | O_NOCTTY);
if ( fd == -1) {
fprintf(stderr,"Can not open %s, %s\n", DEVICE, strerror(errno));
return 2;
}
if (tcgetattr(fd,&tc) == -1)
fprintf(stderr,"Error can not get attributes %s\n",strerror(errno));
cfsetospeed(&tc,baud);
cfsetispeed(&tc,baud);
tc.c_iflag = IGNBRK;
tc.c_lflag |= ICANON;
tc.c_cflag |= CLOCAL | CREAD | CSTOPB;
tcsetattr(fd,TCSANOW,&tc);
--
Vadim Smelyansky (AKA Proglot) Haifa,Israel mailto:mayonez@i.am
voice: 972-(0)53-876933 http://unix.widenet.co.il/~jim