Need help receiving data into a buffer
Don M
Posts: 1,652
I am trying to store 6 bytes into a byte buffer. The data is coming in a 9600 baud and here's a screen shot from the Logic analyzer:
As you can see the data is contiguous. I am using a case statement to trigger on the initial byte which is $1_34. From there I want to store the next 6 bytes. Here is a snippet of the code:
I was thinking I could define my byte buffer as valen[6] or even valen[8] to give me a little room. But as you can see from the code I need to make it larger as it seems to be catching some inadvertent $00 that are not in the logic trace.
Here is a screen shot from PST:
If I change "repeat pos from 0 to 8" to "repeat pos from 0 to 7 then it does not get the final byte which is 6A. But what is more concerning to me is why are there extra $00's in the buffer and why do I have to make it so much larger in order to save it?
I don't understand.
Thanks.
Don
Edit: I declared my byte buffer as valen[18] just to make is more than big enough in case you are wondering...
As you can see the data is contiguous. I am using a case statement to trigger on the initial byte which is $1_34. From there I want to store the next 6 bytes. Here is a snippet of the code:
repeat v : \mdb.rx_check if v <> -1 case v $1_34: pos := 0 chksum := v repeat pos from 0 to 8 v := vmc.rx_time(5) valen[pos] := v chksum += v pos++ term.str(string("Valen: ")) repeat pos from 1 to 9 term.hex(valen[pos], 2) term.tx(32) term.tx(13)
I was thinking I could define my byte buffer as valen[6] or even valen[8] to give me a little room. But as you can see from the code I need to make it larger as it seems to be catching some inadvertent $00 that are not in the logic trace.
Here is a screen shot from PST:
If I change "repeat pos from 0 to 8" to "repeat pos from 0 to 7 then it does not get the final byte which is 6A. But what is more concerning to me is why are there extra $00's in the buffer and why do I have to make it so much larger in order to save it?
I don't understand.
Thanks.
Don
Edit: I declared my byte buffer as valen[18] just to make is more than big enough in case you are wondering...
Comments
Also I'm not storing the initial command which is larger than a byte but even so I would think that it would store the "34" portion of it and skip the "1" if I was.
But rx_check only returns one byte (if it doesn't return a -1).
It will only see an $01 or a $34; never a $0134.
Duane- The serial receive object I'm using deals in words so it does return a word. It is a custom object written for me by Jonny Mac several years ago.
Mike- see above. Also I should mention that the data is inverted. So it goes from low to high.
Duane- there is a screen shot of the trace in the very first post. I shows the $0134. I'm using the Saleae analyzer that has the mdb protocol as one of the settings. It labels any data that has the 9th bit set as "address".
Again I'm wondering where the extra $00's are coming from and whether it's my code logic that isn't right to avoid them. I am lost at this point.
Fair enough.
Here's the main code:
Here's a screen shot of the Saleae Logic analyzer trace:
Here's a screen shot of PST:
So again why isn't the "4B" available as the very next byte in the buffer? See my comments in the code as to how I have to get it. What am I doing wrong?
If you look at the logic trace you see 0C (not saved) 00 3F 00 00 4B. But in the buffer it has an extra 00 in it. I realize that I'm not saving all those byte to the buffer but even if you change the code to do so it still gives the same result.
Thanks for your help.
Don
Jonathan
The problem was that I was incrementing pos in my loop when in reality the statement "repeat pos from 0 to 3" already increments pos.... so it got incremented twice.
So here is the fixed code...
Amazing what you can spend hours trying to track down. I hope this helps anyone else that may run into this.
Thanks again.
Don