Starprnt
Cordova plugin for the Star micronics printers
Install / Use
/learn @auctifera-josed/StarprntREADME
StarPRNT Plugin
Cordova plugin for using Star micronics printers from a cordova, phonegap or Ionic application.
React Native Version ➜ here
Note: This is based on the work from the guys at InteractiveObject
This plugin defines global starprnt object.
Although in the global scope, it is not available until after the deviceready event.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(starprnt);
}
Example
Ionic 1 example app: https://github.com/infoxicator/StarprntDemo-Ionic1
Ionic 2/3 example app: https://github.com/infoxicator/StarprnDemoIonicV2
Install
Cordova: cordova plugin add cordova-plugin-starprnt
Github: cordova plugin add https://github.com/auctifera-josed/starprnt
Warning: when updating you should run first ionic cordova plugin rm cordova-plugin-starprnt and then install again
Example
starprnt.portDiscovery('All', function(result) {
console.log(result);
},
function(error){
console.log(error);
});
Success Log Example: console[{modelName: "TSP700II", macAddress: "00:00:00:00", portName: "TCP:192.168.1.1"}]
SMPort Example
SMPort opens the connection to the printer and closes it after the commands are successfully sent.
printObj = {
text:"Star Clothing Boutique\n123 Star Road\nCity, State 12345\n\n",
cutReceipt:"true",
openCashDrawer: "true"
}
starprnt.printRawText("TCP:192.168.1.1","StarLine", printObj, function(result){
console.log(result);
},
function(error) {
console.log(error);
});
StarIOExtManager Example
StarIOExtManager Allows you to connect to the printer and listen for hardware events, you will need to manually open and close the connection.
starprnt.connect("TCP:192.168.1.1","StarLine", function(err,res) {});
printObj = {
text:"Star Clothing Boutique\n123 Star Road\nCity, State 12345\n\n",
cutReceipt:"true",
openCashDrawer: "true"
}
/*Send null to use a printer connected via StarIOExtManager using the connect() function*/
starprnt.printRawText(null, "StarLine", printObj, function (result) {
console.log(result);
},
function(error){
console.log(error);
});
Printing Special Characters ( £, € )
To print special characters using the print() function, select the correct Encoding, CodePageType and International then send the bytes using the appendBytes command.
Pound Sign (£) Example
var commands = [];
commands.push({appendCodePage:'CP858'});
commands.push({appendEncoding:'US-ASCII'});
commands.push({appendInternational: 'UK'});
commands.push({appendBytes:[0x9c]});
starprnt.print("TCP:192.168.1.1","StarLine", commands, function(result) {
console.log(result);
},
function(error){
console.log(error);
});
Euro Sign (€) Example
var commands = [];
commands.push({appendCodePage:'CP858'});
commands.push({appendEncoding:'Windows-1252'});
commands.push({appendInternational: 'Spain'});
commands.push({appendBytes:[0xd5]});
starprnt.print("TCP:192.168.1.1","StarLine", commands, function(result) {
console.log(result);
}, function(error) {
console.log(error);
});
API Reference
- portDiscovery(type, success, error)
- checkStatus(port, emulation, success, error)
- printRawText(port, emulation, printObj, success, error)
- printRasterReceipt(port, emulation, rasterObj, success, error)
- printImage(port, emulation, imageObj, success, error)
- printBase64Image(port, emulation, imageObj, success, error)
- print(port, emulation, commandArray, success, error)
- connect(port, emulation, hasBarcodeReader, callback)
- disconnect(success, error)
- openCashDrawer(port, emulation, success, error)
Events
PrintCommand
List of commands available through the print() function
PrintCommand Constants
- InternationalType
- FontStyleType
- CutPaperAction
- BlackMarkType
- LogoSize
- AlignmentPosition
- BarcodeSymbology
- BarcodeWidth
- QrCodeModel
- QrCodeLevel
- BitmapConverterRotation
Functions
Almost all the methods take success an error functions as parameters, these are callback functions to execute in either case. They are not listed in the parameters for simplicity.
Note: asterisk (*) indicates a required parameter
Port discovery
The portDiscovery(type, success, error) Find available printers
| Paremeter | Description | Type/Example | | ----------- | -------- | ---------- | | type* | Port types are: 'All', 'Bluetooth', 'USB', 'LAN' | String |
Check Status
The checkStatus(port, emulation, success, error) returns the current status of the printer, as well as model number and firmware information. Checking status of a printer while connected to that printer can produce unexpected results.
| Paremeter | Description | Type/Example | | ----------- | -------- | ---------- | | port* | Printer port name i.e BT:StarMicronics | String: "TCP:192.168.1.1" | | emulation* | Emulation type depending on the printer model | String: Emulation |
Print Raw Text
The printRawText(port, emulation, printObj, success, error) Prints plain text and command
| Paremeter | Description | Type/Example | | ----------- | -------- | ---------- | | port* | Printer port name i.e BT:StarMicronics. Send null to use a printer connected via StarIOExtManager using the connect() function | String: "TCP:192.168.1.1" | | emulation* | Emulation type depending on the printer model | String: Emulation | | printObj* | Object containing the text and printer options | Object: Example Below |
var printObj = {
text:"Star Clothing Boutique\n123 Star Road\nCity, State 12345\n\n",
cutReceipt:true, // optional - Defaults to true
openCashDrawer:true // optional -Defaults to true
}
Print Raster Receipt
The printRasterReceipt(port, emulation, rasterObj, success, error) Converts the text into a bitmap image and sends it to the printer
| Paremeter | Description | Type/Example | | ----------- | -------- | ---------- | | port* | Printer port name i.e BT:StarMicronics. Send null to use a printer connected via StarIOExtManager using the connect() function | String: "TCP:192.168.1.1" | | emulation* | Emulation type depending on the printer model | String: Emulation | | rasterObj* | Object containing the text and printer options | Object: Example Below |
var rasterObj = {
text : " Star Clothing Boutique\n" +
" 123 Star Road\n" +
" City, State 12345\n" +
"\n" +
"Date:MM/DD/YYYY Time:HH:MM PM\n" +
"--------------------------------------\n" +
"SALE\n" +
"SKU Description Total\n" +
"300678566 PLAIN T-SHIRT 10.99\n" +
"300692003 BLACK DENIM 29.99\n" +
"300651148 BLUE DENIM 29.99\n" +
"300642980 STRIPED DRESS 49.99\n" +
"30063847 BLACK BOOTS 35.99\n" +
"\n" +
"Subtotal 156.95\n" +
"Tax 0.00\n" +
"--------------------------------------\n" +
"Total $156.95\n" +
"--------------------------------------\n" +
"\n" +
"Charge\n" +
"156.95\n" +
"Visa XXXX-XXXX-XXXX-0123\n" +
"Refunds and Exchanges\n" +
"Within 30 days with receipt\n" +
"And tags attached\n",
fontSize: 25, //Defaults to 25
paperWidth: 576, // options: 384 = 2", 576 = 3", 832 = 4"
cutReceipt:true, // Defaults to true
openCashDrawer:true // Defaults to true
};
Print Image
The printImage(port, emulation, imageObj, success, error) prints a picture from the photo library or camera, Gets an image from a string URI and converts it to bitmap to send it to the printer.
| Paremeter | Description | Type/Example | | ----------- | -------- | ---------- | | port* | Printer port name i.e BT:StarMicronics. Send null to use a printer connected via StarIOExtManager using the connect() function | String: "TCP:192.168.1.1" | | emulation* | Emulation type depending on the printer model | String: Emulation | | imageObj* | Object containing the URI and printer options | Object: Example Below |
var imageObj = {
uri: 'file:///var/mobile/Containers/Data/Application/1B4B8C4C-6487-45AB-B950-0AC3633542F5/tmp/cdv_photo_002.jpg',
width: 576 // options: 384 = 2", 576 = 3", 832 = 4"
cutReceipt:true, // Defaults to true
openCashDrawer:true // Defaults to true
};
Print Base64 Image
Note: The base64 option was originally left out because of performance concerns. The preferred option is using images stored in the phone
