Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.

Commit 8107630

Browse files
Merge pull request #54 from kso512/master
Add datetime.py script
2 parents 27002bb + 0667533 commit 8107630

5 files changed

Lines changed: 57 additions & 7 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/__pycache__/
2+
3+
# for Snyk
4+
.dccache

Adafruit_Thermal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Adafruit_Thermal(Serial):
5050
lineSpacing = 8
5151
barcodeHeight = 50
5252
printMode = 0
53-
defaultHeatTime = 120
53+
defaultHeatTime = 180
5454
firmwareVersion = 268
5555
writeToStdout = False
5656

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ Install Raspbian Buster and Wire the printer according to [this](https://learn.a
88

99
Run a test to see if the printer is working by punching in these commands into the terminal.
1010

11-
```
11+
``` shell
1212
stty -F /dev/serial0 19200
1313
echo -e "This is a test.\\n\\n\\n" > /dev/serial0
1414
```
1515

1616
### Installing
1717

18-
Update the system and install prequisities.
18+
Update the system and install prerequisites.
1919

20-
```
20+
``` shell
2121
sudo apt-get update
2222
sudo apt-get install git cups wiringpi build-essential libcups2-dev libcupsimage2-dev python3-serial python-pil python-unidecode
2323
```
2424

2525
Install the printer driver. Don't worry about the warnings that g++ gives.
2626

27-
```
27+
``` shell
2828
git clone https://github.com/adafruit/zj-58
2929
cd zj-58
3030
make
@@ -33,14 +33,14 @@ sudo ./install
3333

3434
Make the printer the default printer. This is useful if you are going to be doing other things with it.
3535

36-
```
36+
``` shell
3737
sudo lpadmin -p ZJ-58 -E -v serial:/dev/serial0?baud=19200 -m zjiang/ZJ-58.ppd
3838
sudo lpoptions -d ZJ-58
3939
```
4040

4141
Restart the system. Clone this repository and try to run *printertest.py*.
4242

43-
```
43+
``` shell
4444
git clone https://github.com/galacticfan/Python-Thermal-Printer/
4545
cd Python-Thermal-Printer
4646
python3 printertest.py
-15.2 KB
Binary file not shown.

datetime.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python3
2+
3+
# Python3 script to print the current date and time, using
4+
# the Adafruit_Thermal library, in ISO 8601 format.
5+
# https://www.iso.org/iso-8601-date-and-time-format.html
6+
7+
import time
8+
from Adafruit_Thermal import *
9+
10+
# Lines of margin (integer)
11+
i_feed = 3
12+
# Seconds to pause (float)
13+
f_pause = 1.0
14+
15+
# Define the printer port, speed, and timeout
16+
printer = Adafruit_Thermal("/dev/ttyS0", 19200, timeout=5)
17+
18+
# Build the date stamp in the format YYYY-MM-DD ex: "2021-12-25"
19+
datestamp = time.strftime("%Y-%m-%d", time.gmtime())
20+
print ("Date in preferred format:", datestamp)
21+
22+
# Build the time stamp in the format Thh:mm:ssZ ex: "T23:59:59Z"
23+
timestamp = 'T' + time.strftime("%H:%M:%S", time.gmtime()) + 'Z'
24+
print ("Time in preferred format:", timestamp)
25+
26+
# Tell printer to sleep
27+
printer.sleep()
28+
# Sleep for the defined time in case we're called many times in a row
29+
time.sleep(f_pause)
30+
# Call wake() before printing again, even if reset
31+
printer.wake()
32+
# Restore printer to defaults
33+
printer.setDefault()
34+
35+
# Give a little room at the top
36+
printer.feed(i_feed)
37+
# Center justify
38+
printer.justify('C')
39+
# Large size
40+
printer.setSize('L')
41+
# Print the date
42+
printer.println(datestamp)
43+
# Print the time
44+
printer.println(timestamp)
45+
# Give a little room at the bottom
46+
printer.feed(i_feed)

0 commit comments

Comments
 (0)