You are on page 1of 59

SNMP_4 1/59

Function block library

SNMP_4

for PLCnext Engineer


Documentation for
PHOENIX CONTACT function blocks
PHOENIX CONTACT GmbH & Co. KG
Flachsmarktstrasse 8
D-32825 Blomberg, Germany
This documentation is available in English only.
SNMP_4 2/59

Table of Contents
1 Installation hint
2 General information
3 Change notes
4 Supported PLCs
5 Function blocks
6 SNMP_Agent
6.1 Function block call
6.2 Input parameters
6.3 Output parameters
6.4 Inout parameters
6.5 Diagnosis
6.6 Block parameters
7 SNMP_Client
7.1 Function block call
7.2 Input parameters
7.3 Output parameters
7.4 Inout parameters
7.5 Diagnosis
7.6 Block parameters
8 SNMP_TSend
8.1 Function block call
8.2 Input parameters
8.3 Output parameters
8.4 Inout parameters
8.5 Diagnosis
8.6 Block parameters
9 SNMP_TRecv
9.1 Function block call
9.2 Input parameters
9.3 Output parameters
9.4 Inout parameters
9.5 Diagnosis
9.6 Block parameters
10 SNMP_BUF_TO_ADDR
10.1 Function block call
10.2 Input parameters
10.3 Output parameters
11 SNMP_BUF_TO_DINT
11.1 Function block call
11.2 Input parameters
11.3 Output parameters
12 SNMP_BUF_TO_DWORD
12.1 Function block call
SNMP_4 3/59

12.2 Input parameters


12.3 Output parameters
13 SNMP_BUF_TO_OID
13.1 Function block call
13.2 Input parameters
13.3 Output parameters
14 SNMP_BUF_TO_TOID
14.1 Function block call
14.2 Input parameters
14.3 Output parameters
15 SNMP_BUF_TO_UDINT
15.1 Function block call
15.2 Input parameters
15.3 Output parameters
16 SNMP_DINT_TO_BUF
16.1 Function block call
16.2 Input parameters
16.3 Output parameters
17 SNMP_DWORD_TO_BUF
17.1 Function block call
17.2 Input parameters
17.3 Output parameters
18 SNMP_OID_GET
18.1 Function block call
18.2 Input parameters
18.3 Output parameters
19 SNMP_OID_SET
19.1 Function block call
19.2 Input parameters
19.3 Output parameters
20 SNMP_OID_TO_BUF
20.1 Function block call
20.2 Input parameters
20.3 Output parameters
21 SNMP_TOID_GET
21.1 Function block call
21.2 Input parameters
21.3 Output parameters
22 SNMP_TOID_SET
22.1 Function block call
SNMP_4 4/59

22.2 Input parameters


22.3 Output parameters
23 SNMP_TOID_TO_BUF
23.1 Function block call
23.2 Input parameters
23.3 Output parameters
24 SNMP_UDINT_TO_BUF
24.1 Function block call
24.2 Input parameters
24.3 Output parameters
25 Startup example
25.1 Example 1: SNMP_*_EXA
26 Appendix
26.1 Diag codes of used firmware function blocks
26.2 Data types
27 In case of problems
28 Support
SNMP_4 5/59

1 Installation hint
Please copy the library data to your PLCnext Engineer (former: PC Worx Engineer) working library directory.
If you did not specify a different directory during PLCnext Engineer installation the default PLCnext Engineer
working library directory is
C:\Users\Public\Documents\PLCnext Engineer\Libraries

2 General information
The SNMP library contains 4 function blocks for use of the Simple Network Management Protocol (SNMP) with the
control program.
SNMP is a well established IT standard from the office world for configuration and diagnostics in networks.
Controllers are integrated into local or worldwide network management solutions whereby not only the controller
can be represented as a network device, but also the variables from the control program. The user is completely
free when defining and processing the SNMP information. Direct communication between controllers on the basis
of the standard protocol is also possible.
The SNMP Agent block represents a server that enables access to the information of the control program over the
SNMP. Management Information Base (MIB) objects to be supported are communicated to the SNMP Agent
function block. SNMP requests according to protocol version 2c are accepted by the agent, which checks the
content and discloses the requested object to the control program. In turn, the response is passed onto the block
where an SNMP response is created and transmitted. The block supports requests of the Get- Request, Get-Next-
Request, Get-Bulk-Request and Set-Request type whereby several variable bindings may be contained within a
request.
The SNMP Client block is used for communication with remote SNMP agents. The request is forwarded to the
block from the control program. This creates an SNMP packet according to protocol version 2c or 1 and transmits
it to the agent. Response packets received by the block are checked and forwarded to the control program. The
block supports requests of the Get-Request, Get-Next-Request, Get-Bulk-Request and Set-Request type whereby
several variable bindings may be contained within a request.
The Trap Sender block allows transmission of alarm messages. The block puts the data provided into an SNMP
trap according to protocol version 2c and transmits it. Various different additional information, the variable bindings
can be added to a trap.
The Trap Receiver block listens for incoming traps, checks them and forwards the data to the control program. The
block supports traps according to protocol version 2c and can process various different amounts of additional
information, so-called variable bindings, from the trap.
Note:
For using this library the IP_Com library has to be included in your project.
The IP_Com library is located in the SNMP setup.
SNMP_4 6/59

3 Change notes
Library Library PLCnext
version build Engineer Change notes
version
4 20230918 2022.0 Added IP_Com documentation to *.zip-file
LTS
4 20220714 2022.0
LTS General : Removed iVarBindMax from communication structure.
SNMP_Agent : Fixed a bug when receiving a WALK request.
SNMP_Agent : Now shows the source ip adress and port.
SNMP_Agent : When receiving an BULK request with a number of
varbinding bigger than supported, it now just send the biggest
possible number of objects.
SNMP_Client : Internal improvement.
SNMP_TRecv : Now shows the source ip adress and port.
SNMP_TOID_TO_BUF : Fixed internal bug.
SNMP_TOID_SET : Fixed internal bug.
SNMP_OID_TO_BUF : Fixed internal bug.
SNMP_OID_SET: Fixed internal bug.

3 20201125 2020.0
LTS Documentation improved

3 20201125 2020.0
LTS Documentation improved

3 20200915 "
Data type documentation changed. No changes of the data types,
only documentation
IP_Com_10 is used
SNMP_4 7/59

2 20200206 " All function blocks:


- fixed bug where the function block could not send a message after an
error occured
- fixed bug where xActive was FALSE in an error case
- fixed bug where the function block disabled the UDP communication when
it was deactivated
- added the auto retry functionality from the IPC_Socket function block
SNMP_Agent :
- added the output xBusy
- added a timeout of 10 seconds for getting a send acknowlegde
- fixed bug for the internal SNMP-message check
- fixed bug where the function block did not reset the xSendReq from the
udtIP_Com structure
SNMP_Client :
- added the output xBusy
- fixed bug where no error occured when a timeout was detected
- changed the procedure of opening the UDP port. Now it is not closed
when the function block is deactivated in case the same connection is
used again. Only if a other function block uses the same IPC_Socket
function block, the port is closed.
- fixed bug where the function block did not reset the xSendReq from the
udtIP_Com structure
SNMP_TRecv :
- added the output xBusy
SNMP_TSend :
- expand the functionality of the output xBusy
- added a timeout of 10 seconds for getting a send acknowlegde
- changed the procedure of opening the UDP port. Now it is not closed
when the function block is deactivated in case the same connection is
used again. Only if a other function block uses the same IPC_Socket
function block, the port is closed.
- fixed bug where the function block did not reset the xSendReq from the
udtIP_Com structure
1 20191010 2019.0 Revised documentation
LTS
2019.3
2019.6
2019.9
1 20191007 " Converted from PC Worx 6
New version number: Functional changes of at least one function block, incompatibilities (e.g. change of library
format)
New build number: No functional changes, but changes in the ZIP file (e.g. documentation update, additional
examples)
SNMP_4 8/59

4 Supported PLCs
AXC F 1152 (1151412),
AXC F 2152 (2404267),
AXC F 3152 (1069208)
SNMP_4 9/59

5 Function blocks
Function block Description Version Supported License
articles
SNMP_Agent Function block for realising a SNMP Agent 3 all none
on the Controller.
SNMP_Client Function block for sending SNMP requests 3 all none
to a SNMP agent and receiving the response.
SNMP_TRecv Function block for receiving SNMP trap 3 all none
messages.
SNMP_TSend Function block for sending SNMP trap 2 all none
messages.
SNMP_BUF_TO_ADDR Function block for converting array of byte in 1 all none
special snmp format into an ip address string
in dotted notation.
SNMP_BUF_TO_DINT Function block for converting array of byte in 1 all none
special snmp format into signed double
integer value with given byte length.
SNMP_BUF_TO_DWORD Function block for converting array of byte in 1 all none
special snmp format into double word value
with given byte length.
SNMP_BUF_TO_OID Function block for converting array of byte in 1 all none
special snmp format into OID string.
SNMP_BUF_TO_TOID Function block for converting array of byte in 1 all none
special snmp format into TOID string.
SNMP_BUF_TO_UDINT Function block for converting array of byte in 1 all none
special snmp format into unsigned double
integer value with given byte length.
SNMP_DINT_TO_BUF Function block for converting a signed double 1 all none
integer value into array of byte in special
snmp format.
SNMP_DWORD_TO_BUF Function block for converting a double word 1 all none
value into array of byte in special snmp
format.
SNMP_OID_GET Function block for converting an OID from 1 all none
array of byte into a string.
SNMP_OID_SET Function block for converting an OID from 2 all none
string into an array of byte.
SNMP_OID_TO_BUF Function block for converting an OID from 2 all none
string into an array of byte.
SNMP_TOID_GET Function block for converting an TOID from 1 all none
array of byte into a string.
SNMP_TOID_SET Function block for converting an TOID from 2 all none
string into an array of byte.
SNMP_TOID_TO_BUF Function block for converting an TOID from 2 all none
string into an array of byte.
SNMP_UDINT_TO_BUF Function block for converting a unsigned 1 all none
double integer value into array of byte in
special snmp format.
SNMP_4 10/59

