免费注册 查看新帖 |

Chinaunix

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

简单RS232通信程序 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-03-18 09:49 |只看该作者 |倒序浏览

/**********************************rs232.h 头文件*******************************/
#include           
#include         
#include         
#include      
#include     
#include     
#include     
#include        
#include           
#include         
#include         
#include     
#include     
#include     
#define FALSE  -1
#define TRUE   0
#define NET_PORT 19988
/**打开设备**/
extern int opendev(char *dev,mode_t mode);
/** 设置串口通信速率×*/
void set_speed(int fd, int speed);

/** 设置串口数据位,停止位和效验位×*/
extern int set_parity(int fd,int databits,int stopbits,int parity);
#define MAX_BUF_SIZE 4096
struct net2net_buf{
int len;
char buf[MAX_BUF_SIZE];
};
/********************************** set232.c 串口打开,设置函数********************************/
/**
#include "rs232.h"
[email=*@brief]*brief[/email]
  设置串口通信速率
[email=*@param]*param[/email]
  fd     类型 int  打开串口的文件句柄
[email=*@param]*param[/email]
  speed  类型 int  串口速度
[email=*@return]*return[/email]
  void
*/
int speed_arr[] = { B38400, B19200, B9600, B4800, B2400, B1200, B300,
  B38400, B19200, B9600, B4800, B2400, B1200, B300, };
int name_arr[] = {38400,  19200,  9600,  4800,  2400,  1200,  300, 38400,  
   19200,  9600, 4800, 2400, 1200,  300, };
void set_speed(int fd, int speed){
int   i;
int   status;
struct termios   Opt;
tcgetattr(fd, &Opt);
for ( i= 0;  i 0)
{
  printf("nread:%d
",nread);
  retbytes += nread;
  all_bytes  += nread;
}
return all_bytes;
}


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/380/showart_16282.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP