free papers,research papers,free term paper samples

VB-based and software implementation of serial communication

Abstract: The serial communication because of its simple, flexible, easy to use, in many areas has broad application prospects. This in-depth understanding of the basis of serial communication technology, combined with its own engineering practice, describes the techniques of serial programming VB. Combined with a communication instance, the concrete realization of communication, Researchers in related fields to provide valuable reference information.

Keywords: Serial; RS232; API; Pcomm; Mscomm; communication program
Abstract: Serial communication has broad application in many fields because of its simple communication circuitry and flexibility. Based on deep comprehension of the technology of the serial communications, this article expounds important technology detail integrated with practice experience. An example of communication program is presented and analyzed, which gives other Researchers valuable reference information.

Keywords:: serial; RS232; API; Pcomm; Mscomm; communication program < BR>
now more and more communication, faster and faster, but due to its low cost serial communication, protocol transparent, less investment in hardware, software, programming is simple, and many other advantages of remote data acquisition, monitoring, communication and control area has been occupied an important position. It not only failed to progress because of the times to be eliminated, but the specifications become more perfect, more and more broad, long-lasting.


1 serial communication communication mechanism

PC serial communication is directly to the serial port UART (PC UART machine, also known as asynchronous communication adapter, a PC, for asynchronous communication interface) for programming communication. PC, the INS8250 UART in each of 10 single-byte programmable register can be used to control and monitor the operation of the serial ports, COM1 of the register address 3F8H-3FEH, COM2 register address is 2F8H-2FEH. 10 register address access by the 7, 5 of which is to register to access conditions set 3FBH top line control register bit to "1", this bit is also called DLAB status bits. [1]
Generally speaking, PC machine has one or more serial ports, they were Com1, Com2 ... .... These external devices with serial port provides a PC for data transfer and communication channels between the CPU and peripheral role as an interpreter. When the character data sent to the peripherals from the CPU, these characters will be converted into serial data bit stream data; and when receiving data, the incoming bit stream from the outside world the data is converted into character data passed to the CPU for processing. In operating systems, Windows drivers with communication (COMM.DRV) API function calls to send and receive data. When using communication control or call the API function declaration, they explain and by the COMM.DRV passed to the device driver.

As a VB programmer, to write serial communication program, you know the communication control functions available to the Windows communications API interface can be, in other words, just set the properties of the control and monitoring communications and time can be.


2 serial communication interface RS-232

previous section discussed the communication mechanism of serial communication, but in order to achieve the specific data collection, monitoring, communication feature, you must understand the specific form of serial . Currently the most widely used, there are two serial interfaces: RS-232 and RS-485. This article focuses on RS-232, RS-485 not be introduced.

RS-232C standard stands for EIA-RS-232C standard, which represent the United States Electronics Industry Association EIA, RS representatives recommended standard, is the identification number 232, C on behalf of the latest in a modified RS232 (1969), before There RS232A, RS232B agreement. It provides cable and mechanical, electrical properties, function and signal transmission process. EIA-RS-232C defines the bit-serial transmission of data terminal equipment (DTE) and data communications equipment (DCE) interface between the information. RS-232C DTE or computer from the point of view to define the pin serial interface signals.

The current RS-232 PC, and communication is the most widely used in Industry as a serial interface. RS232 is defined as a low-speed serial communication in increasing communication distance of the single-ended standards. RS232 to unbalanced transmission mode, the so-called single-ended communication. [2]
DB9 (9-pin serial port) of the connection as follows: 1 foot, the data carrier detect DCD; 2 feet, and receive data RXD; 3 feet, sending data TXD; 4 feet, and Data Terminal Ready DTR; 5 feet, signal to GND; 6 feet, Data Set Ready DSR; 7 feet, request RTS; 8 feet, clear to send CTS; 9 feet, ringing instructions DELL.

DB25 (25 array serial port), also commonly used 9 pin, and the and the DB9 to-one correspondence, the specific connection mode is: 8 feet, the data carrier detect DCD; 3 feet, and receive data RXD; 2 feet, sending data TXD; 20 feet, and Data Terminal Ready DTR; 7 feet, the signal ground GND; 6 feet, and Data Set Ready DSR; 4 feet, and request to send RTS; 5 feet, clear to send CTS; 22 feet, and ringing instructions DELL.

General, for less demanding situations, the use of receive data RXD, transmit data TXD, GND signals to achieve data transmission can be three feet. If you require hardware flow control, you must use the DTR, DSR, RTS and CTS four feet.

Is worth noting that RS-232C is used to indicate positive and negative voltage logic state, and TTL logic state to high requirements that are different. Therefore, in order to work with a computer interface or TTL device connection terminals must be RS-232C and TTL logic circuit relationship between the level and transformation. Now more widely used integrated circuit conversion devices, such as the MC1489, SN75150 chip TTL level to be completed EIA level conversion, and MC1489, SN75154 EIA level to achieve TTL level conversion.


3 are three ways to read data from serial port

current generic software implementation of serial communication methods are 3 kinds of paper are introduced in detail, they each have their own advantages and disadvantages, readers programming can be based on the specific situation choose the right way.

3.1
VB using Mscomm control provided by the communication control to "hide" most of the underlying serial communication operation, the programmer simply write a small amount of code to complete the software development process. Small amount of data in communication, communication requirements are not very high in this case recommended way.

Use Mscomm control for communication is the most need to know several of its main attributes, select one of the following important are introduced, and the rest can refer to the relevant information. [3]
(1) Settings attributes: a string and return the form to set the baud rate, parity, data bits, stop bits. This property is important, for different terminal equipment need to be adjusted by the device (for example, the device is different from the United States, Japan, the equipment, often using odd parity.)
(2) InputMode property: Set the type of receive data, text format 0 and 1 for the binary format.

(3) Input attributes: read and delete the received data stream buffer.

(4) Output properties: send buffer to send a data stream.

(5) Rthreshold property: This property is a threshold that determines when the receive buffer the number of bytes within reach or exceed the value generated code ComEvReceive after the OnComm events.

(6) Handshaking property: Set and return handshake protocol, that is, inside the computer between the CPU and serial communication protocol, to ensure that the data in the buffer overload is not lost. This property guarantees the correctness of data transmission have a significant role, there are four options, namely that: ① no flow control; ② software flow control; ③ hardware flow control; ④ hardware and software flow control. When using hardware flow control, requires the serial port and cable support hardware handshaking between the serial communication line to produce their own, the hardware handshake lines RTS, CTS, DSR, DTR should be connected correctly.

In the right setting on the basis of these properties, and the rest is open the serial port, serial port to send and receive data. This following sections explain in detail using an example set of these attributes and the specific code.

3.2 communication functions directly call the Win32 API call to Windows API functions directly
, can clearly understand the mechanism of serial communication, the flexibility to configure the serial port of the various parameters and attributes, but also directly call the low-level API function, communication efficiency relatively high, but the cost is more complicated procedures, programming cycle is long, suitable for large-scale communication procedures and situations requiring high quality communications.

In the 32-bit Windows systems, serial communication is treated as a file, serial port operation is generally open, close, read, write and other operations, the corresponding Windows API functions are as follows: [4]
(1 ) CreateFile () function: to achieve the initialization of the serial port and open the serial port, serial port handle returned for follow-up resources to process calls.

(2) CloseFile () function: close the serial port, serial non-shared resources, the application used exclusively, communication end should be closed immediately.

Links to Research Papers Download http://www.hi138.com

Newest Research Papers

  • Newest
  • Communication Studies Papers

MOST POPULAR Communication Studies Papers

  • 24Hours
  • 7Days
  • 30Days