Capture and compare serial data
Hi Guys
Haven't been around in a while and I hope everyone is well :-)
I am trying to do a kind of wireless capture and compare but I have a problem on the receiving end that I lookings for some suggestions on.
Heres the pseudo code:
1.send/transmit 4 bytes 4 times (done and it's working!)
2.receive the 4 bytes 4 times (the receiver receives the 4 bytes 4 times successfully -using serial port tool)
3.Store the 4 instances/lines of 4 bytes (Here's where I have the problem)
4.Compare lines 3 and 4 (or any of the lines with one of the others.This is the other problem I have)
Heres my code:
Code:
'Variables begin here
SYNK VAR BYTE
SYNK = $7E '126 DECIMAL, BINARY 11111110
TRAIN VAR BYTE
TRAIN = $B3
WNUM VAR BYTE
XNUM VAR BYTE
YNUM VAR BYTE
ZNUM VAR BYTE
WNUM = 31
XNUM = 1
YNUM = 2
znum = 2
'end of variables
main:
low led 'set led low
If GPIO.2 = 1 then main 'check button
send:
for counter = 0 to 3
DEBUG train,train,train,train,train,synk,WNUM,XNUM,YNUM,ZNUM,$d,$a
next counter
high led 'set led high
pause 200
goto main
end
So as you can see I use DEBUG to send the same this to the serial port 4 times which renders this output in the serial tool:
Quote:
³³³³³~
³³³³³~
³³³³³~
³³³³³~
which converted to DECIMAL looks like this:
Quote:
17917917917917912631122
17917917917917912631122
17917917917917912631122
17917917917917912631122
PERFECT but .....
How can I receive and store each instance of WNUM,XNUM,YNUM,ZNUM.
In other words I would like to have four instances of WNUM,XNUM,YNUM,ZNUM, so I could compare each instance of WNUM,XNUM,YNUM and ZNUM.
What is the best way to do it ?
Would I use 4 different arrays?
For example array1 would hold the first line conatining the values for WNUM,XNUM,YNUM,ZNUM.
Array2 would hold the values for the second line and array3 for line 3 and array4 for line 4.
Some help would really be appreciated.
Kind regards
Dennis
Apologies for the bad english ...
In my frustration @ myself and my rush to post I really messed up the english for this line
Quote:
I am trying to do a kind of wireless capture and compare but I have a problem on the receiving end that I lookings for some suggestions on.
What it should read is :
I am trying to do a kind of wireless capture and compare but I have a problem on the receiving end that I am looking for some suggestions on.
Looking forward to your replies
Thanks so much
Dennis
Thanks to all have replied so far..
@ Charles ..thanks a million for the tips will check them out as soon as I have the array(s) built up.
@ Al .. Thanks for the tip there , has me wondering how I can put the 2D array to use for my a solution.
I am guessing as a start I should replace the DEBUG sommand with something like serin2 and build the array with one command ?
Something like :
Code:
SerIn2 GPIO.4,T2400,500, main,[WAIT(SYNK),STR DATAIN\4]
This would indeed create an array and store the 4 bytes and the checksum byte.
But again I want to to do this 4 times and have either one array with the contents of each time OR I could try have 4 different arrays (one created for each time) and then check the checksum values for each array.
Now I am wondering if I am doing the right thing , perhaps I should rather have more SYNK/qualifier bytes and send and receive one instance of the data and checksum that.
Problem is that sometimes some corruption occurs at the receiver side so to solve this I thought it best to send more instances of the same data.
Any more suggestions are welcome
Kind regards
Dennis