如何使用sharp snmp lib(hrPrinterDetectedErrorState)解释位串?

时间:2018-03-01 22:44:25

标签: sharp-snmp

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

1 个答案:

答案 0 :(得分: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