Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sistemicorp/scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
sistemicorp committed Jul 30, 2024
2 parents 78880e4 + 5a95b8d commit 563c212
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ public/prism/drivers/brother_ql700/wip/


.vscode/settings.json

public/prism/scripts/a43/temp/
Binary file not shown.
Empty file modified public/prism/drivers/brother_ql700/TIMES.TTF
100644 → 100755
Empty file.
Empty file modified public/prism/drivers/brother_ql700/brother_ql/README.txt
100644 → 100755
Empty file.
Empty file modified public/prism/drivers/brother_ql700/brother_ql/__init__.py
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified public/prism/drivers/brother_ql700/brother_ql/exceptions.py
100644 → 100755
Empty file.
Empty file modified public/prism/drivers/brother_ql700/brother_ql/helpers.py
100644 → 100755
Empty file.
Empty file modified public/prism/drivers/brother_ql700/brother_ql/image_trafos.py
100644 → 100755
Empty file.
Empty file modified public/prism/drivers/brother_ql700/brother_ql/labels.py
100644 → 100755
Empty file.
Empty file modified public/prism/drivers/brother_ql700/brother_ql/models.py
100644 → 100755
Empty file.
Empty file modified public/prism/drivers/brother_ql700/brother_ql/output_helpers.py
100644 → 100755
Empty file.
Empty file modified public/prism/drivers/brother_ql700/brother_ql/raster.py
100644 → 100755
Empty file.
40 changes: 22 additions & 18 deletions public/prism/drivers/brother_ql700/hwdrv_ql700.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,26 @@ def discover_channels(self):
id = 0
dev = usb.core.find(find_all=True)
for d in dev:
# print(d) to see all the attributes
manu = usb.util.get_string(d, d.iManufacturer)
prod = usb.util.get_string(d, d.iProduct)
if manu == "Brother" and prod in ["QL-700", ]:
self.logger.info("Found {} {}".format(manu, prod))

p = '/dev/usb/lp0' # FIXME: when multiple printers exist, need to find file association

drivers.append({"id": id,
"version": VERSION,
"hwdrv": BrotherQL700(id, p),
"play": None,
"show_pass_fail": None,
"show_msg": None,
"close": None})
id += 1
#print(d) #to see all the attributes
try:
manu = usb.util.get_string(d, d.iManufacturer)
prod = usb.util.get_string(d, d.iProduct)
if manu == "Brother" and prod in ["QL-700", ]:
self.logger.info("Found {} {}".format(manu, prod))

p = '/dev/usb/lp0' # FIXME: when multiple printers exist, need to find file association

drivers.append({"id": id,
"version": VERSION,
"hwdrv": BrotherQL700(id, p),
"play": None,
"show_pass_fail": None,
"show_msg": None,
"close": None})
id += 1

except Exception as e:
self.logger.warning(e)

if not drivers:
self.logger.error("printer not found")
Expand All @@ -225,8 +229,8 @@ def discover_channels(self):

