Re: Handling asynchronous hardware events
- From: Uwe Klein <uwe_klein_habertwedt@xxxxxxxxxxx>
- Date: Mon, 30 Oct 2006 18:54:12 +0100
Christian Gollwitzer wrote:
Ralf Fassel wrote:what about using a pipe with your signal handler writing tclish strings
* Christian Gollwitzer <Christian.Gollwitzer@xxxxxxxxxxxxxxx>
| In C I can install an asynchronous handler, that is called when the
| SRQ happens. However, there are some restrictions. For example I'm
| not allowed to call stdio functions in this handler, so typically
| one needs to send a message with SetEvent() on Windows and checks
| with WaitForEvent() in the main loop to handle the request.
This sounds like the equivalent to signal() on Posix: you're allowed
to call only a small range of functions in the signal handler (listed
in the signal(2) man page).
It's not as bad as signal. I'm allowed to malloc() and free(), even to sprintf(), but printf and file I/O is forbidden. The exact requirements are listed on:
http://zone.ni.com/devzone/cda/tut/p/id/3458#2
| I'd like to use Tcl and events instead, e.g. fire an event and
| provide something similiar to fileevent to handle it, so I can get
| rid of all the synchronization hassle in C.
I would bet that you can't use TCL in the signal handler since TCL
could/will invoke 'unsafe' functions like allocating memory or
something like that.
Of course I can't call Tcl_Eval() in the handler. However, the thread safe Tcl provides functions to do that in some way. Concretely, there is
Tcl_AlertNotifier(), Tcl_ThreadAlert(), Tcl_QueueEvent(), Tcl_SetMaxBlockTime(), Tcl_AsyncCreate(), Tcl_AsyncMark(), Tcl_Asyncinvoke(), Tcl_CreateEventSource(), ...
I was able to beat together something for a different project by ripping off code from the Threads package. But it was very complicated (a C function has been called in the context of the second thread, which called Tcl_Eval("event generate ...")), and I bet there must be some straightforward way to insert an event asynchronously from the handler.
Sadly, the man pages have lots of very detailed description, but there is no simple understandable example, how to use these functions.
However, what you could try is to create a TCL channel/pipe, register
a fileevent for it, and in the signal handler write(2) something to
it. The fileevent proc then should take over as soon as the event
queue runs again.
I/O is forbidden.
Or just run some heartbeat proc every N milliseconds which checks a
global status variable which is set in the signal handler.
Well, then I can use gpib-tcl right away... continuous polling aka busy waiting is exactly what I'm trying to avoid.
Christian
of the incoming events to the pipe and the tcl side using fileevent on this pipe?
had a look at menchan and similar stuff? http://wiki.tcl.tk/2083
uwe
.
- References:
- Handling asynchronous hardware events
- From: Christian Gollwitzer
- Re: Handling asynchronous hardware events
- From: Ralf Fassel
- Re: Handling asynchronous hardware events
- From: Christian Gollwitzer
- Handling asynchronous hardware events
- Prev by Date: Re: Syntax, expressiveness and the beauty of Tcl
- Next by Date: Need some guidance -- starting with Tile 0.7.8 ...
- Previous by thread: Re: Handling asynchronous hardware events
- Next by thread: Tcl/Tk Books updated for 8.5
- Index(es):
Relevant Pages
|
|