Announcement

Collapse
No announcement yet.

uadd_3232 et UDEC5ZB

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

  • #46


    In this manual â_â means space.To validate a command you need to send a CR character or CR/LF and the MAD answer endswith a CR character. (Not written in manual examples).

    When you send a command, send "SG" then a CR. When you are receiving an answer, you will get the text string terminated by a CR.

    If you post your current code (or email it), I can have a look....
    _______________
    Best Regards,
    Howard

    Comment


    • #47
      I'll pass code where I work now is the example you gave me spent more pieces that I added for testing.

      there is a small LED that is active only on fixed values., and a keyboard that I have to try to get the value for comparison with the weight value.

      thank you for your help
      thierry



      #platform "uLCD-32PT_GFX2"

      // Program Skeleton 1.0 generated 04/10/2012 16:39:52

      #inherit "4DGL_16bitColours.fnc"

      #inherit "VisualConst.inc"

      #inherit "serial16Const.inc"

      #inherit "ledDigitsDisplay.inc"
      func ledDigitsDisplay_str(var strptr, var index, var left, var Digits, var MinDigits, var WidthDigit, var LeadingBlanks)
      //ledDigitsDisplay_str(ledbufptr, iLeddigits1+1, 13, 6, 5, 32, 1) ;
      // strptr is a string pointer to the start of the chars to display
      var strlength; //Length of the string we are displaying
      var i; //Counter
      var k; //The number to display (for each position)

      strlength := str_Length(strptr); //Get the length of the string
      if(strlength == 0) return; //If null (0 length) just return
      for(i:=0; i<Digits; i++)
      if(i >= (Digits-strlength)) //If the current position is represented by a char in the string
      k:= lookup8(str_GetByte(strptr++),"0123456789")-1; //and if the char is a number then show it
      else
      if (i >=(Digits - MinDigits)) //If not, but is within the minimum # of digits to show,
      k := 00; //then show a zero
      else
      if (LeadingBlanks) k:=-1; else k:=0; //Blank leading zeros (except minimum segments)?
      endif
      endif

      img_SetWord(hndl, index, IMAGE_INDEX, k);
      img_SetWord(hndl, index, IMAGE_XPOS, left+i*WidthDigit) ;
      img_Show(hndl, index);
      next
      endfunc
      func main()
      // var hstrings ; // Handle to access uSD strings, uncomment if required
      // var hFontx ; // Handle to access uSD fonts, uncomment if required and change n to font number
      // Uncomment the following if uSD images, fonts or strings used.

      putstr("chargement...\n");
      if (!(disk:=file_Mount()))
      while(!(disk :=file_Mount()))
      putstr("voir carte sd...");
      pause(200);
      gfx_Cls();
      pause(200);
      wend
      endif
      gfx_TransparentColour(0x0020);
      gfx_Transparency(ON);

      // hFontn := file_LoadImageControl("serial16.dan", "serial16.gcn", 1); // Open handle to access uSD fonts, uncomment if required and change n to font number dropping a and c if > 9
      // hstrings := file_Open("serial16.txf", 'r') ; // Open handle to access uSD strings, uncomment if required
      hndl := file_LoadImageControl("serial16.dat", "serial16.gci", 1);
      pause(200);
      gfx_Cls();

      // logorp 1.0 generated 15/10/2012 10:13:50
      img_Show(hndl,ilogorp) ; // logo entreprise suivant client
      img_Show(hndl, iLeddigits1); // show all digits at 0, only do this once
      img_Show(hndl, iWinbutton1); // show button, only do this once


      var comRX[10] ;
      var strbuf[10]; //String buffer. Hold 20 chars
      var strbufptr; //A byte pointer to the string buffer array
      var strbufctr; //A counter so we know how many bytes are in the string buffer
      var ledbuf[10];
      var ledbufptr;
      var i;
      var x,y;
      var p;
      var val32[2]; //Holds the 32 bit value of the Ascii-encoded characters
      var val32a[2];
      var val32ptr;
      var poids;


      //var val32a[2] :=[0x0000,0x0000]; //Init 32 bit value to 12345678 decimal
      //var val32a[2] :=[0x0000,0x0000]; //Init 32 bit value to 0 decimal
      //var val32b[2] :=[0x0001,0x0000]; //Init 32 bit value to 1 decimal


      com1_Init(comRX,20,0); // use a comms buffer of 20 characters, not really necessary here, but might be needed for more complex programs
      txt_FontID(FONT3) ; // large font
      touch_Set(TOUCH_ENABLE); // enable touch

      to (COM1);print("SG\r");

      //serout1("SG\r");



      repeat
      strbufctr := 0; //Init counter to zero
      strbufptr := str_Ptr(strbuf); //Make a byte pointer to beginning of saved ASCII chars
      mem_Set(strbuf,0x00,sizeof(strbuf)*2); //Initilize the buffer to all 0 so it is nul terminated
      // gfx_MoveTo(0,55);
      // print(" "); //Erase last input chars
      //gfx_MoveTo(0,55);

      repeat
      if (com1_Count() != 0) // is there something on the comms port?
      i := serin1() ; // yes get it and see what it is
      serout(i); //Echo the input char back to terminal for testing
      if(lookup8(i,"0123456789")) //Is the ASCII char a valid number?
      // print(" ",[CHR] i," ",strbufctr," "); //Show it on display

      str_PutByte(strbufptr++,i); //and stuff it into the string buffer
      strbufctr++; //Increment the character counter
      if ((i =='k') &amp;&amp; (i++ == 'g'))
      x == 10;
      if(i == 'g')
      x == 20;

      endif
      endif
      endif
      endif
      until ((strbufctr >= 20) || (i=='\r\n')) ; //Loop until we have 20 chars or character = lf


      gfx_MoveTo(0,80);
      strbufptr := str_Ptr(strbuf); //Refresh string pointer to point back at beginning of the buffer

      str_GetD(&amp;strbufptr,val32); //Get a 32 bit value from the ASCII number string

      val32ptr := str_Ptr(val32);

      to(ledbuf);str_Printf(&amp;val32ptr,"%ld");
      //str_Printf(&amp;val32ptr,"%ld");

      ledbufptr := str_Ptr(ledbuf);
      // uadd_3232(val32a, val32[1],val32[0]);



      /* print ("MSW: ",[HEX4] val32[1]," LSW: ",[HEX4] val32[0],"\n"); //and print the values in Hex
      print ("MSW: ",[UDEC5ZB] val32[1]," LSW: ",[UDEC5ZB] val32[0],"\n");
      print ("str ",strbuf,"\n");
      print ("buffer ",&amp;strbufptr,"\n");
      print ("unit&eacute;e ", [DEC] x ,"\n ");
      print("tram " ,ledDigitsDisplay,"\n") ;
      print ("val ",[DEC] val32ptr,"\n");*/


      // Leddigits1 1.0 generated 15/10/2012 08:49:38

      ledDigitsDisplay_str(ledbufptr, iLeddigits1+1, 44, 6, 2, 32, 1) ;

      // Winbutton1 1.0 generated 15/10/2012 11:41:36
      if(touch_Get(TOUCH_STATUS) == TOUCH_PRESSED) // scan for touch
      x := touch_Get(TOUCH_GETX); // get x coordinate
      y := touch_Get(TOUCH_GETY); // get y coordinate
      if( (x >= 8 &amp;&amp; x <= 108) &amp;&amp; (y >= 160 &amp;&amp; y <= 200) ) // coordinates for Start Button
      img_SetWord(hndl, iWinbutton1, IMAGE_INDEX,0);// (img_GetWord(hndl, iWinbutton1, IMAGE_FLAGS) | I_STAYONTOP) &amp; ~I_TOUCH_DISABLE); // set to enable touch, only need to do this once

      img_Show(hndl, iWinbutton1); // show button, only do this once
      pause(200);
      img_SetWord(hndl, iWinbutton1, IMAGE_INDEX, 1); // where state is 0 for up and 1 for down
      img_Show(hndl,iWinbutton1) ;
      to (COM1);print("SG\n");


      endif
      endif



      //****** petit voyant*********

      poids := val32[0];

      if ((poids >= 100)&amp;&amp; (poids<=499))
      gfx_EllipseFilled(14, 66, 10, 10, RED) ;
      else if ((poids >= 500)&amp;&amppoids<=1000))
      gfx_EllipseFilled(14, 66, 10, 10, GREEN) ;
      else if (poids >= 1001)
      gfx_EllipseFilled(14, 66, 10, 10, YELLOW) ;
      else
      gfx_EllipseFilled(14, 66, 10, 10, BLACK) ;
      endif


      forever


      endfunc
      func clav ()

      // Keyboard1 1.0 generated 24/10/2012 11:23:37
      img_Show(hndl,iKeyboard1) ; // show initial keyboard
      for (i := iKeyboard1+1; i <= iKeyboard1+oKeyboard1[KbButtons]; i++)
      img_SetWord(hndl, i, IMAGE_FLAGS, (img_GetWord(hndl, i, IMAGE_FLAGS) | I_STAYONTOP) &amp; ~I_TOUCH_DISABLE); // set to enable touch, only need to do this once
      next
      // keydown event
      if ((n >= iKeyboard1) &amp;&amp; (n <= iKeyboard1+oKeyboard1[KbButtons]))
      kbDown(iKeyboard1, oKeyboard1, iKeyboard1keystrokes, n-iKeyboard1, KbHandler) ;
      endif
      // keyup event
      if (oKeyboard1[KbDown] != -1) kbUp(iKeyboard1, oKeyboard1) ;


      endfunc

      Comment


      • #48
        I'll pass code where I work now is the example you gave me spent more pieces that I added for testing.

        there is a small LED that is active only on fixed values., and a keyboard that I have to try to get the value for comparison with the weight value.

        thank you for your help
        thierry

        #platform "uLCD-32PT_GFX2"

        // Program Skeleton 1.0 generated 04/10/2012 16:39:52

        #inherit "4DGL_16bitColours.fnc"

        #inherit "VisualConst.inc"

        #inherit "serial16Const.inc"

        #inherit "ledDigitsDisplay.inc"
        func ledDigitsDisplay_str(var strptr, var index, var left, var Digits, var MinDigits, var WidthDigit, var LeadingBlanks)
        //ledDigitsDisplay_str(ledbufptr, iLeddigits1+1, 13, 6, 5, 32, 1) ;
        // strptr is a string pointer to the start of the chars to display
        var strlength; //Length of the string we are displaying
        var i; //Counter
        var k; //The number to display (for each position)

        strlength := str_Length(strptr); //Get the length of the string
        if(strlength == 0) return; //If null (0 length) just return
        for(i:=0; i<Digits; i++)
        if(i >= (Digits-strlength)) //If the current position is represented by a char in the string
        k:= lookup8(str_GetByte(strptr++),"0123456789")-1; //and if the char is a number then show it
        else
        if (i >=(Digits - MinDigits)) //If not, but is within the minimum # of digits to show,
        k := 00; //then show a zero
        else
        if (LeadingBlanks) k:=-1; else k:=0; //Blank leading zeros (except minimum segments)?
        endif
        endif

        img_SetWord(hndl, index, IMAGE_INDEX, k);
        img_SetWord(hndl, index, IMAGE_XPOS, left+i*WidthDigit) ;
        img_Show(hndl, index);
        next
        endfunc
        func main()
        // var hstrings ; // Handle to access uSD strings, uncomment if required
        // var hFontx ; // Handle to access uSD fonts, uncomment if required and change n to font number
        // Uncomment the following if uSD images, fonts or strings used.

        putstr("chargement...\n");
        if (!(disk:=file_Mount()))
        while(!(disk :=file_Mount()))
        putstr("voir carte sd...");
        pause(200);
        gfx_Cls();
        pause(200);
        wend
        endif
        gfx_TransparentColour(0x0020);
        gfx_Transparency(ON);

        // hFontn := file_LoadImageControl("serial16.dan", "serial16.gcn", 1); // Open handle to access uSD fonts, uncomment if required and change n to font number dropping a and c if > 9
        // hstrings := file_Open("serial16.txf", 'r') ; // Open handle to access uSD strings, uncomment if required
        hndl := file_LoadImageControl("serial16.dat", "serial16.gci", 1);
        pause(200);
        gfx_Cls();

        // logorp 1.0 generated 15/10/2012 10:13:50
        img_Show(hndl,ilogorp) ; // logo entreprise suivant client
        img_Show(hndl, iLeddigits1); // show all digits at 0, only do this once
        img_Show(hndl, iWinbutton1); // show button, only do this once


        var comRX[10] ;
        var strbuf[10]; //String buffer. Hold 20 chars
        var strbufptr; //A byte pointer to the string buffer array
        var strbufctr; //A counter so we know how many bytes are in the string buffer
        var ledbuf[10];
        var ledbufptr;
        var i;
        var x,y;
        var p;
        var val32[2]; //Holds the 32 bit value of the Ascii-encoded characters
        var val32a[2];
        var val32ptr;
        var poids;


        //var val32a[2] :=[0x0000,0x0000]; //Init 32 bit value to 12345678 decimal
        //var val32a[2] :=[0x0000,0x0000]; //Init 32 bit value to 0 decimal
        //var val32b[2] :=[0x0001,0x0000]; //Init 32 bit value to 1 decimal


        com1_Init(comRX,20,0); // use a comms buffer of 20 characters, not really necessary here, but might be needed for more complex programs
        txt_FontID(FONT3) ; // large font
        touch_Set(TOUCH_ENABLE); // enable touch

        to (COM1);print("SG\r");

        //serout1("SG\r");



        repeat
        strbufctr := 0; //Init counter to zero
        strbufptr := str_Ptr(strbuf); //Make a byte pointer to beginning of saved ASCII chars
        mem_Set(strbuf,0x00,sizeof(strbuf)*2); //Initilize the buffer to all 0 so it is nul terminated
        // gfx_MoveTo(0,55);
        // print(" "); //Erase last input chars
        //gfx_MoveTo(0,55);

        repeat
        if (com1_Count() != 0) // is there something on the comms port?
        i := serin1() ; // yes get it and see what it is
        serout(i); //Echo the input char back to terminal for testing
        if(lookup8(i,"0123456789")) //Is the ASCII char a valid number?
        // print(" ",[CHR] i," ",strbufctr," "); //Show it on display

        str_PutByte(strbufptr++,i); //and stuff it into the string buffer
        strbufctr++; //Increment the character counter
        if ((i =='k') &amp;&amp; (i++ == 'g'))
        x == 10;
        if(i == 'g')
        x == 20;

        endif
        endif
        endif
        endif
        until ((strbufctr >= 20) || (i=='\r\n')) ; //Loop until we have 20 chars or character = lf


        gfx_MoveTo(0,80);
        strbufptr := str_Ptr(strbuf); //Refresh string pointer to point back at beginning of the buffer

        str_GetD(&amp;strbufptr,val32); //Get a 32 bit value from the ASCII number string

        val32ptr := str_Ptr(val32);

        to(ledbuf);str_Printf(&amp;val32ptr,"%ld");
        //str_Printf(&amp;val32ptr,"%ld");

        ledbufptr := str_Ptr(ledbuf);
        // uadd_3232(val32a, val32[1],val32[0]);



        /* print ("MSW: ",[HEX4] val32[1]," LSW: ",[HEX4] val32[0],"\n"); //and print the values in Hex
        print ("MSW: ",[UDEC5ZB] val32[1]," LSW: ",[UDEC5ZB] val32[0],"\n");
        print ("str ",strbuf,"\n");
        print ("buffer ",&amp;strbufptr,"\n");
        print ("unit&eacute;e ", [DEC] x ,"\n ");
        print("tram " ,ledDigitsDisplay,"\n") ;
        print ("val ",[DEC] val32ptr,"\n");*/


        // Leddigits1 1.0 generated 15/10/2012 08:49:38

        ledDigitsDisplay_str(ledbufptr, iLeddigits1+1, 44, 6, 2, 32, 1) ;

        // Winbutton1 1.0 generated 15/10/2012 11:41:36
        if(touch_Get(TOUCH_STATUS) == TOUCH_PRESSED) // scan for touch
        x := touch_Get(TOUCH_GETX); // get x coordinate
        y := touch_Get(TOUCH_GETY); // get y coordinate
        if( (x >= 8 &amp;&amp; x <= 108) &amp;&amp; (y >= 160 &amp;&amp; y <= 200) ) // coordinates for Start Button
        img_SetWord(hndl, iWinbutton1, IMAGE_INDEX,0);// (img_GetWord(hndl, iWinbutton1, IMAGE_FLAGS) | I_STAYONTOP) &amp; ~I_TOUCH_DISABLE); // set to enable touch, only need to do this once

        img_Show(hndl, iWinbutton1); // show button, only do this once
        pause(200);
        img_SetWord(hndl, iWinbutton1, IMAGE_INDEX, 1); // where state is 0 for up and 1 for down
        img_Show(hndl,iWinbutton1) ;
        to (COM1);print("SG\n");


        endif
        endif



        //****** petit voyant*********

        poids := val32[0];

        if ((poids >= 100)&amp;&amp; (poids<=499))
        gfx_EllipseFilled(14, 66, 10, 10, RED) ;
        else if ((poids >= 500)&amp;&amppoids<=1000))
        gfx_EllipseFilled(14, 66, 10, 10, GREEN) ;
        else if (poids >= 1001)
        gfx_EllipseFilled(14, 66, 10, 10, YELLOW) ;
        else
        gfx_EllipseFilled(14, 66, 10, 10, BLACK) ;
        endif


        forever


        endfunc
        func clav ()

        // Keyboard1 1.0 generated 24/10/2012 11:23:37
        img_Show(hndl,iKeyboard1) ; // show initial keyboard
        for (i := iKeyboard1+1; i <= iKeyboard1+oKeyboard1[KbButtons]; i++)
        img_SetWord(hndl, i, IMAGE_FLAGS, (img_GetWord(hndl, i, IMAGE_FLAGS) | I_STAYONTOP) &amp; ~I_TOUCH_DISABLE); // set to enable touch, only need to do this once
        next
        // keydown event
        if ((n >= iKeyboard1) &amp;&amp; (n <= iKeyboard1+oKeyboard1[KbButtons]))
        kbDown(iKeyboard1, oKeyboard1, iKeyboard1keystrokes, n-iKeyboard1, KbHandler) ;
        endif
        // keyup event
        if (oKeyboard1[KbDown] != -1) kbUp(iKeyboard1, oKeyboard1) ;


        endfunc

        Comment


        • #49
          repeat
          if (com1_Count() != 0) // is there something on the comms port?
          i := serin1() ; // yes get it and see what it is
          serout(i); //Echo the input char back to terminal for testing
          if(lookup8(i,"0123456789")) //Is the ASCII char a valid number?
          // print(" ",[CHR] i," ",strbufctr," "); //Show it on display

          str_PutByte(strbufptr++,i); //and stuff it into the string buffer
          strbufctr++; //Increment the character counter
          if ((i =='k') &amp;&amp; (i++ == 'g'))
          x == 10;
          if(i == 'g')
          x == 20;

          endif
          endif
          endif
          endif
          until ((strbufctr >= 20) || (i=='\r\n')) ; //Loop until we have 20 chars or character = lf
          First, i can never equal a CRLF, as that would be two bytes and you are only reading in one at a time. It should just be i=='\r'));

          Second, look where your if(ii=='k') &amp; i++=='g')) line is. It is inside the lookup8() if block, and can never run, since to be in that section of code i has to be 0-9 ASCII.... Also you have x==10 when it should be x:=10

          if(lookup8(i,"0123456789")) //Is the ASCII char a valid number?
          // print(" ",[CHR] i," ",strbufctr," "); //Show it on display

          str_PutByte(strbufptr++,i); //and stuff it into the string buffer
          strbufctr++; //Increment the character counter
          else
          if (i == 'k') x:= 10;
          if (i == 'g') x:= 20;
          endif
          _______________
          Best Regards,
          Howard

          Comment


          • #50
            that is why my search for unity was not walking.
            I take note of that.

            but this part after I removed it sends the code to see.

            I also try removing | | (i == '\ r \ n')) this line until ((strbufctr> = 20) | | (i == '\ r \ n')) and change lae number of characters received.


            without success

            thank you for the remarks they allow me to know a bit better language.

            thank you
            thierry

            Comment


            • #51
              until ((strbufctr >= 20) || (i=='\r\n')) ; //Loop until we have 20 chars or character = lf
              Do you mean like:
              until ((strbufctr >= 5) || (i=='\r')) ; //Loop until we have 5 chars or character = CR
              Question: Is the scale sending a decimal point? Can you hook the scale up a terminal utility and capture the data the scale is sending to a file so I can have a look?
              _______________
              Best Regards,
              Howard

              Comment


              • #52
                hello howard
                no,i did not keep II (i== '\r')); fit only the number of caract&egrave;rs
                thank you see you soon

                Comment


                • #53


                  alors howard

                  les questions de thierry ne tâintÃressent plus ?

                  bye thierry

                  Comment


                  • #54


                    Hi Thierry,

                    If you have questions, feel free to post them. I've been working 65+ hours a week for the last few months getting a project out for IBM, so not sure how much time I can devote to answering questions on the forum, but if I don't answer I'm sure someone else will.....
                    _______________
                    Best Regards,
                    Howard

                    Comment


                    • #55
                      Hey 4DSysFan,

                      I have a question about your function to allow strings to be displayed with LEDDigits. I have the code working on my temp sensor buffer, that is being sent by an arduino. The problem is that I can't figure out how to print a decimal using the LED Digit wiget control. The program you wrote uses this line:
                      img_Show(hndl, index); // show all digits at 0, only do this once
                      when I customize the program, workshop generates this line:
                      img_Show(hndl, iLeddigits1); // show all digits at 0,

                      you are referencing an index, so when this is changed it conflicts and overprints the numbers on top of each other.
                      the other problem is that I can't change the color of the display. If I change it using the workshop wiget control it generates another line:
                      ledDigitsDisplay_str(&strbufptr, iLeddigits1+1, 149, 4, 2, 38, 1) ;
                      which replaces yours and then nothing is displayed.
                      Can you tell me what I am doing wrong.

                      Thanks for your help
                      Last edited by markl; 18th May 2014, 01:08 AM.

                      Comment

                      Working...
                      X