Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

In every non-trivial program there is at least one bug.


devel / comp.lang.tcl / Re: A fileevent question

SubjectAuthor
* A fileevent questionHelmut Giese
+- Re: A fileevent questionGerald Lester
+* Re: A fileevent questionHarald Oehlmann
|`- Re: A fileevent questionRich
+- Re: A fileevent questionRalf Fassel
`- Re: A fileevent questionHelmut Giese

1
A fileevent question

<k0lstipvfvbkubnbdedko3l44r9cq276fr@4ax.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13005&group=comp.lang.tcl#13005

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgi...@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: A fileevent question
Date: Tue, 27 Feb 2024 22:29:16 +0100
Organization: ratiosoft
Lines: 22
Message-ID: <k0lstipvfvbkubnbdedko3l44r9cq276fr@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="7a84c729b6cab129fd777dabbb579736";
logging-data="3602833"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18tqyrSL3kNVGMjA4gEi0de"
Cancel-Lock: sha1:IWMsuvQtL5d8F/ZjCf9sQRR/wWk=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
 by: Helmut Giese - Tue, 27 Feb 2024 21:29 UTC

Hello out there,
just asking for inspiration.
I have a simulation which executes commands - everything ok.
But now the program should also communicate with external hardware via
a serial connection and that is the problem:
- I don't want to block waiting for an answer since I also have a GUI.
- Turning to file events I now have the problem that the simulation
cannot continue before a particular call to the hardware is complete:
It may ask the hardware for a particular value which is to be used in
the next command.

So my question is: How do I block execution of the simulation part
until an answer arrives /without/ blocking the whole app?
- An attempt to use 'vwait' resulted in the whole app freezing.
- A separate thread would probably solve this problem.
- A coroutine would instinctively be a "lighter" solution but I have
so far never used coroutines and didn't find an example which seemed
to "fit" my situation.
- Any other way ...

Any idea, tip or link will be greatly appreciated
Helmut

Re: A fileevent question

<U0tDN.464738$7sbb.68899@fx16.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13006&group=comp.lang.tcl#13006

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx16.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: A fileevent question
Content-Language: en-US
Newsgroups: comp.lang.tcl
References: <k0lstipvfvbkubnbdedko3l44r9cq276fr@4ax.com>
From: Gerald.L...@gmail.com (Gerald Lester)
In-Reply-To: <k0lstipvfvbkubnbdedko3l44r9cq276fr@4ax.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 34
Message-ID: <U0tDN.464738$7sbb.68899@fx16.iad>
X-Complaints-To: abuse@fastusenet.org
NNTP-Posting-Date: Tue, 27 Feb 2024 22:05:40 UTC
Organization: fastusenet - www.fastusenet.org
Date: Tue, 27 Feb 2024 16:05:40 -0600
X-Received-Bytes: 2103
 by: Gerald Lester - Tue, 27 Feb 2024 22:05 UTC

On 2/27/24 15:29, Helmut Giese wrote:
> Hello out there,
> just asking for inspiration.
> I have a simulation which executes commands - everything ok.
> But now the program should also communicate with external hardware via
> a serial connection and that is the problem:
> - I don't want to block waiting for an answer since I also have a GUI.
> - Turning to file events I now have the problem that the simulation
> cannot continue before a particular call to the hardware is complete:
> It may ask the hardware for a particular value which is to be used in
> the next command.
>
> So my question is: How do I block execution of the simulation part
> until an answer arrives /without/ blocking the whole app?
> - An attempt to use 'vwait' resulted in the whole app freezing.
> - A separate thread would probably solve this problem.
> - A coroutine would instinctively be a "lighter" solution but I have
> so far never used coroutines and didn't find an example which seemed
> to "fit" my situation.
> - Any other way ...
>
> Any idea, tip or link will be greatly appreciated
> Helmut

vwait is the correct answer when used correctly.

