Skip to content

Commit

Permalink
Add darkness parameter to multi printer function
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeoLacruz committed Apr 13, 2024
1 parent 8e71a9f commit ace7df4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ in the label section. These values have to fit the label size that is in
the printer. See the example templates for details on template definition.

## Multi printer hack
We had the requirement to print labels in different sizes. As we do not
We have the requirement to print labels in different sizes. As we do not
want to change the reel for each print we set up a second printer loaded
with a different label size. InvenTree is not yet able to handle different
printers. So I added a multi printer hack. You can define a key with an IP
Expand Down
27 changes: 15 additions & 12 deletions inventree_zebra/zebra_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,24 @@ def print_label(self, **kwargs):
interface = self.get_setting('LOCAL_IF')
port = int(self.get_setting('PORT'))
threshold = self.get_setting('THRESHOLD')
darkness = self.get_setting('DARKNESS')
dpmm = int(self.get_setting('DPMM'))
printer_init = self.get_setting('PRINTER_INIT')
label_image = kwargs['png_file']

# Select the right printer.
# This is a multi printer hack. In case the label has an IP address in the metadata
# the address in the settings is overwritten be the metadata. By this you can
# specify a separate printer for each label.
label = kwargs['label_instance']
try:
ip_address = label.metadata['ip_address']
except Exception:
ip_address = self.get_setting('IP_ADDRESS')
try:
darkness = label.metadata['darkness']
except Exception:
darkness = self.get_setting('DARKNESS')

# Extract width (x) and height (y) information.
width = kwargs['width']
height = kwargs['height']
Expand All @@ -113,17 +126,6 @@ def print_label(self, **kwargs):
# datafile.write(li.dumpZPL())
# datafile.close()

# Select the right printer.
# This is a multi printer hack. In case the label has an IP address in the metadata
# the address in the settings is overwritten be the metadata. By this you can
# specify a separate printer for each label.

label = kwargs['label_instance']
try:
ip_address = label.metadata['ip_address']
except Exception:
ip_address = self.get_setting('IP_ADDRESS')

# Send the label to the printer
if (connection == 'local'):
try:
Expand All @@ -136,6 +138,7 @@ def print_label(self, **kwargs):
elif (connection == 'network'):
try:
mysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysocket.settimeout(5)
mysocket.connect((ip_address, port))
data = li.dumpZPL()
mysocket.send(data.encode())
Expand Down

0 comments on commit ace7df4

Please sign in to comment.