How do you interpret hrPrinterDetectedErrorState (http://cric.grenoble.cnrs.fr/Administrateurs/Outils/MIBS/?oid=1.3.6.1.2.1.25.3.5.1.2) or something like it using Sharp Snmp lib? Is there some kind of bit string type? It's kind of a bitmask, but you may only receive one byte instead of two (or I've seen four bytes).
Asked
Active
Viewed 465 times
1
-
Impossible. To interpret BITS the MIB documents are mandatory and only #SNMP Pro has that kind of support. – Lex Li Mar 02 '18 at 16:28
-
Thanks for the reply. Is there some generic #snmp method that converts a multiple byte octetstring into bits (or an integer)? – js2010 Mar 02 '18 at 16:42
-
`OctetString.GetRaw`. – Lex Li Mar 02 '18 at 17:09
-
GetRaw() returns a byte array. I was thinking of a single integer. – js2010 Mar 02 '18 at 17:20
-
bytes are even easier for bit operations. – Lex Li Mar 02 '18 at 17:21
-
In the case of hrPrinterDetectedErrorState, I would have to have 2 [flags] enum's instead of one, because there are 15 bits to test. – js2010 Mar 02 '18 at 17:28
1 Answers
0
Did it on my own in powershell.
[flags()] Enum hrPrinterDetectedErrorState
{
lowPaper = 0x8000
noPaper = 0x4000
lowToner = 0x2000
noToner = 0x1000
doorOpen = 0x0800
jammed = 0x0400
Offline = 0x0200
serviceRequested = 0x0100
inputTrayMissing = 0x0080
outputTrayMissing = 0x0040
markerSupplyMissing = 0x0020
outputNearFull = 0x0010
outputFull = 0x0008
inputTrayEmpty = 0x0004
overduePreventMaint = 0x0002
notUsed = 0x0001
}
function snmpmessage($data) {
$bytes = [byte[]][char[]]$data
# pack up to two bytes into an int left to right
$code = [int]$bytes[0]
$code = $code -shl 8
if ($bytes[1]) { $code = $code + $bytes[1] }
[hrPrinterDetectedErrorState]$code
}
PS C:\> snmpmessage -join [char[]](0x91,0x04)
inputTrayEmpty, serviceRequested, noToner, lowPaper

js2010
- 23,033
- 6
- 64
- 66