The simulation should:
1) set a global variable.
2) set up the file event.
3) vwait on the global variable.
4) remove the file event.

The file event handler should set the global variable if appropriate.
It should no call update or update idle task.

Re: A fileevent question

<urmpsc$3od7m$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13008&group=comp.lang.tcl#13008

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: A fileevent question
Date: Wed, 28 Feb 2024 09:11:57 +0100
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <urmpsc$3od7m$1@dont-email.me>
References: <k0lstipvfvbkubnbdedko3l44r9cq276fr@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 28 Feb 2024 08:11:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="75088c361c1919e3a5ff940ba499003a";
logging-data="3945718"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/D9RUNEligZXduJF2I5YSE"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:xX7C2ZnnZusFrKj4wHs8ipwMsbs=
Content-Language: en-GB
In-Reply-To: <k0lstipvfvbkubnbdedko3l44r9cq276fr@4ax.com>
 by: Harald Oehlmann - Wed, 28 Feb 2024 08:11 UTC

Am 27.02.2024 um 22:29 schrieb Helmut Giese:
> Hello out there,
> just asking for inspiration.
> I have a simulation which executes commands - everything ok.
> But now the program should also communicate with external hardware via
> a serial connection and that is the problem:
> - I don't want to block waiting for an answer since I also have a GUI.
> - Turning to file events I now have the problem that the simulation
> cannot continue before a particular call to the hardware is complete:
> It may ask the hardware for a particular value which is to be used in
> the next command.
>
> So my question is: How do I block execution of the simulation part
> until an answer arrives /without/ blocking the whole app?
> - An attempt to use 'vwait' resulted in the whole app freezing.
> - A separate thread would probably solve this problem.
> - A coroutine would instinctively be a "lighter" solution but I have
> so far never used coroutines and didn't find an example which seemed
> to "fit" my situation.
> - Any other way ...
>
> Any idea, tip or link will be greatly appreciated
> Helmut

What about a program within a coroutine?
It is suspended until the condition arises.
You may link the coroutine to the fileevent.

That is black magic.

I try to get all vwaits out of my programs. They nest and block each other.

Take care,
Harald

Re: A fileevent question

<ygale74ly1v.fsf@panther.akutech-local.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13010&group=comp.lang.tcl#13010

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: A fileevent question
Date: Wed, 28 Feb 2024 10:48:12 +0100
Lines: 38
Message-ID: <ygale74ly1v.fsf@panther.akutech-local.de>
References: <k0lstipvfvbkubnbdedko3l44r9cq276fr@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net Yj3nP51w7p2IfXlptjQAjAvdLj3lzDuG4Q8vgMQo/G4Yba3aI=
Cancel-Lock: sha1:kSlSOE4EHe43N9SFFDLrq0f4c9g= sha1:chwu/Q7B9D8O7ARAJccO+VQ2bDY= sha256:/xUD8eKEw2EEOXgKoz6eBy/1YdBklNakILP4y0W+jTQ=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Wed, 28 Feb 2024 09:48 UTC

* Helmut Giese <hgiese@ratiosoft.com>
| So my question is: How do I block execution of the simulation part
| until an answer arrives /without/ blocking the whole app?
| - An attempt to use 'vwait' resulted in the whole app freezing.

This is strange, since vwait should process events.

I usually split up the task at hand in 2 parts:

- send command to device
- code to run when answer arrives via fileevent

# assuming line oriented communication
set chan [open $device w+]
fconfigure $chan -blocking 0 -buffering line/none
fileevent $chan readable [list device_answer $chan]

proc send_cmd {chan} {
puts $chan "Answer me!"
# probably set up a timeout timer for the answer to arrive if appropriate
}

proc device_answer {chan} {
set answer [gets $chan]
if {$answer ne ""} {
# handle answer, do all that is necessary
}
if {[eof $chan]} {
close $chan
# diagnostics?
}
}

Then send_cmd just sends the command, and device_answer is called when
the answer from the device arrives.