6 SNMP_Agent
The SNMP Agent block represents a server that enables access to control program information over the Simple
Network Management Protocol (SNMP). Management Information Base (MIB) objects to be supported are
communicated to the SNMP Agent function block. SNMP version 2c requests of the type Get-Request, Get-Next-
Request, Set- Request and Get-Bulk-Request are accepted by the agent which checks the content and then
communicates it to the control program. In turn, the response is passed onto the block where an SNMP response
is created and transmitted. It is possible to specify up to 50 user defined variable bindings (OID + Value).
NOTE : While this function block is active, other function blocks that uses the same udtIP_Socket structure can
not be used.

6.1 Function block call

6.2 Input parameters


Name Type Description
xActivate BOOL Rising edge: Activates the function block.
FALSE: Deactivates the function block.
xReset BOOL Rising edge: Resets the function block.
xSendResponse BOOL Rising edge : builds the SNMP message from the data in udtSnmpData and sends
it to the requesting communication partner.
SNMP_4 11/59

6.3 Output parameters


Name Type Description
xActive BOOL FALSE: Function block is not active.
TRUE: Function block is active. Do not start any
further action unless xActive is TRUE after activation!
xBusy BOOL TRUE: The block is busy with the service execution.
xError BOOL TRUE: An error has occurred. For details refer to
udtDiag strucure “wDiagCode” and “wAddDiagCode”.
xRequestFailure BOOL TRUE : invalid packed was received.
xRequestRcv BOOL TRUE : valid request was received. Data is ready for
further processing in udtSnmpData.
udtDiag SNMP_UDT_SNMP_AGENT_DIAG Diagnostic structure for SNMP_Agent function block.

6.4 Inout parameters


Name Type Description
udtAgentSettings SNMP_UDT_AGENT_SETTINGS Structure with configuration settings such as
communities and MIB object lists for the block.
udtSnmpData SNMP_UDT_DATA Strucutre with the data of the SNMP packet. When
xRequestRcv is TRUE, the received data can be found
in this structure. Then we have to process the data and
change the values we want to send. So when
xSendResponse is TRUE, the data in this structure will
be send to the communication partner that send the
request.
udtIP_Socket IPC_UDT_IP_SOCKET Structure for communication between IPC_Socket and
other function blocks.

6.5 Diagnosis
wDiagCode wAddDiagCode Description
16#0000 16#0000 Function block is deactivated.
16#8000 16#0000 Function block is in regular operation.
16#8500 16#0010 Socket is currently occupied. Waiting
for xOccupied to become FALSE.
16#C030 udtIP_Socket.udtDiag.udtIP_UDP_SOCKET.wStatus Error while connecting to IP
communication partner.
16#C040 udtIP_Socket.udtDiag.udtIP_UDP_SEND.wStatus Error while sending an IP packet..
16#C050 udtIP_Socket.udtDiag.udtIP_UDP_RECEIVE.wStatus Error while receiving an IP packet.
16#C414 16#0001 Timeout while sending.
16#C420 16#0001 Message is longer than 1460 bytes.
16#C510 16#0001 Error at IPC_Socket function block.
SNMP_4 12/59

6.6 Block parameters


6.6.1 SNMP_UDT_AGENT_SETTINGS
Structure for configuration settings, such as agent socket and communication monitoring.

Name Type Description


SnmpPortLocal INT Local port used by snmp agent (default 161).
FailureResponseDisable BOOL Don’t allow the snmp agent to send snmp response
receiving invalid snmp packets (true).
CommunityCheck BOOL Check community by snmp agent (default true).
CommunityReadOnly SNMP_ARR_COM_B_1_X Community for read-only access. Array with 256 byte
elements.
CommunityReadOnlyLen INT Length of the read-only community.
CommunityReadWrite SNMP_ARR_COM_B_1_X Community for read-write access. Array with 256 byte
elements.
CommunityReadWriteLen INT Length of the read-write community.
MibObjectSearch BOOL Search for requested mib object.
MibObjectNumber INT Number of mib objects in the MibObjectList.
Note: max value is the dimension of
SNMP_OBJECT_LIST!
MibObjectList SNMP_ARR_OBJECT List of 50 SNMP_UDT_OBJECT. In this list you can
define the SNMP objects that can be read by SNMP
clients.
VarBindMax INT Maximal number of variable bindings which can be
stored in the the variable binding list. Set the
dimension of type SNMP_ARR_VAR_BIND_LIST
here. Default: 2
SNMP_4 13/59

6.6.2 SNMP_UDT_OBJECT
Structure for user defined SNMP objects that can be read by SNMP clients.

Name Type Description


ObjectId SNMP_ARR_OID_B_1_X Object identifier in BYTE format. Byte array with 256 elements.
ObjectIdLen INT Length of the object identifier (ObjectId) in byte.
ValueAccess BYTE Access rights:

0 = read only
3 = read and write

ValueType BYTE Type of the value:

1 = boolean
2 = integer
3 = bit string
4 = oktet string
5 = null
6 = object identifier
67 = timeticks

ValueLen INT Max value length in BYTE (0..256 BYTE).


SNMP_4 14/59

7 SNMP_Client
The SNMP Client block is used for communication with remote SNMP agents. The request is forwarded to the
block from the control, program. This creates a packet according to SNMP version 2c or 1 and transmits it to the
agent. The packet received from the block is checked and forwarded to the control program.
NOTE : While this function block is active, other function blocks that uses the same udtIP_Socket structure can
not be used.

7.1 Function block call

7.2 Input parameters


Name Type Description
xActivate BOOL Rising edge: Activates the function block.
FALSE: Deactivates the function block.
xReset BOOL Rising edge: Resets the function block.
xSendRequest BOOL Rising edge : builds the SNMP message from the data in udtSnmpData and sends it
to the configured communication partner.
SNMP_4 15/59

7.3 Output parameters


Name Type Description
xActive BOOL FALSE: Function block is not active.
TRUE: Function block is active. Do not start any
further action unless xActive is TRUE after
activation!
xBusy BOOL TRUE: The block is busy with the service execution.
xError BOOL TRUE: An error has occurred. For details refer to
udtDiag strucure “wDiagCode” and “wAddDiagCode”.
xResponseFailure BOOL TRUE : invalid packed was received.
xResponseRcv BOOL TRUE : valid response was received. Data is ready
for further processing in udtSnmpData.
xTimeout BOOL TRUE : the function block send the message as
often as in udtClientSettings configured and waited
the configured timeout interval for a response, but no
response were received.
udtDiag SNMP_UDT_SNMP_CLIENT_DIAG Diagnostic structure for SNMP_Client function
block.

7.4 Inout parameters


Name Type Description
udtClientSettings SNMP_UDT_CLIENT_SETTINGS Structure with configuration settings, such as agent
socket and communication monitoring.
udtSnmpData SNMP_UDT_DATA Strucutre with the data of the SNMP packet. When
xSendRequest is TRUE, the data in this structure will
be send to the communication partner When
xResponseRcv is TRUE, the received data can be
found in this structure.
udtIP_Socket IPC_UDT_IP_SOCKET Structure for communication between IPC_Socket and
other function blocks.

7.5 Diagnosis
wDiagCode wAddDiagCode Description
16#0000 16#0000 Function block is deactivated.
16#8000 16#0000 Function block is in regular operation.
16#8500 16#0010 Socket is currently occupied. Waiting
for xOccupied to become FALSE.
16#C030 udtIP_Socket.udtDiag.udtIP_UDP_SOCKET.wStatus Error while connecting to IP
communication partner.
16#C040 udtIP_Socket.udtDiag.udtIP_UDP_SEND.wStatus Error while sending an IP packet.
16#C050 udtIP_Socket.udtDiag.udtIP_UDP_RECEIVE.wStatus Error while receiving an IP packet.
16#C414 16#0001 Timeout while waiting for response.
16#C420 16#0001 Message is longer that 1460 bytes.
SNMP_4 16/59

7.6 Block parameters


7.6.1 SNMP_UDT_CLIENT_SETTINGS
Structure for configuration settings, such as agent socket and communication monitoring.

Name Type Description


RemoteIp STRING IP address of the remote snmp agent.
RemotePort INT Port number used by remote snmp agent (default port 161).
Timeout TIME Timeout waiting for the snmp response by agent.
Retries INT Number of send retries until an error occures.
VarBindMax INT Enter the maximum number of variable bindings that can be stored in the variable
bindings list.
Maximum two variable bindings in one snmp message are supported due to the
SNMP_ARR_VAR_BIND_LIST size.
If the value is 0, it is set to 1 by default.
SnmpVersion BYTE SNMP protocol version

1 = SNMPv1
2 = SNMPv2 (default)
SNMP_4 17/59

8 SNMP_TSend
The Trap Sender block enables transmitting of alarm messages by the control program. Data forwarded to the
block is converted to a version 2c SNMP trap whereby several variables in the form of Variable Bindings can be
added to it.
NOTE : While this function block is active, other function blocks that uses the same udtIP_Socket structure can
not be used.

8.1 Function block call

8.2 Input parameters


Name Type Description
xActivate BOOL Rising edge: Activates the function block.
FALSE: Deactivates the function block.
xReset BOOL Rising edge: Resets the function block.
xSendTrap BOOL Rising edge : builds the SNMP trap from the data in udtSnmpTrapData and sends it to
the configured communication partner.
SNMP_4 18/59

8.3 Output parameters


Name Type Description
xActive BOOL FALSE: Function block is not active.
TRUE: Function block is active. Do not start any further action
unless xActive is TRUE after activation!
xBusy BOOL TRUE: The block is busy with the service execution.
xError BOOL TRUE: An error has occurred. For details refer to udtDiag
strucure “wDiagCode” and “wAddDiagCode”.
udtDiag SNMP_UDT_SNMP_TSEND_DIAG Diagnostic structure for SNMP_TSend function block.

8.4 Inout parameters


Name Type Description
udtTrapSenderSettings SNMP_UDT_TSEND_SETTINGS Structure with configuration settings such as IP
address and port number of the trap receiver.
udtSnmpTrapData SNMP_UDT_TRAP Strucutre with the data of the SNMP trap.
udtIP_Socket IPC_UDT_IP_SOCKET Structure for communication between IPC_Socket
and other function blocks.

8.5 Diagnosis
wDiagCode wAddDiagCode Description
16#0000 16#0000 Function block is deactivated.
16#8000 16#0000 Function block is in regular operation.
16#8500 16#0010 Socket is currently occupied. Waiting
for xOccupied to become FALSE.
16#C030 udtIP_Socket.udtDiag.udtIP_UDP_SOCKET.wStatus Error while connecting to IP
communication partner.
16#C040 udtIP_Socket.udtDiag.udtIP_UDP_SEND.wStatus Error while sending an IP packet.
16#C050 udtIP_Socket.udtDiag.udtIP_UDP_RECEIVE.wStatus Error while receiving an IP packet.
16#C414 16#0001 Timeout while sending.
16#C420 16#0001 Message is longer that 1460 bytes.
16#C510 16#0001 Error at IPC_Socket function block.
SNMP_4 19/59

8.6 Block parameters


8.6.1 SNMP_UDT_TSEND_SETTINGS

Name Type Description


RemoteIp STRING IP address of the remote snmp trap receiver.
RemotePort INT Port number used by remote snmp trap receiver.
SNMP_4 20/59

9 SNMP_TRecv
The Trap Receiver block listens for incoming messages, checks them and forwards the data to the control
program. Traps according to SNMP v2c containing several Variable Bindings are supported.
NOTE : While this function block is active, other function blocks that uses the same udtIP_Socket structure can
not be used.

9.1 Function block call

9.2 Input parameters


Name Type Description
xActivate BOOL Rising edge: Activates the function block.
FALSE: Deactivates the function block.
xReset BOOL Rising edge: Resets the function block.
SNMP_4 21/59

9.3 Output parameters


Name Type Description
xActive BOOL FALSE: Function block is not active.
TRUE: Function block is active. Do not start any further
action unless xActive is TRUE after activation!
xBusy BOOL TRUE: The block is busy with the service execution.
xError BOOL TRUE: An error has occurred. For details refer to udtDiag
strucure “wDiagCode” and “wAddDiagCode”.
xGetTrap BOOL TRUE : valid trap was received. Data is ready for further
processing in udtSnmpTrapData.
xTrapFailure BOOL TRUE : invalid packed was received.
udtDiag SNMP_UDT_SNMP_TRECV_DIAG Diagnostic structure for SNMP_TRecv function block.

9.4 Inout parameters


Name Type Description
udtTrapRecvSettings SNMP_UDT_TRECV_SETTINGS Structure with configuration settings such as
communities and local port number.
udtSnmpTrapData SNMP_UDT_TRAP Strucutre with the data of the SNMP trap.
udtIP_Socket IPC_UDT_IP_SOCKET Structure for communication between IPC_Socket
and other function blocks.

9.5 Diagnosis
wDiagCode wAddDiagCode Description
16#0000 16#0000 Function block is deactivated.
16#8000 16#0000 Function block is in regular operation.
16#8500 16#0010 Socket is currently occupied. Waiting
for xOccupied to become FALSE.
16#C030 udtIP_Socket.udtDiag.udtIP_UDP_SOCKET.wStatus Error while connecting to IP
communication partner.
16#C040 udtIP_Socket.udtDiag.udtIP_UDP_SEND.wStatus Error while sending an IP packet..
16#C050 udtIP_Socket.udtDiag.udtIP_UDP_RECEIVE.wStatus Error while receiving an IP packet.
SNMP_4 22/59

9.6 Block parameters


9.6.1 SNMP_UDT_TRECV_SETTINGS
Structure with configuration settings, such as local port.

Name Type Description


SnmpPortLocal INT Local port used by snmp trap receiver (default
161).
VarBindMax INT Maximal number of variable bindings which
can be stored in the the variable binding list.
Set the dimension of type
SNMP_ARR_TRAP_PAYLOAD here. Default:
5
CommunityCheck BOOL Check community by snmp trap receiver
(default true).
CommunityReadOnly SNMP_ARR_TRAP_COM_B_1_X Community for read-only access. Array with
256 byte elements.
CommunityReadOnlyLen INT Length of the read-only community.
CommunityReadWrite SNMP_ARR_TRAP_COM_B_1_X Community for read-write access. Array with
256 byte elements.
CommunityReadWriteLen INT Length of the read-write community.
SNMP_4 23/59

10 SNMP_BUF_TO_ADDR
Function block for converting array of byte in special snmp format into an ip address string in dotted notation.

10.1 Function block call

10.2 Input parameters


Name Type Description
arrBuf SNMP_ARR_BUF_B_1_4 Source array of byte.

10.3 Output parameters


Name Type Description
strAgentAddress STRING IP address in dotted notation.
SNMP_4 24/59

11 SNMP_BUF_TO_DINT
Function block for converting array of byte in special snmp format into signed double integer value with given byte
length.

11.1 Function block call

11.2 Input parameters


Name Type Description
arrBuf SNMP_ARR_BUF_B_1_4 Source array of byte.
iRelevantBytes INT Number of bytes that should be used from the buffer.

11.3 Output parameters


Name Type Description
diValue DINT Converted output value.
SNMP_4 25/59

12 SNMP_BUF_TO_DWORD
Function block for converting array of byte in special snmp format into double word value with given byte length.

12.1 Function block call

12.2 Input parameters


Name Type Description
arrBuf SNMP_ARR_BUF_B_1_4 Source array of byte.
iRelevantBytes INT Number of bytes that should be used from the buffer.

12.3 Output parameters


Name Type Description
dwValue DWORD Converted output value.
SNMP_4 26/59

13 SNMP_BUF_TO_OID
Function block for converting array of byte in special snmp format into OID string.

13.1 Function block call

13.2 Input parameters


Name Type Description
arrBuf SNMP_ARR_VAL_B_1_X Source array of byte.
iRelevantBytes INT Number of bytes that should be used from the buffer.

13.3 Output parameters


Name Type Description
strOID STRING Converted output value.
SNMP_4 27/59

14 SNMP_BUF_TO_TOID
Function block for converting array of byte in special snmp format into TOID string.

14.1 Function block call

14.2 Input parameters


Name Type Description
arrBuf SNMP_ARR_TRAP_VAL_B_1_X Source array of byte.
iRelevantBytes INT Number of bytes that should be used from the buffer.

14.3 Output parameters


Name Type Description
strOID STRING Converted output value.
SNMP_4 28/59

15 SNMP_BUF_TO_UDINT
Function block for converting array of byte in special snmp format into unsigned double integer value with given
byte length.

15.1 Function block call

15.2 Input parameters


Name Type Description
arrBuf SNMP_ARR_BUF_B_1_4 Source array of byte.
iRelevantBytes INT Number of bytes that should be used from the buffer.

15.3 Output parameters


Name Type Description
udiValue UDINT Converted output value.
SNMP_4 29/59

16 SNMP_DINT_TO_BUF
Function block for converting a signed double integer value into array of byte in special snmp format.

16.1 Function block call

16.2 Input parameters


Name Type Description
diValue DINT Input value that should be converted.

16.3 Output parameters


Name Type Description
arrBuf SNMP_ARR_BUF_B_1_4 Destination array of byte.
iRelevantBytes INT Number of bytes that has been set in the buffer.
SNMP_4 30/59

17 SNMP_DWORD_TO_BUF
Function block for converting a double word value into array of byte in special snmp format.

17.1 Function block call

17.2 Input parameters


Name Type Description
dwValue DWORD Input value that should be converted.

17.3 Output parameters


Name Type Description
arrBuf SNMP_ARR_BUF_B_1_4 Destination array of byte.
iRelevantBytes INT Number of bytes that has been set in the buffer.
SNMP_4 31/59

18 SNMP_OID_GET
Function block for converting an OID from array of byte into a string.

18.1 Function block call

18.2 Input parameters


Name Type Description
arrBuf SNMP_ARR_OID_B_1_X Source array of byte.
iRelevantBytes INT Number of bytes that should be used from the buffer.

18.3 Output parameters


Name Type Description
strOID STRING Converted output value.
SNMP_4 32/59

19 SNMP_OID_SET
Function block for converting an OID from string into an array of byte.

19.1 Function block call

19.2 Input parameters


Name Type Description
strOID STRING Input value that should be converted.

19.3 Output parameters


Name Type Description
arrBuf SNMP_ARR_OID_B_1_X Destination array of byte.
iRelevantBytes INT Number of bytes that has been set in the buffer.
SNMP_4 33/59

20 SNMP_OID_TO_BUF
Function block for converting an OID from string into an array of byte.

20.1 Function block call

20.2 Input parameters


Name Type Description
strOID STRING Input value that should be converted.

20.3 Output parameters


Name Type Description
arrBuf SNMP_ARR_VAL_B_1_X Destination array of byte.
iRelevantBytes INT Number of bytes that has been set in the buffer.
SNMP_4 34/59

21 SNMP_TOID_GET
Function block for converting an TOID from array of byte into a string.

21.1 Function block call

21.2 Input parameters


