Disposing function when deleting a Node #2665
|
Hi Everyone, I have a question regarding the Bonsai node structure. I am currently developing a hardware system that is compatible with Bonsai RX, and I have run into a problem with managing hardware modules in the workflow. I want the user to be able to define which types of hardware modules they are using in their experiment. To achieve this, I have created a Module Define Bonsai node. This node registers the specified hardware module in an underlying dictionary. The dictionary is then used to verify that the correct hardware is connected before the experiment is started. The registration of the hardware modules works as intended. However, I cannot find a way to automatically remove the corresponding entry from the dictionary when the node is deleted from the Bonsai workflow. Is there a specific function, API-call, or lifecycle method that I need to implement so that my C# code can detect when the node is removed and execute an unregister function? |
Replies: 1 comment 5 replies
|
Hi! I am a bit confused how you are setting this up. If an experiment is running, the workflow cannot be edited. Otherwise it sounds like you are trying to connect to hardware prior to workflow start time. We have tried this pattern in the past and found it rather clunky. I would stick with, as much as possible, configuring hardware as part of the workflow. |



@glopesdev may be able to give you a more complete answer to this. My take: you should try to avoid injecting workflow logic in the compiler/expression tree. Aim to have configuration simply be part of the workflow; that is what bonsai is good at. If you fight it, it will push back :P.
I usually use one of two patterns to get at what you are trying to do:
A sort of builder pattern:
or, if you can afford to push all your business logic to the device operator, simply have some sort of record-like definition of the devices, and use that as the property instead:
Not to say you cant complicate this further, but I would approach it on a case-by-case basis.