diff --git a/.gitignore b/.gitignore index 16e5ac0..ebfb5fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # Created by https://www.toptal.com/developers/gitignore/api/macos,python,visualstudiocode # Edit at https://www.toptal.com/developers/gitignore?templates=macos,python,visualstudiocode +test.png # File generated by test server + ### macOS ### # General .DS_Store diff --git a/inventree_phomemo/phomemo_label.py b/inventree_phomemo/phomemo_label.py index 8366c60..a0b0c04 100644 --- a/inventree_phomemo/phomemo_label.py +++ b/inventree_phomemo/phomemo_label.py @@ -62,7 +62,7 @@ class PhomemoLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin): print_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print_socket.settimeout(5) print_socket.connect((ip_address, port)) - data = label_image + data = label_image.tobytes("PNG") print_socket.send(data.encode()) print_socket.close() except Exception as error: diff --git a/inventree_phomemo/server.py b/inventree_phomemo/server.py new file mode 100644 index 0000000..01dcdbf --- /dev/null +++ b/inventree_phomemo/server.py @@ -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 \ No newline at end of file