Chapter Contents

Previous

Next
SAS Companion for the OS/2 Environment

Reading Data from the Communications Port

You can read data directly from the communications (serial) port on your machine. To set the serial communications parameters, use the port configuration tools that are in the OS/2 Workplace Shell to set up the communications port. The communications parameters that you specify are specific to each data collection device.

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 that 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 by 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 character (the hexadecimal value of the end-of-file character 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 functions that are useful in data acquisition applications are SLEEP and WAKEUP. These functions enable you to control when your program begins to execute. For example, you can use the WAKEUP function to cause your program to begin executing at exactly 2:00 a.m. For more information on these two functions, see SLEEP and WAKEUP.


Communications Port Timeouts

By default, if you are reading from a communications port and a timeout occurs, an end-of-file (EOF) character 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:
EOF returns an end-of-file character 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 returns a record length of 0 bytes when a timeout occurs. However, the DATA step does not terminate; it simply tries to read data again.

Here is an example of a FILENAME statement that specifies 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.
RTIMEOUT sets the wait on a read timeout in units of 0.01 second. A value of 100 means 1 second.
WTIMEOUT sets the write timeout in units of 0.01 second. A value of 100 means 1 second; a value of 0 means it waits forever.


Reading Data Using DataMyte Processing

The SAS System under Windows supports DataMyte data collection devices through three SAS functions and one CALL routine. These functions are the DMYTECHC, DMYTECWD, and CMYTERVC functions. The CALL routine is DMYTECKS. These functions and the CALL routine are described in SAS Functions under OS/2 and SAS CALL Routines under OS/2.

A full discussion of DataMyte processing is beyond the scope of this book; this section covers only the main points. A DataMyte is a data collection device that you attach to your communications port. The DataMyte device is typically used to interface with precision instruments in industrial and factory applications.

You can send data to and request data from the DataMyte device. A chunk of data that are passed at one time is called a packet. Each packet can be up to 255 characters long and can consist of several components. Two of these components are used by the SAS functions that support DataMyte data collection:

The following additional components are mentioned in the discussion of the SAS functions that support DataMyte data collection:

For more information about DataMyte processing, see your DataMyte documentation.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.