1、TDTransmit Data (Serial data output)74RTSRequest to send (acknowledge to modem that UART is ready to exchange data85CTSClear to send (i.e.; modem is ready to exchange data)6DSRData ready state (UART establishes a link)SGSignal ground1DCDData Carrier detect (This line is active when modem detects a c
2、arrier20DTRData Terminal Ready.922RIRing Indicator (Becomes active when modem detects ringing signal from PSTNAbout 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
3、 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 speed
4、s. 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.Most people today will have 28.8K or 33.6K modems. Therefore, w
5、e 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 spe
6、ed 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
7、 than the modems 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 DTEs together. This is used to transfer files between the computers using pro
8、tocols like Zmodem protocol, xmodem protocol, etc Figure :Above shows the connections of the Null modem using RS-232D connecterAbove-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 comput
9、er. 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 signalground (SG) line of the both must be shorted so that grounds are com
10、mon 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 whi
11、ch 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 bothcomputers communicate together at the same speed, flow control is not needed thus these two lines are also linked together on each computer. When t
12、he 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
13、 not have, a modem connected to the phone line this is left disconnectedTo know about the RS232 ports available in your computer, Right click on My Computer, Goto Properties, Select tab Device Manager, go to Ports( COM & LPT ),In that you will find Communication Port(Com1) etc. If you right click on
14、 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(
15、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
16、. 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
17、 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
18、 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 yo
19、u call inportb or outportb when dos.h has been included, they are treated as macros that expand to inline code.If you dont 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
20、 outportb do not returnFor more details of these functions read article from 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 availab
21、ility. In this method, same function is used to make the settings using control word, to send data to the port and check the status of the port. These actions are distinguished using the first parameter of the function. Along with that we are sending data and the port to be used to communicate.Here
22、are the deatails of the Turbo C Functions for communication ports.Declaration:bioscom(int cmd, char abyte, int port)_bios_serialcom(int cmd ,int port, char abyte)bioscom() and _bios_serialcom() uses the bios interrupt 0x14 to perform various communicate the serial communication over the I/O ports gi
23、ven in port.cmd: The I/O operation to be performed.cmd (boiscom)cmd(_bios_serialcom)Action_COM_INITInitialise the parameters to the port_COM_SENDSend the character to the port_COM_RECEIVEReceive character from the port_COM_STATUSReturnsrhecurrentstatusofthe communication portportid: port to which da
24、ta is to be sent or from which data is to be read. 0: COM11: COM22: COM3abyte:When cmd =2 or 3 (_COM_SEND or _COM_RECEIVE) parameter abyte is ignored.When cmd = 0 (_COM_INIT), abyte is an OR combination of the following bits (One from each group):value of abyteMeaningBioscom_bios_serialcom0x020x03_C
25、OM_CHR7_COM_CHR87 data bits8 data bits0x000x04_COM_STOP1_COM_STOP21 stop bit2 stop bits0x080X10_COM_NOPARITY_COM_ODDPARITY_COM_EVENPARITYNo parity Odd parity Even parity0x200x400x600x800xA00xC00xE0_COM_110_COM_150_COM_300_COM_600_COM_1200_COM_2400_COM_4800_COM_9600110 baud150 baud300 baud600 baud120
26、0 baud2400 baud4800 baud9600 baudFor example, if abyte = 0x8B = (0x80 | 0x08 | 0x00 | 0x03) = (_COM_1200 | COM_ODDPARITY | _COM_STOP1 | _COM_CHR8)he communications port is set to 1200 baud(0x80 = _COM_1200)Odd parity (0x08 = _COM_ODDPARITY) 1 stop bit (0x00 = _COM_STOP1)8 data bits (0x03 = _COM_CHR8)To initialise the port with above settings we have to write bioscom(0, 0x8B, 0); To send a data to COM1, the format of the function will be bioscom(1, data, 0). Similarly biosco