m43 mod ok tbt

This commit is contained in:
edo-neo 2025-07-24 15:42:11 +02:00
parent 4bf059656e
commit 59ad46b932
4 changed files with 66 additions and 47 deletions

View File

@ -22,7 +22,7 @@ barcode_prefix = f"#{PN} ###*1IT ECE"
barcode_suffix = "*="
barcode_format = "{barcode_prefix}{SN7}{check}{barcode_suffix}"
barcode_format = f"#{PN} ###*1IT ECE{SN7}{M43:X:Y}*="
module_data_format ="1IT ECE{SN7}"
def main():

View File

@ -13,6 +13,4 @@ class Print_Step_Editor(Editor):
"labeltxt_5": self.labeltxt_5,
"extra_label": self.extra_label,
"barcode": self.barcode,
"prefix_mod_43": self.prefix_43,
"suffix_mod_43": self.suffix_43,
})

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>846</width>
<height>686</height>
<width>750</width>
<height>332</height>
</rect>
</property>
<property name="windowTitle">
@ -243,33 +243,6 @@
</property>
</widget>
</item>
<item row="15" column="1">
<widget class="QLineEdit" name="prefix_43"/>
</item>
<item row="16" column="1">
<widget class="QLineEdit" name="suffix_43"/>
</item>
<item row="15" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>PREFIX</string>
</property>
</widget>
</item>
<item row="16" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>SUFFIX</string>
</property>
</widget>
</item>
<item row="14" column="1">
<widget class="QLabel" name="label_11">
<property name="text">
<string>MOD 43</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -70,6 +70,10 @@ class Test(Widget):
else:
self.flag_label.setVisible(False)
# Initialize barcode formatting variables
self.barcode_prefix = ""
self.barcode_suffix = "*="
self.active_errors = [] # List to hold current errors (type: tuples of (message, is_error))
self.current_error_index = 0 # Keeps track of the current error index during alternation
@ -843,12 +847,8 @@ class Test(Widget):
recipe = archived.test_data.get("recipe", {})
# Define barcode format variables
part_number = recipe.get("part_number", "-")
# Use prefix_mod_43 from print step editor if available, otherwise use default
self.barcode_prefix = self.print_step.spec.get("prefix_mod_43", f"#{part_number} ###*1IT ECE")
self.module_data_format = f"1IT ECE{archived.id:0>7}"
self.module_data_format = "1IT ECE{SN7}"
# Use suffix_mod_43 from print step editor if available, otherwise use default
self.barcode_suffix = self.print_step.spec.get("suffix_mod_43", "*=")
self.barcode_format = self.print_step.spec.get("barcode")
leak_test_1 = archived.test_data.get("leak_1", {})
leak_test_1_step = leak_test_1.get("step", {})
@ -954,16 +954,9 @@ class Test(Widget):
label_brother = context.get("RECIPE_TO_PRINT", "-") + context.get("DD","-") + context.get("MO","-") + context.get("YY","-") + context.get("SN5","-")
barcode = str(label_brother)
formatted_module_data = self.module_data_format.format(**context)
check = self.calculate_modulo43_checksum(formatted_module_data)
context.update(
{
"barcode_prefix": self.barcode_prefix,
"check": check,
"barcode_suffix": self.barcode_suffix,
}
)
formatted_barcode = self.barcode_format.format(**context)
# Process any {M43:X:Y} patterns in the barcode format
processed_barcode_format = self.process_m43_patterns(self.barcode_format, context)
formatted_barcode = processed_barcode_format.format(**context)
context['BCODE'] = formatted_barcode
self.printed_barcode = formatted_barcode
if self.archived is not None:
@ -1118,6 +1111,61 @@ class Test(Widget):
else: # No args provided
self.flag_label.setVisible(False) # Hide label
def process_m43_patterns(self, barcode_format, context):
"""
Process any {M43:X:Y} patterns in the barcode format string.
The pattern {M43:X:Y} is replaced with the modulo 43 check digit calculated
for the substring of the formatted barcode starting at position X and
containing Y characters.
Args:
barcode_format: The barcode format string that may contain {M43:X:Y} patterns.
context: The context dictionary used for formatting.
Returns:
The processed barcode format string with {M43:X:Y} patterns replaced by
placeholders that will be filled with the calculated check digits.
"""
import re
# Create a temporary copy of the barcode format for processing
processed_format = barcode_format
# Find all {M43:X:Y} patterns in the barcode format
pattern = r'\{M43:(\d+):(\d+)\}'
matches = re.finditer(pattern, barcode_format)
# Process each match
for i, match in enumerate(matches):
# Extract X and Y values
x = int(match.group(1))
y = int(match.group(2))
# Create a placeholder for this check digit
placeholder = f"{{m43_check_{i}}}"
# Replace the {M43:X:Y} pattern with the placeholder
processed_format = processed_format.replace(match.group(0), placeholder)
# Format the barcode without the M43 patterns to get the base string
base_format = re.sub(pattern, "", barcode_format)
base_string = base_format.format(**context)
# Extract the substring for checksum calculation
if x < len(base_string) and x + y <= len(base_string):
substring = base_string[x:x+y]
# Calculate the check digit
check_digit = self.calculate_modulo43_checksum(substring)
# Add the check digit to the context
context[f"m43_check_{i}"] = check_digit
else:
# Handle out-of-range indices
self.log.warning(f"M43 pattern with X={x}, Y={y} is out of range for string of length {len(base_string)}")
context[f"m43_check_{i}"] = "?"
return processed_format
def calculate_modulo43_checksum(self,data_sequence: str) -> str:
"""
Calculates the Modulo 43 checksum for a given data sequence.