Using External Files under Windows |
You can read data directly from the communications (serial) port on your machine. To set the serial communications parameters, use the port configuration tools in the Windows Control Panel to set up the communications port. The communications parameters you specify are specific to each data collection device.
After you invoke SAS, 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 SAS encounters an end-of-file (the hexadecimal 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 Function: Windows and WAKEUP Function: Windows.
Communications Port Timeouts |
By default, if you are reading from a communications port and a timeout occurs, an end-of-file (EOF) is returned to the program. You can specify how communications port timeouts are handled by using the COMTIMEOUT= option. The COMTIMEOUT= option is valid in the FILENAME statement and must be used in conjunction with the COMMPORT device-type keyword in the FILENAME statement.
The COMTIMEOUT= option accepts the following values:
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 eof=eof; input @; eof: 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.
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.