# do not allow the test script validation step to succeed if can't print a test label
for d in drivers:
id, path = d["printer"].get_id_path()
success = d["printer"].print_ruid_barcode("id{}-{}".format(id, path))
id, path = d["hwdrv"].get_id_path()
success = d["hwdrv"].print_ruid_barcode("id{}-{}".format(id, path))
if not success:
self.logger.error("failed to print")
pub_notice("HWDriver:{}: failed to print".format(self.SFN), sender="discover_channels", type=PUB.NOTICES_ERROR)
Expand Down
117 changes: 117 additions & 0 deletions public/prism/scripts/a43/FAT/a43_FAT_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Sistemi Corporation, copyright, all rights reserved, 2024
Martin Guthrie
"""
import os
import base64
from PIL import Image, ImageDraw, ImageFont
import qrcode
from core.test_item import TestItem
from public.prism.api import ResultAPI

import logging
logger = logging.getLogger()


def QL_700_Label(model, serial, hwver):
""" Create label for P1150 bottom side
"""
TEMP_PATH = "public/prism/scripts/a43/temp"
QRCODE_PATH = TEMP_PATH + "/qrcode.PNG"
BODY_PATH = TEMP_PATH + "/pil_text.png"
LABEL_PATH = TEMP_PATH + "/label.png"

if not os.path.exists(TEMP_PATH):
os.makedirs(TEMP_PATH)

qr = qrcode.QRCode(version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=8,
border=1)

encrypted_info = "{}".format(serial)

qr.add_data(encrypted_info)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
img.save(QRCODE_PATH)
qrcode_path = os.path.abspath(QRCODE_PATH)

img = Image.new('RGB', (696, 309), color='white')

d = ImageDraw.Draw(img)
font_path = './public/prism/drivers/brother_ql700/AnonymousPro-Regular.ttf'
logger.debug(font_path)
font = ImageFont.truetype(font_path, 34)
d.text((10, 10), "MDL:{}".format(model), fill=(0, 0, 0), font=font)
d.text((10, 40), "VER:{}".format(hwver), fill=(0, 0, 0), font=font)
d.text((10, 70), "SN :{}".format(serial.upper()), fill=(0, 0, 0), font=font)
d.text((10, 100), "www.sistemi.ca", fill=(0, 0, 0), font=font)
d.text((10, 130), "Made in Canada", fill=(0, 0, 0), font=font)
img.save(BODY_PATH)
body_path = os.path.abspath(BODY_PATH)

text = Image.open(body_path, 'r')
barcode = Image.open(qrcode_path, 'r')

label = Image.new('RGBA', (696, 180), color="white")
label.paste(text, (0, 0))
label.paste(barcode, (500, 0))
label.save(LABEL_PATH)
img_file = os.path.abspath(LABEL_PATH)

with open("{}".format(img_file), 'rb') as image:
str = base64.b64encode(image.read())
file = open(TEMP_PATH + "/img.txt", 'w')
file.write(str.decode("utf-8"))
file.close()

return img_file


# file and class name must match
class a43_FAT_01(TestItem):
"""
"""

def __init__(self, controller, chan, shared_state):
super().__init__(controller, chan, shared_state)
self.logger = logging.getLogger("{}.{}".format(__name__, self.chan))
self.printer = None

def FAT000SETUP(self):
""" Setup
"""
ctx = self.item_start() # always first line of test
printer_info = self.shared_state.get_drivers(None, type="Brother_QL-700")
if not printer_info:
self.logger.error("Printer not found")
self.item_end(ResultAPI.RECORD_RESULT_INTERNAL_ERROR)
return

self.printer = printer_info[0]['obj']['hwdrv']
self.item_end() # always last line of test

def FAT010_LABEL(self):
ctx = self.item_start() # always first line of test

label_path = QL_700_Label("P1150","0123456", "a430800")
self.printer._print_label(label_path)

self.item_end() # always last line of test

def FAT999TRDN(self):
""" Teardown
"""
ctx = self.item_start() # always first line of test
# there is nothing to do...
self.item_end() # always last line of test



27 changes: 27 additions & 0 deletions public/prism/scripts/a43/FAT/a43_FAT_01.scr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Sistemi P1150 a4308 Final Assembly Test (FAT)
{
"info": {
"product": "P1150",
"bom": "a0430800",
"lot": "12345",
"location": "K0H2H0"
},
"config": {
"fail_fast": true,
// channel_hw_driver: list of code to initialize the test environment, must be specified
"drivers": ["public.prism.drivers.fake.hwdrv_fake",
"public.prism.drivers.brother_ql700.hwdrv_ql700"]
},
"tests": [
{
// module is path to python code supporting this test
"module": "public.prism.scripts.a43.FAT.a43_FAT_01",
"options": {},
"items": [
{"id": "FAT000SETUP", "enable": true },
{"id": "FAT010_LABEL", "enable": true },
{"id": "FAT999TRDN", "enable": true }
]
}
]
}

0 comments on commit 563c212

Please sign in to comment.