logo elektroda
logo elektroda
X
logo elektroda

Can someone explain why Berry code behaves differently depending on how it’s run?

ZappedBrainCell 165 1
ADVERTISEMENT
  • #1 21552352
    ZappedBrainCell
    Level 1  
    - If I run a .be file via “Reset SVM and run as script thread”, everything works: print(), setChannel(), runCmd().
    - If I run the exact same file using `startScript` from autoexec.bat or event handler, none of that works. No output, no GPIO, no command access.

    There’s no error. It just runs in silence and does nothing useful.

    How are we supposed to write reliable Berry logic if the execution model is invisible?
    Right now it feels like I'm guessing. Is there a clear spec for which context gives you full runtime access and which ones don't?

    Please help.
    AI: Can you specify which device or platform you’re running Berry on (e.g., hardware model, firmware version, or software environment)?
    CB3S (BK7321N) OpenBK7231N_QIO_1.18.101_berry.bin
    AI: Could you share a minimal example of the .be script you’re running, or at least the relevant parts that use print(), setChannel(), and runCmd()?
    file my_script.be
    print("test message")
    runCmd("any_obk_cmd")
    setChannel(1, 100)
  • ADVERTISEMENT
  • #2 21552536
    p.kaczmarek2
    Moderator Smart Home
    This is a native behaviour of berry import. Berry import runs module only on the first run, that's why "reset SVM" works every time.
    Screenshot of editing autoexec.be with the Save, Reset SVM and run file as script thread button highlighted.
    I may try to fix it soon, but it's strictly related to berry, I would need to alter berry behaviour itself, more or less.

    If you want to call berry from autoexec.bat, do:
    
    // autoexec.bat
    berry import test
    addRepeatingEvent 5 -1 berry test.mySample(2)
    

    
    // test.be
    test = module('test')
    # Add functions to the module
    test.mySample = def(x)\
         addChannel(5, x) 
    end
    return test
    

    Verified by self test:
    Screenshot showing source code in Visual Studio, focused on testing berry import module integration.

    If you want to have click directly in berry:
    Section of C code with a test function Test_Berry_Click and multiple SELFTEST_ASSERT_CHANNEL macro calls.

    If you want to add a delay in a click:
    Screenshot of Visual Studio Code with the selftest_berry.c file open, showing a function for testing click and timeout in Berry.

    OBK Berry tutorial first part is here: https://www.elektroda.com/rtvforum/topic4117238.html second part will be released soon.
    Helpful post? Buy me a coffee.
ADVERTISEMENT