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
35f1a446
Commit
35f1a446
authored
Jun 12, 2019
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added height/width size. Added cut mode. Fixed feed and reverse feed bugs.
parent
2d8cc467
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
20 deletions
+48
-20
example.dart
example/example.dart
+5
-3
commands.dart
lib/src/commands.dart
+2
-1
printer.dart
lib/src/printer.dart
+41
-16
No files found.
example/example.dart
View file @
35f1a446
import
'package:esc_pos_printer/esc_pos_printer.dart'
;
import
'package:esc_pos_printer/src/printer.dart'
;
main
()
{
Printer
.
connect
(
'192.168.0.123'
).
then
((
printer
)
{
printer
.
reset
();
printer
.
println
(
'Normal text'
);
printer
.
println
(
'Bold text'
,
bold:
true
);
printer
.
println
(
'Reverse text'
,
reverse:
true
);
printer
.
println
(
'Underlined text'
,
underline:
true
);
printer
.
println
(
'Align left'
,
align:
TextAlign
.
left
);
printer
.
println
(
'Align center'
,
align:
TextAlign
.
center
);
printer
.
println
(
'Align right'
,
align:
TextAlign
.
right
);
printer
.
println
(
'Align left'
,
align:
Pos
TextAlign
.
left
);
printer
.
println
(
'Align center'
,
align:
Pos
TextAlign
.
center
);
printer
.
println
(
'Align right'
,
align:
Pos
TextAlign
.
right
);
printer
.
cut
();
...
...
lib/src/commands.dart
View file @
35f1a446
...
...
@@ -12,7 +12,8 @@ const cCutPart = '${esc}m'; // Execute paper partial cut.
// Character
const
cReverseOn
=
'
${gs}
B1'
;
// Turn white/black reverse print mode on
const
cReverseOff
=
'
${gs}
B0'
;
// Turn white/black reverse print mode off
const
cSizeN
=
'
$gs
!'
;
// Select character size [N]
const
cSizeGSn
=
'
$gs
!'
;
// Select character size [N]
const
cSizeESCn
=
'
$esc
!'
;
// Select character size [N]
const
cUnderlineOff
=
'
$esc
-0'
;
// Turns off underline mode
const
cUnderline1dot
=
'
$esc
-1'
;
// Turns on underline mode (1-dot thick)
const
cUnderline2dots
=
'
$esc
-2'
;
// Turns on underline mode (2-dots thick)
...
...
lib/src/printer.dart
View file @
35f1a446
import
'dart:io'
;
import
'dart:typed_data'
;
import
'commands.dart'
;
enum
TextAlign
{
left
,
center
,
right
}
enum
CutMode
{
normal
,
partial
,
full
}
enum
PosTextAlign
{
left
,
center
,
right
}
enum
PosCutMode
{
normal
,
partial
,
full
}
class
PosTextSizeHeight
{
final
value
;
const
PosTextSizeHeight
.
_internal
(
this
.
value
);
static
const
normal
=
const
PosTextSizeHeight
.
_internal
(
0x00
);
static
const
double
=
const
PosTextSizeHeight
.
_internal
(
0x10
);
}
class
PosTextSizeWidth
{
final
value
;
const
PosTextSizeWidth
.
_internal
(
this
.
value
);
static
const
normal
=
const
PosTextSizeWidth
.
_internal
(
0x00
);
static
const
double
=
const
PosTextSizeWidth
.
_internal
(
0x20
);
}
/// Abstract printer.
class
Printer
{
...
...
@@ -46,22 +61,24 @@ class Printer {
bool
bold
=
false
,
bool
reverse
=
false
,
bool
underline
=
false
,
TextAlign
align
=
TextAlign
.
left
,
int
charHeight
=
-
1
,
// TODO replace by font size
int
charWidth
=
-
1
,
PosTextAlign
align
=
Pos
TextAlign
.
left
,
PosTextSizeHeight
height
=
PosTextSizeHeight
.
normal
,
PosTextSizeWidth
width
=
PosTextSizeWidth
.
normal
,
int
linesAfter
=
0
,
})
{
_socket
.
write
(
bold
?
cBoldOn
:
cBoldOff
);
_socket
.
write
(
reverse
?
cReverseOn
:
cReverseOff
);
_socket
.
write
(
underline
?
cUnderline1dot
:
cUnderlineOff
);
_socket
.
write
(
align
==
TextAlign
.
left
_socket
.
write
(
align
==
Pos
TextAlign
.
left
?
cAlignLeft
:
(
align
==
TextAlign
.
center
?
cAlignCenter
:
cAlignRight
));
:
(
align
==
Pos
TextAlign
.
center
?
cAlignCenter
:
cAlignRight
));
if
(
charHeight
>
0
&&
charWidth
>
0
)
{
var
n
=
16
*
(
charWidth
-
1
)
+
(
charHeight
-
1
);
_socket
.
writeAll
([
cSizeN
,
n
]);
}
// Font size
_socket
.
add
(
Uint8List
.
fromList
(
List
.
from
(
cSizeESCn
.
codeUnits
)..
add
(
height
.
value
+
width
.
value
),
),
);
_socket
.
writeln
(
text
);
emptyLines
(
linesAfter
);
...
...
@@ -80,19 +97,27 @@ class Printer {
void
feed
(
int
n
)
{
if
(
n
>=
0
&&
n
<=
255
)
{
_socket
.
writeAll
([
cFeedN
,
n
.
toString
()]);
_socket
.
add
(
Uint8List
.
fromList
(
List
.
from
(
cFeedN
.
codeUnits
)..
add
(
n
),
),
);
}
}
void
reverseFeed
(
int
n
)
{
_socket
.
writeAll
([
cReverseFeedN
,
n
.
toString
()]);
_socket
.
add
(
Uint8List
.
fromList
(
List
.
from
(
cReverseFeedN
.
codeUnits
)..
add
(
n
),
),
);
}
void
cut
({
CutMode
mode
=
CutMode
.
normal
})
{
void
cut
({
PosCutMode
mode
=
Pos
CutMode
.
normal
})
{
_socket
.
write
(
'
\n\n\n\n\n
'
);
if
(
mode
==
CutMode
.
partial
)
{
if
(
mode
==
Pos
CutMode
.
partial
)
{
_socket
.
write
(
cCutPart
);
}
else
if
(
mode
==
CutMode
.
full
)
{
}
else
if
(
mode
==
Pos
CutMode
.
full
)
{
_socket
.
write
(
cCutFull
);
}
else
{
_socket
.
write
(
cCut
);
...
...
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