HTH
R'

Re: A fileevent question

<uro41o$298v$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13015&group=comp.lang.tcl#13015

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: A fileevent question
Date: Wed, 28 Feb 2024 20:11:36 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <uro41o$298v$1@dont-email.me>
References: <k0lstipvfvbkubnbdedko3l44r9cq276fr@4ax.com> <urmpsc$3od7m$1@dont-email.me>
Injection-Date: Wed, 28 Feb 2024 20:11:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3969d4cbf4a1a941a2e1c6234b083434";
logging-data="75039"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+e8REy0oj/7kSsIVs3UVJL"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:m/3KO6phUkTAQnN6dsSLr/F9xiA=
 by: Rich - Wed, 28 Feb 2024 20:11 UTC

Harald Oehlmann <wortkarg3@yahoo.com> wrote:
> Am 27.02.2024 um 22:29 schrieb Helmut Giese:
>> Hello out there,
>> just asking for inspiration.
>> I have a simulation which executes commands - everything ok.
>> But now the program should also communicate with external hardware via
>> a serial connection and that is the problem:
>> - I don't want to block waiting for an answer since I also have a GUI.
>> - Turning to file events I now have the problem that the simulation
>> cannot continue before a particular call to the hardware is complete:
>> It may ask the hardware for a particular value which is to be used in
>> the next command.
>>
>> So my question is: How do I block execution of the simulation part
>> until an answer arrives /without/ blocking the whole app?
>> - An attempt to use 'vwait' resulted in the whole app freezing.
>> - A separate thread would probably solve this problem.
>> - A coroutine would instinctively be a "lighter" solution but I have
>> so far never used coroutines and didn't find an example which seemed
>> to "fit" my situation.
>> - Any other way ...
>>
>> Any idea, tip or link will be greatly appreciated
>> Helmut
>
> What about a program within a coroutine?

The general architecture you describe is one that would 'fit' nicely
into a coroutine design. But, when one is 'new' to coroutines, it is
harder to wrap one's mind around how to structure things. And most of
us are 'new' to thinking in "coroutine" style.

> It is suspended until the condition arises.
> You may link the coroutine to the fileevent.

You can read an example of converting an otherwise sequential, wait
(note, not vwait, just blocking I/O waits) style program into event
driven coroutine style here on the wiki:

https://wiki.tcl-lang.org/page/Coroutines+for+event%2Dbased+programming

Re: A fileevent question

<qrdvti1nadc9glk29i1lmct5070f22afss@4ax.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13016&group=comp.lang.tcl#13016

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: hgi...@ratiosoft.com (Helmut Giese)
Newsgroups: comp.lang.tcl
Subject: Re: A fileevent question
Date: Wed, 28 Feb 2024 23:56:13 +0100
Organization: ratiosoft
Lines: 16
Message-ID: <qrdvti1nadc9glk29i1lmct5070f22afss@4ax.com>
References: <k0lstipvfvbkubnbdedko3l44r9cq276fr@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="e7eb05c0bfda78cd16d648aa2ab4c99e";
logging-data="147200"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19vQdaOhWhpJCaP7aHyABSp"
Cancel-Lock: sha1:L6E5Dc9VHXO6i76ZVeNuluDsQNo=
X-Newsreader: Forte Free Agent 1.93/32.576 English (American)
 by: Helmut Giese - Wed, 28 Feb 2024 22:56 UTC

Hello,
many thanks to all of you who responded.
Rich was right with his comment: Although I read the manual on
coroutines and several pages on the use of and examples with
coroutines I still could not 'grasp' how they work. (But I tuck Rich's
link away for further reference).

So
- I created a very simple example involving 2 Tcl programs: one
sending, the other receiving
- I slowly moved them somewhat into the direction of my app and
- what do you know: 'vwait' is working !

Now I "only" have to find the bug in my first attempt, sigh.
But thanks to you I am at least on track again
Helmut

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor