FB_GetSnmp

The Function Block allows to receive SNMPv1 GET-commands. You can add variable bindings for sending additional information to the SNMP. The following SNMP Data Types are supported by the function block for the variable bindings: OCTET_STRING, INTEGER32, COUNTER32, GAUGE32, TIMETICKS, OBJECT_ID

VAR_INPUT
    bEnable               :BOOL;
    bReceive              :BOOL;
    bSendTrap             :BOOL;
    bSendResponse         :BOOL;
    sLocalHostIp          :STRING(15);
    nLocalHostPort        :UDINT;
    sManagerIP            :STRING(15);
    sTcIpConnSvrAddr      :T_AmsNetId :='';
    sObjectID             :T_MAXSTRING;
    sCommunity            :STRING(60);
    iGenericTrapNumber    :INT;
    iSpecificTrapNumber   :BYTE;
    nVarBindings          :USINT := 0;
    pArrVarBinding        :POINTER TO ARRAY[1..iMAX_TRAPBUF_SIZE] OF ST_SNMP_VariableBinding;
    iError                :INT;
END_VAR

bEnable: With a rising edge on this input the system attempts to create a Socket. Once established the Output bEnabled is set to TRUE. The Socket can be closed again with a falling edge.

bReceive: Signal a received GET command.

bSendTrap: Signal a sended TRAP.

bSendResponse: Signal an answer is ready to send.

sLocalHostIP: String containing the (IPv4) dotted network address of the local host (e.g. '172.33.5.1'). If there is more than one network adapter present on the machine, the sLocalHostIP parameter allows you to specify which adapter to use.

sLocalHostPort(optional): The local IP port number.

sManagerIP: IP address (IPv4) of the SNMP Manager.

sTcIpConnSvrAddr: not supported

sObjectID: String containing the dotted numerical value that represents the MIB (Management Information Base) of the device. Maximum length of the string is 255. Valid values for each number between the dots are 0...65535. (e.g., '1.3.1.3.2555.3')

sCommunity: String containing the SNMP Community String (e.g. public)

iGenericTrapNumber: The SNMP Generic Trap Number defined in E_SNMP_GenericTrapNumber.

iSpecificTrapNumber: The SNMP Specific Trap Number. Automatically set to 0 if iGenericTrapNumber is not 0x06(E_SNMP_EnterpriseSpecific). Valid values are 1...255.

pArrVarBinding (optional): Pointer to an array of SNMP_ST_VariableBinding.

nVarBindings (optional): Number of the elements in pArrVarBinding. Maximum is iMAX_TRAPBUF_SIZE (defined in Global_Variables)

iError:  Returns specific SNMP error code.

VAR_OUTPUT
    bBusy               :BOOL;
    bError              :BOOL;
    bEnabled            :BOOL;
    bReceived           :BoOL;
    iRecSNMPVersion     :INT; (* SNMP Version, sample SNMPv1 = 0 *)
    sRecCommunity       :STRING(60); (*Community Name *)
    iRecPDUType         :INT;(* SNMP PDU Type, sample GET = A0 *)
    arrRecPDURequestID  :ARRAY[0..3] OF BYTE; (* SNMP PDU Request ID *)
    iRecPDUError        :INT; (*SNMP PDU Error *)
    iRecPDUErrorIndex   :INT; (* SNMP PDU Error Index*)
    sRecObjectID        :T_MAXSTRING; (* Object Identifier *)
    arrRecObjectID      :ARRAY[0..128] OF UDINT;
    nErrID              :UDINT;
END_VAR

bBusy: When the function block is activated this output is set while sending.

bError: Becomes TRUE as soon as an error has occurred

bEnabled: This output is set if a Socket is open.

bReceived: This oputput is set if a get command has occured..

iRecSNMPVersion: Info about SNMP version. SNMPv1 = 0.

sRecCommunity: Info about the received community strings.

iRecPDUType: Info about the PDU type.

arrRecPDURequestID: Array with PDU request IDs.

iRecPDUError: Output of the PDU errorID.

iRecPDUErrorIndex: Output of error index.

sRecObjectID: String with the objectID.

arrRecObjectID: Array with the received objectIDs .

nErrID: If the bError output is set, this parameter returns a TwinCAT TCP/IP Connection Server error or E_SNMP_ErrorCodes.

The function block is tested with:

SNMP Trap Watcher  (BTT Software)

Wireshark 1.2.5

iReasoning MIB Browser Personal Edition 7.0

Requirements

Development environment

Target system type

PLC libraries to be linked

TwinCAT version 2.8.0 or higher

PC or CX (x86)

TcpIp.Lib ( Standard.Lib; TcBase.Lib; TcSystem.Lib are included automatically )