Difference between revisions of "Simple guide to use a thermo printer with python"
Jump to navigation
Jump to search
(2 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
from escpos.printer import Usb #imports the library in the script.py | from escpos.printer import Usb #imports the library in the script.py | ||
import time #import the time library | import time #import the time library | ||
− | iprinter = Usb(0x0416,0x5011) #defines where the printer is connected | + | iprinter = Usb(0x0416,0x5011) #defines where the printer is connected - in this case its a usb connection the first number is the vendor ID and the secondnumber is the product ID |
− | + | while True: #this function is running now for ever | |
iprinter.text("Hello World") #sends "Hello World" to the printer | iprinter.text("Hello World") #sends "Hello World" to the printer | ||
iprinter.text("\n") #sends a new line to the printer | iprinter.text("\n") #sends a new line to the printer | ||
Line 17: | Line 17: | ||
</pre> | </pre> | ||
+ | |||
+ | |||
+ | <pre> | ||
from escpos import * #imports the library in the script.py | from escpos import * #imports the library in the script.py | ||
import time #import the time library | import time #import the time library | ||
− | + | iprinter = printer.Serial("/dev/cu.usbserial-10") #in this case the printer is connected via a usb to serial device and the printer.Serial command sends to the serial device | |
− | |||
− | iprinter = printer.Serial("/dev/cu.usbserial-10") | ||
while True: #this function is running now for ever | while True: #this function is running now for ever | ||
Line 27: | Line 28: | ||
iprinter.text("\n") #sends a new line to the printer | iprinter.text("\n") #sends a new line to the printer | ||
time.sleep(1) #makes a bre | time.sleep(1) #makes a bre | ||
+ | </pre> | ||
+ | |||
+ | [[Category:Python]] |
Latest revision as of 16:44, 21 November 2022
- connect the printer via usb to your PC/Pi/...
- install the escpos library via pip. more info about this python library here
pip install escpos
- create a script.py file
from escpos.printer import Usb #imports the library in the script.py import time #import the time library iprinter = Usb(0x0416,0x5011) #defines where the printer is connected - in this case its a usb connection the first number is the vendor ID and the secondnumber is the product ID while True: #this function is running now for ever iprinter.text("Hello World") #sends "Hello World" to the printer iprinter.text("\n") #sends a new line to the printer time.sleep(1) #makes a break for one second
from escpos import * #imports the library in the script.py import time #import the time library iprinter = printer.Serial("/dev/cu.usbserial-10") #in this case the printer is connected via a usb to serial device and the printer.Serial command sends to the serial device while True: #this function is running now for ever iprinter.text("Hello World") #sends "Hello World" to the printer iprinter.text("\n") #sends a new line to the printer time.sleep(1) #makes a bre