Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send Text To Printer with ZPL

Status
Not open for further replies.

UncleCake

Technical User
Feb 4, 2002
355
US
Hi,

I posted a little about this yesterday, but I have made some steps closer to my goal. I am trying to print labels to a Zebra printer on our network.

What I am trying to accomplish is to send just text to the label printer, which has a generic/text driver installed for it. In my VB code, I am currently setting the printer, doing a Printer.Print "ZPL code goes here" and Printer.EndDoc. When I send it to the printer the data light on the printer is illuminated, but nothing prints. My question is how do I send just text to the printer or do I have to actually send a text file?

I know my ZPL code is correct because I have it in a text file and do a File >> Print and it prints out as it should.

-UncleCake
 
I print ZPL files across our network using FTP. I also use the Zebra print servers that connect to the LPT port that allows a network connection. Here is the code I use to print across our network.
Code:
Open "c:\temp\label.zpl" For Output As #1
Write #1, g_strZPL
Close #1

'****** Print through the network *******
sBuffer = "FTP -n -s:G:\FTPRUN.TXT " & PrintSVR 'ZBR2424237"
ExecCmd sBuffer

in the file FTPRIN.TXT is the FTP commands to print the file written above.
Also each of the print servers has a unique number that is assigned to it (ZBR2424237 for example). This can be changed to better identify the printer server with the software that comes with them or is available from the website. Can't remember where I got it.
Code:
put C:\Temp\Label.zpl
quit

You will need to put this in a module
Code:
Option Explicit

'******This module takes the place of "GetModuleUsage%" used in VB 4.0******

Private Type STARTUPINFO
         cb As Long
         lpReserved As String
         lpDesktop As String
         lpTitle As String
         dwX As Long
         dwY As Long
         dwXSize As Long
         dwYSize As Long
         dwXCountChars As Long
         dwYCountChars As Long
         dwFillAttribute As Long
         dwFlags As Long
         wShowWindow As Integer
         cbReserved2 As Integer
         lpReserved2 As Long
         hStdInput As Long
         hStdOutput As Long
         hStdError As Long
      End Type
 
      Private Type PROCESS_INFORMATION
         hProcess As Long
         hThread As Long
         dwProcessID As Long
         dwThreadID As Long
      End Type
 
      Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
         hHandle As Long, ByVal dwMilliseconds As Long) As Long
 
      Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
         lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
         lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
         ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
         ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
         lpStartupInfo As STARTUPINFO, lpProcessInformation As _
         PROCESS_INFORMATION) As Long
 
      Private Declare Function CloseHandle Lib "kernel32" (ByVal _
         hObject As Long) As Long
 
      Private Const NORMAL_PRIORITY_CLASS = &H20&
      Private Const INFINITE = -1&
      Private Const STARTF_USESHOWWINDOW = &H1

 
      Public Sub ExecCmd(cmdline$)
      
      '******This is the SUB (ExecCmd) you call instead of GetModuleUsage%********
      
         Dim proc As PROCESS_INFORMATION
         Dim start As STARTUPINFO
         Dim ret As Long
         
         ' Initialize the STARTUPINFO structure:
         start.wShowWindow = 1                                  'Set to use minimized window
         start.dwFlags = STARTF_USESHOWWINDOW                   'Tells to use new "showwindow" settings
         start.cb = Len(start)
 
         ' Start the shelled application:
         ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
            NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
 
         ' Wait for the shelled application to finish:
         ret& = WaitForSingleObject(proc.hProcess, INFINITE)
         ret& = CloseHandle(proc.hProcess)
      End Sub

HTH
 
Sorry I didn't follow-up, I have been fumbling around tiring to decide/figure out what to do.

I don't really want to go FTP, but this morning I did figure out that I can use the printer object and do a Printer.Print with the ZPL, set the driver of the printer to Text Only and send the ZPL directly to the printer. So far in my tests it looks like this will work.

-UncleCake
 
Glad you are making progress. I didn't want to do it this way either but with DHCP and an IT department who didn't have "time" to help me out and a static IP was out of the question. Using FTP freed up some "time" for them as I didn't need there assistance. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top