英文文献及翻译 下载本文

内容发布更新时间 : 2024/10/19 0:31:46星期一 下面是文章的全部内容请认真阅读。

原文:

Serial Communication via RS232 Port

By Harsha Perla and Veena Pai from: http://electrosofts.com/index.html

RS232 is the most known serial port used in transmitting the data in communication and interface. Even though serial port is harder to program than the parallel port, this is the most effective method in which the data transmission requires less wires that yields to the less cost. The RS232 is the communication line which enables the data transmission by only using three wire links. The three links provides ?transmit?, ?receive? and common ground...

The ?transmit? and ?receive? line on this connecter send and receive data between the computers. As the name indicates, the data is transmitted serially. The two pins are TXD & RXD. There are other lines on this port as RTS, CTS, DSR, DTR, and RTS, RI. The ?1? and ?0? are the data which defines a voltage level of 3V to 25V and -3V to -25V respectively.

The electrical characteristics of the serial port as per the EIA (Electronics Industry Association) RS232C Standard specifies a maximum baud rate of 20,000bps, which is slow compared to today?s standard speed. For this reason, we have chosen the new RS-232D Standard, which was recently released.

The RS-232D has existed in two types. i.e., D-TYPE 25 pin connector and D-TYPE 9 pin connector, which are male connectors on the back of the PC. You need a female connector on your communication from Host to Guest computer. The pin outs of both D-9 & D-25 are show below.

D-Type-9 pin no. 3 2 7 D-Type-25 pin no. 2 3 4 RD TD RTS Receive Data (Serial data input) Transmit Data (Serial data output) Request to send (acknowledge to modem that UART is ready to exchange data 8 5 CTS Clear to send (i.e.; modem is ready to exchange data) 6 6 DSR Data ready state (UART establishes a link) 5 1 7 8 SG DCD Signal ground Data Carrier detect (This line is active when modem detects a carrier 4 9 20 22 DTR RI Data Terminal Ready. Ring Indicator (Becomes active when modem detects ringing signal from PSTN About DTE & DCE:

Devices, which use serial cables for their communication, are split into two categories. These are DCE (Data Communications Equipment) and DTE (Data Terminal Equipment.) Data Communications Equipments are devices such as your modem, TA adapter, plotter etc while Data Terminal Equipment is your Computer or Terminal. A typical Data Terminal Device is a computer and a typical Data Communications Device is a Modem. Often people will talk about DTE to DCE or DCE to DCE speeds. DTE to DCE is the speed between your modem and computer, sometimes referred to as your terminal speed. This should run at faster speeds than the DCE to DCE speed. DCE to DCE is the link between modems, sometimes called the

line speed.

Pin outs Function

Most people today will have 28.8K or 33.6K modems. Therefore, we should expect the DCE to DCE speed to be either 28.8K or 33.6K. Considering the high speed of the modem we should expect the DTE to DCE speed to be about 115,200 BPS. (Maximum Speed of the 16550a UART) . The communications program, which we use, has settings for DCE to DTE speeds. However, the speed is 9.6 KBPS, 144 KBPS etc and the modem speed.

If we were transferring that text file at 28.8K (DCE- DCE), then when the modem compresses it you are actually transferring 115.2 KBPS between computers and thus have a DCE- DTE speed of 115.2 KBPS. Thus, this is why the DCE- DTE should be much higher than the modem's connection speed. Therefore, if our DTE to DCE speed is several times faster than our DCE to DCE speed the PC can send data to your modem at 115,200 BPS. What is NULL MODEM? Null modem is used to connect two DTE's together. This is used to transfer files between the computers using protocols like Zmodem protocol, xmodem protocol, etc

Figure :Above shows the connections of the Null modem using RS-232D connecter Above-mentioned figure shows the wiring of the null modem. The main feature indicated here is that the to make the computer to chat with the modem rather than another computer. The guest & host computer connected through the TD, RD, and SG pins. Any data that is transmitted through TD line from the Host to Guest is received on RD line. The Guest computer must have the same setup as the Host. The signal

ground (SG) line of the both must be shorted so that grounds are common to each computer.

The Data Terminal Ready (DTR) is looped back to Data Set Ready and Carrier Detect on both computers. When the Data Terminal Ready is asserted active, then the Data Set Ready and Carrier Detect immediately become active. At this point, the computer thinks the Virtual Modem to which it is connected is ready and has detected the carrier of the other modem.

All left to worry about now is the Request to Send and Clear To Send. As both computers communicate together at the same speed, flow control is not needed thus these two lines are also linked together on each computer. When the computer wishes to send data, it asserts the Request to Send high and as it is hooked together with the Clear to Send, It immediately gets a reply that it is ok to send and does so. The Ring indicator line is only used to tell the computer that there is a ringing signal on the phone line. As we do not have, a modem connected to the phone line this is left disconnected

To know about the RS232 ports available in your computer, Right click on \Computer\In that you will find 'Communication Port(Com1)' etc. If you right click on that and go to properties, you will get device status. Make sure that you have enabled the port( Use this port is selected).

How to program the Serial Port using C/C++?

There are two popular methods of sending data to or from the serial port in Turbo C. One is using outportb(PORT_ID, DATA) or outport(PORT_ID,DATA) defined in “dos.h”. Another method is using bioscom() function defined in “bios.h”. Using outportb() : The function outportb () sends a data byte to the port ?PORT_ID?. The function outport() sends a data word. These functions can be used for any port including serial port, parallel ports. Similarly to receive data these are used. · inport reads a word from a hardware port ·inportb reads a byte from a hardware port ·outport outputs a word to a hardware port

·outportb outputs a byte to a hardware port Declaration:

· int inport(int portid);

·unsigned char inportb(int portid); ·void outport(int portid, int value);

·void outportb(int portid, unsigned char value); Remarks:

·inport works just like the 80x86 instruction IN. It reads the low byte of a word from portid, the high byte from portid + 2. ·inportb is a macro that reads a byte

·outport works just like the 80x86 instruction OUT. It writes the low byte of value to portid, the high byte to portid + 1.

·outportb is a macro that writes value Argument portid: ·Inport- port that inport and inportb read from; ·Outport- port that outport and outportb write to value: ·Word that outport writes to portid; ·Byte- that outportb writes to portid.

If you call inportb or outportb when dos.h has been included, they are treated as macros that expand to inline code.

If you don't include dos.h, or if you do include dos.h and #undef the macro(s), you get the function(s) of the same name.

Return Value:

# inport and inportb return the value read # outport and outportb do not return

For more details of these functions read article from beondlogic.com Using bioscom: The macro bioscom () and function _bios_serialcom() are used in this method in the serial communication using RS-232 connecter. First we have to set the port with the settings depending on our need and availability. In this method, same function is used to make the settings using control word, to send data to the port and