下载此文档

嵌入式串口和网络编程实验报告.doc


文档分类:IT计算机 | 页数:约159页 举报非法文档有奖
1/159
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/159 下载此文档
文档列表 文档介绍
1
嵌入式串口和网络编程实验报告
第一篇:嵌入式串口和网络编程实验报告
嵌入式实验报告
题目:linux
串口和网络编程
一、实验目的:
1、强化本学期所学的相关的内容。
2、掌握串口相关设置。
3、强化基于TCP网络传ily
=
AF_INET;

=
htons(CLIENT_PORT);
=
htons(INADDR_ANY);
if(bind(clifd,(struct
sockaddr*
)&cliaddr,sizeof(cliaddr))
<
0
)
9
{
printf(
"bind
to
port
%d
failure!\n
"
,CLIENT_PORT);
exit(
1
);
}//绑定的目的是让其端口是随机的,否则端口是自增1
//一般情况下client端不用绑定
bzero(&servaddr,
sizeof(servaddr));

=
AF_INET;
inet_aton(argv[1],
&);

=
10
htons(SERVER_PORT);
if(connect(clifd,(
struct
sockaddr
*)&servaddr,
socklen)
<
0)
{
printf(
"can't
connect
to
%s!\n",
argv[1]);
exit(1);
}
runflag=1;
pth=pthread_create(&tidp,NULL,Thread1,NULL);
if(pth!=0){printf("error!");return
-1;}
pth=pthread_create(&tidp2,NULL,Thread2,NULL);
if(pth!=0){printf("error!");return
11
-1;}
pthread_detach(tidp);
pthread_detach(tidp2);
while(runflag){;}
close(clifd);
return
0;
}
4、
相关代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
12
#include
#include
#include
#include
#include
#define
COM0
0
#define
BLOCK_MODE
1
#define
NONBLK_MODE
0
#define
SERVER_PORT
20220
#define
LENGTH_OF_LISTEN_QUEUE
10
#define
QUEUE
2022define
13
BUFFER_SIZE
256
#define
WELCOME_MESSAGE
"welcome
to
connect
the
server."
static
struct
termios
g_newtio,g_oldtio;
static
int
speed_arr[]
=
{
B1152022
B57600,
B38400,
B192022
B9600,
14
B4800,
B2400,
B12022
B300,
B1152022
B57600,
B38400,
B192022
B9600,
B4800,
B2400,
B12022
B300,
};
static
int
name_arr[]
=
{
1152022
57600,
38400,
192022
15
9600,
4800,
2400,
12022
300,
1152022
57600,
38400,
192022
9600,
4800,
2400,
12022
300,
};
int
Init_COM(int
Comm,int
Baudrate,int
Parity,int
Stopbit,int
Flagblock)
{
16
int
ret,i;
char
dev_buf[16];
if(Comm
>
3)
{
printf("Com%d
not
exist\n",Comm);
return
-1;
}
memset(

嵌入式串口和网络编程实验报告 来自淘豆网m.daumloan.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数159
  • 收藏数0 收藏
  • 顶次数0
  • 上传人琥珀
  • 文件大小133 KB
  • 时间2022-07-18