C++ API for Duet 3 Mainboard 6HC
-
@droftarts Hello,
I have a new question regarding the communication between a third-party software (that I will be programming) and the Duet 3 M6HC
I will be connecting a Raspberry Pi 4 to the Duet 3 through SPI and then the Raspberry Pi will run the Duet Web Server.
With this configuration, will I be able to use the HTTP Requests handle by RepRapFirmware please ? -
@ElevenJune You could but if you are using the SBC there are multiple client libraries to interact with DuetControlServer that are much more efficient than using HTTP requests. Currently there are implementations in C#.NET (native language of DuetSoftwareFramework), Python and GoLang.
-
@ElevenJune see here:
https://github.com/Duet3D/DSF-APIs
If you have to use C++ you can adapt one of the other APIs. alternatively maybe you can use the C# API directly.
-
@T3P3Tony and @wilriker Thanks a lot for your answers !
How more efficient would using a client library you mentioned be compared to using HTTP requests please ? Are we talking about speed or something else ?I guess that if I use the SBC without the HTTP requests then the app i'll be developing can only be deployed on the Raspberry Pi connected by SBC to the Duet ?
-
@ElevenJune how much more efficient it is depends on how much information you need to query, network performance etc. if you need very frequently updates the it will be a lot faster than the network interface. OTOH if you don't need frequent updates but you need to do loads of calculations then maybe using the network interface and running your application on a more powerful machine will be faster...
@ElevenJune said in C++ API for Duet 3 Mainboard 6HC:
I guess that if I use the SBC without the HTTP requests then the app i'll be developing can only be deployed on the Raspberry Pi connected by SBC to the Duet ?
Yes
-
@T3P3Tony Thank you for your clear answer ! I'll choose accordingly to the needs I will have. But I guess that not being restricted to the Raspberry Pi can be interesting on the long run.
-
@T3P3Tony I have a question just to be sure I understood well. I will soon start the development of a control App and want to be sure before beginning to code.
I will develop a C++ software, can it communicate with the Duet 3 in these configurations :
-
Duet 3 6HC In Standalone mode. I plug a RJ45 cable between the Duet and a PC (no Raspberry Pi or other SBC is involved) and can use the HTTP Requests to communicate with the card (https://github.com/Duet3D/RepRapFirmware/wiki/HTTP-requests). My software exchanges directly with RepRapFirmware
-
Duet 3 6HC connected to an Raspberry Pi 4 (a SBC) through SPI. I run the Duet Web Server on the Raspberry and can there use the RESTful API (https://github.com/Duet3D/DuetSoftwareFramework#rest-api) to communicate with the card. I can deploy my software on the Raspeberry Pi or on a more powerful PC (not a SBC) that I will connect to the Raspberry with RJ45. My software exchanges with Duet Web Server , like Duet Web Control exchanges with Duet Web Server
Is this right please ?
There is the third option where I can develop my own C++ API communicating with the card through SBC and use it as part of my C++ software. I do not plan on choosing this one.
I really thank you in advance !
-
-
@ElevenJune said in C++ API for Duet 3 Mainboard 6HC:
@T3P3Tony I have a question just to be sure I understood well. I will soon start the development of a control App and want to be sure before beginning to code.
I will develop a C++ software, can it communicate with the Duet 3 in these configurations :
- Duet 3 6HC In Standalone mode. I plug a RJ45 cable between the Duet and a PC (no Raspberry Pi or other SBC is involved) and can use the HTTP Requests to communicate with the card (https://github.com/Duet3D/RepRapFirmware/wiki/HTTP-requests). My software exchanges directly with RepRapFirmware
Yes, configure a fixed IP on the Duet and your laptop within the same range
- Duet 3 6HC connected to an Raspberry Pi 4 (a SBC) through SPI. I run the Duet Web Server on the Raspberry and can there use the RESTful API (https://github.com/Duet3D/DuetSoftwareFramework#rest-api) to communicate with the card. I can deploy my software on the Raspeberry Pi or on a more powerful PC (not a SBC) that I will connect to the Raspberry with RJ45. My software exchanges with Duet Web Server , like Duet Web Control exchanges with Duet Web Server
That is also possible. If you are deploying to the Same raspberry pi then I have not tested connection to the Webserver restful API using 127.0.0.1, you might need to use the external facing IP.
Is this right please ?
There is the third option where I can develop my own C++ API communicating with the card through SBC and use it as part of my C++ software. I do not plan on choosing this one.
I really thank you in advance !
-
@T3P3Tony Thanks a lot ! This is clear for me !
-
@T3P3Tony I have a new question regarding a command
How does the M291 command (to display a message) works ?
If this command is in a G-Code being executed, how can I retrieve the message ? How will the REST API will notify me of this please ? -
Concerning the REST API, can I access a statut Response like the one proposed by RepRapFirmware please ? https://github.com/Duet3D/RepRapFirmware/wiki/JSON-responses
I can't find any info on this. -
That's one for @chrishamm, however there is some documentation here https://github.com/Duet3D/DuetSoftwareFramework/blob/master/README.md.
-
@dc42 Thank you for your answer ! My question is regarding this request : https://github.com/Duet3D/DuetSoftwareFramework/blob/master/README.md#get-machinestatus
Do you know where I can find the status response that I will receive when using this request please ? -
@ElevenJune: When getting status information I think you may benefit from understanding the JSON Machine Model, as most of the information returned via status requests will be either the full Machine Model, a subset, or a patch - depending on the api and commands you use. There is a Machine Model plugin for DWC which is a great way of navigating the model to find where keys/values are.
For example you mentioned a M291 msg: When triggered, an M291 command will populate the Machine Model keys:
state.messageBox.title
state.messageBox.message
So the command : M291 P"This Is A Test Msg" R"My Msg"
Would result in:state.messageBox.title : "My Msg"
state.messageBox.message : "This Is A Test Msg"
The values will auto clear once the msg has been acknowledged or timed-out.
(Note: There are other keys set by M291 but I have excluded them for brevity)(I actually use these keys specifically in my NodeDSF project to trigger events. I would normally point you at my code to give you an idea, but its node.js/javascript so I'm not sure it would be much help.)
Hope this helps!
-
@MintyTrebor Thanks for your reply ! Unfortunately I will be programming in C++ so I cannot use this Machine Model. Do you know how I can access this type of information with the REST API to later use it in C++ please ?
-
@ElevenJune If your using the rest api to query the status then you will have to use the machine model. The HTTP GET /machine/status request you can send returns a JSON object which is the Machine Model. If you go the websocket route, it will still be JSON and the machine model. I don't think there is any way around it with the rest api.
-
@MintyTrebor Thanks for your reply.
Is MachineModel a Json structure that will be returned with the request ? Or is it a something like a JavaScript class ? I don't understand. -
Is MachineModel a Json structure that will be returned with the request ?
Yes.
The easiest way of seeing it is by entering:http://[your sbc/dsf ip address]/machine/status
into your browser.
It should just return the full JSON Machine Model as text (if using firefox it will automatically parse for you).
For the avoidance of confusion - the returned data is just text with an enforced structural pattern (JSON)
-
@MintyTrebor Thanks for your reply and your patience, I got a bit confused while reading the last messages !
This is what I am looking for. I don't have received my Duet card yet so I can't try the request, would you have a link showing the content of the Machine Model or an example of it please ? -
https://duet3d.dozuki.com/Wiki/Object_Model_of_RepRapFirmware
will get you started.