Skip to content

Commit 6a98b80

Browse files
committed
Push Original Code
First code commit, setting cursor doesn't work
1 parent 7b4fe2a commit 6a98b80

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

const.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# ---------- CONSTANTS FOR pyBA63 ----------
3+
#
4+
5+
LF = bytearray([10]) #\x0A - Line Feed
6+
CR = bytearray([13]) #\x0D - Carriage Return
7+
CLR = bytearray([27, 91, 50, 74]) #\x1B\x5B\x32\x4A - Clear Display
8+
DEL = bytearray([27, 91, 48, 75]) #\x1B\x5B\x30\x4B - Delete to End of Line
9+
BS = bytearray([8]) #\x08 - Backspace without deleting

pyBA63.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# ---------- Main pyBA63 library ---------
3+
#
4+
5+
import const # Import constant sendables
6+
import serial # Import (py)serial
7+
8+
ser = serial.Serial() # Make Serial object
9+
10+
def open(port):
11+
ser.port = port # Ser serial port
12+
ser.parity = serial.PARITY_ODD # Set ODD parity
13+
ser.open() # Open serial port
14+
15+
def close():
16+
ser.close() # Close serial port
17+
18+
def SetCountryCode(number):
19+
value = bytearray([27, 82, number]) #\x1B\x52 number - Set Country Code
20+
ser.write(value) # Write value to serial
21+
22+
def SetCursor(x, y):
23+
value = bytearray([27, 91, y, 59, x, 72]) #\x1B\x5B y \x3B x \x48 - Set Cursor Position
24+
ser.write(value) # Write value to serial
25+
26+
def WriteData(data):
27+
length = len(data) # Get length of data
28+
value = bytearray([2, 0, length])+data.encode('ascii') #\x02\x00 length data - Format data for sending
29+
ser.write(value) # Write value to serial
30+
31+
def clear():
32+
ser.write(const.CLR) # Write clear to serial
33+
SetCursor(0, 0) # Set cursor to beginning

0 commit comments

Comments
 (0)