我用的是s3c2410A的板子,上面有两个串口,先用串口1与电脑连接,在开发板上运行读串口2的程序,然后将电脑与串口2连接,再打开串口调试助手发送数据;最后在用电脑连接串口1,看能否读到发送的数据, 但是不能成功,我不知道为什么,请不吝赐教,谢谢啊......
下面是主程序:
/*com_write*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <termios.h>
#include "uart_api.h"
int main(void)
{
int fd,fd1,recv_fd;
int i;
//int recv_fd;
unsigned char buff[BUFFER_SIZE];
int real_read,real_write,serial_read;
struct termios new_cfg,old_cfg;
int speed;
//unsigned char RS485_date;
if ((recv_fd = open(RECV_FILE_NAME, O_CREAT|O_WRONLY, 0644)) < 0)
{
perror("open");
return 1;
}
if((fd = open_port(TARGET_COM_PORT)) < 0) /* 打开串口 */
{
perror("open_port");
return 1;
}
if(set_com_config(fd, 115200, 8, 'N', 1) < 0) /* 配置串口 */
{
perror("set_com_config");
return 1;
}
memset(buff, 0, BUFFER_SIZE);
printf("buff=%s\n",buff);
while(1)
{
real_read = read(fd, buff, BUFFER_SIZE);
usleep(1000000);
printf("real_read=%d\n",real_read);
write(recv_fd, buff, real_read);
}
close(fd);
return 0;
}