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
3f4b0782
Commit
3f4b0782
authored
Jul 04, 2019
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added code pages support
parent
ade19f67
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
9 deletions
+50
-9
commands.dart
lib/src/commands.dart
+2
-0
pos_styles.dart
lib/src/pos_styles.dart
+2
-0
printer.dart
lib/src/printer.dart
+46
-9
No files found.
lib/src/commands.dart
View file @
3f4b0782
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
const
esc
=
'
\
x1B'
;
const
esc
=
'
\
x1B'
;
const
gs
=
'
\
x1D'
;
const
gs
=
'
\
x1D'
;
const
fs
=
'
\
x1C'
;
// Miscellaneous
// Miscellaneous
const
cInit
=
'
$esc
@'
;
// Initialize printer
const
cInit
=
'
$esc
@'
;
// Initialize printer
...
@@ -32,6 +33,7 @@ const cFontB = '${esc}M1'; // Font B
...
@@ -32,6 +33,7 @@ const cFontB = '${esc}M1'; // Font B
const
cTurn90On
=
'
${esc}
V1'
;
// Turn 90° clockwise rotation mode on
const
cTurn90On
=
'
${esc}
V1'
;
// Turn 90° clockwise rotation mode on
const
cTurn90Off
=
'
${esc}
V0'
;
// Turn 90° clockwise rotation mode off
const
cTurn90Off
=
'
${esc}
V0'
;
// Turn 90° clockwise rotation mode off
const
cCodeTable
=
'
${esc}
t'
;
// Select character code table [N]
const
cCodeTable
=
'
${esc}
t'
;
// Select character code table [N]
const
cKanjiCancel
=
'
$fs
.'
;
// Cancel Kanji character mode
// Print Position
// Print Position
const
cAlignLeft
=
'
${esc}
a0'
;
// Left justification
const
cAlignLeft
=
'
${esc}
a0'
;
// Left justification
...
...
lib/src/pos_styles.dart
View file @
3f4b0782
...
@@ -19,6 +19,7 @@ class PosStyles {
...
@@ -19,6 +19,7 @@ class PosStyles {
this
.
height
=
PosTextSize
.
size1
,
this
.
height
=
PosTextSize
.
size1
,
this
.
width
=
PosTextSize
.
size1
,
this
.
width
=
PosTextSize
.
size1
,
this
.
fontType
=
PosFontType
.
fontA
,
this
.
fontType
=
PosFontType
.
fontA
,
this
.
codeTable
,
});
});
final
bool
bold
;
final
bool
bold
;
...
@@ -29,4 +30,5 @@ class PosStyles {
...
@@ -29,4 +30,5 @@ class PosStyles {
final
PosTextSize
height
;
final
PosTextSize
height
;
final
PosTextSize
width
;
final
PosTextSize
width
;
final
PosFontType
fontType
;
final
PosFontType
fontType
;
final
PosCodeTable
codeTable
;
}
}
lib/src/printer.dart
View file @
3f4b0782
...
@@ -21,7 +21,7 @@ class Printer {
...
@@ -21,7 +21,7 @@ class Printer {
}
}
final
Socket
_socket
;
final
Socket
_socket
;
PosCodeTable
_codeTable
=
PosCodeTable
.
pc437
;
PosCodeTable
_codeTable
;
/// Creates a new socket connection to the network printer.
/// Creates a new socket connection to the network printer.
///
///
...
@@ -42,14 +42,17 @@ class Printer {
...
@@ -42,14 +42,17 @@ class Printer {
_socket
.
destroy
();
_socket
.
destroy
();
}
}
void
setCodeTable
(
PosCodeTable
codeTable
)
{
/// Set global code table which will be used instead of the default printer's code table
void
setGlobalCodeTable
(
PosCodeTable
codeTable
)
{
_codeTable
=
codeTable
;
_codeTable
=
codeTable
;
if
(
codeTable
!=
null
)
{
_socket
.
add
(
_socket
.
add
(
Uint8List
.
fromList
(
Uint8List
.
fromList
(
List
.
from
(
cCodeTable
.
codeUnits
)..
add
(
codeTable
.
value
),
List
.
from
(
cCodeTable
.
codeUnits
)..
add
(
codeTable
.
value
),
),
),
);
);
}
}
}
/// Generic print for internal use
/// Generic print for internal use
///
///
...
@@ -63,7 +66,6 @@ class Printer {
...
@@ -63,7 +66,6 @@ class Printer {
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'
);
final
hexPair
=
HEX
.
decode
(
hexStr
);
final
hexPair
=
HEX
.
decode
(
hexStr
);
// print('dec: $pos \t hex: $hexStr \t pair $hexPair');
_socket
.
write
(
styles
.
bold
?
cBoldOn
:
cBoldOff
);
_socket
.
write
(
styles
.
bold
?
cBoldOn
:
cBoldOff
);
_socket
.
write
(
styles
.
turn90
?
cTurn90On
:
cTurn90Off
);
_socket
.
write
(
styles
.
turn90
?
cTurn90On
:
cTurn90Off
);
...
@@ -87,7 +89,16 @@ class Printer {
...
@@ -87,7 +89,16 @@ class Printer {
),
),
);
);
_socket
.
write
(
cKanjiCancel
);
if
(
styles
.
codeTable
!=
null
)
{
_socket
.
add
(
Uint8List
.
fromList
(
List
.
from
(
cCodeTable
.
codeUnits
)..
add
(
styles
.
codeTable
.
value
),
),
);
}
_socket
.
write
(
text
);
_socket
.
write
(
text
);
// TOOD Kanji set
}
}
/// Sens raw command(s)
/// Sens raw command(s)
...
@@ -107,6 +118,32 @@ class Printer {
...
@@ -107,6 +118,32 @@ class Printer {
reset
();
reset
();
}
}
/// Print selected code table.
///
/// If [codeTable] is null, global code table is used.
/// If global code table is null, default printer code table is used.
void
printCodeTable
({
PosCodeTable
codeTable
})
{
_socket
.
write
(
cKanjiCancel
);
if
(
codeTable
!=
null
)
{
_socket
.
add
(
Uint8List
.
fromList
(
List
.
from
(
cCodeTable
.
codeUnits
)..
add
(
codeTable
.
value
),
),
);
}
final
List
<
int
>
list
=
[];
for
(
int
i
=
0
;
i
<
256
;
i
++)
{
list
.
add
(
i
);
}
_socket
.
add
(
Uint8List
.
fromList
(
List
.
from
(
list
)),
);
reset
();
}
/// Print a row.
/// Print a row.
///
///
/// A row contains up to 12 columns. A column has a width between 1 and 12.
/// A row contains up to 12 columns. A column has a width between 1 and 12.
...
@@ -152,7 +189,7 @@ class Printer {
...
@@ -152,7 +189,7 @@ class Printer {
/// Clear the buffer and reset text styles
/// Clear the buffer and reset text styles
void
reset
()
{
void
reset
()
{
_socket
.
write
(
cInit
);
_socket
.
write
(
cInit
);
setCodeTable
(
_codeTable
);
set
Global
CodeTable
(
_codeTable
);
}
}
/// Skips [n] lines
/// Skips [n] lines
...
...
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