Andrew Bedno    Andrew@Bedno.com • 773-442-2386
 History   Kudos   Samples 

Cobol
1992
Cobol (click for next photo)

Serial Communications Utilities

Utilities for communicating with serial devices from Cobol.
Also download my library of Cobol utility routines.

000000* 92.03.17 AIB - Pass through device support for Cobol.
000000*
000000* This is a general purpose direct to device communications
000000* communications module.  It opens separate in and out channels
000000* to eliminate character loss during turn around.
000000* It automatically supports direct to device or pass through use.
000000* Pass through mode is used if the device name is "PASS" or
000000* "/dev/tty" or "/DEV/TTY", otherwise pass though sequences,
000000* even if they have been set for the terminal, are not sent.
000000* Typically, and pthru calls will be ordered as follows:
000000*     PTHRU-OPEN
000000*     PTHRU-INIT
000000*     PTHRU-READ/PTHRU-WRITE
000000*     PTHRU-RESET
000000*     PTHRU-CLOSE
000000* For use other than pass through, the application must set
000000*  PTHRU-DEV-NAME as desired.
000000* An optional log records all serial communications for debugging.
000000* Place a /X on the command line to enable the log.
000000* PTHRU-READ requires the PTHRU-READ-LEN variable to be set to the
000000* required length of the incoming text.
000000* For strings which may not terminate at a fixed length,
000000* create a PTHRU-READ-DONE-CHECK procedure which sets
000000* the PTHRU-READ-DONE variable to "Y" when the receive is finished.
000000* This procedure is called once for every character received
000000* by PTHRU-READ.  A dummy procedure must be created if this
000000* feature is not used.
000000* Section names have been omitted, as it is expected that this code
000000* may be pasted into a larger parent application.
000000
000000 01 PTHRU-IN-FILE-NAME. 
000000     05 FILLER                   PIC X(03) VALUE "-D ". 
000000     05 PTHRU-IN-DEV-NAME        PIC X(32) VALUE SPACES. 
000000 01 PTHRU-OUT-FILE-NAME. 
000000     05 FILLER                   PIC X(03) VALUE "-D ". 
000000     05 PTHRU-OUT-DEV-NAME       PIC X(32) VALUE SPACES. 
000000 01 PTHRU-LOG-FILE-NAME. 
000000     05 FILLER                   PIC X(9) VALUE "PTHRU.LOG".
000000 01 PTHRU-DEV-NAME               PIC X(32) VALUE "/dev/tty".
000000 01 PTHRU-IN-FILE-STATUS         PIC X(02) VALUE SPACES. 
000000 01 PTHRU-OUT-FILE-STATUS        PIC X(02) VALUE SPACES. 
000000 01 PTHRU-LOG-FILE-STATUS        PIC X(02) VALUE SPACES. 
000000 01 PTHRU-RECORD-LOG             PIC X(1) VALUE "N".
000000 01 PTHRU-WRITE-LEN              PIC 99 VALUE ZERO.
000000 01 PTHRU-READ-LEN               PIC 99 VALUE ZERO.
000000 01 PTHRU-LEN-LOOP               PIC 99 VALUE ZERO.
000000 01 PTHRU-READ-DONE              PIC X VALUE "N".
000000 01 PTHRU-BUF.
000000     05 PTHRU-BUFFER             PIC X(40).
000000     05 PTHRU-BUF-ARR REDEFINES PTHRU-BUFFER
000000            PIC X OCCURS 40 TIMES.
000000 01 PTHRU-INIT-SEQUENCE          PIC X(30).
000000 01 PTHRU-RESET-SEQUENCE         PIC X(30).
000000 01 PTHRU-OPEN-OK                PIC X VALUE "N".
000000
000000 FD PTHRU-IN-FILE 
000000     DATA RECORD IS PTHRU-IN-CHAR.
000000 01 PTHRU-IN-CHAR                 PIC X.
000000
000000 FD PTHRU-OUT-FILE 
000000     DATA RECORD IS PTHRU-OUT-CHAR.
000000 01 PTHRU-OUT-CHAR                PIC X.
000000
000000 FD PTHRU-LOG-FILE 
000000     DATA RECORD IS PTHRU-LOG-CHAR.
000000 01 PTHRU-LOG-CHAR                PIC X.
000000
000000     SELECT PTHRU-IN-FILE 
000000         ASSIGN TO PTHRU-IN-FILE-NAME
000000         ORGANIZATION IS BINARY SEQUENTIAL
000000         FILE STATUS IS PTHRU-IN-FILE-STATUS. 
000000
000000     SELECT PTHRU-OUT-FILE 
000000         ASSIGN TO PTHRU-OUT-FILE-NAME
000000         ORGANIZATION IS BINARY SEQUENTIAL
000000         FILE STATUS IS PTHRU-OUT-FILE-STATUS. 
000000
000000     SELECT PTHRU-LOG-FILE 
000000         ASSIGN TO PTHRU-LOG-FILE-NAME
000000         ORGANIZATION IS BINARY SEQUENTIAL
000000         FILE STATUS IS PTHRU-LOG-FILE-STATUS. 
000000
000000 PTHRU-UTILITIES SECTION.
000000
000000* Open/close for each character forces buffer flush.
000000* Recording enabled by /X switch.
000000 PTHRU-LOG.
000000     IF ( PTHRU-RECORD-LOG = "Y" ) AND
000000        ( PTHRU-LOG-FILE-STATUS = I-O-OK )
000000       OPEN EXTEND PTHRU-LOG-FILE
000000       IF PTHRU-LOG-FILE-STATUS = I-O-OK
000000         WRITE PTHRU-LOG-CHAR
000000         CLOSE PTHRU-LOG-FILE
000000       END-IF
000000     END-IF.
000000
000000 PTHRU-INIT.
000000     IF PTHRU-OUT-DEV-NAME = "/dev/tty"
000000       MOVE SPACES TO PTHRU-BUFFER
000000       MOVE PTHRU-INIT-SEQUENCE TO PTHRU-BUFFER
000000       PERFORM PTHRU-WRITE.
000000
000000 PTHRU-RESET.
000000     IF PTHRU-OUT-DEV-NAME = "/dev/tty"
000000       MOVE SPACES TO PTHRU-BUFFER
000000       MOVE PTHRU-RESET-SEQUENCE TO PTHRU-BUFFER
000000       PERFORM PTHRU-WRITE.
000000
000000 PTHRU-OPEN.
000000     IF ( PTHRU-DEV-NAME = "PASS" ) OR
000000        ( PTHRU-DEV-NAME = "/DEV/TTY" )
000000       MOVE "/dev/tty" TO PTHRU-IN-DEV-NAME
000000     ELSE
000000       MOVE PTHRU-DEV-NAME TO PTHRU-IN-DEV-NAME.
000000     MOVE PTHRU-IN-DEV-NAME TO PTHRU-OUT-DEV-NAME.
000000     PERFORM PTHRU-READ-CONFIG.
000000     OPEN INPUT PTHRU-IN-FILE. 
000000     OPEN OUTPUT PTHRU-OUT-FILE. 
000000     IF ( PTHRU-IN-FILE-STATUS = I-O-OK ) AND
000000        ( PTHRU-OUT-FILE-STATUS = I-O-OK )
000000       MOVE "Y" TO PTHRU-OPEN-OK.
000000
000000 PTHRU-CLOSE. 
000000     CLOSE PTHRU-IN-FILE. 
000000     CLOSE PTHRU-OUT-FILE. 
000000
000000 PTHRU-WRITE.
000000* Determine length then write one character at a time.
000000     MOVE 0 TO PTHRU-WRITE-LEN.
000000     PERFORM VARYING PTHRU-LEN-LOOP FROM 1 BY 1
000000     UNTIL PTHRU-LEN-LOOP > 40
000000         IF ( PTHRU-BUF-ARR( PTHRU-LEN-LOOP ) NOT = " " ) AND
000000            ( PTHRU-BUF-ARR( PTHRU-LEN-LOOP ) NOT = LOW-VALUE )
000000           MOVE PTHRU-LEN-LOOP TO PTHRU-WRITE-LEN
000000         END-IF
000000     END-PERFORM.
000000     MOVE x"0A" TO PTHRU-LOG-CHAR.
000000     PERFORM PTHRU-LOG.
000000     MOVE "-" TO PTHRU-LOG-CHAR.
000000     PERFORM PTHRU-LOG.
000000     MOVE ">" TO PTHRU-LOG-CHAR.
000000     PERFORM PTHRU-LOG.
000000     MOVE " " TO PTHRU-LOG-CHAR.
000000     PERFORM PTHRU-LOG.
000000     PERFORM VARYING PTHRU-LEN-LOOP FROM 1 BY 1
000000     UNTIL PTHRU-LEN-LOOP > PTHRU-WRITE-LEN
000000         MOVE PTHRU-BUF-ARR( PTHRU-LEN-LOOP ) TO PTHRU-OUT-CHAR
000000         WRITE PTHRU-OUT-CHAR 
000000         MOVE PTHRU-OUT-CHAR TO PTHRU-LOG-CHAR
000000         PERFORM PTHRU-LOG
000000     END-PERFORM.
000000
000000 PTHRU-READ. 
000000     MOVE SPACES TO PTHRU-BUFFER.
000000     MOVE "N" TO PTHRU-READ-DONE.
000000     MOVE x"0A" TO PTHRU-LOG-CHAR.
000000     PERFORM PTHRU-LOG.
000000     MOVE "<" TO PTHRU-LOG-CHAR.
000000     PERFORM PTHRU-LOG.
000000     MOVE "-" TO PTHRU-LOG-CHAR.
000000     PERFORM PTHRU-LOG.
000000     MOVE " " TO PTHRU-LOG-CHAR.
000000     PERFORM PTHRU-LOG.
000000     PERFORM VARYING PTHRU-LEN-LOOP FROM 1 BY 1
000000     UNTIL ( PTHRU-LEN-LOOP > PTHRU-READ-LEN ) OR
000000           ( PTHRU-READ-DONE = "Y" )
000000         READ PTHRU-IN-FILE
000000         MOVE PTHRU-IN-CHAR TO PTHRU-LOG-CHAR
000000         PERFORM PTHRU-LOG
000000         PERFORM PTHRU-READ-DONE-CHECK
000000         IF PTHRU-READ-DONE NOT = "Y"
000000             MOVE PTHRU-IN-CHAR TO PTHRU-BUF-ARR( PTHRU-LEN-LOOP )
000000         END-IF
000000     END-PERFORM.
000000
000000 PTHRU-CONFIG.
000000* Setup terminal pass through seq here.
000000     IF ( RM-LINK-SWITCH-1 = "X" ) OR
000000        ( RM-LINK-SWITCH-2 = "X" ) OR
000000        ( RM-LINK-SWITCH-3 = "X" )
000000       OPEN EXTEND PTHRU-LOG-FILE
000000       IF PTHRU-LOG-FILE-STATUS NOT = I-O-OK
000000         OPEN OUTPUT PTHRU-LOG-FILE
000000       END-IF
000000       IF PTHRU-LOG-FILE-STATUS = I-O-OK
000000         CLOSE PTHRU-LOG-FILE
000000       END-IF
000000     END-IF.
000000     MOVE ?????? TO PTHRU-INIT-SEQUENCE.
000000     MOVE ?????? TO PTHRU-RESET-SEQUENCE.
000000
000000 PTHRU-UTILITIES-EXIT.
000000     EXIT.


 DOWNLOAD         < NEWER    OLDER >