Name Type Description
arrBuf SNMP_ARR_TRAP_OID_B_1_X Source array of byte.
iRelevantBytes INT Number of bytes that should be used from the buffer.

21.3 Output parameters


Name Type Description
strOID STRING Converted output value.
SNMP_4 35/59

22 SNMP_TOID_SET
Function block for converting an TOID from string into an array of byte.

22.1 Function block call

22.2 Input parameters


Name Type Description
strOID STRING Input value that should be converted.

22.3 Output parameters


Name Type Description
arrBuf SNMP_ARR_TRAP_OID_B_1_X Destination array of byte.
iRelevantBytes INT Number of bytes that has been set in the buffer.
SNMP_4 36/59

23 SNMP_TOID_TO_BUF
Function block for converting an TOID from string into an array of byte.

23.1 Function block call

23.2 Input parameters


Name Type Description
strOID STRING Input value that should be converted.

23.3 Output parameters


Name Type Description
arrBuf SNMP_ARR_TRAP_VAL_B_1_X Destination array of byte.
iRelevantBytes INT Number of bytes that has been set in the buffer.
SNMP_4 37/59

24 SNMP_UDINT_TO_BUF
Function block for converting a unsigned double integer value into array of byte in special snmp format.

24.1 Function block call

24.2 Input parameters


Name Type Description
udiValue UDINT Input value that should be converted.

24.3 Output parameters


Name Type Description
arrBuf SNMP_ARR_BUF_B_1_4 Destination array of byte.
iRelevantBytes INT Number of bytes that has been set in the buffer.
SNMP_4 38/59

25 Startup example
For the startup instruction of the SNMP function blocks please find the following example:

SNMP_*_EXA.pcwex

This example is packed in the zipped Examples folder of the library.

25.1 Example 1: SNMP_*_EXA


25.1.1 Plant
For this example, the following hardware is used:

AXC F 2152 (2404267)

25.1.2 Example description


The following examples can be executed:

Function iExample Codesheet


Receive a request and send a response with the SNMP_Agent function block. 1000 SNMP_Agent
Send a request and receive a response with the SNMP_Client function block. 2000 SNMP_Client
Send a SNMP trap with the SNMP_TSend function block. 3000 SNMP_TSend
Receive a SNMP trap with the SNMP_TRecv function block. 4000 SNMP_TRecv

25.1.2.1 Example machine

For starting ExampleMachine function block, the requested example can be selected at iExample input and xStart
input has set to TRUE.

25.1.2.2 Example E_1000


(* SNMP Agent example *)
IF udtExample.iExample = 1000 THEN
CASE udtExample.iState OF
0: (* Init *)
strStatus := 'Execute Example ';
strStatus := CONCAT(strStatus, TO_STRING(udtExample.iExample,'{0:d}'));
(* Set settings for the agent *)
udtExample.udtAgent.udtAgentSettings.CommunityCheck := TRUE;
SNMP_4 39/59

udtExample.udtAgent.udtAgentSettings.SnmpPortLocal := 1610;
(* Set community for read-write access to "public" *)
udtExample.udtAgent.udtAgentSettings.CommunityReadWrite[1] := BYTE#16#70;
udtExample.udtAgent.udtAgentSettings.CommunityReadWrite[2] := BYTE#16#75;
udtExample.udtAgent.udtAgentSettings.CommunityReadWrite[3] := BYTE#16#62;
udtExample.udtAgent.udtAgentSettings.CommunityReadWrite[4] := BYTE#16#6C;
udtExample.udtAgent.udtAgentSettings.CommunityReadWrite[5] := BYTE#16#69;
udtExample.udtAgent.udtAgentSettings.CommunityReadWrite[6] := BYTE#16#63;
udtExample.udtAgent.udtAgentSettings.CommunityReadWriteLen := 6;
(* Set community for read-only access to "public" *)
udtExample.udtAgent.udtAgentSettings.CommunityReadOnly[1] := BYTE#16#70;
udtExample.udtAgent.udtAgentSettings.CommunityReadOnly[2] := BYTE#16#75;
udtExample.udtAgent.udtAgentSettings.CommunityReadOnly[3] := BYTE#16#62;
udtExample.udtAgent.udtAgentSettings.CommunityReadOnly[4] := BYTE#16#6C;
udtExample.udtAgent.udtAgentSettings.CommunityReadOnly[5] := BYTE#16#69;
udtExample.udtAgent.udtAgentSettings.CommunityReadOnly[6] := BYTE#16#63;
udtExample.udtAgent.udtAgentSettings.CommunityReadOnlyLen := 6;
(* Set MIB object number to 1, so the agent only accepts 1 valid OID *)
udtExample.udtAgent.udtAgentSettings.MibObjectNumber := 2;
(* The agent should search in the MIB objects for a valid OID *)
udtExample.udtAgent.udtAgentSettings.MibObjectSearch := TRUE;
(* Define the valid MIBs *)
(* 1.3.6.1.2.1.1.4.8 *)
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[1] :=
BYTE#16#2B;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[2] :=
BYTE#16#06;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[3] :=
BYTE#16#01;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[4] :=
BYTE#16#02;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[5] :=
BYTE#16#01;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[6] :=
BYTE#16#01;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[7] :=
BYTE#16#04;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[8] :=
BYTE#16#08;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectIdLen :=
8;
(* Access read-write *)
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ValueAccess :=
BYTE#03;
(* Value type integer32 *)
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ValueType :=
BYTE#2;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ValueLen :=
4;
(* 1.3.6.1.2.1.1.4.9 *)
udtExample.udtAgent.udtAgentSettings.MibObjectList[2].ObjectId[1] :=
BYTE#16#2B;
udtExample.udtAgent.udtAgentSettings.MibObjectList[2].ObjectId[2] :=
BYTE#16#06;
udtExample.udtAgent.udtAgentSettings.MibObjectList[2].ObjectId[3] :=
BYTE#16#01;
udtExample.udtAgent.udtAgentSettings.MibObjectList[2].ObjectId[4] :=
BYTE#16#02;
udtExample.udtAgent.udtAgentSettings.MibObjectList[2].ObjectId[5] :=
SNMP_4 40/59

BYTE#16#01;
udtExample.udtAgent.udtAgentSettings.MibObjectList[2].ObjectId[6] :=
BYTE#16#01;
udtExample.udtAgent.udtAgentSettings.MibObjectList[2].ObjectId[7] :=
BYTE#16#04;
udtExample.udtAgent.udtAgentSettings.MibObjectList[2].ObjectId[8] :=
BYTE#16#09;
udtExample.udtAgent.udtAgentSettings.MibObjectList[2].ObjectIdLen :=
8;
(* Access read-write *)
udtExample.udtAgent.udtAgentSettings.MibObjectList[2].ValueAccess :=
BYTE#03;
(* Value type integer32 *)
udtExample.udtAgent.udtAgentSettings.MibObjectList[2].ValueType :=
BYTE#2;
udtExample.udtAgent.udtAgentSettings.MibObjectList[2].ValueLen :=
4;
(* Activate the agent *)
udtExample.udtAgent.xActivate := TRUE;
(*Example value*)
bValue := BYTE#16#0F;
udtExample.iState := 100;
100: (* Wait for agent to be active *)
IF
udtExample.udtAgent.xActive = TRUE AND
udtExample.udtAgent.xBusy = FALSE
THEN
udtExample.iState := 110;
END_IF;
110: (* Wait for a valid request *)
IF udtExample.udtAgent.xRequestFailure = TRUE THEN
(* In this case we have an error and can process it in state 999 *)
udtExample.iState := 9000;
ELSIF udtExample.udtAgent.xRequestRcv = TRUE THEN
udtExample.iState := 120;
END_IF;
120: (*Check request and build response*)
(* Check if we have a Get request *)
IF udtExample.udtSnmpData.PduType = BYTE#16#00 THEN
(* Fill the variable bindings of the answer *)
udtExample.udtSnmpData.VarBindList[1].Value[1] := bValue;
udtExample.udtSnmpData.VarBindList[1].ValueLen := 1;
(* Vaue type integer32 *)
udtExample.udtSnmpData.VarBindList[1].ValueType := BYTE#16#02;
(* Send the response *)
udtExample.udtAgent.xSendReponse := TRUE;
udtExample.iState := 130;
(* Check if we have a Set request *)
ELSIF udtExample.udtSnmpData.PduType = BYTE#16#3 THEN
(* Set the local example value bValue with the value of the
variable binding of the set request *)
bValue := udtExample.udtSnmpData.VarBindList[1].Value[1];
(* Fill the variable bindings of the answer *)
udtExample.udtSnmpData.VarBindList[1].Value[1] := bValue;
udtExample.udtSnmpData.VarBindList[1].ValueLen := 1;
udtExample.udtSnmpData.VarBindList[1].ValueType := BYTE#16#02;
SNMP_4 41/59

