<< Click to Display Table of Contents >> Navigation: 3. Script Language > Environment Variables and Global Signals > Environment Variables and Global Signals |
MiniRobotLanguage (MRL)
SGS. Command
Set Global Alive-Signal (Mutex)
Intention
The SGS.-Command can be used to set/remove or wait for a PC-Global Signal, which can be checked for its existence in another instance of this robot using IGS. or SGS.
You can imagine these Signals like a Table with names in it.
Any program in the Computer can
- add a name to that table
- ask "Is the name XXX already in the table?"
- delete self created names (in case of Mutex)
- or delete any names (in case of Atoms)
There are two types of Global Signals that are currently available: one is called "Mutex" and the second is called "Atom". Both are different in some points.
1. Mutex disappear when the program closes that has set these mutex.
2. Atom do not necessarily disappear when a program closes
3. Mutex can only be deleted by the program which created them
4. Atoms can be deleted by anybody who knows the name of the "Atom"
A Mutex can be set from another instance of this robot using SGS - Set Global Signal (Mutex) or any other application, using the windows-API CreateMutex.
While a "Alive Signal" (=Mutex) can only be deleted by the application that created the Signal, the second Sort of Signals, the so called "Atoms" can be deleted by anybody who knows their name.
You can set a signal, then this signal will stay until the Robot is closed, or until the
SGS.[Signal]|R
Command is executed. If you prefer to use an Atom rather then a Mutex, just add an "A".
SGS.[Signal]|RA
Please note that in case of Mutex, only the Process that created the Signal can remove the Signal.
SGS. can be used to synchronize systemwide resources.
Therefore it can wait for a Signal to be removed, and then it can automatically set the Signal for itself. This way resources can be shared over many instances or programs.
You could even run several installations at the same time, while leaving the mouse to the instance which actually owns the Signal.
The Signal is an "Alive-Signal", it will only be there as long as the robot that has set the signal is "alive". Therefore the Signal can also be used to trap, if a robot has been killed or has ended its task. Because then the signal is automatically destroyed.
Technically the robot should be able to receive Variable-Content (PRV.,WFV.) while waiting for a signal with SGS..
"Global Alive Signals" (Mutex) can also be used to synchronize your script with self written applications*.
*use MSDN-API: OpenMutex()
Syntax
SGS.P1[|P2]
Parameter Explanation
P1 - Name of the Mutex or Atom that should be handled.
P2 - (optional)one of the letters below. If omitted,
the "M" (create Mutex) is the default.
For Mutex:
M - Create Mutex (Raise Signal).
R - Remove Signal - the Signal will be removed.
Only Signals which have been raised by this instance
can be removed from this instance.
W - Wait (unlimited time!) for Signal to be removed by
another instance or program.
C - Wait-and-set signal. Wait till the Signal is removed,
then set the signal himself.
F - Wait for Signal to be set.
For Atoms:
MA - Create Mutex (Raise Atom).
RA - Remove Signal - the Signal will be removed.
WA - Wait (unlimited time!) for Signal to be removed by
another instance or program.
CA - Wait-and-set signal. Wait till the Signal is removed,
then set the signal himself.
FA - Wait for Signal to be set.
FA - Wait for Signal to be set. When Signal was set,
delete Signal and go on ...
Example
'*************************************************
' SGS. - Exampel 1 using Mutex
'*************************************************
$$MYS=Mya_
PRR.0
DOL.1
IGS.$$MYSSignal
PRT.Got Signal !!
SGS.$$MYSSignal_Rec
PAU.0.1
SGS.$$MYSSignal_Rec|R
EIF.
PRT.Looping
PAU.0.2
OOP.
END.
PRE.
$$MYS=Myb_
PRR.0
DOL.1
IGS.$$MYSSignal
PRT.Got Signal !!
SGS.$$MYSSignal_Rec
PAU.0.1
SGS.$$MYSSignal_Rec|R
EIF.
PRT.Looping
PAU.0.1
OOP.
END.
PRE.
FOR.$$CNT|1|9
PAU.1
$$MYS=Mya_
GSB.do_send
$$MYS=Myb_
GSB.do_send
NEX.
MBX.Waiting
ENR.
:do_send
' Sende globales Signal
SGS.$$MYSSignal
' Warte auf Received Signal
SGS.$$MYSSignal_Rec|F
' Lösche Signal
SGS.$$MYSSignal|R
RET.
ENR.
'*************************************************
' SGS. - Exampel 1 using Atoms
'*************************************************
$$MYS=Mya_
PRR.0
DOL.1
IGS.$$MYSSignal|A
PRT.Got Signal !!
SGS.$$MYSSignal|RA
EIF.
PRT.Looping
PAU.0.2
OOP.
END.
PRE.
$$MYS=Myb_
PRR.0
DOL.1
IGS.$$MYSSignal|A
PRT.Got Signal !!
SGS.$$MYSSignal|RA
EIF.
PRT.Looping
PAU.0.1
OOP.
END.
PRE.
FOR.$$CNT|1|9
PAU.1
$$MYS=Mya_
GSB.do_send
$$MYS=Myb_
GSB.do_send
NEX.
MBX.Waiting
ENR.
:do_send
' Sende globales Signal
SGS.$$MYSSignal|MA
RET.
ENR.
'*************************************************
' SGS. - Exampel 2 using Atoms
'*************************************************
' We start 2 Parallel Robots
$$MYS=Mya_
$$MYT=0.2
GSB.Paro
$$MYS=Myb_
$$MYT=0.1
GSB.Paro
' This is the Main Robot
FOR.$$CNT|1|9
PAU.1
$$MYS=Mya_
GSB.do_send
$$MYS=Myb_
GSB.do_send
NEX.
MBX.Waiting
ENR.
:do_send
' Sende globales Signal
SGS.$$MYSSignal|MA
RET.
ENR.
:Paro
PRR.0
DOL.1
SGS.$$MYSSignal|KA
PRT.Got Signal !!
PAU.$$MYT
OOP.
END.
PRE.
RET.
Remarks
-
Limitations:
Currently there is no way to change the waiting time to anything else then unlimited if using SGS.
To use a timeout, use IGS. and #dsince# (See Systemvariables).
See also:
• IGS. / NGS. - If-Global-Signal (Mutex)
• PRE. - Parallelrobot-Run-End
• PRV. - Parallel-Robot send Variable
• WFV. - Wait-For-VariableChange
• SGS - Set Global Signal (Mutex)