免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1463 | 回复: 0
打印 上一主题 下一主题

[操作系统] 串口应用程序问题请教? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-07-07 23:13 |只看该作者 |倒序浏览
串口应用程序问题请教?

大家好,我在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);

}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP