home *** CD-ROM | disk | FTP | other *** search
- /* TTY.c
- a very simple sample terminal application. It demonstrates
- the basics in the use of the Windows Comm functions. It also
- shows the basic structure for a terminal program.
-
- */
-
- The TTY program is designed to demonstrate the basics of using the
- Windows Communications functions. This demonstration is in the form
- of a simple tty terminal program.
-
- The general procedure used for performing communications with these
- functions is:
- 1. Call OpenComm to open the communications port.
- 2. Call SetCommState to set the baud rate, parity, and other
- communications parameters.
- 3. Call WriteComm to transmit characters to another computer or device.
- 4. Call ReadComm to read characters that have been received from
- another computer or device.
- 5. Call CloseComm to close the communications port.
-
- Before you start working with the communications functions, it is
- recommended that you read a reference on this subject, so that you
- understand the terms and hardware issues involved. The MS-DOS Encyclopedia,
- published by Microsoft Press, contains a good discussion of the hardware
- and general communications ideas, and describes the creation of a device
- driver for serial communications. Another source is "Communications and
- Networking for the IBM PC & Compatibles" by Larry Jordan and Brucde
- Churchill, published by Brady.
-
- Below are descriptions of the communications functions:
-
- BuildCommDCB Fills a device control block (DCB) with control codes.
- The DCB is passed to the SetCommState function to set
- the various parameters of the port. BuildCommDCB
- provides a convenient way to set the fields of the DCB,
- using a parameter string, similar to the one used for
- the DOS Mode command. This function isn't required, and
- doesn't replace the SetCommState function. The fields of
- the DCB can be set with normal C commands. Some fields,
- such as the flow control flags and Xon/Xoff characters,
- default to zero, and are not set by BuildCommDCB. They
- must be set directly using C.
-
- ClearCommBreak Clears the communication break state from a communcation
- device. This function is used with the SetCommBreak
- function. To issue a break to a device, you call
- SetCommBreak, wait for a certain period of time, and
- call ClearCommBreak.
-
- CloseComm Closes a communication device after transmitting the
- current buffer. You must close the port when you are
- finished using it. No other application will be able to
- access the port while it is opened. The port isn't closed
- automatically, when the application quits.
-
- FlushComm Flushes characters from a communication device. If you call
- this function while characters are still in the queue,
- those characters will be lost.
-
- GetCommError Fills a ComStat buffer with the communication status. If
- one of the communication I/O function returns an error,
- this function should be called to determine the cause of
- the error and clear the error state. I/O will not continue
- until the error state is cleared.
-
- GetCommEventMask Retrieves, and then clears an event mask.
-
- GetCommState Fills a DCB buffer with the current device control block.
- This is used to return the values of the parameters
- currently being used.
-
- OpenComm Opens a communication device.