[英](SNMP) How to set Object's value?
I'm using delphi xe3 to write a program which can read object's value but don't know how to change it? 我正在使用delphi xe3编写一个程序,该程序可以读取对象的值,但不知道如何更改它?
Click SAVE button to set new Power Level value 单击“保存”按钮以设置新的功率电平值
Symbol Rate is read only 符号率是只读的
QuickSend()
is only for retrieving values. QuickSend()
仅用于检索值。 There is no equivalent QuickSend()
for setting values. 没有等效的
QuickSend()
来设置值。 You will have to use SendQuery()
directly for that, eg: 您将必须直接使用
SendQuery()
,例如:
procedure TForm1.BtnEnterClick(Sender: TObject);
var
SNMP: TIdSNMP;
dn, PLevel, SRate: string;
p: Extended;
begin
SNMP := TIdSNMP.Create(nil);
try
SNMP.Host := Trim(HostIP.Text);
SNMP.Community := Trim(ComString.Text);
if SNMP.Host = '' then begin
MessageDlg('Chưa nhập IP của thiết bị!', mtError, [mbOK], 0);
Exit;
end;
if SNMP.Community = '' then begin
MessageDlg('Chưa nhập SNMP read community string', mtError, [mbOK], 0);
Exit;
end;
PowerLevelValue.Clear;
SymbolRateValue.Clear;
SNMP.ReceiveTimeout := 1000;
if SNMP.QuickSend('1.3.6.1.2.1.1.1.0', SNMP.Community, SNMP.Host, dn) then
DeviceName.Caption := dn;
if SNMP.QuickSend('1.3.6.1.4.1.6247.24.1.2.2.10.0', SNMP.Community, SNMP.Host, PLevel) then
begin
p := Abs(StrToFloat(Plevel))/10;
Plevel := FloatToStr(p);
PowerLevelValue.Text := Plevel;
end;
if SNMP.QuickSend('1.3.6.1.4.1.6247.24.1.2.2.12.0', SNMP.Community, SNMP.Host, SRate) then
SymbolRateValue.Text := SRate;
finally
SNMP.Free;
end;
end;
procedure TForm1.BtnSaveClick(Sender: TObject);
var
SNMP: TIdSNMP;
PLevel: string;
p: Extended;
begin
Plevel := PowerLevelValue.Text;
p := StrToFloat(Plevel);
PLevel := FloatToStr(Abs(p*10));
SNMP := TIdSNMP.Create(nil);
try
SNMP.Host := Trim(HostIP.Text);
SNMP.Community := Trim(ComString.Text);
if SNMP.Host = '' then begin
MessageDlg('Chưa nhập IP của thiết bị!', mtError, [mbOK], 0);
Exit;
end;
if SNMP.Community = '' then begin
MessageDlg('Chưa nhập SNMP read community string', mtError, [mbOK], 0);
Exit;
end;
SNMP.ReceiveTimeout := 1000;
SNMP.Query.Clear;
SNMP.Query.PDUType := PDUSetRequest;
SNMP.Query.MIBAdd('1.3.6.1.2.1.1.1.0', DeviceName.Caption);
SNMP.Query.MIBAdd('1.3.6.1.4.1.6247.24.1.2.2.10.0', PLevel);
SNMP.Query.MIBAdd('1.3.6.1.4.1.6247.24.1.2.2.12.0', SymbolRateValue.Text);
SNMP.SendQuery;
finally
SNMP.Free;
end;
end;
As you can see, SendQuery()
supports multiple OIDs, so you could replace QuickSend()
with SendQuery()
so you are only sending 1 query instead of 3 queries: 正如你所看到的,
SendQuery()
支持多个OID,所以你可以替换QuickSend()
与SendQuery()
所以你只发送1个查询,而不是3个查询:
procedure TForm1.BtnEnterClick(Sender: TObject);
var
SNMP: TIdSNMP;
PLevel: string;
p: Extended;
begin
SNMP := TIdSNMP.Create(nil);
try
SNMP.Host := Trim(HostIP.Text);
SNMP.Community := Trim(ComString.Text);
if SNMP.Host = '' then begin
MessageDlg('Chưa nhập IP của thiết bị!', mtError, [mbOK], 0);
Exit;
end;
if SNMP.Community = '' then begin
MessageDlg('Chưa nhập SNMP read community string', mtError, [mbOK], 0);
Exit;
end;
PowerLevelValue.Clear;
SymbolRateValue.Clear;
SNMP.ReceiveTimeout := 1000;
SNMP.Query.Clear;
SNMP.Query.PDUType := PDUGetRequest;
SNMP.Query.MIBAdd('1.3.6.1.2.1.1.1.0', '');
SNMP.Query.MIBAdd('1.3.6.1.4.1.6247.24.1.2.2.10.0', '');
SNMP.Query.MIBAdd('1.3.6.1.4.1.6247.24.1.2.2.12.0', '');
if SNMP.SendQuery then
begin
DeviceName.Caption := SNMP.Reply.MIBGet('1.3.6.1.2.1.1.1.0');
PLevel := SNMP.Reply.MIBGet('1.3.6.1.4.1.6247.24.1.2.2.10.0');
p := Abs(StrToFloat(Plevel))/10;
Plevel := FloatToStr(p);
PowerLevelValue.Text := Plevel;
SymbolRateValue.Text := SNMP.Reply.MIBGet('1.3.6.1.4.1.6247.24.1.2.2.12.0');
end;
finally
SNMP.Free;
end;
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.