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

    DSF Plugin: How do use DSF executable?

    Scheduled Pinned Locked Moved Solved
    DSF Development
    g-code
    3
    10
    764
    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.
    • peterwilliundefined
      peterwilli
      last edited by

      Hi there,

      Currently I stumbled upon this README: https://github.com/Duet3D/DuetSoftwareFramework/blob/master/PLUGINS.md#zip-file-structure

      It talks about the structure of DSF plugins in their zip file.

      In my plugin, I need to be able to check if a print has been ended (a message g-code will be sent).
      I have to make sure that I can catch this event, even if DWC is not open on the user side, and I don't know if I understood correctly but there is a section that reads "dsf/ directory: Contains executable and config files for the SBC portion (if applicable)" and I was thinking that's where I put an executable that can listen for events over say a socket interface, if I understand it correctly.

      Please correct me if I'm wrong, I may have mistaken myself entirely here. In any case, I can't find an example plugin that uses this dsf/ folder, so I cannot tell for sure.

      If anyone has more info on this, that'd be much appreciated!

      resamundefined 1 Reply Last reply Reply Quote 0
      • resamundefined
        resam @peterwilli
        last edited by

        @peterwilli You are almost there! The missing part is that you need to write a small script or application to listen for your events - or whatever logic you want.
        You can use a Python SDK https://github.com/Duet3D/dsf-python/ or golang SDK https://github.com/Duet3D/dsf-go or use the .NET SDK from DSF itself https://github.com/Duet3D/DuetSoftwareFramework/tree/master/src/DuetAPIClient

        Then you simple package everything (and compile to a binary executable if necessary) and place it into the dsf/ folder you mentioned -- and instruct your plugin.json to start your app when the your plugin gets started during boot-up of the SBC.

        peterwilliundefined 1 Reply Last reply Reply Quote 1
        • peterwilliundefined
          peterwilli @resam
          last edited by

          @resam Thanks a lot. I will try python, that's what I'm most familiar with!

          resamundefined 1 Reply Last reply Reply Quote 0
          • resamundefined
            resam @peterwilli
            last edited by

            @peterwilli take a look at this post - and the GitHub project linked. This could be a good starting point or template for your project:
            https://forum.duet3d.com/post/241194

            peterwilliundefined 2 Replies Last reply Reply Quote 0
            • peterwilliundefined
              peterwilli @resam
              last edited by

              @resam Thank you that is very helpful. I already managed to get the GUI portion working by making my own DWC plugin. I'm now looking at the way the DSF sdk works. Your link really has a good example.

              1 Reply Last reply Reply Quote 0
              • peterwilliundefined
                peterwilli @resam
                last edited by peterwilli

                @resam Hi there, I managed to connect to our printer so I could test it out.
                The DWC says "partially started", and it seems the python portion does not want to load.

                I checked dmesg and it seems that Apparmor is blocking the execution of the script:

                [ 9345.841913] audit: type=1400 audit(1627397274.769:95): apparmor="DENIED" operation="exec" profile="/opt/dsf/plugins/FilamentLoadCell/**" name="/usr/bin/python3.7" pid=3055 comm="filament_load_c" requested_mask="x" denied_mask="x" fsuid=996 ouid=0
                [ 9345.842277] audit: type=1400 audit(1627397274.769:96): apparmor="DENIED" operation="exec" profile="/opt/dsf/plugins/FilamentLoadCell/**" name="/usr/bin/python3.7" pid=3055 comm="filament_load_c" requested_mask="x" denied_mask="x" fsuid=996 ouid=0
                

                I wondered if others had this problem too with Python scripts?

                Edit: I deleted the Apparmor profiles to see what would happen. I still seem not to be able to run it entirely, wouldn't the DSF module be loaded by default? Btw, the DWC portion works fine.

                ● duetpluginservice.service - Duet Plugin Service
                   Loaded: loaded (/lib/systemd/system/duetpluginservice.service; enabled; vendor preset: enabled)
                   Active: active (running) since Tue 2021-07-27 16:10:49 BST; 6min ago
                 Main PID: 3634 (DuetPluginServi)
                    Tasks: 14 (limit: 4915)
                   CGroup: /system.slice/duetpluginservice.service
                           └─3634 /opt/dsf/bin/DuetPluginService
                
                Jul 27 16:16:53 raspberrypi DuetPluginService[3634]: [info] Plugin FilamentLoadCell: Process has been started (pid 3760)
                Jul 27 16:16:53 raspberrypi DuetPluginService[3634]: [error] Plugin FilamentLoadCell: Traceback (most recent call last):
                Jul 27 16:16:53 raspberrypi DuetPluginService[3634]: [error] Plugin FilamentLoadCell:   File "/opt/dsf/plugins/FilamentLoadCell/dsf/filament_load_cell.py", line 10, in <module>
                Jul 27 16:16:53 raspberrypi DuetPluginService[3634]: [error] Plugin FilamentLoadCell:     from dsf.commands.basecommands import HttpEndpointType
                Jul 27 16:16:53 raspberrypi DuetPluginService[3634]: [error] Plugin FilamentLoadCell: ModuleNotFoundError: No module named 'dsf'
                Jul 27 16:16:53 raspberrypi DuetPluginService[3634]: [info] Plugin FilamentLoadCell: Process has been stopped with exit code 1
                
                1 Reply Last reply Reply Quote 0
                • peterwilliundefined
                  peterwilli
                  last edited by peterwilli

                  Edit 2: (New post becuase I'm not allowed to edit posts anymore)

                  I managed to get past the first error by running pip3 install dsf, but now I get the second error, and I have no idea what random_UA really is...

                  pi@raspberrypi:~ $ systemctl status duetpluginservice.service
                  ● duetpluginservice.service - Duet Plugin Service
                     Loaded: loaded (/lib/systemd/system/duetpluginservice.service; enabled; vendor preset: enabled)
                     Active: active (running) since Tue 2021-07-27 16:17:14 BST; 1h 4min ago
                   Main PID: 919 (DuetPluginServi)
                      Tasks: 15 (limit: 4915)
                     CGroup: /system.slice/duetpluginservice.service
                             └─919 /opt/dsf/bin/DuetPluginService
                  
                  Jul 27 17:18:38 raspberrypi DuetPluginService[919]: [error] Plugin FilamentLoadCell: ModuleNotFoundError: No module named 'random_UA'
                  Jul 27 17:18:38 raspberrypi DuetPluginService[919]: [info] Plugin FilamentLoadCell: Process has been stopped with exit code 1
                  Jul 27 17:21:38 raspberrypi DuetPluginService[919]: [info] Plugin FilamentLoadCell: Process has been started (pid 1586)
                  Jul 27 17:21:38 raspberrypi DuetPluginService[919]: [error] Plugin FilamentLoadCell: Traceback (most recent call last):
                  Jul 27 17:21:38 raspberrypi DuetPluginService[919]: [error] Plugin FilamentLoadCell:   File "/opt/dsf/plugins/FilamentLoadCell/dsf/filam
                  Jul 27 17:21:38 raspberrypi DuetPluginService[919]: [error] Plugin FilamentLoadCell:     from dsf.commands.basecommands import HttpEndpo
                  Jul 27 17:21:38 raspberrypi DuetPluginService[919]: [error] Plugin FilamentLoadCell:   File "/usr/local/lib/python3.7/dist-packages/dsf/
                  Jul 27 17:21:38 raspberrypi DuetPluginService[919]: [error] Plugin FilamentLoadCell:     import random_UA
                  Jul 27 17:21:38 raspberrypi DuetPluginService[919]: [error] Plugin FilamentLoadCell: ModuleNotFoundError: No module named 'random_UA'
                  Jul 27 17:21:38 raspberrypi DuetPluginService[919]: [info] Plugin FilamentLoadCell: Process has been stopped with exit code 1
                  

                  I love Duet 😂 meme

                  Edit 3: I managed to get past the dsf error, apparently I installed the wrong DSF, I need to install like this: sudo pip3 install dsf-python (Mind the use of sudo! I tried it without first by accident which caused it not to work).

                  However, it seems to fail to start the exposed command API.

                  Jul 27 18:04:03 raspberrypi DuetPluginService[2417]: [error] Plugin FilamentLoadCell: Traceback (most recent call last):
                  Jul 27 18:04:03 raspberrypi DuetPluginService[2417]: [error] Plugin FilamentLoadCell:   File "/opt/dsf/plugins/FilamentLoadCell/dsf/filament_load_cell.py", line 61, in add_dsf_http_endpoint
                  Jul 27 18:04:03 raspberrypi DuetPluginService[2417]: [error] Plugin FilamentLoadCell:     cmd_connection.connect()
                  Jul 27 18:04:03 raspberrypi DuetPluginService[2417]: [error] Plugin FilamentLoadCell:   File "/usr/local/lib/python3.7/dist-packages/dsf/connections.py", line 425, in connect
                  Jul 27 18:04:03 raspberrypi DuetPluginService[2417]: [error] Plugin FilamentLoadCell:     return super().connect(clientinitmessages.command_init_message(), socket_file)
                  Jul 27 18:04:03 raspberrypi DuetPluginService[2417]: [error] Plugin FilamentLoadCell:   File "/usr/local/lib/python3.7/dist-packages/dsf/connections.py", line 66, in connect
                  Jul 27 18:04:03 raspberrypi DuetPluginService[2417]: [error] Plugin FilamentLoadCell:     self.socket.connect(socket_file)
                  Jul 27 18:04:03 raspberrypi DuetPluginService[2417]: [error] Plugin FilamentLoadCell: FileNotFoundError: [Errno 2] No such file or directory
                  

                  So now the only error that is left is the problem with the apparmor that I disabled for now and this Python thingy...

                  I'll keep looking myself too! Thanks a lot!

                  Edit 4: I managed to run the Python portion! The trick was: git clone https://github.com/Duet3D/dsf-python and then cd to that directory, then run sudo mkdir -p /usr/local/lib/python3.7/dist-packages/ and then run sudo python3 setup.py install

                  I guess that there's a problem with the latest release which is fixed in the github repo...

                  resamundefined 1 Reply Last reply Reply Quote 0
                  • resamundefined
                    resam @peterwilli
                    last edited by

                    @peterwilli The dsf-python dependency is mentioned in https://github.com/Kriechi/duet-plugin-filament-load-cell#software-setup

                    But yes, I think the latest version on pypi is buggy - @mfs12 ?

                    The AppArmor problem is indeed a possible pitfall for others - because I never installed it on my custom setup. Maybe you can try the instructions from https://github.com/Duet3D/DuetSoftwareFramework/wiki/SBC-Setup-Guide#third-party-plugins-only-v33-and-newer about disabling AppArmor - but be aware of the risk.

                    1 Reply Last reply Reply Quote 0
                    • mfs12undefined
                      mfs12
                      last edited by mfs12

                      Hey @resam and @peterwilli, just released 3.3.1 which fixes two issues.

                      • fixed default socket file name
                      • deleted flush function from intercept connection

                      Please check https://pypi.org/project/dsf-python/3.3.1/

                      Visit me on github at https://github.com/mfs12/

                      peterwilliundefined 1 Reply Last reply Reply Quote 0
                      • peterwilliundefined
                        peterwilli @mfs12
                        last edited by

                        @mfs12 Thanks a lot I will update this later in our image builder so it gets the latest version.

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