fix(label): Encode label to png before sending
This commit is contained in:
parent
86b1c9c1a7
commit
60f3d79e73
3 changed files with 26 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -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
|
||||||
|
|
|
@ -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:
|
||||||
|
|
23
inventree_phomemo/server.py
Normal file
23
inventree_phomemo/server.py
Normal 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
|
Loading…
Add table
Reference in a new issue