-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John Major
committed
Oct 31, 2023
1 parent
e13b5cf
commit 39760a3
Showing
4 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
Tools to get and (soon) set varios zebra printer config. | ||
""" | ||
|
||
import socket | ||
|
||
class ZebraPrinter: | ||
|
||
def __init__(self, ip_address, port=9100, buffer_size=1024): | ||
self.ip_address = ip_address | ||
self.port = port | ||
self.buffer_size = buffer_size | ||
|
||
|
||
def send_command(self, command): | ||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | ||
s.connect((self.ip_address, self.port)) | ||
s.sendall(command.encode()) | ||
response = s.recv(self.buffer_size) | ||
return response.decode() | ||
|
||
|
||
def get_configuration(self): | ||
"""Retrieve printer configuration using ^HH command""" | ||
return self.send_command("^XA^HH^XZ") | ||
|
||
|
||
def set_configuration(self, config): | ||
""" | ||
Set printer configuration. | ||
The `config` parameter should contain the necessary ZPL commands to adjust the configuration. | ||
After sending the configuration commands, the ^JUS command saves the configuration. | ||
""" | ||
self.send_command(config) | ||
return self.send_command("^XA^JUS^XZ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
^XA | ||
^FO30,10 | ||
^ADN,30,20 | ||
^FD{XX}^FS | ||
^FO300,10 | ||
^ADN,30,20 | ||
^FD{YY}^FS | ||
^FO300,200 | ||
^ADN,25,12 | ||
^FD{ZZ}^FS | ||
^FO250,10 | ||
^FO30,170 | ||
^ADN,30,20 | ||
^FD{WW}^FS | ||
^XZ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters