Chapter Contents |
Previous |
Next |
SAS Companion for the Microsoft Windows Environment |
After you invoke the SAS System, submit a FILENAME statement to associate a fileref with the communications port, as in the following example:
filename test commport "com1:";
This FILENAME statement defines the fileref TEST, uses the COMMPORT device-type keyword that specifies you are going to use a communications port, and specifies the COM1: reserved physical name.
Next, read the data from COM1: into a SAS data set using
the TEST fileref. The following DATA step reads in the data, 1 byte at a
time, until the SAS System encounters an end-of-file (the hex value of end-of-file
is
'1a'x
):
data acquire; infile test lrecl=1 recfm=f unbuffered; input i $; /* Read until you find an end-of-file. */ if i='1a'x then stop; run;
The communications port can be accessed multiple times. However, while multiple reads are allowed, only one user at a time can write to the port.
Two useful functions in data acquisition applications are SLEEP and WAKEUP. These functions enable you to control when your program is invoked. For example, you can use the WAKEUP function to start your program at exactly 2:00 a.m. For more information about these two functions, see SLEEP and WAKEUP.
Communications Port Timeouts |
The COMTIMEOUT= option accepts the following values:
EOF | returns an end-of-file when a timeout occurs. This is the default behavior. This causes the current DATA step to terminate. |
WAIT | instructs the communications port to wait forever for data. In other words, this value overrides the timeout. In this case, no record is returned to the DATA step until data are available. This can cause your program to go into an infinite loop, so use this value with caution. |
ZERO | does not wait if there is no incoming data. |
Here is an example of a FILENAME statement specifying that a record length of 0 bytes be returned to the program when a timeout occurs:
filename test commport "com1:" comtimeout=EOF; data test; infile test length=linelen recfm=F; input @; if linelen ne 0 then input value; else put 'Timeout reading from COM1:'; run;
Options that Relate to Communications Port Timeouts |
These options relate to the communications port timeouts.
RMULTI | specifies the multiplier, in milliseconds, that is used to calculate the total timeout period for read operations. For each read operation, this value is multiplied by the requested number of bytes to be read. |
RCONST | specifies the constant, in milliseconds, that is used to calculate the total timeout period for read operations. For each read operation, this value is added to the product of RMULTI and the requested number of bytes. |
WMULTI | specifies the multiplier, in milliseconds, that is used to calculate the total timeout period for write operations. For each write operation, this value is multiplied by the number of bytes to be written. |
WCONST | specifies the constant, in milliseconds, that is used to calculate the total timeout period for write operations. For each write operation, this value is added to the product of the WMULTI member and the number of bytes to be written. |
RINT | specifies the maximum time, in milliseconds, that is allowed to elapse between the arrival of two characters on the communications line. |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.