Supported platforms: CODESYS 3.5

 

Modem (FB)

Description

This function block includes functionality for using a GPRS/LTE modem connection.

All input parameters are taken in use at the rising edge of i_Enable.

Limitations

This section applies to 6000 series units with a modem card.

 

Connectivity settings such as APN, phone number, SIM PIN code, and the Network mode depend on the operator, SIM card and the purchased data plan.

 

Only one instance of function block is supported.

 

From library version 3.1.0.0 the Modem connection can be controlled without calling the methods, but the FB instead.

 

From library version 3.1.0.0 the Modem main FB has automatic reconnection functionality. The FB tries reconnection after given interval time when connection is lost.

 

Inputs

Input variable name

Data type

Default

Description

i_Enable

BOOL

FALSE

Enable operation.

i_AccessPoint

STRING

'internet'

Access point name (APN).

i_PhoneNumber

STRING

'*99#'

Phonenumber.

i_NetworkMode

ModemNetworkMode

Auto

Used network mode

i_NumberOfRetries

UINT

10

Number of retries when trying to (re)connect.

The retry count is reset

- at the rising edge of i_Enable input, and

- when connected successfully.

i_RetryInterval

UINT

30s

Retry interval time in seconds.

Outputs

Output variable name

Data type

Description

o_State

ModemConnectionState

Modem connection state.

o_Error

ModemError

Modem connection error.

o_RetryCounter

UINT

Current connection retry count.

 

 

The old interface methods are supported, but not adviced to be used.

MethodsMethods

Init (Method)

The method initializes function block.

 

Init must be called before any other method of the FB.

Inputs

No inputs.

Return value

Data type

Description

ModemError

Library error code.

 

SetModemSettings (Method)

The method sets modem settings for connection.

 

This method must be called with proper settings before opening connection.

Inputs

Input variable name

Data type

Description

i_pSettings

POINTER TO ModemSettings

Pointer to modem settings.

Return value

Data type

Description

ModemError

Library error code.

 

OpenConnection (Method)

The method opens modem connection asynchronously. After this method is called, connection status can be checked by GetConnectionState method.

 

CloseConnection method has no effect until connection state is ModemConnected.

Inputs

No inputs.

Return value

Data type

Description

ModemError

Library error code.

 

GetModemSettings (Method)

The method gets current modem settings.

Inputs

Input variable name

Data type

Description

i_pSettings

POINTER TO ModemSettings

Pointer to modem settings.

Return value

Data type

Description

ModemError

Library error code.

 

GetConnectionState (Method)

Method returns current connection state.

Inputs

No inputs.

Return value

Data type

Description

ModemConnectionState

Modem connection state.

 

CloseConnection (Method)

The method closes modem connection asynchronously. This method is automatically called when

application is reset, application is downloaded, or application exits.

 

CloseConnection method has no effect until connection state is ModemConnected.

Inputs

No inputs.

Return value

Data type

Description

ModemError

Library error code.

 

 

Example code

Definitions:

 

LTE: EPEC_Modem.Modem;

enable: BOOL := TRUE;

error: EPEC_Modem.ModemError;

state: EPEC_Modem.ModemConnectionState;

 

 

Code:

 

 

 

LTE(

    i_Enable := enable,

    i_AccessPoint := 'internet',

    i_PhoneNumber := '*99#',

    i_NetworkMode := EPEC_Modem.ModemNetworkMode.ModemNetworkModeAuto,

    i_NumberOfRetries := 10,

    i_RetryInterval := 30,

    o_State => state,

    o_Error => error

);

 

 

 

 

See also

-

 

 

Source file topic000946.htm

Last updated 4-Sep-2025