Announcement

Collapse
No announcement yet.

Differentiate data from serin()

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

  • Differentiate data from serin()

    Hello,

    Assume I have two different LedDigits, one for temperature and the second for humidity.

    The data is received thru the serin(),

    I can send any kind of data structure from the microcontroller.

    Is there an example code that can help me ?

    Thank you,

  • #2
    Hi,


    Fortunately, we have an application note and a downloadable code example for it, please visit ViSi Data Loop Back Testing of Serial Hardware.
    This is a great start for you on the basic asynchronous serial hardware loopback.


    Hope it helps,

    Best regards,
    Kayven
    Last edited by [email protected]; 23 January 2019, 04:42 PM.

    Comment


    • #3
      Hi,
      I used as base your ViSi Data Loop Back Testing of Serial Hardware example and implement it on Gen4-uLCD-43DT. I made the application simpler with only one serial port (COM1) and the same interface (1 slider 1 digit display and 1 Coolgauge). It work fine but not allays. some time the Coolgauge have one input delay, in other words if I change the slier 5 times and set 20-80-90-30-50 the cool gauge will show 20-80-90-90-30.
      Can you pleas explain this behavior and suggest a solution?
      Best regards
      Mario

      Code:
      #platform "Gen4-uLCD-43DT"
      
      
      // Program Skeleton 1.4 generated 04/10/2021 18:12:31
      
      #inherit "4DGL_16bitColours.fnc"
      #inherit "ledDigitsDisplay.inc"
      
      #inherit "VisualConst.inc"
      
      // var gradientRAM[29+xxx*2] := [-1,-1,-9999,0,0,xxx] ; // uncomment and replace xxx with maximum of all inherent 'media' widgets
      
      #inherit "sertryConst.inc"
      
      
      
      
      
      // Slider1 1.0 generated 04/10/2021 18:14:49
      
      
      var buffer0[5],buffer1[5], buffer2[5], buffer3[5];
      var x, y;
      
      func moveSlider1()
      var posn, frame ;
      
      // Slider1 1.0 generated 8/26/2013 8:59:20 PM
      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 := gfx_XYlinToVal(x, y, 1, 8, 456, 0, 100) ;
      img_SetWord(hndl, iSlider1, IMAGE_INDEX, posn);
      img_Show(hndl, iSlider1);
      
      // Customdigits1 1.0 generated 8/26/2013 9:18:54 PM
      // Leddigits1 1.0 generated 04/10/2021 18:14:42
      img_Show(hndl, iLeddigits1); // show all digits at 0, only do this once
      ledDigitsDisplay(posn, iLeddigits1+1, 28, 4, 3, 47, 0) ;
      
      serout1(posn); // COM0 TX
      frame:=serin1();
      // COM0 RX
      // print(frame);
      
      // frame:=50;
      // Coolgauge1 1.0 generated 04/10/2021 18:14:46
      img_SetWord(hndl, iCoolgauge1, IMAGE_INDEX, frame) ; // where frame is 0 to 100 (for a displayed -1 to -1)
      img_Show(hndl,iCoolgauge1) ;
      
      
      endfunc
      
      
      
      func main()
      var state, n ;
      
      COM1_RX_pin(PA4); // select the hardware pin for COM1 receive line
      COM1_TX_pin(PA5); // select the hardware pin for COM1 transmit line
      
      COM2_RX_pin(PA6); // select the hardware pin for COM1 receive line
      COM2_TX_pin(PA7); // select the hardware pin for COM1 transmit line
      
      COM3_RX_pin(PA8); // select the hardware pin for COM1 receive line
      COM3_TX_pin(PA9); // select the hardware pin for COM1 transmit line
      
      com_Init(buffer0,5,0);
      com1_Init(buffer0,5,0);
      com2_Init(buffer0,5,0);
      com3_Init(buffer0,5,0);
      com_SetBaud(COM0, 11500);
      com_SetBaud(COM1, 11500);
      com_SetBaud(COM2, 11500);
      com_SetBaud(COM3, 11500);
      
      
      
      
      putstr("Mounting...\n");
      if (!(file_Mount()))
      while(!(file_Mount()))
      putstr("Drive not mounted...");
      pause(200);
      gfx_Cls();
      pause(200);
      wend
      endif
      gfx_TransparentColour(0x0020);
      gfx_Transparency(ON);
      gfx_Cls();
      
      hndl := file_LoadImageControl("sertry.dat", "sertry.gci", 1);
      
      img_Show(hndl, iLeddigits1);
      //img_Show(hndl, iCustomdigits2);
      //img_Show(hndl, iCustomdigits3);
      //img_Show(hndl, iCustomdigits4);
      img_Show(hndl,iCoolgauge1) ;
      //img_Show(hndl,iCoolgauge2) ;
      //img_Show(hndl,iCoolgauge3) ;
      //img_Show(hndl,iCoolgauge4) ;
      img_Show(hndl,iSlider1) ;
      //img_Show(hndl,iSlider2) ;
      //img_Show(hndl,iSlider3) ;
      //img_Show(hndl,iSlider4) ;
      //name1();
      // name2();
      // name3();
      // name4();
      
      
      
      img_SetWord(hndl, iSlider1, IMAGE_FLAGS, (img_GetWord(hndl, iSlider1, IMAGE_FLAGS) | I_STAYONTOP) & ~I_TOUCH_DISABLE); // set to enable touch, only need to do this once
      //img_SetWord(hndl, iSlider2, IMAGE_FLAGS, (img_GetWord(hndl, iSlider2, IMAGE_FLAGS) | I_STAYONTOP) & ~I_TOUCH_DISABLE); // set to enable touch, only need to do this once
      //img_SetWord(hndl, iSlider3, IMAGE_FLAGS, (img_GetWord(hndl, iSlider3, IMAGE_FLAGS) | I_STAYONTOP) & ~I_TOUCH_DISABLE); // set to enable touch, only need to do this once
      //img_SetWord(hndl, iSlider4, IMAGE_FLAGS, (img_GetWord(hndl, iSlider4, IMAGE_FLAGS) | I_STAYONTOP) & ~I_TOUCH_DISABLE); // set to enable touch, only need to do this once
      
      touch_Set(TOUCH_ENABLE); // enable the touch screen
      
      repeat
      state := touch_Get(TOUCH_STATUS); // get touchscreen status
      n := img_Touched(hndl,-1) ;
      
      //-------------------------------------------------------------
      if(state == TOUCH_PRESSED) // if there's a press
      x := touch_Get(TOUCH_GETX);
      y := touch_Get(TOUCH_GETY);
      endif
      //-------------------------------------------------------------
      if(state == TOUCH_RELEASED) // if there's a release
      endif
      //-------------------------------------------------------------
      if(state == TOUCH_MOVING) // if it's moving
      x := touch_Get(TOUCH_GETX);
      y := touch_Get(TOUCH_GETY);
      if (n == iSlider1) moveSlider1() ;
      //if (n == iSlider2) moveSlider2() ;
      // if (n == iSlider3) moveSlider3() ;
      //if (n == iSlider4) moveSlider4() ;
      endif
      forever
      endfunc

      Comment

      Working...
      X