For Programmers: Free Programming Magazines  


Home > Archive > Tcl > October 2006 > Handling asynchronous hardware events









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Handling asynchronous hardware events
Christian Gollwitzer

2006-10-30, 7:32 pm

Hello,

I'd like to use TCL (and especially its event loop) to control my
devices over the GPIB/IEEE488.1 serial bus. I know that there exists a
package gpib-tcl, but it does not provide the functionality I'd like to
have.

GPIB devices can send a so called "service request" or SRQ, that is an
interrupt on the GPIB board, to signal e.g. that a new measurement has
been performed. 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.

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'm quite lost in the man pages of Notifier, EventSource and so on. Can
someone provide me with a simple example, what functions (on the C
level) have to be called in the interrupt handler to queue an event,
unblock the event loop, and how to register event handling on the Tcl
level.

Many thanks,

Christian
Pat Thoyts

2006-10-31, 7:07 pm

Christian Gollwitzer <Christian.Gollwitzer@uni-bayreuth.de> writes:

>Hello,
>
>I'd like to use TCL (and especially its event loop) to control my
>devices over the GPIB/IEEE488.1 serial bus. I know that there exists a
>package gpib-tcl, but it does not provide the functionality I'd like
>to have.
>
>GPIB devices can send a so called "service request" or SRQ, that is an
>interrupt on the GPIB board, to signal e.g. that a new measurement has
>been performed. 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.
>
>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'm quite lost in the man pages of Notifier, EventSource and so
>on. Can someone provide me with a simple example, what functions (on
>the C level) have to be called in the interrupt handler to queue an
>event, unblock the event loop, and how to register event handling on
>the Tcl level.
>
>Many thanks,
>
> Christian


I've got a sample project that handles mailslots and is probably the
kind of thing you need to modify. If you have a waitable HANDLE then
you can do the waiting in the SetupProc and CheckProc functions that
you register for your package and then raise a Tcl event to actually
get work done. Mail me if you want some code to look at.

--
Pat Thoyts http://www.patthoyts.tk/
To reply, rot13 the return address or read the X-Address header.
PGP fingerprint 2C 6E 98 07 2C 59 C8 97 10 CE 11 E6 04 E0 B9 DD
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com