2.1.1 • Published 1 month ago

@mitsuharu/react-native-sunmi-printer-library v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

@mitsuharu/react-native-sunmi-printer-library

React Native module that support for SUNMI mobile printer devices.

Verification devices

I validate it with GMS enable and developable SUNMI V2 PRO and SUNMI V2s as follows. Though I do not have other devices, users report to work with V1s and V2.

AndroidSUNMI OSfirmwarestoragememoryNFC
SUNMI V2 PRO7.13.6.2375416 GB2 GBenable
SUNMI V2 PRO (foodpanda)7.11.0.331388 GB1 GBdisable
SUNMI V2s113.0.1124232 GB3 GBenable

^GMS: Google Mobile Services https://www.android.com/gms

Installation

npm install @mitsuharu/react-native-sunmi-printer-library

or

yarn add @mitsuharu/react-native-sunmi-printer-library

Usage

You see example directory for details.

prepare

import * as SunmiPrinterLibrary from '@mitsuharu/react-native-sunmi-printer-library'
try {
    await SunmiPrinterLibrary.prepare()
} catch (error: any) {
    console.warn("This device is not supported.")
}

print Text

await SunmiPrinterLibrary.printText('Hello World')

or

SunmiPrinterLibrary.printText('Hello World')

!WARNING Printing without await is faster, but may be interrupted by other printing.

change style

await SunmiPrinterLibrary.setAlignment('center')
await SunmiPrinterLibrary.setTextStyle('bold', true)
await SunmiPrinterLibrary.setParagraphStyle('textRightSpacing', 5)
await SunmiPrinterLibrary.setFontSize(32)
await SunmiPrinterLibrary.printText('Hello World')

print Image (Base64)

const base64 = 'data:image/png;base64,iVBORw0KGgoAAAA...'
await SunmiPrinterLibrary.printImage(base64, 384, 'binary')
await SunmiPrinterLibrary.printImage(base64, 384, 'grayscale')

print QR code

await SunmiPrinterLibrary.printQRCode('Hello World', 8, 'middle')

scan QR code

const result = await SunmiPrinterLibrary.scan()

or

SunmiPrinterLibrary.scan()
useEffect(() => {
   DeviceEventEmitter.addListener(
      SunmiPrinterLibrary.EventType.onScanSuccess,
      (message) => {
        console.log(`[onScanSuccess] ${message}`)
      })
   DeviceEventEmitter.addListener(
      SunmiPrinterLibrary.EventType.onScanFailed, 
      (message) => {
        console.log(`[onScanFailed] ${message}`)
      })
   return () => {
      DeviceEventEmitter.removeAllListeners(SunmiPrinterLibrary.EventType.onScanSuccess)
      DeviceEventEmitter.removeAllListeners(SunmiPrinterLibrary.EventType.onScanFailed)
    }
}, [])

Transaction

await SunmiPrinterLibrary.enterPrinterBuffer(true)

SunmiPrinterLibrary.printText('Transaction Test 0')

await SunmiPrinterLibrary.commitPrinterBuffer()

SunmiPrinterLibrary.printText('Transaction Test 1')
SunmiPrinterLibrary.printText('Transaction Test 2')
SunmiPrinterLibrary.printText('Transaction Test 3')
SunmiPrinterLibrary.lineWrap(4)

await SunmiPrinterLibrary.exitPrinterBuffer(true)

not support

  • Cash Drawer API
  • Black Mark Print API

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Develop

yarn
yarn example android

Guides

I recommend that also modify test, readme and example.

License

MIT


Made with create-react-native-library

2.1.1

1 month ago

2.1.0

1 month ago

2.0.0

2 months ago

1.0.1

5 months ago

1.0.0

5 months ago

0.1.1

6 months ago

0.1.0

6 months ago