Results 1 to 5 of 5

Thread: Get printer status before printing

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    3

    Exclamation Get printer status before printing

    Hi,

    I have to watch the printer status of a matrix printer (Epson LQ1070+). Therefore I used the WMI class 'Win32_Printer'. But I only get a status (eq. Out of paper) when I am trying to print. When no print job is in the spooler I always get the status 'READY/IDLE', even when the printer got no paper and the red 'Out of paper' LED on the printer is ON.

    Does anyone know how I can get a status before I send a printjob?

    I heard that it's also possible to read the LPT-port directly. As I read obn a webpage, a couple of pins from the printerconnector are also sending a status. But I'm using win NT4, and I don't know how I have to read the LPT-port directly.

    Can somebody give me an example-code on how to read the LPT port?


    Thanx for your help!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    This should tell you just about anything you need to know about your printer. Associated Links:
    http://www.merrioncomputing.com/Prog...rintStatus.htm
    http://www.merrioncomputing.com/Prog...g/PrintJob.htm
    VB Code:
    1. Private Const NULLPTR = 0&
    2. ' Constants for DEVMODE
    3. Private Const CCHDEVICENAME = 32
    4. Private Const CCHFORMNAME = 32
    5. ' Constants for DocumentProperties
    6. Private Const DM_MODIFY = 8
    7. Private Const DM_COPY = 2
    8. Private Const DM_IN_BUFFER = DM_MODIFY
    9. Private Const DM_OUT_BUFFER = DM_COPY
    10. ' Constants for dmOrientation
    11. Private Const DMORIENT_PORTRAIT = 1
    12. Private Const DMORIENT_LANDSCAPE = 2
    13. ' Constants for dmPrintQuality
    14. Private Const DMRES_DRAFT = (-1)
    15. Private Const DMRES_HIGH = (-4)
    16. Private Const DMRES_LOW = (-2)
    17. Private Const DMRES_MEDIUM = (-3)
    18. ' Constants for dmTTOption
    19. Private Const DMTT_BITMAP = 1
    20. Private Const DMTT_DOWNLOAD = 2
    21. Private Const DMTT_DOWNLOAD_OUTLINE = 4
    22. Private Const DMTT_SUBDEV = 3
    23. ' Constants for dmColor
    24. Private Const DMCOLOR_COLOR = 2
    25. Private Const DMCOLOR_MONOCHROME = 1
    26.  
    27. Private Type DEVMODE
    28.     dmDeviceName(1 To CCHDEVICENAME) As Byte
    29.     dmSpecVersion As Integer
    30.     dmDriverVersion As Integer
    31.     dmSize As Integer
    32.     dmDriverExtra As Integer
    33.     dmFields As Long
    34.     dmOrientation As Integer
    35.     dmPaperSize As Integer
    36.     dmPaperLength As Integer
    37.     dmPaperWidth As Integer
    38.     dmScale As Integer
    39.     dmCopies As Integer
    40.     dmDefaultSource As Integer
    41.     dmPrintQuality As Integer
    42.     dmColor As Integer
    43.     dmDuplex As Integer
    44.     dmYResolution As Integer
    45.     dmTTOption As Integer
    46.     dmCollate As Integer
    47.     dmFormName(1 To CCHFORMNAME) As Byte
    48.     dmUnusedPadding As Integer
    49.     dmBitsPerPel As Integer
    50.     dmPelsWidth As Long
    51.     dmPelsHeight As Long
    52.     dmDisplayFlags As Long
    53.     dmDisplayFrequency As Long
    54. End Type
    55.  
    56. Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, ByVal pDefault As Long) As Long
    57. Private Declare Function DocumentProperties Lib "winspool.drv" Alias "DocumentPropertiesA" (ByVal hwnd As Long, ByVal hPrinter As Long, ByVal pDeviceName As String, pDevModeOutput As Any, pDevModeInput As Any, ByVal fMode As Long) As Long
    58. Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
    59. Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
    60.  
    61.  
    62. Private Function StripNulls(OriginalStr As String) As String
    63.     If (InStr(OriginalStr, Chr(0)) > 0) Then
    64.         OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
    65.     End If
    66.     StripNulls = Trim(OriginalStr)
    67. End Function
    68.  
    69. Private Function ByteToString(ByteArray() As Byte) As String
    70.     Dim TempStr As String
    71.     Dim I As Integer
    72.  
    73.     For I = 1 To CCHDEVICENAME
    74.         TempStr = TempStr & Chr(ByteArray(I))
    75.     Next I
    76.     ByteToString = StripNulls(TempStr)
    77. End Function
    78.  
    79. Private Function GetPrinterSettings(szPrinterName As String, hdc As Long) _
    80.             As Boolean
    81.     Dim hPrinter As Long
    82.     Dim nSize As Long
    83.     Dim pDevMode As DEVMODE
    84.     Dim aDevMode() As Byte
    85.     Dim TempStr As String
    86.  
    87.     If OpenPrinter(szPrinterName, hPrinter, NULLPTR) Then
    88.         nSize = DocumentProperties(NULLPTR, hPrinter, szPrinterName, _
    89.                 NULLPTR, NULLPTR, 0)
    90.         ReDim aDevMode(1 To nSize)
    91.         nSize = DocumentProperties(NULLPTR, hPrinter, szPrinterName, _
    92.                 aDevMode(1), NULLPTR, DM_OUT_BUFFER)
    93.         Call CopyMemory(pDevMode, aDevMode(1), Len(pDevMode))
    94.  
    95.         List1.Clear   ' empty the ListBox
    96.         List1.AddItem "Printer Name: " & _
    97.                 ByteToString(pDevMode.dmDeviceName)
    98.  
    99.         If pDevMode.dmOrientation = DMORIENT_PORTRAIT Then
    100.             TempStr = "PORTRAIT"
    101.         ElseIf pDevMode.dmOrientation = DMORIENT_LANDSCAPE Then
    102.             TempStr = "LANDSCAPE"
    103.         Else
    104.             TempStr = "UNDEFINED"
    105.         End If
    106.         List1.AddItem "Orientation: " & TempStr
    107.  
    108.         Select Case pDevMode.dmPrintQuality
    109.             Case DMRES_DRAFT
    110.                 TempStr = "DRAFT"
    111.             Case DMRES_HIGH
    112.                 TempStr = "HIGH"
    113.             Case DMRES_LOW
    114.                 TempStr = "LOW"
    115.             Case DMRES_MEDIUM
    116.                 TempStr = "MEDIUM"
    117.             Case Else   ' positive value
    118.                 TempStr = CStr(pDevMode.dmPrintQuality) & " dpi"
    119.         End Select
    120.         List1.AddItem "Print Quality: " & TempStr
    121.  
    122.         Select Case pDevMode.dmTTOption
    123.             Case DMTT_BITMAP    ' default for dot-matrix printers
    124.                 TempStr = "TrueType fonts as graphics"
    125.             Case DMTT_DOWNLOAD  ' default for HP printers that use PCL
    126.                 TempStr = "Downloads TrueType fonts as soft fonts"
    127.             Case DMTT_SUBDEV    ' default for PostScript printers
    128.                 TempStr = "Substitute device fonts for TrueType fonts"
    129.             Case Else
    130.                 TempStr = "UNDEFINED"
    131.         End Select
    132.         List1.AddItem "TrueType Option: " & TempStr
    133.  
    134.         ' Windows NT drivers often return COLOR from Monochrome printers
    135.         If pDevMode.dmColor = DMCOLOR_MONOCHROME Then
    136.             TempStr = "MONOCHROME"
    137.         ElseIf pDevMode.dmColor = DMCOLOR_COLOR Then
    138.             TempStr = "COLOR"
    139.         Else
    140.             TempStr = "UNDEFINED"
    141.         End If
    142.         List1.AddItem "Color or Monochrome: " & TempStr
    143.  
    144.         If pDevMode.dmScale = 0 Then
    145.             TempStr = "NONE"
    146.         Else
    147.             TempStr = CStr(pDevMode.dmScale)
    148.         End If
    149.         List1.AddItem "Scale Factor: " & TempStr
    150.  
    151.         List1.AddItem "Y Resolution: " & pDevMode.dmYResolution & " dpi"
    152.         List1.AddItem "Copies: " & CStr(pDevMode.dmCopies)
    153.         ' Add any other items of interest ...
    154.  
    155.         Call ClosePrinter(hPrinter)
    156.         GetPrinterSettings = True
    157.     Else
    158.         GetPrinterSettings = False
    159.     End If
    160. End Function
    161.  
    162. 'Add A Listbox, or someother type of display control
    163. 'For detailed information about your printer, place the following
    164. 'code in the click event of something
    165. If GetPrinterSettings(Printer.DeviceName, Printer.hdc) = False Then
    166.    List1.AddItem "No Settings Retrieved!"
    167. End If

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Posts
    3
    Thanks for the code Hack!

    I tried it, but I get the same result. I can only read the status
    from the document that is currently processed.

    Do you know something about reading the parallel port directly?

    Greetz,

    M.Mans

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

  5. #5
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    The OpenPrinter() and GetPrinter() API calls return the values for the printer status that they get from the printer driver itself.

    In many cases (for non BIDI interface type printers) the only way that the printer driver knows that there is a problem with the printer is when a job stalls so for such printer drivers it is not possible to know the status of the printer before a job is sent to it.

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width