run-daccs2.cmd

client-server process example

The following example shows that the same DAC channel, named "dac-ch0", cannot be shared among two processes: the client process cannot see the changes that the server process makes to the DAC channel.

Please read the output the test produces.

Server process output.

DacServer  1.0 (22 Jan 2004)  Use Rulbus DAC from client and server processes.

This program generates a squarewave on DAC channel 0 [voltage -5,5 V].

ISA Rulbus Interface at [0x200], using CanIO port I/O

opened Rulbus device 'dac-ch0' at [0:0xD0]

[5][-5][5][-5]

Client process output.

DacClient  1.0 (22 Jan 2004)  Use Rulbus DAC from client and server processes.

This program reads the voltage from DAC channel 0 [expecting voltage -5,5 V],
and copies the voltage to DAC channel 1.

ISA Rulbus Interface at [0x200], using CanIO port I/O

opened Rulbus device 'dac-ch0' at [0:0xD0]
opened Rulbus device 'dac-ch1' at [0:0xD2]

[0][0][0][0][0][0]

Here is the Rulbus configuration file used.

# dac client--server test

rack "top"
{
   address = 0

   rb8510_dac12 "dac-ch0" { address = 0xD0 }
   rb8510_dac12 "dac-ch1" { address = 0xD2 }
}

The C++ source of the server program.

/*
 * dacserver.cpp - generate alternating -5V, +5V on DAC channel 0.
 */

#include "rulbus.h"
#include <iostream>

/*
 * the Server namespace
 */

namespace Server
{
   const char *title = "DacServer  1.0 (22 Jan 2004)  Use Rulbus DAC from client and server processes.\n";

   const double LoVoltage = -5.0;       // DAC lower voltage
   const double HiVoltage = +5.0;       // DAC higher voltage

   int   server( int handle );
   int   error ();

   /*
    * the program
    */

   int main()
   {
      std::cout <<
         title <<
         "\n"
         "This program generates a squarewave on DAC channel 0 [voltage " <<
           LoVoltage << ',' << HiVoltage << " V].\n" << std::endl;

      /*
       * report on Rulbus Interface:
       */

      rdl_printRulbusInterface();

      /*
       * open DAC channel 0:
       */

      int32   dac0;
      float32 vpb0;

      if ( rb8510_dac12_open( &dac0, "dac-ch0"     ) ||
           rb8510_dac12_getVoltperbit( dac0, &vpb0 )   )
      {
         return error();
      }

      std::cerr << "opened "; RulbusDevice_print( dac0 );
      std::cerr << std::endl;

      return server( dac0 );
   }

   /*
    * server -
    */

   int server( int handle )
   {
      while( true )
      {
         float32 v;

         Sleep( 2000 );

         if ( rb8510_dac12_setVoltage( handle, +5.0 ) ||
              rb8510_dac12_getVoltage( handle,  &v  )    )
              return error();

         std::cerr << "[" << v << "]";

         Sleep( 2000 );

         if ( rb8510_dac12_setVoltage( handle, -5.0 ) ||
              rb8510_dac12_getVoltage( handle,  &v  )    )
              return error();

         std::cerr << "[" << v << "]";
      }

      //return EXIT_SUCCESS;
   }

   /*
    * error - retrieve and print Rulbus error.
    */

   int error()
   {
      const int len = 100; char  msg[len];

      rdl_getLastError( msg, len );
      std::cerr << msg << std::endl;

      return EXIT_FAILURE;
   }

} // namespace Server

/*
 * end of file
 */

The C++ source of the client program.

/*
 * dacclient.cpp - read voltage from DAC channel 0, copy it to DAC channel 1.
 */

#include "rulbus.h"
#include <iostream>

/*
 * the Client namespace
 */

namespace Client
{
   const char *title = "DacClient  1.0 (22 Jan 2004)  Use Rulbus DAC from client and server processes.\n";

   const double LoVoltage = -5.0;       // DAC lower voltage
   const double HiVoltage = +5.0;       // DAC higher voltage

   int   client( int handle0, int handle1 );
   int   error ();

   /*
    * the program
    */

   int main()
   {
      std::cout <<
         title <<
         "\n"
         "This program reads the voltage from DAC channel 0 [expecting voltage " <<
           LoVoltage << ',' << HiVoltage << " V],\n"
         "and copies the voltage to DAC channel 1.\n" << std::endl;

      /*
       * report on Rulbus Interface:
       */

      rdl_printRulbusInterface();

      /*
       * open DAC channel 0:
       */

      int32 dac0, dac1;
      float32 vpb0;

      if ( rb8510_dac12_open( &dac0, "dac-ch0" ) ||
           rb8510_dac12_open( &dac1, "dac-ch1" ) ||
           rb8510_dac12_getVoltperbit( dac0, &vpb0 ) )
      {
           return error();
      }

      std::cerr << "opened "; RulbusDevice_print( dac0 );
      std::cerr << "opened "; RulbusDevice_print( dac1 );
      std::cerr << std::endl;

      return client( dac0, dac1 );
   }

   /*
    * client - read DAC channel0 and copy to DAC channel 1
    */

   int client( int handle0, int handle1 )
   {
      while( true )
      {
         float32 v;

         if ( rb8510_dac12_getVoltage( handle0, &v ) ||
              rb8510_dac12_setVoltage( handle1,  v )    )
         {
              return error();
         }

         std::cerr << "[" << v << "]"; Sleep( 750 );
      }

      //return EXIT_SUCCESS;
   }

   /*
    * error - retrieve and print Rulbus error.
    */

   int error()
   {
      const int len = 100; char  msg[len];

      rdl_getLastError( msg, len );
      std::cerr << msg << std::endl;

      return EXIT_FAILURE;
   }

} // namespace Client

/*
 * end of file
 */

This is the batch command file used to invoke the client and server programs.

@echo off
rem
rem run-daccs2.bat - setup environment to use .\run-daccs.conf, run daccs.
rem

cls
echo Run-daccs2 - setup environment to use .\run-daccs.conf, run dacclient and -server.
echo.

set RULBUS.ORG=%RULBUS%
set RULBUS_CONFIG_FILE.ORG=%RULBUS_CONFIG_FILE%

:set RULBUS=epp,0x378;nocheck
set RULBUS=isa

echo Using RULBUS=%RULBUS%
echo ___
echo.

set RULBUS_CONFIG_FILE=run-daccs.conf

copy ..\bin\rulbus.dll . >nul

start dacclient
start dacserver

rem
rem restore environment:
rem

set RULBUS=%RULBUS.ORG%
set RULBUS.ORG=

set RULBUS_CONFIG_FILE=%RULBUS_CONFIG_FILE.ORG%
set RULBUS_CONFIG_FILE.ORG=

rem
rem end of file
rem


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