by [Theo Verelst] This pagevis about two essential tcl scripts for a big project of mine, whichvis a computer and otherwise controlled audio mixer. [http://82.170.247.158/Wiki/dsc00194b.jpg] The prototype hardware in buildup Both the control side in the mixer machine and the control program on a PC are pure [Tcl], which is fun and well maintainable. The prototype with its tcl-scripts currently controls (in very high quality) one stereo volume via a slider on the screen of a Linux (I used Fedora Core 6/64) or Windows XP (professional): [http://82.170.247.158/Wiki/scrvol1.jpg] The first tryout script is this one: proc slidsend { {n} {v} } { set w [format "%.2x" [expr $v+191]] send "00$w$w$w" } proc slidsendupdate { } { # send update } set sock {} proc send { {line {\n}} } { global sock if {$sock == -1} { # log "(failed attempt to send:\n$line)\n" return } puts $sock $line flush $sock # log $line\n } proc log a {puts -nonewline $a} set sock [socket 192.168.1.38 4448] #sliders {{vol 255}} wm geometry . 88x478 scale .sl .sl conf -from 64 -to -191 -tickinterval 32 -command {slidsend 0 } pack .sl -expand y -fill y The slider above is shown on the screen, moving it immedeately changes the volume of the single text channel of the mixer. The ticks are in 0.5 dB steps ( a small volume change), which is not to lose resolution, when the slider values would be in Decibels, (-96 .. 31.5) the accuracy would become a decibel per slider step. The send command computes the hardware setting and assumes exactly 4 bytes must be send over the socket per volume change. The local IP address is of the mixer machine. [http://82.170.247.158/Wiki/volume1.jpg] set sock [socket -server connect 4448] set s1 {} proc connect {s host port} { global s1 set s1 $s fconfigure $s1 -blocking 0 -buffering line fileevent $s1 readable [list handleSocket $s1] } proc handleSocket {s} { gets $s line if {[eof $s]} { close $s set s -1 return } if {$line eq ""} return w $line } set fh [open /dev/ttyS2 RDWR] fconfigure $fh -blocking 0 -mode 115200,n,8,1 -translation binary \ -buffering full fileevent $fh readable { set w [read $fh] ; foreach c [split $w {}] { binary scan $c H* a; set v $a if {$s1 != {}} {puts $s1 "$v"} # flush stdout } } proc w h { global fh puts -nonewline $fh [binary format H* "$h"] ; flush $fh } w 00 ; w C0 ; w C0 ; w C0 # after 500 exit vwait forever