Jump to content

LPT1 and Zebra Printers


Recommended Posts

I have searched through the forums looking for what might be an answer and I can't find anything, so my appologies if I have missed something already posted!

I have applications developed in Delphi and VB that print to a Zebra (barcode) printers. I have being trying to do the samething with AutoIt. Is it possible?

Here is a sampling of VBA code I use:

Open "LPT1:" For Output As #1

Write #1, "^XA"

Write #1, "^LH10,10^FS" ' Set label home

Write #1, "^FWn^FS"

Write #1, "^BY4,3,225^FS"

Write #1, "^FO15,30^ADn,36,40^FD" & sMessage1 & "^FS"

Write #1, "^FO15,80^ADn,36,40^FD" & sMessage1a & "^FS"

Write #1, "^FO15,130^ADn,36,40^FD" & sMessage1b & "^FS"

Write #1, "^FO15,250^ADn,36,20^FD" & sName & "^FS"

Write #1, "^FO15,300^ADn,36,20^FD" & sDept & "^FS"

Write #1, "^FO15,380^ADn,36,50^FD" & sMessage2 & "^FS"

Write #1, "^XZ"

Close #1

Thanks in advance for any assistance!

Link to comment
Share on other sites

Why not simply writing to the Windows printer device, like is done in your VBA example? _Much_ simpler and cleaner than doing the dirty job on the physical port yourself.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Why not simply writing to the Windows printer device, like is done in your VBA example? _Much_ simpler and cleaner than doing the dirty job on the physical port yourself.

Sorry, I am kind of new at this - could you be a little more specific or give me an example? Thanks!

Link to comment
Share on other sites

Differences from VBA to AutoIt are not that big: your code should translate nicely into:

; of course you need to have data variables declared and loaded...
; I seem to recall that VBA appends a CRLF to every write except when instructed not to.
; In case this is wrong, change accordingly.

Local $hdl = FileOpen("LPT1:", 1)
FileWriteLine($hdl, "^XA")
FileWriteLine($hdl, "^LH10,10^FS") ; Set label home
FileWriteLine($hdl, "^FWn^FS")
FileWriteLine($hdl, "^BY4,3,225^FS")
FileWriteLine($hdl, "^FO15,30^ADn,36,40^FD" & $sMessage1 & "^FS")
FileWriteLine($hdl, "^FO15,80^ADn,36,40^FD" & $sMessage1a & "^FS")
FileWriteLine($hdl, "^FO15,130^ADn,36,40^FD" & $sMessage1b & "^FS")
FileWriteLine($hdl, "^FO15,250^ADn,36,20^FD" & $sName & "^FS")
FileWriteLine($hdl, "^FO15,300^ADn,36,20^FD" & $sDept & "^FS")
FileWriteLine($hdl, "^FO15,380^ADn,36,50^FD" & $sMessage2 & "^FS")
FileWriteLine($hdl, "^XZ")
FileClose($hdl)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Differences from VBA to AutoIt are not that big: your code should translate nicely into:

; of course you need to have data variables declared and loaded...
; I seem to recall that VBA appends a CRLF to every write except when instructed not to.
; In case this is wrong, change accordingly.

Local $hdl = FileOpen("LPT1:", 1)
FileWriteLine($hdl, "^XA")
FileWriteLine($hdl, "^LH10,10^FS") ; Set label home
FileWriteLine($hdl, "^FWn^FS")
FileWriteLine($hdl, "^BY4,3,225^FS")
FileWriteLine($hdl, "^FO15,30^ADn,36,40^FD" & $sMessage1 & "^FS")
FileWriteLine($hdl, "^FO15,80^ADn,36,40^FD" & $sMessage1a & "^FS")
FileWriteLine($hdl, "^FO15,130^ADn,36,40^FD" & $sMessage1b & "^FS")
FileWriteLine($hdl, "^FO15,250^ADn,36,20^FD" & $sName & "^FS")
FileWriteLine($hdl, "^FO15,300^ADn,36,20^FD" & $sDept & "^FS")
FileWriteLine($hdl, "^FO15,380^ADn,36,50^FD" & $sMessage2 & "^FS")
FileWriteLine($hdl, "^XZ")
FileClose($hdl)

Thanks - I will try this - someone has run off with my printer - when I get it back will let you know. Thanks Again!
Link to comment
Share on other sites

Thanks - I will try this - someone has run off with my printer - when I get it back will let you know. Thanks Again!

Sorry so late getting back to you - I just got my printer back today. I tried the code and thought that I had before I posted the question and it still won't print - the application locks up on: FileOpen("LPT1:", 1) - I reran my VBA code to ensure the printer was correctly set up and it ran.

Any thoughts?

Link to comment
Share on other sites

Yeah, that's strange. I'll try to get it to work somehow...

Please try this. I don't even have a non-Ethernet printer here and my Brother barcode printer (networked as well) wouldn't eat Zebra code anyway.

#include <WinAPI.au3>

; insert data variables definition here

Local $sText =  "^XA" & @CRLF & _
                "^LH10,10^FS" & @CRLF & _ ; Set label home
                "^FWn^FS" & @CRLF & _
                "^BY4,3,225^FS" & @CRLF & _
                "^FO15,30^ADn,36,40^FD" & $sMessage1 & "^FS" & @CRLF & _
                "^FO15,80^ADn,36,40^FD" & $sMessage1a & "^FS" & @CRLF & _
                "^FO15,130^ADn,36,40^FD" & $sMessage1b & "^FS" & @CRLF & _
                "^FO15,250^ADn,36,20^FD" & $sName & "^FS" & @CRLF & _
                "^FO15,300^ADn,36,20^FD" & $sDept & "^FS" & @CRLF & _
                "^FO15,380^ADn,36,50^FD" & $sMessage2 & "^FS" & @CRLF & _
                "^XZ" & @CRLF

Local $tBuffer = DllStructCreate("char[" & StringLen($sText) & "]")
DllStructSetData($tBuffer, 1, $sText)
Local $nWritten
Local $hFile = _WinAPI_CreateFile("LPT1", 2)
_WinAPI_WriteFile($hFile, DllStructGetPtr($tBuffer), StringLen($sText), $nWritten)
_WinAPI_CloseHandle($hFile)
Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...