Announcement

Collapse
No announcement yet.

Get LEDDigit value as integer over serial and set LED digit

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

  • Get LEDDigit value as integer over serial and set LED digit

    Hi guys,

    So I have a uLCD_32PTU and I want to receive data over serial and then set some LED digits accordingly. So I know how the serial communication works and can read in the values. For example I send the string "S1000" to set the speed to 1000. I can read in "S" as the type and "1000" as a string as the digits. But I don't get how to convert the "1000" string to the number 1000. I need the number to set the digits to the new value.
    Basically I just want to know how to convert a string to a number.

    This is probably a dumb question but I am really getting depressed by this right now.

    Thanks for your help


  • #2
    Hi,

    Have you had a chance to explore the str_GetD(&ptr,&var); function?

    You may find a sample code about that on the Picaso internal functions manual.

    Additionally, this forum post might provide more insights

    convert string to int32
    https://forum.4dsystems.com.au/node/67163

    I hope this helps.

    Best regards,
    Michael

    Comment


    • #3
      Hi Micheal,

      thanks for the quick reply. That helped me a bit but sadly it does not work for me. Sending any 4 digit number results in all vars[] values being zero. I also tried str_GetW() instead. But that leads to the same result.
      Can you tell me what I am doing wrong?
      Thanks

      Here you see my attempt of coding it:

      Code:
         
      repeat
              chReceived := serin1();
              if (chReceived > 0)
                  // Store character in the buffer
                  str_PutByte(pchTextBuffer + counter, chReceived);
                  counter += 1;
                  if (counter >= messageSize)
                      idx := str_GetC(&pchTextBuffer, &typeS);
                      putch(typeS);
                      // string functions
                      while(str_GetD(&pchTextBuffer, &vars[n]) != 0) n:=n+2; //read all the numbers
                      //till we get a non number
                      print( [DEC] vars[1], ":" , [DEC] vars[0], "\n" );
      
      
                      // Speed 1.0 generated 5/14/2019 2:08:39 AM
                      img_Show(hndl, iSpeed);  // show all digits at 0, only do this once
                      ledDigitsDisplay(vars[0]*100+vars[1], iSpeed+1, 0, 3, 1, 59, 1) ;
      
                      counter := 0;
                  endif
              endif
          until (com_Error());

      Comment


      • #4
        Hi,

        I cant really test the snippet that you sent, since I don't have the definition of your variables.

        However, if you're receiving strings like "s100" where the first character is not a number, I don't think while(str_GetD(&pchTextBuffer, &vars[n]) != 0) n:=n+2; will work.

        Since the first character is no a number, n will not be updated.

        I used this snippet to simulate your issue:
        Code:
        var buffer[10]; // character buffer for a source string
        var p; // string pointer
        var n;
        var vars[4]; // for our results
        var i;
        
        func main()
        
        gfx_ScreenMode(LANDSCAPE);
        
        to (buffer); print("s1000");
        
        p:=str_Ptr(buffer);
        p+=1; // offset pointer to ignore the leeter 's'
        print(p,"\n");
        str_GetD(&p,&vars[0]);
        
        print("0: ",vars[0], "\n");
        
        repeat
        forever
        endfunc
        In there, I used an offsetting value so that str_GetD would ignore the first character.

        I hope this helps.

        Best regards,
        Michael

        Comment


        • #5
          Ah ok thank you I figured it out. If I first read in the char it automatically advances in the string and then I can read in the integer. I wrote this explanation in case anyone else has a problem with this.

          Code:
              repeat
                  chReceived := serin1();
                  if (chReceived > 0)
                      // Store character in the buffer
                      str_PutByte(pchTextBuffer + counter, chReceived);
                      counter += 1;
                      if (counter >= messageSize)
                          str_GetC(&pchTextBuffer, &typeS);
                          str_GetD(&pchTextBuffer, &value);
                          //print(value, "\n");
                          counter := 0;
                      endif
                  endif
              until (com_Error());
          endfunc

          Comment

          Working...
          X