0

您如何使用 Sharp Snmp lib 解释 hrPrinterDetectedErrorState ( http://cric.grenoble.cnrs.fr/Administrateurs/Outils/MIBS/?oid=1.3.6.1.2.1.25.3.5.1.2 ) 或类似的东西?有某种位串类型吗?这是一种位掩码,但您可能只收到一个字节而不是两个(或者我已经看到了四个字节)。

4

1 回答 1

0

我自己在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
于 2019-03-28T21:31:04.543 回答