From:	SMTP%"David@tcs01.demon.co.uk" 26-MAY-1993 11:58:32.50
To:	EVERHART
CC:	
Subj:	Reading OPCOM messages on an LTA device

X-Newsgroups: comp.os.vms
Subject: Reading OPCOM messages on an LTA device
Message-Id: <738355514snz@tcs01.demon.co.uk>
From: david@tcs01.demon.co.uk (David James)
Date: 25 May 93 18:45:14 GMT
Reply-To: David@tcs01.demon.co.uk
Sender: usenet@demon.co.uk
Organization: DIS(organised)
X-Newsreader: Simple NEWS 1.90 (ka9q DIS 1.21)
Lines: 168
To: Info-VAX@kl.sri.com
X-Gateway-Source-Info: USENET

I am running a plant control system. It is a 24 hour a day 7 days a week 
operation without system operators. I want to be able to intercept messages 
from OPCOM so that I can look for ones of specific interest and then pass 
them on to the application running on the system so that it can notify the
plant operators through their normal user interface rather then them having
to understand VMS (operator) commands.

I could use DCM (Data Centre Monitor - or whatever it is called in its latest
incarnation) but that is a rather large sledge hammer to crack this small
nut.

So what I am doing is telling OPCOM to write messages to one port on a 
terminal server which I then have connected back to another terminal server
port on which a little C program is running to read the messages (and 
eventually process them and pass them on to the plant control application).

My problem is that I don't manage to read all of the message - I seem to 
lose the last white-space (plus, maybe, dollar sign) delimited word from
the text that OPCOM puts out.

It must be a stupid error - can anyone suggest what it is.  The program 
follows:

/* 
   This program reads OPCOM messages. It runs on a node called COMIS.
    
   The OPCOM messages are read from port LTA991: on the terminal server COCTS2.
   LTLOAD.COM has done:-
   CREATE PORT LTA991:
   SET PORT LTA991: /NODE=COCTS2 /PORT=PORT_6

   LTLOAD has also done:-
   CREATE PORT LTA990:
   SET PORT LTA990: /NODE=COCTS2 /PORT=PORT_5

   and we've done:-
   $DEFINE/USER SYS$COMMAND LTA990:
   $REPLY/ENABLE
   to get OPCOM to write OPCOM messages out of LTA990:

   On the terminal server ports 5 and 6 are linked by a simple null-modem 
   cable.

   The intention is to pass selected messages on to the application that the
   plant operators are running so that they can see the important OPCOM
   messages on their normal terminals rather than on an operator terminal.

=============================================================================

   This version uses UNIX I/O on the LTA device (open and read):  I find that
   things work fine, except that I lose the last part of the last line of 
   each OPCOM message, for example, 
   if I do a
   $REQUEST 
   this program reads "_COMIS$"
   if I do a 
   $REQUEST test
   this program reads "_COMIS$LTA1167:, "
   if I do a 
   $REQUEST "test message"
   this program reads "_COMIS$LTA1167:, test "
   If I do a
   $REQUEST "test message 2"
   this program reads "_COMIS$LTA1167:, test message "

   A version using Standard I/O (fopen and fgets) behaves in the same way.

=============================================================================

*/

#include unixio
#include file
#include descrip
#include errno.h
#include iodef.h

#define NIL 0
#define MAXBUF 255

unsigned short LTAchannel;



main(int argc, char **argv)
{
   int numchar;
   int status;
   int done;
   int fd;
   char buf[MAXBUF];
   $DESCRIPTOR(st,buf);
   $DESCRIPTOR(LTADSC,"LTA991:");
   unsigned short LTA_QIOiosb[4];

   FILE *knownfile, *discardfile, *unknownfile;


   printf("Starting\n");

/* Assign a channel to the LTA device.*/

   if (!((status = sys$assign(&LTADSC, &LTAchannel, 0, 0)) & 1))
   {
      printf("Error assigning channel to the LTA device.\n");
      lib$signal(status);
   }
   printf("sys$assign status %d, channel %d\n",status, LTAchannel);

/* Cause the LTA device to be connected to the server and port that were
   specified by LTLOAD.COM */

   if (!((status = sys$qiow(0, LTAchannel,
                            IO$_TTY_PORT|IO$M_LT_CONNECT,
                            &LTA_QIOiosb,
                            0, 0, 0, 0, 0, 0, 0, 0)) & 1))
   {
      printf("Error connecting to the server.\n");
      lib$signal(status);
   }
   printf("sys$qiow connect status %d\n",status);

/* Open the LTA device. */

   fd = open("LTA991:", O_RDONLY,0);



/* Read input from the LTA device ... */

   status = 1;
   while (status > 0)
   {
      printf("Waiting for input ...\n");
      status = read(fd,buf,MAXBUF);
      numchar = status;
      if (numchar > 0)
      {

/* what we really want to do now is to look to see if this is a message that we
   are interested in, and if so pass it on to the control application, for now
   just print it out so that we can see what is happening.*/

         printf("\nLine of %d characters read\n",numchar);
         if (buf[numchar-1] = 10)
         {
            numchar = numchar-1;
         }
         buf[numchar] = 0;
         st.dsc$w_length = numchar;
   
         printf("\nLine of %d characters read\n",numchar);
         printf("line was |%s|\n",buf);

      }
      else
         perror("read");
   }

/* Let image exit close down the connection to the LTA device. */

} /* of main */

/*--------------------------------------------------------------------*/

-- 
David James
david@tcs01.demon.co.uk

