Last active
December 10, 2021 10:07
-
-
Save Bouni/0dda3d5e6425630ccd405cf3e6cb30e3 to your computer and use it in GitHub Desktop.
Control Weber Marking Markoprint X1Jet printer with python
This file contains hidden or 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
| # https://www.weber-marking.com/inkjet-printers/drop-on-demand-inkjet-printers/markoprint-x1jet.html | |
| import serial | |
| ESC = "\x1B" | |
| CR = "\x0D" | |
| STX = "\x02" | |
| ETX = "\x03" | |
| class X1Jet: | |
| def __init__(self, port="COM1", baud=9600, timeout=1): | |
| self.serial = serial.Serial(port=port, baudrate=baud, timeout=timeout) | |
| def handshake(self): | |
| """Send handshake to X1JET""" | |
| # <ESC>*<CR> | |
| with self.serial as s: | |
| print("Send handshake") | |
| command = f"{ESC}*{CR}" | |
| s.write(bytearray(command, encoding="UTF-8")) | |
| response = s.readline() | |
| print(response.decode("UTF-8")) | |
| def save_print( | |
| self, name="MABI", angle=0, x="00000", y="0000", font="A8mm", text="Text" | |
| ): | |
| """Send print data to X1JET""" | |
| # <ESC>EW----;1.00I<CR> | |
| # <ESC>P1-0-000000000:A8mm;Test<CR> | |
| # <ESC>EX----;<CR> | |
| with self.serial as s: | |
| print("Save print") | |
| commands = [ | |
| f"{ESC}EW----;{name}.00I{CR}", | |
| f"{ESC}P1-{angle}-{x}{y};{font};{text}{CR}", | |
| f"{ESC}EX----;{CR}", | |
| ] | |
| for command in commands: | |
| s.write(bytearray(command, encoding="UTF-8")) | |
| response = s.readline() | |
| print(response.decode("UTF-8")) | |
| def load_print(self, name="1", head=1, mode=1): | |
| """Load print data for printing""" | |
| # <STX>TZ1.00I;11<CR><ETX> | |
| with self.serial as s: | |
| print("Load print") | |
| command = f"{STX}TZ{name}.00I;{head}{mode}{CR}{ETX}" | |
| s.write(bytearray(command, encoding="UTF-8")) | |
| response = s.readline() | |
| print(response.decode("UTF-8")) | |
| def enable_print(self): | |
| """Enable print""" | |
| # <ESC>F<CR> | |
| with self.serial as s: | |
| print("Enable print") | |
| command = f"{ESC}F{CR}" | |
| s.write(bytearray(command, encoding="UTF-8")) | |
| response = s.readline() | |
| print(response.decode("UTF-8")) | |
| x1jet = X1Jet() | |
| x1jet.handshake() | |
| x1jet.save_print(text="Hello World") | |
| x1jet.load_print() | |
| x1jet.enable_print() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Important, if the selected font (A8mm) is not installed on the printer, nothing happens.
Additional fonts can be uploaded using iDesign8.