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
836424f9
Commit
836424f9
authored
Jan 16, 2020
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bluetooth manager : using PosPrintResult for error handling.
parent
78cbb375
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
16 deletions
+22
-16
enums.dart
lib/src/enums.dart
+6
-0
printer_bluetooth_manager.dart
lib/src/printer_bluetooth_manager.dart
+16
-16
No files found.
lib/src/enums.dart
View file @
836424f9
...
...
@@ -17,6 +17,8 @@ class PosPrintResult {
static
const
timeout
=
PosPrintResult
.
_internal
(
2
);
static
const
printerNotSelected
=
PosPrintResult
.
_internal
(
3
);
static
const
ticketEmpty
=
PosPrintResult
.
_internal
(
4
);
static
const
printInProgress
=
PosPrintResult
.
_internal
(
5
);
static
const
scanInProgress
=
PosPrintResult
.
_internal
(
6
);
static
String
msg
(
PosPrintResult
val
)
{
if
(
val
==
PosPrintResult
.
success
)
{
...
...
@@ -27,6 +29,10 @@ class PosPrintResult {
return
'Error. Printer not selected'
;
}
else
if
(
val
==
PosPrintResult
.
ticketEmpty
)
{
return
'Error. Ticket is empty'
;
}
else
if
(
val
==
PosPrintResult
.
printInProgress
)
{
return
'Error. Another print in progress'
;
}
else
if
(
val
==
PosPrintResult
.
scanInProgress
)
{
return
'Error. Printer scanning in progress'
;
}
else
{
return
'Unknown error'
;
}
...
...
lib/src/printer_bluetooth_manager.dart
View file @
836424f9
...
...
@@ -69,16 +69,16 @@ class PrinterBluetoothManager {
_selectedPrinter
=
printer
;
}
Future
<
void
>
writeBytes
(
List
<
int
>
bytes
)
async
{
Future
<
PosPrintResult
>
writeBytes
(
List
<
int
>
bytes
)
async
{
final
Completer
<
PosPrintResult
>
completer
=
Completer
();
const
int
timeout
=
5
;
if
(
_selectedPrinter
==
null
)
{
throw
Exception
(
'Print failed (Select a printer first)'
);
}
if
(
_isScanning
.
value
)
{
throw
Exception
(
'Print failed (scanning in progress)'
);
}
if
(
_isPrinting
)
{
throw
Exception
(
'Print failed (another printing in progress)'
);
return
Future
<
PosPrintResult
>.
value
(
PosPrintResult
.
printerNotSelected
);
}
else
if
(
_isScanning
.
value
)
{
return
Future
<
PosPrintResult
>.
value
(
PosPrintResult
.
scanInProgress
);
}
else
if
(
_isPrinting
)
{
return
Future
<
PosPrintResult
>.
value
(
PosPrintResult
.
printInProgress
);
}
_isPrinting
=
true
;
...
...
@@ -97,7 +97,7 @@ class PrinterBluetoothManager {
// To avoid double call
if
(!
_isConnected
)
{
await
_bluetoothManager
.
writeData
(
bytes
);
// TODO Notify data sent
completer
.
complete
(
PosPrintResult
.
success
);
}
// TODO sending disconnect signal should be event-based
_runDelayed
(
3
).
then
((
dynamic
v
)
async
{
...
...
@@ -118,17 +118,17 @@ class PrinterBluetoothManager {
_runDelayed
(
timeout
).
then
((
dynamic
v
)
async
{
if
(
_isPrinting
)
{
_isPrinting
=
false
;
throw
Exception
(
'Print failed (timeout)'
);
completer
.
complete
(
PosPrintResult
.
timeout
);
}
});
return
completer
.
future
;
}
Future
<
void
>
printTicket
(
Ticket
ticket
)
async
{
if
(
ticket
!=
null
&&
ticket
.
bytes
.
isNotEmpty
)
{
final
Future
<
void
>
res
=
writeBytes
(
ticket
.
bytes
);
return
res
;
}
else
{
throw
Exception
(
'Print failed (ticket is empty)'
);
Future
<
PosPrintResult
>
printTicket
(
Ticket
ticket
)
async
{
if
(
ticket
==
null
||
ticket
.
bytes
.
isEmpty
)
{
return
Future
<
PosPrintResult
>.
value
(
PosPrintResult
.
ticketEmpty
);
}
return
writeBytes
(
ticket
.
bytes
);
}
}
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