fix(label): Encode label to png before sending

This commit is contained in:
Andreas Mieke 2024-04-17 21:54:13 -04:00
parent 86b1c9c1a7
commit 60f3d79e73
Signed by: zenermerps
SSH key fingerprint: SHA256:Ne+hwc5QIgYlqCuLZ0LV3301Wo/p8UoGOrGC+T6S0t8
3 changed files with 26 additions and 1 deletions

2
.gitignore vendored
View file

@ -1,6 +1,8 @@
# Created by https://www.toptal.com/developers/gitignore/api/macos,python,visualstudiocode # Created by https://www.toptal.com/developers/gitignore/api/macos,python,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,python,visualstudiocode # Edit at https://www.toptal.com/developers/gitignore?templates=macos,python,visualstudiocode
test.png # File generated by test server
### macOS ### ### macOS ###
# General # General
.DS_Store .DS_Store

View file

@ -62,7 +62,7 @@ class PhomemoLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin):
print_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print_socket.settimeout(5) print_socket.settimeout(5)
print_socket.connect((ip_address, port)) print_socket.connect((ip_address, port))
data = label_image data = label_image.tobytes("PNG")
print_socket.send(data.encode()) print_socket.send(data.encode())
print_socket.close() print_socket.close()
except Exception as error: except Exception as error:

View file

@ -0,0 +1,23 @@
# server.py
# simple listener to an IP port to test the phomemo plugin
import socket
PORT = 9100 # Port to listen on
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', PORT))
s.listen(1)
while True:
conn, addr = s.accept()
print(addr)
while True:
data = conn.recv(9100)
print('data received')
print('Sending to printer...')
printer=open('test.png','wb')
printer.write(data)
printer.close()
if not data:
break