-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_commandline.py
95 lines (77 loc) · 2.65 KB
/
main_commandline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# IMPORTS
import binascii
import math
from hex_functions import *
from esc_functions import *
from characters import *
import numpy as np
# SPECIFY FILENAME, PRINTERNAME AND OUTPUTFOLDER
filename = 'test_matrix'
# one of the printers for which the header and footer files are available in the 'prns' folder
printer = 'p600'
outputfolder = 'output'
# SET PARAMETERS
# These parameters depend on the specific printer
# printer units can be found by parsing the prn file
# Same with color codes, print a file with all colors and parse it
# other specs can be found by looking in spec sheet or service manual (if available)
# Shown parameters should work with R2400 / P600 / R3000
# unit parameters
pmgmt = 720
vert = 720
hor = 720
mbase = 2880
nozzles = 180
# set nozzle row numbers (def black = 00)
# Should work with R2400 and P600
black = b'\x00'
lightBlack = b'\x10'
lightLightBlack = b'\x30'
cyan = b'\x02'
lightCyan = b'\x12'
magenta = b'\x01'
lightMagenta = b'\x11'
yellow = b'\x04'
# select dot size
d = b'\x10'
# set page method ID
esc_m = ESC_m(b'\x20')
# set uni or bi directional mode
unim = b'\x00' # 01 uni, 00 bi
# CREATE THE RASTERDATA
# initialize empty byte string containing the rasterdata
raster = b''
# location of raster (in inches)
x = 1 # one inch from left edge of paper
y = 1 # one inch from top edge of paper
# Create the matrix
# width of the matrix (number of droplets in printhead travel direction)
width = 100
matrix = np.zeros((nozzles, width)) # init the matrix as all zeros
# set all rows of the matrix to 3's (large droplets), except for the last 2 rows
matrix[0:58, :] = 3
# Create the raster,
# First set the x position of the printhead,
# Print the matrix
raster += ESC_dollar(hor, x) + ESC_i_matrix(black, matrix, spacing=0, fan=0)
# First set the vertical position on the paper, then print the raster as composed in the previous step, add a linefeed
rasterdata = ESC_v(pmgmt, y) + raster + b'\x0c'
# LOAD HEADER AND FOOTER FOR SELECTED PRINTER
# header = load_prn_file('prns/' + printer + '/' + printer + '-header.prn')
# footer = load_prn_file('prns/' + printer + '/' + printer + '-footer.prn')
header = b''
footer = b''
# COMPOSE BODY
body = ESC_Graph() + ESC_Units(pmgmt, vert, hor, mbase) + ESC_Kmode() + \
ESC_imode(n=b'\x00') + ESC_Umode(unim) + ESC_edot(d) + ESC_Dras(v=240/3, h=120/3) + \
ESC_C(pmgmt) + ESC_c(pmgmt) + ESC_S(pmgmt) # + esc_m
# COMBINE
total = header + body + rasterdata + footer
# CREATE OUTPUT DIR
filename = outputfolder + '/' + filename + '.prn'
# if not os.path.exists(outputfolder):
# os.makedirs(outputfolder)
# SAVE PRN FILE
save_prn_file(total, filename)
print('DONE!')
print('path: ' + filename)