(* Send the response. NOTE : for a set request, a get answer is sent *)
udtExample.udtAgent.xSendReponse := TRUE;
udtExample.iState := 130;
END_IF;
130:
udtExample.udtAgent.xSendReponse := FALSE;
IF xRepeat = TRUE THEN
(* Wait for next request *)
udtExample.iState := 110;
ELSE
udtExample.iState := 140;
END_IF;
140: (* Deactivate agent *)
udtExample.udtAgent.xSendReponse := FALSE;
udtExample.udtAgent.xActivate := FALSE;
udtExample.iState := 32000;
9000: (* Error handling *)
(* Insert your error handling here *)
IF xStart = FALSE THEN
udtExample.udtAgent.xSendReponse := FALSE;
udtExample.udtAgent.xActivate := FALSE;
udtExample.iState := 32000;
END_IF;
32000: (* Example is finished *)
IF udtExample.udtAgent.xActive = FALSE THEN
udtExample.udtAgent.udtAgentSettings.CommunityCheck := FALSE;
udtExample.udtAgent.udtAgentSettings.SnmpPortLocal := 0;
udtExample.udtAgent.udtAgentSettings.CommunityReadWrite[1] := BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.CommunityReadWrite[2] := BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.CommunityReadWrite[3] := BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.CommunityReadWrite[4] := BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.CommunityReadWrite[5] := BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.CommunityReadWrite[6] := BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.CommunityReadWriteLen := 0;
udtExample.udtAgent.udtAgentSettings.CommunityReadOnly[1] := BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.CommunityReadOnly[2] := BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.CommunityReadOnly[3] := BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.CommunityReadOnly[4] := BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.CommunityReadOnly[5] := BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.CommunityReadOnly[6] := BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.CommunityReadOnlyLen := 0;
udtExample.udtAgent.udtAgentSettings.MibObjectNumber := 0;
udtExample.udtAgent.udtAgentSettings.MibObjectSearch := FALSE;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[1] :=
BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[2] :=
BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[3] :=
BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[4] :=
BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[5] :=
BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[6] :=
BYTE#16#00;
SNMP_4 42/59

udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[7] :=
BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[8] :=
BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectId[9] :=
BYTE#16#00;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ObjectIdLen :=
0;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ValueAccess :=
BYTE#0;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ValueType :=
BYTE#0;
udtExample.udtAgent.udtAgentSettings.MibObjectList[1].ValueLen :=
0;
udtExample.udtSnmpData.VarBindList[1].Value[1] := BYTE#16#00;
udtExample.udtSnmpData.VarBindList[1].ValueLen := 0;
udtExample.udtSnmpData.VarBindList[1].ValueType := BYTE#16#00;
udtExample.iState := 0;
udtExample.iExample := 32000;
END_IF;
END_CASE;
END_IF;

25.1.2.3 Example E_2000


(* SNMP Client example *)
IF udtExample.iExample = 2000 THEN
CASE udtExample.iState OF
0: (* Init *)
strStatus := 'Execute Example ';
strStatus := CONCAT(strStatus, TO_STRING(udtExample.iExample,'{0:d}'));
(* Set client settings for the SNMP communication *)
udtExample.udtClient.udtClientSettings.RemoteIp := '10.250.85.13';
udtExample.udtClient.udtClientSettings.RemotePort := 1610;
udtExample.udtClient.udtClientSettings.Retries := 5;
udtExample.udtClient.udtClientSettings.Timeout := t#5s;
udtExample.udtClient.udtClientSettings.SnmpVersion := BYTE#16#02;
(* Set the community for the SNMP request, here "public" *)
udtExample.udtSnmpData.Community[1] := BYTE#16#70;
udtExample.udtSnmpData.Community[2] := BYTE#16#75;
udtExample.udtSnmpData.Community[3] := BYTE#16#62;
udtExample.udtSnmpData.Community[4] := BYTE#16#6C;
udtExample.udtSnmpData.Community[5] := BYTE#16#69;
udtExample.udtSnmpData.Community[6] := BYTE#16#63;
udtExample.udtSnmpData.CommunityLen := 6;
(* Set the number of variable bindings in the request *)
udtExample.udtSnmpData.VarBindNumber := 1;
(* Set the object id of the variable binding to 1.3.6.1.2.1.1.4.9 *)
udtExample.udtSnmpData.VarBindList[1].ObjectId[1] := BYTE#16#2B;
udtExample.udtSnmpData.VarBindList[1].ObjectId[2] := BYTE#16#06;
udtExample.udtSnmpData.VarBindList[1].ObjectId[3] := BYTE#16#01;
udtExample.udtSnmpData.VarBindList[1].ObjectId[4] := BYTE#16#02;
udtExample.udtSnmpData.VarBindList[1].ObjectId[5] := BYTE#16#01;
udtExample.udtSnmpData.VarBindList[1].ObjectId[6] := BYTE#16#01;
udtExample.udtSnmpData.VarBindList[1].ObjectId[7] := BYTE#16#04;
udtExample.udtSnmpData.VarBindList[1].ObjectId[8] := BYTE#16#09;
udtExample.udtSnmpData.VarBindList[1].ObjectIdLen := 8;
SNMP_4 43/59

(* Set initial value *)


bCurVal := BYTE#16#0F;
udtExample.iState := 100;
100: (* Prepare a Set request *)
(* Value for "Set request" here is 3 *)
udtExample.udtSnmpData.PduType := BYTE#16#03;
udtExample.udtSnmpData.VarBindList[1].Value[1] := bCurVal;
udtExample.udtSnmpData.VarBindList[1].ValueLen := 1;
(* Value for "Integer32" here is 2 *)
udtExample.udtSnmpData.VarBindList[1].ValueType := BYTE#16#02;
udtExample.udtClient.xActivate := TRUE;
udtExample.iState := 110;
110: (* Send the request *)
IF
udtExample.udtClient.xActive = TRUE AND
udtExample.udtClient.xBusy = FALSE
THEN
udtExample.udtClient.xSendRequest := TRUE;
udtExample.iState := 120;
END_IF;
120: (* Wait for the response *)
IF udtExample.udtClient.xResponseRcv = TRUE THEN
udtExample.iState := 130;
END_IF;
130: (* Check response *)
(* The value has to be the same value that we set in our previous request *)
IF udtExample.udtSnmpData.VarBindList[1].Value[1] = bCurVal THEN
udtExample.udtClient.xSendRequest := FALSE;
udtExample.iState := 200;
END_IF;
200: (* Wait for client to be active and send the request *)
(* Now we send a "Get request", here the value is 0 *)
udtExample.udtSnmpData.PduType := BYTE#16#00;
IF
udtExample.udtClient.xActive = TRUE AND
udtExample.udtClient.xBusy = FALSE
THEN
udtExample.udtClient.xSendRequest := TRUE;
udtExample.iState := 210;
END_IF;
210: (* Wait for the response *)
IF udtExample.udtClient.xTimeout = TRUE THEN
(* The agent did not answer, we can process the error in state 9000 *)
udtExample.iState := 9000;
ELSIF udtExample.udtClient.xResponseRcv = TRUE THEN
udtExample.iState := 220;
END_IF;
220: (* Check response *)
(* Here we check if the value of the first variable binding is
what we expected *)
IF udtExample.udtSnmpData.VarBindList[1].Value[1] = bCurVal THEN
udtExample.udtClient.xSendRequest := FALSE;
udtExample.iState := 300;
END_IF;
300: (* No we can repeat everything or just deactivate the function blocks. *)
SNMP_4 44/59

IF xRepeat = TRUE THEN


(* Send requests again *)
TON_NEW_REQUEST.IN := TRUE;
udtExample.iState := 310;
ELSE
(* Deactivate client *)
udtExample.udtClient.xSendRequest := FALSE;
udtExample.udtClient.xActivate := FALSE;
udtExample.iState := 32000;
END_IF;
310: (* Check if the interval is done and prepare the request *)
IF TON_NEW_REQUEST.Q = TRUE THEN
TON_NEW_REQUEST.IN := FALSE;
bCurVal := TO_BYTE(TO_INT(bCurVal) + 1);
udtExample.iState := 100;
END_IF;
9000: (* Error handling *)
(* Insert your error handling here *)
IF xStart = FALSE THEN
udtExample.udtClient.xSendRequest := FALSE;
udtExample.udtClient.xActivate := FALSE;
udtExample.iState := 32000;
END_IF;
32000: (* Example is finished *)
IF udtExample.udtClient.xActive = FALSE THEN
udtExample.udtClient.udtClientSettings.RemoteIp := '';
udtExample.udtClient.udtClientSettings.RemotePort := 0;
udtExample.udtClient.udtClientSettings.Retries := 0;
udtExample.udtClient.udtClientSettings.Timeout := t#0s;
udtExample.udtClient.udtClientSettings.SnmpVersion := BYTE#16#00;
udtExample.udtSnmpData.Community[1] := BYTE#16#00;
udtExample.udtSnmpData.Community[2] := BYTE#16#00;
udtExample.udtSnmpData.Community[3] := BYTE#16#00;
udtExample.udtSnmpData.Community[4] := BYTE#16#00;
udtExample.udtSnmpData.Community[5] := BYTE#16#00;
udtExample.udtSnmpData.Community[6] := BYTE#16#00;
udtExample.udtSnmpData.CommunityLen := 0;
udtExample.udtSnmpData.PduType := BYTE#16#00;
udtExample.udtSnmpData.VarBindNumber := 0;
udtExample.udtSnmpData.VarBindList[1].ObjectId[1] := BYTE#16#00;
udtExample.udtSnmpData.VarBindList[1].ObjectId[2] := BYTE#16#00;
udtExample.udtSnmpData.VarBindList[1].ObjectId[3] := BYTE#16#00;
udtExample.udtSnmpData.VarBindList[1].ObjectId[4] := BYTE#16#00;
udtExample.udtSnmpData.VarBindList[1].ObjectId[5] := BYTE#16#00;
udtExample.udtSnmpData.VarBindList[1].ObjectId[6] := BYTE#16#00;
udtExample.udtSnmpData.VarBindList[1].ObjectId[7] := BYTE#16#00;
udtExample.udtSnmpData.VarBindList[1].ObjectId[8] := BYTE#16#00;
udtExample.udtSnmpData.VarBindList[1].ObjectId[9] := BYTE#16#00;
bValue := BYTE#16#00;
udtExample.udtSnmpData.VarBindList[1].Value[1] := BYTE#16#00;
udtExample.udtSnmpData.VarBindList[1].ValueLen := 0;
udtExample.udtSnmpData.VarBindList[1].ValueType := BYTE#16#00;
udtExample.udtSnmpData.VarBindList[1].ObjectIdLen := 0;
udtExample.iState := 0;
SNMP_4 45/59

