I've slowly progressing through my serialport tcl app but hit another wall.
I want to create an array of boolean values to iterate in a for loop.
In the for loop, DTR will send a serial output.
Below I have the following code:
set rs232 [open COM3: r]
fconfigure $rs232 -ttycontrol {DTR 0}
array set values {
0 0
1 1
}
set n [array size values]
set x 0
for {set a 0} {$a <=15} {incr a} {
fconfigure $rs232 -ttycontrol {DTR $values(0)}
wait 1000
fconfigure $rs232 -ttycontrol {DTR $values(1)}
wait 1000
}
I run it and I get the error:
expected boolean value but got "$values(0)"
Can anyone tell me why this is and how do I fix it?
This invocation:
fconfigure $rs232 -ttycontrol {DTR $values(0)}
passes the value "DTR $values(0)" for -ttycontrol
to fconfigure
. The invocation
fconfigure $rs232 -ttycontrol [list DTR $values(0)]
passes "DTR 0".
The braces prevent substitution of the variable, but the invocation of list
enforces it.
Alternatively, you could use one of
fconfigure $rs232 -ttycontrol "DTR $values(0)"
fconfigure $rs232 -ttycontrol [subst {DTR $values(0)}]