- 论坛徽章:
- 0
|
/**********************************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 |
|