Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
esc_pos_print_plus
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dio Maulana
esc_pos_print_plus
Commits
43233a73
Commit
43233a73
authored
Jun 12, 2019
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added beep and fontType commands
parent
81180762
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
1 deletion
+40
-1
commands.dart
lib/src/commands.dart
+3
-0
printer.dart
lib/src/printer.dart
+37
-1
No files found.
lib/src/commands.dart
View file @
43233a73
...
@@ -3,6 +3,7 @@ const gs = '\x1D';
...
@@ -3,6 +3,7 @@ const gs = '\x1D';
// Miscellaneous
// Miscellaneous
const
cInit
=
'
$esc
@'
;
// Initialize printer
const
cInit
=
'
$esc
@'
;
// Initialize printer
const
cBeep
=
'
${esc}
B'
;
// Beeper [count] [duration]
// Mech. Control
// Mech. Control
const
cCut
=
'
${gs}
V0'
;
// Cut paper
const
cCut
=
'
${gs}
V0'
;
// Cut paper
...
@@ -19,6 +20,8 @@ const cUnderline1dot = '$esc-1'; // Turns on underline mode (1-dot thick)
...
@@ -19,6 +20,8 @@ const cUnderline1dot = '$esc-1'; // Turns on underline mode (1-dot thick)
const
cUnderline2dots
=
'
$esc
-2'
;
// Turns on underline mode (2-dots thick)
const
cUnderline2dots
=
'
$esc
-2'
;
// Turns on underline mode (2-dots thick)
const
cBoldOn
=
'
${esc}
E1'
;
// Turn emphasized mode on
const
cBoldOn
=
'
${esc}
E1'
;
// Turn emphasized mode on
const
cBoldOff
=
'
${esc}
E0'
;
// Turn emphasized mode off
const
cBoldOff
=
'
${esc}
E0'
;
// Turn emphasized mode off
const
cFontA
=
'
${esc}
M0'
;
// Font A
const
cFontB
=
'
${esc}
M1'
;
// Font B
// Print Position
// Print Position
const
cAlignLeft
=
'
${esc}
a0'
;
// Left justification
const
cAlignLeft
=
'
${esc}
a0'
;
// Left justification
...
...
lib/src/printer.dart
View file @
43233a73
...
@@ -4,6 +4,7 @@ import 'commands.dart';
...
@@ -4,6 +4,7 @@ import 'commands.dart';
enum
PosTextAlign
{
left
,
center
,
right
}
enum
PosTextAlign
{
left
,
center
,
right
}
enum
PosCutMode
{
normal
,
partial
,
full
}
enum
PosCutMode
{
normal
,
partial
,
full
}
enum
PosFontType
{
fontA
,
fontB
}
class
PosTextSize
{
class
PosTextSize
{
final
int
value
;
final
int
value
;
...
@@ -21,6 +22,20 @@ class PosTextSize {
...
@@ -21,6 +22,20 @@ class PosTextSize {
16
*
(
width
.
value
-
1
)
+
(
height
.
value
-
1
);
16
*
(
width
.
value
-
1
)
+
(
height
.
value
-
1
);
}
}
class
PosBeepDuration
{
final
int
value
;
const
PosBeepDuration
.
_internal
(
this
.
value
);
static
const
beep50ms
=
const
PosBeepDuration
.
_internal
(
1
);
static
const
beep100ms
=
const
PosBeepDuration
.
_internal
(
2
);
static
const
beep150ms
=
const
PosBeepDuration
.
_internal
(
3
);
static
const
beep200ms
=
const
PosBeepDuration
.
_internal
(
4
);
static
const
beep250ms
=
const
PosBeepDuration
.
_internal
(
5
);
static
const
beep300ms
=
const
PosBeepDuration
.
_internal
(
6
);
static
const
beep350ms
=
const
PosBeepDuration
.
_internal
(
7
);
static
const
beep400ms
=
const
PosBeepDuration
.
_internal
(
8
);
static
const
beep450ms
=
const
PosBeepDuration
.
_internal
(
9
);
}
/// Abstract printer.
/// Abstract printer.
class
Printer
{
class
Printer
{
Printer
(
this
.
_socket
)
{
Printer
(
this
.
_socket
)
{
...
@@ -66,6 +81,7 @@ class Printer {
...
@@ -66,6 +81,7 @@ class Printer {
PosTextAlign
align
=
PosTextAlign
.
left
,
PosTextAlign
align
=
PosTextAlign
.
left
,
PosTextSize
height
=
PosTextSize
.
size1
,
PosTextSize
height
=
PosTextSize
.
size1
,
PosTextSize
width
=
PosTextSize
.
size1
,
PosTextSize
width
=
PosTextSize
.
size1
,
PosFontType
fontType
=
PosFontType
.
fontA
,
int
linesAfter
=
0
,
int
linesAfter
=
0
,
})
{
})
{
_socket
.
write
(
bold
?
cBoldOn
:
cBoldOff
);
_socket
.
write
(
bold
?
cBoldOn
:
cBoldOff
);
...
@@ -74,7 +90,7 @@ class Printer {
...
@@ -74,7 +90,7 @@ class Printer {
_socket
.
write
(
align
==
PosTextAlign
.
left
_socket
.
write
(
align
==
PosTextAlign
.
left
?
cAlignLeft
?
cAlignLeft
:
(
align
==
PosTextAlign
.
center
?
cAlignCenter
:
cAlignRight
));
:
(
align
==
PosTextAlign
.
center
?
cAlignCenter
:
cAlignRight
));
_socket
.
write
(
fontType
==
PosFontType
.
fontA
?
cFontA
:
cFontB
);
// Text size
// Text size
_socket
.
add
(
_socket
.
add
(
Uint8List
.
fromList
(
Uint8List
.
fromList
(
...
@@ -87,6 +103,26 @@ class Printer {
...
@@ -87,6 +103,26 @@ class Printer {
reset
();
reset
();
}
}
void
beep
(
{
int
count
=
3
,
PosBeepDuration
duration
=
PosBeepDuration
.
beep450ms
})
{
if
(
count
<=
0
)
{
return
;
}
int
beepCount
=
count
;
if
(
beepCount
>
9
)
{
beepCount
=
9
;
}
_socket
.
add
(
Uint8List
.
fromList
(
List
.
from
(
cBeep
.
codeUnits
)..
addAll
([
beepCount
,
duration
.
value
]),
),
);
beep
(
count:
count
-
9
,
duration:
duration
);
}
void
reset
()
{
void
reset
()
{
_socket
.
write
(
cInit
);
_socket
.
write
(
cInit
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment