Phonegap plugin for Star Micronics bluetooth/LAN printers. It works with Android and iOS
How to use :
-
Integrate the SDK into your project. Visit the Star Micronics developer section and follow the appropriate documentation.
-
Install the plugin:
cordova plugin add https://github.com/jhonylucas74/StarIOPlugin
If this not work. Try install plugin with --nofetch
flag.
window.plugins.starPrinter.portDiscovery('All', function(error, printerList){
if (error) {
console.error(error);
} else {
console.log(printerList[0].name);
console.log(printerList[0].macAddress);
}
});
Port types are: 'All', 'Bluetooth', 'USB', 'LAN'
window.plugins.starPrinter.checkStatus(portName, function(error, result){
if (error) {
console.error(error);
} else {
console.log(result.offline ? "printer is offline : "printer is online);
}
});
note: the function printreceipt
doesn't exists anymore. Now you need use Builder
To print a receipt you need create a builder with this code:
var builder = window.plugins.starPrinter.Builder({ width: 384 });
The width represent the paper width. With the instance of builder is possible now add commands.
builder.text("Hello world", {});
In example a text command was added in pipeline. the second argument is a object that represent a style of text. Below follow all the possible values.
size
:int
| size of text.font
:string
| font family:monospace
,sans serife
,serife
ordefault
.weight
:string
| weight of text:bold
,bold italic
,italic
ornormal
.align
:string
| align of text:center
,opposite
ornormal
.
Example with default configuration of style.
builder.text("Hello world", {
size: 15,
font: 'default',
weight: 'normal',
align: 'normal',
});
Full example with 3 lines:
window.plugins.starPrinter.Builder({ width: 384 })
.text("Hello world", {})
.text("This is a example", {})
.text("Say, good bye!", {})
.cutPaper()
.print(portName, function(err, result){
if (err) return console.log(err);
// code here...
});
Example with shared style:
var myStyle = {
size: 23,
weight: 'bold',
align: 'center'
};
window.plugins.starPrinter.Builder({ width: 384 })
.text("Title in center", myStyle)
.text("I'm center too", myStyle)
.text("all is center", myStyle)
.cutPaper()
.print(portName, function(err, result){
if (err) return console.log(err);
// code here...
});
Add a image to builder. The first input must be a base64 encoded image.
builder.image('data:image/jpg;base64, ....');
The second param is optional, but you can change the width anda the align when pass a style.
builder.image('data:image/jpg;base64, ....', {
align: 'center'
});
Style image options:
width
:int
| size of image.align
:string
| align of image:center
,left
orright
.
Cut the paper.
builder.cutPaper();
I'm not sure if this work with TSP100.
builder.openCashDrawer();
Finally for print, just call print
command.
builder.print(portName, function(error, result){
if (error) {
console.error(error);
} else {
console.log("printReceipt finished");
}
});
window.plugins.starPrinter.connect(portName, function(error, result){
if (error) {
console.error(error);
} else {
console.log("connect finished");
}
});
window.addEventListener('starIOPluginData', function (e) {
switch (e.dataType) {
case 'printerCoverOpen':
break;
case 'printerCoverClose':
break;
case 'printerImpossible':
break;
case 'printerOnline':
break;
case 'printerOffline':
break;
case 'printerPaperEmpty':
break;
case 'printerPaperNearEmpty':
break;
case 'printerPaperReady':
break;
case 'barcodeReaderConnect':
break;
case 'barcodeDataReceive':
break;
case 'barcodeReaderImpossible':
break;
case 'cashDrawerOpen':
break;
case 'cashDrawerClose':
break;
}
});
window.plugins.starPrinter.openCashDrawer(name, function(error, result){
if (error) {
console.error(error);
} else {
console.log("openCashDrawer finished");
}
});
Copyright (c) 2016 Interactive Object . Licensed under the MIT license.