Jump to content
Sign in to follow this  
simy8891

Netcat to send ZPL files to Zebra printers

Recommended Posts

simy8891

Hi all,

I'm struggling since a few days with a little script I'm trying to write but it won't work.

To make it short: it creates a .ZPL file which then has to be sent to a Zebra label printer via its IP address.

It works like a charm when I excute the command from the command line or with a .bat file.

This is the script (made it a bit shorter):

$netcat=@ScriptDir&'\netcat\nc.exe'
$printerIP='192.168.0.5'

;*** Build ZPL and write it to a file **************************************************************************

$zplprocesslocation='C:\Users\autoit\Desktop\tmp\VM Shared\PrintLabel\Test-Script\Process'
$zplfilename=@YEAR & @MON &  @MDAY & '-' & @HOUR & '-' & @MIN&'-'&@SEC&'.ZPL'
$zplfilefull=$zplprocesslocation&'\'&$zplfilename

$zplcontent='^XA'&@CRLF
$zplcontent=$zplcontent&'^PW862'&@CRLF
$zplcontent=$zplcontent&'^FT165,88^A@N,79,81,TT0003M_^FH\^CI17^F8^FDDP / N:654321^FS^CI0'&@CRLF
$zplcontent=$zplcontent&'^BY4,3,154^FT43,308^BCN,,Y,N'&@CRLF
$zplcontent=$zplcontent&'^FD>;4321>6dcba>51234>6abcd>51234^FS'&@CRLF
$zplcontent=$zplcontent&'^PQ1,0,1,Y^XZ'

;Writing the zpl file
$file = FileOpen($zplfilefull,1)
    FileWrite($file, $zplcontent)
    Sleep(100)
FileClose($file)
;**************************************************************************************************************

;*** Print ZPL and back it up *********************************************************************************

;RunWait(@ComSpec&' /c "'&$netcat&'" -w 2 -d '&$printerIP&' 9100 < "'&$zplfilefull&'"', '', @SW_HIDE, 2)
;_RunDos(@ComSpec&' /C "'&@ScriptDir&'\print.bat" "'&$netcat&'" '&$printerIP&' "'&$zplfilefull&'"')

Run('"'&$netcat&'" -w -2 -d '&$printerIP&' 9100 < "'&$zplfilefull&'"',"",@SW_HIDE)

Now, the two comments you see for RunWait and _RunDos (I know it's missing process.au3) are the other tests I've made. Really I don't know anymore what to change.

I've also tried to write the Run command into a file to check if it was actually right, and indeed it was, I was able to copy the whole text and paste it into a CMD line and it worked!

Another thing I've done was writing a batch file:

%1 -w 2 -d %2 9100 < %3

Where basically I passed the full netcat location, the printer's IP and the location of the .ZPL. I then used Run and _RunDos to try to pass these variables to it, nothing. That works when I manually use it though.

Any help is appreciated, probably I'm doing something stupid I can't see :).

Cheers

Share this post


Link to post
Share on other sites
lordofthestrings
RunWait(@ComSpec & ' /c ' & $netcat & ' -w -2 -d ' & $printerIP & ' 9100 ^< '& Chr(34) & $zplfilefull & Chr(34),'',@SW_SHOW)
 
I think you need to escape the special character "<" like I did..
Kind regards,

Share this post


Link to post
Share on other sites
simy8891

Thanks Polymath, but nope, it didn't work.

There's also a dash before "2" which shouldn't be there, I tried also with Chr(60) instead of ^< or of <, nothing.

I write the exact output to a file, open it with notepad, copy the whole thing and paste it in the command prompt: works like a charm.

Any other suggestion?

Thanks

Share this post


Link to post
Share on other sites
lordofthestrings
$netcat = "nc.exe"
$printerIP = "10.0.0.1"
$zplfilefull="test.txt"
If FileExists (@ScriptDir & "\run.cmd") Then FileDelete (@ScriptDir & "\run.cmd")
RunWait(@ComSpec & ' /c echo ' & $netcat & ' -w -2 -d ' & $printerIP & ' 9100 ^< '& Chr(34) & $zplfilefull & Chr(34) & ">>" & @ScriptDir & "\run.cmd",'',@SW_SHOW)
;RunWait("\run.cmd",@ScriptDir, @SW_SHOW)

Share this post


Link to post
Share on other sites
simy8891

Thanks again. Sorry for the delay but it's a pretty busy period and I didn't have much time left to work on this.

Anyway, I didn't take your script as it is, but I tried again to use the RunWait, this time specifying @scriptdir as working directory and using just the file names on print.bat which expect two variables: printer name and zpl name.

It worked great, so I think i'll keep building the script from there.

Thank you :)

  • Like 1

Share this post


Link to post
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
Sign in to follow this  

×