Sending an SMS via the Beckhoff 4G stick

The installed 4G stick is connected as a virtual serial interface, through which the PLC can connect via ADS. By calling the function block "SendSMS" the SMS is sent to a recipient.

  1. Enter in the data structure stSerialCfg.
  2. Enter in the string variable sNumber of the recipient.
  3. Send an SMS by a rising edge at bConnect.

Program variables

(*
COM_VCOM_SMS
Sends a SMS over a connected GSM Device especially over a virtual serial com port
*)
PROGRAM MAIN
VAR
(* function-block for sending a SMS *)
fbSendSMS : SendSMS;
sText : STRING := 'Please check machine #5, threshold is reached';
sSend : BOOL;
sNumber : STRING := '';
sBusy : BOOL;
sError : INT;

(* communication buffer between application and SerialLineControl *)
RxBuffer : ComBuffer;
TxBuffer : ComBuffer;

(* serial line control *)
fbLineCtrlAds : SerialLineControlADS;
bAdsError : BOOL;
nAdsErrorID : UDINT;
bConnect : BOOL;
sNetId : T_AmsNetId;
stSerialCfg : ComSerialConfig;
END_VAR

Program code

(*~~~~~~~~~~~~~~~~ cyclic call of serial background comm. ~~~~~~~~~~~~~~~~~*)
fbLineCtrlAds(
Connect := bConnect, //bConnect has to be set to true, after the
stSerialCfg is checked
SerialCfg := stSerialCfg, //stSerialCfg has to be filled with your
Com-Settings (Com-Port, Baudrate, etc.)
NetId := sNetId,
Timeout := ,
TxBuffer := TxBuffer,
RxBuffer := RxBuffer,
Busy => ,
Error => bAdsError,
ErrorID => nAdsErrorID,
PortOpened =>
);
fbSendSMS(
Send:= sSend, //sSend has to be set to true, when the message is ready
Number:= sNumber, //sNumber is the number of the recipient
Text:= sText, //sText is the text you would like to send to the recipient
Busy=> sBusy,
Error=> sError,
RXbuffer:= RxBuffer,
TXbuffer:= TxBuffer);

Requirements

Development environment

Target system type

PLC libraries to be linked

TwinCAT v3.0.0

PC or CX (x86)

Tc2_Sms, Tc2_SerialCom Library