Last active
September 14, 2021 19:41
-
-
Save ChrisHinde/03c649d3cb72104fadf168c7f51e85a3 to your computer and use it in GitHub Desktop.
Convert text to character codes for (some) Sharp POS/Cash registers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
# Author: Christopher Hindefjord - chris.hindefjord.se | |
# September 2021 | |
# License: CC-0 (Public domain) | |
# =========================== | |
# Converts a list of strings/descriptions to numeric character code for (some) Sharp cash registers. | |
# The character codes are taken from the "Instruction manual" for Sharp XE-A113! | |
# Refer to the manual of your unit, to see if it uses the same codes. | |
# | |
# USAGE: Change the values of the first array bellow [strings] to the text that you want to convert | |
# You can also change the how the resulting codes are separated (by default just a space) | |
# | |
# REQUIRES Python3+ | |
# | |
# NOTE: | |
# a) This script DOES NOT support the full character set, due to that it includes some characters that are | |
# not in the UTF-8 character set (Like superscribt F, subscript T), and that I got tired of looking up | |
# (more or less) "obscure" characters. If you need any of the missing characters: I'm sorry! | |
# b) For character codes with one (or two) leading zeros (0) you do need to enter (on the PoS unit) | |
# the zeros for every character (except the first one), | |
# so the text ABC (A: 065, B: 066, C: 067) would need to be entered as | |
# 65066067 | |
# | |
# - - - - | |
# | |
# DISCLAIMER: | |
# No quarantees given that the output of this script produces the correct codes! | |
# | |
# | |
# =========================== | |
# Change these values to the text that you want converted | |
strings = [ "My Amazing store", | |
"https://myamazing.store", | |
"INGA ÅTERKÖP!", | |
"NO RETURNS" ] | |
# Change this if you want the character codes to be one per line, etc. | |
separator = " " # For one character per line, change to: "\n", or comma separated: ", " | |
# ----------------------- MAIN CODE (no need to edit!)--------------------------- # | |
# Array with all the "Descriptor codes" for (some) Sharp cash registers | |
ch_list = { "á": "001", "â": "002", "ê": "003", "î": "004", "ì": "005", "í": "006", "ô": "007", "ó": "008", "û": "009", "ú": "010", | |
"œ": "011", "ű": "012", "ú": "013", "ő": "014", "ó": "015", "Λ": "016", "Ψ": "017", "Γ": "018", "¨": "019", "Ω": "020", | |
"Δ": "021", "Θ": "022", "Ξ": "023", "Π": "024", "Σ": "025", "Υ": "026", "Φ": "027", "Ű": "028", "Ú": "029", "Ő": "030", | |
"Ó": "031", " ": "032", "!": "033", "\"": "034", "#": "035", "$": "036", "%": "037", "&": "038", "'": "039", "(": "040", | |
")": "041", "*": "042", "+": "043", ",": "044", "-": "045", ".": "046", "/": "047", "0": "048", "1": "049", "2": "050", | |
"3": "051", "4": "052", "5": "053", "6": "054", "7": "055", "8": "056", "9": "057", ":": "058", ";": "059", "<": "060", | |
"=": "061", ">": "062", "?": "063", "@": "064", "A": "065", "B": "066", "C": "067", "D": "068", "E": "069", "F": "070", | |
"G": "071", "H": "072", "I": "073", "J": "074", "K": "075", "L": "076", "M": "077", "N": "078", "O": "079", "P": "080", | |
"Q": "081", "R": "082", "S": "083", "T": "084", "U": "085", "V": "086", "W": "087", "X": "088", "Y": "089", "Z": "090", | |
"Ä": "091", "Ö": "092", "Ü": "093", "^": "094", "_": "095", "'": "096", "a": "097", "b": "098", "c": "099", "d": "100", | |
"e": "101", "f": "102", "g": "103", "h": "104", "i": "105", "j": "106", "k": "107", "l": "108", "m": "109", "n": "110", | |
"o": "111", "p": "112", "q": "113", "r": "114", "s": "115", "t": "116", "u": "117", "v": "118", "w": "119", "x": "120", | |
"y": "121", "z": "122", "{": "123", "|": "124", "}": "125", "β": "126", "¢": "127", "‼": "128", "₁": "129", "₂": "130", | |
"₃": "131", "₄": "132", "½": "133", "FT": "134", "←": "135", "→": "136", "◀": "139", "▶": "140", | |
"↓": "143", "ç": "144", "°": "145", "¿": "146", "ù": "147", "à": "148", "Æ": "149", "ø": "150", | |
"Å": "151", "¤": "152", "é": "153", "è": "154", "i": "156", "Ñ": "157", "ò": "158", "£": "159", "¥": "160", | |
"°": "161", u"\u2BFE": "163", | |
"€": "207", | |
"*": "224", "§": "225", "Ø": "226", "^": "227", "↑": "228", "]": "229", "[": "230", | |
"ä": "232", "ö": "233", "ü": "234", "æ": "235", "å": "236", "É": "237", "ñ": "238", } | |
# "": "253", # <<-- This "character" (DOUBLE) does not have a matching character in ASCII/UTF-8 | |
# The function that does "the work": | |
# Takes a string and outputs the matching character code | |
# The seperator between each character code can be changed by setting the second (seperator) argument (default: [SPACE]) | |
def convert(in_str, separator = " "): | |
print(in_str + ":") | |
for ch in in_str: | |
c = ch_list[ch] | |
print(c, end = separator) | |
print("\n") | |
# Loop through the list of strings to convert | |
for s in strings: | |
convert(s, separator) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment