Code Monkey home page Code Monkey logo

nativescript-star-printer's Introduction

NativeScript Star Printer

NPM version Downloads Twitter Follow

That's the demo app in action, printing on a Star Micronics TSP650II

Installation

For NativeScript 7+, please use plugin version 4+

tns plugin add nativescript-star-printer

API

requiring / importing the plugin

All examples below assume you're using TypeScript, but here's how to require the plugin with plain old JS as well:

JavaScript

var StarPrinterPlugin = require("nativescript-star-printer");
var starPrinter = new StarPrinterPlugin.StarPrinter();

TypeScript

import { StarPrinter, SPPrinter, SPCommands } from "nativescript-star-printer";

export Class MyPrintingClass {
  private starPrinter: StarPrinter;
  
  constructor() {
    this.starPrinter = new StarPrinter();
  }
}

searchPrinters

If you're searching for a Bluetooth printer, enable Bluetooth in the device settings and pair/connect the printer. Then do:

this.starPrinter.searchPrinters().then(
    (printers: Array<SPPrinter>) => {
      console.log(`Found ${printers.length} printers`);
    }, (err: string) => {
      console.log(`Search printers error: ${err}`);
    });

The most useful property on the SPPrinter class is the portName which you will need in other API methods.

The only other property is modelName.

connect

Once you know the printer port name, you can connect to it.

Note that there's no need to connect if you want to print as the print function does this automatically.

this.starPrinter.connect({
  portName: thePortName
}).then((result: SPPrinterStatusResult) => console.log("Connected: " + result.connected));

getPrinterStatus

After connecting to a printer, you can use this method to poll for the 'online' and 'paper' statuses.

this.starPrinter.getPrinterStatus({
  portName: this.lastConnectedPrinterPort
}).then(result => {
  const online: boolean = result.online;
  const onlineStatus: PrinterOnlineStatus = result.onlineStatus;
  const paperStatus: PrinterPaperStatus = result.paperStatus;
});

print

Once you've got the port of the printer you want to print to, just do:

this.starPrinter.print({
  portName: this.selectedPrinterPort,
  commands: commands
});

So what are those commands? Let's recreate the fake receipt below to answer that (see the TypeScript definition for all options):

const image = ImageSource.fromFile("~/res/mww-logo.png");

// Note that a standard 3 inch roll is 48 characters wide - we use that knowledge for our "columns"
let commands = new SPCommands()
    .image(
        image,
        true, // diffuse
        true // align center (set to 'false' to align left)
     )
    // alternatively, you can use imagePositioned for a bit more control (on Android this behaves the same as 'image' though)
    .imagePositioned(
        image,
        80, // width
        20, // position
        true, // both scale
        true, // diffuse
        true // align center (set to 'false' to align left)
     )
    .alignCenter()
    .text("My Awesome Boutique").newLine()
    .text("In a shop near you").newLine()
    .setFont("smaller")
    .text("Planet Earth").newLine()
    .setFont("default")
    .newLine()
    .text("Date: 11/11/2017                   Time: 3:15 PM")
    .horizontalLine() // you can pass in the character and the nr of characters (use 48 for a 3" roll, 42 for a smaller one)
    .newLine()
    .textBold("SKU           Description                  Total").newLine()
    .text("300678566     Plain White Tee             €10.99").newLine()
    .text("300692003     Black Dénim                 €29.99").newLine()
    .text("300651148     Blue Denim                  €29.99").newLine()
    .newLine()
    .newLine()
    .barcode({
      type: "Code128",
      value: "12345678",
      width: "large",
      height: 60,
      appendEncodedValue: false
    })
    .newLine()
    .cutPaper();

this.starPrinter.print({
  portName: this.selectedPrinterPort,
  commands: commands
});

openCashDrawer

In case a cash drawer is connected via the UTP (network) connector of the Star printer, you can open the drawer from your code!

this.starPrinter.openCashDrawer({
  portName: this.selectedPrinterPort
});

iOS runtime permission reason

iOS 10+ requires a permission popup when connecting (the first) time to a Bluetooth peripheral explaining why it needs to connect.

