1
votes

I'm using python to communicate with a zebra R600 (latest firmware) printer over TCP/IP for sending ZPL that will read the TID from the tag and store in in a file using ZPL ^HV.

My problem is that every 80 tags or so(random) im getting a shorter TID from the printer (example below)

I have tried to change the printer cache but it didn't seem to have any effect and the problem is quite random and the short output is from a normal tag. Any suggestion ?

My code:

#!/usr/bin/env python

import socket
import os.path
from os import rename

global data
global count

count = 0


def writeTID(tid):  
    f = open("UID_list.txt",'a')
    f.write(str(tid) + "\n")
    f.close()


def Read_TID(quantity):
    global count
    f = open("UID_list.txt",'a')
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((TCP_IP, TCP_PORT))
    for x in range(0,int(quantity)):
        zpl = """
        ^XA
        ^RSB,B30,236,3,N
        ^RR10
        ^XZ
        ^XA
        ^SZ2^JMA
        ^MCY^PMN
        ^PW1215^MTT
        ^MNW
        ~JSN
        ~SD18^MD0
        ^PR8,8,8
        ^JZY
        ^LH0,0^LRN
        ^FN4^FS
        ^FN4^RFR,H,0,12,2^FS
        ^FH_^HV4,24,,,L^FS
        ^PQ1,0,1,Y^XZ
        """
        print "Tag number:"+str(x+1)
        s.send(str(zpl))
        data = s.recv(BUFFER_SIZE)

        print "Received data:", data
        f.write(str(data) + "\n")
        if (len(data)<24):
            count+=1
    print "\nnumber of errors: "+str(count)
    s.close()
    f.close()

#printer settings
TCP_IP = '192.168.7.220'
TCP_PORT = 9100
BUFFER_SIZE = 1024



print ("\t\t\t ##############################################################")
print ("\t\t\t ##############################################################")
print ("\t\t\t #######                                              #########")
print ("\t\t\t #######          TID file maker v1.0.0               #########")
print ("\t\t\t #######                                              #########")
print ("\t\t\t ##############################################################")
print ("\t\t\t ##############################################################")
print ("\t\t\t\nM A I N    M E N U")
print ("\t\t\t\n------------------\n")

while True :
    if os.path.isfile("UID_list.txt"):
        num_lines = sum(1 for line in open("UID_list.txt"))
        print("\nYou have "+str(num_lines)+" labels in corrent roll")
    print("\n1:Start or continue roll\n2:Finish roll\n")
    selected = raw_input("\tPlease select an option: ")

    if selected =="1":
        add_number = raw_input("How many labels to manufacture?\n ")
        Read_TID(add_number)

    elif selected =="2":
        roll_number = raw_input("What is the roll number?\n ")
        rename("UID_list.txt","UID_list_Roll_"+str(roll_number)+".txt") 

Output file:

E280116020006537E1EA08F1
E280116020007527E1EA08F1
E280116020007517E1EA08F1
E280116020006507E1EA08F1
E280116020006357E1E608F1
E280116020007347E1E608F1
E280116020006337E1E608F1
E280116020007327E1E608F1
E280116020007317E1E608F1
E280116
E2801160200061F7E1E408F1
E2801160200071E7E1E408F1
E280116020006157E1E408F1
E280116020007147E1E408F1
E2801160200071F7E1D608F1
E2801160200061E7E1D608F1
E2801160200061D7E1D608F1
E2801160200071C7E1D608F1
E2801160200061B7E1D608F1
E2801160200071A7E1D608F1
E280116020007197E1D608F1
E
E280116020007167E1D608F1
E280116020007157E1D608F1
E280116020006147E1D608F1
E280116020007137E1D608F1
E280116020006127E1D608F1
E280116020006117E1D608F1
E280116020006507E1EA08F1
E2801160200063F7E1E608F1

BR, Idan.

1

1 Answers

0
votes

Added a delay between s.send(str(zpl)) and s.recv(BUFFER_SIZE) that is equal to the time for the printer to eject the label( time.sleep(1.5) )