StrComp question
Mikael S
Posts: 60
Hello!
I try to compare a string recieved from my gsm modem with a given DAT byte, but without luck. I think the problem is that the recieved string does not contain a terminating zero.
Can someone please give me a example how i can add that zero to my recieved string, or what can it be??
Thanks!
/Micke
I try to compare a string recieved from my gsm modem with a given DAT byte, but without luck. I think the problem is that the recieved string does not contain a terminating zero.
Can someone please give me a example how i can add that zero to my recieved string, or what can it be??
Thanks!
/Micke
Comments
Here comes the code:
I think I added up 127 bytes in your buffers.
Example using a 4port serial object:
It doesent work for me...
I have increased the "var byte message" to 127, and i have put the "bytefill(@message, 0, 127" just before the gsm.RxStr.
What is it im doing wrong, can someone please help me?!
/Micke
Now i have tried that, same result...
Here is my latest code, the message consists just of the two letters "on".
[code]
obj
gsm: "Extended_FDSerial"
debug: "Parallax Serial Terminal"
var
byte message[127], phonenumber[16], mess1[16], mess2[16], mess3[16], mess5[16], mess6[16], mess7[16]
dat
on byte "on", 0
off byte "off", 0
pub main
debug.start (115200)
gsm.start (26, 27, 0, 9600)
waitcnt (clkfreq * 2 + cnt)
dira[2] :=1
readmessage
pub readmessage
repeat
waitcnt (clkfreq * 5 + cnt)
gsm.rxflush
gsm.str (string("AT+CMGR=1")) 'Read sms in first memory
gsm.tx(13) 'CT
debug.str (string("Get message in memory1..."))
bytefill(@message, 0, 127)
debug.newline
gsm.RxStrTime(300,@mess1)
gsm.RxStrTime(300,@mess2)
gsm.RxStrTime(300,@mess3)
gsm.RxStrTime(300,@phonenumber)
gsm.RxStrTime(300,@mess5)
gsm.RxStrTime(300,@mess6)
gsm.RxStrTime(300,@mess7)
gsm.RxStrTime(200,@message)
waitcnt (clkfreq * 1 + cnt)
gsm.str(string("AT+CMGD=2")) 'Delete message in first memory
gsm.tx(13)
waitcnt (clkfreq * 1 + cnt)
debug.newline
debug.str(@mess1)
debug.newline
debug.str(@mess2)
debug.newline
debug.str(@mess3)
debug.newline
debug.str(@phonenumber)
debug.newline
debug.str(@mess5)
debug.newline
debug.str(@mess6)
debug.newline
debug.str(@mess7)
debug.newline
debug.str(string("H
debug.str(string("H
(I cant copy and paste from Serial Terminal, i hope this will do)
The only last thing I might try for some understanding is to look at each element in the var:
debug.str(@message[0])
debug.newline
debug.str(@message[1])
debug.newline
debug.str(@message[2])
debug.newline
Hopefully someone will enlighten us both.
Results from Parallax Serial Terminal
John Abshier
My problem is why i cant parse the incomming message with the actual three given words.
But in my code i have the debug.str(@message) and that give me the right result from the string (on).
Another question, is there any way to copy the result from the Serial Terminal, without using the print screen?
copy/paste is possible. Just select the area with the mouse then press ctrl+C. Once you have your clock setup sorted can you generate another data dump?
Apologies for using the wrong method names. PST uses char instead of tx (I modified the code fragment posted earlier).
Or is there any other solution to read a "part" of a string without knowing the start bit??
Or, try this test:
This would normally search within the string and find on or off, not sure how it reacts with LF as part of the string.
How can i add the <LF> in my DAT byte?
I have a "on byte "on", 0" in my DAT section, is there any way to add the <LF> command before the "on" ?
Just to test my theory...
Now to the next issue....
I use the code below to read the message from my modem, and it seems to work fine, for a while...
It seems like the prop hangs if the modem recieves a message exactly at the same time this code is executed.
If there is no message to read, i just use the time-out part in the RxStrTime, and its then this seems to happen.
[code]
gsm.rxflush
gsm.str (string("AT+CMGR=1")) 'Read sms in first memory
gsm.tx(13) 'CT
debug.str (string("Get message in memory 1..."))
bytefill(@message, 0, 127)
gsm.RxStrTime(300,@mess1) '