Duet3D Logo

    Duet3D

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Documentation
    • Order

    DSF .Net Core : Event suscribtion

    DSF Development
    1
    2
    70
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Donpi
      Donpi last edited by Donpi

      Hi,

      I am trying/playing with the Duet Server Framwork with .Net Core.
      I dont get how to suscribe to the events.

      Here is my code, see near the end of Main where I suscrib to the event.
      The event is never fiered, even when the temperature change.

      If someone can tell me where I'am wrong :

      static void Main(string[] args)
      {
               Console.WriteLine("Début");
               Console.WriteLine("Connection");
               SubscribeConnection oCon = new SubscribeConnection();
               try
               {
                        Task oTaskCon = oCon.Connect(SubscriptionMode.Full,"/var/run/dsf/dcs.sock");
                        oTaskCon.Wait();
               }
               catch (Exception oE)
               {
                        Console.WriteLine("-----------------------------");
                        Console.WriteLine("---- erreur de connection ---");
                        Console.WriteLine("-----------------------------");
                        throw oE;
               }
               if (oCon.IsConnected)
                        Console.WriteLine("Connection OK");
               else
                        Console.WriteLine("Connection échouée");
                  
               Console.WriteLine("Recupération du modèle");
               Task<MachineModel> oTask = oCon.GetMachineModel();
               oTask.Wait();
               MachineModel oModel = oTask.Result;
               
               Console.WriteLine("Lecture des capteurs");
               Sensors oSensors = oModel.Sensors;
               Console.WriteLine(oSensors.Analog.Count.ToString() + " Analog sensors");
               Console.WriteLine(oSensors.Endstops.Count.ToString() + " Endstops sensors");
               Console.WriteLine(oSensors.FilamentMonitors.Count.ToString() + " FilamentMonitors sensors");
               Console.WriteLine(oSensors.GpIn.Count.ToString() + " GpIn sensors");
               Console.WriteLine(oSensors.Probes.Count.ToString() + " Probes sensors");
      
               Console.WriteLine("Capteurs Analogiques");
               AnalogSensor oMCU = oSensors.Analog[3];
               oMCU.PropertyChanged += OMCU_PropertyChanged;
               Console.WriteLine(oMCU.Name + " : " + oMCU.LastReading + " C°");
               for (int i = 0; i < 400; i++)
               {
                        Thread.Sleep(50);
               }
      
               Console.WriteLine("Fin");
      }
                  
      private static void OMCU_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
      {
               AnalogSensor oMCU = sender as AnalogSensor;
               Console.WriteLine(oMCU.Name + " : " + oMCU.LastReading + " C°");
      }
      

      Bye
      Juan

      Donpi 1 Reply Last reply Reply Quote 0
      • Donpi
        Donpi @Donpi last edited by

        @Donpi Dear myself, try this way :

                static void Main(string[] args)
                {
                    Console.WriteLine("Début");
        
                    Console.WriteLine("Connection");
                    SubscribeConnection oCon = new SubscribeConnection();
                    try
                    {
                        Task oTaskCon = oCon.Connect(SubscriptionMode.Full,"/var/run/dsf/dcs.sock");
                        oTaskCon.Wait();
                    }
                    catch (Exception oE)
                    {
                        Console.WriteLine("-----------------------------");
                        Console.WriteLine("---- erreur de connection ---");
                        Console.WriteLine("-----------------------------");
                        throw oE;
                    }
                    if (oCon.IsConnected)
                        Console.WriteLine("Connection OK");
                    else
                        Console.WriteLine("Connection échouée");
        
                    Console.WriteLine("Recupération du modèle");
                    Task<MachineModel> oTask = oCon.GetMachineModel();
                    oTask.Wait();
                    MachineModel oModel = oTask.Result;
        
                    Console.WriteLine("Lecture des capteurs");
                    Sensors oSensors = oModel.Sensors;
                    Console.WriteLine(oSensors.Analog.Count.ToString() + " Analog sensors");
                    Console.WriteLine(oSensors.Endstops.Count.ToString() + " Endstops sensors");
                    Console.WriteLine(oSensors.FilamentMonitors.Count.ToString() + " FilamentMonitors sensors");
                    Console.WriteLine(oSensors.GpIn.Count.ToString() + " GpIn sensors");
                    Console.WriteLine(oSensors.Probes.Count.ToString() + " Probes sensors");
        
                    Console.WriteLine("Capteurs Analogiques");
                    AnalogSensor oMCU = oSensors.Analog[3];
                    oMCU.PropertyChanged += OMCU_PropertyChanged;
                    Console.WriteLine(oMCU.Name + " : " + oMCU.LastReading + " C°");
                    
                    Console.WriteLine("Updating model");
                    while (true)
                    {
                        Task<JsonDocument> oTaskPatch = oCon.GetMachineModelPatch();
                        oTaskPatch.Wait();
                        oModel.UpdateFromJson(oTaskPatch.Result.RootElement);
                        Thread.Sleep(250);
                    }
                }
        
                private static void OMCU_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
                {
                    AnalogSensor oMCU = sender as AnalogSensor;
                    Console.WriteLine(oMCU.Name + " : " + oMCU.LastReading + " C° from event");
                }
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Unless otherwise noted, all forum content is licensed under CC-BY-SA