Hi Jaewon,
Because I need to give a reward before "run_scene" is completed, I tried to pass an arduino object created in the alert_function.m to a custom adapter that I wrote. The idea is that I can track a certain variable while the scene is running, before the success state of the adapter is verified. This works well in the first run; however, I get the following error when ML2 tries to create or update the bhv2 file:
'fieldnames' is not an accessible method of base class 'handle'.
Error in matlabshared.hwsdk.internal.base/fieldnames
Error in mlbhv2/write_recursively (line 227)
field = fieldnames(val)'; nfield =
length(field);
fwrite(obj.fid,nfield,'uint64');
To reproduce my problem in a simple way, I wrote 2 custom adapters based on the adapter programming tutorial of ML2. The problematic one is "adapter_with_alert_function". It should deliver 100 ms of reward at approximately 1 sec since the trial started and the trial should continue running until app. 3 seconds.
In addition to that, I wrote another custom adapter which creates and deletes the arduino object at every scene. Even though it works, the creation of the arduino object causes a lag at the execution, which interferes with what I need. This second adapter is called "adapter_without_alert_function". I am sending both of them attached.
My questions are: 1) Is there a way to pass an arduino object created by the alert function to a custom adapter?
2) Is there a better way of doing what I need? If yes, would you please tell me how?
Best.
PS: I've just verified that if I change the extension of the bhv file from .bhv2 to .mat, I get the warning below but the code still works. So, maybe it would be to good to have an option not to save arduino objects to the bhv2 files or to give a warning like the one below instead of an error?
Warning: arduino objects cannot be saved to disk, and will be
skipped.