Spk/Slt, Tango

The following code creates a widget to operate Slt/Spk PLCs. In the meantime the features are available from online -tki itself ( to be invoked by a right-click on the motor name in the toplevel widget). However the code has been kept here to serve as an example.

$Spc::res_h{ blsc} = "spk1, other, devices";
$Spc::res_h{ spk1_title} = { text => "Spk1"}; 

$Spc::res_h{ spk1_help} = sub 
{ 
    Util::display_text( "Help Spk1", 
'
  State
    0 ON
    6 MOVING
  
  Home
    Starts the homing sequence

  Toggle auto-refresh 
    If enabled, the menu items are updated every 2 seconds. 
    See current state of this flag is displayed in the 
    log widget of the toplevel menu, if it is changed.
'
)};
$Spc::res_h{ "spk1_io1"} = { 
    label => { name => "Position", 
	       get => sub { sprintf "%g", Spectra::tng_attrDoubleRd( "spk1", "Position");}},
    entry => { set => sub { Spectra::tng_attrDoubleWrt( "spk1", "Position", $_[0])}}};

$Spc::res_h{ "spk1_io2"} = { 
    label => { name => "Encoder Home Position", 
	       get => sub { if( Spectra::tng_attrLongRd( "spk1", "FlagEncoderHomeDefined"))
			    {
				sprintf "%g", Spectra::tng_attrDoubleRd( "spk1", "HomePosition");
			    }
			    else { "home not defined";}}},
    entry => { set => sub { Spectra::tng_attrDoubleWrt( "spk1", "HomePosition", $_[0])}}}; 
$Spc::res_h{ "spk1_io3"} = { 
    label => { name => "FlagHomed", 
	       get => sub { Spectra::tng_attrLongRd( "spk1", 
						       "FlagEncoderHomed");}}};
$Spc::res_h{ "spk1_io4"} = { 
    label => { name => "State", 
	       get => sub { Spectra::tng_state( "spk1");}}}; 
$Spc::res_h{ "spk1_io5"} = { 
    label => { name => "Error code", 
	       get => sub { Spectra::tng_attrLongRd( "spk1", "ErrorCode");}}}; 

$Spc::res_h{ spk1_b1} = { 
    name => "Home", 
    command => sub { Spectra::tng_inout( "spk1", "MoveHome");}};

$Spc::res_h{ spk1_b2} = { 
    name => "ResetMotor", 
    command => sub { Spectra::tng_inout( "spk1", "ResetMotor");}};

$Spc::res_h{ spk1_b3} = { 
    name => "ClearError", 
    command => sub { Spectra::tng_inout( "spk1", "ClearError");}};

$Spc::res_h{ spk1_option1} = { 
    name => "Toggle auto-refresh", 
    command => sub { if( defined( $BLSC::h{ w_timer}))
		     {
			 $BLSC::h{ w_timer}->cancel(); 
			 delete $BLSC::h{ w_timer};
			 Util::log( "BLSC: timer cancelled"); 
		     }
		     else
		     {
			 $BLSC::h{ w_timer} = 
			     $BLSC::h{ w_top}->after( 2000, \&BLSC::refresh);
			 Util::log( "BLSC: timer started"); 
		     }}};

Figure 14.10: Spk
Image blsc_spk