Signal when Slider is active.

2019-10-24
2019-10-31
  • paularnenyborg - 2019-10-24

    Hi.

    I have a couple of sliders in my visu. Is it possible to get a signal from a slider that it is being touched?
    I'm not thinking about the value that I change, but rather a BOOL that goes TRUE when I touch the slider and FALSE again when I don't touch it.
    I have tried with hollow buttons, invisible buttons etc with no luck.

    Paul

     
  • m.prestel - 2019-10-24

    Hello Paul,

    do you mind sharing what you want to do with this signal?
    This may help me or others understand what you need and how you can achieve it.

    Best regards,
    Marcel

     
  • paularnenyborg - 2019-10-24

    m.prestel hat geschrieben:
    Hello Paul,
    do you mind sharing what you want to do with this signal?
    This may help me or others understand what you need and how you can achieve it.
    Best regards,
    Marcel

    Hi Marcel.

    I want the slider to go back to a set value when I release it. My slider spans from -100 to + 100. I want it to 0 when I don't touch it.
    I thought I could write a small code that takes the slider to 0 when that signal goes FALSE.

     
  • Lo5tNet - 2019-10-24

    Don't know if this is the correct way of doing it but this has worked for me in the past. You can build off of this to make sure the pointer is valid, slider element is pointing to the correct slider, etc...:

    VAR_INPUT
        siSlider1POS : SINT := 0; (*Slider value*)
    END_VAR
    VAR
        xInit : BOOL := TRUE;
        pSlider1 : POINTER TO visufbelemslider;  (*Library part of "System_VisuElemsWinControls that should already be in your project*)
    END_VAR
    IF xInit THEN
        xInit := FALSE;
        pSlider1 := ADR(__VisuInitInstantiation_Gvl.__VisuInitInstantiation_Instance.inst__Home.GEN_Instance_2._visufbelemslider[0]); (*Pointer to slider*)
    END_IF
    IF NOT pSlider1^.m_bDragged THEN
        siSlider1POS := 0; //Set slider value to 0 when slider is not being dragged.
    END_IF
    
     
  • m.prestel - 2019-10-25

    Hello Paul,

    attached you can find an example using the interface IMouseEventHandler.

    With this you are not depending on internal structures, which may change at any time.

    Keep in mind, this attached example is only designed for a single client!
    If you have multiple clients, we would have to store the iSliderValueOnMouseDown in an array.

    Best regards,
    Marcel

    ResetSliderValue.project [175.13 KiB]

     
  • paularnenyborg - 2019-10-29

    Comingback4u hat geschrieben:
    Don't know if this is the correct way of doing it but this has worked for me in the past. You can build off of this to make sure the pointer is valid, slider element is pointing to the correct slider, etc...:

    VAR_INPUT
        siSlider1POS : SINT := 0; (*Slider value*)
    END_VAR
    VAR
        xInit : BOOL := TRUE;
        pSlider1 : POINTER TO visufbelemslider;  (*Library part of "System_VisuElemsWinControls that should already be in your project*)
    END_VAR
    IF xInit THEN
        xInit := FALSE;
        pSlider1 := ADR(__VisuInitInstantiation_Gvl.__VisuInitInstantiation_Instance.inst__Home.GEN_Instance_2._visufbelemslider[0]); (*Pointer to slider*)
    END_IF
    IF NOT pSlider1^.m_bDragged THEN
        siSlider1POS := 0; //Set slider value to 0 when slider is not being dragged.
    END_IF
    

    Hi, and thanks for reply.
    I am having trouble pointing to my slider. It has ID 0 i my visu. Is it suppose to be located in the Input Assistant?

     
  • Lo5tNet - 2019-10-31

    Hello,
    If you can do it the way M.Prestel shows it i'm sure it is a better approach. If you can't do it that way maybe you could upload a sample project for me to take a look at. As Marcel mentions Pointers is not the best approach but I'm using 3.5.5.4 and don't know if his approach is available in this version. Haven't had time to look into it thoroughly. What version of CoDeSys are you using also helps.

    Regards,
    CB

     

Log in to post a comment.