udtExample.iExample := 32000;
END_IF;
END_CASE;
END_IF;

25.1.2.4 Example E_3000


(* SNMP TSend example *)
IF udtExample.iExample = 3000 THEN
CASE udtExample.iState OF
0: (* Init *)
strStatus := 'Execute Example ';
strStatus := CONCAT(strStatus, TO_STRING(udtExample.iExample,'{0:d}'));
(* Set trap sender settings for the SNMP communication *)
udtExample.udtTSend.udtTrapSenderSettings.RemoteIp := '10.250.85.13';
udtExample.udtTSend.udtTrapSenderSettings.RemotePort := 1620;
(* Set the community for the SNMP request, here "public" *)
udtExample.udtSnmpTrapData.Community[1] := BYTE#16#70;
udtExample.udtSnmpTrapData.Community[2] := BYTE#16#75;
udtExample.udtSnmpTrapData.Community[3] := BYTE#16#62;
udtExample.udtSnmpTrapData.Community[4] := BYTE#16#6C;
udtExample.udtSnmpTrapData.Community[5] := BYTE#16#69;
udtExample.udtSnmpTrapData.Community[6] := BYTE#16#63;
udtExample.udtSnmpTrapData.CommunityLen := 6;
(* Set settings for the trap sender *)
udtExample.udtSnmpTrapData.CommunityChecked := FALSE;
(* Value for a trap message *)
udtExample.udtSnmpTrapData.PduType := BYTE#16#07;
(* Set the object id of the variable binding to 1.3.6.1.2.1.2.2.1.1 *)
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[1] := BYTE#16#2B;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[2] := BYTE#16#06;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[3] := BYTE#16#01;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[4] := BYTE#16#02;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[5] := BYTE#16#01;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[6] := BYTE#16#02;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[7] := BYTE#16#02;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[8] := BYTE#16#01;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[9] := BYTE#16#01;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectIdLen := 9;
(* Value for integer32 *)
udtExample.udtSnmpTrapData.VarBindList[1].ValueType := BYTE#16#02;
udtExample.udtSnmpTrapData.VarBindList[1].ValueLen := 1;
udtExample.udtSnmpTrapData.VarBindList[1].Value[1] := BYTE#16#FF;
(* Set number of variable bindings of the trap message *)
udtExample.udtSnmpTrapData.VarBindNumber := 1;
(* Activate trap sender *)
udtExample.udtTSend.xActivate := TRUE;
udtExample.iState := 100;
100: (* Wait for trap sender to be active and send trap *)
IF
udtExample.udtTSend.xActive = TRUE AND
udtExample.udtTSend.xBusy = FALSE
THEN
udtExample.udtTSend.xSendTrap := TRUE;
udtExample.iState := 110;
SNMP_4 46/59

END_IF;
110: (* Function block should be busy *)
IF udtExample.udtTSend.xBusy = TRUE THEN
udtExample.iState := 120;
END_IF;
120: (* When not busy anymore and no error occured, the trap was sent *)
IF udtExample.udtTSend.xError = TRUE THEN
udtExample.iState := 9000;
ELSIF udtExample.udtTSend.xBusy = FALSE THEN
udtExample.iState := 130;
END_IF;
130: (* Deactivate trap sender *)
udtExample.udtTSend.xActivate := FALSE;
udtExample.udtTSend.xSendTrap := FALSE;
udtExample.iState := 32000;
9000: (* Error handling *)
(* Insert your error handling here *)
IF xStart = FALSE THEN
udtExample.udtTSend.xActivate := FALSE;
udtExample.udtTSend.xSendTrap := FALSE;
udtExample.iState := 32000;
END_IF;
32000: (* Example is finished *)
udtExample.udtTSend.udtTrapSenderSettings.RemoteIp := '';
udtExample.udtTSend.udtTrapSenderSettings.RemotePort := 0;
udtExample.udtSnmpTrapData.Community[1] := BYTE#16#00;
udtExample.udtSnmpTrapData.Community[2] := BYTE#16#00;;
udtExample.udtSnmpTrapData.Community[3] := BYTE#16#00;;
udtExample.udtSnmpTrapData.Community[4] := BYTE#16#00;;
udtExample.udtSnmpTrapData.Community[5] := BYTE#16#00;;
udtExample.udtSnmpTrapData.Community[6] := BYTE#16#00;;
udtExample.udtSnmpTrapData.CommunityLen := 0;
udtExample.udtSnmpTrapData.CommunityChecked := FALSE;
udtExample.udtSnmpTrapData.PduType := BYTE#16#00;;
udtExample.udtSnmpTrapData.RequestId := DWORD#16#00000000;
udtExample.udtSnmpTrapData.ErrorStatus := BYTE#16#00;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[1] := BYTE#16#00;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[2] := BYTE#16#00;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[3] := BYTE#16#00;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[4] := BYTE#16#00;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[5] := BYTE#16#00;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[6] := BYTE#16#00;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[7] := BYTE#16#00;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[8] := BYTE#16#00;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectId[9] := BYTE#16#00;
udtExample.udtSnmpTrapData.VarBindList[1].ObjectIdLen := 0;
udtExample.udtSnmpTrapData.VarBindList[1].ValueType := BYTE#16#00;
udtExample.udtSnmpTrapData.VarBindList[1].ValueLen := 0;
udtExample.udtSnmpTrapData.VarBindList[1].Value[1] := BYTE#16#00;
udtExample.udtSnmpTrapData.VarBindNumber := 0;
udtExample.iState := 0;
udtExample.iExample := 32000;
SNMP_4 47/59

END_CASE;
END_IF;

25.1.2.5 Example E_4000


(* SNMP TRecv example *)
IF udtExample.iExample = 4000 THEN
CASE udtExample.iState OF
0: (* Init *)
strStatus := 'Execute Example ';
strStatus := CONCAT(strStatus, TO_STRING(udtExample.iExample,'{0:d}'));
(* Set trap receiver settings *)
udtExample.udtTRecv.udtTrapRecvSettings.CommunityCheck := TRUE;
udtExample.udtTRecv.udtTrapRecvSettings.SnmpPortLocal := 1620;
(* Set community for read-write access to "public" *)
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWrite[1] := BYTE#16#70;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWrite[2] := BYTE#16#75;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWrite[3] := BYTE#16#62;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWrite[4] := BYTE#16#6C;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWrite[5] := BYTE#16#69;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWrite[6] := BYTE#16#63;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWriteLen := 6;
(* Set community for read-only access to "public" *)
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnly[1] := BYTE#16#70;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnly[2] := BYTE#16#75;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnly[3] := BYTE#16#62;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnly[4] := BYTE#16#6C;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnly[5] := BYTE#16#69;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnly[6] := BYTE#16#63;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnlyLen := 6;
(* Activate trap receiver *)
udtExample.udtTRecv.xActivate := TRUE;
udtExample.iState := 100;
100: (* Wait for trap receiver to be active *)
IF
udtExample.udtTRecv.xActive = TRUE AND
udtExample.udtTRecv.xBusy = FALSE
THEN
udtExample.iState := 110;
END_IF;
110: (* Wait until the function block receives a trap *)
IF udtExample.udtTRecv.xTrapFailure = TRUE THEN
(* An invalid trap was received, we can process the error in state 9000 *)
udtExample.iState := 9000;
ELSIF udtExample.udtTRecv.xGetTrap = TRUE THEN
udtExample.iState := 120;
END_IF;
120: (* Process the trap message *)
IF udtExample.udtSnmpTrapData.PduType = BYTE#16#07 THEN
udtExample.iState := 130;
END_IF;
130: (* Deactivate trap receiver *)
udtExample.udtTRecv.xActivate := FALSE;
udtExample.iState := 32000;
SNMP_4 48/59

9000: (* Error handling *)


(* Insert your error handling here *)
IF xStart = FALSE THEN
udtExample.udtTRecv.xActivate := FALSE;
udtExample.iState := 32000;
END_IF;
32000: (* Example is finished *)
IF udtExample.udtTRecv.xActive = FALSE THEN
udtExample.udtTRecv.udtTrapRecvSettings.CommunityCheck := FALSE;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWrite[1] := BYTE#16#00;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWrite[2] := BYTE#16#00;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWrite[3] := BYTE#16#00;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWrite[4] := BYTE#16#00;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWrite[5] := BYTE#16#00;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWrite[6] := BYTE#16#00;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadWriteLen := 0;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnly[1] := BYTE#16#00;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnly[2] := BYTE#16#00;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnly[3] := BYTE#16#00;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnly[4] := BYTE#16#00;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnly[5] := BYTE#16#00;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnly[6] := BYTE#16#00;
udtExample.udtTRecv.udtTrapRecvSettings.CommunityReadOnlyLen := 0;
udtExample.udtTRecv.udtTrapRecvSettings.SnmpPortLocal := 0;
udtExample.iState := 0;
udtExample.iExample := 32000;
END_IF;
END_CASE;
END_IF;
SNMP_4 49/59

26 Appendix
26.1 Diag codes of used firmware function blocks
26.1.1 TCP_SOCKET
ERROR = FALSE

Status code Description


16#0000 Situation is normal (no error).
16#8000 Socket is trying to connect the partner.
16#8001 Server is listening for a client.
16#8002 Server has rejected a client because the IP address and port number do not match.
16#8003 Not all data could be sent. Remaining data will be sent in the next cycle(s).
16#8004 Not all data received: Received length < Expected length
ERROR = TRUE

Error Description Error only for


