Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Publishing external/additional Inputs to ObjectModel

    Scheduled Pinned Locked Moved
    DSF Development
    4
    14
    375
    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.
    • reroundefined
      rero
      last edited by

      Good Evening,

      we plan a setup with a Duet3 Mini5+ and a RPi-5 in SBC mode.
      We also want to use additional (most of them digital) inputs from an external uC-Board (we design/implement ourselves). These inputs/values will be used in different macros on the Duet-Board.

      As far as I understood, it is not possible to publish/modify global variables of the ObjectModel directly, if the systems runs in SPI (https://forum.duet3d.com/topic/31248/modify-a-global-variable-value).

      So possible ways to go are:
      a) write a C#/Python-Daemon who periodically pushes the input-states via a simple NC-command to the board ("set global.my_input=...")
      b) write a NC-filter-daemon to intercept user-defined M-Codes to query the inputs (not sure if this will work / if NC-macros can parse/handle the answers from the M-codes correctly).
      c) modify our uC-Board to support Duet's CAN-Bus (like the Sammy-C21) and publish relevant inputs over CAN

      I would prefer solution a) or b).
      May I run into other issues doing this or is there a better, more elegant solution for my problem?

      Thanks and regards,
      Reiner

      dc42undefined 1 Reply Last reply Reply Quote 0
      • dc42undefined
        dc42 administrators @rero
        last edited by

        @rero global variables are already published in the Object Model. The current states of GpIn pins on the Duet are also published.

        Duet WiFi hardware designer and firmware engineer
        Please do not ask me for Duet support via PM or email, use the forum
        http://www.escher3d.com, https://miscsolutions.wordpress.com

        reroundefined 1 Reply Last reply Reply Quote 0
        • reroundefined
          rero @dc42
          last edited by

          @dc42 thanks for your quick reply.

          The inputs I am referring to are not on the Duet, they are on an extra 'standalone' board.
          But I need to handle some of these inputs in Duet-Macros to execute axis-motions depending on the inputs(-states).

          So I would like to update the input-state via DSF (C#- or python), e.g. I would update their value twice per second with a call to 'perform_simple_code("set global.var_name=value")' for every input.

          Can this cause performance-issues when a nc-job is running?

          Regards,
          Reiner

          chrishammundefined 1 Reply Last reply Reply Quote 0
          • chrishammundefined
            chrishamm administrators @rero
            last edited by chrishamm

            @rero In SBC mode, it doesn't really make sense to use global variables to store SBC-specific data in the object model. Instead, consider defining a custom JSON object in the plugin.json manifest of your new plugin and define it using the data property:

            {
              ...
              "data": {
                "myVal": 123
              }
            }
            

            and update it using the SetPluginData IPC command:

            conn/set_plugin_data("myVal", 456, <plugin ID if plugin is not started by DSF>)
            

            Then you can access it using plugins.<plugin ID>.data.myVal in meta G-code expressions.

            See also https://github.com/Duet3D/DuetSoftwareFramework/wiki/Third-Party-Plugins

            Duet software engineer

            reroundefined 1 Reply Last reply Reply Quote 0
            • reroundefined
              rero @chrishamm
              last edited by

              @chrishamm perfect! That was the detail I was searching for 👍

              I will prepare a test-setup with an arduino and some buttons/LEDs to see how it works.

              Thanks for your quick help @dc42 and @chrishamm!

              reroundefined 1 Reply Last reply Reply Quote 0
              • reroundefined
                rero @rero
                last edited by

                So with the usual fiddling around I was able to prepare a test-configuration.

                Everything works as expected except one thing: updating the plugin-data via "set_plugin_data".

                I declared 4 inputs and 4 outputs in the plugins plugin.json description file. After installing the plugin the object-model looks like this:
                dsf_01.jpg

                Once I modified the plugins data for a single input with this code:

                if gOutputs[i]:
                  plugin_update_connection.set_plugin_data("IOExample", "output{0}".format(i),"1")
                else:
                  plugin_update_connection.set_plugin_data("IOExample", "output{0}".format(i),"0")
                

                All the data properties/values are lost and only the last one modified remains:
                dsf_02.jpg

                I tried to lock/unlock the object-model and also to update all 4 inputs in a for-loops, didn't work too...

                @chrishamm any idea what is causing this?

                chrishammundefined 1 Reply Last reply Reply Quote 0
                • chrishammundefined
                  chrishamm administrators @rero
                  last edited by

                  @rero Are you using software version 3.5 or 3.6-beta?

                  Duet software engineer

                  reroundefined 2 Replies Last reply Reply Quote 0
                  • reroundefined
                    rero @chrishamm
                    last edited by

                    @chrishamm I was using stable 3.5.4

                    Tried unstable 3.6.0-beta2 tonite and got a different behaviour, the connection was closed by the server with this error "Closing connection: Internal Server Exception" when calling set_plugin_data.

                    I tried to call the function with a wrong key-name and/or wrong plugin-id, but this didn't change anything.

                    The log with debug enabled looks like:

                    Dec 09 23:44:01 duetpi DuetControlServer[725]: [debug] IPC#62: Granting full DSF permissions to external plugin
                    Dec 09 23:44:01 duetpi DuetControlServer[725]: [debug] Command processor added for IPC#62
                    Dec 09 23:44:01 duetpi DuetControlServer[725]: [debug] IPC#62: Received command WriteMessage
                    Dec 09 23:44:01 duetpi DuetControlServer[725]: [info] [IOExample]: IO [auto:True; inputs:True,False,False,True; outputs:True,False,False,False]
                    Dec 09 23:44:01 duetpi DuetControlServer[725]: [debug] Got new connection IPC#63, checking permissions...
                    Dec 09 23:44:01 duetpi DuetControlServer[725]: [debug] IPC#63: Granting full DSF permissions to external plugin
                    Dec 09 23:44:01 duetpi DuetControlServer[725]: [debug] IPC#62: Connection closed
                    Dec 09 23:44:01 duetpi DuetControlServer[725]: [debug] Command processor added for IPC#63
                    Dec 09 23:44:01 duetpi DuetControlServer[725]: [debug] IPC#63: Received command WriteMessage
                    Dec 09 23:44:01 duetpi DuetControlServer[725]: [info] [IOExample]: Closing connection:  Internal Server Exception
                    Dec 09 23:44:01 duetpi DuetControlServer[725]: [debug] IPC#63: Connection closed
                    Dec 09 23:44:01 duetpi DuetPluginService[1702]: [info] Plugin IOExample: Process has been stopped with exit code 0
                    

                    Calling the function ('set_plugin_data("IOExample", "output0", 1)') with a non-string value gives a different error:
                    "Closing connection: value must be a string"

                    Anything else I can test ... ?

                    chrishammundefined AndyE3Dundefined 3 Replies Last reply Reply Quote 0
                    • chrishammundefined
                      chrishamm administrators @rero
                      last edited by

                      @rero The dsf-python library for v3.6 is being overhauled, because unfortunately it didn't fully adhere to the IPC protocol standard. A while ago I made a DSF plugin in C# for DSF 3.5 and that worked well with SetPluginData but I'm going to test it again to be sure.

                      Version 3.5.4 should work as expected, but note that I've never tested the Python set_plugin_data function myself.

                      Duet software engineer

                      1 Reply Last reply Reply Quote 0
                      • AndyE3Dundefined
                        AndyE3D @rero
                        last edited by

                        @rero Hi, these errors should be fixed in dsf-python 3.6.0-b2.post3. Let me know if you have any further issues

                        AndyE3Dundefined 1 Reply Last reply Reply Quote 0
                        • AndyE3Dundefined
                          AndyE3D @AndyE3D
                          last edited by

                          @rero regarding the issue where the data variables disappear from the OM, in my testing on 3.6-b2 the variables are still accessible with meta gcode but are not being displayed by the OM plugin correctly. This is likely a DWC issue which @chrishamm is looking into.

                          You can test if the variables still exist with

                          echo {plugins.IOExample.data.output0}
                          echo {plugins.IOExample.data.output1}
                          echo {plugins.IOExample.data.output2}
                          echo {plugins.IOExample.data.output3}
                          
                          1 Reply Last reply Reply Quote 0
                          • chrishammundefined
                            chrishamm administrators @rero
                            last edited by

                            @rero I could confirm that there is a problem in DWC preventing the correct display of updated plugin data even though it's correct in DSF. I've got a fix ready for the next DWC beta. Thanks for reporting this!

                            Duet software engineer

                            1 Reply Last reply Reply Quote 0
                            • reroundefined
                              rero @chrishamm
                              last edited by

                              @AndyE3D @chrishamm thanks for the investigations and the fixes.

                              Did a quick test, stayed with 3.6.0-beta2 and updated dsy-python to 3.6.0-b2.post3:
                              -> No exception/exit anymore
                              -> String-values are correctly set via set_plugin_data
                              -> Object model plugin variables disappear (only last one modified is visible), accessing them via 'echo ..." works
                              Reloading the OM-plugin page via browser reload also brings back all values.

                              Will test tomorrow if using non-string values also works for me and also test 3.5.4 again.

                              Thanks for your help, have a good evening!

                              reroundefined 1 Reply Last reply Reply Quote 1
                              • reroundefined
                                rero @rero
                                last edited by

                                Final tests:

                                For 3.6.0-beta2(.post3) all relevant data-types (float,int,bool,string) worked as expected.

                                For 3.5.4 with dsf-python-3.5.0 setting string-data and accessing it via "echo ..." also works.

                                So issue solved for me - merci!
                                Thx @all for their support to answer questions and find/solve issues!

                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post
                                Unless otherwise noted, all forum content is licensed under CC-BY-SA