PerlTk with deltaFSD

PerlTk is a good way of of implementing panels for deltaFSD.

It's quick, it's easy and there is a lot of good code out there which can be used or developed.

There are four possible approaches:

  1. Use the Perl interface to call directly into the code for the PerlTk panel. This results in two main loops and despite encouraging noises in the documentation getting the balance right doesnt appear to be a reliable process - at the cost of significant increase in complexity.
  2. Use threads to solve the problems of 1 - at the cost of significant extra complexity
  3. Use Tk's built in interprocess communication facility.
  4. Use the deltaFSD socket facility to communicate with a separate PerlTk panel process.

1, 2 and 3 all suffer the problem that they require deltaFSD to collect the data from any outputs from the panel.

We have samples of options 3 and 4.

The Panel widgets

Both samples use the same set of utility modules which can be assembled into a grid to form a panel:

Using Method 3

There are three components:

  1. deltaFSD
  2. The Perl interface subroutine called from deltaFSD

  3. The target panel

The target panel needs to implement Tk:Receive. In the sample the sub implements the default Tcl:Tk behaviour of executing the received string.

sub Tk::Receive 
{
	my($mw, $cmd) = @_;
	return (eval (detaint($cmd)));
}

The interface subroutine called from deltaFSD assembles the command string to set the outputs ($set) and get the inputs ($get) and sends it:

	return (eval (mainwindow->send('tkPanel', " $set  $get ")));

The only complexity here is the need to overcome the tainting security applied by perlTk

To get send/receive to work the target panel must be invoked with -T, eg:

 perl -T sendpanel

this means that the packages is uses, the main window and the commands it receives must all be detainted.

The sample panel has two inputs and three outputs so the deltaFSD function needs to be configured to match this - the interface sub name is "sendit".

sendsub.pl sends its command to the application named "tkPanel" - this is the default appname used in sendpanel.pl.

The (potentially) recursive loop through the Perl function means that you need force an update to start the send-process in deltaFSD-receive-process in Perl loop running.

The sample deltaFSD data file is "send" which produces something like:

Using Method 4

Here there are just two components:

  1. The socket interface provided in deltaFSD
  2. The target panel - socket.pl

The target panel implements a simple socket interface and parses the received data to separate the (comma separated) channel, value pairs.

The setit sub in socket.pl is called when a data source has a changed value. This sends the value back to deltaFSD.

The default communication port used by socket.pl is 6739 - matching the default for deltaFSD.

The sample data file is "socket" which produces something like: