Question
Is there a script example to implement event receiver in BVMS SDK scriplet?
System overview:
Expected result:
Control Operator Client, whenever a Virtual Input changes state (either ON->OFF or vice-versa).
Example:
- When Virtual Input (any) is open- some action follows in Op Client
OR - When Virtual Input (any) is closed, some action follows
Answer
Concept for you to use:
- In BVMS OC use scriplet, that registers for Events (ex. Virtual Input)
- filter the events and reacts (changes the layout, calls a Favorite, etc.) on particular event
Please find below an example of script that can be used:
// ScriptType: ClientScript // ScriptLanguage: CS using System; using System.Diagnostics; using System.Collections.Generic; using log4net; using Bosch.Vms.Core; using Bosch.Vms.SDK; [BvmsScriptClass()] public class ClientScript : IDisposable { private readonly IClientApi Api; private readonly ILog Logger; Guid almId_global; private EventReceiver myEventRecWS; RemoteServerApi RSApi; // then declare the EventReceiver class
private class MyEventRecieverWS : EventReceiver { private IClientApi myApi; public MyEventRecieverWS(IClientApi api) { myApi = api; } public override void OnEvent(EventData ed) { // //if((ed.Type=="InputState") && (ed.DeviceName=="Virtual Input 1")) // this is just example with the Type of the event. One could also include the Device name - (ed.DeviceName=="Virtual Input 1") and so on if((ed.Type=="InputState")) { //if the VI is open if(ed.State.IsValid == true) myApi.ContentManager.ResetMonitor(1); //add an action here for example /* myApi.ContentManager.ResetMonitor(1); myApi.ContentManager.SetGranularity(1,2); ImagePane ipPane1 = new ImagePane(1, 1); cCam111 = myApi.CameraManager.GetCameraByLogicalNumber(4); DateTime timestamp1 = myApi.ContentManager.GetCurrentTimeStamp(ipPane1); myApi.ContentManager.DisplayCamera(ipPane1, cCam4); */ if(ed.State.IsValid == false) myApi.ContentManager.ResetMonitor(1); //add an action here for example } } } public ClientScript(IClientApi api) { this.Logger = LogManager.GetLogger("ClientScript"); this.Api = api; } [Scriptlet("f52c4b76-9b1d-4fd2-abb4-617249d3fe7f")] public void ReactOnEvent() { // Should be called only as sart up script!!! There is restriction of the numbers of event/alarm receivers per system // System.Threading.Thread.Sleep(2000); try { myEventRecWS = new MyEventRecieverWS(Api); } catch (Exception mye) { Api.ApplicationManager.ShowMessage(mye.Message + "Couldn't create event reciever"); } try { // here use the IP of the BVMS server and the corresponding credentials valid for the current BVMS OC user RSApi = new RemoteServerApi ("172.16.50.79:5390", "Admin", "" ); //Api.ApplicationManager.ShowMessage("connected to server"); } catch (Exception mye) { Api.ApplicationManager.ShowMessage(mye.Message + "Couldn't connect to server"); } try { RSApi.EventManager.Register(myEventRecWS); //Api.ApplicationManager.ShowMessage("registered receiver"); } catch (Exception mye) { Api.ApplicationManager.ShowMessage(mye.Message + "Couldn't register"); } // unregister is made automatically for client scripts when the operator logs off } |
Note: This is simplified and generalized example, that could be helpful in building a particular tailored script.
Info:
Q: What is the maximum number of receivers?
A: There is no hard limit, but one should take into the account the size of the installation and the expected server load.