锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲一区二区三区首页,国产精品亚洲一区二区在线观看,亚洲视频国产视频http://m.tkk7.com/Vincent-chenxj/zh-cnMon, 12 May 2025 16:38:18 GMTMon, 12 May 2025 16:38:18 GMT60C# Sample code to talk to a printer using SNMP to get its status. http://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283093.htmlVincent-chenVincent-chenThu, 18 Jun 2009 09:24:00 GMThttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283093.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/283093.htmlhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283093.html#Feedback2http://m.tkk7.com/Vincent-chenxj/comments/commentRss/283093.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/283093.html
The following code will allow you to talk to a printer (running on a specific IP Address) to query its current status.
OLEPRNLib is a COM object that appears to be installed on XP and greater machines.
On my machine I made a reference on the COM tab of the Add Reference dialog to “oleprn 1.0 Type Library“ which lived in “c:\Windows\System32\oleprn.dll“
using System;
using OLEPRNLib;
namespace PrinterStatus
{/// /// Summary description for Class1.
///
class Class1
{/// /// The main entry point for the application.
///
[STAThread]staticvoid Main(string[] args){
string[] ErrorMessageText = new string[8];
ErrorMessageText[0] = "service requested";
ErrorMessageText[1] = "offline";
ErrorMessageText[2] = "paper jammed";
ErrorMessageText[3] = "door open";
ErrorMessageText[4] = "no toner";
ErrorMessageText[5] = "toner low";
ErrorMessageText[6] = "out of paper";
ErrorMessageText[7] = "low paper";int DeviceID = 1;int Retries = 1;int TimeoutInMS = 2000;
string CommunityString = "public";
string IPAddressOfPrinter = "10.3.0.93";// Create instance of COM object
OLEPRNLib.SNMP snmp = new OLEPRNLib.SNMP();// Open the SNMP connect to the printer
snmp.Open(IPAddressOfPrinter, CommunityString, Retries, TimeoutInMS);// The actual Warning/Error bits
uint WarningErrorBits = snmp.GetAsByte(String.Format("25.3.5.1.2.{0}", DeviceID));// The actual Status
uint StatusResult = snmp.GetAsByte(String.Format("25.3.2.1.5.{0}", DeviceID));// uint Result2 = snmp.GetAsByte(String.Format("25.3.5.1.1.{0}", DeviceID));
string Result1Str = "";switch(StatusResult){case 2 : Result1Str = "OK";break;case 3 : Result1Str = "Warning: ";break;case 4 : Result1Str = "Being Tested: ";break;case 5 : Result1Str = "Unavailable for any use: ";break;default : Result1Str = "Unknown Status Code : "+StatusResult;break;}
string Str = "";if((StatusResult == 3 || StatusResult == 5)){int Mask = 1;int NumMsg = 0;for(int i=0; i< 8; i++){if((WarningErrorBits & Mask) == Mask){if(Str.Length > 0)
Str += ", ";
Str += ErrorMessageText[i];
NumMsg = NumMsg + 1;}
Mask = Mask * 2;}}
Console.WriteLine(Result1Str + Str);}}}
posted on Monday, August 08, 2005 8:13 PM | Filed Under [ c# ]
Comments
#re: C# Sample code to talk to a printer using SNMP to get its status.
Hello.
I have been talked to a print by this code.
But I couldn't talk to Zebra Barcode Printer ( 140 Xi III Plus Model ).
I catched Ready Status and Out of Paper Error, but another status, for example, Printing(Running) and OffLine(Pause) status.
#re: C# Sample code to talk to a printer using SNMP to get its status.
Can you explain me what do "25.3.5.1.2.{0}" mean and what do "25.3.5.1.5.{0}"
is there any other code like this. if so can me provide the link so that i can know more about SNMP and try to handle/get status information the devices from remote location
Bits are numbered starting with the most significant bit of the first byte being bit 0, the least significant bit of the first byte being bit 7, the
most significant bit of the second byte being bit 8, and so on. A one bit encodes that the condition was detected, while a zero bit encodes that the condition was not detected.
This object is useful for alerting an operator to specific warning or error conditions that may occur, especially those requiring human intervention.
The best way to see what is around is to look at a MIB Browser
http://www.ireasoning.com/mibbrowser.shtml
If you download the tool above there is a free version and you would then load the Printer-MIB.MIB to get information like above.
#re: C# Sample code to talk to a printer using SNMP to get its status.
My SNMP program is the simple program and write in the C# language. But I faced the problem that I need to type the IP address for my slave before I can get the MIB of my slave, how I can detect my slave's IP address directly without type the IP address? Can you give me some guidelines? Furthermore, I need some coding that write in C# that can show the status for my slaves, such as my slave is on or off. I hope that you can give me some guidelines. Thanks.
#re: C# Sample code to talk to a printer using SNMP to get its status.
nice peace of code, thanks for sharing. unfortunately oleprn.dll isn't documented anywhere...but nevertheless i think i can use it for simple snmp queries.
seems to me as if you forgot to
snmp.close();
after querying.
#re: C# Sample code to talk to a printer using SNMP to get its status.
hi ,
I need to know whether the printer(dymo label printer) status active or not which was installed on the network (192.168.1.18\dymolabel shared) from the other machine.
the above example doesent work for me as i cant get the OID for the dymo label printer.
Can any one help me how to do the above requirement please
#re: java Sample code to talk to a printer using SNMP to get its status.
i am going to develop simulator printer,so i need to develop printer mibs for virtual printer to operate them by snmp operation like set,get and trap by specifying oids.
#re: C# Sample code to talk to a printer using SNMP to get its status.
hello everyone,
can anybody guide me to write the code in C# to access the of various node status in LAN using SNMP protocol.If any one is interested please mail me.
#re: C# Sample code to talk to a printer using SNMP to get its status.
hai thnks for giving this code to get status . I need more information about Printer like
1. whether Printer is Printing or not,
2. whether it is on Or off,
3.how many copies printed.
CPU
percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0
raw user cpu time: .1.3.6.1.4.1.2021.11.50.0
percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0
raw system cpu time: .1.3.6.1.4.1.2021.11.52.0
percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0
raw idle cpu time: .1.3.6.1.4.1.2021.11.53.0
raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0
Memory Statistics
Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0
Total RAM used: .1.3.6.1.4.1.2021.4.6.0
Total RAM Free: .1.3.6.1.4.1.2021.4.11.0
Total RAM Shared: .1.3.6.1.4.1.2021.4.13.0
Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0
Total Cached Memory: .1.3.6.1.4.1.2021.4.15.0
Disk Statistics
The snmpd.conf needs to be edited. Add the following (assuming a machine with a single / partition):
disk / 100000 (or)
includeAllDisks 10% for all partitions and disks
The OIDs are as follows
Path where the disk is mounted: .1.3.6.1.4.1.2021.9.1.2.1
Path of the device for the partition: .1.3.6.1.4.1.2021.9.1.3.1
Total size of the disk/partion (kBytes): .1.3.6.1.4.1.2021.9.1.6.1
Available space on the disk: .1.3.6.1.4.1.2021.9.1.7.1
Used space on the disk: .1.3.6.1.4.1.2021.9.1.8.1
Percentage of space used on disk: .1.3.6.1.4.1.2021.9.1.9.1
Percentage of inodes used on disk: .1.3.6.1.4.1.2021.9.1.10.1
CPU
percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0
raw user cpu time: .1.3.6.1.4.1.2021.11.50.0
percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0
raw system cpu time: .1.3.6.1.4.1.2021.11.52.0
percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0
raw idle cpu time: .1.3.6.1.4.1.2021.11.53.0
raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0
Memory Statistics
Total Swap Size: .1.3.6.1.4.1.2021.4.3.0
Available Swap Space: .1.3.6.1.4.1.2021.4.4.0
Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0
Total RAM used: .1.3.6.1.4.1.2021.4.6.0
Total RAM Free: .1.3.6.1.4.1.2021.4.11.0
Total RAM Shared: .1.3.6.1.4.1.2021.4.13.0
Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0
Total Cached Memory: .1.3.6.1.4.1.2021.4.15.0
Disk Statistics
The snmpd.conf needs to be edited. Add the following (assuming a machine with a single / partition):
disk / 100000 (or)
includeAllDisks 10% for all partitions and disks
The OIDs are as follows
Path where the disk is mounted: .1.3.6.1.4.1.2021.9.1.2.1
Path of the device for the partition: .1.3.6.1.4.1.2021.9.1.3.1
Total size of the disk/partion (kBytes): .1.3.6.1.4.1.2021.9.1.6.1
Available space on the disk: .1.3.6.1.4.1.2021.9.1.7.1
Used space on the disk: .1.3.6.1.4.1.2021.9.1.8.1
Percentage of space used on disk: .1.3.6.1.4.1.2021.9.1.9.1
Percentage of inodes used on disk: .1.3.6.1.4.1.2021.9.1.10.1
Communicating with SNMP using C# - The Very Beginning http://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283059.htmlVincent-chenVincent-chenThu, 18 Jun 2009 07:30:00 GMThttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283059.htmlhttp://m.tkk7.com/Vincent-chenxj/comments/283059.htmlhttp://m.tkk7.com/Vincent-chenxj/archive/2009/06/18/283059.html#Feedback1http://m.tkk7.com/Vincent-chenxj/comments/commentRss/283059.htmlhttp://m.tkk7.com/Vincent-chenxj/services/trackbacks/283059.html
Who Should Read This
You want to program SNMP with C# but have no idea for beginning.
You've googled for a while, but don't get a simple working example.
What you're looking for, is just a simple requirement to get a status value from a device through SNMP.
Introduction
My purpose is to get an uint value from a temperature sensor through SNMP. This is a very simple requirement, and I don't want to understand the whole detail of SNMP protocol. In JAVA, there's lot of open source resources for SNMPprogramming, for example, SNMP4j. How ever, I found no simple guidance for C# SNMP programming. If you have the same problem, you can have following example to start your way toward SNMP.
Pre-requirement
C# Programming Basics
A working SNMPhost to communicate with. For example, a temperature sensor, a networked printer or a router with SNMPfunctions.
Sample SNMP Class Firstly, you have to add a reference to OLEPRNLIB. You can find it from "Add reference" -> "COM". The path of the dll is located at C:\Windows\System32 by Default.
Here is a sample SNMP Class:
using System;
using System.Collections.Generic;
using System.Text;
using OLEPRNLib;
namespace MrFu
{
public class SimpleSnmp
{
private String hostIp;
private String oid;
private String communityString;
where the "hostIp" is the IP address of the target, of course,
the "communityString" is "public" by default for most SNMP device. If you changed it on device configuration, remember to modify it.
the "retries" and "timeout" indicate how many times the system should retry if connection failed over the milliseconds given by "timeout".
And, That's All to Connect to A Device Through SNMP. COOL!
Second line you might want to know is:
uint result = snmp.GetAsByte(this.oid);
That's the basic way to get the status or value from your host device. You can convert it into String or any thing you like.
To explain in a simple way, the "oid" is the unique id for some status on the device. You can obtain the correct oid from your device manual. For example, the oid of my temperature sensor is:
".1.3.6.1.4.1.3854.1.2.2.1.16.1.3.0"
So you should be able to find some string looks like that from your device suppliers or documents.
For more detailed description of SNMPprotocol, you can look into wikipedia.
That's all. So easy, and you can have a first shot of SNMPprogramming with C# now.
Conclusin
This is quiet a easy way to have a quick look of SNMPprogamming with C#. Surely, the detailed packet parsing or other SNMPfunctions are NOT shown in this post. But that's all I need to solve my problem. And I hope this post can help you, too.
h:outputText鏈変竴涓?nbsp; escape 灞炴х敤鏉ュ鐞唄tml 鏍囩. 榛樿鍊間負true.榪欐剰鍛崇潃鎵鏈夌壒孌婄殑絎﹀悎閮借杞箟涓?&'浠g爜. 璇風湅涓嬮潰紺轟緥: <h:outputText value="<b>This is a text</b>"/> 鎵撳嵃鐨勭粨鏋滄槸: <b>This is a text</b> 鑰?nbsp;<h:outputText escape="false" value="<b>This is a text</b>"/> 鎵撳嵃鐨勭粨鏋滄槸: This is a text 褰撶敤鎴風偣鍑籆ommand Link鍚庡浣曟樉紺虹‘璁ゅ璇濇?
h:commandLink鎸囧畾浜?nbsp;onclick 灞炴т負鍐呴儴浣跨敤. 鍥犳浣犱笉鍙互浣跨敤濂逛簡, 璇ラ棶棰樺凡緇忓湪JSF1.2涓慨澶嶄簡,瀵逛簬JSF1.2浠ュ墠鐨勭増鏈?浣犲彲浠ュ湪onclick浠ュ墠浣跨敤 onmousedown 浜嬩歡 <script language="javascript"> function ConfirmDelete(link) { var delete = confirm('Do you want to Delete?'); if (delete == true) { link.onclick(); } }</script>