赞
踩
import socket mysocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) host = "X.X.X.X" //打印机ip地址 port = 9100 //打印机端口 image_path = "123.pcx" class Function(): @staticmethod def Print_pcx(): try: mysocket.connect((host, port)) with open(image_path,"rb") as f: img = f.read() len_img = len(img) a0 = b'I8,1,001\r\n' a0 += b'ZN\r\n' a0 += b'q795\r\n' a0 += b'O\r\n' a0 += b'*D5F\r\n' a0 += b'JF\r\n' a0 += b'H10\r\n' a0 += b'ZT\r\n' a0 += b'Q520,25\r\n' a0 += b'GK"img_1"\r\n' a0 += b'GM"img_1"' + bytes(str(len_img), 'GBK') + b'\r\n' a0 += img + b'\r\n' a0 += b'N\r\n' a0 += b'GG50,50,"img_1"\r\n' a0 += b'W1\r\n' a0 += b'GK"img_1"\r\n' mysocket.send(a0) mysocket.close() except: print("Printer connection failed") function = Function() function.Print_pcx()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。