|
Serial Data Captured |
Need to record data being sent over an asynchronous serial line? Here's a program that lets you store a data transmission to a fileSeveral years ago Frank Lees contributed a program useful for capturing characters sent to a Unix system over an asynchronous serial line. I decided to update the program to add POSIX support and a time-out feature designed with help from Ray Swartz. With this program, you can upload files to a Unix system using error-correcting modems and any terminal emulation program that can read or transmit files. Dear Editor: I use the upload C program [see Part A of the Listing] on my Unix system to capture files sent from PCs, intelligent terminals, or data-recording devices. It reads standard input and writes to a file, terminating when there is no input for a specified time, or 10 seconds by default. The Unix system asynchronous serial device driver is placed in ``raw'' mode so all characters can be collected without change. By default, Control-M and Control-Z characters are not stored in the output file but can be stored if so desired. To upload a file using a communication program from another system, first invoke upload on the destination machine so it will begin storing characters that it reads from the serial port that is used for communication with the source system. Next request that the source system send the contents of the desired file through the communication port to the destination system. The upload program will ``time out'' after all the data has been transferred, finally closing the output file and restoring the original serial driver modes before exiting. You must specify an argument on the Several options can be used to modify the default actions.
Specify Normally, if no characters are received for 10 seconds,
This program performs no error detection or correction.
You'll have to rely on underlying protocols to provide error-free
transmission. I developed Usage Notes. Ensure that your Unix system input
buffer doesn't overflow. The You'll want to use binary mode to store all eight bits of every
character received, which is necessary for compiled programs or 8-bit
data. If the sending system includes parity bits when they
send 7-bit data, they will be stored as the most significant bit
in the output file. If you want to upload all characters of a
text file, including Control-M's and Control-Z's, specify the
Some of you may wonder: Why bother with Implementation Notes. As usual the program starts
with constant definitions and variable declarations. However,
provision has been made for portability between two major ways to
control serial drivers--the POSIX ``termios'' structure and the
System V ``termio'' structure-by using ``pound define''
constructs to select between two groups of definitions,
declarations, and header-file ``include'' directives. Lines 2-5
will be compiled if Line 7 defines Line 79 rounds up the user-specified quit-time value to the
next highest multiple of 10. On line 98 we open the output file
so that if the file already exists, an error is returned. This
approach prevents overwriting of data on the destination system
disk. Part C shows one way to change
the POSIX provides a portable approach to get and set the modes of
an asynchronous serial driver. The implementation-specific
Serial-driver parameters are manipulated through a data
structure. POSIX uses a structure named ``termios'' [Part D of the Listing], which is
virtually identical to its predecessor, ``termio'' [Part E]. The primary difference is that
``termios'' doesn't include the ``termio'' line-discipline
member, Two nested loops do the work. The outer ``while''loop (Part A, lines 141-154) determines how long the program idles after the last character has been received. Each iteration of that loop decrements a loop count- which was originally set by line 140-to one-tenth the quit-time value. When this loop exits, the output file is closed, the serial-line I/O modes reset to their original values, and the program terminates after an end-of-transfer message is displayed for the operator. Each iteration of the inner loop [lines 142-153] reads a
character and then tests whether it's to be written to the output
file. Lines 146-147 perform several tests separated by the
logical OR ( If no input character is available, the ``read'' call [line
142] won't be satisfied (will return control to the calling
program) until the basic time-out period (10 seconds) has
expired. This circumstance arises by using ``noncanonical mode''
(by disabling the Every time a character is read, the outer loop-count value is reset by line 152. This way, after the last character is read, the total quit time will have the correct value. This operation doesn't seem to slow down the loop enough to effect data transmission, even at 9,600 bits per second. We're looking for readers who have the inclination, time, and resources to help us test ``Wizard's Grabbag'' contributions. This way we can provide a more portable program for our readers. In particular, interested readers who have access to one or more of the following Unix implementations: SCO Xenix 2.3.2, SCO Unix 3.2.x, DECstation Ultrix 4.1, or HP 700 HP-UX 8.07 should contact me via e-mail. |
Print This Page Send as e-mail |












