FB_SEND_TRAP

The function block allows to send SNMPv1 Traps. You can add variable bindings for sending additional information to the manager along with the trap. The following SNMP Data Types are supported by the function block for the variable bindings: OCTET_STRING, INTEGER32, COUNTER32, GAUGE32, TIMETICKS, OBJECT_ID

The uptime field is always zero.

The maximum paket size is limited to 2000 byte. If more bytes are committed the function block will return a error.

The function block FB_SEND_TRAP should be called in each cycle for a proper operation.

VAR_INPUT
    bEnable               :BOOL;
    bExecute              :BOOL;
    sLocalHostIp          :STRING(15);
    sLocalHostPort        :UDINT;
    sManagerIP            :STRING(15);
    sTcIpConnSvrAddr      :T_AmsNetId;
    sObjectID             :T_MAXSTRING;
    sCommunity            :STRING(60);
    iGenericTrapNumber    :INT;
    bySpecificTrapNumber  :BYTE;
    nVarBindings          :USINT;
    pArrVarBinding        :POINTER TO ARRAY[1..iMAX_TRAPBUF_SIZE] OF ST_SNMP_VariableBinding;
             
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.

bExecute: Send one Trap with a rising edge on bExecute. A rising edge will clear the output nErrID and bError. A opened Socket is required.

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 is 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.

bySpecificTrapNumber: 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)

VAR_OUTPUT
    bBusy         :BOOL;
    bEnabled      :BOOL;
    bError        :BOOL;
    nErrID        :DINT;
END_VAR

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

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

bError: Becomes TRUE as soon as an error has occurred

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 the following software:

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 )