code
16#C001 Socket creation failed.
16#C002 IP has wrong format.
16#C003 Memory allocation failed.
16#C100 Unexpected error during connecting of a client to a server. TCP/TLS_SOCKET /
TLS_SOCKET_2
16#C101 Unexpected error during receive operation. UDP/TCP/TLS_RECEIVE
16#C102 Unexpected error during send operation. UDP/TCP/TLS_SEND
16#C103 Unexpected error during bind operation. UDP_SOCKET /
UDP_SOCKET_2
16#C104 Unexpected error during listen operation. TCP/TLS_SOCKET /
TLS_SOCKET_2
16#C105 Unexpected error during accept operation. TCP/TLS_SOCKET /
TLS_SOCKET_2
16#C150 The TLS parameterization of the TLS_SEND/TLS_RECEIVE function TLS_*
blocks is inconsistent with the TLS_SOCKET / TLS_SOCKET_2
function block.
This is the case when:

TLS_SEND/TLS_RECEIVE require secure transmission/reception


of data (SEND_SECURE/RECEIVE_SECURE input = TRUE), but
the socket is not yet initialized for TLS communication
(START_TLS input of TLS_SOCKET / TLS_SOCKET_2 is
FALSE).
TLS_SEND/TLS_RECEIVE require insecure
transmission/reception of data
(SEND_SECURE/RECEIVE_SECURE input = FALSE), but the
socket is already initialized for TLS communication (START_TLS
input of TLS_SOCKET / TLS_SOCKET_2 is TRUE).
SNMP_4 50/59

16#C151 An error regarding the START_TLS input of the TLS_SOCKET / TLS_*


TLS_SOCKET_2 function block has occurred. START_TLS was set
from TRUE to FALSE during opened TLS socket (ACTIVE input =
TRUE). This is the case when:
16#C201 There are too many open sockets in the underlying socket provider.
16#C202 An operation on a nonblocking socket cannot be completed
immediately.
16#C204 The datagram is too long.
16#C205 Only one use of an address is normally permitted.
16#C206 The selected IP address is not valid in this context.
16#C207 The connection was aborted by the .NET Framework or the underlying
socket provider.
16#C208 The connection was reset by the remote peer.
16#C210 The application tried to send or receive data, and the Socket is not
connected (_SOCKET.ACTIVE == False).
16#C211 No such host is known. The name is not an official host name or alias.
16#C212 An unspecified System.Net.Sockets. Socket error has occurred.
16#C213 The remote host is actively refusing a connection.
16#C214 An invalid argument was supplied to a System.Net.Sockets.Socket
member.
16#C215 A blocking operation is in progress.
16#C216 The overlapped operation was aborted due to the closure of the
System.Net.Sockets.Socket.
16#C217 The application has initiated an overlapped operation that cannot be
completed immediately.
16#C218 A blocking System.Net.Sockets.Socket call was canceled.
16#C219 An attempt was made to access a System.Net.Sockets.Socket in a
way that is forbidden by its access permissions.
16#C21A An invalid pointer address was detected by the underlying socket
provider.
16#C21B A System.Net.Sockets.Socket operation was attempted on a non-
socket.
16#C21C A required address was omitted from an operation on a
System.Net.Sockets.Socket.

16#C21D An unknown, invalid, or unsupported option or level was used with a


System.Net.Sockets.Socket.
16#C21E The protocol type is incorrect for this System.Net.Sockets.Socket.
16#C21F The protocol is not implemented or has not been configured.
16#C220 The support for the specified socket type does not exist in this address
family.
16#C221 The address family is not supported by the protocol family.
16#C222 The protocol family is not implemented or has not been configured.
16#C223 he address family specified is not supported. This error is returned if
the IPv6 address family was specified and the IPv6 stack is not
installed on the local machine. This error is returned if the IPv4 address
family was specified and the IPv4 stack is not installed on the local
machine.
16#C224 The network is not available.
16#C225 No route to the remote host exists.
SNMP_4 51/59

16#C226 The application tried to set System.Net.Sockets.SocketOptionName.


KeepAlive on a connection that has already timed out.
16#C227 No free buffer space is available for a System.Net.Sockets.Socket
operation.
16#C228 A request to send or receive data was disallowed because the
System.Net.Sockets.Socket has already been closed.
16#C229 The connection attempt timed out, or the connected host has failed to
respond.
16#C22A The operation failed because the remote host is down.
16#C22B There is no network route to the specified host. Could not connect to
DEST_IP.
16#C22C Too many processes are using the underlying socket provider.
16#C22D The network subsystem is unavailable.
16#C22E The version of the underlying socket provider is out of range.
16#C22F The underlying socket provider has not been initialized.
16#C230 A graceful shutdown is in progress.
16#C231 The specified class was not found.
16#C232 The name of the host could not be resolved. Try again later.
16#C233 The error is unrecoverable or the requested database cannot be
located.
16#C234 The requested name or IP address was not found on the name server.
SNMP_4 52/59

26.2 Data types

TYPE
(* array for snmp packets given by function block *)
SNMP_ARR_PACKET_B_1_1462 : ARRAY [1..1462] OF BYTE;
SNMP_ARR_TRAP_B_1_1462 : ARRAY [1..1462] OF BYTE;
(* array for converting snmp values *)
SNMP_ARR_BUF_B_1_4 : ARRAY [1..4] OF BYTE;
(* decrease the buffer size of the following 6 buffers to save memory *)
(* array for snmp information / value *)
SNMP_ARR_VAL_B_1_X : ARRAY [1..256] OF BYTE;
(* array for snmp information / community *)
SNMP_ARR_COM_B_1_X : ARRAY [1..256] OF BYTE;
(* array for snmp information / object identifier *)
SNMP_ARR_OID_B_1_X : ARRAY [1..256] OF BYTE;
(* array for snmp information / object identifier *)
SNMP_ARR_TRAP_OID_B_1_X : ARRAY [1..256] OF BYTE;
(* array for snmp information / value *)
SNMP_ARR_TRAP_VAL_B_1_X : ARRAY [1..256] OF BYTE;
(* array for snmp information / community *)
SNMP_ARR_TRAP_COM_B_1_X : ARRAY [1..256] OF BYTE;
(* structure of one variable binding *)
SNMP_UDT_VAR_BIND : STRUCT
(* object number in the user mib list given by the snmp agent *)
ObjectNumber : INT;
(* object identifier in BYTE format *)
ObjectId : SNMP_ARR_OID_B_1_X;
(* len of the object identifier in BYTE *)
ObjectIdLen : INT;
(* type of data
1 - bool
2 - INTeger
3 - bit string
4 - oktet string
5 - null
6 - object identifier
67 - timeticks *)
ValueType : BYTE;
(* snmp data *)
Value : SNMP_ARR_VAL_B_1_X;
(* len of data in BYTE *)
ValueLen : INT;
END_STRUCT;

(* list of variable bindings for the exchange of data between snmp and fb
note : adjust maximal number of variable bindings here and take care about
the 'SNMP_UDT_AGENT_SETTINGS'.VarBinMax and
'SNMP_UDT_CLIENT_SETTINGS'.VarBindMax. *)
SNMP_ARR_VAR_BIND_LIST : ARRAY [1..2] OF SNMP_UDT_VAR_BIND;
(* adjust the buffer size for your application *)
(* information of snmp packet used by the snmp agent and client internal *)
SNMP_4 53/59

(* structure for snmp data of a packet read from or send to the network
used for internal processing *)
SNMP_UDT_PACKET : STRUCT
(* 1) paket lenght in BYTE *)
PacketLength : INT;
(* 2) snmp version number *)
SnmpVersion : BYTE;
(* 3) community name *)
Community : SNMP_ARR_COM_B_1_X;
(* len of the community in BYTE *)
CommunityLen : INT;
(* pdu header *)
(* 4) pdu type (pdu header) *)
PduType : BYTE;
(* 5) pdu len in BYTE *)
PduLen : INT;
(* 6) request id *)
RequestId : DWORD;
(* 7) error status *)
ErrorStatus : BYTE;
(* 8) error index *)
ErrorIndex : BYTE;
(* pdu body *)
(* 9) len of pdu body in BYTE *)
PduBodyLen : INT;
(* VariableBinding *)
(* 10a) len of varBind in BYTE *)
VarBindLen : INT;
(* list of variable bindigs *)
VarBindList : SNMP_ARR_VAR_BIND_LIST;
(* number of variable bindings (payloads) *)
VarBindNumber : INT;
END_STRUCT;
(* information of the snmp packet used by the application *)
(* struct of snmp data received by or send to snmp agent by application *)
SNMP_UDT_DATA : STRUCT
(* snmp protocol version (default 2 - SNMPv2, 1 - SNMPv1) *)
SnmpVersion : BYTE;
(* snmp community *)
Community : SNMP_ARR_COM_B_1_X;
(* len of the snmp community in BYTE *)
CommunityLen : INT;
(* community has been checked by snmp agent *)
CommunityChecked : BOOL;
(* pdu type :
0 - Get Request
1 - Get Next Request
2 - Response (filtered out by the snmp agent)
3 - Set Request
5 - Get Bulk Request *)
PduType : BYTE;
RequestId : DWORD;
(* error status :
0 - no Error
1 - tooBig
2 - noSuchName
3 - badValue
4 - readOnly
5 - genError *)
ErrorStatus : BYTE;
(* error index - in case of an error the index is the number of the
variable binding causing the failure *)
ErrorIndex : BYTE;
SNMP_4 54/59

(* list of variable bindings *)


VarBindList : SNMP_ARR_VAR_BIND_LIST;
(* number of variables bindings (payloads) *)
VarBindNumber : INT;
(* Source *)
uiSourcePort : UINT;
strSourceAddress : STRING;
END_STRUCT;
(* information for one object of the MIB of snmp agent fb *)
SNMP_UDT_OBJECT : STRUCT
(* object identifier in BYTE format *)
ObjectId : SNMP_ARR_OID_B_1_X;
(* len of the object identifier in BYTE *)
ObjectIdLen : INT;
(* access right (0 - read-only, 3 - read-write) *)
ValueAccess : BYTE;
(* value type :
1 - bool
2 - integer
3 - bit string
4 - octet string
5 - null
6 - object identifier
67 - timeticks *)
ValueType : BYTE;
(* max value length in BYTE (0..256 BYTE) *)
ValueLen : INT;
END_STRUCT;
(* example for an object id in BYTE format : *)
(* iso.org.dod.INTernet.mgmt.mib2.system.sysName.0 *)
(* 1. 3. 6. 1. 2. 1. 1. 3.0 *)
(* 0x2B 0x06 0x01 0x02 0x01 0x01 0x03 0x00 *)

