How to Use SnmpManager to Manage Devices/Clients in a Network
SNMP agent running on a device/client supporting protocol version v1 or v2c
oMIB structure with its OID (Object IDentifier).
oPort and IP address of the device/client on which the SNMP agent is running.
oThe different community names configured in the SNMP agent for reading and writing.
How to Set a New Value in an OID (Example)
Declaration:
PROGRAM SetRequest
VAR
sNewSysName : STRING[60];
fbSnmpManager : SE_SNMP.FB_SnmpManager;
stRequestInfo : SE_SNMP.ST_RequestInformation;
etRequest : SE_SNMP.ET_SnmpRequest;
etProtocolVersion : SE_SNMP.ET_SnmpProtocolVersion;
xError : BOOL;
xDone : BOOL;
xBusy : BOOL;
xActive : BOOL;
xReady : BOOL;
etResult : SE_SNMP.ET_Result;
sResultMsg : STRING(255);
END_VAR
Implementation:
sNewSysName := 'SchneiderSystem';
stRequestInfo.i_stRequest.pbyValueBuffer := ADR(sNewSysName);
stRequestInfo.i_stRequest.dwNumBytesValue := 60;
stRequestInfo.i_stRequest.sAgentIp := '10.128.154.41';
stRequestInfo.i_stRequest.sOid := '1.3.6.1.2.1.1.5.0'; //SysName
stRequestInfo.i_stRequest.uiAgentSnmpPort := 161;
stRequestInfo.i_stRequest.etValueType := SE_SNMP.ET_SnmpTag.OctetString;
etRequest := SE_SNMP.ET_SnmpRequest.SetRequest;
etProtocolVersion := SE_SNMP.ET_SnmpProtocolVersion.Version2c
fbSnmpManager( i_xEnable := TRUE,
i_xExecute := TRUE,
i_etRequest := etRequest,
i_etVersion := etProtocolVersion
iq_stRequestInfo := stRequestInfo,
q_xActive => xActive,
q_xReady => xReady,
q_xBusy => xBusy,
q_xDone => xDone,
q_xError => xError,
q_etResult => etResult,
q_sResultMsg => sResultMsg
)
Description of the parameters used:
|
Step |
Action |
|---|---|
|
1 |
In the stRequestInfo.i_stRequest, set the IP address (sAgentIp) of your device where the SNMP agent is running, for example, 10.128.154.47. |
|
2 |
In the stRequestInfo.i_stRequest, set the port (uiAgentSnmpPort) of the SNMP agent. Standard port of SNMP and default port of the library are 161. |
|
3 |
In the stRequestInfo.i_stRequest, set the OID (sOid) of the value to modify, for example, 1.3.6.1.2.1.1.5.0 (SysName). |
|
4 |
In the stRequestInfo.i_stRequest, set the pointer (pbyValueBuffer) which points to the value to set in the OID (in case of a GetRequest: set the pointer to the buffer where the received value is stored). |
|
5 |
In the stRequestInfo.i_stRequest, set the value type (etValueType), for example, OctetString (in case of a GetRequest: this parameter is not used). |
|
6 |
In the stRequestInfo.i_stRequest, set the size of your value (dwNumBytesValue), for example, 60 (in case of a GetRequest: set the size of your value buffer). NOTE: For string types add an additional byte for the end of string character. |
|
7 |
In the ET_SnmpProtocolVersion, set the type of the SNMP protocol version. The default version of the library is set to Version2c. |
|
8 |
In the ET_SnmpRequest, set the type of request, for example, SetRequest. |
|
9 |
Call the FB_SnmpManager with the settings/parameters/variables above. |