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 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.

  2. #2
    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.

  3. #3
    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

  4. #4


    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

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Hi Denis, I think you could take some advantage from this thread :http://www.picbasic.co.uk/forum/showthread.php?t=12870
    In post # 4 DT is giving an interesting snippet for having 2d array in PBP.

    I don't know if you have already used bi-dimensional arrays, if not let me say that they could easy your compare problem.


    You cannot corrupt the variable within a FOR/NEXT cycle:

    For Counter =0 to 19
    .
    .
    .
    counter=counter+1
    Next Counter

    You should expect some problem from this code!

    Al.
    Last edited by aratti; - 6th April 2010 at 02:14.
    All progress began with an idea

  6. #6


    Did you find this post helpful? Yes | No

    Default 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

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


    Did you find this post helpful? Yes | No

    Default

    Here is something else if you want to go the route of sending "good" data the first time.
    You might be able to get an idea or two... or more confused
    http://www.picbasic.co.uk/forum/showthread.php?t=12554
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,167


    Did you find this post helpful? Yes | No

    Default

    Another one idea is to have the 3rd string stored in an array and then on the 4th reception compare in the serial input that string using the wait modifier
    like this:

    debugin [str my_array\4]

    and then

    debugin [waitstr my_array\4]

    I'll try to put up an example soon. I got to go now... sorry

    Ioannis
    Last edited by Ioannis; - 6th April 2010 at 10:11.

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