Announcement

Collapse
No announcement yet.

Working with SmartWidgets in ViSi Genie Magic

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Working with SmartWidgets in ViSi Genie Magic

    Good morning,
    I created with VisiGenie a smartgauge widget with 3 values but only two images because I would like to manage the widget in this way:
    Value = 0 -> image 1
    Value = 2 -> image 2
    Value = 1 -> Alternation of image 1 and 2
    I ask if possible from Magic Code, to read which value has been attributed to the Smartgauge and then (if value = 1) to write to it alternatively, with the control of a timer, the other two (0..2).
    In this way I would have a Smartgauge which, by sending it a value of 1, alternates the images 0-2.
    I hope I was clear and thank you in advance.
    Max

  • #2
    Sorry, I forgot to say that, at the moment it is already working via serial commands, but I would like, if possible, to make the smartgauge autonomous in order to avoid congesting communications to the display since while the widget is flashing, other objects are managed repeatedly.

    Comment


    • #3
      Hi MaxWood,

      Good day!

      You can read the current value of the SmartGauge by simply using a MagicEvent. To do this, you need to create a MagicEvent and set your SmartGauge's Onchanged Event to MagicEventN.

      Click image for larger version

Name:	ObjectInspector.png
Views:	22
Size:	3.4 KB
ID:	74316

      This passes the current value of your SmartGauge to the newval argument in your MagicEvent function. Thus,

      Code:
      func MagicEvent0(var newval)
           WriteObject(tLeddigits, 0, newval) ; //set the value of the Leddigits0 using the newval value
      endfunc
      where newval is the current value of your SmartGauge widget.

      I have attached a sample project for you to try.

      Hope this helps and Best Regards,
      Eran

      Comment


      • #4
        hi Eran,
        unfortunately I tried to use the code you sent me but it doesn't work .. (That is, as sent it works but not for my needs).
        If I understand correctly, each time the SmartGauge state changes (state coming from my controller on the serial port) the MagicEvent handle is called, so I entered the following code:

        in Magic Code0 (Costant / global / data)
        var newval;

        in Magic event0:
        func MagicEvent0 (var newval)
        if (newval == 1)
        WriteObject (tSmartGauge, 0, 2);
        endif
        endif

        so, every time my controller sends the value 1 to the smartgauge, it immediately switches to value 2, setting the timer at 500mS from the expiry date.

        Also, in magic code 1 (MainLoop) I entered:
        if (sys_GetTimer (TIMER1) == 1)
        if (newval == 1)
        WriteObject (tSmartGauge, 0, 2);
        sys_SetTimer (TIMER1, 500);
        else if (newval == 2)
        WriteObject (tSmartGauge, 0, 1);
        sys_SetTimer (TIMER1, 500);
        else
        sys_SetTimer (TIMER1,0);
        endif

        in such a way that, as long as the value is not changed from 1 or 2, the widget alternates 1 and 2 instead of 0 or 3 remains fixed ..
        Where did I go wrong?
        I apologize for the insistence and wish you a good evening
        Max

        Comment


        • #5
          Sorry, the right code in Magic Event is:

          func MagicEvent0 (var newval)
          if (newval == 1)
          WriteObject (tSmartGauge, 0, 2);
          sys_SetTimer (TIMER1, 500);
          endif
          endfunc
          Last edited by MaxWood; 1 week ago.

          Comment


          • #6
            Good morning,
            I noticed that in Magic Event it ends there only if another object writes in the SmartGauge, not if it is the controller via serial.

            Comment


            • #7
              Hi MaxWood,

              Have you tried using another global variable that will hold the state of the SmartGauge? In your example shown, the global newval variable is not changing its value since the newval variable in the MagicEvent0 function is a local variable of the function.

              For example:
              in Magic Code0 (Costant / global / data)
              Code:
              var smartGaugeVal;
              in Magic Event function
              Code:
              func MagicEvent0 (var newval)
              smartGuageVal := newval;   //set the value of the global variable smartgaugeVal
              if (newval == 1)
                  WriteObject (tSmartGauge, 0, 2);
                  sys_SetTimer (TIMER1, 500);
                  endif
              endfunc
              You can then use your smartGaugeVal variable in your Main Loop.

              Hope this helps and Best Regards,
              Eran

              Comment


              • #8
                Hi Eran
                I solved it using a MagicObject.
                Thank you and sorry for the time you have dedicated to me.

                MaxWood
                Last edited by MaxWood; 1 week ago.

                Comment


                • #9
                  Hi MaxWood,

                  No worries. Please don't hesitate to reach us if you ever need help.

                  Best Regards,
                  Eran
                  Eran

                  Comment

                  Working...
                  X