Professional Documents
Culture Documents
SNMP_4
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
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
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.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.2 SNMP_UDT_OBJECT
Structure for user defined SNMP objects that can be read by SNMP clients.
0 = read only
3 = read and write
1 = boolean
2 = integer
3 = bit string
4 = oktet string
5 = null
6 = object identifier
67 = timeticks
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.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
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.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
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.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
10 SNMP_BUF_TO_ADDR
Function block for converting array of byte in special snmp format into an ip address string in dotted notation.
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.
12 SNMP_BUF_TO_DWORD
Function block for converting array of byte in special snmp format into double word value with given byte length.
13 SNMP_BUF_TO_OID
Function block for converting array of byte in special snmp format into OID string.
14 SNMP_BUF_TO_TOID
Function block for converting array of byte in special snmp format into TOID string.
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.
16 SNMP_DINT_TO_BUF
Function block for converting a signed double integer value into array of byte in special snmp format.
17 SNMP_DWORD_TO_BUF
Function block for converting a double word value into array of byte in special snmp format.
18 SNMP_OID_GET
Function block for converting an OID from array of byte into a string.
19 SNMP_OID_SET
Function block for converting an OID from string into an array of byte.
20 SNMP_OID_TO_BUF
Function block for converting an OID from string into an array of byte.
21 SNMP_TOID_GET
Function block for converting an TOID from array of byte into a string.
22 SNMP_TOID_SET
Function block for converting an TOID from string into an array of byte.
23 SNMP_TOID_TO_BUF
Function block for converting an TOID from string into an array of byte.
24 SNMP_UDINT_TO_BUF
Function block for converting a unsigned double integer value into array of byte in special snmp format.
25 Startup example
For the startup instruction of the SNMP function blocks please find the following example:
SNMP_*_EXA.pcwex
For starting ExampleMachine function block, the requested example can be selected at iExample input and xStart
input has set to TRUE.
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;
udtExample.iExample := 32000;
END_IF;
END_CASE;
END_IF;
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;
26 Appendix
26.1 Diag codes of used firmware function blocks
26.1.1 TCP_SOCKET
ERROR = FALSE
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
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
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: