Skookum
Butt Sniffer


Joined: 26 Oct 2001 Posts: 1541
Location: I dunno, I lost my Mommy
|
Posted:
Mon Sep 17, 2007 1:25 pm Post subject: Printer Parallel PJL problem |
|
Using Windows XP and a parallel printer (the one I am playing with now is a HP LaserJet 1100 A) how do I interface with the printer?
What I am trying to do is play with the PJL settings on the printer to adjust the resolutions and possibly check toner info. I am able to do this on networked printers by telneting to the printer on port 9100
Then I can run all the PJL commands that I want.....well until I make a typo then the printer prints all of my commands (stupid interface junk port 9100)
I have tried using HyperTerm to try and connect to a Com port, that failed miserably, and I have been googling for a while now without success. I would rather not write a driver that does this for me. I am looking for something fairly simple.
My end goal is to be able to tell toner levels on local printers. I am able to do this on network printers using SNMP.
Here is my code for that:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForWriting = 8
Const ForReading = 1
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objSHell = WScript.CreateObject("WScript.Shell")
Start = Now
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=Workstation;"
objRecordSet.CursorLocation = adUseClient
ipAccountingLJ4100N = "10.1.10.2"
ipAR = "10.1.10.20"
ipCS = "10.1.10.34"
ipAP = "10.1.10.7"
ipEngineering2 = "10.1.10.8"
ipMaintenance = "10.1.10.17"
ipMaterials = "10.1.10.10"
ipMFG = "10.1.10.11"
ipMODLabel = "10.1.10.14"
ipMFGENG = "10.1.10.13"
ipBW = "10.1.10.33"
ipShippingTable = "10.1.10.3"
ipShippingLJ1100 = "10.1.10.18"
ipEngineeringColor = "10.1.10.31"
arrPrinters = ARRAY(ipAccountingLJ4100N, ipAR, ipCS, ipAP, ipEngineering2, ipMaintenance, ipMaterials, ipMFG, ipMODLabel, ipMFGENG, ipBW)
For Each objPrinter in arrPrinters
if objFSO.FileExists ("C:\Printers\MaxTonerBlk.txt") Then
objFSO.DeleteFile ("C:\Printers\MaxTonerBlk.txt")
End If
if objFSO.FileExists ("C:\Printers\CurrentTonerBlk.txt") Then
objFSO.DeleteFile ("C:\Printers\CurrentTonerBlk.txt")
End If
if objFSO.FileExists ("C:\Printers\MaxTonerCyan.txt") Then
objFSO.DeleteFile ("C:\Printers\MaxTonerCyan.txt")
End If
if objFSO.FileExists ("C:\Printers\CurrentTonerCyan.txt") Then
objFSO.DeleteFile ("C:\Printers\CurrentTonerCyan.txt")
End If
if objFSO.FileExists ("C:\Printers\MaxTonerMag.txt") Then
objFSO.DeleteFile ("C:\Printers\MaxTonerMag.txt")
End If
if objFSO.FileExists ("C:\Printers\CurrentTonerMag.txt") Then
objFSO.DeleteFile ("C:\Printers\CurrentTonerMag.txt")
End If
if objFSO.FileExists ("C:\Printers\MaxTonerYel.txt") Then
objFSO.DeleteFile ("C:\Printers\MaxTonerYel.txt")
End If
if objFSO.FileExists ("C:\Printers\CurrentTonerYel.txt") Then
objFSO.DeleteFile ("C:\Printers\CurrentTonerYel.txt")
End If
set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & objPrinter & "'")
For Each objRetStatus in objPing
If objRetStatus.StatusCode = 0 then
objShell.Run "cmd /c snmpget -v 1 -c public " & objPrinter & " mib-2.43.11.1.1.8.1.1 > C:\Printers\MaxTonerBlk.txt",7,True
Wscript.Sleep 3000
objShell.Run "cmd /c snmpget -v 1 -c public " & objPrinter & " mib-2.43.11.1.1.9.1.1 > C:\Printers\CurrentTonerBlk.txt",7,True
Wscript.Sleep 3000
If objPrinter = "10.1.10.31" Then
objShell.Run "cmd /c snmpget -v 1 -c public " & objPrinter & " mib-2.43.11.1.1.8.1.1 > C:\Printers\MaxTonerCyan.txt",7,True
Wscript.Sleep 3000
objShell.Run "cmd /c snmpget -v 1 -c public " & objPrinter & " mib-2.43.11.1.1.9.1.1 > C:\Printers\CurrentTonerCyan.txt",7,True
Wscript.Sleep 3000
objShell.Run "cmd /c snmpget -v 1 -c public " & objPrinter & " mib-2.43.11.1.1.8.1.1 > C:\Printers\MaxTonerMag.txt",7,True
Wscript.Sleep 3000
objShell.Run "cmd /c snmpget -v 1 -c public " & objPrinter & " mib-2.43.11.1.1.9.1.1 > C:\Printers\CurrentTonerMag.txt",7,True
Wscript.Sleep 3000
objShell.Run "cmd /c snmpget -v 1 -c public " & objPrinter & " mib-2.43.11.1.1.8.1.1 > C:\Printers\MaxTonerYel.txt",7,True
Wscript.Sleep 3000
objShell.Run "cmd /c snmpget -v 1 -c public " & objPrinter & " mib-2.43.11.1.1.9.1.1 > C:\Printers\CurrentTonerYel.txt",7,True
Wscript.Sleep 3000
Set objMaxTonerBlk = objFSO.OpenTextFile("C:\Printers\MaxTonerBlk.txt", ForReading)
DO Until objMaxTonerBlk.AtEndOfStream
strTonerBlk = objMaxTonerBlk.ReadLine
strSNMPLen = len(strToner)
intMaxTonerBlk = LTrim(Mid(strToner, 45, strSNMPLen))
strTonerBlk = empty
strSNMPLen = empty
Loop
Set objCurrentTonerBlk = objFSO.OpenTextFile("C:\Printers\CurrentTonerBlk.txt", ForReading)
DO Until objCurrentTonerBlk.AtEndOfStream
strToner = objCurrentTonerBlk.ReadLine
strSNMPLen = len(strToner)
intCurrentTonerBlk = LTrim(Mid(strToner, 45, strSNMPLen))
strTonerBlk = empty
strSNMPLen = empty
Loop
intPercentLeftBlk = (intCurrentTonerBlk / intMaxTonerBlk) * 100
Set objMaxTonerCyan = objFSO.OpenTextFile("C:\Printers\MaxTonerCyan.txt", ForReading)
DO Until objMaxTonerCyan.AtEndOfStream
strTonerCyan = objMaxTonerCyan.ReadLine
strSNMPLen = len(strToner)
intMaxTonerCyan = LTrim(Mid(strToner, 45, strSNMPLen))
strTonerCyan = empty
strSNMPLen = empty
Loop
Set objCurrentTonerCyan = objFSO.OpenTextFile("C:\Printers\CurrentTonerCyan.txt", ForReading)
DO Until objCurrentTonerCyan.AtEndOfStream
strToner = objCurrentTonerCyan.ReadLine
strSNMPLen = len(strToner)
intCurrentTonerCyan = LTrim(Mid(strToner, 45, strSNMPLen))
strTonerCyan = empty
strSNMPLen = empty
Loop
intPercentLeftCyan = (intCurrentTonerCyan / intMaxTonerCyan) * 100
Set objMaxTonerMag = objFSO.OpenTextFile("C:\Printers\MaxTonerMag.txt", ForReading)
DO Until objMaxTonerMag.AtEndOfStream
strTonerMag = objMaxTonerMag.ReadLine
strSNMPLen = len(strToner)
intMaxTonerMag = LTrim(Mid(strToner, 45, strSNMPLen))
strTonerMag = empty
strSNMPLen = empty
Loop
Set objCurrentTonerMag = objFSO.OpenTextFile("C:\Printers\CurrentTonerMag.txt", ForReading)
DO Until objCurrentTonerMag.AtEndOfStream
strToner = objCurrentTonerMag.ReadLine
strSNMPLen = len(strToner)
intCurrentTonerMag = LTrim(Mid(strToner, 45, strSNMPLen))
strTonerMag = empty
strSNMPLen = empty
Loop
intPercentLeftMag = (intCurrentTonerMag / intMaxTonerMag) * 100
Set objMaxTonerYel = objFSO.OpenTextFile("C:\Printers\MaxTonerYel.txt", ForReading)
DO Until objMaxTonerYel.AtEndOfStream
strTonerYel = objMaxTonerYel.ReadLine
strSNMPLen = len(strToner)
intMaxTonerYel = LTrim(Mid(strToner, 45, strSNMPLen))
strTonerYel = empty
strSNMPLen = empty
Loop
Set objCurrentTonerYel = objFSO.OpenTextFile("C:\Printers\CurrentTonerYel.txt", ForReading)
DO Until objCurrentTonerYel.AtEndOfStream
strToner = objCurrentTonerYel.ReadLine
strSNMPLen = len(strToner)
intCurrentTonerYel = LTrim(Mid(strToner, 45, strSNMPLen))
strTonerYel = empty
strSNMPLen = empty
Loop
intPercentLeftYel = (intCurrentTonerYel / intMaxTonerYel) * 100
If intPercentLeftBlk <= 25 Then
strPrinterQuery = "SELECT PrinterName, Manufacturer, Model, Location, TonerCartridgeBlk FROM printers WHERE IP = '" & objPrinter & "'"
Set objRecordSet = CreateObject("ADODB.Recordset")
objRecordSet.Open strPrinterQuery, objConnection, 3, 3
strPrinterName = objRecordSet("PrinterName")
strManufacturer = objRecordSet("Manufacturer")
strModel = objRecordSet("Model")
strLocation = objRecordSet("Location")
strTonerCartridgeBlk = objRecordSet("TonerCartridgeBlk")
Set objEMail = CreateObject("CDO.Message")
objEMail.From = "PrinterNinja@ninja.com"
objEMail.To = "bob@bob.com"
objEMail.Subject = "Printer: " & RTrim(strPrinterName) & " Toner Level: " & Left(intPercentLeftBlk, 4) & "%"
objEMail.Textbody = "The toner for " & RTrim(strPrinterName) & " is currently at or below 25%" & vbCrLf & "Printer Name: " & vbTab & vbTab & vbTab & strPrinterName & vbCrLf & "Black Toner Percentage Left: " & vbTab & Left(intPercentLeftBlk, 4) & "%" & vbCrLf & "Printer Manufacturer: " & vbTab & vbTab & strManufacturer & vbCrLf & "Printer Model Number: " & vbTab & vbTab & strModel & vbCrLf & "Printer Physical Location: " & vbTab & strLocation & vbCrLf & "Toner Cartridge Model: " & vbTab & vbTab & strTonerCartridgeBlk & vbCrLf & vbCrLf & "Your Friendly," & vbCrLf & "Printer Ninja"
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEMail.Configuration.Fields.Update
objEMail.Send
End If
If intPercentLeftCyan <= 25 Then
strPrinterQuery = "SELECT PrinterName, Manufacturer, Model, Location, TonerCartridgeCyan FROM printers WHERE IP = '" & objPrinter & "'"
Set objRecordSet = CreateObject("ADODB.Recordset")
objRecordSet.Open strPrinterQuery, objConnection, 3, 3
strPrinterName = objRecordSet("PrinterName")
strManufacturer = objRecordSet("Manufacturer")
strModel = objRecordSet("Model")
strLocation = objRecordSet("Location")
strTonerCartridgeCyan = objRecordSet("TonerCartridgeCyan")
Set objEMail = CreateObject("CDO.Message")
objEMail.From = "PrinterNinja@ninja.com"
objEMail.To = "bob@bob.com"
objEMail.Subject = "Printer: " & RTrim(strPrinterName) & " Toner Level: " & Left(intPercentLeftCyan, 4) & "%"
objEMail.Textbody = "The toner for " & RTrim(strPrinterName) & " is currently at or below 25%" & vbCrLf & "Printer Name: " & vbTab & vbTab & vbTab & strPrinterName & vbCrLf & "Cyan Toner Percentage Left: " & vbTab & Left(intPercentLeftCyan, 4) & "%" & vbCrLf & "Printer Manufacturer: " & vbTab & vbTab & strManufacturer & vbCrLf & "Printer Model Number: " & vbTab & vbTab & strModel & vbCrLf & "Printer Physical Location: " & vbTab & strLocation & vbCrLf & "Toner Cartridge Model: " & vbTab & vbTab & strTonerCartridgeCyan & vbCrLf & vbCrLf & "Your Friendly," & vbCrLf & "Printer Ninja"
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEMail.Configuration.Fields.Update
objEMail.Send
End If
If intPercentLeftMag <= 25 Then
strPrinterQuery = "SELECT PrinterName, Manufacturer, Model, Location, TonerCartridgeMag FROM printers WHERE IP = '" & objPrinter & "'"
Set objRecordSet = CreateObject("ADODB.Recordset")
objRecordSet.Open strPrinterQuery, objConnection, 3, 3
strPrinterName = objRecordSet("PrinterName")
strManufacturer = objRecordSet("Manufacturer")
strModel = objRecordSet("Model")
strLocation = objRecordSet("Location")
strTonerCartridgeMag = objRecordSet("TonerCartridgeMag")
Set objEMail = CreateObject("CDO.Message")
objEMail.From = "PrinterNinja@ninja.com"
objEMail.To = "bob@bob.com"
objEMail.Subject = "Printer: " & RTrim(strPrinterName) & " Toner Level: " & Left(intPercentLeftMag, 4) & "%"
objEMail.Textbody = "The toner for " & RTrim(strPrinterName) & " is currently at or below 25%" & vbCrLf & "Printer Name: " & vbTab & vbTab & vbTab & strPrinterName & vbCrLf & "Magenta Toner Percentage Left: " & vbTab & Left(intPercentLeftMag, 4) & "%" & vbCrLf & "Printer Manufacturer: " & vbTab & vbTab & strManufacturer & vbCrLf & "Printer Model Number: " & vbTab & vbTab & strModel & vbCrLf & "Printer Physical Location: " & vbTab & strLocation & vbCrLf & "Toner Cartridge Model: " & vbTab & vbTab & strTonerCartridgeMag & vbCrLf & vbCrLf & "Your Friendly," & vbCrLf & "Printer Ninja"
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEMail.Configuration.Fields.Update
objEMail.Send
End If
If intPercentLeftYel <= 25 Then
strPrinterQuery = "SELECT PrinterName, Manufacturer, Model, Location, TonerCartridgeYel FROM printers WHERE IP = '" & objPrinter & "'"
Set objRecordSet = CreateObject("ADODB.Recordset")
objRecordSet.Open strPrinterQuery, objConnection, 3, 3
strPrinterName = objRecordSet("PrinterName")
strManufacturer = objRecordSet("Manufacturer")
strModel = objRecordSet("Model")
strLocation = objRecordSet("Location")
strTonerCartridgeYel = objRecordSet("TonerCartridgeYel")
Set objEMail = CreateObject("CDO.Message")
objEMail.From = "PrinterNinja@ninja.com"
objEMail.To = "bob@bob.com"
objEMail.Subject = "Printer: " & RTrim(strPrinterName) & " Toner Level: " & Left(intPercentLeftYel, 4) & "%"
objEMail.Textbody = "The toner for " & RTrim(strPrinterName) & " is currently at or below 25%" & vbCrLf & "Printer Name: " & vbTab & vbTab & vbTab & strPrinterName & vbCrLf & "Yellow Toner Percentage Left: " & vbTab & Left(intPercentLeftYel, 4) & "%" & vbCrLf & "Printer Manufacturer: " & vbTab & vbTab & strManufacturer & vbCrLf & "Printer Model Number: " & vbTab & vbTab & strModel & vbCrLf & "Printer Physical Location: " & vbTab & strLocation & vbCrLf & "Toner Cartridge Model: " & vbTab & vbTab & strTonerCartridgeYel & vbCrLf & vbCrLf & "Your Friendly," & vbCrLf & "Printer Ninja"
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEMail.Configuration.Fields.Update
objEMail.Send
End If
objMaxTonerBlk.Close
objCurrentTonerBlk.Close
objMaxTonerCyan.Close
objCurrentTonerCyan.Close
objMaxTonerMag.Close
objCurrentTonerMag.Close
objMaxTonerYel.Close
objCurrentTonerYel.Close
strTonerCartridgeBlk = empty
intCurrentTonerBlk = empty
intMaxTonerBlk = empty
intPercentLeftBlk = empty
strTonerCartridgeCyan = empty
intCurrentTonerCyan = empty
intMaxTonerCyan = empty
intPercentLeftCyan = empty
strTonerCartridgeMag = empty
intCurrentTonerMag = empty
intMaxTonerMag = empty
intPercentLeftMag = empty
strTonerCartridgeYel = empty
intCurrentTonerYel = empty
intMaxTonerYel = empty
intPercentLeftYel = empty
Else
Set objMaxToner = objFSO.OpenTextFile("C:\Printers\MaxTonerBlk.txt", ForReading)
DO Until objMaxToner.AtEndOfStream
strToner = objMaxToner.ReadLine
strSNMPLen = len(strToner)
intMaxToner = LTrim(Mid(strToner, 45, strSNMPLen))
strToner = empty
strSNMPLen = empty
Loop
Set objCurrentToner = objFSO.OpenTextFile("C:\Printers\CurrentTonerBlk.txt", ForReading)
DO Until objCurrentToner.AtEndOfStream
strToner = objCurrentToner.ReadLine
strSNMPLen = len(strToner)
intCurrentToner = LTrim(Mid(strToner, 45, strSNMPLen))
strToner = empty
strSNMPLen = empty
Loop
intPercentLeft = (intCurrentToner / intMaxToner) * 100
If intPercentLeft <= 25 Then
strPrinterQuery = "SELECT PrinterName, Manufacturer, Model, Location, TonerCartridgeBlk FROM printers WHERE IP = '" & objPrinter & "'"
Set objRecordSet = CreateObject("ADODB.Recordset")
objRecordSet.Open strPrinterQuery, objConnection, 3, 3
strPrinterName = objRecordSet("PrinterName")
strManufacturer = objRecordSet("Manufacturer")
strModel = objRecordSet("Model")
strLocation = objRecordSet("Location")
strTonerCartridge = objRecordSet("TonerCartridgeBlk")
Set objEMail = CreateObject("CDO.Message")
objEMail.From = "PrinterNinja@ninja.com"
objEMail.To = "bob@bob.com"
objEMail.Subject = "Printer: " & RTrim(strPrinterName) & " Toner Level: " & Left(intPercentLeft, 4) & "%"
objEMail.Textbody = "The toner for " & RTrim(strPrinterName) & " is currently at or below 25%" & vbCrLf & "Printer Name: " & vbTab & vbTab & vbTab & strPrinterName & vbCrLf & "Toner Percentage Left: " & vbTab & vbTab & Left(intPercentLeft, 4) & "%" & vbCrLf & "Printer Manufacturer: " & vbTab & vbTab & strManufacturer & vbCrLf & "Printer Model Number: " & vbTab & vbTab & strModel & vbCrLf & "Printer Physical Location: " & vbTab & strLocation & vbCrLf & "Toner Cartridge Model: " & vbTab & vbTab & strTonerCartridge & vbCrLf & vbCrLf & "Your Friendly," & vbCrLf & "Printer Ninja"
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
objEMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEMail.Configuration.Fields.Update
objEMail.Send
End If
End If
strPrinterName = empty
strManufacturer = empty
strModel = empty
strLocation = empty
strTonerCartridge = empty
strPrinterQuery = empty
intCurrentToner = empty
intMaxToner = empty
intPercentLeft = empty
objMaxToner.Close
objCurrentToner.Close
Else
Set objPingErrFile = objFSO.OpenTextFile("C:\Printers\NoPing.txt", ForWriting)
objPingErrFile.Write objPrinter & vbCrLf
objPingErrFile.Close
End If
Next
intMaxToner = empty
intMaxTonerBlk = empty
intMaxTonerCyan = empty
intMaxTonerMag = empty
intMaxTonerYel = empty
objPrinter = empty
Next
objConnection.Close
Wscript.Echo "Script Completed in " & DateDiff("s", Start, Now) & " Seconds"
It is rather sloppy but it works. I havn't gone through to clean it up yet. I added the info for the color printers this morning, so that made it look even worse. This so far only works for HP and Kyocera printers, I will be trying to add Toshiba and Konica Minolta printers also.
Any suggestions for parallel communications? If I can run PJL on the printer I should be able to tell when the toner low alarm comes on using a USTATUS
[edited] because I am retarded and left personal info in my code [/edited] |
_________________ "Paranoia is no longer a mental illness it is a way of life" - Me
|
|