Announcement

Collapse
No announcement yet.

serin() dropping characters?

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

  • tonton81
    replied
    well it should be global hehe

    Leave a comment:


  • jmracepoint
    replied
    I think there may be a stack issue. If I declare the buffer array outside of main, everything works as expected.

    Leave a comment:


  • jmracepoint
    replied
    That was a typo when I copied and pasted into the forum. My code does in fact have the := there. I was hoping that would be the issue but I double-checked. It doesn't compile without the :.

    Leave a comment:


  • tonton81
    replied

    command = serin(); shouldnt it be := ?

    Leave a comment:


  • jmracepoint
    replied
    I am using the qualifier with length requirement to ensure that I don't read before the 4th byte is received. You can see from my command string that the qualifier is sent followed by the length (0x04) followed by the 4 data bytes. I can confirm this is working since nothing is written until the 4th byte is sent.

    Leave a comment:


  • tonton81
    replied
    yeah but reading the com port before it has the bytes in the buffer can lead to that type of behavior

    the tight loop could start reading 4 bytes while you sent it the first 3, before the 4th finished, leading to random garbage on the next pull

    Leave a comment:


  • jmracepoint
    replied
    I'm not checking because this is a test to figure out why it's not working. I know I am sending 4 bytes and have previously checked the # of bytes.

    But just for reference, here is the declaration:

    var combuf[255];

    Leave a comment:


  • tonton81
    replied
    why are you not checking available bytes in buffer before pulling them? is your com buffer really 3/4 bytes wide? i dont see the size of it

    Leave a comment:


  • jmracepoint
    started a topic serin() dropping characters?

    serin() dropping characters?

    I am having an issue using serin().

    Here is my code:

    Code:
    com_Init(combuf, 0, ':');
    
    repeat
    until(com_Full()); // loop until buffer is full
    
    serout(serin());
    serout(serin());
    serout(serin());
    serout(serin());
    Here is the terminal output.
    2:14:20 PM > 3A 04 31 32 33 34
    2:14:25 PM < 31 32 33 34

    You can see that the 4 bytes are echoed properly.

    However, this code fails:

    Code:
    com_Init(combuf, 0, ':');
    
    repeat
    until(com_Full()); // loop until buffer is full
    
    command := serin();
    serout(serin());
    serout(serin());
    serout(serin());
    Here is the terminal output.
    2:14:20 PM > 3A 04 31 32 33 34
    2:14:25 PM < 00 33 34

    You can see that the 3 bytes are not echoed properly, the first byte should have been 32, but 00 was output.

    I suspect the issue is with the word width of the variable command, but would like some clarification on what I am doing wrong here.
    Last edited by jmracepoint; 21 September 2017, 05:48 AM.
Working...
X