Giter VIP home page Giter VIP logo

capacitor-plugin-sunmi's Introduction

@bistroo/capacitor-plugin-sunmi

Install

pnpm add -D @bistroo/capacitor-plugin-sunmi
import { Sunmi } from '@bistroo/capacitor-plugin-sunmi'

// start the buffer
Sunmi.start()
Sunmi.line('fdfdfdfd')

// commit the buffer
await Sunmi.print()

Or without using a buffer

import { Sunmi } from '@bistroo/capacitor-plugin-sunmi'

Sunmi.line('fdfdfdfd')

API

interface SunmiPlugin {
  start(): void
  table(options: { rows: TableRow[] }): void
  text(options: { text: string }): void
  line(options: { text?: string, wrap: boolean }): void
  wrap(): void
  bold(): void
  normal(): void
  align(options: { direction: "LEFT" | "CENTER" | "RIGHT" }): void
  print(): Promise<void>
  image(options: { image: string }): void
  font(options: { type: number }): void
  fontSize(options: { size: 1 | 2 | 3 | 4 }): void
  deviceInfo(): Promise<{ serial_number: string, model: string }>
  addListener(
    eventName: 'printer-state',
    listenerFunc: (response: { status: number }) => void,
  ): Promise<PluginListenerHandle> & PluginListenerHandle;
}

export type TableRow = {
  value: string
  size: number
  alignment: 0 | 1 | 2
}

export const Sunmi: SunmiPlugin

capacitor-plugin-sunmi's People

Contributors

weareinvision avatar yooouuri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

capacitor-plugin-sunmi's Issues

Add new functions

Thank you so much for your plugin. Please, can you add these new function asap? This plugin really needs function for cut paper.

In SunmiPlugin.java:
@PluginMethod(returnType = PluginMethod.RETURN_NONE)
public void cutPaper(PluginCall call) throws RemoteException {
if (mPrinterService != null) {
mPrinterService.cutPaper(new InnerResultCallback() {
@OverRide
public void onRunResult(boolean isSuccess) {
Log.d(TAG, String.format("InnerResultCallback#onRunResult() %b", isSuccess));
}

            @Override
            public void onReturnString(String result) {
                Log.d(TAG, String.format("InnerResultCallback#onReturnString() %s", result));
            }

            @Override
            public void onRaiseException(int code, String msg) {
                Log.e(TAG, String.format("InnerResultCallback#onRaiseException() %s, %d", msg, code));

                call.reject(msg, String.valueOf(code));
            }

            @Override
            public void onPrintResult(int code, String msg) {
                if (code == 0) {
                    Log.d(TAG, String.format("InnerResultCallback#onPrintResult() %s, %d", msg, code));

                    call.resolve();
                } else {
                    Log.e(TAG, String.format("InnerResultCallback#onPrintResult() %s, %d", msg, code));

                    call.reject(msg, String.valueOf(code));
                }
            }
        });
    }
}

@PluginMethod(returnType = PluginMethod.RETURN_NONE)
public void printBarcode(PluginCall call) throws RemoteException {
    if (mPrinterService != null) {
        String data = call.getString("data");
        int size = call.getInt("size");
        int errorlevel = call.getInt("errorlevel");
        mPrinterService.printQRCode(data, size, errorlevel, null);
    }
}

In definitions.ts :
cutPaper(): void
printBarcode(options: {
data: string;
size: 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16;
errorlevel: 0 | 1 | 2 | 3;
}): void;

Thanks.

Sunmi.image() does not work.

when i use Sunmi.image() it does not work.Do it use for print image in paper? i did not seem anything.I replace image option witn image url or base 64 image file it do not print.What this command use for?

Added necessary function

Can you add the all new function to your plugin since QRcode and cutpaper it use full to me but i cannot use it.

Printing image repeat

When using Sunmi.image it repeat the last order . I need a way to print invoice and finish process . Then start a new one

Add QR method

Good evening, I was able to add the qr method manually, at least it works for me.

I would appreciate it if you could incorporate this method into the plugin accordingly as it is very useful.

Thanks in advance for the plugin that works excellent and is very useful.

File: SunmiPlugin.java

@PluginMethod(returnType = PluginMethod.RETURN_NONE)
public void qr(PluginCall call) throws RemoteException {
if (mPrinterService != null) {
String data = call.getString("data");
int size = call.getInt("size");
int errorlevel = call.getInt("errorlevel");

        mPrinterService.printQRCode(data, size, errorlevel, null);
    }
}

File: definitions.ts

qr(options: {
data: string;
size: 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16;
errorlevel: 0 | 1 | 2 | 3;
}): void;

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.