Parsing data from debugin


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2004
    Posts
    448

    Default Parsing data from debugin

    Hi,

    Its been some time since I used PBP on a serious project, and I'm afraid I've gone a bit rusty.

    I get a string of 9 characters (numerals only) from a device; the 1st character is always an '8'.

    How would I split up the remaining 8 characters as 4 nos of 1,1,3 and 3 digits respectively?

    I am using debug to read the incoming string. I suspect the first character, a constant "8", can be used as a qualifier.

    What would the syntax for the debugin line be?

    And then, suppose I receive a string ""812345678", how would I assign values to variables a,b,c,d such that a=1, b=2, c=345 and d=678?

    Thanks for the help, guys!

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Parsing data from debugin

    Quote Originally Posted by ardhuru View Post
    Hi,

    Its been some time since I used PBP on a serious project, and I'm afraid I've gone a bit rusty.

    I get a string of 9 characters (numerals only) from a device; the 1st character is always an '8'.

    How would I split up the remaining 8 characters as 4 nos of 1,1,3 and 3 digits respectively?

    I am using debug to read the incoming string. I suspect the first character, a constant "8", can be used as a qualifier.

    What would the syntax for the debugin line be?

    And then, suppose I receive a string ""812345678", how would I assign values to variables a,b,c,d such that a=1, b=2, c=345 and d=678?

    Thanks for the help, guys!
    Here is a program that has a qualifier and 2 variables to control relays.
    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
    DEFINE OSC 4
    
    
    DEFINE DEBUG_MODE  0    ' Debug sending True serial data
    DEFINE DEBUG_REG_PORTA  ' Debug Port = PortA as required by PICKIT2 serial Monitor
    DEFINE DEBUG_BIT 0      ' Debug.bit = PortA.0
    DEFINE DEBUG_BAUD 9600  ' Default baud rate = 9600
    DEFINE DEBUGIN_REG PORTA' Debug Port = PortA as required by PICKIT2 serial Monitor 
    DEFINE DEBUGIN_BIT 1    ' Debugin bit PortA.1
    DEFINE DEBUGIN_BAUD 9600' Default baud rate = 9600
    DEFINE DEBUGIN_MODE 0   ' Debugin receiving data true = 0 inverted = 1
    relay		var byte     'relay number storage variable
    state		var byte     'relay state of ON/OFF variable
    
    state = 0
    relay = 0
    PORTC = 0
    ANSEL=0
    ANSELH=0
    ADCON0 = 0
    ADCON1 = 0
    CCP1CON = %10001100 ;Dual PWM 10xx11xx P1A/RC5 P1B/RC4 RC3/AN7 RC2/AN6
    TRISA = %00001110           
    TRISB = %00000000           
    TrisC = %00000000            
    
    main:
    DEBUGIN [WAIT($FF),state,RELAY]
    PAUSE 30
    
    
    ON RELAY GOSUB  RELAY0,RELAY1,RELAY2,RELAY3,RELAY4
    
    
    DEBUG state,RELAY
    ;TOGGLE PORTC.0
    
    
    
    
    goto main
    
    RELAY0:
    IF state = 1 THEN
    PORTC.0 = 1
    ELSE
    PORTC.0 = 0
    ENDIF
    RETURN
    
    RELAY1:
    IF state = 1 THEN
    PORTC.1 = 1
    ELSE 
    PORTC.1 = 0
    ENDIF
    RETURN
    
    
    RELAY2:
     IF state = 1 THEN
    PORTC.2 = 1
    ELSE 
    PORTC.2 = 0
    ENDIF
    RETURN
    
    
    RELAY3:
    IF state = 1 THEN 
    PORTC.3 = 1
    ELSE 
    PORTC.3 = 0
    ENDIF
    RETURN
    
    RELAY4:           'controls all ports simultaneously
    IF state = 1 THEN 
    PORTC = 15
    ELSE 
    PORTC = 0
    ENDIF
    RETURN 
    
    end
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Re: Parsing data from debugin

    Hi,
    How about
    Code:
    Value_A VAR BYTE
    Value_B VAR BYTE
    Value_C VAR WORD
    Value_D VAR WORD
    
    DEBUGIN [WAIT("8"), DEC1 Value_A, DEC1 Value_B, DEC3 Value_C, DEC3 Value_D]
    Untested so take it for what it is.

    /Henrik.

  4. #4
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: Parsing data from debugin

    Thanks Archangel, Henrik, worked a treat.

    Couldnt imagine it would be that simple.

    And now for one more related question; how reliable would it be if I use the MCLR pin as the debugin input?

    Thanks for the prompt response, guys!

Similar Threads

  1. Parsing serial data
    By Heckler in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th March 2010, 14:25
  2. Parsing Strings...
    By TerdRatchett in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 15th February 2009, 04:13
  3. Parsing Serial data stream
    By boroko in forum Serial
    Replies: 5
    Last Post: - 26th October 2008, 11:12
  4. String Parsing
    By eoasap in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th February 2006, 17:20
  5. serial string parsing
    By billybobbins in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 8th September 2004, 21:34

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