(* list of supported mib objects by the snmp agent


note : adjust the maximal number of mib objects here *)
SNMP_ARR_OBJECT : ARRAY [1..50] OF SNMP_UDT_OBJECT;
(* settings for the snmp agent (optional) *)
SNMP_UDT_AGENT_SETTINGS : STRUCT
(* local port used by snmp agent (default 161) *)
SnmpPortLocal : INT;
(* don't allow the snmp agent to send snmp response receiving invalid
snmp packets (true) *)
FailureResponseDisable : BOOL;
(* check community by snmp agent (true) *)
CommunityCheck : BOOL;
(* community for read-only access *)
CommunityReadOnly : SNMP_ARR_COM_B_1_X;
(* length of the read-only community *)
CommunityReadOnlyLen : INT;
(* community for read-only access *)
CommunityReadWrite : SNMP_ARR_COM_B_1_X;
(* length of the read-write community *)
CommunityReadWriteLen : INT;
(* search for requested mib object *)
MibObjectSearch : BOOL;
(* number of mib objects in the MibObjectList
note : max value is the dimension of SNMP_OBJECT_LIST ! *)
MibObjectNumber : INT;
(* list of snmp mib objects *)
MibObjectList : SNMP_ARR_OBJECT;
SNMP_4 55/59

END_STRUCT;
(* settings for the snmp client *)
SNMP_UDT_CLIENT_SETTINGS : STRUCT
(* port number used by the remote snmp agent *)
RemoteIp : STRING;
(* port number of remote snmp agent (default 161) *)
RemotePort : INT;
(* timeout waiting for the snmp response by agent *)
Timeout : TIME;
(* number of retries send a request and wait for the response *)
Retries : INT;
(* snmp protocol version (default 2 - SNMPv2, 1 - SNMPv1) *)
SnmpVersion : BYTE;
END_STRUCT;
(* Diagnostic structure for SNMP_Agent *)
SNMP_UDT_SNMP_AGENT_DIAG : STRUCT
iFunction : INT;
wDiagCode : WORD;
wAddDiagCode : WORD;
END_STRUCT;
(* Diagnostic structure for SNMP_Client *)
SNMP_UDT_SNMP_CLIENT_DIAG : STRUCT
iFunction : INT;
wDiagCode : WORD;
wAddDiagCode : WORD;
END_STRUCT;
(* Diagnostic structure for SNMP_TRecv *)
SNMP_UDT_SNMP_TRECV_DIAG : STRUCT
iFunction : INT;
wDiagCode : WORD;
wAddDiagCode : WORD;
END_STRUCT;
(* Diagnostic structure for SNMP_TSend *)
SNMP_UDT_SNMP_TSEND_DIAG : STRUCT
iFunction : INT;
wDiagCode : WORD;
wAddDiagCode : WORD;
END_STRUCT;
(* Info of payload for the trap sender and receiver function block *)
SNMP_UDT_TRAP_PAYLOAD : STRUCT
(* object identifier byte format *)
ObjectId : SNMP_ARR_TRAP_OID_B_1_X;
(* len of the object identifier in byte *)
ObjectIdLen : INT;
(* value type
1 - bool
2 - integer
3 - bit string
4 - oktet string
5 - null
6 - object identifier
67 - timeticks *)
ValueType : BYTE;
Value : SNMP_ARR_TRAP_VAL_B_1_X;
(* max value length in byte (0..256 byte) *)
ValueLen : INT;
END_STRUCT;
SNMP_4 56/59

(* example for an object id in byte format : *)


(* iso.org.dod.internet.mgmt.mib2.system.sysName.0 *)
(* 1. 3. 6. 1. 2. 1. 1. 3.0 *)
(* 0x2B 0x06 0x01 0x02 0x01 0x01 0x03 0x00 *)
(* list of supported mib objects by the snmp trap sender and receiver
note : adjust the maximal number of trap variable bindings here and take
care about the 'SNMP_TRECV_SETTINGS'.VarBindMax *)
(* adjust the buffer size for your application ! *)
SNMP_ARR_TRAP_PAYLOAD : ARRAY [1..5] OF SNMP_UDT_TRAP_PAYLOAD;
(* information of snmp trap packet *)
(* structure for snmp trap data of a packet read from or send to the
network used for internal processing *)
SNMP_UDT_TRAP_PACKET : STRUCT
(* 1) paket lenght in byte *)
PacketLength : INT;
(* 2) snmp version number (0x2 0x1 0x0) *)
SnmpVersion : BYTE;
(* 3) community name *)
Community : SNMP_ARR_TRAP_COM_B_1_X;
(* len of the community in byte *)
CommunityLen : INT;
(* pdu header *)
(* 4) pdu type (pdu header) *)
PduType : BYTE;
(* 5) pdu len in byte *)
PduLen : INT;
(* 6) request id *)
RequestId : DWORD;
(* 7) error status *)
ErrorStatus : BYTE;
(* 8) error index *)
ErrorIndex : BYTE;
(* pdu body *)
(* 9) len of pdu body in byte *)
PduBodyLen : INT;
(* VariableBinding *)
(* 10a) len of varBind in byte *)
VarBindLen : INT;
(* variable bindings (payload) *)
VarBindList : SNMP_ARR_TRAP_PAYLOAD;
(* number of variable bindings (payloads) *)
VarBindNumber : INT;
END_STRUCT;
(* information of the snmp trap packet used by the application *)
(* structure of snmp trap data received /send by trap sender /receiver *)
SNMP_UDT_TRAP : STRUCT
(* snmp community *)
Community : SNMP_ARR_TRAP_COM_B_1_X;
(* len of the snmp community in byte *)
CommunityLen : INT;
(* community has been checked by snmp trap receiver (true) *)
CommunityChecked : BOOL;
(* pdu type : 7 - snmpv2 trap, 6 - inform request *)
PduType : BYTE;
(* request id *)
RequestId : DWORD;
(* error status
0 - no Error
1 - tooBig
2 - noSuchName
3 - badValue
SNMP_4 57/59

4 - readOnly
5 - genError *)
ErrorStatus : BYTE;
(* variable bindings (payload) *)
VarBindList : SNMP_ARR_TRAP_PAYLOAD;
(* number of variables bindings (payloads) *)
VarBindNumber : INT;
(* Source *)
uiSourcePort : UINT;
strSourceAddress : STRING;
END_STRUCT;
(* settings for the snmp trap receiver (optional) *)
SNMP_UDT_TRECV_SETTINGS : STRUCT
(* local port used by the snmp trap receiver *)
SnmpPortLocal : INT;
(* check community by snmp trap receiver *)
CommunityCheck : BOOL;
(* community for read-only access *)
CommunityReadOnly : SNMP_ARR_TRAP_COM_B_1_X;
(* length of the read-only community *)
CommunityReadOnlyLen : INT;
(* community for read-only access *)
CommunityReadWrite : SNMP_ARR_TRAP_COM_B_1_X;
(* length of the read-write community *)
CommunityReadWriteLen : INT;
END_STRUCT;
(* settings for the snmp trap sender *)
SNMP_UDT_TSEND_SETTINGS : STRUCT
(* port number used by remote snmp trap receiver *)
RemoteIp : STRING;
(* port number of the remote snmp trap receiver *)
RemotePort : INT;
END_STRUCT;
(* structure of snmp trap data received /send by trap receiver/ sender *)
SNMP1_UDT_TRAP : STRUCT
Community : SNMP_ARR_TRAP_COM_B_1_X;
CommunityLen : INT;
CommunityChecked : BOOL;
(* pdu type 4 - snmpv1 trap *)
PduType : BYTE;
EnterpriseOid : SNMP_ARR_TRAP_OID_B_1_X;
EnterpriseOidLen : INT;
AgentAddress : SNMP_ARR_BUF_B_1_4;
GenericTrapCode : DWORD;
SpecificTrapCode : DWORD;
TimeStamp : UDINT;
VarBindList : SNMP_ARR_TRAP_PAYLOAD;
VarBindNumber : INT;
END_STRUCT;
END_TYPE
SNMP_4 58/59

27 In case of problems
In case of problems you should check in general:

1. Is the latest version of the library used? You can download the latest version from the PLCnext Store
(https://www.plcnextstore.com).
2. Is the library released for the PLCnext Engineer version you are using? Please refer to the chapter “Change
notes” of this documentation.
3. Is the library released for the PLC / PLC firmware version you are using? Please refer to the chapter “Change
notes” of this documentation.
4. Does every module in your system has the required firmware version? In some cases functionalities are
supported for higher firmware versions only.
5. Is your system running? Check all LEDs of all modules. Check the status in the web based management of
your PLC.
SNMP_4 59/59

28 Support
For technical support please contact your local PHOENIX CONTACT agency
at https://www.phoenixcontact.com
Owner:
PHOENIX CONTACT Electronics GmbH
Business Unit Automation Systems
System Services
Library Services
In case of a support request we need:

Development system with


Name (e.g. PC Worx, PLCnext Engineer)
Version (e.g. PLCnext Engineer 2022.0.1 LTS)
Bus structure / plant including all articles with
Name
Order number
Firmware version
External components
Used libraries with
Name
Version (e.g. IOL_Basic_7)
Detailed problem description with
Diag codes of all function blocks in error state

You might also like