Skip to content

Latest commit

 

History

History
200 lines (147 loc) · 9.05 KB

README_JP.md

File metadata and controls

200 lines (147 loc) · 9.05 KB

react-native-star-io10

react-native-star-io10はスター精密デバイス向けアプリケーション開発をサポートするライブラリです。

本ライブラリはStarXpand SDKに含まれます。

ドキュメント

StarXpand SDKのドキュメントはこちらを参照ください。

ドキュメントにはSDKの概要、サンプルアプリのビルド方法、APIの使用方法、APIリファレンスなどが含まれます。

動作環境

Platform OS Version Arch
iOS iOS 12.0 以降 実機: arm64
シミュレータ: x86_64, arm64
Android Android 6.0 以降 arm64-v8a, armeabi-v7a, x86, x86_64
Windows Windows 11 / Windows 10 1909 以降 x86, x64

導入

npm install react-native-star-io10 --save

iOS

プリンターのインターフェースによって、必要な対応があります。
下記表を確認し対応をしてください。

プリンターのインターフェース 必要な対応
Bluetooth 1. & 2. & 4.
Bluetooth Low Energy 2.
Ethernet (iOS14以上) 3.
Lightning USB 1. & 4.

1. Supported external accessory protocols 項目の設定

  1. Information Property List(デフォルトでは"Info.plist")を選択します。
  2. Keyに Supported external accessory protocols を追加します。
  3. 項目名左側の▽をクリックして表示される"Item 0"の[Value]に jp.star-m.starpro を設定します。

⚠️ 該当するプリンターを使用しない場合は、この設定を行わないでください。

2. Bluetooth Always Usage Description 項目および Bluetooth Peripheral Usage Description 項目の設定

  1. Information Property List(デフォルトでは"Info.plist")を選択します。
  2. Keyに Privacy – Bluetooth Always Usage Description を追加します。
  3. Deployment Target をiOS12に設定する場合、Keyに Privacy – Bluetooth Peripheral Usage Description を追加します。
  4. それぞれのValue に Bluetoothの利用目的(例: Use Bluetooth for communication with the printer.)を設定します。
  5. Bluetoothにてプリンターと通信するとき、Bluetoothへのアクセス許可を求めるダイアログが表示されます。その際、Valueに設定した文字列がBluetoothを利用する理由として表示されます。

より詳しくは、下記URLを参照してください。

https://developer.apple.com/documentation/bundleresources/information_property_list/nsbluetoothperipheralusagedescription

3. Local Network Usage Description 項目の設定

  1. Information Property List(デフォルトでは"Info.plist")を選択します。
  2. Keyに Privacy - Local Network Usage Description を追加します。
  3. Value に Local Networkの利用目的(例: Use Local Network for communication with the printer or discovery the printers.)を設定します。
  4. iOS14以上でEthernetプリンターと通信するとき、Local Networkへのアクセス許可を求めるダイアログが表示されます。その際、Valueに設定した文字列がLocal Networkを利用する理由として表示されます。

4. MFi対応プリンター向けアプリ認証を取得

MFi認証プリンターに対応したiOSアプリケーションを設計・開発し、 Apple iTunes App Storeにアプリケーション登録を行う場合、下記のURLに記載の手順によりアプリ認証を取得してください。Appleによるアプリ審査前に完了しておく必要があります。

https://star-m.jp/products/s_print/apple_app_mfi/index.html

⚠️ Bluetooth Low Energyプリンターを使用する場合は、このアプリ認証を行う必要はありません。

Android

サンプルコードを参考にして、プリンターとの通信や検索を開始する前に、BLUETOOTH_CONNECTパーミッションを要求してください。

Windows

  • 機能をPackage.appxmanifestに追加してください。
    • Bluetooth
    • インターネット(クライアント)
    • プライベート ネットワーク (クライアントとサーバー)
  • プロジェクトの「参照」に"Visual C++ 2015-2019 UWP Desktop Runtime for native apps"を追加してください。

制限事項

Android端末を使用する場合、URLで指定した画像が低い解像度で印字されることがある

actionPrintImageメソッドの引数ImageParameterのsourceにある程度サイズが大きい画像ファイルのURLを指定した場合、Android端末から印刷データが送付されると、画像が粗く印字されることがあります。

下記いずれかの方法により回避することができます。

  • あらかじめ画像の解像度を下げるなどして画像のデータ量を下げる
  • アプリ内で画像をダウンロードし、sourceには画像ファイルを直接指定する

Examples

StarXpand SDKにはプリンターと組み合わせて動作を確認できるサンプルアプリが含まれています。リンク先の各機能の解説と合わせてご利用ください。

ラベル用の印刷レイアウトを作成するのに活用できる各業態の印刷サンプル(サンプルコードと印刷結果画像)もご利用ください。

⚠️ プリンターのモデルによっては印刷できないサンプルがあります。また、ご利用の際は適宜レイアウトを調節してください。

Get printer status

async getStatus(): Promise<void> {
    // Specify your printer connection settings.
    var settings = new StarConnectionSettings();
    settings.interfaceType = InterfaceType.Lan;
    settings.identifier = '00:11:62:00:00:00';
    var printer = new StarPrinter(settings);

    try {
        // Connect to the printer.
        await printer.open();

        // Get printer status.
        var status = await printer.getStatus();
        console.log(status);
    }
    catch(error) {
        // Error.
        console.log(error);
    }
    finally {
        // Disconnect from the printer and dispose object.
        await printer.close();
        await printer.dispose();
    }
}

Monitor printer

printer: StarPrinter;

async monitor(): Promise<void> {
    // Specify your printer connection settings.
    var settings = new StarConnectionSettings();
    settings.interfaceType = InterfaceType.Lan;
    settings.identifier = '00:11:62:00:00:00';
    printer = new StarPrinter(settings);

    // Callback for printer state changed.
    printer.printerDelegate.onReady = () => {
        console.log(`Printer: Ready`);
    }
    printer.drawerDelegate.onOpenCloseSignalSwitched = (openCloseSignal) => {
        console.log(`Drawer: Open Close Signal Switched: ${String(openCloseSignal)}`);
    }
    printer.inputDeviceDelegate.onDataReceived = (data) => {
        console.log(`Input Device: DataReceived ${String(data)}`);
    }
    printer.displayDelegate.onConnected = () => {
        console.log(`Display: Connected`);
    }
    // ...
    // Please refer to document for other callback.

    try {
        // Connect to the printer.
        await printer.open();
    }
    catch(error) {
        // Error.
        console.log(error);
    }
}

Copyright

Copyright 2021 Star Micronics Co., Ltd. All rights reserved.