Search code examples
pythonrfidzebra-printerszplzpl-ii

How to capture the ZPL ^HV ouotput


I need help implementing the ^HV ZPL command and to capture it as the host.

I want to read the TID and encode it to the EPC using Python, i can send print and encode command to the printer but how do i read back from it ?

If I'm using the "Direct Communication" program in the Zebra Setup Utilities tool i can get the TID back in the "Data received" window.

Ive tried using TCP/IP but i dont know how to pull the info just to print

But how can i capture it using python ?

Thanks !


Solution

  • Communicating with a Zebra printer over TCP is the same as any other TCP connection. If the question is how to use the ^HV command, it is usually put into a stored format. The response happens when you use the format to print. Here's a snippet I modified from wiki.python.org.

    #!/usr/bin/env python
    
    import socket
    
    TCP_IP = '127.0.0.1'
    TCP_PORT = 9100
    BUFFER_SIZE = 1024
    FORMAT = "^XA^DFE:TEST.ZPL^FO30,30^A0N,50,50^FN1^FS^HV1,15,[,],^FS^XZ"
    PRINT = "^XA^XFE:TEST.ZPL^FN1^FDHELLO WORLD^FS^XZ"
    
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((TCP_IP, TCP_PORT))
    s.send(FORMAT)
    s.send(PRINT)
    data = s.recv(BUFFER_SIZE)
    s.close()
    
    print "received data:", data