The receiveSMS function block in the base is not intended for use in FBD, as it would query messages in each program cycle. However, it can be used in FBD with appropriate modifications

This function block has no input variables, but contains 5 outputs:

  • channel: variable of type string, contains the designation of the alarm channel on which the SMS was received (in case of multiple modems)
  • sender: variable of type string, contains telephone number in international format (e.g. +420777666555)
  • message: variable of type string, contains the text of the SMS message itself
  • receivetime: variable of type DT, contains the time when the message was received

The last output is an unlabeled output, which is of type integer and contains a numeric status with the result of the operation. More is described below in the text (for the output result).

Since the block is intended only for use in the ST, it is necessary to create your own function block written in the ST for its use. This is only possible in Full Mode solution. The procedure for switching to full mode can be found here in the introductory article.

To receive an SMS, create a function block by right-clicking on the project (e.g. in executable projects).

A dialog box will appear, select/paste here:

  • Name: ReceiveSMS_fbd
  • Type: FunctionBlock
  • Language: st
  • Namespace: v0_0

and confirm by clicking OK.

A window with the code structure example of the function block will open. Delete all the contents of the block and replace them with the following code:

		trigger : R_TRIG;
		readPulse : bool := 0;
		readSMS : bool := 0;
		result : int := 31;
		sms_channel : string := "";
		sender : string := "";
		message : string := "";
		receive_time : dt := dt#0001-01-01-00:00:00;

	IF readPulse THEN
			CHANNEL => sms_channel,
			SENDER => sender,
			MESSAGE => message,
			RECEIVETIME => receive_time


The result should look like this:

You can now close the function block window, then save and compile the solution.

Then open main.program.fbd and right-click on an empty space and select from the context menu: Add library box → Add library box.

A dialog window for searching for functions and function blocks opens. In the Name field, enter a name of the block: ReceiveSMS_fbd, highlight it and click OK.

This inserts the block into the program space:

Now you need to create several test variables. First, create an input variable trigger of type bool and enter False as its initial value. Connect the variable to the readSMS input of the block:

Next, create the output variables channel, sender, and message, all of the type string. Lastly, create a variable receivetime of type DT. Since all variables are output, it is not necessary to set their initial values. Finally, connect them to the block.

The result should look something like this:

Upload the solution and start debugging. Each time the value of the variable trigger is changed from False to True, one message is read from the SIM card memory.

The result output will be 0 if the message was read correctly and 31 if no message is available. Other values indicate an error, see the help (F1 key) for the receivesms function block.