You can provide your own reason by adding something like this to app/App_Resources/ios/Info.plist:

  <key>NSBluetoothPeripheralUsageDescription</key>
  <string>My reason justifying fooling around with your Bluetooth</string>

To not crash your app in case you forgot to provide the reason this plugin adds an empty reason to the .plist during build. This value gets overridden by anything you specified yourself. You're welcome.

Known limitations

On iOS you want to run this on a real device.

Future work

Possibly add more print formatting options.

nativescript-star-printer's People

Contributors

acrollet avatar eddyverbruggen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nativescript-star-printer's Issues

Add barcode printing support

Let's add support for printing Code128 barcodes. The SDK supports more types, but this seems like a decent start.

print image

Hello thank you for very useful plugins.

I am not sure about it's your issue
i am developing bluetooth pos terminal and i used your commands.
then i use with text it working perfect 👍
but image is not printing image.
Do you have any solution for me ?

NativeScript 7+ support not working

Getting the following error on ns core 8.0.3 when searching for printers:

(file:///data/data/no.okam.store/files/app/vendor.js:84383:43)
	at StarPrinter.searchPrinters(file:///data/data/no.okam.store/files/app/vendor.js:84382:16)
	at loadPrinters(file:///data/data/no.okam.store/files/app/bundle.js:6878:24)
	at invokeWithErrorHandling(file:///data/data/no.okam.store/files/app/vendor.js:90827:26)
	at invoker(file:///data/data/no.okam.store/files/app/vendor.js:91484:14)
	at _executeCallback(file:///data/data/no.okam.store/files/app/vendor.js:45898:27)
	at TapAndDoubleTapGestureListenerImpl._handleSingleTap(file:///data/data/no.okam.store/files/app/vendor.js:45641:17)
	at TapAndDoubleTapGestureListenerImpl.onSingleTapUp(file:///data/data/no.okam.store/files/app/vendor.js:45610:14)
	at androidOnTouchEvent(file:///data/data/no.okam.store/files/app/vendor.js:45832:41)
	at (file:///data/data/no.okam.store/files/app/vendor.js:39308:25)
	at handleGestureTouch(file:///data/data/no.okam.store/files/app/vendor.js:39307:18)
	at TouchListenerImpl.onTouch(file:///data/data/no.okam.store/files/app/vendor.js:39038:15)

This worked before updating from ns 6.5. I have "nativescript-star-printer": "^4.0.0 installed

Star SDK inclusion Legal?

You might want to double check the sdk agreement, I'm pretty sure that you are NOT allowed to distribute the Star SDK except in a compiled application. They don't really like you distributing something that they will be updating and having older copies out in the wild.

Loading class com.starmicronics.starioextension.s was unsuccessful

I have a very simple code on my page trying to use this plugin, but nothing is loaded.
I looked at other issues where this kind of message appears, but also nothing helped me to overcome this issue.
My project is running with NS 4.2 plus the 2.0 vue-cli-template and for Android only.

The only code I'm trying to execute is:

var StarPrinterPlugin = require("nativescript-star-printer");

methods: {
      printItem(item) {
            let commands = new StarPrinterPlugin .SPCommands()
               .text(this.$moment().format('DD/MM/YYYY h:mm a ')).newLine()
               .textBold(item.name).newLine()
               .newLine()
               .newLine()
               .newLine()
               .cutPaper();

            this.starPrinter.print({
               portName: this.printerPortName,
               commands: commands
            }); //The issue title error message happens after trying to execute this print method.
         }
},

mounted() {
         this.starPrinter = new StarPrinterPlugin.StarPrinter();
         console.log('Mounted: ', JSON.stringify(this.starPrinter)); // Prints and empty object '{}'
         this.starPrinter.searchPrinters().then(
            (printers) => {
               this.printerPortName = printers[0].portName;
               console.log('success!');
            }, (err) => {
               console.log(err);
            });

}

I really don't know what else I can do to resolve this issue.

Print Error

Hello, I followed the setup and I am able to execute mostly all starPrinter methods also was able to see portName but for some reason when I run print method I receive console issue. If you encounter this before please let me know.
My Source Code
`export class DriverComponent {
private starPrinter:StarPrinter;
public printers: ObservableArray = new ObservableArray();
public constructor() {
this.starPrinter = new StarPrinter();
}

ngOnInit() : void {
    Bluetooth.isBluetoothEnabled().then(
        (enable) => {
            if(!enable) {
                dialogs.alert("Bluetooth Error: Turn on Bluetooth");
            } else {
                dialogs.confirm({
                    title: "Test Print",
                    message: "Please setup device & printer pair before proceeding",
                    okButtonText: "Start Print",
                    cancelButtonText: "Cancel"
                }).then(res => {
                    this.starPrinter.searchPrinters().then(
                    (printers: Array<SPPrinter>) => {
                        this.printers.push(printers);
                        this.printReceipt();
                    });
                });
            }
        });
}

public printReceipt(): void {
     let cmds = new SPCommands();
        cmds.setFont("smaller")
        cmds.alignCenter()
        cmds.text("Hello World!").newLine()
        cmds.newLine()
        cmds.cutPaper();
        
     this.starPrinter.print({
            portName: this.printers.getItem(0).portName,
            commands: cmds
        }).then(res => {
            console.log(res);
        });
}

}`
Exception Message
_ERROR Error: Uncaught (in promise): Error: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
JS: com.starmicronics.stario.a.f(Unknown Source:232)
JS: com.starmicronics.stario.a.(Unknown Source:38)
JS: com.starmicronics.stario.StarIOPort.getPort(Unknown Source:211)
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116)
JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:996)
JS: com.tns.Runtime.callJSMethod(Runtime.java:983)
JS: com.tns.Runtime.callJSMethod(Runtime.java:967)
JS: com.tns.Runtime.callJSMethod(Runtime.java:959)
_

Star Printer - SMT300i Android Build

Hello Everyone,

I have a particular issue that happens once in a while. So I have this application which prints out automatically 3 receipts. It works perfect most of the time but users have experience were it stops printing. The current solution to fix this is as follows:

  • closing app
  • power off Bluetooth
  • power off printer
  • turn on printer
  • turn on Bluetooth
  • sign App again
  • Try print and this works

So this is a solution now but long term painful. If anyone has ideas that will be great. I have also tried the some of the methods to detect print state but no luck.

The gist of the code I am running below:
`
//somewhere in my constructor this exists
this.starPrinter = new StarPrinter();

//setup commands
const cmds = new SPCommands()
.image(
image,
true,
true
)
.newLine()
.setFont("default")
.textLargeBold("Lot Number: " + this.lot.lotID.toString())
.newLine()
.textBold("Printed Date: " + today.toLocaleString())
.newLine()
.newLine()
.barcode({
type: "Code128",
value: this.lot.lotID.toString(),
width: "large",
height: 60,
appendEncodedValue: false
})
.newLine()
.newLine()
.alignCenter()
.textBold("Receipt of Fruit Harvested").newLine()
.alignLeft();

//print receipt x3
this.starPrinter.print({
portName: this.portName,
commands: cmds
}).then((res) => {
if (this.copyCount < 3) {
this.copyCount = this.copyCount + 1;
this.onPrint();
} else {
this.isPrinting = false;
this.copyCount = 1;
this.starPrinter.disconnect({
portName: this.portName
});
}
}, (err) => {
this.logFileService.writeToFile(JSON.stringify(err));
dialogs.alert(this.errorMessage[1] + err);
});
`

no exported member 'AutofillType

Namespace '"C:/Development/Portal-Website/src/Andromeda.Portal.Website/ClientApp/node_modules/@nativescript/core/core-types/index".CoreTypes' has no exported member 'AutofillType

In the index.d.ts file AutofillType is showing compile error.
/**
* Gets or sets the autofill type.
*/
autofillType: CoreTypes.AutofillType;

Fail to Open Port with SM-L200

Hi!

I am having an issue with printing with my SM-L200. I can find the printer, get the port. I can also connect to the device (returns 'Connected: true').
But, when connecting, the other properties are

connected: true online: false onlineStatus: "UNKNOWN" paperStatus: "UNKNOWN"

And when trying to print, it returns "Fail to Open Port".

The printer is using low power bluetooth. In the SDK app the connection method is different from regular bluetooth. Could the be the reason?

Thanks!

Heyddi

does the plugin support usb thermal printer ?

Hello
thanks Eddy for the great job y're doing for nativescript developers. I am stuck, i want to connect my usb epson thermal printer with my tablet by using the nativescript-star-printer. It seems that the plugin doesn't support usb connectivity. when i use the searchPrinters function nothing appeared however the printer is properly conected to the android device(confirmed by a test print).
I really need help
Any suggestion will be welcome

Trouble with ethernet printer

I'm having trouble getting this demo app to work for an ethernet-connected star micronics printer. In the demo app when I click search printers, it correctly finds my printer port: TCP:192.168.1.47 and when I hit connect/reconnect it console logs Connected: true. However, when I click the print option nothing happens. I added a .then() and a .catch() to the print command and the .then() is being triggered and is just returning undefined so I'm not sure what's going wrong. I see in the ReadMe that it references bluetooth - does this plugin only work for bluetooth connections? I just figured it would work for ethernet since it's finding the printer and returning connected: true.

On another note, I know this printer works because I've been able to print from it using the star micronics TSP100III Utility app.

Which platform(s) does your issue occur on?

iOS

Please, provide the following version numbers that your issue occurs with:

CLI: 3.1.3
Cross-platform modules: 2.5.3
Runtime(s): 3.0.1
Plugin(s):
"dependencies": {
"nativescript-star-printer": "file:../src",
"nativescript-theme-core": "^1.0.2",
"nativescript-unit-test-runner": "^0.3.4",
"tns-core-modules": "^2.5.1"
},
"devDependencies": {
"babel-traverse": "6.12.0",
"babel-types": "6.11.1",
"babylon": "6.8.4",
"filewalker": "0.1.2",
"jasmine-core": "^2.5.2",
"karma": "^1.3.0",
"karma-jasmine": "^1.0.2",
"karma-nativescript-launcher": "^0.4.0",
"lazy": "1.0.11",
"nativescript-dev-typescript": "^0.3.7",
"typescript": "^2.1.0"
}
Please, tell us how to recreate the issue in as much detail as possible.

Running the sample demo on an iPad while attempting to print to a star micronics ethernet printer.

Is there any code involved?

I'm running the sample demo

Demo compiled successfully but runtime error in phone.

Hi,

Thanks for this. I have a problem running on a Pixel 2 XL.

The Demo app compiled and installed run as soon as it runs, it gives an error. I have copied it below, would you be able to help, please?

Is it because I have updated am using version 5? Please let me know if you require anything and I will get back ASAP.

Thanks again.

11-21 20:43:14.898 30872 30872 E AndroidRuntime: at com.tns.Runtime.callJSMethodNative(Native Method)
11-21 20:43:14.898 30872 30872 E AndroidRuntime: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
11-21 20:43:14.898 30872 30872 E AndroidRuntime: at com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
11-21 20:43:14.898 30872 30872 E AndroidRuntime: at com.tns.Runtime.callJSMethod(Runtime.java:970)
11-21 20:43:14.898 30872 30872 E AndroidRuntime: at com.tns.Runtime.callJSMethod(Runtime.java:954)
11-21 20:43:14.898 30872 30872 E AndroidRuntime: at com.tns.Runtime.callJSMethod(Runtime.java:946)
System.err: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.demo/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Failed to find module: "nativescript-star-printer", relative to: app/tns_modules/
System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2914)
System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3049)
System.err: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
System.err: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1809)
System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
System.err: at android.os.Looper.loop(Looper.java:193)
System.err: at android.app.ActivityThread.main(ActivityThread.java:6680)
System.err: at java.lang.reflect.Method.invoke(Native Method)
System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
System.err: Caused by: com.tns.NativeScriptException: Failed to find module: "nativescript-star-printer", relative to: app/tns_modules/
System.err: at com.tns.Module.resolvePathHelper(Module.java:146)
System.err: at com.tns.Module.resolvePath(Module.java:55)
System.err: at com.tns.Runtime.callJSMethodNative(Native Method)
System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:970)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:954)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:946)
System.err: at com.tns.NativeScriptActivity.onCreate(NativeScriptActivity.java:18)
System.err: at android.app.Activity.performCreate(Activity.java:7144)
System.err: at android.app.Activity.performCreate(Activity.java:7135)
System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2894)

eror print System.err: TypeError: SPCommands is not a constructor

help me, I'm not using a script. i use javascript core
This error when I do print

System.err: Calling js method onClick failed
System.err: TypeError: SPCommands is not a constructor
System.err:
System.err: StackTrace:
System.err: cetak(file:///app\print\print-page.js:37:0)
System.err: at push.../node_modules/@nativescript/core/data/observable/observable.js.Observable.notify(file:///node_modules@nativescript\core\data\observable\observable.js:110:0)
System.err: at push.../node_modules/@nativescript/core/data/observable/observable.js.Observable._emit(file:///node_modules@nativescript\core\data\observable\observable.js:127:0)
System.err: at ClickListenerImpl.onClick(file:///node_modules@nativescript\core\ui\button\button.js:29:0)
System.err: at com.tns.Runtime.callJSMethodNative(Native Method)
System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1286)
System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:1173)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1160)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1138)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1134)
System.err: at com.tns.gen.java.lang.Object_vendor_14846_32_ClickListenerImpl.onClick(Object_vendor_14846_32_ClickListenerImpl.java:18)
System.err: at android.view.View.performClick(View.java:6597)
System.err: at android.view.View.performClickInternal(View.java:6574)
System.err: at android.view.View.access$3100(View.java:778)
System.err: at android.view.View$PerformClick.run(View.java:25885)
System.err: at android.os.Handler.handleCallback(Handler.java:873)
System.err: at android.os.Handler.dispatchMessage(Handler.java:99)
System.err: at android.os.Looper.loop(Looper.java:193)
System.err: at android.app.ActivityThread.main(ActivityThread.java:6680)
System.err: at java.lang.reflect.Method.invoke(Native Method)
System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

StarPrinter Library implementation question

For the specific Star printer that I'm using, it takes in bitmap (UIImage for iOS) instead of text data. StarIO_Extension.framework has the implementation for these raster printers, so I'm trying to add it to this plugin so I can . I dropped the .framework file in the platforms/ios folder and was able to build the project, but when I run the command "TNS_TYPESCRIPT_DECLARATIONS_PATH="$(pwd)/typings" tns build ios" to output all the Clang modules, I'm not seeing any of the implementations for any of the framework functions.

I noticed for your plugin, there is a StarPrinter.d.ts file which has all the declarations from the StarPrinter header files, but I don't have that for mine - do I have to write that myself for the StarIO_Extension framework?

I'm pretty new to developing custom {N} plugins (especially without CocoaPods) so any guidance would be appreciated.

Another possibility I was looking into to get around having to import this framework would be converting the UIImage directly to a byte stream that I can send to the printer, similar to the .appendData and .appendBytes functions you have in your star-printer.ios.ts. I tried a few things for that but with no luck, so I'm not sure which would be the easier route to take.

[Feature Request] Barcode Scanner

Hello.

Thanks for your work on this plugin. I'm using it for some PoC to build A PoS using nativescript rather than going native, and your plugin contributed a lot to this success, so many thanks. Looking at reading from barcode scanner, though, seems challenging. Can we request a sponsored feature implementation for the plugin? Initially I was hoping we would implemented this and Co tribute the work to your repo.

Looking forward to hearing from you.

Provide more control over image printing

I need this for iOS, so implementing a new method imagePositioned where one can specify width and position properties.

Let's also bump the iOS SDK to the latest version.

Unable to build the demo app

When I run this command:
npm run build-ios-bundle

I get the below error:

@ build-ios-bundle /Users/rebaca/Desktop/star_printer/nativescript-star-printer/demo
npm run ns-bundle --ios --build-app

@ ns-bundle /Users/rebaca/Desktop/star_printer/nativescript-star-printer/demo
ns-bundle

Running tns prepare...
Executing before-prepare hook from /Users/rebaca/Desktop/star_printer/nativescript-star-printer/demo/hooks/before-prepare/nativescript-dev-typescript.js
Preparing project...
Project successfully prepared (ios)
Executing after-prepare hook from /Users/rebaca/Desktop/star_printer/nativescript-star-printer/demo/hooks/after-prepare/nativescript-unit-test-runner.js
Running webpack for ios...
/Users/rebaca/Desktop/star_printer/nativescript-star-printer/demo/node_modules/webpack/bin/webpack.js:323
throw e;
^

TypeError: Cannot read property 'emit' of undefined
at NativeScriptWorkerPlugin.exports.NativeScriptWorkerPlugin.NativeScriptWorkerPlugin.apply (/Users/rebaca/Desktop/star_printer/nativescript-star-printer/demo/node_modules/nativescript-worker-loader/NativeScriptWorkerPlugin.js:9:24)
at Compiler.apply (/Users/rebaca/Desktop/star_printer/nativescript-star-printer/demo/node_modules/tapable/lib/Tapable.js:375:16)
at webpack (/Users/rebaca/Desktop/star_printer/nativescript-star-printer/demo/node_modules/webpack/lib/webpack.js:32:19)
at processOptions (/Users/rebaca/Desktop/star_printer/nativescript-star-printer/demo/node_modules/webpack/bin/webpack.js:313:14)
at Object. (/Users/rebaca/Desktop/star_printer/nativescript-star-printer/demo/node_modules/webpack/bin/webpack.js:373:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
child process exited with code 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ ns-bundle: ns-bundle
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ ns-bundle script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/rebaca/.npm/_logs/2018-09-28T06_44_52_709Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ build-ios-bundle: npm run ns-bundle --ios --build-app
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ build-ios-bundle script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/rebaca/.npm/_logs/2018-09-28T06_44_52_779Z-debug.log

Print after reconnect Bluetooth

Hello All,

So I have a situation which I am trying to fix in some cases the end user disconnects bluetooth and if user attempts to print without bluetooth I do check display message. My issue is that when end user reconnects bluetooth and is still pair to same printer the app should just pickup printer. Well I am getting error message below after attempting to print

Error message:

Error: com.starmicronics.stario.StarIOPortException: failed to write
com.starmicronics.stario.a.g(Unknown Source:304)
com.starmicronics.stario.a.retreiveStatus(Unknown Source:0)
com.starmicronics.stario.a.beginCheckedBlock(Unknown Source:0)
com.tns.Runtime.callJSMethodNative(Native Method)
com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116) com.tns.Runtime.callJSMethodImpl(Runtime.java:996)
com.tns.Runtime.callJSMethod(Runtime.java:983)
com.tns.Runtime.callJSMethod(Runtime.java:967)
com.tns.Runtime.callJSMethod(Runtime.java:959)
com.tns.gen.java.lang.Runnable.run(Runnable.java:15)
android.os.Handler.handleCallback(Handler.java:873)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:214)
android.app.ActivityThread.main(ActivityThread.java:7073)
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)

Code Example:
`
import { StarPrinter, SPCommands} from "nativescript-star-printer";
import * as Bluetooth from "nativescript-bluetooth";

private portName: string = "BT:Star Micronics"
public starPrinter: StarPrinter;

//check bluetooth enable
Bluetooth.isBluetoothEnabled()
.then(
(enable) => {
if (!enable) {
console.log("Bluetooth Off");
this.starPrinter = null;
} else {
//instance printer
this.starPrinter = new StarPrinter();
const cmds = new SPCommands()
.newLine()
.setFont("default")
.textLargeBold("Hello World ");
this.starPrinter.print({
portName: this.portName,
commands: cmds
}).then((res) => {
console.log('Print Done');
}, (err) => {
console.log(err);
});
}
}
);

`

Some few debug things I have done is also added the connect method and the printer does come back online. Also moved the starprinter instance to constructor but I don't believe this should matter. I know if I kill the app and relaunch that will work but trying to avoid them having to close the app.

Any ideas will be apreciated!

Printing not working with demo + TSP100III

I've installed the demo (using the ns6 PR I just submitted) and have a TSP100III printer. I can connect and view status, but it will not print. There are no console errors of any kind. Any ideas of what to poke at? thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.