Trying to understand @addresses
Brian Carpenter
Posts: 728
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?
CODE
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
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
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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
yes and then Port_ID[noparse][[/noparse] 4] should be assigned with a zero
let's assume your Port-ID is "8156"
so
best regards
Stefan
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