15 01 KVOKMKDZU2W2MCRU5YBCWK4VSJTRJRDEGXEL6RI




Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Serial Communication
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6! (Publisher: The Coriolis Group) Author(s): Peter G. Aitken ISBN: 1576102815 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




Chapter 15Serial Communication


The Visual Basic Comm control makes it easy for your Visual Basic programs to communicate over serial connections.
It’s a rare computer that operates in total isolation these days. Even computers that are not a part of a local area network frequently communicate with other computers to exchange data files, programs, and electronic mail. Most people who access CompuServe, America Online, or the Internet do so with serial communication (via a modem). If you need to transfer that 15MB data file from one computer to another, you’ll find that setting up a serial link is much easier than shuffling floppy diskettes for an hour.
Serial communication has many uses that most of us never even consider. Some high-end pen plotters—the kind used to create architectural drawings—require a serial link to the controlling computer. Many laboratory instruments and industrial components are controlled via a serial link. All in all, it’s a topic you should know something about—if only the basics.
Serial Communication Fundamentals
Serial communication is called serial, because the individual bits of data follow each other over the same electrical connection. It contrasts with parallel communication, where multiple connections enable the link to carry more than one bit at a time (for example, your printer port). Serial communication is bi-directional, meaning that data flows in both directions: from computer A to computer B, and from B to A.
Serial communication is carried out by means of a serial port on your computer. Serial ports have many names, including COM ports, RS-232 ports, and asynchronous communication ports. Whatever the moniker, it refers to the same piece of hardware. In theory, a serial link requires only three wires: one wire for the data going out, one for the data coming in, and a ground wire. If you look at the serial ports on the back of your computer, however, you’ll find that the physical connection is either a 9-pin D shell on newer models or a 25-pin D shell on older systems. Why all the extra connections? Many of the pins remain unused in the 25-pin serial connection. On the other hand, many more than three lines are employed in most serial connections. These “extra” lines do not carry data; they are used for handshaking signals. The computers on the two ends of the serial link use hand-shaking signals to coordinate their actions.
Of course, you can use serial communication for much more than linking one computer to another. It can also link a computer to a modem, mouse, plotter, and printer, to mention just a few. No matter which two devices are involved in a serial link, however, certain things remain constant. Serial communication standards ensure that all serial ports follow the same rules. Within this set of rules, however, is some room for flexibility. You can control how fast data is sent over the serial link, and you can control certain aspects of the data format. These settings are called communication parameters For serial communication to operate properly, the devices at both ends of the link must use the same parameters.

TIP:  Making The Serial Connection
If you want to connect two computers by means of their serial ports, you must use a null modem. This is a serial cable in which the send and receive lines are crossed, so that one computer’s send line is connected to the other computer’s receive line.


Serial Communication Parameters
Perhaps the most important parameter is the baud rate, which determines the speed at which data is transmitted. The baud rate is approximately equal to the number of bits transmitted per second. Serial port hardware supports a variety of standard baud rates, ranging from the totally obsolete and horridly slow 110 baud to more than 100,000 baud. Note that the baud rates supported by your serial port may differ from those supported by your modem.
Another parameter is the word length, which specifies the number of bits that make up each unit of data transmitted. While serial hardware can support word lengths of five to eight bits, PCs always work with word lengths of seven or eight bits.
The parity parameter determines whether a parity bit is added to each word. A parity bit enables the serial port hardware to detect certain kinds of errors in transmission. You can set parity to None, Odd, or Even. A setting of None does not add a parity bit. For Odd parity, the parity bit is set to zero or one, so that the total number of bits set to one in the data-word/parity-bit combination is odd. Even parity works the same way, but the total number of set bits is even. At the receiving end, the hardware looks at each data-word/parity-bit set to see if the proper number (even or odd) of bits is set. If a single bit has flipped because of a transmission error, the receiving hardware will detect the error and request that the word be re-sent.
The stop bit parameter specifies how many stop bits are used. In serial communication, start and stop bits delineate the beginning and end of each data word. One start bit is always used, and one or two stop bits can be used. Most PC communications use one stop bit.

TIP:  Serial Ports And Modems
One of the most common uses for serial ports is to connect a modem (even if your modem is internal, it is still logically connected to one of the system’s serial ports). Do you need to worry about that alphabet soup of modem protocols when programming a serial port? In a word, no. The various protocols that adorn modem advertisements (such as V.32bis and MNP5) have to do with transmission speeds, error correction protocols, and data compression standards. When you use a modem attached to a serial port (as we’ll do later in the chapter), you may send it commands specifying which of these protocols to use. The serial port is still just a serial port, however, and is treated the same, regardless of whether a modem, printer, or plotter is on the other end.








Previous
Table of Contents
Next








Wyszukiwarka

Podobne podstrony:
Wykład z Ch Organicznej 15 01 2013
500 złotych 15 01 1946
Programowanie zjazd VIII 15 01 2011
Zajęcia 15 01 10
RÓWNOWAGA FAZOWA w układach JEDNOSKŁADNIKOWYCH(15 01)
15 01 2012
E 12 X 15 01
instrukcja elektroniczny nadawca klient 5 0 1 15 01 2014 v08
PATOMORFOLOGIA, ĆWICZENIE 15, 16, 8 01 2013, 15 01 2013 Ćwiczenia sekcyjne
15 01
1000 złotych 15 01 1946
odpowiedzi do egzaminu 15 01 2008

więcej podobnych podstron