|Author||Forum: PowerSNMP for .NET|
Topic: How do I set a Hex-String
Member Since: 03/25/15
|posted March 25, 2015 5:28 PM
I am using managed C++ to call the .Net library. I have an integer that I want to write to the MIB as a Hex-String.
I tried writing it as an Octet string and when I do an SNMP walk I get:
.22.214.171.124.126.96.36.199.5.1.2 = STRING: "00"
What I want is:
.188.8.131.52.184.108.40.206.5.1.2 = Hex-STRING: 00
This is the code I'm using to write the value:
array<Byte>^ dataValue = gcnew array<Byte>(value.size());
System::Runtime::InteropServices::Marshal::Copy(ptrValue, dataValue, 0, value.size());
m_agent->Variables->Add(gcnew Variable(gcnew System::String(oid.c_str()), gcnew SimpleType::OctetString(dataValue)));
How do I accomplish this?
|Nick B (Admin)
From: Utica, NY USA
Member Since: 05/25/10
Extra Support Options
Custom Application Development
|posted March 26, 2015 12:00 PM
'Hex-STRING' is not a type that is communicated via SNMP; the value will be sent as an OCTET STRING type, and then the MIB can inform the application how it should be displayed, such as as a hex value string.
What are you using to query the value? If you're using our component: as it's an OctetString, by default it is displayed as a straight string representation of the bytes received in the response. However, if Manager.MibNodes contains a definition for the OID and a DisplayHint is present, Variable.FormatValue will use the DisplayHint and render it likely as you expect (this method was added in the current version, 4.8. If you are using 4.7 or below, OctetString.ToString(DisplayHint) must be used).
In order to populate the Variable on the Agent, use the hex character literal in your string to populate the OctetString(string) constructor with a string containing hex values, or populate the OctetString(byte) constructor with the bytes representing the hex values. OctetString.Value exposes the byte array value it was populated with, and you can convert that to the desired display format as needed if you do not have a MIB defining a display hint.
Member Since: 03/25/15
|posted March 26, 2015 2:35 PM
Thanks, I understand what I need to do.
|Reply | PowerSNMP for .NET Topics | Forums|
|This site is powered by PowerTCP WebServer for ActiveX|