Send ZLP directly to Zebra thermal printer without temp file

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
MikeOrlando
Posts: 22
Joined: 05 Jun 2017, 08:18

Send ZLP directly to Zebra thermal printer without temp file

02 Sep 2023, 17:26

Hello All,

I currently have a AHK script that calls a VBSscript, which uses Zebra's 'Print a ZPL File Using the Generic Text Printer' method to generate labels. While this does work, I would like to get this all in the same AHK script and using the same language (IE: ditch the VBS). It would also be great to eliminate the need for the temporary file in the process and send the ZPL directly to the printer.

> https://supportcommunity.zebra.com/s/ar ... eArticle=1

Looking through v1 posts, @jNizM seemed had a great looking 'Class Printers" project and it sounds like @Bkid and @RussF have very similar goals as I did so it would be great not to reinvent the wheel.

> posting.php?mode=quote&f=6&p=532738

Was hoping to move this conversation over to the v2 forum and hoping there was some advice whether pursuing a v2 version of jNizM's class or if there is another option that would allow to send ZLP directly to a Zebra printer, without the need for temp files.


Thanks!
Mike
lexikos
Posts: 9593
Joined: 30 Sep 2013, 04:07
Contact:

Re: Send ZLP directly to Zebra thermal printer without temp file

03 Sep 2023, 20:44

Unless I've overlooked something, that script doesn't have anything for sending data/jobs to a printer.

I believe you would need to follow the process described in the following article:
https://learn.microsoft.com/en-us/windows/win32/printdocs/sending-data-directly-to-a-printer
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Send ZLP directly to Zebra thermal printer without temp file

04 Sep 2023, 01:14

If the printers are not directly connected to the PC or installed and you can print via IP over port 9100 (RAW), you can also print directly to the printer with the socket class.

Example:
viewtopic.php?p=339490#p339490

You can also save the raw file directly in a variable and store it in the script if it does not change.

You only have to look for the socket class for v2 in the forum (there are already one or two) and the rest is easily translatable into v2.
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
MikeOrlando
Posts: 22
Joined: 05 Jun 2017, 08:18

Re: Send ZLP directly to Zebra thermal printer without temp file

04 Sep 2023, 09:54

There are various methods to send data to a Zebra thermal. I had thought the method where you can print a text file to a generic printer using similar scripts that you had referenced may be the easiest; however I do not have have a printer IP to use the socket method.

My Zebra is a mobile printer and connected by bluetooth so I believe the connection is only available through its virtual COM4. Zebra also allows to copy a file to the COM port, but this is where there is a temporary file that I am trying to avoid.

Code: Select all

copy Zebra_ZPL.tmp COM4
Is there a more direct way to "copy" to a COM port without actually using a temp file to copy? I have looked into FileCopy, but of course that requires a source file to copy.
wineguy
Posts: 10
Joined: 03 Dec 2019, 16:26

Re: Send ZLP directly to Zebra thermal printer without temp file

04 Sep 2023, 17:20

You could try a COM library like this viewtopic.php?f=83&t=120880

I don't have access to my zebra to test at the moment, so would be interested to hear if this woks.
MikeOrlando
Posts: 22
Joined: 05 Jun 2017, 08:18

Re: Send ZLP directly to Zebra thermal printer without temp file

13 Sep 2023, 19:32

Thanks for the suggestion. I tired the COM library without success. I couldn't even see data being written to COM4 when using a serial port monitor app when using this script and library.

I did find a post form @its_just_me using FileOpen and had quick success sending a ZPL formatted string to the my Bluetooth Zebra printer.

Code: Select all

#Requires AutoHotkey >=2.0

port := FileOpen("COM4", "w") ; Open for writing
ZPLdata := "^XA^CF0,60^FO220,50^FDHELLO WORLD^FS^CF0,30^XZ"

port.Write(ZPLdata) ; Write ZPL
port.Read(0) ; Flushes the write buffer.
port.Close() ; Close the Port
The only item I had to alter from the original post was the flushing of the write buffer, originally "port.__Handle". I am not sure if my update is correct or even required as it does print without this line. I would imagine it is always best practice to clear the buffer, if someone could advise if this looks correct or need changes that would be great!

I was able to use this site to generate test data/string formatted as ZPL: http://labelary.com/viewer.html

For the printer install, I searched for new devices in Windows printer setup and it found the Bluetooth Zebra, which created COM3-COM5. Windows didn't even find the drivers as it says "driver is unavailable," but all I needed was to have the serial over Bluetooth link created to display the ports. COM4 seems to be the only one that worked in my case.

Seems to work like a charm!

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: hiahkforum, lexikos, wineguy and 51 guests