No announcement yet.

how to send slider value over serial communication?

  • Filter
  • Time
  • Show
Clear All
new posts

  • how to send slider value over serial communication?

    I am using the gen4-uLCD-35DT and I am not sure how to go about sending the slider value over serial comm. Below is the code I am using to get the slider functional, I just need some help sending the serial data in Visie.

    Any help is appreciated, thanks.

    func Sliders()
    var posn;
    var y;
    y := touch_Get(TOUCH_GETY);
    img_Show(hndl,iSlider1) ; // show initialy, if required
    img_ClearAttributes(hndl, iSlider1, I_TOUCH_DISABLE); // set to enable touch, only need to do this once
    posn := y - 111;
    if(posn < 0)
         posn := 100;
    else if(posn > 230)
         posn := 0;
         posn := 100 - 100 * posn / 230;
    img_SetWord(hndl, iSlider1, IMAGE_INDEX, posn);
    img_Show(hndl,iSlider1) ;

  • #2
    Good day!

    If you already got UART setup properly, then you only need to use serout to send bytes to the Serial communication.

    This will send 2 bytes containing the value of the slider.

    Alternatively, if you wish to send it as ASCII string, you can do something like this:

    to(COM0); print(posn, "\n");
    This will send a data array containing the string formatted value of slider followed by a line feed at the end.

    I hope this helps.

    Best Regards
    Juniel Cruz


    • #3
      Thank you, that worked perfectly. I have a couple more questions, is there a way to have the slider start in the middle and how do I save the position of the slider so when I go to another form then come back to my slider form, the slider position is where I left it last?


      • Juniel Cruz
        Juniel Cruz
        4D Staff
        Juniel Cruz commented
        Editing a comment
        Widgets typically stores its value when you update it. You would normally just need to show the widget again (unless you are resetting the value every time you redraw the form)

        To start the widgets in the middle, then simply set its value before you show it the first time.

        If you are using GCI sliders (those without the letter 'i' in it icon), then you are using img_Show to show the widget and img_SetWord to change its value.

    • #4
      Hi I am using visi magic also, I want to control the system from a PC. How can I set a variable on the screen from the PC? I can set the value in a leddigit but I cannot read the leddigit back into my variable. Also is there a way I can send a hex command from the PC to simulate pressing a button?


      • #5

        I want to control the system from a PC. How can I set a variable on the screen from the PC?
        Can you specify what software you are using in your PC to control the display? Also, you can use the 4D Terminal Utility to send hex command to the display.

        Click image for larger version  Name:	4dterminalutility.png Views:	0 Size:	41.1 KB ID:	77244

        Best Regards