Announcement

Collapse
No announcement yet.

Printer Identification

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Printer Identification

    I just bought a new HP LaserJet Pro M402n printer. Now I want to modify programs that used another printer but i can't figure out what the name of the new printer is. The old printer was attached to another computer that shared its printer. The new one connect directly to the Internet so I have an IP address, a printer name, and a port name to work with. The printer name is 37 characters and spaces long, the port name is 45 characters and spaces long. I got these names using the PRINTER$ command.

    My code fails:

    DIM DEVICE AS STRING

    DEVICE$ = PRINTER$ (PORT,1) 'or (NAME,1) to get the printer name
    'port name looks like: WSD-9e302c7c-6400-4902- & on & on & on..... port name is 45 characters long
    'printer name looks like: HP LaserJet Pro M402-M403 n-dne PCL-6 .......name is 37 characters long

    LPRINT ATTACH DEVICE$ 'and have tried XPRINT ATTACH DEVICE$
    LPRINT "HELLO WORLD" 'and have tried XPRINT "HELLO WORLD"

    WAITKEY$

    I have tried adding back slashes to these names. I have tried just the IP address with and without backslashes, but I can't hit on just the right name.

    LPRINT ATTACH DEVICE$ ---- limits device names to 32 characters:
    device$ must be a valid device name and cannot exceed 32 characters in length

    This has to be a simple problem that professional programmers take in stride. You have no idea what printer you have to deal with so I assume you depend on results returned from the DEVICE$ command rather than hard coding a particular printer name. Tomorrow your client could purchase all new printers making hard coded names obsolete.

    Help would be greatly appreciated!

    Tim

  • #2
    Try this
    Code:
    #COMPILE EXE
    %IDOK = 1
    %IDCANCEL = 2
    %IDTEXT = 100
    %BN_CLICKED = 0
    %BS_DEFAULT = 1
    %MF_ENABLED = 0
    %WM_COMMAND = &H111
    
    
    %ID_OPEN = 401
    %ID_EXIT = 402
    %ID_PrCurve = 403
    
    %ID_HELP = 405
    %ID_ABOUT = 406
    
    #INCLUDE "Win32Api.inc"
    #INCLUDE "CommCtrl.inc"
    
    
    '  Globals for the printing of curves
       GLOBAL MAXP() , MINP()   AS LONG
       GLOBAL MIDX             AS DOUBLE
       GLOBAL MIDY             AS DOUBLE
       GLOBAL ROTCOS           AS DOUBLE
       GLOBAL ROTSIN           AS DOUBLE
       GLOBAL SCALE            AS DOUBLE
    
       GLOBAL SCALX            AS DOUBLE
       GLOBAL SCALY            AS DOUBLE
       GLOBAL TLTANG           AS DOUBLE
       GLOBAL TLTCOS           AS DOUBLE
       GLOBAL TLTSIN           AS DOUBLE
       GLOBAL VDIST            AS DOUBLE
    
       GLOBAL VERT             AS DOUBLE
       GLOBAL PLTRAD           AS DOUBLE
       GLOBAL XP               AS LONG
       GLOBAL YP               AS LONG
    
       GLOBAL hMenu, hDlg, hprHook AS DWORD
    
    
    
    '==================================
     FUNCTION PBMAIN () AS LONG
    
      CreateBarMenu
    
     ' ** Create a new dialog template
      DIALOG NEW PIXELS, 0, "Print Test Menu" , 160,160,250,200, _
              %WS_BORDER  OR %WS_SYSMENU OR %WS_THICKFRAME OR _
              %WS_VISIBLE OR %WS_CLIPCHILDREN OR %SS_GRAYFRAME _
              OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT _
              OR %WS_EX_TRANSPARENT , _
              %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
              %WS_EX_RIGHTSCROLLBAR OR %WS_EX_TOPMOST, TO hDlg
    
    
       MENU ATTACH hMenu, hDlg
    
    
      ' ** Display the dialog
       DIALOG SHOW MODAL hDlg, CALL DlgProc
    
    
    END FUNCTION
    
    
    
    
    '====================================
    CALLBACK FUNCTION DlgProc()
      IF CB.MSG = %WM_COMMAND THEN
    
          IF CB.CTL = %ID_PrCurve THEN
               PrinCurves
              EXIT FUNCTION
          END IF
    
         IF CB.CTL => %ID_OPEN AND CB.CTL <= %ID_ABOUT THEN
          MSGBOX "WM_COMMAND received from a menu item!", &H00002000&
            FUNCTION = 1
        END IF
     END IF
    END FUNCTION
    
    
    
    '====================================
    ' To hook the Printer dialog and set it
    ' to be  the Topmost dialog
    FUNCTION PrinterDialogHook(BYVAL lMsg AS LONG, _
        BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
      IF lMsg < 0 THEN
          EXIT FUNCTION
      END IF
     IF lMsg = %HCBT_ACTIVATE THEN
       SetWindowPos(wParam, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOSIZE OR %SWP_NOMOVE)
       UnhookWindowsHookEx(hprHook)
     END IF
     END FUNCTION
    
    
    
    
    
    
    
    '======================
    SUB CreateBarMenu
    
      LOCAL hPopup1 AS DWORD
      LOCAL hPopup2 AS DWORD
    
     ' ** First create a top-level menu:
      MENU NEW BAR TO hMenu
    
     ' ** Add a top-level menu item with a popup menu:
      MENU NEW POPUP TO hPopup1
      LOCAL MenuInf AS MENUINFO
      MenuInf.cbSize  = SIZEOF(MENUINFO)
      MenuInf.fMask   = %MIM_STYLE OR %MIM_BACKGROUND OR %MIM_MAXHEIGHT
      MenuInf.dwStyle = %MNS_NOCHECK 'Remove the checked space area
      'Back color
      MenuInf.hbrBack =%RGB_LIGHTYELLOW ' GetSysColorBrush(%COLOR_DESKTOP)
      MenuInf.cyMax   = 200 'Add scrollbar to menu if height exceed cyMax pixels
      SetMenuInfo(hPopup1, MenuInf)
    
      MENU ADD POPUP, hMenu, "&File", hPopup1, %MF_ENABLED
      MENU ADD STRING, hPopup1, "&Open", %ID_OPEN, %MF_ENABLED
      MENU ADD STRING, hPopup1, "&Print Curves", %ID_PrCurve, %MF_ENABLED
      MENU ADD STRING, hPopup1, "&Exit", %ID_EXIT, %MF_ENABLED
      MENU ADD STRING, hPopup1, "-", 0, 0
    
      MENU NEW POPUP TO hPopup2
    
     ' ** Now add a new menu item to the first menu.
      ' This item will bring up the sub-menu when selected:
      MENU ADD POPUP, hPopup1, "&More Options", hPopup2, %MF_ENABLED
    
    
      MENU NEW POPUP TO hPopup1
      MENU ADD POPUP, hMenu, "&Help", hPopup1, %MF_ENABLED
      MENU ADD STRING, hPopup1, "&Help", %ID_HELP, %MF_ENABLED
      MENU ADD STRING, hPopup1, "-", 0, 0
      MENU ADD STRING, hPopup1, "&About", %ID_ABOUT, %MF_ENABLED
    
    
    END SUB
    
    
    
    
    
    
    
    
    
    
    '====================================
    SUB PrinCurves
       LOCAL MyWin            AS DWORD
       LOCAL HS               AS DOUBLE
       LOCAL LS               AS DOUBLE
       LOCAL LINSPA           AS DOUBLE
       LOCAL LNSLIN           AS DOUBLE
       LOCAL MAXX             AS DOUBLE
       LOCAL MAXY             AS DOUBLE
    
       LOCAL PI               AS DOUBLE
       LOCAL PLTLEN           AS DOUBLE
       LOCAL PLTLIM           AS DOUBLE
    
       LOCAL PTSLIN           AS DOUBLE
       LOCAL R                AS DOUBLE
       LOCAL ROTANG           AS DOUBLE
    
       LOCAL X1               AS DOUBLE
       LOCAL Y1               AS DOUBLE
       LOCAL Z1               AS DOUBLE
       LOCAL MYHEADING        AS STRING
    
    
      ' Initialize ------------------------
       PI     = 3.14159
       MAXX   = 6300        ' 3150
       MAXY   = 4800        ' 2400
       MIDX   = MAXX / 2
       MIDY   = MAXY / 2
       LS     = -100
       HS     = MAXX + 100
       PLTLIM = 6.4
       PLTRAD = 4
       VDIST  = PLTLIM * 50
       PTSLIN = 3000
       LNSLIN = 75
       ROTANG = 20
       TLTANG = 30
       SCALE  = 2
       VERT   = 1
       SCALX  = MIDX * .7 / PLTLIM
       SCALY  = MIDY * .9 / PLTLIM
       LINSPA = 2 * PLTLIM / LNSLIN
       PLTLEN = PLTLIM / PTSLIN
       ROTANG = ROTANG * PI / 180
       TLTANG = TLTANG * -PI / 180
       ROTCOS = COS(ROTANG)
       ROTSIN = SIN(ROTANG)
       TLTCOS = COS(TLTANG)
       TLTSIN = SIN(TLTANG)
       MYHEADING = "z = (cos(2r) - sin(r))"
    
    
    
       REDIM MAXP(LS TO HS)
       REDIM MINP(LS TO HS)
    
       LOCAL I AS DOUBLE
       FOR I = LS TO HS
         MAXP(I) = -999999
         MINP(I) =  999999
       NEXT
    
    
     'Install hook just before "XPRINT ATTACH CHOOSE"
      hprHook = SetWindowsHookEx(%WH_CBT, CODEPTR(PrinterDialogHook), _
                 GetModuleHandle(BYVAL 0), GetCurrentThreadId)
     ' Allow for Selection of printers -- note that there is some slight delay
      ' which you cannot select printer -- need to click on properties
      ' but after this is ok
       XPRINT ATTACH CHOOSE       ' User choose Windows printer
    
    
       XPRINT SET ORIENTATION 2   ' Landscape mode
       XPRINT SCALE (-5,MAXY+5)-(MAXX+40,0)
     ' XPRINT COLOR BLACK
    
    ' Border
       XPRINT WIDTH 8
       XPRINT BOX (0,0)-(MAXX,MAXY)
       XPRINT WIDTH 1
    
    ' Heading
       XPRINT FONT "Ariel", 14, 1
       XPRINT TEXT SIZE MYHEADING TO XP, YP
       XPRINT SET POS ((MAXX - XP) / 2, YP+20)
       XPRINT MYHEADING
    
    
    
       ' plotting here-----------------------
    ' First border
       FOR Y1 = -PLTLIM TO PLTLIM + LINSPA / 10 STEP PLTLEN
         X1 = PLTLIM
          Plot(X1,Y1)
       NEXT
    
    ' Lateral Lines
       FOR Y1 = -PLTLIM TO PLTLIM + LINSPA / 10 STEP LINSPA
         FOR X1 = PLTLIM TO -(PLTLIM + PLTLEN / 10) STEP -PLTLEN
            Plot(X1,Y1)
         NEXT
    
       NEXT
    
    ' Last Border
       FOR Y1 = -PLTLIM TO PLTLIM + LINSPA / 10 STEP PLTLEN
         X1 = -PLTLIM
          Plot(X1,Y1)
       NEXT
    
       XPRINT CLOSE
       MSGBOX "Plot complete"
    
    
     END SUB
    
    
    
    
    '======================================
    ' Plot the points
    SUB Plot( Xp1 AS DOUBLE, Yp1 AS DOUBLE)
    ' Calculate Function
      LOCAL R,Z1, X,Y,Z,S  AS DOUBLE
    
       R = SQR(Xp1 * Xp1 + Yp1 * Yp1)
    
       Z1 = (COS(R + R) - SIN(R)) * SCALE + VERT    ' Calculate Z value
    
       X = Xp1 * ROTCOS + Yp1 * ROTSIN       ' Rotate
       Y = Yp1 * ROTCOS - Xp1 * ROTSIN
       Z = Z1 * TLTCOS - Y * TLTSIN        ' Tilt
       Y = Y * TLTCOS + Z1 * TLTSIN
       S = VDIST / (VDIST + Y)             ' Perspective
       X = X * S
       Z = Z * S
       XP = MIDX + (X * SCALX)             ' Scale to Screen
       YP = MIDY + (Z * SCALY)
       IF YP > MAXP(XP) THEN               ' Plot point if visible
          MAXP(XP) = YP
        ' XPRINT SET PIXEL (XP,YP)
          XPRINT ELLIPSE (XP-PLTRAD,YP-PLTRAD)-(XP+PLTRAD,YP+PLTRAD),-1,-1
       END IF
       IF YP < MINP(XP) THEN
          MINP(XP) = YP
        ' XPRINT SET PIXEL (XP,YP)
          XPRINT ELLIPSE (XP-PLTRAD,YP-PLTRAD)-(XP+PLTRAD,YP+PLTRAD),-1,-1
       END IF
    END SUB

    Comment


    • #3
      Click on menu bar
      File
      --> Print curves
      --> Printer dialog

      You would be able to select which printer and click on the print button to print the curves




      Comment


      • #4
        Thank you Anne,
        An important piece of information I forgot to mention is that I am using the PBCC environment. Something in the CALLBACK function doesn't work in PBCC.

        This little program gets the string "HELLO WORLD" to the spooler, but nothing happens after that.

        #COMPILE EXE
        #DIM ALL

        FUNCTION PBMAIN () AS LONG

        DIM DEVICE AS STRING
        DEVICE$ = PRINTER$ (NAME,1)
        'xprint attach device$ 'try 1 is to use the PRINTER$ command to find the name
        XPRINT ATTACH DEFAULT 'try 2 is to use the term DEFAULT
        PRINT DEVICE$ 'prints ->
        XPRINT "HELLO WORLD"
        PRINT ERR
        WAITKEY$

        END FUNCTION

        Tim

        Comment


        • #5
          Code:
          function pbmain () as long
           xprint attach choose
           xprint "hello world"
           xprint close  'or xprint formfeed
          end function
          https://duckduckgo.com instead of google

          Comment


          • #6
            Mike,
            Thanks your code worked. Mine didn't and they aren't that much different. Then I remembered that nothing happens, print wise, until the XPRINT CLOSE command is given. I modified my code appropriately and it worked just fine. I knew it was just a simple problem, but this must be brain fog day!

            Thanks!
            Tim

            Comment


            • #7
              Originally posted by Tim Collins View Post
              LPRINT ATTACH DEVICE$ 'and have tried XPRINT ATTACH DEVICE$
              LPRINT "HELLO WORLD" 'and have tried XPRINT "HELLO WORLD"

              LPRINT ATTACH DEVICE$ ---- limits device names to 32 characters
              Part of the problem is that LPRINT really works best with printers that don't require Windows to do most of their thinking since it send the data directly to the printer, and not through the windows printing sub-system. To be honest, I'm sure about the current crop of network attached laser printers, but I can say that with most cheap lasers and all the inkjets I've come across, XPRINT is the better choice. At work, I cheat and do a NET USE LPT1: \\printer_name\port_name on our network attached Brother laser printers, and LPRINT ATTACH LPT1 and the other LPRINT works just fine. Up until early this year, we were printing bills of lading on a dot matrix printer (don't laugh). What took the windows based programs 4 minutes to print, I got with PB in a few seconds. For printing to lasers, we purchased Virtual Print Engine (VPE). It's saved us TONS of time on complex documents. Not that they are impossible with XPRINT, just that VPE is easier.
              Real programmers use a magnetized needle and a steady hand

              Comment


              • #8
                The windows bitmap printing way has to send a lot more information to the printer because it has to print by way of image. Adobe was the first do this by way of postscript they created to deal with non line print printers. The windows way takes out the use of having to use built in type fonts in a printer or download fonts to the printer first.
                I noticed in years past by looking at spooled doucuments where adobe reader was creating significantly less code to the printer than Foxit PDF reader and printing much faster. And this mattered on networks where the speed was much slower then. Unix and Linux history on printing will provide some great knowledge on what happened in the past concerning printing. Windows is a knock off those systems.
                p purvis

                Comment


                • #9
                  Bud Durland & Paul Purvis,

                  Thank you for explaining XPRINT vs LPRINT. I've seen other posts that recommend XPRINT over LPRINT, but I was never sure why.

                  I bought PBCC about a year ago which was an upgrade for me from PowerBasic Version 2.10a. Programming is a hobby that sometimes came in handy when I was working. Now that I'm retired I'm learning again, but there is a big gap between 2.10a and PBCC.

                  Tim

                  Comment


                  • #10
                    Originally posted by Tim Collins View Post
                    Bud Durland & Paul Purvis,
                    Thank you for explaining XPRINT vs LPRINT. I've seen other posts that recommend XPRINT over LPRINT, but I was never sure why.
                    For me, LPRINT is most useful when I want to send data to the printer with any molestation by Windows. In our environment, that's mostly sending data to label printers using the ZPL encoding.

                    Real programmers use a magnetized needle and a steady hand

                    Comment


                    • #11
                      Cool that a dot-matrix printer can be used with LPRINT, but have to wonder why if there is a Windows printer driver for thermal, ink-jet and laser printers.
                      Haven't seen a dot-matrix printer in over a decade (except maybe at Walgreens.)


                      https://duckduckgo.com instead of google

                      Comment


                      • #12
                        Originally posted by Mike Doty View Post
                        Cool that a dot-matrix printer can be used with LPRINT, but have to wonder why if there is a Windows printer driver for thermal, ink-jet and laser printers.
                        Haven't seen a dot-matrix printer in over a decade (except maybe at Walgreens.)
                        There's still quite a market for dot matrix - especially in business applications that use multi-part forms. They still do very well in terms of durability and cost per page.

                        Comment

                        Working...
                        X