外文文献翻译-VB.doc_第1页
外文文献翻译-VB.doc_第2页
外文文献翻译-VB.doc_第3页
外文文献翻译-VB.doc_第4页
外文文献翻译-VB.doc_第5页
免费预览已结束,剩余3页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

communication method of computer and total-station instruments of data at VB environmentSummary this text mainly inquiry in to carried out communication between computer and the total-station instrument data under VisualBasic6.0(call VB as follows) environments. Two kinds of communication methods: the usage mscomm control and the function of windows API. The application that also combined a solid example to carry out their string to go communication Procedure and step. Finally carried on comparison and summary to two kinds of methods.Keyword Visual Basic 6.0 data communication the mscomm control All of the electronics total-station instrument because its function is strong and operate convenience and consumedly raised an open country homework efficiency. Therefore it just and gradually replace traditional diagraph instrument and it is expanded for an application. Although making use of the system menu function of total-station instruments can immediately complete normal regulations diagraph, monitor in the big dam safety, side the ascent transform a monitor etc. this kind of data is a little bit greatly and need solid the applied situation of processing data, it is will not satisfy demands only by function and amount of memory of instrument. The data at this time can be output a computer by the instrumental data exportation port, and the data can be processed and saved by software. Along with the extensive usage of calculator, many local open country digatial measure diagram method also need to carry out real-time transport. VB is released by the Microsoft company of according to visual programming language, its adoption faces to the program design method that object, affairs drives and operate simple, therefore doubly be subjected to program design personnels favor.Underneath with Leica Tc 2002 whole station instrument for example, introduce how to carry out the communication between computer and total-station in the VB 6. 0 environment by making use of mscomm and the function of Windows API One,usage MSComm control a piece VB 6.0 provided an ActiveX to control Communication of a Microsoft Control, brief name MS Common controlled a piece, customer can at own of imbed MSComm to control a piece in the applied procedure, should control a piece to deliver and receive a data through a string of line port, for applied the procedure provide a string of line communication function. Choose VB 6.0engineering menus, open parts dialog box, pick out Microsoft Comm Control 6.0, can immediately control the piece to the mscomm and add a box of controlling of person VB. The mscomm that may use controls the attribute of piece to have several followings:The CommPort: the constitution string go slogan;Settings: constitution string the line communication parameter;Portpopen: constitution or return to a string of communication appearance of;InputMode: the constitution put off to a later time blunt area to read numeral format;Input: from receive buffer area to read data;Output: Write a number toward the buffer area according to:In Buffer Size: receive the size of buffer area;Out Buffer Size: send out the size of buffer area;Out Buffer Count: send out the word stanza of buffer area number;Input Len: constitution or return to Input to read the word stanza of each time number;MS Comm controls the way that the piece provided two kinds of processings string communication: search method and affairs drive I/O method. Searching a way is direct and be easy to comprehension, but take up for a great deal of CPU time;The affairs drives a way from Windows 98 notice applied the procedure some affairs when take place, then according to the matter taken place The feeling comes to carries on an operation to the string. These two kinds of methods each beneficial fraud and oneself apply of realm, so in the different correspondence system, can according to the dissimilaritys requesting adoption different technique. In the middle of monitoring system, because of the contingency and request transmission data of affairs of solid sex, the calculator often adopts affairs to drive I/O method to carry on the spot monitor. It uses a step for:1, open the port that needs to carry on communication, accept for communication and send out a data brigade the row assign memory area.2, carry on a beginning to start to turn to the communication port, lead especially such as the wave, strange accidentally the school check, data, stop etc.3, carry on reading and writing an operation to the communication port.4, such as the be over string go communication, the close beats to rise of communication port.For example, control Leica with the calculator when the Tc2002 whole station instrument auto measure writing the following code can nicely carry out two of communication:The MS CommlCOmmPort=1the constitution string go a communicationThe MS CommlSettings=2400, e.7, IP1constitution wave especially rate, strange accidentally check a school, data number and stop numberThe MS Comml InputLen=1constitution or return to receive to use Input inside the buffer area an attribute to read the persons character list pieceThe MS Comml InbufferSize =4096establish Buffer area sizeThe MS CommlPortOpen=Trueopen a communication portAttention:1, be the string that the procedure would automatically close to open while terminating line.2, if receiving buffer area is more big, the effective memory of procedure usage more small, whereas probably receive buffer area spillage, therefore should pass an experiment to enlarge its size gradually. According to the constitution like this, get up a calculator, the whole station instrument conjunction with an electric cable, can carry out the string of calculator and whole station instruments line communication.Two, make use of the function of Windows APIUnder the some condition, MSComm, control a piece isnt suitable for our requests. We can use Windows at this time API provides of communication function to carry out can transplant sex strong string of line of communication procedure with writing. Windows 98 correspondence the system provided the string of an improvement line application the procedure pick up a people API to use to carry on handing over type string with each other line correspondence. Among them, string the and other correspond by letter an equipments is a document to carry on the processed, open, close, reading of string and write in the function used similar to the function of the operation document.Before adjusting to use APIA function, have to the first essentials pronouncement change to measure and function.Dim dcb As DCBDim ofstructl As OFSTRUCTDim operport As LongOpen an API text to originally look into a machine in the V B wreath territory bottom, open Win32. Txt document, atpronouncementing can the options win election in OpenFilc and Setup Cornm, Setup CommState and ReadFile, WriteFile, CIoscHand, le etc. function, in type can the options win election in DCB, OVERLAPPED etc. structure, in constant can the options win election in ODDPARITY, EVRXCHAR etc. often quantity, then choose a replication, make duplicate them to the scrapbook, and glue to stick application procedure code in. Adjust to carry on a string of line communication with API in the VB 6.0 timeses:1,adjust to use CreateFile line communication first carry on a beginning to start to turn to the string. CreateFile function for read an interview or write an interview to beatOpen a string of, return to that string of sentence handle after opening successfully, then adjust to use SetComm function is in a string of line allotment buffer area size, provide to read and write a string of usage, immediately after use DCB the structure change to measure a constitution to need to change the communication parameter of lacking the string line of saving the value, such as wave especially rate, strange accidentally the school check a , data, stop.2,adjust to use Write File, the Read File function carries on reading and writing an operation to the string line. Carry on a data to send out with Write File, for synchronous I/O operation, its last parameter can be NULL, but tread an I/O operation to the difference, its last parameter musts be a direction OVERLAPPED structure of point needle, make reading and writing of data the operation carry on in the backstage and pass this OVERLAPPEDstructure to acquire current operation appearance. Use Read File receive buffer area to read from the string data, data before reading, use Clear Comm Error the function acquire word stanza within buffer area number.3, use Clothes Handle function close string line communicationThis method communication code is as follows:The Dim ComDev, Err, Errl, bWriteState, dwBytesRead,dwBytesRead As LongThe ComDev = CreateFiles(COM 1, GENERIC-READ|GENERIC -WRITE, 0, NULL,OPEN -EXISTING, FILE -ATTRIBUTE NORMAL, NULL) open COM 1The if ComDev=-1 ThenMsgboxcan not open in a string of line:Exit SubErr= SetupComm(hComDev, 1024, 512), establish to place the size of receiving the buffer area and exportation buffer areaThe GetCommState(hComDev, &cb)return the constitution circumstance of current string ofdcb .BaudRate=2400the wave lead to 2400 bpses especiallydcb .f Parity=NOPARITYhave no strange accidentally the school checkDcb.ByteSize=7data is 7dcb . StopBits=1establish a stopErrl =SetCommStates( hComDev, & dcb)DCB the contents within structure write to establish toward the stringDo EventsThe bWrite State= WriteFile(hComDev,1plnBuffer, 1, dwBytesRead, NULL)send outResultRead File(hComDev, 1 pinBuffer, 1, dwBytesRead, NULIJread dataClose Handle(h Comdev)close an equipments sentence handleThree, end languageIn the VB under 6.0 environments in two kinds of methods of development string line communication procedure, make use of API the function write a string of communication procedure more complicated, need to have a certain plait distance experience, its advantage is to carry out function more abundant, application noodles more extensive, more complicated communication function. But MSComn: control a piece is packed by a series of Windows API function to gather but become, its usage door averted from to carry on to the complicated and low level function direct operation, provide standard affairs processing function, process, and carry on the constitution of communication parameter in a string of line in the way of attribute, can a little bit easily solution string zXun problem. Customer while being physically applying can according to the circumstance that review request and oneself, choose an appropriate method, develop a foolish good whole station of an effect the instrument and calculator carry on the procedure of data communication.VB环境下计算机与全站仪的数据通讯方法摘 要 本文主要探讨了在VisualBasic6 .0(以下简称VB)环境下实现计算机与全站仪数据通讯的两种方法:使用mscomm控件和windows API函数。并结合实例给出了实现两者串行通讯的应用程序及步骤,最后对两种方法进行了比较和总结。关键词 VisualB asic6 .0 数据通讯mscomm控件电子全站仪由于其功能强大,操作方便,大大提高了野外作业效率。因此它正逐步取代传统的测量仪器被推广应用。虽然利用全站仪本身的系统菜单功能即可完成常规测量作业,但在大坝安全监测、边坡变形监测等这种数据量较大、需实时处理数据的应用场合,单靠仪器本身的功能和内存量将不能满足要求。此时可将数据通过仪器的数据输出端口输出到计算机,并由软件对数据进行处理和存储。随着计算机的广泛使用,目前国内许多野外数字测图也要实现数据的实时转输。VB是由微软公司推出的基于Windows的可视化编程语言,它采用面向对象、事件驱动的程序设计方法,操作简便,因此倍受程序设计人员的青睐。下面就以Leica Tc2002全站仪为例,介绍如何在VB 6. 0环境下利用mscomm控件和Windows API函数实现计算机与全站仪的数据通讯。一 、使用 MSComm控件VB 6 .0 提供了一个ActiveX控件MicrosoftCommuniacation Control,简称MSComm控件,用户可以在自己的应用程序中嵌入MSComm控件,该控件通过串行端口传输和接收数据,为应用程序提供串行通讯功能。选择VB 6.0 “工程”菜单,打开“部件”对话框,选中Microsoft Comm Control 6.0,即可把mscomm控件加人VB的控件箱。可能用到的mscomm控件的属性有以下几个:CommPort:设置串行口号;Settings : 设置串行口通讯参数;PortPopen: 设置或返回串口的通讯状态;Input Mode: 设置从缓冲区读取数字的格式;Input : 从接收缓冲区读取数据;Output: 向缓冲区写人数据:InBufferSize: 接收缓冲区的大小;OutBufferSize: 发送缓冲区的大小;OutBufferCount: 发送缓冲区的字节数;InputLen:设置或返回Input每次读出的字节数;MS Comm控件提供了两种处理串口通讯的方式:查询方式和事件驱动I/O方式。查询方式直接,易于理解,但占用大量CPU时间;事件驱动方式是由Windows 98通知应用程序某些事情什么时候发生,然后根据所发生的事情来对串口进行操作。这两种方式各有利弊和自己适用的领域,所以在不同的通信系统中,可以根据不同的要求采用不同的技术。在监测系统中,由于事件的偶然性和要求传送数据的实时性,计算机常采用事件驱动I/O方式来进行现场监测。其使用步骤为:1、 打开需要进行通讯的端口,为通讯接受和发送数据队列分配内存区。2、 对通讯端口进行初始化,如波特率、奇偶校验、数据位、停止位等。3、 对通讯端口进行读写操作。例如,用计算机控制LeicaT c2002全站仪自动测量时,编写下列代码能很好地实现二者的通讯:MS CommlCOmmPort=1 设置串行通讯口MS CommlSettings=2400,e.7,IP1 设置波特率、奇偶检校、数据位数、停止位数MS Comml InputLen= 1 设置或返回接收缓冲区内用Input属性读人的字符个数MS Comml InbufferSize = 4096 设置缓冲区大小MS CommlPortOpen=True 打开通讯端口注 意 :1、当程序终止时将自动关闭打开的串行口。2、如果接收缓冲区越大,程序使用的有效内存就越小,反之有可能接收缓冲区溢出,因此应通过实验逐渐增大其尺寸。依据这样的设置,用RS-232型电缆将计算机、全站仪连接起来,就能实现计算机与全站仪的串行通讯了。二 、利 用 WindowsA PI函数在有些情况下,MSComm、控件不适合我们的要求。这时我们可以用Windows API提供的通讯函数来实现,以编写出可移植性强的串行通讯程序。Windows 98通信体系提供了一个改进的串行应用程序接口API用来进行交互式串行通信。其中,串口和其它通信设备是作为文件进行处理的,串口的打开、关闭、读取和写入所用的函数和操作文件的函数相同。在调用 APIA函数之前,必须先要声明变量和函数。Dim dcb As DCBDim ofstructl As OFSTRUCTDim operport As Long在 V B环 境下打开API文本查看器,打开Win32. txt文件,在“声明”可选项中选中OpenFilc、SetupCornm, SetupCommState、ReadFile, WriteFile, CIoscHand,le等函数,在“类型”可选项中选中DCB,OVERLAPPED等结构,在“常

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论