Announcement

Collapse
No announcement yet.

Odd behaviour using UART

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

  • #16


    could k be an unprintable value? - what are you sending - what is this 0x48 ('0') - 0x48 is not '0' - dec 48 is '0' as 0x30 - are you mixing Hex and Dec values

    Karl

    Comment


    • #17


      Yeah sorry is decimal not hexadecimal. I will try on this way:
      print("k = ", [HEX] k);

      Comment


      • #18


        Hi again . The problem was my PIC wasnt sending correctly. Now i receive perfectly the frequency but i have another problem and its very strange:for(n:=0,k:=0x00;k!='F' k := serin(); if(k > 0) frec[n] := k; ++n; print( [CHR] k ); pause(500); endifnextOn this way it print the number of the frequency perfectly. Every time PIC finish of sending the frequency it sends 'F' character. But i want to capture all the frequency, save it in an array and then show it. But it doesnt work so i try doing it:for(n:=0,k:=0x00;k!='F' k := serin(); if(k > 0) frec[n] := k; ++n; print( [CHR] frec[n] ); pause(500); endifnext
        But it doesnt show anything and it is suppose that frec[n] = k so why it doesnt show anything? My idea is to do this:
        for(n:=0,k:=0x00;k!='F'
        k := serin();
        if(k > 0)
        frec[n] := k;
        ++n;
        endif
        next
        putstr(frec);

        But it only shows the letter F. Hope you can help me.
        Thanks

        Comment


        • #19


          no, that wont work, arrays in 4DGL are generically 16 bit so array indexing occurs 2 bytes at a time - each time you save a char in the array, its saving it as 16bit. If you try to print the result, you will just get the first byte (the low byte), the second byte being a zero (the high byte)

          so try these examples

          [table]

          #platform "uLCD-28PT_GFX2"

          var k, n;
          var freq[10]; // eg 20 character buffer

          // load buffer from serin, terminate on 'F', n hold numchars
          // cant print buffer normally, must loop and putch
          func main()
          repeat
          n := 0;
          repeat
          k := serin(); // if we get a character
          if(k > 0) freq[n++] := k; // save it to the buffer
          until(k=='F');

          // now print the buffer
          k:=0;
          while(n--)
          putch(freq[k++]);
          wend
          putch('');
          forever
          endfunc

          // Here is another example showing how to raise a string pointer'
          // and deal with it as bytes instead of words
          // Also, you can print it normally.

          // load buffer from serin, terminate on 'F', n hold numchars
          func main2()
          var p;
          repeat
          p := str_Ptr(freq); // point to the buffer
          //p := freq
          Regards,
          Dave

          Comment


          • #20


            Thanks!! It works perfectly now!!

            Comment

            Working...
            X