Mam listę ip drukarek i chce zrobić program wyświetlający nazwę drukarki oraz stan tonerów. Czego użyć do połączenia z drukarka?
0
0
Witam,
Na szybko znalazłem coś takiego: http://www.papercut.com/products/ng/manual/applicationserver/topics/printer-toner-levels.html
Pozdrawiam,
mr-owl
0
Wybaczcie, ale kompletnie nie mogę tego ogarnąć. Gubię się nawet w dokumentacji. Próbuję zrobić coś z tym, jednak nie wiem czy dobrze. Korzystam z http://www.docs.snmpsharpnet.com/docs-0-9-1/
oto mój kod (metodą SetHostName chcę na razie pobrać jakiekolwiek informacje z drukarki)
namespace Program_Drukarki
{
public class cPrinterInfo : INotifyPropertyChanged
{
public cPrinterInfo(string IP)
{
Timer.Elapsed += CheckingTimerElapsed;
CheckingEnabled = true;
IPAddress = IP;
CheckingEnabled = true;
ConnectionStatus = eConnectionStatus.InProgress;
}
#region INotifypropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
var handler = this.PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
#region CheckingEnabled
private bool checkingEnabled;
public bool CheckingEnabled
{
get
{
return checkingEnabled;
}
set
{
checkingEnabled = value;
OnPropertyChanged("CheckingEnabled");
if (checkingEnabled == true)
Timer.Start();
else
Timer.Stop();
}
}
#endregion
#region Checking Connection Timer and Action
public enum eConnectionStatus
{
InProgress,
Enable,
Disable
}
private eConnectionStatus connectionStatus;
public eConnectionStatus ConnectionStatus
{
get
{
return connectionStatus;
}
private set
{
connectionStatus = value;
OnPropertyChanged("ConnectionStatus");
}
}
private Timer Timer = new Timer(5000);
private async void CheckingTimerElapsed(object sender, ElapsedEventArgs e)
{
await Task.Run(() => CheckPrintStatus());
}
private async void CheckPrintStatus()
{
Ping Ping = new Ping();
PingReply Reply = Ping.Send(System.Net.IPAddress.Parse(IPAddress));
if (Reply.Status.ToString().Equals("Success"))
ConnectionStatus = eConnectionStatus.Enable;
else
ConnectionStatus = eConnectionStatus.Disable;
SetHostName();
}
#endregion
#region Print's Information - IP
private string iPAddress;
public string IPAddress
{
get
{
return iPAddress;
}
set
{
iPAddress = value;
OnPropertyChanged("IPAddress");
ConnectionStatus = eConnectionStatus.InProgress;
IpAddressChanged(iPAddress);
}
}
private async void IpAddressChanged(string IP)
{
ConnectionStatus = eConnectionStatus.InProgress;
await Task.Run(() => CheckPrintStatus());
}
#endregion
#region Print's Information - MAC and HOSTNAME
private string hostName;
public string HostName
{
get
{
return hostName;
}
set
{
hostName = value;
OnPropertyChanged("HostName");
}
}
private void SetHostName()
{
if(ConnectionStatus == eConnectionStatus.Enable)
{
String snmpAgent = IPAddress;
String snmpCommunity = "public";
SimpleSnmp snmp = new SimpleSnmp(snmpAgent, snmpCommunity);
Dictionary<SnmpSharpNet.Oid, AsnType> result = snmp.Get(SnmpVersion.Ver1, new string[] { "1.3.6.1.2.1.1.1.0" });
if (result == null)
{
HostName = "Błąd";
}
else
{
HostName = "";
foreach (KeyValuePair<Oid, AsnType> entry in result)
{
HostName += entry.Key.ToString() + " = " + SnmpConstants.GetTypeName(entry.Value.Type) + ": " + entry.Value.ToString() + ", ";
}
}
}
else
{
HostName = "Niedostępne";
}
}
#endregion
Prawdę mówiąc chcę odskoczyć od dna i odczytać cokolwiek z drukarki. Nie wiem, czy dobrze mam nawet zrobiony kod, bo nie mam na stanie żadnej drukarki sieciowej. Możecie powiedzieć czy idę w dobrym kierunku?