Trying to sniff and display data. Need some help with code.
Don M
Posts: 1,653
I am sniffing a 9600 baud buss. I'm having trouble getting the data to display correctly.
Here's my code:
And here's a screen shot from the Logic Analyzer:
You can see there is quite a delay once the data quits and the data is printed to PST.
I have tried changing mdbm.rx_time from (1) to (2) ms and with 1 ms it prints each individual byte on each line like this:
Changing it to (2) ms prints the 2 bytes together on the line like I want but sometimes it misses a beat and prints either 1 or 3 bytes.
I think my problem is with the code determining when the data quits coming into the buffer but I don't know how to solve it.
Maybe I need to do this a different way? Looking for any help or suggestions. I'll be adding a second receive line that responds to this and try to get it to line up and print correctly.
Sorry if I'm not explaining myself well here.
Thanks.
Don
Here's my code:
repeat d := mdbm.rx_time(2) if(d <> -1) ' anything from Master? bufm[0] := d & $0_FF ' strip off address bit i := 1 ' set index counter to 1 repeat ' if data present repeat until d := mdbm.rx_time(2) ' no data present or until 36 bytes received if(d == -1) or (i => 36) ' exit repeat quit ' store data in bufm indexed by i bufm[i] := d ' increment index i i++ ' assign i to num_bytes num_bytes := i ' print M" on PST term.str(string(" M: ")) ' print data on PST from bufm repeat i from 0 to num_bytes - 1 term.hex(bufm[i], 2) term.tx(" ") term.tx(13)
And here's a screen shot from the Logic Analyzer:
You can see there is quite a delay once the data quits and the data is printed to PST.
I have tried changing mdbm.rx_time from (1) to (2) ms and with 1 ms it prints each individual byte on each line like this:
Changing it to (2) ms prints the 2 bytes together on the line like I want but sometimes it misses a beat and prints either 1 or 3 bytes.
I think my problem is with the code determining when the data quits coming into the buffer but I don't know how to solve it.
Maybe I need to do this a different way? Looking for any help or suggestions. I'll be adding a second receive line that responds to this and try to get it to line up and print correctly.
Sorry if I'm not explaining myself well here.
Thanks.
Don
Comments
The rx_time(x) method waits x ms for data and returns a -1 if no data.
My guess is you'd be better off just using rxcheck instead of rx_time and use a separate cog to monitor for idle times (unless you can use a beginning or ending marker).
Edit: This might be easy to do from the PASM part of the driver. You could start a timer after each stop bit and indicate to the parent object when a delay above a set amount of time occurs.
Which serial driver are you using?
The problem is that the commands vary in length and different manufacturers of "Masters" send the data at different intervals so timing becomes an issue.
After some thought here I think I'm going to go a different route. I'm going to look at using one cog to collect the data using case statements to define the length of the data collection since they are known and defined. Then use a main cog to display the data that was stored in the buffers.
For asynchronous serial communications to work both the sender and receiver need to agree on the bit rate and the number of bits in a word. You may need a "smart" logic analyzer to watch your data and interpret it.
Duane- I tried using rx_check method and I will only get 1 byte at a time. I have been working with this off and on for a while and it seems to me that the only difference between rx_check and rx_time is how long after the data starts that it waits to see if there is more. There is a 1.6ms gap between the end of the last byte from the first command and the first byte of the second command. It seems to me that the rx_time method is not accurate enough or there is some other overhead that gets in the way.
I don't know what to do at this point and really need some help with this.
Don