Search
Search は近くの Brother プリンターを探します。結果は Events の onPrinterAvailable で届きます。インストール のあとで呼び出します。
search
戻り値は void です。プリンターはイベントから集めます。
import { BrotherPrint, BRLMPrinterPort } from '@rdlabo/capacitor-brotherprint';
await BrotherPrint.search({
port: BRLMPrinterPort.wifi,
searchDuration: 15, // seconds
});
searchDuration は wifi と bluetoothLowEnergy で使います。usb は Android のみです。見つからない場合はエラーにはならず、プリンターも届きません。
method search(...)
Search for printers. If not found, it will return an empty array.(not error)
search(option: BRLMSearchOption) => Promise<void>
type alias BRLMSearchOption
{ /** * 'usb' is android only, and now developing. */ port: BRLMPrinterPort; /** * searchDuration is the time to end search for devices. * default is 15 seconds. * use only port is 'wifi' or 'bluetoothLowEnergy'. */ searchDuration: number; }
isChannelAvailable
最後の BRLMChannelResult を保存している場合、Print の前にそのチャネルがまだ使えるかを確認できます。
import { BrotherPrint } from '@rdlabo/capacitor-brotherprint';
import type { BRLMChannelResult } from '@rdlabo/capacitor-brotherprint';
const checkChannel = async (lastPrinter: BRLMChannelResult) => {
const { result } = await BrotherPrint.isChannelAvailable(lastPrinter);
if (!result) {
await BrotherPrint.search({
port: lastPrinter.port,
searchDuration: 15,
});
}
};
method isChannelAvailable(...)
If you have saved the last connected <a href="#brlmchannelresult">BRLMChannelResult</a>,
you can use it to verify whether it is currently usable.
isChannelAvailable(option: BRLMChannelResult) => Promise<isChannelAvailableResult>
type alias isChannelAvailableResult
{ result: boolean; }
type alias BRLMChannelResult
{ port: BRLMPrinterPort; modelName: string; serialNumber: string; macAddress: string; nodeName: string; location: string; /** * This need to connect to the printer. * wifi: IP Address * bluetooth: macAddress * bluetoothLowEnergy: modelName for bluetoothLowEnergy */ channelInfo: string; }
cancelSearchWiFiPrinter / cancelSearchBluetoothPrinter
探索はもともとタイムアウトします。複数の search port を同時に走らせ、片方だけ自分で止めたいとき使います。
import { BrotherPrint } from '@rdlabo/capacitor-brotherprint';
await BrotherPrint.cancelSearchWiFiPrinter();
await BrotherPrint.cancelSearchBluetoothPrinter();
method cancelSearchWiFiPrinter()
Basically, it times out, so there is no need to use it. Use it when you want to run multiple connectType searches at the same time and time out any of them manually.
cancelSearchWiFiPrinter() => Promise<void>
method cancelSearchBluetoothPrinter()
Basically, it times out, so there is no need to use it. Use it when you want to run multiple connectType searches at the same time and time out any of them manually.
cancelSearchBluetoothPrinter() => Promise<void>