To give you an example of how easy it'll be to get started, here's some example code:
Code:
# Create a procedure to connect to the device.
proc openConnection {address} {
# Open a connection to the device and save the socket handle in the local var $sock.
set sock [socket $address 10001]
# Configure the connection.
fconfigure $sock -buffering line -blocking false
# Setup an event callback that will be triggered whenever data is received from the device.
fileevent $sock readable [list showOutput $sock]
return $sock
}
# Create a procedure to display output from the device.
proc showOutput {sock} {
# Put what the device sent us into our text box.
.textbox insert end [read $sock]
# Check if the connection has been closed.
if { [eof $sock] } {
close $sock
.textbox insert end "The device has been disconnected."
}
}
# Create a procedure to routinely check the status of a relay on the device.
proc getStatus {sock} {
# Check if the connection is still open.
if { [lsearch -exact [file channels] $sock] > -1 } {
# Get the status of relay 1 on the device.
puts $sock 1sR
# Call this procedure again in ten seconds.
after 10000 [list getStatus $sock]
}
}
# Show the console so that you can interactively type commands.
catch {console show}
# Create a simple text box.
pack [text .textbox]
# Connect to the device
set sock [openConnection jacuzzi.net]
# Activate relay 1.
puts $sock 1r1
# Get the status of the device every 10 seconds.
getStatus $sock
It's a little more than 10 lines of code (19 to be exact, excluding comments & formatting), but of course I added more than is necessary, but this is still a simple example.
As DWallach mentioned, Expect is a nice tool that may make things easier for you. Expect is probably more widely known among developers than the language it was written in. But it's not like Tcl is difficult to learn, and Expect is used mostly for testing applications.
I hope this helps. I know it's always fun programmatically controlling things other than computer monitors.