No announcement yet.

uadd_3232 et UDEC5ZB

  • Filter
  • Time
  • Show
Clear All
new posts

  • uadd_3232 et UDEC5ZB

    and i have a new problem

    in the piece of code that I sent there are two variable corespondent at high and low for my weight variable received by com1, which is greater than 16 bits.
    msw val32 [1] lsw val32 [0] works well.

    I added to the 32-bit to send the result on leddigitsdisplay.

    I try with uadd_3232 but I do not understand the example manual picaso-GFX2 4DGL internal function.

    page 42

    thank you

  • #2

    Didn't I give you a sample that would work?

    Best Regards,


    • #3

      excuse me howard

      but you already send the link and I do not understand.

      otherwise I do not redemanderais.

      thank you


      • #4

        Can someone translate "redemanderais" ?
        Best Regards,


        • #5

          Hi Thierry,
          I am not sure what you do not understand? The program?

          The program is demonstrating how to display a 32 bit number on the leddigit control. I think that you are asking how to display the 32 bit number that you have?

          If not, try to rephrase the question, and include your source, and I'll try to help.....
          Best Regards,


          • #6

            Can someone translate "redemanderais"?

            I should rest not issue new "re-ask"
            hi howard

            I'll send you the code as soon as I récupèremon workstation I have not taken my backup this weekend.
            I do not understand what is valid and then VALB Vala [0] = 0 valid [1] = 1 then VALB [0] = 0 VALB [1]: = 1, which is four times 16-bit and we add the so-called result.

            I have just two 16-bit signed variable that I want to add and unsigned. because the code I received for the frame decripter series of com1
            retrieves the characters in the buffer, if there are 20 character or the character "\ n" (lf)
            the buffer is displayed and the results are displayed.

            print ("msw" val32 [1], "lsw" val32 [0], "\ n"), the code that I already had.

            if I put val32 [0] in leddigitsdisplay correct value is 0 to 32768 and after displays rectangles with a red cross on the inside.

            I try to leddigitsdisplay ([undec] val32 [0], ileddigit1+1, x, x, x, x);
            I get an error at compile time, I do not know how to write.
            I ask avenue33 and send my address where I can read the writing syntaxes C. I thank

            I'll pass the code on Monday.



            • #7


              look "leddigit -32 bit" on the forum



              • #8

                Hi Thierry,

                The format directives ( [UDEC], [HEX], etc ) modify the representation or interpretation of variables or strings. For example, if A:=4 and I print A, I print the string '4', which is actually the ASCII value 52. If I print([HEX4] A); I get "0004" which is a string of 4 bytes, not the value 4. The format directives ARE NOT type-casters. 4DGL only processes (numerically) signed, 16 bit numbers, you can't type-cast them to any other representation.

                Let's take an example: the decimal number 500. To 4DGL, the number 500 is represented in 16 bits internally in binary as 0000000111110100. It does not know 500 (base 10), or 764 (base 8), or 1F4 (base 16). However, we can say take this binary number and translate it into a string in the HEX format........

                The fact that you are trying leddigitsdisplay ([undec] val32 [0], ileddigit1+1, x, x, x, x); leads me to believe that the value you have in val32[0] has the MSB set, which makes it negative since all vars are signed in 4DGL. But if it were unsigned, the binary value would represent the correct unsigned value that you want. You are probably frustrated, as you can PRINT the correct value, but not get leddigitsdisplay to show it. But, leddigitdisplay takes a number, not a string, so you can't tell it to display the unsigned representation. What you need is a function that can handle the string representation of the number you want to display.

                If you look in the code I linked to, I modified the leddigitsdisplay routine to do exactly that. You store your string representation in a buffer, pass a pointer to the buffer to the leddigitsdisplay_str function, and it will step through the string and display each 0-9 character in the string.....

                So, let's take the signed 16 bit number -1. In binary, 4DGL sees 1111111111111111. If you print it, you see -1. But you want to see 65535 (unsigned decimal) on the display. If A = -1, you:

                to (strbuf); print([UDEC] A);

                This makes a string = "65535" in the buffer. Next, create a string pointer to the buffer. We need a string pointer because we are going to traverse the buffer byte by byte, not word by word.

                strbufptr := str_Ptr(strbuf);

                Note that the ledDigitsDisplay_str indexes the string pointer, so you need the above command before you call the ledDigitsDisplay function so the pointer points to the beginning of the buffer.

                Next, you need to send the address of the string buffer pointer to the ledDigitsDislay_str function:

                ledDigitsDisplay_str(&strbufptr, ileddigits+1,........ etc.

                Now, I am going to assume (from past threads / discussions) that you have the 32 bit value val32[], which contains the MSW and LSW.

                //Let's say var32[] represents the decimal number 12345678
                //or 0x00BC614E hex
                var val32[2] := [0x614e, 0x00bc]; //Allocate variables
                var val32ptr; //A byte pointer to beginning of 32 bit variable
                var strbuf[10]; //Holds the string representation of the number
                var strbufptr; //Holds a string pointer to beginning of string buffer

                Now, get the big string that represents the unsigned value in the 32 bit array. This string can be up to "4294967295".....The str_printf function expects the address of a byte pointer to the data structure:

                val32ptr := str_Ptr(val32); //create byte Pointer to val32 array
                to(strbuf); str_Printf(&val32ptr,"%ld"); //Pass the address of the byte pointer

                Now, the string buffer contains the decimal string representation of the 32 bit word. Next, Pass the address of a string pointer that points to the string buffer:

                strbufptr := str_Ptr(strbuf); Create string point to the string buffer
                ledDigitsDisplay_str(&strbufptr, iLeddigits.....) //and pass the address of the pointer

                Sorry if this seems overly complicated, but in code it is not too bad.... If anyone can simplify it significantly, I am open to suggestions and do not mind someone else entering the discussion!
                Best Regards,


                • #9

                  hello howard
                  I thank you for your explanations, it helps me a lot.
                  I understand that you take the characters one by one to put in memory
                  then read the memory one by one in ledDigitsDisplay.
                  -------------------------------------------------- --------------------
                  he must do so before str_getd (& strbufptr, val32)?

                  the buffer is received it is memory or replace it
                  -------------------------------------------------- -----------------------------

                  strbufctr = the number reaching character.

                  you can only read one character?

                  -------------------------------------------------- -------------------------------

                  I get an error when I write ledDigitsDisplay_str? No. leddigitsdsplay found.
                  is the _str that does not suit him.

                  see you soon
                  thank you


                  • #10

                    If you open the file at , and open the LED_Digit_Test1.4dg file, you will see the function ledDigitsDisplay_str() which would need to be copied to your existing project.

                    str_getd() reads the ascii character buffer, and converts the ascii character representation to a 32 bit value. For example, if you sent over the serial port "12345678", the buffer will contain the ascii chars '1' , '2', '3', etc which are decimal values 49, 50, 51, etc. str_getd() will parse the buffer character by character and calculate the actual decimal value. In reality, you only need to do this if your 4DGL program needs to know the actual value to calculate another value or make a decision based on the value (is my weight to high? etc). If you only need to display the incoming data on the leddigits display, you could also pass the address of the Ascii buffer directly to the ledDigitsDisplay_str function, which would traverse the buffer and convert the ascii values to the appropriate digits.

                    The strbufctr was used to track the number if incoming ascii digits, so that you can't overflow the buffer and crash the program. If your buffer can hold 10 chars, and you send "123456789123456789123456789", you need to ensure that buffer overflow can't occur (it's good programming practice).

                    Not sure what you mean by read only one character.......
                    Best Regards,


                    • #11

                      I'm lost
                      Here is my full code

                      thank you Attached files serial15.4dg (5.7 KB)


                      • #12

                        hello howard

                        I think you saw my post and that you're trying to decode my code crazy.

                        I am completely lost. display the result no longer has anything.

                        has time with small values of the digits led digitsDisplay are less wide.

                        genrela value of 10230. 0 are both half-width less than the other digits 123.

                        please do if you can not look at my code ..

                        thank you thierry


                        • #13

                          Here is what I managed to do. I didn't have a lot of time to look at it.....

                          You will need to change back to com1, change the display type (I have 4.3"), and move the LED locations called out in leddigits display.... Attached files serial15.4dg (6.3 KB)
                          Best Regards,


                          • #14

                            hello howard
                            I thank you for the code gives what I want and I also created another buffer that I call ledbufptr., but I forgot one (val32a) who dragged the wrong place. that's why I was lost ....

                            However, there is a problem with leading zero because I deleted the comma.
                            I have a departing zero and after one I sent four zero six digits on the display unit. test sends 12345 crlf , 0 crlf then it will remain 0000.

                            it should not be serious.

                            ps if you know little leddigitsdisplay display anything other than as 0123456789

                            - + ABCDEF.

                            because I need to neutralise display or if I overload or upperload the scale sends ol ul and I thought writing DEF or -------------.

                            thank you see you soon



                            • #15

                              Are you saying that if you send '0' then a CRLF, you want to see just '0' on the display?

                              If so, then change min digits to 1:

                              //ledDigitsDisplay_str( strptr, index, left, Digits, MinDigits, WidthDigit, LeadingBlanks) ledDigitsDisplay_str(dispbufptr, iLeddigits1+1, 192, 8, 1, 32, 1) ;
                              Best Regards,