Listing 1 TICK1.CPP

#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <time.h>

#define RACK 1

#define ERR if (*err<0))   \
   printf("\nError No. %d, \
   Address No. %d,        \
   Command No. %d", *err, \
   *add, *com);

int near *err; //ptr to error return
int near *add; //ptr to optomux address
int near *com; //ptr to optomux command

//pointers to module position in optomux rack,
//modifier array, and data return array:
int near modu[16], modi[2], dat[16];

//initialize rack and variables
void ints(void);

//read inputs
void read_modules(void);

//call the driver
extern "C" void pascal
  optoware(int near*, int near*, int near*,
         int near*, int near*, int near*);
// driver
main()
{
int count = 0; //value of scans ctr

//clock ticks at current scan
clock_t curr_time = 0;

//clock ticks at first scan
clock_t start_time = 0;

clrscr();
inits(); // ready sys for startup

//clock ticks at initial scan
start_time = clock();

//loop through 5000 reads
while (count < 5000 && !kbhit()){
   read_size();
   curr_time = clock(); //clk ticks now
   count+= 1; // clock ticks now
   }
clrscr();
gotoxy(22, 2);
printf( "Total ticks for 5000 reads..%ld",
   curr_time-start_time);
if (kbhit()) // loop early exit
   {
   clrscr();
   gotoxy(22, 10);
   printf("Oops, you hit the ");
   printf("boo boo bye bye key!");
   gotoxy(1, 1)
   }
return 0; // end of function main
}

/********************************/
// ready system for operation
void inits(void)
{
int i; // array variable index
//array variable indexes
int er = 0, cmd = 102;
int ad = 0; // host address

err= &er;
add = &ad;
com = &cmd;
dat[0] = 3; // set host to com3

//call driver
optoware(err, add, com, modu, modi, dat);
ERR        // error macro

// set host baud rate to 38400
cmd= 104;
dat[0]= 38400;
optoware(err, add, com, modu, modi, dat);
ERR

//initialize optoware parameters
for (i=0; i<=15; ++i){
   modu[i] = 0;
   dat[i] = 0;
   }

modi[0] = 0;
modi[1] = 0;
cmd = 0; //disable power-up clear msg.
add = RACK; // for optomux rack
er= 0;
optoware(err, add, com, modu, modi, dat);
ERR

return;
}
/*******************************/
void read_modules(void)
{
int ad_size = RACK; // at address RACK

int s_cmd = 12; // 12 is command to read

// reset any previous errors
int s_err = 0;

// point globals to locals
add = &ad_size;
com = &s_cmd;
err = &s_err;

optoware(err, add, com, modu, modi, dat);
ERR

// For anyone curious to know, this program
// indicates about 5.65 millisecond per scan
return;
}
// End of File