Shop OBEX P1 Docs P2 Docs Learn Events
Trying to understand @addresses — Parallax Forums

Trying to understand @addresses

Brian CarpenterBrian Carpenter Posts: 728
edited 2009-08-23 05:37 in Propeller 1
I have an issue where i am collecting data by using the Extended Full Duplex Serial object and storing it into address (slots) using @


First, the problem.· When i 'print' the data that i collected, back out to the PC, i am getting a problem.· If you notice, where it says (Port ID is - 008011011011) it should only read 0080.· it is also grabing the next variables value and adding it.· Am i explaining this correctly?· How do i fix this?· The pertinat snipit of code is below.· Any glaring problems?
This is the data that i am getting in my PC debug window

Remote IP Address is - 192.169.0.6
Port ID is - 008011011011
The current Alarms are - 11011011

CODE
VAR
  Byte  Remote_IP[noparse][[/noparse]16]
  Byte  Port_ID[noparse][[/noparse]4]
  Byte  Alarms[noparse][[/noparse]8]
  Byte  Report_Freq[noparse][[/noparse]4]
  Byte  Message[noparse][[/noparse]16]
  
PUB  MAIN                       
  ser.start(RX_PIN, TX_PIN, 0, BAUD_RATE) 'to the serial device    
  pc.start(Digi_RX,Digi_TX,0,Digi_Baud)   ' to the PC
  waitcnt(80000000 + cnt)  
  REPEAT
    ser.str(string("$$$",13,10))
    waitcnt(80000000 + cnt)
    ser.str(string("open",13,10))
    waitcnt(80000000 + cnt)
    ser.str(string("GET /CMP.php?name=CMP&A="))
    ser.dec(therm1H)
    ser.str(string("&B="))
    ser.dec(therm2H)
    ser.str(string("&C="))
    ser.dec(therm4H)
    ser.str(string("&D="))
    ser.dec(therm3H)
    ser.str(string(" HTTP/1.0",13,10,"Host: air-commander.com",13,10))
    ser.str(string("User-Agent: PropTCP",13,10))
    ser.str(string("Connection: close",13,10,13,10))
    repeat until ser.rx == "#"                     '' Wait for # at start of string
    ser.RxStr(@Remote_IP) 
    ser.RxStr(@Port_ID)
    ser.RxStr(@Alarms)
    ser.str(string("$$$",13,10))
    waitcnt(80000000 + cnt)
    ser.str(string("close",13,10))
    ser.str(string("exit",13,10))
    'Display data collected to the PC Debug window via PST
    pc.str(string("Remote IP Address is - "))
    pc.str(@Remote_IP)
    pc.str(string(13,10))
    pc.str(string("Port ID is - "))
    pc.str(@Port_ID)
    pc.str(string(13,10))      
    pc.str(string("The current Alarms are - "))
    pc.str(@Alarms)
    pc.str(string(13,10))  
    waitcnt(80000000 + cnt)
    waitcnt(80000000 + cnt)
    waitcnt(80000000 + cnt)
    waitcnt(80000000 + cnt)
    waitcnt(80000000 + cnt)
    waitcnt(80000000 + cnt)
    waitcnt(80000000 + cnt)
    waitcnt(80000000 + cnt)
    waitcnt(80000000 + cnt)
    waitcnt(80000000 + cnt)
    waitcnt(80000000 + cnt)


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


It's Only A Stupid Question If You Have Not Googled It First!!

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-23 05:00
    Brian,

    Strings need to be terminated with a zero byte. That's the only way that the methods you call to output them can tell how long they are. This implies that you need to include room for an extra byte in your array dimensions.

    -Phil
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2009-08-23 05:03
    Lets try it in here.  So if i know that i am expecting 4 characters for Port_ID, i shoud use Port_ID[noparse][[/noparse]5] ?
     
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!

    Post Edited (Brian Carpenter) : 8/23/2009 5:13:30 AM GMT
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-08-23 05:32
    Hello Brian,

    yes and then Port_ID[noparse][[/noparse] 4] should be assigned with a zero

      Port_ID[noparse][[/noparse] 4] := 0
    
    
    



    let's assume your Port-ID is "8156"

    so
      Port_ID[noparse][[/noparse] 0] contains the "8"
      Port_ID[noparse][[/noparse] 1] contains the "1"
      Port_ID[noparse][[/noparse] 2] contains the "5"
      Port_ID[noparse][[/noparse] 3] contains the "6"
    
      Port_ID[noparse][[/noparse] 4] contains a REAL zero 0 to terminate the string
    
    
    



    best regards

    Stefan
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-08-23 05:37
    Brian,

    Just to expand on Stefan's comment, if Port_ID is a VAR variable, and if Port_ID[noparse][[/noparse]4] is never assigned anything else, it will equal zero from the program's initialization. So you shouldn't have to do anything except to allocate the extra byte.

    -Phil
Sign In or Register to comment.