pattern.cpp

This example shows how you may write a data pattern to the Rulbus, using the general interface functions.

/*
 * pattern - write a data pattern to the Rulbus.
 */

#include "rulbus.h"             // header
#include <stdio.h>              // for fprintf()
#include <stdlib.h>             // for EXIT_SUCCESS
#include <conio.h>              // for kbhit()

int error() { return EXIT_FAILURE; }

int main()
{
   int32 pattern = 0x5E;        // test pattern
   int32 rack    = 0;           // rulbus rack number
   int32 addr    = 0;           // rulbus base address
   int32 offset  = 0x12;        // rulbus address offset
   int32 handle  = 0;           // handle to generic rulbus device
                                // open the generic rulbus device
   if ( RulbusDevice_open( &handle, "Rulbus-test-device" ) )
      return error();

   RulbusDevice_getRack   ( handle, &rack );
   RulbusDevice_getAddress( handle, &addr );

   fprintf( stdout, "Writing [%d:0x%02X] <- 0x%02X\n", rack, addr + offset, pattern );
   fprintf( stderr, "\nPress a key to stop..." );

   while( !kbhit() )            // write pattern until a key is pressed
      if ( 0 > RulbusDevice_putByte( handle, offset, pattern ) );
         return error();

   (void) getch();              // eat character

   if ( RulbusDevice_close( handle ) )
      return error();           // close the generic rulbus device

   return EXIT_SUCCESS;
}


Generated on Wed Apr 6 08:59:18 2005 for Rulbus Device Library for Microsoft Windows by doxygen 1.4.0