Announcement

Collapse
No announcement yet.

to(outstream) issues

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

  • to(outstream) issues

    All, my setup:
    uLCD-43DT
    IDE 4.3.0.8
    WIN10 PRO

    My to() function seems to not work like I would think:

    Code:
      
    var TX_buffer[200];
    var crc;
    
        to(TX_buffer); print("123456789");
        crc := crc_CSUM_8(TX_buffer, sizeof(TX_buffer));
    
        to(COM0); print("123456789");
        serout(crc); // send CRC out COMM port
    What I would expect is the TX_buffer gets stuffed with "123456789", which it does because the CRC ends up being the "text book example" 0x0023, or 35 decimal.

    Then when I use the terminal I receive:

    00 31 32 33 34 35 36 37 38 39 00 00 00 ......... lots of nulls here then....... 31 32 33 34 35 36 37 38 39 23

    why is it twice??

    Then this configuration.... changing the 2 different to() functions around;
    Code:
      
    var TX_buffer[200];
    var crc;
    
        to(COM0); print("123456789");
    
        to(TX_buffer); print("123456789");
        crc := crc_CSUM_8(TX_buffer, sizeof(TX_buffer));
        serout(crc); // send CRC out COMM port
    I receive this on the terminal:
    31 32 33 34 35 36 37 38 39 00 31 32 33 34 35 36 37 38 39 00 00 00 00 00 00 00 ...... lots of nulls here then ..... 23


    EDITED:
    Also, interesting note:
    Code:
      
    var TX_buffer[200];
    var crc;
    
        to(TX_buffer); print("123456789");
        crc := crc_CSUM_8(TX_buffer, sizeof(TX_buffer));
        serout(crc); // send CRC out COMM port
    This code will also send out a complete stream to the COM port:
    00 31 32 33 34 35 36 37 38 39 00 00 00 00 00 00 00 ...... lots of nulls here then ..... 23

    So maybe my issue is my serout() command???

    Why is my TX_buffer also getting added into my COM0 outstream?

    What I would like to accomplish is:
    calculate CSUM
    send String to COMM port
    send CRC to COMM port


    Thanks,
    Keith

    Last edited by ch701builder; 14th February 2017, 04:29 AM.

  • #2
    Hi ch701builder,

    Have you tried or able in your setup to send the string and crc through COM1?

    Code:
    var TX_buffer[200];
    var buffer[10];
    var crc;
    
    //---
    
       COM1_RX_pin(PA2);
       COM1_TX_pin(PA3);
       com_SetBaud(COM1, 960);
       com1_Init(buffer, 20, 0 );
    
        to(TX_buffer); print("123456789");
        crc := crc_CSUM_8(str_Ptr(TX_buffer), sizeof(TX_buffer));
    
        to(COM1); print("123456789");
        to(COM1); putch(crc);
        to(COM1); putch('\n');
    The serial example might interest you as well. 'File' - 'Samples' - 'Picaso Designer' - 'BUFFEREDTX'.

    Hope this helps,
    Last edited by Joseph Herrera; 14th February 2017, 05:02 PM.

    Comment


    • #3
      Joseph,
      I haven't tried re-configuring my system for the different COM port yet, but it still doesn't explain why the following code:

      Code:
        
      var TX_buffer[200];
      var crc;
      
          to(TX_buffer); print("123456789");
          crc := crc_CSUM_8(TX_buffer, sizeof(TX_buffer));
          to(COM0); print([CHR]crc);
      has a result of:
      00 31 32 33 34 35 36 37 38 39 00 00 00 00 00 00 00 00 .................................................... 00 00 00 00 23

      isn't the to(outstream) only supposed to print out the CRC, and then after the print() is done, it defaults back to TEXT to screen? the append() is supposed to takeup where the to() left off.
      Also, why is my whole TX_buffer[200] being sent to the COM port when only the CRC is supposed to be sent?


      Here is another interesting example just to see if both, buffer, and to(outstream) get sent:
      Code:
        
      
      var TX_buffer[200];
      var crc;
      
          to(TX_buffer); print("123456789");
          crc := crc_CSUM_8(TX_buffer, sizeof(TX_buffer));
      
          to(COM0); print("$CPYMAIN_DIR.TXT");
          to(COM0); print([CHR]crc);
      Here is the result from the 4D built in Tools Terminal 9600
      00 31 32 33 34 35 36 37 38 39 00 00 00 00 00 00 00 00 00 00 .................... 00 00 00 00 00 00 24 43 50 59 4D 41 49 4E 5F 44 49 52 2E 54 58 54 23

      The TX_buffer 123456789 is first??? then there are numerous NULLS, then followed with the $CPYMAIN_DIR.TXT which I expected to be first... followed by the CRC which is correct for the TX_buffer of "123456789"........

      All tests are with the built-in >Tools>Terminal 9600 program.
      EDITED----
      I also tried Hyperterminal and I get the same results.. so it isn't a Terminal issue...
      EDITED---
      I just tried sending the COM to Arduino Mega2560 and using its built in Terminal..... same thing.....


      Keith





      Last edited by ch701builder; 15th February 2017, 01:05 AM.

      Comment


      • #4
        All, My workaround.

        First
        sizeof()
        doesn't look for the first NULL character. It returns the complete buffer, so in my example it would return 200 since my TX_buffer was 200.
        I used str_Length() instead.
        p := str_Ptr(TX_buffer); // p = pointer to TX_buffer
        len := str_Length(p); // len = length of TX_buffer text

        Then I used this value into the crc_CSUM_8() as the length.

        Then I created a loop to send out my TX_buffer using
        str_ByteMove(p + i, dest, 1);
        to(COM0); print([CHR]dest);

        Then I followed up with
        to(COM0); print([CHR]crc); // send CRC CheckSum
        to send my crc value.

        seems to be working, but not understanding why my TX_buffer was always being sent out the COM even though I never issued a command (that I can tell) to send it.

        Have a good day everybody!!!

        Keith


        Comment


        • #5
          Hi Keith,

          Currently, the command 'crc_CSUM_8(buf, count)' uses the COM0, so it might be the reason it is being seen in COM0.

          This will be fixed in the next PmmC Release. Thank You.

          'str_Length()' returns the length of a byte aligned string excluding terminator.
          While 'sizeof()' returns the size of the buffer.

          Thank you and Regards,

          Comment


          • #6
            All,
            Since I started this thread, my current issues might somewhat still be related.
            The following code (not complete) works in my little testing program -- 1600 bytes and 340 lines works just like it should.... but.... when I transfer it into my main program 19,000 bytes and 4000 lines, my pointers point to ?????.

            I have even tried local vars for p, len, crc, dest, i..... but it doesn't work. TX_buffer DOES contain the expected data, as I verify that with my print, (in both the small checkout program and the big main program) but when I use my terminal program (the built in tools, terminal) I get different results. Even if I rem out the crc statement, I get different results.

            All I have done is copied from my small working program into my big main program. I have tried different items such as also use serout(??), and that doesn't send out just 1 char, it sends out the length of TX_buffer some bogus value. Sometimes it's 00, sometimes it's A0, sometimes it's ??????

            I can re-arrange my var positions and func locations in my main program and even get different results of what is sent out the serial port.

            You will notice that I have 2 different CRC routines. The built in CRC messes up the COM0 function, but if you print out 1 char at a time it works. Otherwise if you use the to(COM0); print(????????), it prints it out twice. I have even tried to print out to COM0 before I do the crc and that doesn't always have the correct results.

            Any ideas???

            Code:
            func send_TX_buffer()
            
                ACK := 0;
            
                // print TX_buffer to screen just to let user know something is
                // happening
                print("TX_buffer = ",[STR]TX_buffer,"\n");
            
                while (ACK == 0)  // stay in this loop until we receive an ACK from Arduino
                    //===================================================================
            
                    p := str_Ptr(TX_buffer);            // p = pointer to TX_buffer
                    len := str_Length(p);               // len = length of TX_buffer text
                    len++;
                    crc := crc_CSUM_8(TX_buffer, len);  // builtin 4D perform CRC CheckSum
            //        crc := crc_CSUM8(TX_buffer, len);  // my version perform CRC CheckSum
            
                    dest := str_Ptr(temp);              // setup destination for each byte
                    for (i := 0; i < len; i++)
                        str_ByteMove(p + i, dest, 1);
                        to(COM0); print([CHR]dest);
                        pause(1);
                    next
            
                    to(COM0); print([CHR]crc);          // send CRC CheckSum
                    to(COM0); print([CHR]13);
            
                    pause(1);                           // delay for Arduino to setup
            
            //remove when ready to test ACK and NAK

            Comment


            • #7
              All,
              I found a work around.... still don't know what the issue is with the pointers.... but....

              I changed:

              str_ByteMove(p + i, dest, 1)
              to
              dest := str_GetByte(p + i);

              and did calls to my crc_CSUM8() instead of 4D's crc_CSUM_8()

              That way I don't have anything conflicting with the COM0 buffer.

              Later,
              Keith



              Comment

              Working...
              X