Announcement

Collapse
No announcement yet.

c# RegisterEventCB problem. HELP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • c# RegisterEventCB problem. HELP

    I have tried to get to work some time now. I find the documentation lacking for good examples. And I was unable to find anything useful on this forum.
    I'm trying to create a console test application (is running on another computer on the same network) to receive all value changes from HS3.
    I can browse thru all the devices but I can't receive any value notifications.

    This is my complete code.
    (in my frustration to find any working code this code is not good)

    Code:
    using System;
    using System.Threading;
    using HomeSeerAPI;
    using HSCF.Communication.Scs.Communication;
    using HSCF.Communication.Scs.Communication.EndPoints.Tcp;
    using HSCF.Communication.ScsServices.Client;
    using Scheduler;
    using Scheduler.Classes;
    
    namespace HS3TEST
    {
        class Program
        {
            public string OurInstanceFriendlyName = "";
            public bool BShutDown = false;
            static IHSApplication _host = new hsapplication();
            static clsHSPI _plugin;
            private static IAppCallbackAPI _callback;
            private const string IFACE_NAME = "iHome";
            private IHSApplication hs;
            private static IScsServiceClient<IHSApplication> _client;
            private static IScsServiceClient<IAppCallbackAPI> _clientCallback;
    
    
    
            static void Main()
            {
                _plugin = new clsHSPI();
                _client = ScsServiceClientBuilder.CreateClient<IHSApplication>(new ScsTcpEndPoint("10.0.0.185", 10400), _plugin);
                _clientCallback = ScsServiceClientBuilder.CreateClient<IAppCallbackAPI>(new ScsTcpEndPoint("10.0.0.185", 10400), _plugin);
    
                _client.Connect();
                _clientCallback.Connect();
                
                _host = _client.ServiceProxy;
                _host.Connect(IFACE_NAME, "");
                _host.RegisterEventCB(Enums.HSEvent.VALUE_CHANGE, IFACE_NAME, ""); // ????
                
                _callback = _clientCallback.ServiceProxy;
                Console.WriteLine("callback.APIVersion = "+_callback.APIVersion);
                _callback.RegisterEventCB(Enums.HSEvent.VALUE_CHANGE, IFACE_NAME, ""); // ?????
                
    
    
                // THIS WORKS FINE. ALL DEVICES IS RETURNING
                var en = (clsDeviceEnumeration) _host.GetDeviceEnumerator();
                while (!en.Finished)
                {
                    var dv = en.GetNext();
                    var code = dv.get_Code(null);
                    var name = dv.get_Name(null);
                    Console.WriteLine("Code='" + code +"' name='" + name+"', ver='" + dv.Version+"'");
                }
    
                // A2 IS A DIMMER. VALUE RETURNING IS -1 
                var value = _host.DeviceValueByName("A2"); // Where is the function for device code?
                Console.WriteLine("A2=" + value);
                
                var oldSec = -1;
                Console.WriteLine("Press any key to quit");
                while (_clientCallback.CommunicationState == CommunicationStates.Connected)
                {
                    Thread.Sleep(10);
                    if (Console.KeyAvailable) break;
                    if (oldSec == DateTime.Now.Second) continue;
                    oldSec = DateTime.Now.Second;
                    _host.SetDeviceValue("A2", oldSec);
                }
    
                _client.Disconnect();
                _clientCallback.Disconnect();
            }
    
    
            /// <summary>
            /// THERE IS NO EVENT 
            /// </summary>
            /// <param name="evtype"></param>
            /// <param name="parms"></param>
            public static void HSEvent(int evtype, object[] parms)
            {
                try
                {
                    Console.WriteLine("HSEvent=" + evtype);
                }
                catch (Exception err)
                {
                    Console.WriteLine("HSEvent ERROR=" + err);
                }
            }
    
        }
    }
Working...
X