主题 : 串口应用程序问题请教? 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 105870
精华: 0
发帖: 22
金钱: 110 两
威望: 22 点
综合积分: 44 分
注册时间: 2014-07-07
最后登录: 2015-02-09
楼主  发表于: 2014-07-07 23:26

 串口应用程序问题请教?

串口应用程序问题请教?

大家好,我在PC 虚拟机 linux redhat下编写了串口应用程序代码,用GCC编译顺利通过,什么运行./serial的时候虚拟机没有反应啊。
我又用arm-linux-gcc编译顺利通过,在mini2440开发板上运行./serial,串口仍然没有任何反应。

linux系统下均有相应的设备文件"/dev/ttyS0"

恳请指教,多谢了。


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <signal.h>
#include <string.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>

#include "serial.h"

#define BUFFER_SIZE 1024

#define com_port_1  1
#define com_port_2  2




int main (void)
{
    int len;
    int serialfd;
    char buff[1024];
    
    serialfd= OpenComPort(com_port_1, 9600, 8, "1", 'N');      //zigbee串口设置的波特率
    if (serialfd < 0)
        {
          printf("Error: Opening Com Port %d\n",com_port_1);
          exit (1);
        }
    else
        {
          printf("Open Com Port %d Success, Now going to read port\n", com_port_1);
        }
    
    while(1)
        {
            
         memset(buff,0, BUFFER_SIZE);
         len = ReadComPort(serialfd,buff,BUFFER_SIZE);
         if(len > 0)//read success
           {
            buff[len]='\0';
            printf("Read %d numbers from com_port_%d buff=%s\n",len,com_port_1,buff);    
            WriteComPort(serialfd,buff,BUFFER_SIZE);  
           }  
        }    
      /* end of while */
    close(serialfd);

}