我的程序是这样的:
1.实现虚拟机与mini2440串口通讯,虚拟机发送字符串,mini2440接收字符串并在终端打印出来
我用的Mini2440开发板是串口0(ttySAC0),虚拟机用的是串口1(ttyS1),因为用了一开始用来输入输出调试信息的串口0,所以在做串口通讯的时候用telnet来监控mini2440的工作状态
问题:
开始设置波特率为115200的时候可以正常工作,接收端可以正常工作,并且在终端打印出相应的数据,
但是当我把波特率改为9600或者其它的时候,终端感觉上应该是有接收到信息,但是打印出的是空白数据
我的代码是更改了波特率,其他的设置都没有动,为什么115200就能正常工作,而降低的波特率反而智能检测到有数据,但是不能够正确输出呢?是不是改了波特率,其他还有什么对应的数据要设置呢?

解决方案 »

  1.   

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <errno.h>
    #include <unistd.h>
    #include <termios.h>
    #include "uart_api.h"
    #define BUFFER_SIZE 1024
    #define HOST_COM_PORT 1
    int main(void)
    {
            int fd;
            char buff[BUFFER_SIZE];
            if((fd = open_port(HOST_COM_PORT)) < 0) /* 打开串口 */
            {
                    perror("open_port");
                    return 1;
            }        if(set_com_config(fd, 9600, 8, 'N', 1) < 0) /* 配置串口 */
     {
                    perror("set_com_config");
                    return 1;
            }
            while(1){
                    printf("Input some words(enter 'quit' to exit):");
                    memset(buff, 0, BUFFER_SIZE);
                    if (fgets(buff, BUFFER_SIZE, stdin) == NULL)
                    {
                            perror("fgets");
                            break;
                    }
                    if(write(fd, buff, strlen(buff))>0)
                       {
                            printf("The sended words are : %s", buff);
                    }
               printf("ok\n");
            }        close(fd);
            return 0;
    }这个是串口发送端的代码