Compare commits
8 Commits
5677de4120
...
3d16fd8ee1
Author | SHA1 | Date |
---|---|---|
章文轩 | 3d16fd8ee1 | 2 years ago |
章文轩 | 1d11eb7b2c | 2 years ago |
章文轩 | 952b5c75b4 | 2 years ago |
章文轩 | da66b76e8d | 2 years ago |
章文轩 | 0094f481f3 | 2 years ago |
章文轩 | 921d52fb72 | 2 years ago |
章文轩 | 7764ef51a5 | 2 years ago |
meng-fucius | 2dce9eaf2a | 3 years ago |
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1 @@
|
||||
hy_printer
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenRepo" />
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="Google" />
|
||||
<option name="name" value="Google" />
|
||||
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/hy_printer.iml" filepath="$PROJECT_DIR$/.idea/modules/hy_printer.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
@ -1,7 +1,15 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.hy.print.hy_printer">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.hy.print.hy_printer">
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" tools:remove="android:maxSdkVersion" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
||||
</manifest>
|
||||
|
@ -0,0 +1,372 @@
|
||||
package com.hy.print.hy_printer;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import cpcl.PrinterHelper;
|
||||
import io.flutter.plugin.common.EventChannel;
|
||||
|
||||
//import com.sewoo.port.android.BluetoothPort;
|
||||
//import com.sewoo.request.android.RequestHandler;
|
||||
|
||||
|
||||
public class Bluetooth {
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
//private BluetoothPort bluetoothPort;
|
||||
|
||||
private BroadcastReceiver connectDevice;
|
||||
private BroadcastReceiver discoveryResult;
|
||||
private BroadcastReceiver searchFinish;
|
||||
private BroadcastReceiver searchStart;
|
||||
|
||||
private Thread btThread;
|
||||
|
||||
private boolean searchflags;
|
||||
private boolean disconnectflags;
|
||||
|
||||
public void init() {
|
||||
|
||||
// bluetoothPort = BluetoothPort.getInstance();
|
||||
// bluetoothPort.SetMacFilter(false);
|
||||
bluetoothSetup();
|
||||
searchflags = false;
|
||||
disconnectflags = false;
|
||||
System.out.println("打印机蓝牙初始化完成");
|
||||
}
|
||||
|
||||
//初始化连接监听
|
||||
public void createConnectBroadcast(Context context, EventChannel.EventSink eventSink) {
|
||||
|
||||
connectDevice = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
|
||||
eventSink.success("connected");
|
||||
} else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) {
|
||||
try {
|
||||
PrinterHelper.portClose();
|
||||
// if (bluetoothPort.isConnected()) {
|
||||
// System.out.println("1111s");
|
||||
// bluetoothPort.disconnect();
|
||||
// }
|
||||
if ((btThread != null) && (btThread.isAlive())) {
|
||||
cancelThread();
|
||||
}
|
||||
System.out.println("disconnected");
|
||||
eventSink.success("disconnected");
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
context.registerReceiver(connectDevice, new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED));
|
||||
context.registerReceiver(connectDevice, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
||||
System.out.println("注册连接广播");
|
||||
}
|
||||
|
||||
public boolean isValidAddress(String address) {
|
||||
String[] btDevAddr = new String[]{"00:12:6f", "00:13:7b", "00:07:80", "88:6b:0f", "40:19:20", "00:01:90", "ec:1b:bd", "58:8e:81", "14:b4:57", "90:fd:9f", "00:0b:57", "68:0a:e2", "84:2e:14", "08:6b:d7", "60:a4:23", "cc:cc:cc", "bc:33:ac", "74:f0:7d", "84:fd:27", "84:71:27", "80:4b:50", "5c:02:72", "cc:86:ec", "2c:11:65", "b4:e3:f9", "0c:43:14", "50:32:5f", "04:cd:15", "8c:f6:81", "90:35:ea"};
|
||||
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
|
||||
return false;
|
||||
} else {
|
||||
for(int i = 0; i < btDevAddr.length; ++i) {
|
||||
if (btDevAddr[i].equalsIgnoreCase(address.substring(0, 8))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//初始化搜索设备监听
|
||||
public void createDiscoveryBroadcast(Context context, EventChannel.EventSink eventSink) {
|
||||
discoveryResult = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String key = "";
|
||||
BluetoothDevice remoteDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
String name = remoteDevice.getName();
|
||||
System.out.println(name);
|
||||
System.out.println(remoteDevice.getAddress());
|
||||
System.out.println(remoteDevice.getBluetoothClass().getMajorDeviceClass());
|
||||
if (remoteDevice != null && name != null&&remoteDevice.getBluetoothClass().getMajorDeviceClass()==1536) {
|
||||
if (remoteDevice.getBondState() != BluetoothDevice.BOND_BONDED) {
|
||||
key = "{" + "\"name\":" + "\"" + name + "\"" + ","
|
||||
+ "\"address\":" + "\"" + remoteDevice.getAddress() + "\"" + ","
|
||||
+ "\"isPaired\":" + false
|
||||
+ "}";
|
||||
|
||||
} else {
|
||||
|
||||
key = "{" + "\"name\":" + "\"" + name + "\"" + ","
|
||||
+ "\"address\":" + "\"" + remoteDevice.getAddress() + "\"" + ","
|
||||
+ "\"isPaired\":" + true
|
||||
+ "}";
|
||||
}
|
||||
System.out.println(key);
|
||||
eventSink.success(key);
|
||||
System.out.println(key);
|
||||
// if (isValidAddress(remoteDevice.getAddress())) {
|
||||
// eventSink.success(key);
|
||||
// System.out.println(key);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
context.registerReceiver(discoveryResult, new IntentFilter(BluetoothDevice.ACTION_FOUND));
|
||||
searchStart = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
eventSink.success("start");
|
||||
System.out.println("start");
|
||||
}
|
||||
};
|
||||
context.registerReceiver(searchStart, new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_STARTED));
|
||||
|
||||
searchFinish = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
eventSink.success("finish");
|
||||
searchflags = true;
|
||||
System.out.println("finish");
|
||||
}
|
||||
};
|
||||
context.registerReceiver(searchFinish, new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED));
|
||||
System.out.println("注册搜索广播");
|
||||
}
|
||||
|
||||
//蓝牙设置
|
||||
private void bluetoothSetup() {
|
||||
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (mBluetoothAdapter == null) {
|
||||
System.out.println("不支持蓝牙");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//搜索设备
|
||||
public void SearchingBTDevice() {
|
||||
|
||||
new CheckTypesTask().execute();
|
||||
System.out.println("开始搜索");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void btConn(final String address, Context context) throws Exception {
|
||||
|
||||
System.out.println("btConn");
|
||||
|
||||
btThread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
System.out.println(address);
|
||||
final int result = PrinterHelper.portOpenBT(context,address);
|
||||
PrinterHelper.logcat("portOpen result:"+ result);
|
||||
System.out.println(result);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
btThread.start();
|
||||
//final int result = PrinterHelper.portOpenBT(context,address);
|
||||
//new connBT().execute(address);
|
||||
}
|
||||
|
||||
//断开连接
|
||||
public void DisconnectDevice(Context context) {
|
||||
try {
|
||||
// bluetoothPort.disconnect();
|
||||
PrinterHelper.portClose();
|
||||
// if ((btThread != null) && (btThread.isAlive()))
|
||||
// btThread.interrupt();
|
||||
if ((btThread != null) && (btThread.isAlive())) {
|
||||
Thread dummy = btThread;
|
||||
btThread = null;
|
||||
dummy.interrupt();
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
disconnectflags = true;
|
||||
context.unregisterReceiver(connectDevice);
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//取消搜索
|
||||
public void cancelDiscoveryResult(Context context) {
|
||||
System.out.println("取消搜索");
|
||||
mBluetoothAdapter.cancelDiscovery();
|
||||
context.unregisterReceiver(discoveryResult);
|
||||
context.unregisterReceiver(searchStart);
|
||||
context.unregisterReceiver(searchFinish);
|
||||
}
|
||||
|
||||
|
||||
public void cancelThread() {
|
||||
btThread.interrupt();
|
||||
btThread = null;
|
||||
}
|
||||
|
||||
private class CheckTypesTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
mBluetoothAdapter.startDiscovery();
|
||||
super.onPreExecute();
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
// TODO Auto-generated method stub
|
||||
try {
|
||||
while (true) {
|
||||
if (searchflags)
|
||||
break;
|
||||
|
||||
Thread.sleep(100);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
|
||||
searchflags = false;
|
||||
super.onPostExecute(result);
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// class connBT extends AsyncTask<String, Void, Integer> {
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// protected Integer doInBackground(String... strings) {
|
||||
// Integer retVal = null;
|
||||
//
|
||||
// //bluetoothPort.connect(strings[0]);
|
||||
//
|
||||
// retVal = Integer.valueOf(0);
|
||||
//
|
||||
// return retVal;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onPreExecute() {
|
||||
//
|
||||
// super.onPreExecute();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onPostExecute(Integer result) {
|
||||
// if (result.intValue() == 0) // Connection success.
|
||||
// {
|
||||
//// RequestHandler rh = new RequestHandler();
|
||||
//// btThread = new Thread(rh);
|
||||
//// btThread.start();
|
||||
// } else // Connection failed.
|
||||
// {
|
||||
//
|
||||
// }
|
||||
// super.onPostExecute(result);
|
||||
// }
|
||||
// }
|
||||
|
||||
public void ExcuteDisconnect(Context context) {
|
||||
// new ExcuteDisconnectBT().execute(context);
|
||||
try {
|
||||
DisconnectDevice(context);
|
||||
|
||||
while (true) {
|
||||
if (disconnectflags)
|
||||
break;
|
||||
|
||||
Thread.sleep(100);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// private class ExcuteDisconnectBT extends AsyncTask<Context, Void, Void> {
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// protected Void doInBackground(Context... contexts) {
|
||||
// try {
|
||||
// DisconnectDevice(contexts[0]);
|
||||
//
|
||||
// while (true) {
|
||||
// if (disconnectflags)
|
||||
// break;
|
||||
//
|
||||
// Thread.sleep(100);
|
||||
// }
|
||||
// } catch (InterruptedException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onPreExecute() {
|
||||
// super.onPreExecute();
|
||||
// }
|
||||
//
|
||||
// ;
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// protected void onPostExecute(Void result) {
|
||||
// disconnectflags = false;
|
||||
// super.onPostExecute(result);
|
||||
// }
|
||||
//
|
||||
// ;
|
||||
// }
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,9 +1,11 @@
|
||||
class Device {
|
||||
final String name;
|
||||
final String address;
|
||||
String name;
|
||||
String address;
|
||||
bool isPaired;
|
||||
|
||||
const Device({
|
||||
Device({
|
||||
required this.name,
|
||||
required this.address,
|
||||
required this.isPaired,
|
||||
});
|
||||
}
|
||||
|
@ -0,0 +1,195 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:hy_printer/status_enum.dart';
|
||||
|
||||
class DjPrinter {
|
||||
static late final DjPrinter _instance = DjPrinter._();
|
||||
|
||||
DjPrinter._();
|
||||
|
||||
factory DjPrinter() => _instance;
|
||||
static const MethodChannel _channel = MethodChannel('hy_printer');
|
||||
static const EventChannel _deviceChannel =
|
||||
EventChannel("com.discovery.devices");
|
||||
StreamSubscription? _discoveryStream;
|
||||
|
||||
StreamSubscription addDiscoveryListen(
|
||||
{required void Function(dynamic data) onReceive,
|
||||
void Function()? onStart,
|
||||
void Function()? onFinish}) {
|
||||
if (_discoveryStream == null) {
|
||||
return _deviceChannel.receiveBroadcastStream().listen((data) {
|
||||
if (data == "start" && onStart != null) {
|
||||
onStart();
|
||||
} else if (data == "finish" && onFinish != null) {
|
||||
onFinish();
|
||||
} else {
|
||||
onReceive(data);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return _discoveryStream!;
|
||||
}
|
||||
}
|
||||
|
||||
void cancelDiscovery() {
|
||||
_discoveryStream?.cancel();
|
||||
_discoveryStream = null;
|
||||
print('结束搜索');
|
||||
disposeDiscovery();
|
||||
}
|
||||
|
||||
static const EventChannel _connectChannel = EventChannel("com.connect");
|
||||
StreamSubscription? _connectStream;
|
||||
|
||||
StreamSubscription addConnectListen({required void Function() onConnect,
|
||||
required void Function() onDisconnect}) {
|
||||
if (_connectStream == null) {
|
||||
return _connectChannel.receiveBroadcastStream().listen((data) {
|
||||
if (data == 'connected') {
|
||||
onConnect();
|
||||
} else if (data == 'disconnected') {
|
||||
onDisconnect();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return _connectStream!;
|
||||
}
|
||||
}
|
||||
|
||||
void cancelConnect() {
|
||||
if (_connectStream != null) {
|
||||
_connectStream!.cancel();
|
||||
_connectStream = null;
|
||||
}
|
||||
}
|
||||
|
||||
void get startSearch {
|
||||
final res = _channel.invokeMethod('startSearch');
|
||||
}
|
||||
|
||||
bool _hasInit = false;
|
||||
|
||||
bool get hasInit => _hasInit;
|
||||
|
||||
Future<bool?> connect(String address) async {
|
||||
|
||||
final res = await _channel.invokeMethod('connect', {'address': address});
|
||||
return res;
|
||||
}
|
||||
|
||||
void disposeDiscovery() {
|
||||
print('disposeDiscovery');
|
||||
final res = _channel.invokeMethod('disposeDiscovery');
|
||||
}
|
||||
|
||||
Future<bool?> disposeConnect() async {
|
||||
final res = await _channel.invokeMethod('disposeConnect');
|
||||
return res;
|
||||
}
|
||||
|
||||
Future<bool?> init() async {
|
||||
final res = await _channel.invokeMethod('init');
|
||||
_hasInit = true;
|
||||
return res;
|
||||
}
|
||||
|
||||
//0 normal
|
||||
//1 busy
|
||||
//2 paper empty
|
||||
//4 cover open
|
||||
//8 battery low
|
||||
// Future<PRINT_STATUS?> getStatus() async {
|
||||
// final res = await _channel.invokeMethod('getStatus');
|
||||
// switch (res) {
|
||||
// case 0:
|
||||
// return PRINT_STATUS.normal;
|
||||
// case 1:
|
||||
// return PRINT_STATUS.busy;
|
||||
// case 2:
|
||||
// return PRINT_STATUS.paperEmpty;
|
||||
// case 4:
|
||||
// return PRINT_STATUS.coverOpen;
|
||||
// case 8:
|
||||
// return PRINT_STATUS.batteryLow;
|
||||
// default:
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//0 normal
|
||||
//-1 发送失败
|
||||
//2 paper empty
|
||||
//6 cover open
|
||||
|
||||
Future<PRINT_STATUS?> getStatus() async {
|
||||
final res = await _channel.invokeMethod('getStatus');
|
||||
switch (res) {
|
||||
case 0:
|
||||
return PRINT_STATUS.normal;
|
||||
case -1:
|
||||
return PRINT_STATUS.fail;
|
||||
case 2:
|
||||
return PRINT_STATUS.paperEmpty;
|
||||
case 6:
|
||||
return PRINT_STATUS.coverOpen;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool?> printNewAScode({required String code,
|
||||
required String barCode,
|
||||
required String channel,
|
||||
required String country,
|
||||
required String num,
|
||||
required String sum,
|
||||
required int offset,
|
||||
required bool hasPlan}) async {
|
||||
final res = await _channel.invokeMethod('newPrint', {
|
||||
'code': code,
|
||||
'barCode':barCode,
|
||||
'channel': channel,
|
||||
'country': country,
|
||||
'num': num,
|
||||
'sum': sum,
|
||||
'offset': offset,
|
||||
'hasPlan': hasPlan,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Future<bool?> printAScode({required String code,
|
||||
required String channel,
|
||||
required String country,
|
||||
required String countStr,
|
||||
required int offset,
|
||||
required bool hasPlan}) async {
|
||||
final res = await _channel.invokeMethod('print', {
|
||||
'code': code,
|
||||
'channel': channel,
|
||||
'country': country,
|
||||
'countStr': countStr,
|
||||
'offset': offset,
|
||||
'hasPlan': hasPlan,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
// enum PRINT_STATUS {
|
||||
// normal,
|
||||
// busy,
|
||||
// paperEmpty,
|
||||
// coverOpen,
|
||||
// batteryLow,
|
||||
// }
|
||||
enum PRINT_STATUS {
|
||||
normal,
|
||||
fail,
|
||||
paperEmpty,
|
||||
coverOpen,
|
||||
}
|
Loading…
Reference in new issue