Capture and compare serial data


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default a checksum..

    @Charles and Dave

    I definitely agree with the checksum idea , in fact, it is the checksum concept that has led to the confusion

    As a reference let's use this thread (thanks Art for his input!)
    http://www.picbasic.co.uk/forum/showthread.php?t=12492

    SO from that thread POST #2 one possible method of checksumming is described, since it's fairly straight forward we could use that as a reference.

    So the bytes I would like to transmit are declared as
    WNUM,XNUM,YNUM and ZNUM respectively.

    ***NOTE that this fairly trivial when comparing each byte of a single transmission BUT I am transmitting the same thing 4 times and that's whats confusing me.
    The reason I want to do it 4 (or more) times is because from what I have seen in my tests the first one and/or second received line is usually damaged/corrupted so I figured it is probably best if I compare the third and 4th transmitted lines. Does that make sense?

    Here's an example of the transmit code:

    Code:
    WNUM as byte
    XNUM as byte
    YNUM as byte
    ZNUM as byte
    CHECKSUM as byte
    CHECKSUM = $3F
    
    'now do the XOR checksumming
    Checksum = Checksum ^ WNUM
    Checksum = Checksum ^ XNUM
    Checksum = Checksum ^ YNUM
    Checksum = Checksum ^ ZNUM
    
    'and now TX the data 4 times 
    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,CHECKSUM,$d,$a
         	
               next counter
                  high led 'set led high
            
                 pause 200
        goto main
    end
    On the receiver side the code (as per the thread referenced earlier) would look like this:

    Code:
    'Variables begin here 
       
        SYNK    VAR BYTE
        SYNK = $7E
        WNUM    VAR BYTE
        XNUM    VAR BYTE
        YNUM    VAR BYTE
        ZNUM    VAR BYTE
        CHECKSUM var byte 'this holds the received checksum
        CHECKSUM_CHECK var byte 'hold the XOR'd value
        Checksum_Check = $3F 'this is the checksum value to XOR with 
        
      'Variables end here 
    
    DEBUGIN [WAIT(SYNK),WNUM,XNUM,YNUM,ZNUM,CHECKSUM]
               ' wait for SYNK, when received store next 4 bytes in variables WNUM,XNUM,YNUM,ZNUM
               'then send these to hyperterminal or serial program or wherever 
                
                'checksum the received bytes using XOR with 3F 
                Checksum_Check = Checksum_Check ^ WNUM
                debug "xNUM checksum_check is ",HEX checksum_check
                Checksum_Check = Checksum_Check ^ XNUM
                debug "wNUM checksum_check is ",HEX checksum_check
                Checksum_Check = Checksum_Check ^ YNUM
                debug "yNUM checksum_check is ",HEX checksum_check
                Checksum_Check = Checksum_Check ^ ZNUM
                debug "zNUM checksum_check is ",HEX checksum_check
                
    IF Checksum_Check = Checksum THEN
    DEBUG "WNUM is ",DEC WNUM,"XNUM is ",DEC XNUM,"YNUM is ",DEC YNUM,"ZNUM is ",DEC ZNUM,$d,$a
    ENDIF
    BUT as you can see the receive code only does its thing for each received line. I want to store all 4 lines of data then do a compare of the received lines 3 and 4.

    See the problem is if only one transmission is made (one line) and there is a corruption of a byte (checksum mismatch anywhere in the line) then the TX fails. That is why I thought to send and receive 4 lines (or more) of the same thing and then do a compare.

    I am totally confused (again)

    PLEASE HELP..........!

    Kind regards

    Dennis
    Last edited by Dennis; - 6th April 2010 at 00:34.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Not sure exactly what you are trying to do?

    Send the same thing four times and if any of them fail the whole thing fails? Even if one is good?

    Even doing a compare will not tell you which one is good. Only the checksum (CRC) thing will do that.
    Last edited by mackrackit; - 6th April 2010 at 00:43.
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default something like that :-0

    Hi Dave

    Send same thing 4 times
    so
    1
    2
    3
    4
    and compare instance 3 and 4 'cos usually correction occurs on 1 and 2
    If 3 and 4 match then TX was good.

    Hope that helps

    Kind regards
    Dennis

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    OK, how about this.

    Receive the first two and do nothing with that data because it is most likely bad.

    Do the checksum on data #3.
    if good then ... STOP??
    OR go on and run the check on data #4

    If #4 check then GO ON.

    No compare any where...

    MAYBE...
    Dave
    Always wear safety glasses while programming.

  5. #5


    Did you find this post helpful? Yes | No

    Default That could work!

    @ Dave

    OK cool

    So I Will
    1. Capture all 4 lines into and array each one is 4 bytes and a checksum byte so array needs to receive 20 bytes total.
    2. Check 4 for checksum match
    Continue on ...

    It certainly seems doable and will give it a bash right away!

    Still just wondering if there is a way to capture and compare all 4 lines

    Kind regards
    Dennis
    Last edited by Dennis; - 6th April 2010 at 01:52.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    If you really want to do each line then I guess the way would be ...

    IF array1 bit1 = array2 bit1 then
    IF array1 bit2 = array2 bit2 then
    IF array1 bit3 = array2 bit3 then
    ......on and on and on....

    But something like Charles said
    IF check1 = check2 then
    IF check2 = check3 then
    IF check3 = check4 then
    Hey. it is done...
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Depending on what your data looks like, you can also do some neat things with:

    ARRAYREAD (name_of_first_string),(nocompare_location),(numbe r_of_chars_to_compare),[WAITSTR name_of_second_string]
    Charles Linquist

  8. #8


    Did you find this post helpful? Yes | No

    Default rewind....

    AHA...

    That's where I'm stuck ....at step 1 I mentioned earlier ...

    1. Capture all 4 lines into and array each one is 4 bytes and a checksum byte so array needs to receive 20 bytes total.
    I this is the line I am using to receive the data

    Code:
    DEBUGIN [WAIT(SYNK),WNUM,XNUM,YNUM,ZNUM,CHECKSUM]
               ' wait for SYNK, when received store next 4 bytes in variables WNUM,XNUM,YNUM,ZNUM
               'then send these to hyperterminal or serial program or wherever
    What must be changed in order for me receive it 4 times and build the array?

    I was playing around with this as a start..but it's here where I am stuck!
    Code:
    For counter=0 To 19 
    DEBUGIN [WAIT(SYNK),WNUM,XNUM,YNUM,ZNUM,CHECKSUM]
               ' wait for SYNK, when received store next 4 bytes in variables WNUM,XNUM,YNUM,ZNUM
               'then send these to hyperterminal or serial program or wherever 
             counter=counter+1
            Next
    As always any help would be appreciated

    Kind regards

    Dennis

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts