Scripting 101 - #4 Blocking/Signaling
Posted: Sun Jan 10, 2016 7:37 am
Before we being to speak of basic logical operations, I think a bit more needs
to be said about block and signal. For a program that wishes to efficiently monitor
pins or signals and trigger logic in other scripts, blocks and signals are particularly
valuable. In the near future I will add a call to allow you to get a signal on the change
in any hardware signal, so, for example, you'll be able to tell Auggie to signal
when it see's pin15 on the IO Pokeys go high..
Perhaps something like SetSignalIO( 15, true, "Pin15High" ); You would do this in the main
screen initialization script. You'd also start a script ( or more than 1 ) that is similar to
global TripAlarmOnPin15 = function()
{
while( 1 )
{
block("Pin15High"); //this script will nap forever, until someone, or auggie does a signal("Pin15High");
Engine.Execute(); //so this button will start a program run remotely.
//the program then goes back to napping...
}
}
So as you can see, signals and blocks are a way for the designer to create an event driven realtime
response network, defining how the controller works in most areas. You may have several of these types
of scripts running as each takes no resources at all until tripped and then only takes a ms or so to run,
though Im unsure as yet what the limit is before we run into time trouble..
In some cases it may be more efficient to do a collection of signals in a block, imagine a system
doing THC control of some sort, so they begin with this in the init script..
SetSignalIO( 15, true, "GoLower" );
SetSignalIO( 16, true, "GoHigher" );
SetSignalIO( 17, true, "StopMonitoring" ); , so these 3 pins now have names.. ( this function is not yet implemented as of today.)
And then the init script spins off a thread with
thread( MonitorTHC ); //call this with "thread" so it continues on its own, we wont wait for it in init.
And in a mythical THCLib library you'd find a function..
global MonitorTHC = function()
{
while(1)
{
//this next line blocks until any of the three terms are signaled..
whathappened = block( "GoLower" , "GoHigher", "StopMonitoring" );
//then when one of them happens..
switch( whathappened )
{
case "GoLower" : { MoveAxisDown(1); }
case "GoHigher" :{ MoveAxisUp(1); }
case "StopMonitoring" :{ return; }
}
//so, now finished saving the world, we go back to sleep..
}
};
So this function would respond to a square wave coming in an up or down pin, and stop monitoring
if a third pin goes active. A pretty powerful way to respond the events from hardware.. The SetSignal call
for commanding such responses should be ready shortly, but block/signal are active now and can be used
by scripts.
I think that's enough for now on blocking and signaling.. Ill wait a few days for the next literary assault,
so you have time to play in the scripter with various snippets and get comfortable with the way it operates,
I suggest you make many mistakes and observe the errors, once you get used to them they really do point
to what you've done wrong in most instances, and you'll find parse errors and such are more instructive
than one thinks at first.
Good luck
Art