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
db0da480
Commit
db0da480
authored
Jun 12, 2019
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Revert "Added documentstion""
This reverts commit
76899b33
.
parent
76899b33
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
86 additions
and
11 deletions
+86
-11
esc_pos_printer.dart
lib/esc_pos_printer.dart
+1
-1
commands.dart
lib/src/commands.dart
+8
-0
enums.dart
lib/src/enums.dart
+8
-0
exceptions.dart
lib/src/exceptions.dart
+9
-0
pos_string.dart
lib/src/pos_string.dart
+9
-0
printer.dart
lib/src/printer.dart
+47
-6
pubspec.yaml
pubspec.yaml
+4
-4
No files found.
lib/esc_pos_printer.dart
View file @
db0da480
/*
/*
* esc_pos_printer
* esc_pos_printer
* Created by Andrey U
* Created by Andrey U
shakov
*
*
* See LICENSE for distribution and usage details.
* See LICENSE for distribution and usage details.
*/
*/
...
...
lib/src/commands.dart
View file @
db0da480
/*
* esc_pos_printer
* Created by Andrey Ushakov
*
* Copyright (c) 2019. All rights reserved.
* See LICENSE for distribution and usage details.
*/
const
esc
=
'
\
x1B'
;
const
esc
=
'
\
x1B'
;
const
gs
=
'
\
x1D'
;
const
gs
=
'
\
x1D'
;
...
...
lib/src/enums.dart
View file @
db0da480
/*
* esc_pos_printer
* Created by Andrey Ushakov
*
* Copyright (c) 2019. All rights reserved.
* See LICENSE for distribution and usage details.
*/
enum
PosTextAlign
{
left
,
center
,
right
}
enum
PosTextAlign
{
left
,
center
,
right
}
enum
PosCutMode
{
full
,
partial
}
enum
PosCutMode
{
full
,
partial
}
enum
PosFontType
{
fontA
,
fontB
}
enum
PosFontType
{
fontA
,
fontB
}
...
...
lib/src/exceptions.dart
View file @
db0da480
/*
* esc_pos_printer
* Created by Andrey Ushakov
*
* Copyright (c) 2019. All rights reserved.
* See LICENSE for distribution and usage details.
*/
/// Used by [Printer.printRow] method
class
PosRowException
implements
Exception
{
class
PosRowException
implements
Exception
{
PosRowException
(
this
.
_msg
);
PosRowException
(
this
.
_msg
);
String
_msg
;
String
_msg
;
...
...
lib/src/pos_string.dart
View file @
db0da480
/*
* esc_pos_printer
* Created by Andrey Ushakov
*
* Copyright (c) 2019. All rights reserved.
* See LICENSE for distribution and usage details.
*/
import
'enums.dart'
;
import
'enums.dart'
;
/// A string with styles
class
PosString
{
class
PosString
{
PosString
(
PosString
(
this
.
text
,
{
this
.
text
,
{
...
...
lib/src/printer.dart
View file @
db0da480
/*
* esc_pos_printer
* Created by Andrey Ushakov
*
* Copyright (c) 2019. All rights reserved.
* See LICENSE for distribution and usage details.
*/
import
'dart:io'
;
import
'dart:io'
;
import
'dart:typed_data'
;
import
'dart:typed_data'
;
import
'package:hex/hex.dart'
;
import
'package:hex/hex.dart'
;
...
@@ -30,7 +38,9 @@ class Printer {
...
@@ -30,7 +38,9 @@ class Printer {
_socket
.
destroy
();
_socket
.
destroy
();
}
}
/// colInd range: 0..11
/// Generic print for internal use
///
/// [colInd] range: 0..11
void
_print
(
PosString
data
,
{
int
colInd
=
0
,
int
linesAfter
=
0
})
{
void
_print
(
PosString
data
,
{
int
colInd
=
0
,
int
linesAfter
=
0
})
{
final
int
pos
=
colInd
==
0
?
0
:
(
512
*
colInd
/
11
-
1
).
round
();
final
int
pos
=
colInd
==
0
?
0
:
(
512
*
colInd
/
11
-
1
).
round
();
final
hexStr
=
pos
.
toRadixString
(
16
).
padLeft
(
3
,
'0'
);
final
hexStr
=
pos
.
toRadixString
(
16
).
padLeft
(
3
,
'0'
);
...
@@ -61,6 +71,7 @@ class Printer {
...
@@ -61,6 +71,7 @@ class Printer {
_socket
.
write
(
data
.
text
);
_socket
.
write
(
data
.
text
);
}
}
/// Prints one line of styled text
void
println
(
PosString
data
,
{
int
linesAfter
=
0
})
{
void
println
(
PosString
data
,
{
int
linesAfter
=
0
})
{
_print
(
data
,
linesAfter:
linesAfter
);
_print
(
data
,
linesAfter:
linesAfter
);
_socket
.
writeln
();
_socket
.
writeln
();
...
@@ -68,6 +79,23 @@ class Printer {
...
@@ -68,6 +79,23 @@ class Printer {
reset
();
reset
();
}
}
/// Print a row.
///
/// A row contains up to 12 columns. A column has a width between 1 and 12.
/// Total width of columns in one row must be equal 12.
///
/// [cols] parameter is used to define the row structure (each integer value is one column width).
/// [data] parameter is used to define the column data (text, align inside of the column and styles).
/// Column data is represented by [PosString] class.
///
/// ```dart
/// printer.printRow(
/// [3, 6, 3],
/// [ PosString('col3'),
/// PosString('col6'),
/// PosString('col3') ],
/// );
/// ```
void
printRow
(
List
<
int
>
cols
,
List
<
PosString
>
data
)
{
void
printRow
(
List
<
int
>
cols
,
List
<
PosString
>
data
)
{
final
validRange
=
cols
.
every
((
val
)
=>
val
>=
1
&&
val
<=
12
);
final
validRange
=
cols
.
every
((
val
)
=>
val
>=
1
&&
val
<=
12
);
if
(!
validRange
)
{
if
(!
validRange
)
{
...
@@ -90,13 +118,15 @@ class Printer {
...
@@ -90,13 +118,15 @@ class Printer {
reset
();
reset
();
}
}
void
beep
(
/// Beeps [n] times
{
int
count
=
3
,
PosBeepDuration
duration
=
PosBeepDuration
.
beep450ms
})
{
///
if
(
count
<=
0
)
{
/// Beep [duration] could be between 50 and 450 ms.
void
beep
({
int
n
=
3
,
PosBeepDuration
duration
=
PosBeepDuration
.
beep450ms
})
{
if
(
n
<=
0
)
{
return
;
return
;
}
}
int
beepCount
=
count
;
int
beepCount
=
n
;
if
(
beepCount
>
9
)
{
if
(
beepCount
>
9
)
{
beepCount
=
9
;
beepCount
=
9
;
}
}
...
@@ -107,19 +137,26 @@ class Printer {
...
@@ -107,19 +137,26 @@ class Printer {
),
),
);
);
beep
(
count:
count
-
9
,
duration:
duration
);
beep
(
n:
n
-
9
,
duration:
duration
);
}
}
/// Clear the buffer and reset text styles
void
reset
()
{
void
reset
()
{
_socket
.
write
(
cInit
);
_socket
.
write
(
cInit
);
}
}
/// Skips [n] lines
///
/// Similar to [feed] but uses an alternative command
void
emptyLines
(
int
n
)
{
void
emptyLines
(
int
n
)
{
if
(
n
>
0
)
{
if
(
n
>
0
)
{
_socket
.
write
(
List
.
filled
(
n
,
'
\n
'
).
join
());
_socket
.
write
(
List
.
filled
(
n
,
'
\n
'
).
join
());
}
}
}
}
/// Skips [n] lines
///
/// Similar to [emptyLines] but uses an alternative command
void
feed
(
int
n
)
{
void
feed
(
int
n
)
{
if
(
n
>=
0
&&
n
<=
255
)
{
if
(
n
>=
0
&&
n
<=
255
)
{
_socket
.
add
(
_socket
.
add
(
...
@@ -130,6 +167,7 @@ class Printer {
...
@@ -130,6 +167,7 @@ class Printer {
}
}
}
}
/// Reverse feed for [n] lines (if supported by the priner)
void
reverseFeed
(
int
n
)
{
void
reverseFeed
(
int
n
)
{
_socket
.
add
(
_socket
.
add
(
Uint8List
.
fromList
(
Uint8List
.
fromList
(
...
@@ -138,6 +176,9 @@ class Printer {
...
@@ -138,6 +176,9 @@ class Printer {
);
);
}
}
/// Cut the paper
///
/// [mode] is used to define the full or partial cut (if supported by the priner)
void
cut
({
PosCutMode
mode
=
PosCutMode
.
full
})
{
void
cut
({
PosCutMode
mode
=
PosCutMode
.
full
})
{
_socket
.
write
(
'
\n\n\n\n\n
'
);
_socket
.
write
(
'
\n\n\n\n\n
'
);
if
(
mode
==
PosCutMode
.
partial
)
{
if
(
mode
==
PosCutMode
.
partial
)
{
...
...
pubspec.yaml
View file @
db0da480
name
:
esc_pos_printer
name
:
esc_pos_printer
description
:
A new Flutter package projec
t.
description
:
ESC/POS (thermal, receipt) printing for Flutter & Dar
t.
version
:
0.
0.1
version
:
0.
9.0
author
:
author
:
Andrey Ushakov
homepage
:
homepage
:
https://github.com/andrey-ushakov/esc_pos_printer
environment
:
environment
:
sdk
:
"
>=2.1.0
<3.0.0"
sdk
:
"
>=2.1.0
<3.0.0"
...
...
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