我使用python通过TCP/IP与zebra R600(最新固件)打印机通信,以发送ZPL,该ZPL将从标签读取TID并使用ZPL ^HV存储在文件中。
我的问题是每80个标签左右(随机)我从打印机得到一个更短的TID(示例如下)
我试图改变打印机缓存,但它似乎没有任何效果,问题是相当随机的,短输出是从一个正常的标签。有什么建议吗?
我代码:#!/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 ("ttt ##############################################################")
print ("ttt ##############################################################")
print ("ttt ####### #########")
print ("ttt ####### TID file maker v1.0.0 #########")
print ("ttt ####### #########")
print ("ttt ##############################################################")
print ("ttt ##############################################################")
print ("tttnM A I N M E N U")
print ("tttn------------------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 rolln2:Finish rolln")
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")
输出文件:
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,艾丹•。
增加了s.s send(str(zpl))和s.s recv(BUFFER_SIZE)之间的延迟,该延迟等于打印机弹出标签的时间(time.sleep(1.5))