<< Click to Display Table of Contents >> Navigation: 3. Script Language > IPC, InterKOM and Exit Code > ! Smart Package Robot 's InterKOM Technology |
Smart Package Robot 's InterKOM Technology
Intention
What is InterKOM good for?
The SPR System is actually a system that contains multiple components. You have one ore more robots, a Plug In, the Mini-Browser, the Editor and in the future there will be a lot more components.
All of these components need to work together in a synchronized way. They need to communicate to each other. For example, the robot may want to ask the Browser "are you ready loading that page?"
Synchronization and data exchange must be done in a very fast way and also it may be necessary to communicate even through cross boundaries of rights-management.
This is not possible using actual windows messaging.
That is why we invented InterKOM.
InterKOM withing the SPR-System means "Inter Process Communication".
For example, if your Robot is running in another session you may still want it to send a debugging message to the Editor or to another robot instance.
As a base for actual and future "Inter Process Communication, InterKOM was made.
Its the newest technological step ahead in the SPR System.
Together with the new background technology that was added recently, InterKOM will build the base for interesting developements in the future.
It can interface and synchronize any thinkable executable that should be integrated into the SPR system in a lighning fast way.
And it works system-wide, for example you can send InterKOM Messages to robots that run in another session, which will not work using regular windows messaging.
Using GIK. you can read a number of defined values that can be read or written by any other InterKOM program also.
Its like you have a shared pool of variables. And as InterKOM is lightning fast, this is perfect for synchronization between all components.
In the same way, you can sent InterKOM-Messages using SIK.
For this to be possible, each program that joins InterKOM will get a "InterKOM" handle, that is like a postal address for InterKOM. In fact its nothing complicated.
The first program that joins InterKOM receives the handle "1", the second receives the handle "2" and so on. Its a number and currently the upper limit is 16.
This may change in future versions, as InterKOM's architecture could handle a lot more.
Its is currently the maximum number of possible InterKOM users and 16 robots and Editors and browsers are enough for now.
Each program that starts up, whether its a robot, and editor or an Mini-Browser, will immediately get an InterKOM handle. And that handle is called a "CUN" which means "communication unique number". Because its unique and because its purpose is to enable communication between the programs.
What are the InterKOM Commands?
Mostly InterKOM serves two purposes: Synchronization and Messaging.
All of these use the same commands:
• WIK. - Wait until an InterKOM event has happened.
• SIK. - Set an InterKOM event or send an InterKOM Message.
• GIK. - Get an InterKOM State or get an InterKOM Message.
• IIK. / NIK. - Check if an InterKOM Event has happened
Do I have special system variables for use with InterKOM?
You have the following System-Variable for use with InterKOM:
#cun# - CUN of the actual robot that runs this script
#ecun# - CUN of the Editor that has started this robot - if any.
#fcun# - CUN of the robot that has started a Parallel-Robot (father-CUN)
#bcun# - CUN of the last started Mini-Browser (LBR.-Command only)
#pcun# - CUN of the last started Parallel-Robot (PRR.-Command)
What are the InterKOM Sync-Bytes?
For Synchronisation purposes, Interkom offers a number of Synchronisation Bytes.
These Bytes are unique for each InterKOM Member. If you have for example 3 programs that use InterKOM, then any of this programs has the full set of InterKOM-Bytes.
If a program leaves InterKOM, these Bytes are being deleted automatically.
Let's take a look which synchronization bytes we have (for each InterKOM member):
• 1-250 Byte
Bytes can hold any value from 0 to 255
• 1-250 Long
Longs can hold any value from -2147483648 to 2147483647
• 1-250 Quad
A Quad can hold any value from zero to 18446744073709551615.
Each Quad can also hold a text of 8 letters.
• 1-250 Float
A Float can hold positive or negative values that contain a fractional part.
For example 1.234354 or such. They use very high precision internally.
Higher then +/-1.7976931348623157E+308#
In fact InterKOM offers more then 250 Bytes of each sort. However these last bytes are reserved for internal usage of the robot system. Do not try to use them, or you may experience unknown problems.
As each InterKOM using program has a private, full set/pool of "own Sync-Bytes", you need to specify the CUN of the Member, who's bytes you want to read or change.
Was ist ein InterKOM Typ?
Any System-Component, like for example Robot, Editor or Mini-Browser will log on to InterKOM and tell its TYPE to InterKOM.
This way InterKOM always knows the Type of any running Module, and therefore you can search a CUN by TYPE. The actually defined Types are:
TYP unkonwn = 0
TYP Robot = 1
TYP Editor = 2
TYP PlugIn = 3
TYP Aoolication = 4
TYP Mini Browser = 5
In case there are multiple Instances of, for example Robots, you can specify a number to select the one you want. Example:
$$TYP=1
$$NUM=2
GIK.cft|$$TYP|$$NUM|$$RES
DBP.Robot CUN is: $$RES / #cun#
Hint: InterKOM will also be know about the Hwnd and the PID of any attached Component.
Therefore you can also search a Component CUN by its Hwnd or its PID.
In the other direction, you can ask InterKOM for the Hwnd of a Component, if you have
the CUN. You can get the CUN most easy using System-Variables.
How will InterKOM Handle Messages internally?
InterKOM will que all Messages to a specific CUN, until the receiver CUN will use GIK. to receive these Messages. To prevent the Message-Cue from Overflow, it has a maximum value of >4000 Messages that are inserted into the que.
If you retrieve a message using GIK. , the message is been deleted from the Message Que. There is no need to get all Messages out before shutting down a Component. However when a Component ends, all left over message are being discarded.
An Example Script
'**********************************
' This example uses INTERKOM to signal a second Robot to
' end running in a looping.
'**********************************
'
' Run Parallel Robot
PRR.
' Get InterKOM CUN of father-robot
$$CUN=#fcun#
' Here is the Loop
DOL.
' Using GIK. we will read the Byte Nr.1 and put
' the result in $$RES
GIK.Byte|1|$$CUN|$$RES
PRT.received: $$RES
PAU.0.5
OOP.$$RES=10
MBX.Ending.
ENR.
PRE.
' Here is the Main Robot
PAU.0.2
' Set the Pool-Byte to 10 this will make the Parallel-Robot
' end its loop.
SIK.Byte|1|10
' Receive the byte also
GIK.Byte|1||$$RES
DBP.received: $$RES
MBX.Signal sent.
ENR.
'**********************************
' Get any Message Sample-Script
'**********************************
$$CUN=#cun#
$$PCU=#pcun#
PRR.
DOL.
$$ERG=0
GIK.ma.|$$ERG
PRT.Message=$$ERG
GSB.Lab_From
IVS.$$ERG=Ende
$$RES=1
ELS.
$$RES=0
EIF.
PRT.Looping with: $$RES
PAU.1.1
OOP.($$RES=1)
ENR.
PRE.
PAU.5
$$PCU=#pcun#
SIK.message to|$$PCU|Ende
MBX.!
ENR.
' Find out from WHO the message is
' this is stored as ASC. in the first byte of the Message
:Lab_From
JIV.$$ERG=0|Lab_over
' THis line is more ore less cosmetic, ASC. could do without
GSS.1|1|$$ERG|$$FRO
ASC.$$FRO|$$NUM
PRT.Message is from CUN: $$NUM
GSS.2|0|$$ERG|$$ERG
:Lab_over
RET.
'-----------------------------------------------------------
ENR.
'**********************************
' Get Handle from CUN
'**********************************
'
$$CUN=#cun#
GIK.handle|$$CUN|$$RES
DBP.My Handle is: $$RES = #cbw#
ENR.
Limitations
The maximum Message size using InterKOM is currently around 650 kb this limitation may be increased or removed in future versions.
See also:
• PRE. - Parallelrobot-Run-End
•