1、摘要当今世界,随着计算机与数据终端的普及,对数据通信的要求日益迫切,应用更加广泛。当前最灵活与经济实用的方法是利用数据调制解调器(MODEM)借助现在的模拟电话公用交换网进行数据传输。网络和多媒体技术的发展,有线的实时数据传输系统在国内已经到了实用阶段,但是由于有线传输的局限性,如要预埋线路,机动性差,造价高等缺点,使得有线的点对点数据传输系统的使用受到限制。而无线通讯与有线相比,有其固定的优越性:联网方便,费用低廉等,所以开发点对点的超短波数据传输系统有很高的实用价值。本文主要介绍了在Windows环境下通过Modem和无线对讲机实现PC机系统之间的超短波数据传输方法,并且用VB语言设计了一
2、个用于无线通信的应用软件。系统主要采用FSK调制解调和无线数据传输技术传输文本、图像、二进制文件,并且可以进行多方实时对话,是一种简便易操作的数据传输系统。可应用于学校、企业、工厂局域网无线通信,水、电、煤气、自动无线抄表,电力负荷监视仪,IC卡电话,商用收费系统,工业现场测控,智能化小区、家庭安全防范,以及城市环境噪音数据采集等领域。系统数据传输波特率为1200bps,采用半双工通信方式,数据传输可在短时间内完成,传输率高。数据传输时一般不受外界干扰,数据可准确发送,稳定性强。系统界面简单,功能完善,不用大规模的使用电缆线,使用方便,而且所需设备简单、经济,广大用户均可承受,成本低。 关键词
3、:串行通信, 波特率, 单片机, 调制解调器, VBPressing increasingly to the data communication demand , the application is more wide-ranging to the popularization in the wake of the calculating machine against the data terminal in the world at present . Present the pragmatic means the most agile together with economical
4、ly is utilizing the analog telephone communal switched network that now the data modulation demodulator ( MODEM ) draw support from to carry on the data transmission Wired real-time data transmission system was reachd pragmatic phase electric network and the multi-medium technique development at hom
5、e , yet the limitations thanks to wire transmission , in case will cover up the line beforehand , maneuverability is bad , and the cost awaits the defect , and causes that the wired point-to-point data transmission system use is subjected to the limit . But not to there is not string news dispatch t
6、ogether with wired is contrastd , and possess such settled admittedly advantage : The networking is convenient , and the expense is inexpensive and so on , therefore opening up that the point-to-point ultrashort wave data transmission systematically possess very tall pragmatic value The main introdu
7、ction of the original be living below Windows environment by means of Modem with does not there is not the pair say , and the engine is achieved the ultrashort wave data transmission means between PCs engine system , moreover design an application software that is used the wireless communication in
8、VBs language The system chiefly adopts that the modulate FSKs solution conciliation does not there is not the line number rumour has it that to be beaten the technique transfer version and image and binary system papers , moreover may carry on in every way conversation real time , and be one kind of
9、 data transmission system which portably easily manipulated . May use to the educational institution and the business and the plant local area network wireless communication , the water , electricity , gas and not thering is not the string voluntarily to transcribe the form , IC checks the phone wit
10、h the electric power burden monitoring instrument , commercial the chargeing system observes and controls at industry field , is on guard in little district of intelligentization and household security , along with the ambient noise data acquisition in town and so on the territory The system data tr
11、ansmits the Baud and adopts the half-duplex transmission means in the interest of 1200bps , the data transmission may be living briefly time inner place completees , the transfer rate is tall . Oridinarily not acceping the jam in the outside world when the data transmission , the data may accurately
12、 be transmited , and the stability is powerful . The systematic interface is easy , and the meritorous service be able to be improved , and it is convenient to employ to the disuse large scale use electric cable string , but also the installation requireing is easy and economy , widely standing in t
13、he way of the per family , the cost is leted drop Keyword : Serial communication , the Baud , the oneboard computer , the modulate demodulator , VB 目录引言 - 5第一章 超短波数据传输系统的概述 - 6第一节 超短波数据传输系统的介绍 - 6第二节 超短波数据传输系统的特点 - 6第三节 超短波数据传输系统的应用 - 6第四节 无线通信和数据传输技术的发展 - 6第二章 超短波数据传输系统的系统结构 - 7 第一节 系统结构 - 7第二节 结构描
14、述 - 7第三章 计算机软件模块 - 8第一节 程序流程图 - 8第二节 程序设计 - 81、收发文本文件 - 82、收发程序文件 - 143、收发图象文件 - 204、实时对话 - 25第四章 系统硬件描述 - 29第五章 软件使用说明 - 30第六章 结束语 - 35参考文献 - 36引言Visual Basic 是Mcrosoft公司推出的强有力的系列开发软件之一,而且以其实用、方便、快捷、开发周期短、广泛而强大的功能越来越被广大编程人员所亲赖,广为流传。在Visaul Basic开发工具中提供了大量的控件(或称控制、组件)供编程人员使用,可以方便的利用这些组件中的属性、方法、语言等以事
15、件驱动方式开发应用程序,还可以利用WINDOWS SDK中的API中的应用程序接口等工具开发应用程序。VB还自带一个控件开发软件包CDK,利用CDK可以开发自己需要的Controls 。在通讯问题中我们可以使用VB提供的通讯控件或调用WINDOWS API通讯函数。利用VB开发通信程序主要的方法有两种,一是利用VB本身提供的控件(CONTRALS),另一种方法是利用WINDOWS API应用程序接口,WINDOWS API主要提供了三个动态连接库KERNEL.EXE、USER.EXE、GDI.EXE供开发人员调用,其中KERNEL.EXE 主要包括一些底层操作函数,完成一些资源管理、任务、内存
16、等操作,USER.EXE包含了一些与WINDOWS管理有关的函数,如通讯、菜单、消息、光标、插入符、计时器以及绝大多数非显示函数,GDI.EXE图形设备接口库,主要内容为与设备输出有关的函数。和串口通讯有关系的函数BuilidCommDCB、ClearCommBreak、SetCommBreak、FlushComm、GetCommError、GetCommState、WriteComm、ReadComm、SetCommState、CloseComm等均在 Windowssystem 子目录下的USER.EXE动态连接库中,在VB调用之前应该先在全局变量定义处声明API通讯函数、定义常量。计算机
17、通信技术除用在传统的数据通信外,在监测与控制系统中也获得越来越广泛的应用,许多测控系统需要把现场采集的数据传送给远方的监控机或者服务器。随着计算机与数据终端的普及,对数据通信的要求日益迫切,应用更加广泛。当前最灵活与经济实用的方法是利用数据调制解调器(MODEM)借助现在的模拟电话公用交换网进行数据传输。国内市场上单片FSK MODEM集成电路较多,主要有MOTOROLA、INTEL、AMD、TI、OKI等公司的产品。随着网络和多媒体技术的发展有线的实时数据传输系统在国内已经到了实用阶段,但是由于有线传输的局限性,如要预埋线路,机动性差,造价高等缺点,使得有线的点对点数据传输系统的使用受到限制
18、。而无线通讯与有线相比,有其固定的优越性:联网方便,费用低廉等,所以开发点对点的超短波数据传输系统有很高的实用价值。第一章 超短波数据传输系统的概述第一节 超短波数据传输系统的介绍随着单片机测控技术的广泛应用和无线通信技术的发展以及工业测控现场数据传输、无线抄表等需要,越来越多的计算机信息将采用无线通信方式,而且在有些没有通信线路或者很难架设通信线路的地方只能采用无线传输方式。无线传输具有很高的实用性。本系统主要采用FSK调制解调和无线数据传输技术传输文本、图像、二进制文件,并且可以进行多方实时对话。是一种简便易操作的数据传输系统。 第二节 超短波数据传输系统的特点传输率高。本系统数据传输波特
19、率为1200bps,采用半双工通方式,数据传输可在短时间内完成。稳定性强。本系统数据传输时一般不受外界干扰,数据可准确发送。用方便。系统界面简单,功能完善,不用大规模的使用电缆线。成本低。 所需设备简单、经济,广大用户均可承受。 第三节 超短波数据传输系统的应用该系统主要可应用于学校、企业、工厂局域网无线通信,水、电、煤气、自动无线抄表,电力负荷监视仪,IC卡电话,商用收费系统,工业现场测控,智能化小区、家庭安全防范,以及城市环境噪音数据采集等领域。 第四节 无线通信和数据传输技术的发展 无线通信技术和数据传输技术正趋于融合的潮流之中,这种融合使无线技术正面临一次深刻的变化。在很多情况下,在一
20、个固定的地点有大量数据传输需求的时候局域网是一种很好的方式,由于无线网有很好的移动性,它可以作为有线网络的一种有效补充,如果完全建成有线网络,在成本费用上会很贵。无线局域网可移动的特性方便了许多用户,但有一个安全问题。其实,无线通信技术和数据传输技术的融合可以逐步完善,目前无线局域网已经完全解决了安全问题,英特尔的IT部门很多都使用了无线方式。因此,无线通信技术的开发具有较高的实用价值。第二章 超短波数据传输系统的系统结构 第一节 系统结构无线Modem把串口发来的数字信号调制成适合无线传输的FSK信号电台把来自无线Modem的FSK信号进行二次调制,通过天线发射到 空中软件通过串口把数据送到
21、无线Modem电台把接收到的载波信号转换成FSK信号,送到无线Modem处理软件把串口接收到的数据组合成文件保存起来无线Modem把FSK信号转换成数字信号,送到串口甲乙 图1、超短波数据传输系统的系统结构第二节 结构描述 通信双方通过无线Modem和电台建立点对点的通信通道。系统结构如上图所示,以甲,乙两地的数据传输为例来说明一下:在甲地,计算机通过串口1把数据传送到无线Modem,无线Modem把串口发来的数字信号调制成适合无线传输的FSK信号,电台把来自无线Modem的FSK信号进行二次调制,通过天线发射到空中,这样就完成了数据的传送。在乙地,电台把接收到的载波信号转换成FSK信号,送到
22、无线Modem处理,无线Modem把FSK信号转换成数字信号,送到串口1,计算机软件把串口接收到的数据组合成文件保存起来。到此,数据接收也已完成。收到甲地的信息后,乙地可以回复信息。此时,乙地作为发送方,甲地作为接收方。第三章 计算机软件模块第一节 软件流程图 接收完毕返回发送文件头(包括类型、发送地址、接收地址、文件长度),发送文件,发结束标志退出?N检查文件头,是否给本机发送,如不是则退出,如果是则接收,转相应处理开始初始化一些关键变量,包括发送标志、使用用户等。 初始化MSComm控件,打开串口1,打开发送定时器。YYYNNEnd发送完毕返回MSComm检查接收缓冲是否有数据定时器检查发
23、送标志S_flag是否为TrueTrue图2、软件结构流程图第二节 程序设计1、收发文本文件l 如果用户选择功能为进行收发文本文件,则在主窗口中打开收发文本文件对话框,选择发送单位,进行文本文件传输,窗口如下:图1收发文本文件窗口图2 选择文本文件图3 正在传输文本文件图4 文本文件传输结束代码如下:Private Sub Form_Load() =初始化= MSComm1.Settings = 1200,n,8,1 设定波特率1200bps,无校验,8位数据位,1位停止位 MSComm1.CommPort = 1 串口1 MSComm1.SThreshold = 0 MSComm1.RThr
24、eshold = 1 设定RThreshold = 1,等待出发OnComm事件 MSComm1.OutBufferCount = 0 清空输出缓冲区 MSComm1.InBufferCount = 0 清空输入缓冲区 MSComm1.PortOpen = True 启动串口 SSTab1.Tab = 3 初始化为在第一个页面 Timer1.Enabled = True 打开定时器,检查S_flag标志 R_Flag = False FormMain.Caption = 超短波数据传输系统 使用单位: + D End SubPrivate Sub Form_Unload(Cancel As I
25、nteger)EndEnd SubPrivate Sub Command6_Click()EndEnd Sub=发送文本文件=Private Sub Command1_Click() CommonDialog1.Filter = 文本文件(*.txt)|*.txt|所有文件|*.* CommonDialog1.InitDir = C:bysjfiles CommonDialog1.CancelError = False CommonDialog1.FileName = CommonDialog1.ShowOpen If CommonDialog1.FileName = Then Exit Su
26、b End If S_Name = CommonDialog1.FileName S_Type = P_Begin + Trim(Str(User) + AA FormSelect.Show 1End SubSelect Case R_Type Case AA SSTab1.Tab = 0 Open App.Path + files + R_Name For Binary As #R_File Label1.Caption = 正在接收来自 + B + 的文本文件,请稍候. Label1.Visible=TrueIf Plong 0Then =DDDDDD= 接收文件 R_Var = MSCo
27、mm1.Input R_Byte = R_Var(0) Put #R_File, , R_Byte Plong = Plong - 1 ProgressBar1.Value = ProgressBar1.Value + 1 StatusBar1.Panels(2).Text = 文件总长度: + Str(R_long) + 剩余: + Str(Plong) If MSComm1.InBufferCount = 0 Then Exit Sub Else GoTo getc End IfElse =DDDDDD= Close #R_File R_Flag = False Label1.Visibl
28、e = False Label2.Visible = False Label3.Visible = False Command1.Enabled = True Command2.Enabled = True Command3.Enabled = True Command6.Enabled = True If R_Type = CC Then FormMain.Image1.Visible = True FormMain.Image1.Picture = LoadPicture(App.Path + files + R_Name) End If R_Char = MSComm1.InBuffer
29、Count = 0 MSComm1.InputMode = comInputModeText FormMain.Enabled = True MsgBox 文件 + R_Name + 传输结束,放于 + App.Path + files目录中, vbOKOnly, 提示 StatusBar1.Panels(2) = ProgressBar1.Value = 0 Label1.Visible = False Label2.Visible = False Label3.Visible = False End If 2、收发程序文件l 如果用户选择功能为进行收发程序文件,则在主窗口中打开收发程序文件
30、对话框,选择发送单位,进行程序文件传输,窗口如下:图1收发程序文件窗口图2 选择程序文件图3 正在发送程序文件图4 程序文件传输结束代码如下:Private Sub Form_Load() =初始化= MSComm1.Settings = 1200,n,8,1 设定波特率1200bps,无校验,8位数据位,1位停止位 MSComm1.CommPort = 1 串口1 MSComm1.SThreshold = 0 MSComm1.RThreshold = 1 设定RThreshold = 1,等待出发OnComm事件 MSComm1.OutBufferCount = 0 清空输出缓冲区 MSCo
31、mm1.InBufferCount = 0 清空输入缓冲区 MSComm1.PortOpen = True 启动串口 SSTab1.Tab = 3 初始化为在第一个页面 Timer1.Enabled = True 打开定时器,检查S_flag标志 R_Flag = False FormMain.Caption = 超短波数据传输系统 使用单位: + D End SubPrivate Sub Form_Unload(Cancel As Integer)EndEnd SubPrivate Sub Command6_Click()EndEnd Sub=发送程序文件=Private Sub Comma
32、nd2_Click() CommonDialog1.Filter = 程序文件(*.exe)|*.exe|程序文件(*.com)|*.com|所有文件|*.* CommonDialog1.InitDir = C:bysjfiles CommonDialog1.CancelError = False CommonDialog1.FileName = CommonDialog1.ShowOpen If CommonDialog1.FileName = Then Exit Sub End If S_Name = CommonDialog1.FileName S_Type = P_Begin + Tr
33、im(Str(User) + BB FormSelect.Show 1End SubCase BB SSTab1.Tab = 1 Open App.Path + files + R_Name For Binary As #R_File Label2.Caption = 正在接收来自 + B + 的程序文件,请稍候. Label2.Visible = TrueIf Plong 0Then =DDDDDD= 接收文件 R_Var = MSComm1.Input R_Byte = R_Var(0) Put #R_File, , R_Byte Plong = Plong - 1 ProgressBar
34、1.Value = ProgressBar1.Value + 1 StatusBar1.Panels(2).Text = 文件总长度: + Str(R_long) + 剩余: + Str(Plong) If MSComm1.InBufferCount = 0 Then Exit Sub Else GoTo getc End IfElse =DDDDDD= Close #R_File R_Flag = False Label1.Visible = False Label2.Visible = False Label3.Visible = False Command1.Enabled = True
35、 Command2.Enabled = True Command3.Enabled = True Command6.Enabled = True If R_Type = CC Then FormMain.Image1.Visible = True FormMain.Image1.Picture = LoadPicture(App.Path + files + R_Name) End If R_Char = MSComm1.InBufferCount = 0 MSComm1.InputMode = comInputModeText FormMain.Enabled = True MsgBox 文
36、件 + R_Name + 传输结束,放于 + App.Path + files目录中, vbOKOnly, 提示 StatusBar1.Panels(2) = ProgressBar1.Value = 0 Label1.Visible = False Label2.Visible = False Label3.Visible = False End If 3、收发图象文件l 如果用户选择功能为进行收发图象文件,则在主窗口中打开收发图象文件对话框,选择发送单位,进行图象文件传输,窗口如下:图1 收发图象文件窗口图2 选择程序文件图3 正在发送图象文件图4 图象文件传输结束代码如下:Private Sub Form_Load() =初始化= MSComm1.Settings = 1200,n,8,1 设定波特率1200bps,无校验,8位数据位,1位停止位 MSComm1.CommPort = 1 串口1 MSComm1.SThreshold = 0 MSComm1.RThreshold = 1 设定RThreshold = 1,等待出发O