How to get started with daemon.g
-
Hello
I recently posted a request for help “Duet 2 IDLE State Power Off”
https://forum.duet3d.com/topic/34479/duet-2-idle-state-power-off.
I had some very helpful suggestions from Phaedrux and OwenD, which pointed me in the right direction. With their help, I think I now understand what needs to done and I have already got the code I think I will need using daemon.g. I understand GCode meta commands and Object Model calls / interrogating.
However, there are some fundamental issues with daemon.g I still need help with. I have scour the Internet, the Duet forum and the Duet website, I am amazed that there seems to be no entries (I can find) which tell you how to actually get started with daemon.g. No daemon.g how too’s, no daemon.g basics, nothing to help a newbie get going.
The following information is what I need help with please:-- Where to compose your code. Notepad, Notpad++, Word?
- How do I test run my code for syntax and or code errors?
- How would you title you code if you wanted to control more than one aspect on your duet board? For example, if you wanted write code to flash your printers LED lights and at the same time play a Christmas tune via the sounder in your PanelDue display? You only seem to be able to have one daemon.g code list in your system directory.
- How do forum contributors get the fancy text colours on the code they publish?
- I got my head around how the GCode Meta Commands work, no problem, but flummoxed with how to get started. I expected to easily find this information on the Duet forum at least.
Cheers..
-
Not going to say much about the code since I'm slowly figuring it out too. For writing it I like notepad++. Mostly for the compare plugin. That is so useful I can place code side by side and compare..
Thiings I found useful were, https://forum.duet3d.com/topic/16495/conditional-g-code-introduction-tutorial-pdf
https://docs.duet3d.com/User_manual/Reference/Gcode_meta_commands
-
@Cubiceye said in How to get started with daemon.g:
The following information is what I need help with please:-
- Where to compose your code. Notepad, Notpad++, Word?
G Code is simply plain ascii text. Any text editor will work.
More advanced ones allow syntax highlighting which makes it easier to read.
I use RJ TextEd and have created a set of syntax highlighting files and mouseover help. See here
Others here are working on similar for other text editors.- How do I test run my code for syntax and or code errors?
You just run it
In the case of daemon.g it's probably best to call it something else first and simply run it as a macro.
That will help find any syntax errors etc.
Once you name it daemon.g and put it in the /sys folder, it will by default run every 10 seconds.
To change it, you usually have to rename it first.- How would you title you code if you wanted to control more than one aspect on your duet board? For example, if you wanted write code to flash your printers LED lights and at the same time play a Christmas tune via the sounder in your PanelDue display? You only seem to be able to have one daemon.g code list in your system directory.
All G Code files run sequentially however it happens quickly.
To do your example you would have to mix the lights commands with the music commands. There is no real way of running two files at the same time like thread although there are now multiple movement queues.- How do forum contributors get the fancy text colours on the code they publish?
By selecting the code and pressing the </> button above the text box.
This applies a syntax highlighter to the text.- I got my head around how the GCode Meta Commands work, no problem, but flummoxed with how to get started. I expected to easily find this information on the Duet forum at least.
There is quite a lot of documentation, but it's a big job for the developers to keep on top of.
Searching the forum is helpful as there have been many discussions on daemon.g and meta commands in general.
Bear in mind there are 100 different ways of doing things and they are nearly all correct -
My top tips for writing code daemon.g are:
-
Don't forget - It's just a macro. Anything you can write in any other macro can be written and run in daemon.g.
-
Don't forget - It runs every 10 seconds. Anything you put in will run again and again unless you make it stop.
Often times, you'll want to run something just one time, when something happens. You can use daemon.g to watch for that thing to happen. This is in the form of an IF statement in daemon.g, followed by the thing you want to do. (I have one that watches for the network to connect, then I display the IP address on PanelDue). Now I need a way to stop it from happening again. I nest the IF statement above in another if statement that looks at a global variable called something line global.not_run_yet. If not_run_yet is TRUE, then the code proceeds to check if the network is connected. And if it is true and the network is connected, then after I print my message, I set the value of global.not_run_yet to FALSE. Next time Daemon.g runs, this will cause it to skip the print statement. To make this work, you need to create the global variable somewhere other than daemon.g . It might be in config.g or another macro called by config.g.
In my case, I also wanted to give the system some time to get that network connected, so I created a global variable that is used as a counter. If daemon.g gets past the IF network_not connected command, I increment the counter. If the counter gets to 5 (meaning daemon.g has run this code 5 times, or 40-50 seconds have passed), I decide to stop trying and set"network_not_connected" to False anyway.
-
-
Hi Guys
Thank you for your replies. I think I now have all the info I need to actually get going.
Cheers.