Programming Guide (JScript)



Yüklə 6,96 Mb.
Pdf görüntüsü
səhifə9/22
tarix07.11.2018
ölçüsü6,96 Mb.
#78683
1   ...   5   6   7   8   9   10   11   12   ...   22

25
 function  NotifyEventGlobal (msgevent : MsgObject)
Method arguments:
msgevent - required argument. It sets the event transmitted to the system. It takes the following values: MsgObject objects created earlier in the script.
Example. When Macro 1 starts, the first camera is set for recording. The command is to be transmitted to all system kernels as the event to be registered in the Events Log.
 if (Event.SourceType == "MACRO"&& Event.SourceId == "1" && Event.Action == "RUN")
{
var msgevent = CreateMsg();
msgevent.SourceType = "CAM";
msgevent.SourceId = "1";
msgevent.Action = "REC";
NotifyEventGlobal(msgevent);
}
The CreateMsg method
The CreateMsg method creates objects based on the MsgObject prototype.
Method call syntax
 function  CreateMsg() : MsgObject
Method arguments: no arguments.
Usage examples
Problem 1. When an alarm is received, send the “panic lock” event corresponding to the camera region. For camera identification numbers from 1 to 4, use region 1, for camera 
numbers from 5 to 10, use region 2.
Note
 While executing this script, camera1 is not set for recording.


26
if (Event.SourceType == "CAM" && Event.Action == "MD_START")
{
  var msgevent = CreateMsg();
  msgevent.SourceType = "REGION";
  msgevent.Action = "PANIC_LOCK";
  if (Event.SourceId <=4)
  {
    msgevent.SourceId = "1";
  }
  if ((Event.SourceId > 4) &&  (Event.SourceId < 10))
  {
    msgevent.SourceId = "2";
  }
  NotifyEvent(msgevent);
}
Problem 2. When timer №1 starts, start macro №1 every 30 seconds.
if (Event.SourceType == "TIMER" && Event.SourceId == "1" && Event.Action == "TRIGGER")
{
var msg = CreateMsg();
 msg.StringToMsg(GetObjectParams("TIMER", "1"));
 if(msg.GetParam("s") == "1")
{
 DoReactStr("MACRO", "1", "RUN", "");
 SetObjectParam("TIMER","1","s","30");
DoReactStr("TIMER","1", "DISABLE", "");
DoReactStr("TIMER","1", "ENABLE", "");
 }
if(msg.GetParam("s") == "30")
{
Note
 To start this script create the 
 object with ID=1 beforehand. Set value=1 to the 
 parameter of the 
 object, leave other parameters without changing («
Timer
Second
Timer
Any
by default)


27
 DoReactStr("MACRO", "1", "RUN", "");
                SetObjectParam("TIMER","1","s","1");
DoReactStr("TIMER","1", "DISABLE", "");
DoReactStr("TIMER","1", "ENABLE", "");
 }

 
The Lock and Unlock methods
The Lock and Unlock methods are used to create a global critical section when synchronization of scripts started in different streams is required. The Lock method opens a critical 
section and the Unlock method closes it.
It is recommended to avoid using the Lock and Unlock methods.
Method call syntax
 function Lock()
 function Unlock()
Example. When Macro 1 starts, calculate total alarmed relays and sensors. Objects of each type are to be calculated at the same time (in an individual script). The result is to be stored 
to “counter” global variable.
Script 1:
 // Number of alarmed relays is calculated
var i = Number(0);
if (Event.SourceType == "MACRO" && Event.SourceId== "1" && Event.Action == "RUN")
{
Attention!
Attention! If the Lock method has been called, then the Unlock method has to be called too. Otherwise the system can freeze.


28
var msg = CreateMsg();
msg.StringToMsg(GetObjectIds("GRELE"));
var objCount = msg.GetParam("id.count");
var k;
for(k= 0; k < objCount; k++)
if(GetObjectState("GRELE", msg.GetParam("id." + k))== "ALARM"){
                Lock();
                 i = Itv_var("counter");
i++;
Itv_var("counter")=i;
Unlock();
}
}
 
Script 2:
 //Number of alarmed sensors is calculated
var i = Number(0);
 if (Event.SourceType == "MACRO" && Event.SourceId== "1" && Event.Action == "RUN")
{
var msg = CreateMsg();
msg.StringToMsg(GetObjectIds("GRAY"));
var objCount = msg.GetParam("id.count");
var k;
for(k = 0; k < objCount; k++)
if(GetObjectState("GRAY", msg.GetParam("id." + k))== "ALARMED"){
                Lock();
                 i = Itv_var("counter");
i++;
Itv_var("counter")=i;
Unlock();
}
}


29
1.  
2.  
3.  
4.  
1.  
2.  
3.  
4.  
5.  
6.  
The IsAvailableObject method
The IsAvailableObject method is used to determine the current access rights to an object.
Method call syntax:
function  IsAvailableObject(compname: String, objtype: String,  id: String,  param : String) : String
The method returns 0 if the current user has not been assigned access rights of type 
 for the object; it returns 1 if these rights have been assigned.
param
Method arguments:
compname - required. Corresponds to the name of the 
 object on which the object was created in the hardware tree.
Computer
objtype - required. Corresponds to the type of the system object to which access rights are are being checked. Allowed values: String type; the set of values is restricted to 
the object types registered in the system.
id - required. Corresponds to the identification (registration) number of the object of the type specified by the 
 argument. Allowed values: String type; the set of values 
objtype
is restricted to the identification numbers of objects of the specified type, which are registered in the system.
param - required. Corresponds to the number of the type of rights which are being checked. A description of rights is given in 
Limiting access to the administration of the 
 of the 
. Allowed values:
system objects, control and viewing functions
Administrator’s Guide
0 - NoView access rights. The method will return 1 if there are no administrative, control-, or viewing rights for the object (red 'x').
1 - NoControl access rights. The method will return 1 if there are only viewing rights (letter M).
2 - ViewAndControl access rights. The method will return 1 if there are control- and viewing rights for the object (green box).
3 - ViewOrControl access rights. The method will return 1 if there is either viewing or control rights for the object.
4 - Not access rights (e.g. no access rights).
5 - Configure access rights. The method will return 1 if there are administrative, control- and viewing rights for the object (gray box).
For example: Based on a 
 object named "S-UYUTOVA", a 
 object with the identifier 1 has been created in the hardware tree. To determine the current access rights 
Computer
Camera
to the object:
 
var i = 0;
for(i = 0; i <= 5; i++)
{
     var result =
Note
 If the Lock() and Unlock() methods are not used in this example, then collisions may occur and calculated value will be less than a real one


Yüklə 6,96 Mb.

Dostları ilə paylaş:
1   ...   5   6   7   8   9   10   11   12   ...   22




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə