PDA

View Full Version : Programming in tcl



Dave20042004
04-12-2009, 02:33 PM
I know this isn't Tivo related but since I first heard of TCL here I though I'd let one of our TCL experts respond....
Much to my surprise, I recently purchased a front end to an analytical instrument (NearIR) that allows scripting runtime code using tcl. How cool is that?

My goal is to allow multiple users to control the instrument by simply generating a file on a shared network directory called X:\RunMyScan.txt. This text file would contain the letter A, B or C etc. depending on which user generated the file.

I would like the runtime script to continuously check to see if X:\RunMyScan.txt exists. For example, if RunMyScan shows up containing A the script should:
1. Set variable = A
2. Run the rest of my runtime script using $variable
3. Delete RunMyScan.txt
4. Go back to waiting for RunMyScan.txt to show up.

Thanks in advance!
Dave

djl
04-14-2009, 07:35 PM
You're right, it's not Tivo-related. Everything I've learned about TCL came from the Tivo though, so...


#!/bin/bash

proc WaitForFlag {} {
while 1 {
foreach {user} "A B C" {
if {[file exists "RunMyScan.$user"]} {return $user}
}
after 30000 ;# or however often you want it to check
}
}
while 1 {
set user [WaitForFlag]
... do user stuff

file delete "RunMyScan.$user"
}


Seems to me that it's better to just create a flag file with the user's extension - that way you don't have to keep reading from it. Also, be sure to give yourself a way to break out of the main loop!



I know this isn't Tivo related but since I first heard of TCL here I though I'd let one of our TCL experts respond....
Much to my surprise, I recently purchased a front end to an analytical instrument (NearIR) that allows scripting runtime code using tcl. How cool is that?

My goal is to allow multiple users to control the instrument by simply generating a file on a shared network directory called X:\RunMyScan.txt. This text file would contain the letter A, B or C etc. depending on which user generated the file.

I would like the runtime script to continuously check to see if X:\RunMyScan.txt exists. For example, if RunMyScan shows up containing A the script should:
1. Set variable = A
2. Run the rest of my runtime script using $variable
3. Delete RunMyScan.txt
4. Go back to waiting for RunMyScan.txt to show up.

Thanks in advance!
Dave

Dave20042004
04-15-2009, 09:41 PM
You are the man!
Works great...
Dave