int n
sbuf[]={Hello,this is a Serial_Port test!\n };//待发送数据
int len_send="sizeof"(sbuf);//发送缓冲区字节数定义
n = write(fd,sbuf,len_send); //写缓冲区
if(n == -1)
{
printf("Wirte sbuf error.\n");
}
......
7.关闭串口
对设备文件的操作与对普通文件的操作一样,打开操作之后还需要关闭,关闭串口用函数close( )来操作,函数原型为:
int close(int fd);
参数说明:
fd:文件描述符
函数返回值:
成功返回0,失败返回-1。
int tcgetattr(int fd, struct termios *termios_p);
int tcsetattr(int fd, int optional_actions, struct termios *termios_p);
int tcsendbreak(int fd, int duration);
int tcdrain(int fd);
int tcflush(int fd, int queue_selector);
int tcflow(int fd, int action);
int cfmakeraw(struct termios *termios_p);
speed_t cfgetispeed(struct termios *termios_p);
speed_t cfgetospeed(struct termios *termios_p);
int cfsetispeed(struct termios *termios_p, speed_t speed);
int cfsetospeed(struct termios *termios_p, speed_t speed);