1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle; |
4
|
|
|
|
5
|
|
|
class ThermalPrinter |
6
|
|
|
{ |
7
|
|
|
const PATH = '/dev/serial0'; |
8
|
|
|
|
9
|
|
|
private $fp = null; |
10
|
|
|
|
11
|
|
|
private $isInverse = false; |
12
|
|
|
|
13
|
|
|
public function __construct($debug = false) |
14
|
|
|
{ |
15
|
|
|
if ($debug) { |
16
|
|
|
$this->fp = fopen('php://stdout', 'w+'); |
17
|
|
|
} else { |
18
|
|
|
$this->fp = fopen(self::PATH, 'w+'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
$this->init(); |
22
|
|
|
|
23
|
|
|
return $this; |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function init() |
27
|
|
|
{ |
28
|
|
|
fwrite($this->fp, chr(27).chr(64)); // flush printer |
29
|
|
|
fwrite($this->fp, chr(27).chr(116).chr(6)); // set codepage |
30
|
|
|
fwrite($this->fp, chr(27).chr(55).chr(8).chr(100).chr(5)); // set codepage |
31
|
|
|
return $this; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function writeString($string) |
35
|
|
|
{ |
36
|
|
|
fwrite($this->fp, wordwrap(iconv('UTF-8', 'cp1251', $string), 32)); |
37
|
|
|
return $this; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function hr() |
41
|
|
|
{ |
42
|
|
|
fwrite($this->fp, "\n\n\n"); |
43
|
|
|
fwrite($this->fp, '================================'); |
44
|
|
|
fwrite($this->fp, "\n\n\n"); |
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function hhr() |
49
|
|
|
{ |
50
|
|
|
fwrite($this->fp, "\n\n\n"); |
51
|
|
|
$this->inv()->writeString(str_repeat(' ', 32))->inv(); |
52
|
|
|
fwrite($this->fp, "\n\n\n"); |
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function inv() |
57
|
|
|
{ |
58
|
|
|
$this->isInverse = !$this->isInverse; |
59
|
|
|
fwrite($this->fp, chr(29).chr(66).chr($this->isInverse?1:0)); |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function fiscal() |
64
|
|
|
{ |
65
|
|
|
fwrite($this->fp, "\n"); |
66
|
|
|
$this->inv(); |
67
|
|
|
fwrite($this->fp, ' '.iconv( |
68
|
|
|
'UTF-8', |
69
|
|
|
'cp1251', |
70
|
|
|
'<D0><A4><D0><98><D0><A1><D0><9A><D0><90><D0><9B><D0><AC><D0><9D><D0><AB><D0><99>' |
71
|
|
|
).' '); |
72
|
|
|
$this->inv(); |
73
|
|
|
fwrite($this->fp, "\n"); |
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function writeText($text) |
78
|
|
|
{ |
79
|
|
|
fwrite($this->fp, iconv('UTF-8', 'cp1251', $text)); |
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function __destruct() |
84
|
|
|
{ |
85
|
|
|
fwrite($this->fp, "\n\n\n\n\n\n\n"); |
86
|
|
|
fclose($this->fp); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|