petrkohut / SNMP-printer-library

PHP library for getting printer's data in a network through the SNMP protocol
33 stars 5 forks source link

Wrong Type and missing information #5

Open cb1ttencourt opened 6 years ago

cb1ttencourt commented 6 years ago

Hello, the entire code work nice on B&W printers, but with my Brother NC-6900h printer (CMYK Printer) the code returns that is a 'mono printer' and even if i force the code i get no information about toners. Can someone help ?

a-a commented 6 years ago

Try an snmpwalk - check what order your toners are reported in.

~$ snmpwalk -Cc -v 1 -c public 192.168.0.38 1.3.6.1.2.1.43.11.1.1.6
iso.3.6.1.2.1.43.11.1.1.6.1.1 = STRING: "Black Cartridge HP CF410A"
iso.3.6.1.2.1.43.11.1.1.6.1.2 = STRING: "Cyan Cartridge HP CF411A"
iso.3.6.1.2.1.43.11.1.1.6.1.3 = STRING: "Magenta Cartridge HP CF413X"
iso.3.6.1.2.1.43.11.1.1.6.1.4 = STRING: "Yellow Cartridge HP CF412A"

The library assumes a printer is mono if the black toner is in the first slot. Given toners could be in any slot dependant on what the manufacturer decides to do, it's likely this is a a bug.

A workaround would be to work through the number of objects returned and assume a mono printer if only one is returned, otherwise it's highly likely to be a colour printer.

JeroenSteen commented 2 years ago

I downloaded the snmpwalk binaries from nxmehta's mediafire link on Serverfault: https://serverfault.com/questions/283922/how-do-i-install-net-snmp-on-windows-without-visual-studio

And i run the snmpwalk that a-a suggested, and got this as result on a Xerox C60 production printer:

C:\Program Files\Net-SNMP\bin>snmpwalk -Cc -v 1 -c public <printer_ip> 1.3.6.1.2.1.43.11.1.1.6
netsnmp_assert s != (-1) failed ..\..\snmplib\transports\snmpUDPBaseDomain.c:494
SNMPv2-SMI::mib-2.43.11.1.1.6.1.2 = STRING: "Yellow Toner [Y];SN.."
SNMPv2-SMI::mib-2.43.11.1.1.6.1.3 = STRING: "Magenta Toner [M];SN.."
SNMPv2-SMI::mib-2.43.11.1.1.6.1.4 = STRING: "Cyan Toner [C];SN.."
SNMPv2-SMI::mib-2.43.11.1.1.6.1.5 = STRING: "Waste Toner Container"
SNMPv2-SMI::mib-2.43.11.1.1.6.1.6 = STRING: "Black Drum Cartridge"
SNMPv2-SMI::mib-2.43.11.1.1.6.1.7 = STRING: "Yellow Drum Cartridge"
SNMPv2-SMI::mib-2.43.11.1.1.6.1.8 = STRING: "Magenta Drum Cartridge"
SNMPv2-SMI::mib-2.43.11.1.1.6.1.9 = STRING: "Cyan Drum Cartridge"
SNMPv2-SMI::mib-2.43.11.1.1.6.1.12 = STRING: "Fuser Assembly"
SNMPv2-SMI::mib-2.43.11.1.1.6.1.30 = STRING: "Black Toner [K1];SN.."
SNMPv2-SMI::mib-2.43.11.1.1.6.1.31 = STRING: "Black Toner **[K2];SN.."**

Can someone give me some hints how to change the code of this printer-library, the full color printer haves two blacks. The two blacks are not in .1, but the code of the library also assumes it's a black mono printer.

a-a commented 2 years ago

Some hints: https://github.com/petrkohut/SNMP-printer-library/blob/b6b6d1fd99d474469756efbe39d9bd04b7260c57/library/Kohut/SNMP/Printer.php#L83

But see everywhere else in the library, the trouble is it's making assumptions that Cyan is always in the first subunit, and this assumption is repeated throughout the code. This means it works for only the printers who return the same order of toners in SNMP as the library was hardcoded for from what i can tell, so if you are unlucky enough to have a printer that returns anything else than cyan for first subunit, the library blindly assumes it's a mono printer.

Edit: OIDs are hardcoded above Line 83 too 🙃