DSF .Net Core : Event suscribtion
-
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 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"); }