Bosch Building Technologies

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    [FAQ] Example BVMS SDK scriplet to receive and react on server events

    100% helpful (1/1)

    Question

     

    Is there a script example to implement event receiver in BVMS SDK scriplet?

     

    System overview:

    • BVMS

    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

     

    • First, we recommend you to check the document BVMS-SDK help.pdf  and in particular the example executable: "Example executable 8: Control Operator Client in response to a Virtual Input Data event and read out the data" from this article

    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. 

    Version history
    Last update:
    ‎02-10-2023 09:40 AM
    Updated by:
    Labels (7)
    Contributors
    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist