Menu

scriptThread.dataReceivedSignal.connect with different functions

Anonymous
2021-01-20
2021-01-21
  • Anonymous

    Anonymous - 2021-01-20

    Bonjour,

    I'd like to use
    scriptThread.dataReceivedSignal.connect to alternate between different
    parsings.

    According some debug and  it seems that the more I call the connect
    signal to different functions, whitout removing the previous one.

    • This behavior should be specified in the documentation
    • It could be usefull to chain or adding features
    • It could be reset to "nothing"

    I'll find a workaround with a global variable and a switch case.
    Nevertheless anyone have experienced this ? Or suggest a better solution ?

    Best regards,
    Pascal

    Here is one example :
    [... script initialization ...]

    // receivers declaration
        function SerialReceive_type1(buffer1)    {
        // do some job with RS232 messages format number 1
        }

    function SerialReceive_type2(buffer2)    {
        // do some other job with RS232 messages format number 2
        }

    // Main task
    scriptThread.dataReceivedSignal.connect(SerialReceive_type1);
        // do tasks while using receiver and parsing for type 1 messages
    [...]

    scriptThread.dataReceivedSignal.connect(SerialReceive_type2);
        // do tasks while using receiver and parsing for type 2 messages
    [...]

    scriptThread.dataReceivedSignal.connect(SerialReceive_type1);
        // switch back to messages type 1
    [...]

    scriptThread.dataReceivedSignal.connect(null);
        // to connection for parsing needed anymore
        // this last line return an error

    [... script end ...]

    The calls trace of such script will looks like :
        receive type 1
        receive type 1
        receive type 1
        receive type 1
        // switch to type 2
        receive type 2
        receive type 1
        receive type 2
        receive type 1
        // switch back to type 1
        receive type 1
        receive type 2
        receive type 1
        receive type 1
        receive type 2
        receive type 1

    --

    Pascal Delrot
    Ingénieur électronique

    1, rue Georges Le breton
    22370 Pléneuf-Val-André, France

    Office :+33 9 67 05 00 40

    www.samea-innovation.com http://www.samea-innovation.com/

     
  • Pascal DELROT

    Pascal DELROT - 2021-01-20

    Note : here is my Sourceforge profile, as the post was anonymous

     
  • Stefan Zieker

    Stefan Zieker - 2021-01-21

    Hi Pascsal,

    you can call disconnect to remove the callback function:

    scriptThread.dataReceivedSignal.disconnect(SerialReceive_type1);
    

    I never used this and therefore I forgot to discribe it in the manuel.

    Regards
    Stefan

     
  • Pascal DELROT

    Pascal DELROT - 2021-01-21

    Hello Stefan, so let's try ! I'll keep you update today. Pascal

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.