帮忙看喜爱这个小程序,都快崩溃了;
#include <stdio.h> #include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <stdlib.h>
int fd;/* File descriptor for the port */
int open_port(void)
{
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
/*
* Could not open the port.
*/
perror("open_port: Unable to open /dev/ttyS0 - ");
}
else
fcntl(fd, F_SETFL, 0);
return (fd);
}
main()
{
int n;
int open_port(void);
/*write data to the serial*/
n = write(fd, "abcdefgh\n", 12);
if (n < 0)
fputs("write serial port failed!\n", stderr);
else
printf("write serial port is:\n");
/*read data for the serail*/
fcntl(fd, F_SETFL, FNDELAY);
close(fd);
}
以上程序执行完后都是得到
abcdefgh
wrwrite serial port is:
而且不管串口有没有连接开发板;
不知道是哪里的问题,求教了;