A trivial example

Here is a script that implements a virtual motor. It maps vm1 to mot2.

Before the virtual motor can be used, the following command has to be entered: ONLINE> def vm1.

#!/usr/bin/perl -w
#
# file name: /online_dir/vm1.pl
#
# This script is a template for a virtual motor. 
# 

my ($method, $value_new) = @ARGV; 

my $status = 1; 

if( $method eq "set_position")
{
    $status = Spectra::move( mot2 => $value_new); 
}
elsif( $method eq "get_position")
{
    $SYM{RETURN_VALUE} = Spectra::gmup( "mot2"); 
}
elsif( $method eq "get_limit_min")
{
    $SYM{RETURN_VALUE} = Spectra::gmuli( "mot2");
}
elsif( $method eq "get_limit_max")
{
    $SYM{RETURN_VALUE} = Spectra::gmula( "mot2");
}
elsif( $method eq "exec_stop")
{
    Spectra::stop_move( "mot2");
}
elsif( $method eq "calibration")
{
    $status = Spectra::calibrate( name => "mot2",
				  unit => $value_new,
				  noconfirm => 1); 
}
else
{
    Spectra::error( "vm1: failed to identify $method"); 
    $status = 0;
    goto finish;
}
finish:
 $status;

Note that the calibrate command is executed with the noconfirm attribute. This is because Online prompts the user for confirmation before it calls the script.