Pointers on using DuetHttpClient and ObjectModel
-
I am trying to write an application interacting with a DuetBoard.
I have got a Working example, a .Net c# console application using DuetHttpClient.I have two questions:
-
How do I get hold of an updated model after connection is established? In my code example a command must be sent ("G31") to get a populated model.
-
Are there any pattern/thoughts on monitoring changes in the model? Looping with a delay and sending "G31" seems crude...
I have not found any info or code on this, there probably is. So some help pointing me in the right direction would be much appreciated.
/Tomas
using DuetHttpClient; var options = new DuetHttpOptions { ObserveObjectModel = true, ObserveMessages = true, }; var session = await DuetHttpSession.ConnectAsync(new Uri("http://192.168.0.117"), options); await session.SendCode("G31"); var model = session.Model; foreach (var a in model.Move.Axes) { Console.Write(a.Letter); Console.Write(": "); Console.WriteLine(a.UserPosition); } Console.ReadLine();
-
-
This post is deleted! -
@fotomas Instead of sending
G31
you can callawait session.WaitForModelUpdate();
to make sure the object model is updated once. It is also a good idea to locksession.Model
while you're dealing with it to avoid race conditions. The object model classes implementINotifyPropertyChanged
andINotifyCollectionChanged
allowing you to track changes where necessary.