?? uartinit.c.svn-base
字號:
/****************************************************************************** * * Copyright (c) 2008 Shanghai IS Software * * All rights reserved * * $Revision$ * * $LastChangedBy$ * * $LastChangedData$ * * Description: * * Revision History: * 2008/08/28 14:33 by lcj * #1.created * *****************************************************************************/#include "modbus_rtu/modbus.h"/*** brief***/int speed_arr[] = {B115200,B57600,B38400,B19200,B9600,B4800,B2400,B1200,B300, B200,B150,B75,B50,B0};int name_arr[] = {115200,57600,38400,19200,9600,4800,2400,1200,300, 200,150,75,50,0};void set_speed(int fd,int speed){ int i; int status; struct termios opt; tcgetattr(fd,&opt); for ( i = 0; i < sizeof(speed_arr) / sizeof(int); i++ ) { if ( speed == name_arr[i] ) { tcflush(fd, TCIOFLUSH); cfsetispeed(&opt,speed_arr[i]); cfsetospeed(&opt,speed_arr[i]); status = tcsetattr(fd,TCSANOW,&opt); if ( status != 0 ) { perror("tcsetattr fd1"); return ; } tcflush(fd,TCIOFLUSH); } } }/*** brief ***/int set_parity(int fd, int databits,int stopbits, int parity){ struct termios options; if ( tcgetattr( fd, &options) != 0 ) { perror("setupserial 1"); return (FALSE); } options.c_cflag &= ~CSIZE; switch ( databits ) { case 7: options.c_cflag |= CS7; break; case 8: options.c_cflag |= CS8; break; default: fprintf(stderr,"Unsupported data size\n"); return FALSE; } switch ( parity ) { case 'n': case 'N': options.c_cflag &= ~PARENB; options.c_iflag &= ~INPCK; break; case 'o': case 'O': options.c_cflag |= (PARODD | PARENB ); options.c_iflag |= INPCK; break; case 'e': case 'E': options.c_cflag |= PARENB; options.c_cflag &= ~PARODD; options.c_iflag |= INPCK; break; case 's': case 'S': options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; break; default: fprintf(stderr,"Unsupported parity\n"); return FALSE; } switch (stopbits) { case 1: options.c_cflag &= ~CSTOPB; break; case 2: options.c_cflag |= CSTOPB; break; default: fprintf(stderr,"Unsupported stop bits\n"); return FALSE; } if ( parity != 'n' ) options.c_iflag |= INPCK; options.c_cc[VTIME] = 150; options.c_cc[VMIN] = 0; tcflush(fd,TCIFLUSH); options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); options.c_oflag &= ~OPOST; if ( tcsetattr(fd, TCSANOW,&options) != 0 ) { perror("setupserial 3"); return FALSE; } return TRUE;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -