String manipulation

J D S

New Member
Hi

I’m working on a program to receive sms messages using a Siemens TC35 GSM Module. When i receive the message it comes in as…
+CMGL : 1, “REC UNREAD”,”+441234567”,,”14/04/03,17:30:25
Test message,

OK

Now I want to pick out the parts i want, if i were using basic i would use Left$ or MID$ how can i do that in pickaxe basic?

Thanks


John
 

inglewoodpete

Senior Member
I wouldn't consider anything less than the X2 series of PICAXE chips. I would use background receive, where the incoming string is automatically written to the scratchpad RAM. From then on, it's a fairly simple matter of setting up the ptr variable and using it to step though the received data to find what you want from the incoming data string.

Others may argue the case for the M2 chips but the X2s make the task so much easier.
 

J D S

New Member
Thanks for your help i've just paled and order for a couple of X2 chips to experiment with. Could I use the serin command with qualifiers to strip out the text I want?
 

inglewoodpete

Senior Member
The difficulty with using the SerIn (or hSerIn) on the M2-series chips is that you have to be very careful with your code to ensure that the serial-input pin is being monitored by your program when the input string arrives. The benefit of the X2's background serial is that the incoming data is written into the scratchpad without any foreground code required to move each character. Your foreground code only needs to periodically monitor the hSerFlag and buffer for new data and process it as required.
 

AllyCat

Senior Member
Hi John,

When i receive the message it comes in as…
+CMGL : 1, “REC UNREAD”,”+441234567”,,”14/04/03,17:30:25
It depends where you have stored the message (RAM or EEPROM, or haven't you done that yet?) and how you want to use the partial string (e.g. output to a Monitor/OLED/LCD, etc.). But generally you need to use an "Indexed" command such as PEEK, READ or @bptr.

For example if the String starts at EEPROM location "BASE" (e.g. 30) and you want to select "LENGTH" (e.g. 3) characters from "START" (e.g. 5) onwards then you could try code like the following in the simulator:

Code:
DATA 30,("ABCDEFGHIJKLMNOPQRST")	 	; Store test data
symbol BASE = 30
symbol START = 5		; Note the First character is numbered zero !
symbol LENGTH = 3
symbol firstchar = b0
symbol lastchar = b1   
symbol index = b2
symbol character = b3
 
firstchar  = BASE + START 
lastchar = firstchar + LENGTH - 1
FOR index = firstchar TO lastchar
	READ index,character
	SERTXD(character)
NEXT
Cheers, Alan.
 
Last edited:

J D S

New Member
Hi Alan

I'm still experimenting with hyper terminal and the GSM module now. I received the X2 chips Saturday so will be building a prototype board next week then start connecting it to the GSM module.

Thanks for the above code i think that will be useful, I'll be using RAM to store the received text but was mainly interested in the text of the message which I was going to start with say 3 special characters like $$$ then the instruction code. The pickaxe could then separate the instruction out using the the qualifiers to pick out the $$$.


John
 

AllyCat

Senior Member
Hi John,

Note that I have corrected the memory type (RAM to EEPROM) for the example in my post above.

For reading data from RAM (or writing it in), the @bptr and @bptrinc variable/command is the most useful, but PEEK and POKE are probably easier to understand at first. So in my example above, change READ to PEEK after loading the RAM with data, for which TABLECOPY (14M2 and 20M2 only) might be useful.

Cheers, Alan.
 
Top