R&D & Software & Technology Alexander Shyrokov on 18 Jul 2008 09:20 am
Automation solution
Hello,
As you know, we have multiple computers that we use during our experiments. We have to prepare every computer before the experiment and then collect the data after the experiment is done. The usual procedure is to use a check list so we do not forget something. NASA have been using this approach for some time:
We still manage to forget things, though. And given that all our computers are connected into a network I decided to automate some of the procedures.
Setup: Multiple computers, each of each must have a set of properly configured applications running. The settings may be changed during different experiment stages. For example: Pre-experiment stage (all applications are launched, subject id is provided), Experiment part 1, Experiment part 2, Post-experiment stage (save data files, close applications).
Solution: Imagine that all the applications that we use can be controlled from a command line. Then all we need to do is to execute proper commands on every computer. That is simple: every computer runs a “command execution server” on startup. The experimenter creates a batch file for every stage of the experiment that connects to the “command execution server” to run commands with proper parameters.
Problem 1. Most applications are GUI based. But AutoHotKey provides a solution for this problem. AutoHotKey can control mouse and send key presses to the windows. It even comes with a recorder that allows easy creation of the scripts.
Problem 2. What to use as an “command execution server”? Programs similar to Remote Desktop are GUI based. Telnet and ssh require user permission settings and could be cumbersome to configure, but they could provide additional security. Given that we are not worried about security (it’s a local isolated network), I implemented a server and a client in perl (thanks to the Network Programming with Perl, a great tutorial by James Lee). The server will execute any perl script that a client sends to it (yes, it can be dangerous, but it is also very flexible).
Solution: The server runs on every computer. Every computer also has a set of AutoHotKey script files that control the applications (this is an example of an AutoHotKey Script, which executes a notepad and writes a message in it). The experimenter executes a client that informs the server to run the proper commands (assuming AutoHotKey is installed properly):
my @args = (”AutoHotkey.exe ScriptExample.ahk _SUBJECT_”);
system(@args) == 0 or die “Failed to execute given command\n”;
Notice that the client substitues _SUBJECT_ for a given parameter and ahk script uses it. This code is saved in a file such as ExecuteScriptExample and is piped to the client. This is what the experimenter does to run a script on a remote computer:
perl NetCli.pl Subject1 IPADDRESS_1 <ExecuteScriptExample
I hope this will help you to automate your own tasks. One can execute or even dynamically create batch or perl scripts and then run them on the remote computer.
Thank you.
Alexander Shyrokov