1

Using Ruby to send a series of data strings to a Zebra printer using its IP address.

Here's the Ruby code I've started with:

require 'socket'  
streamSock = TCPSocket.new( "127.0.0.1", 20000 )  
#streamSock.send( "Hello\n" )  
str = streamSock.recv( 100 )  
print str  
streamSock.close  

I need to replace the "Hello\n" piece with ZPL (Zebra Print Language) code of this series of strings:

"^XA" +

"^FO50,50" +

"^A0N50,50" +

"^FDHello, World!^FS" +

"^XZ";

I've tried several ways of using #streamSock.send( "xxx" ) for each line - example: #streamSock.send( "^XA" ) - and then all the other string elements separately.

I tried a few variants of putting the entire string of ZPL codes into a single line, like

streamSock.send( "^XA^FO50,50^A0N50,50^FDHello, World!^FS^XZ" )

The Zebra label printer does not respond. If I send the earlier series of strings to the printer as a text file using another utility, it prints fine.

Any ideas of what the Ruby code should be to make this work?

2
  • What model of printer is it? Are you saying sending 'Hello\n' prints fine, but not the ZPL? If so, you may have your printer in line-print mode instead of ZPL. If it is in line print mode, it will not understand ZPL, and vice versa, they are mutually exclusive. Commented Aug 13, 2012 at 12:38
  • I got it to work: require 'socket' hostname = '192.168.1.6' port = 515 s = TCPSocket.open(hostname, port) s.puts "^XA^F100,100^BXN,10,200^FO150,120^FD01000012000000311081020122100000009^FS^XZ" s.close Commented Oct 30, 2012 at 20:03

1 Answer 1

2

It works for me:

require 'socket'

streamSock = TCPSocket.new( "192.168.205.214", 6101 )
str = "^XA" + "^FO50,50" + "^A0N50,50" + "^FDHello World^FS" + "^XZ"
streamSock.send( str , 0)

streamSock.close
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.