PDA

View Full Version : Problem receiving string



financecatalyst
- 12th October 2009, 03:08
Hello
I am trying to use the following command:
serin2 rx,baud,5000,main,[WAIT("REC UNREAD"),SKIP 3,STR num\13,SKIP 27,STR sms\14]

I am trying to build an sms controller using my GSM modem with 16F690
My problem is that this code only moves forward if the string is 14 bytes long.

Is there any way I can make this code work if it receives from 1 to upto 14 characters.

Any input will be much appreciated. Thanks

Jerson
- 12th October 2009, 04:37
This should work for a CR terminated string. It will collect uptil CR or 14 characters.

serin2 rx,baud,5000,main,[WAIT("REC UNREAD"),SKIP 3,STR num\13,SKIP 27,STR sms\14\13]

From the manual :
STR ArrayVar\n{\c} - Receive string of n characters optionally ended in character c

aratti
- 12th October 2009, 07:24
Or...

You can use the time out to check your array string.



serin2 rx,baud,5000,main,[WAIT("REC UNREAD"),SKIP 3,STR num\13,SKIP 27,STR sms\14]


From the above code, if you don't receive the whole string (14 characters) then at timeout, program will jump to label main, here you can check your array sms



main:
A0=0
for B0=0 to 13
if sms[B0]>0 then A0=A0+1
next B0
If A0 >0 then goto decode



If variable A0 is found >0 then your array has been loaded and program jump to label Decode where you will decode sms array from sms[0] to sms[A0-1].


Is there any way I can make this code work if it receives from 1 to upto 14 characters.

Once in routine Decode,A0 can be anything from 1 to 14 just what you where searching for.

Naturally, before to go to Serin2 you must clear (set to zero) the array sms.

Al.