Lookdown command the result not consistent


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2009
    Posts
    12

    Default Lookdown command the result not consistent

    Dear all,
    FYI, recently i write a program to detect the data send by PC through UART. Here is the code,

    Get_Data:
    serin2,PORTC.4,16390,[serstring]
    lookdown,serstring["CB2E"],STRING
    Debug DEC STRING,10,13
    goto Get_Data

    Result of STRING: 0 0 0 0 3 3 3 3 3 0 0 0

    The PC data is as below,
    A5 5A 00 20 30 00 00
    A5 33 00 20 30 10 00
    A5 5A CB2E

    My question is :
    - i want to capture data "CB2E" only and ignore the other data. Somehow, i get the result STRING not consistent. I am not familiar with this command Lookdown.
    - Is there anything wrong with my source code??? need some advice from the expect...please help!
    TQ

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


    Did you find this post helpful? Yes | No

    Default Re: Lookdown command the result not consistent

    Lookdown is meant to find only one byte (character), not a series. If you are only interested in whether or not "CB2E" is present in the incoming data stream, and you aren't concerned about where it is in the string, you should you the command

    serin2,PORTC.4,16390,1000,NotFound,[WAIT ("CB2E")]

    ; Gets here if "C2BE" is found within 1000 msec of invoking the command

    NotFound:
    ; Gets here if "C2BE" is NOT found within 1000 msec of invoking the command
    ;------------------------------------------------------------------------------------------

    And one more thing: If your device has a hardware serial port, PLEASE use it.
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default Re: Lookdown command the result not consistent

    I forgot to mention -

    If you want to grab the data and don't want to sit around and wait to see if it is OK,
    you can use the following structure:


    Code:
     
    Parse01: Cmd=01 : ARRAYREAD Data_Array,20,Parse02,[WAIT("Status1?")] : GOTO Foundit
    Parse02: Cmd=02 : ARRAYREAD Data_Array,20,Parse03,[WAIT("Status2?")] : GOTO Foundit
    This is a small part of a command parser that I'm currently using. The data you want to test is placed in the array "Data_Array", it will look at the first 20 characters (of course you can change that), and if it finds "Status1?" it jumps to FOUNDIT: and Cmd contains the line where it was found (in this case, 1). If "Status1?" is not found in the string, it jumps to line 2, and checks for "Status1?"
    etc.
    Charles Linquist

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Lookdown command the result not consistent

    Quote Originally Posted by Charles Linquis View Post
    I forgot to mention -

    If you want to grab the data and don't want to sit around and wait to see if it is OK,
    you can use the following structure:


    Code:
     
    Parse01: Cmd=01 : ARRAYREAD Data_Array,20,Parse02,[WAIT("Status1?")] : GOTO Foundit
    Parse02: Cmd=02 : ARRAYREAD Data_Array,20,Parse03,[WAIT("Status2?")] : GOTO Foundit
    This is a small part of a command parser that I'm currently using. The data you want to test is placed in the array "Data_Array", it will look at the first 20 characters (of course you can change that), and if it finds "Status1?" it jumps to FOUNDIT: and Cmd contains the line where it was found (in this case, 1). If "Status1?" is not found in the string, it jumps to line 2, and checks for "Status1?"

    etc.

    I am sure it was supposed to be "Status2?", just to avoid any confusion here.
    And the previous example was indeed nice; smart.
    This second one is also nice (at least for me).
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default Re: Lookdown command the result not consistent

    No.

    Suppose that you have an input routine where a computer sends you a bunch of commands to parse, and you have to decode those commands. In my case, I have 45 different commands that I have to respond to. Two of those commands are "Status1?" and "Status2?". My incoming packet (it actually is a pre-processed Ethernet packet) is loaded into Data_Array.

    Say the packet contains "Status2?"

    In the first line in the code example above, I look for "Status1?" in the first 20 characters. Since it doesn't exist, I don't get a match and I jump to line 2 and search for "Status2?" in Data_Array. If it finds "Status2?" (which it will), then I jump to Foundit, and CMD = 2. A SELECT CASE structure using CMD then goes and performs the right thing.

    Another tip for those of you who handle a lot of strings (or ARRAYS as they must sadly be called in PBP):
    It is often very convenient to make the first element of the array (element 0) the length of the array.
    Charles Linquist

  6. #6
    Join Date
    Feb 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Lookdown command the result not consistent

    Dear Charles Linquis,
    Thank you for your explanation. really help a lot to me. I am really appreciated.
    Looks like the Lookdown command is only find one byte of character, for example,

    Lookdown,serstring,["A"],String
    Debug DEC String,10,13

    So, this command will reply result in String i.e. decimal value "0", right?

    serin2,PORTC.4,16390,1000,NotFound,[WAIT ("CB2E")]

    This command will look for "CB2E" string only if the incoming data stream is huge and don't care the position of this string, right?
    Yes, for my condition is that i want to detect this "CB2E" string only then carry out next job. Sorry to confuse you, i am now using hardware serial port to do the debugging.

    TQVM

  7. #7
    Join Date
    Feb 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Lookdown command the result not consistent

    Quote Originally Posted by Charles Linquis View Post
    I forgot to mention -

    If you want to grab the data and don't want to sit around and wait to see if it is OK,
    you can use the following structure:


    Code:
     
    Parse01: Cmd=01 : ARRAYREAD Data_Array,20,Parse02,[WAIT("Status1?")] : GOTO Foundit
    Parse02: Cmd=02 : ARRAYREAD Data_Array,20,Parse03,[WAIT("Status2?")] : GOTO Foundit
    This is a small part of a command parser that I'm currently using. The data you want to test is placed in the array "Data_Array", it will look at the first 20 characters (of course you can change that), and if it finds "Status1?" it jumps to FOUNDIT: and Cmd contains the line where it was found (in this case, 1). If "Status1?" is not found in the string, it jumps to line 2, and checks for "Status1?"
    etc.
    Nice! Another way to check for the string.
    ARRAYREAD Data_Array,20,Parse02,[WAIT("Status1?")] : GOTO Foundit

    I will try it tomorrow during debugging. Will update to you the result.

    TQVM



  8. #8
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Lookdown command the result not consistent

    Quote Originally Posted by Charles Linquis View Post
    This is a small part of a command parser that I'm currently using. The data you want to test is placed in the array "Data_Array", it will look at the first 20 characters (of course you can change that), and if it finds "Status1?" it jumps to FOUNDIT: and Cmd contains the line where it was found (in this case, 1). If "Status1?" is not found in the string, it jumps to line 2, and checks for "Status1?"
    etc.

    Charles, don't you have typo in the red?

    That is what I was saying.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default Re: Lookdown command the result not consistent

    Sorry, yes I did have a type. It looks for STATUS2? in the second line. My apologies.
    Charles Linquist

  10. #10
    Join Date
    Feb 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Lookdown command the result not consistent

    Dear Charles,
    Today i try to debug the command code u suggest,

    1) serin2,PORTC.4,16390,1000,NotFound,[WAIT ("CB2E")] --- Result OK.....can detect the string.

    2) my code,

    GET_DATA:
    ' SERIN2 PORTC.4,16390,5000,NotFound,[wait ("C82F")]
    serin2 PORTC.4,16390,5000,notfound,[DATA_array]
    ARRAYREAD data_array,256,NOTFOUND,[wait ("C82F"),serstring1,serstring2]
    debug serstring1
    debug serstring2
    goto REV_DATA
    NotFound:
    debug "Not Found",10,13
    pause 1000
    goto RESET_

    Data stream:
    A5 5A C0C05E
    A5 5A 0E2E 21 00 00 00 00
    A5 5A 0E70 26 FE 00 00 00 00 FF
    A5 5A C870 26 FE 00 00 00 00
    A5 5A C82F
    A5 5A 0E2E 20 00 00 00 00
    A5 5B 0CC2 00
    A5 5A C2D2
    A5 5A 060F 00

    Result: i get "Not Found" but not the serstring1,serstring2 that i debug. I wonder why this happen to the command "Arrayread"?

    TQVM

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


    Did you find this post helpful? Yes | No

    Default Re: Lookdown command the result not consistent

    I don't know exactly what you are trying to do, but the code below works.

    Code:
     
            CR CON 13
            LF CON 10
     
             Data_Array VAR BYTE [30]
             AfterString1 var byte [10]
             AfterString2 var byte[10]
             ArrayWrite AfterString1,[REP 0\10]  ; Zero out the strings
             ArrayWrite AfterString2,[REP 0\10]
     
     
     
     
     
          ArrayWrite  Data_Array,"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S",0]
     
     
     
     
     
          Arrayread Data_Array,20,NotFound,[Wait ("CDE"),STR AfterString1 \6,STR AfterString2 \6]
     
          hserout [CR,LF,"AfterString1 ",STR AfterSTring1,CR,LF]
         hserout [CR,LF,"AfterString2 ",STR AfterSTring2,CR,LF]
          goto home
     
    notfound:
     
         hserout["Not Found"]      
     
    home:
     
       goto home
    Charles Linquist

Members who have read this thread : 1

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