Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Another Newbie question

16 views
Skip to first unread message

Bob

unread,
May 7, 2012, 11:40:25 AM5/7/12
to
Hi again,
Thanks to Eugene for the help in formatting numbers. Now I have another
question....
I have a simple form that contains a text box. I am using the GPIB-Tcl
library to read values from an instrument. My first iteration was to just
read one value from the instrument thus:

set value [eval {gpib read}]
Text1 insert 0.00 "$value"

This works ok. Next I did this to try and get several values at a one
second rate:

for { set i 1 } { $i <= 10 } { incr i } {
set value [eval {gpib read}]
Text1 insert 0.00 "$value"
after 1000
Text1 delete 1.88
}

This works, but the form does not appear until after the 10 second loop
completes. I'd like to see the values displayed as they are gathered.
(Also, I clearly have some work to do on the delete command as my 10 values
are all displayed......but that is another story).

Thanks!

Bob



Georgios Petasis

unread,
May 7, 2012, 11:51:15 AM5/7/12
to
update idletasks (or simply update)
after 1000
Text1 delete 1.88
}

Update will allow pending events to be served, so it will cause a redraw
on changed widgets.

George

Uwe Klein

unread,
May 7, 2012, 11:53:15 AM5/7/12
to
Bob wrote:
> Hi again,
> Thanks to Eugene for the help in formatting numbers. Now I have another
> question....
> I have a simple form that contains a text box. I am using the GPIB-Tcl
> library to read values from an instrument. My first iteration was to just
> read one value from the instrument thus:
>
> set value [eval {gpib read}]
> Text1 insert 0.00 "$value"
>
> This works ok. Next I did this to try and get several values at a one
> second rate:
>
for { set ::i 1 } { $::i <= 10 } {} {
set value [gpib read]
Text1 insert 0.00 "$value"
after 1000 incr ::i
Text1 delete 1.88
}

another alternative would be using [update idletasks]

uwe

Robert Heller

unread,
May 7, 2012, 12:15:46 PM5/7/12
to
Your problem is that without entering the event loop, the display is
never updated.

Try this:

global count
set count 0
global text
set text [text .text1]
pack $text -expand yes -fill both

proc getonevalue {} {
global count
global text
set value [gpib read]
$text insert 1.0 "$value\n"
$text delete 2.0 end
incr count
if {$count < 10} {
after 1000 getonevalue
}
}

The big difference here is the proc is called from the event loop and
the process does its sleeping in the event loop. After the proc reads
from the instrument bus and the inserts the value, it returns to the
event loop, where pending idle tasks are evaluated (the text widget's
update). The $text insert and $text delete both insert something into
the event queue and when the getonevalue proc exits and control is
returned to the event loop these events are handled and th text widget's
display is updated.

>
> Thanks!
>
> Bob
>
>
>
>

--
Robert Heller -- 978-544-6933 / hel...@deepsoft.com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments



Christian Gollwitzer

unread,
May 7, 2012, 1:58:26 PM5/7/12
to
Am 07.05.12 18:15, schrieb Robert Heller:
> At Mon, 7 May 2012 10:40:25 -0500 "Bob"<kva...@nopa.com> wrote:
> Try this:
>
> global count
> set count 0
> global text
> set text [text .text1]
> pack $text -expand yes -fill both
>
> proc getonevalue {} {
> global count
> global text
> set value [gpib read]
> $text insert 1.0 "$value\n"
> $text delete 2.0 end
> incr count
> if {$count< 10} {
> after 1000 getonevalue
> }
> }

I second this answer. Also note, that if your device generates data with
its own timer, and you want to see all values, you should enable SRQ and
wait for that event. Typically, you activate SRQ by sending the "*SRE"
command to the device. With gpib-tcl, you can wait on SRQ by
gpib wait -event srq

NI also supports asnychronous callbacks for SRQ to get truly event based
programs. To use them, I have done my own GPIB library available here:

http://sourceforge.net/projects/gpib-tclsrq/

With it, you get an OO interface to GPIB devices. Assuming your device
has address 8 on the bus you can do:

=============================
package require gpibsrq
gpibdevice dev 8
dev write "*SRE65" ;# must adopt this to your device
proc getonevalue {} {
global text
$text insert 1.0 [dev read]
}
dev srq getonevalue
==============================


and you should see a live update of the measured values

Christian
0 new messages