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

File2 is not a valid CodeChannel

Scheduled Pinned Locked Moved
DSF Development
5
11
512
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.
  • undefined
    Ant1
    last edited by 23 Apr 2024, 12:24

    Hello !

    I wrote a plugin to automatically calibrate print heads using custom M-codes. When I launch the script that intercepts the M-codes manually, everything works as expected. Then, I wrapped my code in a plugin, with the exact same code. This time, however, the code fails, with the following exception:

    Traceback (most recent call last):
      File "/opt/dsf/plugins/AutoCalib/dsf/calib.py", line 243, in <module>
        if any(not h for h in printer.homed()[:3]):
                              ^^^^^^^^^^^^^^^
      File "/opt/dsf/plugins/AutoCalib/dsf/printer.py", line 36, in homed
        om = self.get_object_model()
             ^^^^^^^^^^^^^^^^^^^^^^^
      File "/opt/dsf/plugins/AutoCalib/dsf/printer.py", line 19, in get_object_model
        return self.connection.get_object_model()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/dsf/connections/base_command_connection.py", line 76, in get_object_model
        res = self.perform_command(commands.object_model.get_object_model(), ObjectModel)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/dsf/connections/base_connection.py", line 63, in perform_command
        response.result = cls.from_json(response.result)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/dsf/object_model/model_object.py", line 87, in from_json
        return cls()._update_from_json(**preserve_builtin(data))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/dsf/object_model/object_model.py", line 165, in _update_from_json
        super(ObjectModel, self)._update_from_json(**kwargs)
      File "/usr/local/lib/python3.11/dist-packages/dsf/object_model/model_object.py", line 76, in _update_from_json
        setattr(self, attr_name, attr.update_from_json(json_value))
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/dsf/object_model/model_collection.py", line 57, in update_from_json
        self.append(self._item_constructor().update_from_json(item_to_add))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/dsf/object_model/model_object.py", line 93, in update_from_json
        return self._update_from_json(**preserve_builtin(data))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/dist-packages/dsf/object_model/model_object.py", line 69, in _update_from_json
        setattr(self, json_key_snake, json_value)
      File "/usr/local/lib/python3.11/dist-packages/dsf/object_model/inputs/input_channel.py", line 132, in name
        self._name = CodeChannel(value)
                     ^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/enum.py", line 717, in __call__
        return cls.__new__(cls, value)
               ^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.11/enum.py", line 1133, in __new__
        raise ve_exc
    ValueError: 'File2' is not a valid CodeChannel
    

    So it seems that I cannot get the object model from the code when it is wrapped in the plugin, even though I set the correct permissions ("objectModelReadWrite")...

    Do you have any ideas as of why this happens ?

    Thank you very much for your help !

    Antoine Brunner

    undefined 1 Reply Last reply 21 May 2024, 09:30 Reply Quote 0
    • undefined
      Ant1
      last edited by Ant1 23 Apr 2024, 13:06

      Ahaaa, I managed to see wher the issue comes from !

      It seems like File2 was added in DSF 3.5, and I have a mismatch between the DSF version and the python bindings.

      To try and fix that, I added the following requirement in the plugin.json file:

        "sbcPythonDependencies": [..., "dsf-python>=3.5.0.2rc2"],
      

      But the plugin still fails, so I have the impression that the dsf-python package is not installed with the correct version.

      undefined 1 Reply Last reply 23 Apr 2024, 13:51 Reply Quote 0
      • undefined
        Ant1 @Ant1
        last edited by 23 Apr 2024, 13:51

        Looking at the installation code from the Duet Software Framework repository, I feel like that this line might be wrong, with the comparison inverted:

        comparison = 'version("' + installedVersion + '")' + mCompare + 'version("' + mVersion + '")' # version numbers are strings
        

        https://github.com/Duet3D/DuetSoftwareFramework/blob/04486410a79a75e443ea9f81def4c55b6d8b35b1/pkg/common/duetpluginservice/opt/dsf/bin/pip3_install.py#L125C87-L125C95

        Could this come from here ?

        undefined 1 Reply Last reply 23 Apr 2024, 13:55 Reply Quote 0
        • undefined
          jay_s_uk @Ant1
          last edited by 23 Apr 2024, 13:55

          @Ant1 one for @chrishamm

          Owns various duet boards and is the main wiki maintainer for the Teamgloomy LPC/STM32 port of RRF. Assume I'm running whatever the latest beta/stable build is

          undefined 1 Reply Last reply 24 Apr 2024, 07:48 Reply Quote 0
          • undefined
            chrishamm administrators @jay_s_uk
            last edited by 24 Apr 2024, 07:48

            @stuartofmt any idea?

            Duet software engineer

            undefined 1 Reply Last reply 24 Apr 2024, 08:01 Reply Quote 0
            • undefined
              Ant1 @chrishamm
              last edited by Ant1 24 Apr 2024, 08:01

              @chrishamm @stuartofmt I also find a bit dangerous / weird to use exec(...) to compare the versions, as it can very easily lead to code injection, even though it is probably not the intent of people writing plugins.
              Edit: the allowed characters are limited (for example, no parentheses), so this is probably not possible.

              undefined undefined 2 Replies Last reply 13 May 2024, 11:02 Reply Quote 1
              • undefined
                Falcounet @Ant1
                last edited by 13 May 2024, 11:02

                @Ant1 @chrishamm @stuartofmt I think the issue here is that the version of dsf-python is flagged as beta (rc) and pip3 install dsf-python>=version installs the last stable version.
                To make it to work, you either need to use equal : pip3 install dsf-python==version or to add the --pre argument : pip3 install --pre dsf-python>=version although, I'm not sure this is recommended as it may install unwanted beta versions.

                1 Reply Last reply Reply Quote 0
                • undefined
                  stuartofmt @Ant1
                  last edited by 13 May 2024, 17:41

                  @Ant1 @chrishamm @Falcounet

                  Sorry - for some reason I have not been getting notifications about this thread until today.

                  I will take a look at the installation script to see if it can be improved but ...

                  Please note that it's all a bit "vague". By that I mean there is no sure-fire way to check versions across all libraries. It depends too much on how the author chose to identify (or not) versions.

                  Regarding the use of exec. I was being a bit lazy but at the same time its limited to calling version. I'll take a closer look.

                  undefined 1 Reply Last reply 16 May 2024, 00:53 Reply Quote 0
                  • undefined
                    stuartofmt @stuartofmt
                    last edited by stuartofmt 16 May 2024, 00:53

                    @chrishamm @Falcounet

                    It looks like I have some work to do. I've not dug deeply into it yet but it seems Bookworm does not like pip3 and would prefer / needs to use pipx.
                    I can check versions of Debian and make the appropriate differences transparent to the install program. I just need a few days to carve out some spare time and then it will mostly be testing.

                    EDIT: Looks like using apt is the prefered way ...

                    If I'm missing something obvious here, that you have already encountered / resolved, please let me know.

                    undefined 1 Reply Last reply 17 May 2024, 19:22 Reply Quote 0
                    • undefined
                      stuartofmt @stuartofmt
                      last edited by 17 May 2024, 19:22

                      @chrishamm @Falcounet

                      @chrishamm @Falcounet

                      It looks like I have some work to do. I've not dug deeply into it yet but it seems Bookworm does not like pip3 and would prefer / needs to use pipx.
                      I can check versions of Debian and make the appropriate differences transparent to the install program. I just need a few days to carve out some spare time and then it will mostly be testing.

                      EDIT: Looks like using apt is the prefered way ...

                      If I'm missing something obvious here, that you have already encountered / resolved, please let me know.

                      I've created a chatroom to take any implementation discussion off-line. I'm progressing on the basis of providing each python plugin with its own virtual environment.

                      1 Reply Last reply Reply Quote 1
                      • undefined
                        chrishamm administrators @Ant1
                        last edited by 21 May 2024, 09:30

                        @Ant1 You can now install the python3-dsf-python Debian package or reference it in your plugin provided you're on v3.5 or newer. This package was gratefully provided by @Falcounet.

                        Duet software engineer

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