Merge pull request #1 from meng-fucius/master

Master
master
meng-fucius 3 years ago committed by GitHub
commit 2dce9eaf2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,6 +2,15 @@
汉印打印机插件
仅支持安卓
###
在build.gradle中 需要把minSdkVersion 改为19
权限配置中加入
```dart
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
```
##扫描设备
```dart
HyPrinter.getDevices();

@ -56,7 +56,7 @@ public class HyPrinterPlugin implements FlutterPlugin, MethodCallHandler {
}
result.success(status);
} else if (call.method.equals("printAsOrder")) {
int re = PrintAsOrder.print(call.argument("code"), call.argument("fbaCode"), call.argument("country"), call.argument("channel"), call.argument("count"));
int re = PrintAsOrder.print(call.argument("code"), call.argument("fbaCode"), call.argument("country"), call.argument("channel"), call.argument("count"), call.argument("hasPlan"));
result.success(re);
} else if (call.method.equals("printBarCode")) {
int re = -1;

@ -1,118 +1,117 @@
package com.hy.print.hy_printer;
import android.content.Context;
import cpcl.PrinterHelper;
public class PrintAsOrder {
public static int print(String code, String fbaCode, String country, String channel, String count) {
int reusult = 0;
System.out.println("print start");
try {
PrinterHelper.printAreaSize("0", "200", "200", "400", "1");
} catch (Exception e) {
e.printStackTrace();
reusult = 10;
}
// try {
// PrinterHelper.Align(PrinterHelper.CENTER);
// } catch (Exception e) {
// e.printStackTrace();
// reusult = 1;
// }
private static void setBold() {
try {
PrinterHelper.Barcode(PrinterHelper.BARCODE, PrinterHelper.code128, "2", "1", "130", "45", "26", false, "", "", "", code);
PrinterHelper.SetBold("2");
} catch (Exception e) {
e.printStackTrace();
reusult = 2;
}
}
private static void closeBold() {
try {
PrinterHelper.SetBold("3");
PrinterHelper.SetBold("0");
} catch (Exception e) {
e.printStackTrace();
reusult = 4;
}
try {
PrinterHelper.AutCenter(PrinterHelper.TEXT, "45", "180", 500, 8, code);
} catch (Exception e) {
e.printStackTrace();
reusult = 5;
}
private static void printBarCode(String code) {
String width = "2";
if (code.length() > 18) {
width = "1";
}
try {
PrinterHelper.SetBold("0");
PrinterHelper.Barcode(PrinterHelper.BARCODE, PrinterHelper.code128, width, "1", "130", "10", "26", false, "", "", "", code);
} catch (Exception e) {
e.printStackTrace();
reusult = 4;
}
}
if (fbaCode.isEmpty()) {
fbaCode = "非FBA订单";
public static int print(String code, String fbaCode, String country, String channel, String count, Boolean hasPlan) {
int re = 0;
if (!hasPlan) {
re = printNoPlan(code, count);
} else {
fbaCode = "FBA号" + fbaCode;
re = printHasPlan(code, fbaCode, country, channel, count);
}
return re;
}
public static int printNoPlan(String code, String count) {
int reusult = 0;
System.out.println("print start");
try {
PrinterHelper.AutCenter(PrinterHelper.TEXT, "45", "222", 500, 8, fbaCode);
PrinterHelper.printAreaSize("0", "200", "200", "400", "1");
PrinterHelper.Align(PrinterHelper.CENTER);
printBarCode(code);
PrinterHelper.Align(PrinterHelper.LEFT);
PrinterHelper.SetBold("3");
PrinterHelper.AutCenter(PrinterHelper.TEXT, "45", "170", 500, 4, code);
closeBold();
PrinterHelper.Line("42", "228", "550", "228", "2");
setBold();
PrinterHelper.SetMag("2", "2");
PrinterHelper.Text(PrinterHelper.TEXT, "20", "0", "45", "254", "未建计划");
PrinterHelper.Align(PrinterHelper.RIGHT);
PrinterHelper.Text(PrinterHelper.TEXT, "20", "0", "42", "254", "件数");
PrinterHelper.Text(PrinterHelper.TEXT, "20", "0", "42", "300", count);
PrinterHelper.SetMag("1", "1");
closeBold();
PrinterHelper.Align(PrinterHelper.LEFT);
PrinterHelper.Form();
PrinterHelper.Print();
} catch (Exception e) {
e.printStackTrace();
reusult = 5;
reusult = -1;
}
System.out.println("print finish");
return reusult;
}
// try {
// PrinterHelper.Prefeed("14");
// } catch (Exception e) {
// e.printStackTrace();
// reusult =3;
// }
public static int printHasPlan(String code, String fbaCode, String country, String channel, String count) {
int reusult = 0;
System.out.println("print start");
try {
PrinterHelper.printAreaSize("0", "200", "200", "400", "1");
PrinterHelper.Align(PrinterHelper.CENTER);
printBarCode(code);
PrinterHelper.Align(PrinterHelper.LEFT);
PrinterHelper.SetBold("3");
PrinterHelper.AutCenter(PrinterHelper.TEXT, "45", "170", 500, 4, code);
closeBold();
if (fbaCode.isEmpty()) {
fbaCode = "非FBA订单";
} else {
fbaCode = "FBA号" + fbaCode;
}
PrinterHelper.AutCenter(PrinterHelper.TEXT, "45", "222", 500, 8, fbaCode);
PrinterHelper.Line("42", "269", "550", "269", "2");
} catch (Exception e) {
e.printStackTrace();
reusult = 6;
}
channel = "渠道名称:" + channel;
try {
PrinterHelper.Text(PrinterHelper.TEXT, "8", "0", "45", "290", channel);
} catch (Exception e) {
e.printStackTrace();
reusult = 7;
}
// try {
// PrinterHelper.Align(PrinterHelper.LEFT);
// } catch (Exception e) {
// e.printStackTrace();
// reusult = 1;
// }
country = "目的国:" + country;
try {
setBold();
PrinterHelper.Text(PrinterHelper.TEXT, "8", "0", "45", "290", "渠道名称:");
closeBold();
PrinterHelper.Text(PrinterHelper.TEXT, "8", "0", "180", "290", channel);
country = "目的国:" + country;
PrinterHelper.Text(PrinterHelper.TEXT, "8", "0", "45", "337", country);
} catch (Exception e) {
e.printStackTrace();
reusult = 7;
}
// try {
// PrinterHelper.Align(PrinterHelper.RIGHT);
// } catch (Exception e) {
// e.printStackTrace();
// reusult = 1;
// }
count = "件数:" + count;
try {
PrinterHelper.Text(PrinterHelper.TEXT, "8", "0", "400", "337", count);
} catch (Exception e) {
e.printStackTrace();
reusult = 7;
}
try {
PrinterHelper.Align(PrinterHelper.RIGHT);
setBold();
count = "件数:" + count;
PrinterHelper.Text(PrinterHelper.TEXT, "8", "0", "40", "337", count);
closeBold();
PrinterHelper.Align(PrinterHelper.LEFT);
PrinterHelper.Form();
} catch (Exception e) {
e.printStackTrace();
reusult = 8;
}
try {
PrinterHelper.Print();
} catch (Exception e) {
e.printStackTrace();
reusult = 9;
reusult = -1;
}
System.out.println("print finish");
return reusult;

@ -0,0 +1,38 @@
PODS:
- Flutter (1.0.0)
- flutter_blue (0.0.1):
- Flutter
- flutter_blue/Protos (= 0.0.1)
- flutter_blue/Protos (0.0.1):
- Flutter
- Protobuf (~> 3.11.4)
- hy_printer (0.0.1):
- Flutter
- Protobuf (3.11.4)
DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_blue (from `.symlinks/plugins/flutter_blue/ios`)
- hy_printer (from `.symlinks/plugins/hy_printer/ios`)
SPEC REPOS:
trunk:
- Protobuf
EXTERNAL SOURCES:
Flutter:
:path: Flutter
flutter_blue:
:path: ".symlinks/plugins/flutter_blue/ios"
hy_printer:
:path: ".symlinks/plugins/hy_printer/ios"
SPEC CHECKSUMS:
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
flutter_blue: eeb381dc4727a0954dede73515f683865494b370
hy_printer: 93caaf83154d80a633bd57f43cdec0bb8b14b4c2
Protobuf: 176220c526ad8bd09ab1fb40a978eac3fef665f7
PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d
COCOAPODS: 1.11.0

@ -14,6 +14,7 @@
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
E12BD4EFC4AC35E5A9E0DBE1 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1076D900E2392A1416228F2B /* libPods-Runner.a */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@ -30,9 +31,11 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
1076D900E2392A1416228F2B /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; };
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
73C8556BF52A4B2D10255EE6 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@ -44,6 +47,8 @@
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D6DDA845CF550E6A1F37076D /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
E8D43E98422642241BD1E3DF /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -51,12 +56,32 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E12BD4EFC4AC35E5A9E0DBE1 /* libPods-Runner.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
4A4C9B13300D5707518E7245 /* Pods */ = {
isa = PBXGroup;
children = (
D6DDA845CF550E6A1F37076D /* Pods-Runner.debug.xcconfig */,
E8D43E98422642241BD1E3DF /* Pods-Runner.release.xcconfig */,
73C8556BF52A4B2D10255EE6 /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
867D8BAE1150CBAB8EC404CC /* Frameworks */ = {
isa = PBXGroup;
children = (
1076D900E2392A1416228F2B /* libPods-Runner.a */,
);
name = Frameworks;
sourceTree = "<group>";
};
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
@ -74,7 +99,8 @@
9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
CF3B75C9A7D2FA2A4C99F110 /* Frameworks */,
4A4C9B13300D5707518E7245 /* Pods */,
867D8BAE1150CBAB8EC404CC /* Frameworks */,
);
sourceTree = "<group>";
};
@ -117,6 +143,7 @@
isa = PBXNativeTarget;
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
buildPhases = (
D5F76D05153C5E1BACA5488F /* [CP] Check Pods Manifest.lock */,
9740EEB61CF901F6004384FC /* Run Script */,
97C146EA1CF9000F007C117D /* Sources */,
97C146EB1CF9000F007C117D /* Frameworks */,
@ -208,6 +235,28 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
};
D5F76D05153C5E1BACA5488F /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */

@ -4,4 +4,7 @@
<FileRef
location = "group:Runner.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>

@ -75,10 +75,27 @@ class _HomeState extends State<Home> {
TextButton(
onPressed: () async {
await HyPrinter.printAsOrder(
'ASSZ202112120001', '', "欧洲特快", '法国', "2/10");
code: 'ASASNB2021121200011',
fbaCode: '',
channel: "",
country: '',
count: "2/10",
hasPlan: false);
setState(() {});
},
child: const Text('打印')),
child: const Text('打印面单')),
TextButton(
onPressed: () async {
await HyPrinter.printAsOrder(
code: 'ASASNB2021121200010002',
fbaCode: 'FBA15RY33MN8U00001',
channel: "欧洲特快",
country: '法国',
count: "2/10",
hasPlan: true);
setState(() {});
},
child: const Text('打印FBA面单')),
TextButton(
onPressed: () async {
await HyPrinter.printBarCode(0, 0, "2", "1", "130", "45", "26",

@ -10,11 +10,12 @@
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"getPlatformVersion" isEqualToString:call.method]) {
result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
if ([@"connect" isEqualToString:call.method]) {
int result;
} else {
result(FlutterMethodNotImplemented);
}
}
@end

@ -0,0 +1,82 @@
/*!
* \~chinese
* @header GrayLevel.h
* @abstract
*
* \~english
* @header GrayLevel.h
* @abstract Image gray manager
*/
#import "PTBitmap.h"
#import <UIKit/UIKit.h>
@interface PTBitmap (GrayLevel)
/// 获取图像的灰度数据
/// @param image 图片
+ (NSData *)graylevel256Datas:(UIImage *)image;
/// 获取图像的灰度数据
/// @param image 图片
/// @param needReverse 是否反转灰度值 0->255 254->1
+ (NSData *)graylevel256Datas:(CGImageRef)image reverse:(BOOL)needReverse;
/// 从灰度图片数据获取图像
/// @param data 灰度数据每个字节代表每个像素的256阶灰度值
/// @param width 图片宽度
+ (UIImage *)imageWithGraylevel256Data:(NSData *)data width:(NSUInteger)width;
/// 灰度数据锐化
/// @param data 灰度数据每个字节代表每个像素的256阶灰度值
/// @param width 图片宽度
+ (NSData *)sharpenGraylevel256Data:(NSData *)data width:(NSUInteger)width;
/// 获取经过热补偿处理的数据
/// @param data 灰度数据每个字节代表每个像素的256阶灰度值
/// @param width 图片宽度
+ (NSData *)historyCompensateGraylevel256Data:(NSData *)data width:(NSUInteger)width;
/// 返回黑白图像数据
/// @param data 灰度数据每个字节代表每个像素的256阶灰度值
/// @param width 图片宽度
+ (NSData *)binaryDataOneBytePerPixelGraylevel256Data:(NSData *)data width:(NSUInteger)width;
/// 将图片导入设备灰度空间获取的灰度数据
/// @param image 图片
+ (NSData *)systemGraylevel256Datas:(UIImage *)image;
/// 将bitmap数据转成图片
/// @param bitmap 位图数据
/// @param height 图片高度
+ (UIImage *)image:(NSData *)bitmap height:(size_t)height;
/// 动态获取二值化的阈值
/// @param data 256灰阶数据
/// @param width 图片宽度
/// @param height 图片高度
+ (NSUInteger)getThresholdForBinaryByGrayData:(NSData *)data width:(NSUInteger)width height:(NSUInteger)height;
/// 获取图像的灰度数据
/// @param image 输入数据
+ (NSData *)grayscaleImageForImage:(CGImageRef)image;
@end
@interface PTBitmap(Printer)
+ (NSData *)binaryDataOneBitPerPixelGraylevel256Data:(NSData *)data width:(NSUInteger)width;
+ (NSData *)binaryDataOneBitPerPixelGraylevel256Data:(NSData *)data width:(NSUInteger)width valve:(NSUInteger)valve;
+ (NSData *)ditheredBinaryDataOneBitPerPixelGraylevel256Data:(NSData *)data width:(NSUInteger)width;
+ (NSData *)meiKaLePrinterData:(NSData *)graylevel256Data;
@end

@ -0,0 +1,58 @@
/*!
* \~chinese
* @header PTBitmap.h
* @abstract
*
* \~english
* @header PTBitmap.h
* @abstract Image manager
*/
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#import "SDKDefine.h"
/// 压缩模式
typedef NS_ENUM(NSInteger,PTBitmapCompressMode) {
PTBitmapCompressModeNone = 0, /*! *\~chinese 不压缩 *\~english None */
PTBitmapCompressModeZPL2 = 16, /*! *\~chinese ZPL2压缩算法 *\~english ZPL2 compress */
PTBitmapCompressModeTIFF = 32, /*! *\~chinese TIFF压缩算法 *\~english TIFF compress */
PTBitmapCompressModeLZO = 48, /*! *\~chinese LZO压缩算法 *\~english LZO compress */
};
/// 图片效果
typedef NS_ENUM(NSInteger, PTBitmapMode) {
PTBitmapModeBinary = 0, /*! *\~chinese 黑白二值图像 *\~english Binary */
PTBitmapModeDithering = 1, /*! *\~chinese 灰阶抖动图像 *\~english Dithering */
PTBitmapModeColumn = 2, /*! *\~chinese 无效 *\~english not supported */
};
@interface PTBitmap : NSObject
/// 生成打印机打印图片数据
/// @param image 图片
/// @param mode 图片效果
/// @param compress 压缩模式
/// @param package 数据是否分包
/// @param inversion 数据是否需要取反
+ (NSData *)getImageData:(CGImageRef)image mode:(PTBitmapMode)mode compress:(PTBitmapCompressMode)compress package:(BOOL)package inversion:(BOOL)inversion;
/// 用column算法生成的图片数据
/// @param sourceBitmap 输入数据
+ (NSData *)generateColumnData:(CGImageRef)sourceBitmap;
/// 将bitmap数据转成图片
/// @param image 图片
/// @param mode 生成的位图数据类型 简单的黑白二值化或者抖动处理
+ (UIImage *)generateRenderingWithImage:(CGImageRef)image mode:(PTBitmapMode)mode;
@end

File diff suppressed because it is too large Load Diff

@ -0,0 +1,47 @@
/*!
* \~chinese
* @header PTCommandCommon.h
* @abstract
*
* \~english
* @header PTCommandCommon.h
* @abstract Common Command
*/
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface PTCommandCommon : NSObject
@property(nonatomic, strong) NSMutableData * _Nonnull cmdData;
/// 获取打印机型号,回的数据格式51333142 5400
- (void)getPrinterModelName;
/// 获取打印机固件版本号,版本号返回格式为 X.XX.XX或X.X.X【如1.01.01或1.0.3】
- (void)getPrinterFirmwareVersion;
/// OTA蓝牙固件升级,该功能需要打印机支持
- (void)updateOTABleFirmwareWithData:(NSData *)data;
//=========================固件升级旧的方式=================
/// 打印机固件升级(固定包大小)
/// @param data 固件数据
- (void)updatePrinterFirmwareWithData:(NSData *)data;
//=========================固件升级新的方式=================
/// 获取升级固件每包的大小
- (void)getUpdatePrinterFirmwarePackage;
/// 升级打印机固件
/// @param data 固件数据
/// @param package 每包大小
- (void)updateDeviceFirmwareWithData:(NSData *)data package:(NSInteger)package;
@end
NS_ASSUME_NONNULL_END

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,217 @@
/*!
* \~chinese
* @header PTDispatcher.h
* @abstract
*
* \~english
* @header PTDispatcher.h
* @abstract Protocol
*/
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "SDKDefine.h"
#import "PTPrinter.h"
/// 连接模式
typedef NS_ENUM(NSInteger, PTDispatchMode) {
/// 未知类型
PTDispatchModeUnconnect = 0,
/// 蓝牙
PTDispatchModeBLE = 1,
/// 无线
PTDispatchModeWiFi = 2
};
/// 手机蓝牙状态
typedef NS_ENUM(NSInteger, PTBluetoothState) {
/// 未授权,请前往系统设置授权
PTBluetoothStateUnauthorized = 0,
/// 蓝牙未开
PTBluetoothStatePoweredOff = 1,
/// 正常
PTBluetoothStatePoweredOn = 2,
};
/// 打印完成后打印机返回的状态
typedef NS_ENUM(NSInteger, PTPrintState) {
/// 打印成功
PTPrintStateSuccess = 0xcc00,
/// 打印失败(缺纸)
PTPrintStateFailurePaperEmpty = 0xcc01,
/// 打印失败(开盖)
PTPrintStateFailureLidOpen = 0xcc02
};
/// 返回连接的错误类型
typedef NS_ENUM(NSInteger, PTConnectError) {
/// 连接超时
PTConnectErrorBleTimeout = 0,
/// 获取服务超时
PTConnectErrorBleDisvocerServiceTimeout = 1,
/// 验证超时
PTConnectErrorBleValidateTimeout = 2,
/// 未知设备
PTConnectErrorBleUnknownDevice = 3,
/// 系统错误,由coreBluetooth框架返回
PTConnectErrorBleSystem = 4,
/// 验证失败
PTConnectErrorBleValidateFail = 5,
/// 无线连接超时
PTConnectErrorWifiTimeout = 6,
/// socket错误
PTConnectErrorWifiSocketError = 7
};
/// 返回固件升级错误
typedef NS_ENUM(NSInteger, PTUpgradeFirmwareState) {
/// 升级成功
PTUpgradeFirmwareStateSuccess = 0,
/// 升级失败,数据长度错误
PTUpgradeFirmwareStateFailureDataLengthError,
/// 升级失败,验证或者校验失败
PTUpgradeFirmwareStateFailureValidateFail,
/// 升级失败,写入超时
PTUpgradeFirmwareStateFailureWriteTimout,
/// 升级失败,包序号错误
PTUpgradeFirmwareStateFailurePackageNumberError,
/// 升级失败,包长度错误
PTUpgradeFirmwareStateFailurePackageLengthError,
/// 升级失败,写入失败
PTUpgradeFirmwareStateFailureWriteFail,
/// 升级失败
PTUpgradeFirmwareStateFail
};
@class PTPrinter;
typedef void(^PTPrinterMutableArrayBlock)(NSMutableArray<PTPrinter *> *printerArray);
typedef void(^PTEmptyParameterBlock)(void);
typedef void(^PTBluetoothConnectFailBlock)(PTConnectError error);
typedef void(^PTNumberParameterBlock)(NSNumber *number);
typedef void(^PTDataParameterBlock)(NSData *data);
typedef void(^PTPrintStateBlock)(PTPrintState state);
typedef BOOL(^PTPeripheralFilterBlock)(CBPeripheral *peripheral, NSDictionary<NSString *,id> *advertisementData, NSNumber *RSSI);
typedef void(^PTUnconnectBlock)(NSNumber *number, BOOL isActive);
typedef void(^PTSendSuccessParameterBlock)(int64_t dataCount, double time);
typedef void(^PTUpgradeFirmwareStateBlock)(PTUpgradeFirmwareState state);
@interface PTDispatcher : NSObject
@property (assign, nonatomic) PTDispatchMode mode;
@property (strong, nonatomic, readwrite) PTPrinter *printerConnected; //该属性表示连接后的打印机对象
@property (copy, nonatomic, readwrite) PTSendSuccessParameterBlock sendSuccessBlock;
@property (copy, nonatomic, readwrite) PTEmptyParameterBlock sendFailureBlock;
@property (copy, nonatomic, readwrite) PTNumberParameterBlock sendProgressBlock;
@property (copy, nonatomic, readwrite) PTDataParameterBlock receiveDataBlock;
@property (copy, nonatomic, readwrite) PTPrintStateBlock printStateBlock;
@property (copy, nonatomic, readwrite) PTPrinterMutableArrayBlock findAllPeripheralBlock;
@property (copy, nonatomic, readwrite) PTEmptyParameterBlock connectSuccessBlock;
@property (copy, nonatomic, readwrite) PTBluetoothConnectFailBlock connectFailBlock;
@property (copy, nonatomic, readwrite) PTUnconnectBlock unconnectBlock;
@property (copy, nonatomic, readwrite) PTNumberParameterBlock readRSSIBlock;
@property (copy, nonatomic, readwrite) PTPeripheralFilterBlock peripheralFilterBlock;
@property (copy, nonatomic, readwrite) PTUpgradeFirmwareStateBlock upgradeFirmwareStateBlock;
/// 创建单例对象
+ (instancetype)share;
/// 发送数据
- (void)sendData:(NSData *)data;
/// 暂停发送
- (void)pauseWriteData;
/// 继续发送
- (void)resumeWriteData;
/// 开始扫描蓝牙
- (void)scanBluetooth;
/// 停止扫描蓝牙连接成功后SDK会自动停止扫描
- (void)stopScanBluetooth;
/// 扫描Wi-Fi wifi的端口是9100, 如果需要获得路由的名称以及mac地址信息 ios12+需要Access WiFi Information的权限iOS13+以后要开启定位权限
- (void)scanWiFi:(PTPrinterMutableArrayBlock)wifiAllBlock;
/// 获取已发现的所有打印机
- (void)whenFindAllBluetooth:(PTPrinterMutableArrayBlock)bluetoothBlock;
/// 获取蓝牙的rssi信号强度
- (void)whenReadRSSI:(PTNumberParameterBlock)readRSSIBlock;
/// 连接打印机,传入的是打印机对象
- (void)connectPrinter:(PTPrinter *)printer;
/// 断开打印机连接
- (void)unconnectPrinter:(PTPrinter *)printer;
/// 连接成功回调,连接成功后,会停止扫码设备
- (void)whenConnectSuccess:(PTEmptyParameterBlock)connectSuccessBlock;
/// 连接失败的回调
- (void)whenConnectFailureWithErrorBlock:(PTBluetoothConnectFailBlock)connectFailBlock;
/// 断开连接的回调调用unconnectPrinter断开打印机后会调用该方法
- (void)whenUnconnect:(PTUnconnectBlock)unconnectBlock;
/// 数据发送成功的回调,数据发送完成后,会调用该方法
- (void)whenSendSuccess:(PTSendSuccessParameterBlock)sendSuccessBlock;
/// 数据发送失败的回调
- (void)whenSendFailure:(PTEmptyParameterBlock)sendFailureBlock;
/// 数据发送进度的回调
- (void)whenSendProgressUpdate:(PTNumberParameterBlock)sendProgressBlock;
/// 接收到打印机返回的数据,比如获取打印机名称就是通过该方法返回
- (void)whenReceiveData:(PTDataParameterBlock)receiveDataBlock;
/// 接收到打印机打印状态回调使用该方法前需要保证打印机打开了状态回调的开关比如CPCL指令集中的cpclTurnOnPrintStatusCallBack方法ESC中的turnOnPrintStatusCallBack方法
- (void)whenUpdatePrintState:(PTPrintStateBlock)printStateBlock;
/// 设置蓝牙连接超时时间
- (void)setupBleConnectTimeout:(double)timeout;
/// 设置外设过滤,在发现打印机设备的回调中进行一些过滤,返回自己想要的机型
- (void)setupPeripheralFilter:(PTPeripheralFilterBlock)block;
/// 注册蓝牙中心该接口用于兼容你自己实现的CoreBluetooth框架
- (void)registerCentralManager:(CBCentralManager *)manager delegate:(id<CBCentralManagerDelegate>)delegate;
/// 注销代理
- (void)unregisterDelegate;
/// 升级固件状态回调
- (void)whenUpgradeFirmwareStateBlock:(PTUpgradeFirmwareStateBlock)upgradeFirmwareStateBlock;
/// 手机的蓝牙状态,为了准确获取手机蓝牙状态需要在app启动的时候初始化PTDispatcher
- (PTBluetoothState)getBluetoothStatus;
/// SDK打包时间
- (NSString *)SDKBuildTime;
@end

@ -0,0 +1,88 @@
/*!
* \~chinese
* @header PTEncode.h
* @abstract
*
* \~english
* @header PTEncode.h
* @abstract Coding and decoding
*/
#import <Foundation/Foundation.h>
@interface PTEncode : NSObject
/*!
* \~chinese
* GBK
*
* @param string
*
* @return
*
* \~english
* Encodedefault:GBK
*
* @param string String to be encoded
*
* @return Encoded data
*/
+ (NSData *)encodeDataWithString:(NSString *)string;
/*!
* \~chinese
* ,default:GBK
*
* @param data
*
* @return
*
* \~english
* Decoding,default:GBK
*
* @param data Data to be decoded
*
* @return Decoded data
*/
+ (NSString *)decodeStringWithData:(NSData *)data;
/*!
* \~chinese
*
*
* @param string
* @param encodeType
*
* @return
*
* \~english
* Support various encoding.
*
* @param string String to be encoded
* @param encodeType Encode type
*
* @return Encoded data
*/
+ (NSData *)encodeDataWithString:(NSString *)string encodingType:(CFStringEncodings)encodeType;
/*!
* \~chinese
*
*
* @param data
* @param encodeType
*
* @return
*
* \~english
* Support various decoding.
*
* @param data Data to be decoded
* @param encodeType Encode type
*
* @return Decoded data
*/
+ (NSString *)decodeDataWithString:(NSData *)data encodingType:(CFStringEncodings)encodeType;
@end

@ -0,0 +1,231 @@
/*!
* \~chinese
* @header PTLabel.h
* @abstract
*
* \~english
* @header PTLabel.h
* @abstract Express template
*/
#import <Foundation/Foundation.h>
/*!
* \~chinese
* @brief 使 1.使使2. @""3.
*
* \~english
* @brief By using electronic waybill template, only filling in it accordingly can send and print it outNote 1. When using template to print, you should fill in all the blanks as the template sample showed.2.If there is null data, e.g. claiming value is null, please input null character string @"".3.The data to fill in differs depending on the template, please subject to the sample showed.
*/
@interface PTLabel : NSObject
/*!
* \~chinese
*
*
* \~english
* Express company
*/
@property(strong,nonatomic,readwrite) NSString *express_company;
/*!
* \~chinese
*
*
* \~english
* Delivery number
*/
@property(strong,nonatomic,readwrite) NSString *delivery_number;
/*!
* \~chinese
*
*
* \~english
* Order number
*/
@property(strong,nonatomic,readwrite) NSString *order_number;
/*!
* \~chinese
*
*
* \~english
* Distributing
*/
@property(strong,nonatomic,readwrite) NSString *distributing;
/*!
* \~chinese
*
*
* \~english
* Barcode
*/
@property(strong,nonatomic,readwrite) NSString *barcode;
/*!
* \~chinese
*
*
* \~english
* The character below the bar code
*/
@property(strong,nonatomic,readwrite) NSString *barcode_text;
/*!
* \~chinese
*
*
* \~english
* QRcode
*/
@property(strong,nonatomic,readwrite) NSString *qrcode;
/*!
* \~chinese
*
*
* \~english
* The character below the QR code
*/
@property(strong,nonatomic,readwrite) NSString *qrcode_text;
/*!
* \~chinese
*
*
* \~english
* Recipient name
*/
@property(strong,nonatomic,readwrite) NSString *receiver_name;
/*!
* \~chinese
*
*
* \~english
* Recipient phone
*/
@property(strong,nonatomic,readwrite) NSString *receiver_phone;
/*!
* \~chinese
*
*
* \~english
* Recipient address
*/
@property(strong,nonatomic,readwrite) NSString *receiver_address;
/*!
* \~chinese
*
*
* \~english
* Recipient Information
*/
@property(strong,nonatomic,readwrite) NSString *receiver_message;
/*!
* \~chinese
*
*
* \~english
* Sender name
*/
@property(strong,nonatomic,readwrite) NSString *sender_name;
/*!
* \~chinese
*
*
* \~english
* Sender phone
*/
@property(strong,nonatomic,readwrite) NSString *sender_phone;
/*!
* \~chinese
*
*
* \~english
* Sender address
*/
@property(strong,nonatomic,readwrite) NSString *sender_address;
/*!
* \~chinese
*
*
* \~english
* Sender information
*/
@property(strong,nonatomic,readwrite) NSString *sender_message;
/*!
* \~chinese
*
*
* \~english
* Item name
*/
@property(strong,nonatomic,readwrite) NSString *article_name;
/*!
* \~chinese
*
*
* \~english
* Item weight
*/
@property(strong,nonatomic,readwrite) NSString *article_weight;
/*!
* \~chinese
*
*
* \~english
* Affirmation value
*/
@property(strong,nonatomic,readwrite) NSString *amount_declare;
/*!
* \~chinese
*
*
* \~english
* Payment amount
*/
@property(strong,nonatomic,readwrite) NSString *amount_paid;
/*!
* \~chinese
*
*
* \~english
* Prepayment amount
*/
@property(strong,nonatomic,readwrite) NSString *amount_paid_advance;
/// 由模板数据生成下发给打印机的数据
/// @param filePath 模板路径
- (NSData *)dataWithSourceFile:(NSString *)filePath;
/// 生成TSPL指令的数据
- (NSData *)dataWithTSPL;
/// 由模板数据生成下发给打印机的数据
/// @param source 资源
/// @param labelDict 模板定义的key
/// @param orderDetails 订单详情
- (NSData *)getTemplateData:(NSString *)source labelDict:(NSDictionary *)labelDict orderDetails:(NSArray *)orderDetails;
/// 由模板数据生成下发给打印机的数据
/// @param source 资源
/// @param labelDict 模板定义的key
- (NSData *)getTemplateData:(NSString *)source labelDict:(NSDictionary *)labelDict;
@end

@ -0,0 +1,632 @@
/*!
* \~chinese
* SDK3.0.0使SDK
*
* \~english
* This class is a version before SDK3.0.0. Since many customers still use the previous SDK, after optimizing the interface and making too much change, use a class to retain the previous interface.
*/
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface PTOldCommandCPCL : NSObject
@property(strong,nonatomic,readwrite) NSMutableData * _Nonnull cmdData;
@property (nonatomic, assign) NSStringEncoding encoding;
- (void)appendCommand:(NSString * _Nonnull)cmd;
- (void)appendCommandData:(NSData * _Nonnull)data;
/**
selfTest
*/
- (void)printSelfInspectionPage;
/**
get printer status.
*/
- (void)cpclGetPaperStatus;
/**
turn on/off print status callback.
@param flag on/off
*/
- (void)cpclTurnOnPrintStatusCallBack:(BOOL)flag;
/**
线
Turn on underline
*/
- (void)cpclUnderlineON;
/**
线
Turn off underline
*/
- (void)cpclUnderlineOFF;
- (void)cpclUtilitySession;
/** 行模式指令前缀 Command prefix of line mode */
- (void)cpclLineMode;
- (void)cpclReWindOFF;
/**
SN get printer serial number.
*/
- (void)cpclGetPrinterSN;
/**
* 1 Set the paper type
*
* @param type (0~5)
0: continuous paper
1 Label paper
2 Back black mark
3 Front black mark
43 3 inch black mark
52 2 inch black mark
*/
- (void)cpclPaperTypeWithType:(NSInteger )type;
/**
* 2 Set the paper type
*
* @param type (0~5)
0: continuous paper
2 Label paper
42 2 inch black mark
53 3 inch black mark
64 4 inch black mark
*/
- (void)setPrinterPaperTypeFor4Inch:(NSInteger)type;
/**
Set Label
@param offset The number of units to offset all fields from the left side of the label horizontally. 0-65535
@param hRes The horizontal resolution of this label, expressed in dots per inch. 100 or 200
@param vRes The vertical resolution of this label, expressed in dots per inch. 100 or 200
@param height The height of the label in units. 0-65535
@param quantity The number of copies of the label to print. 0-1024
*/
- (void)cpclLabelWithOffset:(NSInteger)offset
hRes:(NSInteger)hRes
vRes:(NSInteger)vRes
height:(NSInteger)height
quantity:(NSInteger)quantity;
/**
Barcode
@param type The type of barcode to print.
@param width The width of a narrow bar.
@param ratio The ratio of wide to narrow bars. 0-420-30
@param height The height of the barcode.
@param x The X position where the barcode begins
@param y The Y position where the barcode begins
@param barcode The data to be encoded into a barcode
*/
- (void)cpclBarcode:(NSString * _Nonnull)type
width:(NSInteger)width
ratio:(NSInteger)ratio
height:(NSInteger)height
x:(NSInteger)x
y:(NSInteger)y
barcode:(NSString * _Nonnull)barcode;
/**
VBarcode
@param type The type of barcode to print.
@param width The width of a narrow bar.
@param ratio The ratio of wide to narrow bars.
@param height The height of the barcode.
@param x The X position where the barcode begins
@param y The Y position where the barcode begins
@param barcode The data to be encoded into a barcode
*/
- (void)cpclBarcodeVertical:(NSString * _Nonnull)type
width:(NSInteger)width
ratio:(NSInteger)ratio
height:(NSInteger)height
x:(NSInteger)x
y:(NSInteger)y
barcode:(NSString * _Nonnull)barcode;
/**
BarcodeQR
@param xPos The X position where the barcode begins
@param yPos The Y position where the barcode begins
@param model The ratio of wide to narrow bars:1 or 2
@param unitWidth Unit-width of the barcode in dots 1-32,6
*/
- (void)cpclBarcodeQRcodeWithXPos:(NSInteger)xPos
yPos:(NSInteger)yPos
model:(NSInteger)model
unitWidth:(NSInteger)unitWidth;
/**
VBarcodeQR
@param xPos The X position where the barcode begins
@param yPos The Y position where the barcode begins
@param model The ratio of wide to narrow bars:1 or 2
@param unitWidth Unit-width of the barcode in dots
*/
- (void)cpclBarcodeQRcodeVerticalWithXPos:(NSInteger)xPos
yPos:(NSInteger)yPos
model:(NSInteger)model
unitWidth:(NSInteger)unitWidth;
/**
QR Data
@param data Data for barcode
@param config Configuration options for barcode:MN:nunber,MA:Numbers or letters
*/
- (void)cpclBarcodeQRcodeData:(NSString * _Nonnull)data config:(NSString * _Nonnull)config;
/**
The QR code terminator.
*/
- (void)cpclBarcodeQRcodeEnd;
/**
BARCODE-TEXT
@param font A font name or number to create the representation
@param fontSize The size of the font: 0-999
@param offset How far in units the text is from the barcode:0-999
*/
- (void)cpclBarcodeTextWithFont:(NSInteger)font
fontSize:(NSInteger)fontSize
offset:(NSInteger)offset;
/**
BARCODE-TEXT
@param font The filename of the TTF font with extension
@param xScale The X size of the font, in dots: 0-999
@param yScale The Y size of the font, in dots: 0-999
@param offset How far in units the text is from the barcode: 0-999
*/
- (void)cpclBarcodeTextWithTrueTypeFont:(NSInteger)font
xScale:(NSInteger)xScale
yScale:(NSInteger)yScale
offset:(NSInteger)offset;
/**
off barcodeText
*/
- (void)cpclBarcodeTextOff;
/**
* Draw rectangle
*
* @param xPos (0~65535)
* @param yPos (0~65535)
* @param xEnd (0~65535)
* @param yEnd (0~65535)
* @param thickness (0~65535)
*/
- (void)cpclBoxWithXPos:(NSInteger)xPos
yPos:(NSInteger)yPos
xEnd:(NSInteger)xEnd
yEnd:(NSInteger)yEnd
thickness:(NSInteger)thickness;
- (void)cpclCenterWithRange:(NSInteger)range;
- (void)cpclCenter;
- (void)cpclCompressedGraphicsWithImageWidth:(NSInteger)imageWidth
imageHeight:(NSInteger)imageHeight
x:(NSInteger)x
y:(NSInteger)y
bitmapData:(NSData * _Nonnull)bitmapData;
- (void)cpclConcatStartWithXPos:(NSInteger)xPos yPos:(NSInteger)yPos;
- (void)cpclConcatVerticalStartWithXPos:(NSInteger)xPos yPos:(NSInteger)yPos;
/** 字段拼接 Field combination */
- (void)cpclConcatTextWithFont:(NSInteger)font
fontSize:(NSInteger)fontSize
offset:(NSInteger)offset
text:(NSString * _Nonnull)text;
- (void)cpclConcatScaleTextWithScaledFont:(NSInteger)scaledFont
xScale:(NSInteger)xScale
yScale:(NSInteger)yScale
offset:(NSInteger)offset
text:(NSString * _Nonnull)text;
- (void)cpclConcatScaleTextVerticalWithScaledFont:(NSInteger)scaledFont
xScale:(NSInteger)xScale
yScale:(NSInteger)yScale
offset:(NSInteger)offset
text:(NSString * _Nonnull)text;
- (void)cpclConcatTextWithFontGroup:(NSInteger)fontGroup
offset:(NSInteger)offset
text:(NSString * _Nonnull)text;
- (void)cpclConcatEnd;
- (void)cpclPrint;
/** 反向打印 Reverse print */
- (void)cpclPoPrint;
/**
@param xPos x
@param yPos y
@param xEnd x
@param yEnd y
@param thickness
*/
- (void)cpclInverseLineWithXPos:(NSInteger)xPos
yPos:(NSInteger)yPos
xEnd:(NSInteger)xEnd
yEnd:(NSInteger)yEnd
thickness:(NSInteger)thickness;
- (void)cpclLeft:(NSInteger)range;
- (void)cpclLeft;
- (void)cpclLineWithXPos:(NSInteger)xPos
yPos:(NSInteger)yPos
xEnd:(NSInteger)xEnd
yEnd:(NSInteger)yEnd
thickness:(NSInteger)thickness;
- (void)cpclMoveWithRight:(NSInteger)right up:(NSString * _Nonnull)up;
- (void)cpclMultiLineStartWithLineHeight:(NSInteger)lineHeight;
- (void)cpclMultiLineEnd;
- (void)cpclPageWidth:(NSInteger)pageWidth;
- (void)cpclRight:(NSInteger)right;
- (void)cpclRight;
- (void)cpclRotate:(NSInteger)degrees;
- (void)cpclScaleText:(NSString * _Nonnull)scaledFont
xScale:(NSInteger)xScale
yScale:(NSInteger)yScale
x:(NSInteger)x
y:(NSInteger)y
text:(NSString * _Nonnull)text;
- (void)cpclScaleTextVertical:(NSString * _Nonnull)scaledFont
xScale:(NSInteger)xScale
yScale:(NSInteger)yScale
x:(NSInteger)x
y:(NSInteger)y
text:(NSString * _Nonnull)text;
- (void)cpclScaleToFit:(NSString * _Nonnull)scaleFont
width:(NSInteger)width
height:(NSInteger)height
x:(NSInteger)x
y:(NSInteger)y
text:(NSString * _Nonnull)text;
/**
Set the font bold
@param boldness bold value, 0 is not bold
*/
- (void)cpclSetBold:(NSInteger)boldness;
/**
Set character spacing
@param spacing character spacing
*/
- (void)cpclSetSpacing:(NSInteger)spacing;
/**
Set font magnification multiple
@param width magnification multiple of width
@param height magnification multiple of height
*/
- (void)cpclSetMagWithWidth:(NSInteger)width height:(NSInteger)height;
- (void)cpclTempMove:(NSInteger)right up:(NSInteger)up;
/*
font english chinese
1 9x24 24x24
2 8x24 24x24
3 10x20 20x20
4 16x32 32x32
5 12x24 24x24
7 12x24 24x24
8 12x24 12x24
20 8x18 18x18
28 14x28 28x28
55 8x16 16x16
*/
/*!
*
* .
*
* @param rotate :090180270
* @param font 1234578202855
* @param fontSize
* @param x x
* @param y y
* @param safeHeight ,
* @param width ,0
* @param lineSpacing
* @param fontScale
* @param text
* @return
*
*/
- (NSInteger)cpclAutoTextWithRotate:(NSInteger)rotate
font:(NSInteger)font
fontSize:(NSInteger)fontSize
x:(NSInteger)x
y:(NSInteger)y
safeHeight:(NSInteger)safeHeight
width:(NSInteger)width
lineSpacing:(NSInteger)lineSpacing
fontScale:(NSInteger)fontScale
text:(NSString * _Nonnull)text;
/*!
*
* ,90,90\270cpclCenter
*
* @param rotate
* @param font
* @param fontSize
* @param xPos x
* @param yPos y
* @param center
* @param safeHeight ,
* @param width ,0
* @param lineSpacing .
* @param fontScale
* @param text
* @return
*/
- (NSInteger)cpclAutoTextWithRotate:(NSInteger)rotate
font:(NSInteger)font
fontSize:(NSInteger)fontSize
xPos:(NSInteger)xPos
yPos:(NSInteger)yPos
center:(BOOL)center
safeHeight:(NSInteger)safeHeight
width:(NSInteger)width
lineSpacing:(NSInteger)lineSpacing
fontScale:(NSInteger)fontScale
text:(NSString * _Nonnull)text;
/**
Thai Auto
@param font 0:big font 1:small font
@param fontSize fontSize
@param x x-coordinate of start point
@param y y-coordinate of start point
@param lineSpace Line spacing for automatic line feed 30
@param width Print width 0x+widthw,width=w-x
@param text text
*/
- (void)cpclAutoThaiTextWithFont:(NSInteger)font
fontSize:(NSInteger)fontSize
x:(NSInteger)x
y:(NSInteger)y
lineSpace:(NSInteger)lineSpace
width:(NSInteger)width
text:(NSString * _Nonnull)text;
/**
Print center text
@param rotate : rotation angle
@param font 1 2 3 4 8 55 :font size, temporarily supports 1 2 3 4 8 55
@param fontSize : font size
@param x x : x-coordinate of start point
@param y y : y-coordinate of start point
@param width : width of textbox
@param text : content of text
*/
- (void)cpclCenterTextWithRotate:(NSInteger)rotate
font:(NSInteger)font
fontSize:(NSInteger)fontSize
x:(NSInteger)x
y:(NSInteger)y
width:(NSInteger)width
text:(NSString * _Nonnull)text;
/**
Print text
@param rotate : rotation angle of text
@param font : font number
@param fontSize : font size, cannot be used temporarily
@param x x : x-coordinate of start point
@param y y : y-coordinate of start point
@param text : content of text
*/
- (void)cpclTextWithRotate:(NSInteger)rotate
font:(NSInteger)font
fontSize:(NSInteger)fontSize
x:(NSInteger)x
y:(NSInteger)y
text:(NSString * _Nonnull)text;
//反白
- (void)cpclTextReverseWithFont:(NSInteger)font
fontSize:(NSInteger)fontSize
x:(NSInteger)x
y:(NSInteger)y
text:(NSString * _Nonnull)text;
// 反白 加粗 Reverse bold
/**
| Font | Chinese | ASCII character (English, number, etc.) |
| Font | | ASCII |
| ---- | ----- | --------------- |
| 1 | 24*24 | 9*17 |
| 2 | 24*24 | 8*16 |
| 3 | 20*20 | 10*20 |
| 4 | 32*32 | 16*32 |
| 8 | 24*24 | 12*24 |
| 55 | 16*16 | 8*16 |
rotate: 0 90 180 270
*/
- (void)appendTextWithFont:(NSInteger)font
rotate:(NSInteger)rotate
fontSize:(NSInteger)fontSize
reverse:(BOOL)reverse
bold:(NSInteger)bold
x:(NSInteger)x
y:(NSInteger)y
text:(NSString * _Nonnull)text;
/**
Set Background
@param value 0~255,n=0:normal
*/
- (void)cpclSetBackground:(NSInteger)value;
/**
set back text
@param font 1,2,3,4,8,55
@param rotate 0 90 180 270
@param fontSize Size identifier for the font
@param xPos x-coordinate of start point
@param yPos y-coordinate of start point
@param text The text data to be printed
*/
- (void)cpclBackTextWithFont:(NSInteger)font
rotate:(NSInteger)rotate
fontSize:(NSInteger)fontSize
xPos:(NSInteger)xPos
yPos:(NSInteger)yPos
text:(NSString *_Nonnull)text;
/***************** Line Print Commands *******************/
- (void)cpclLineMargin:(NSInteger)offset;
- (void)cpclSetPositionWithXPos:(NSInteger)xPos yPos:(NSInteger)yPos;
- (void)cpclSetPositionWithXPos:(NSInteger)xPos;
- (void)cpclSetPositionWithYPos:(NSInteger)yPos;
/**
lineFeed
*/
- (void)cpclLineFeed;
- (void)cpclContrast:(NSInteger)value;
- (void)cpclFeed:(NSInteger)amount;
- (void)cpclLabel;
- (void)cpclMulti:(NSInteger)quantity;
- (void)cpclNoPace;
- (void)cpclPace;
- (void)cpclPostFeed:(NSInteger)amount;
- (void)cpclPreFeed:(NSInteger)amount;
- (void)cpclReverse:(NSInteger)amount;
- (void)cpclSetFeed:(NSInteger)length skip:(NSInteger)skip;
/**
set the maximum speed
@param value 0-5
*/
- (void)cpclSpeed:(NSInteger)value;
//Take the paper to the next label
- (void)cpclForm;
- (void)cpclTone:(NSInteger)value;
- (void)cpclTurn:(NSInteger)degrees;
- (void)cpclFormFeed;
/****************** Utility and Diagnostic Commands ****************/
- (void)cpclAbort;
- (void)cpclOnFeed_Feed;
- (void)cpclOnFeed_Reprint;
- (void)cpclOnFeed_Ignore;
- (void)cpclReRun;
- (void)cpclWait:(NSInteger)duration;
- (void)cpclSetLabelPositionWithXPos:(NSInteger)xPos yPos:(NSInteger)yPos;
- (void)cpclSetLabelPositionWithXPos:(NSInteger)xPos;
- (void)cpclSetLabelPositionWithYPos:(NSInteger)yPos;
/****************** Codepage Commands ****************/
/**
SetCharacterCodePage
@param codepage parameter
eg:
"USA" "FRANCE" "GERMANY" "UK" "DENMARK" "SWEDEN" "ITALY" "SPAIN" "JAPAN-S" "NORWAY" "DENMARK II" "SPAIN II" "LATIN9" "KOREA" "SLOVENIA" "CHINA" "BIG5" "CP874" "CP850" "CP437" "CP860" "CP863" "CP865" "CP866" "CP852" "CP858" "CP857" "CP737" "CP720" "CP775" "CP855" "CP862" "CP864" "ISO8859-6" "ISO8859-8" "ISO8859-9" "ISO8859-15" "WPC1252" "WPC1250" "WPC1251" "WPC1252" "WPC1254" "WPC1255" "WPC1256" "ISO8859-1" "ISO8859-2" "ISO8859-3" "ISO8859-4" "ISO8859-5" "TIS11" "TIS18"
*/
- (void)cpclSetCharacterCodePage:(NSString *_Nonnull)codepage;
/**
,
@param function 48 491502513
*/
- (void)cpclSetArabicTransformFunction:(NSInteger)function;
/**
00 00 01 001 02 002 03 003
*/
- (void)cpclGetArabicTransformStatus;
/**
@param status 48close 49:open
*/
- (void)cpclSetThaiTransformStatus:(NSInteger)status;
/**
@param function 48 49ASCII 50UTF-8
*/
- (void)cpclSetVietnameseTransformFunction:(NSInteger)function;
/**
00 00 01 00ASCII 02 00UTF-8
*/
- (void)cpclGetVietnameseTransformStatus;
/// 升级打印机固件
/// @param data 固件数据
- (void)updatePrinterFirmwareWithData:(NSData *_Nonnull)data;
@end
NS_ASSUME_NONNULL_END

@ -0,0 +1,649 @@
/*!
* \~chinese
* SDK3.0.0使SDK
*
* \~english
* This class is a version before SDK3.0.0. Since many customers still use the previous SDK, after optimizing the interface and making too much change, use a class to retain the previous interface.
*/
#import <Foundation/Foundation.h>
#import "SDKDefine.h"
#import "PTBitmap.h"
NS_ASSUME_NONNULL_BEGIN
@interface PTOldCommandTSPL : NSObject
@property(strong,nonatomic,readwrite) NSMutableData *cmdData;
@property (nonatomic, assign) NSStringEncoding encoding;
/**
* printer print self-test message.
*
*/
- (void)selfTest;
- (void)appendCommand:(NSString *)cmd;
/** 打印并走纸一行
* Print and feed one line
*/
- (void)printAndLineFeed;
/**
set font bold
@param bold 0 1
*/
- (void)setFontBold:(NSInteger)bold;
/**
104(aa bb cc dd) + 4() + 1 + 00
eg:1.aabbccdd 03000000 2000
2.aabbccdd ffffffff 0000 aabbccdd 00000000 0000
@param status 1 3
*/
- (void)setPrinterStateAutomaticBackWithStatus:(NSInteger)status;
/**
* setting print area size in paper.
*
*/
- (void)setPrintAreaSizeWithWidth:(NSInteger)label_width
Height:(NSInteger)label_height;
/**
get print status
bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0
1 1 1 1 1 1 1 1
*/
- (void)getPrinterStatus;
/**
* setting gap distance during labels.
*
*
* @param distance
* @param offset
*/
- (void)setGapWithDistance:(NSInteger)distance
Offset:(NSInteger)offset;
/**
* setting black line
* 线
*
* @param height 线 0~25.4 mm
* @param offset 线 0~label length
* height,offset 0,0
*/
- (void)setBlineWithHeight:(NSInteger)height
Offset:(NSInteger)offset;
/**
* paper feed with distance.
*
*/
- (void)setOffsetWithDistance:(NSInteger)distance;
/**
* setting print sets and copies.
*
*
* @param sets how many sets of labels will be printed.
* @param copies how many copies should be printed for each particular label set.
*/
- (void)printWithSets:(NSInteger)sets Copies:(NSInteger)copies;
/**
@param x_pos x
@param y_pos y
@param font 1-91-8 99
@param rotation
@param x_multiplication font1-8 font9eg24
@param y_multiplication font1-8 font9eg24
@param safeHeight
@param width 0
@param lineSpacing
@param text
@return
*/
- (NSInteger)printAutoTextForVectorWithXpos:(NSInteger)x_pos
yPos:(NSInteger)y_pos
font:(NSInteger)font
rotation:(NSInteger)rotation
xMultiplication:(NSInteger)x_multiplication
yMultiplication:(NSInteger)y_multiplication
safeHeight:(NSInteger)safeHeight
width:(NSInteger)width
lineSpacing:(NSInteger)lineSpacing
text:(NSString *)text;
/**
@param x_pos x
@param y_pos y
@param font 0-1012x24 24x24 1:8x16 16x16
@param rotation
@param x_multiplication :1-10
@param y_multiplication :1-10
@param safeHeight
@param width 0
@param lineSpacing
@param text
@return
*/
- (NSInteger)printAutoTextWithXpos:(NSInteger)x_pos
yPos:(NSInteger)y_pos
font:(NSInteger)font
rotation:(NSInteger)rotation
xMultiplication:(NSInteger)x_multiplication
yMultiplication:(NSInteger)y_multiplication
safeHeight:(NSInteger)safeHeight
width:(NSInteger)width
lineSpacing:(NSInteger)lineSpacing
text:(NSString *)text;
/**
@param x_pos x
@param y_pos y
@param font 0-8 9
@param rotation 0 90 180 270
@param x_multiplication 1-10 40-80()
@param y_multiplication 1-10 40-80()
@param text
*/
- (void)appendTextWithXpos:(NSInteger)x_pos
Ypos:(NSInteger)y_pos
Font:(NSInteger)font
Rotation:(NSInteger)rotation
Xmultiplication:(NSInteger)x_multiplication
Ymultiplication:(NSInteger)y_multiplication
Text:(NSString *)text;
/**
* clean printer buffer.
*
*/
- (void)setCLS;
/**
* print barcode.
*
*
* @param type bar code type @[128,128M,EAN128,25,25C,39,29S,93,EAN13,EAN13+2,EAN13+5,EAN8,EAN8+5,CODA,POST,UPCA,UPCA+2,UPCA+5,UPCE,UPCE+2,UPCE+5,CPOST,MSI,MSIC,PLESSEY,ITF14,EAN14,11];
* @param readable 01 whether it is readable0: unreadable; 1: readable
* @param rotation rotation090180270
* @param narrow narrow element
* @param wide wide element
*/
/**
print barcode.
eg:100,100,39,96,1,0,2,4,1000 10,10,128M,48,1,0,2,2,!104!096ABCD!101EFGH
@param x_pos Specify the x-coordinate of the bar code on the label
@param y_pos Specify the y-coordinate of the bar code on the label
@param type bar code type @[128,128M,EAN128,25,25C,39,29S,93,EAN13,EAN13+2,EAN13+5,EAN8,EAN8+5,CODA,POST,UPCA,UPCA+2,UPCA+5,UPCE,UPCE+2,UPCE+5,CPOST,MSI,MSIC,PLESSEY,ITF14,EAN14,11];
@param height Bar code height (in dots)
@param readable 01 whether it is readable0: unreadable; 1: readable
@param rotation rotation090180270
@param narrow narrow element
@param wide wide element
@param codeNumber the maximum number of digits of bar code content
*/
- (void)printBarcodeWithXPos:(NSInteger)x_pos
YPos:(NSInteger)y_pos
Type:(NSString *)type
Height:(NSInteger)height
HumanReadable:(NSInteger)readable
Rotation:(NSInteger)rotation
Narrow:(NSInteger)narrow
Wide:(NSInteger)wide
CodeNumber:(NSString *)codeNumber;
/**
print QRCode
eg:100,10,L,7,M,0,M1,S1,"ATHE FIRMWARE HAS BEEN UPDATED"
@param x_pos The upper left corner x-coordinate of the QR code
@param y_pos The upper left corner y-coordinate of the QR code
@param ecc_level Error correction recovery level
L :7% M :15% Q : 25% H : 30%
@param width 1~10
@param mode A/M A:Auto M:Manual
@param rotation 0 90 180 270
@param model M1: (default), original version M2: enhanced version
@param mask S0~S8, default is S7
@param text The encodable character set is described as below
*/
- (void)printQRcodeWithXPos:(NSInteger)x_pos
YPos:(NSInteger)y_pos
EccLevel:(NSString *)ecc_level
CellWidth:(NSInteger)width
Mode:(NSString *)mode
Rotation:(NSInteger)rotation
Model:(NSString *)model
Mask:(NSString *)mask
Text:(NSString *)text;
/**
Print Bitmap
,SDK
@param xpos Specify the x-coordinate
@param ypos Specify the y-coordinate
@param mode mode Graphic modes listed below: 0:OVERWRITE 1:OR 2:XOR 3:compress 16:OVERWRITE compress 17:OR compress 18:XOR compress
@param image image
@param bitmapMode binary/dithering
@param compress TIFF/ZPL2/LZO/None
@return The data is less than the cache and can be printed NO:The data exceeds the cache and cannot be printed
*/
- (BOOL)addBitmapWithXPos:(NSInteger)xpos
YPos:(NSInteger)ypos
Mode:(NSInteger)mode
image:(CGImageRef)image
bitmapMode:(PTBitmapMode)bitmapMode
compress:(PTBitmapCompressMode)compress;
#pragma mark BasicSetting 基本设定
/**
* setting print speed
*
*
*/
- (void)setSpeed:(NSInteger)speed;
/**
* setting print density
*
*
* @param density 0~15 level
*/
- (void)setDensity:(NSInteger)density;
/**
* setting print direction and mirror.
*
*
* @param direction 01
* @param mirror 0 1
*/
- (void)setDirection:(NSInteger)direction Mirror:(NSInteger)mirror;
/**
* setting print reference position
*
*
*/
- (void)setReferenceXPos:(NSInteger)x_pos
YPos:(NSInteger)y_pos;
/**
* page 18.
* setting the code page of inernational character set.
7-bit code page name:
USA: USA
BRI: British
GER: German
FRE: French
DAN: Danish
ITA: Italian
SPA: Spanish
SWE: Swedish
SWI: Swiss
8-bit code page number:
437: United States
850: Multilingual
852: Slavic
860: Portuguese
863: Canadian/French
865: Nordic
857: Turkish (TSPL2 printers only)
Windows code page:
1250: Central Europe (TSPL2 printers only)
1252: Latin I (TSPL2 printers only)
1253: Greek (TSPL2 printers only)
1254: Turkish (TSPL2 printers only)
*
* @param codepage
*/
- (void)setCodePage:(NSString *)codepage;
/**
* page 21.
* feed label with the specified length.
*
* @param feedLength (1~9999)
*/
- (void)setFeedLength:(NSInteger)feedLength;
/**
* feed label to the beginning of next label.
*/
- (void)setFormFeed;
/** 回纸 */
- (void)setBackFeed:(NSInteger)distance;
- (void)setBackUP:(NSInteger)distance;
/**
* page 25.
* feed label until the internal sensor has determined the origin.
*/
- (void)setHome;
/**
* page 28.
* control the sound frequency of the beeper.
*
* @param level 0-9
* @param interval 1-4095
*/
- (void)setSoundWithLevel:(NSInteger)level
Interval:(NSInteger)interval;
/**
* page 29.
* activate the cutter to immediately cut the labels without back feeding the label.
*/
- (void)setCut;
/**
* page 30.
*
*/
- (void)setLimitFeed:(NSInteger)max_len;
/**
* page 32.
* draw a bar on the label format.线
*/
- (void)printBarWithXPos:(NSInteger)x_pos
YPos:(NSInteger)y_pos
Width:(NSInteger)width
Height:(NSInteger)height;
/**
* page 39.
* draw rectangles on the label.
* @param thickness 线
*/
- (void)setBoxWithXStart:(NSInteger)x_start
YStart:(NSInteger)y_start
XEnd:(NSInteger)x_end
YEnd:(NSInteger)y_end
Thickness:(NSInteger)thickness;
/** 在标签上绘制椭圆 */
- (void)setEllipseWithXStart:(NSInteger)x_start
YStart:(NSInteger)y_start
Width:(NSInteger)width
Height:(NSInteger)height
Thickness:(NSInteger)thickness;
/**
* page 41.
* draw a circle on the label.
*
* @param diameter
* @param thickness 线
*/
- (void)setCircleWithXStart:(NSInteger)x_start
YStart:(NSInteger)y_start
Diameter:(NSInteger)diameter
Thickness:(NSInteger)thickness;
/**
* page 43.
* clear a specified region in the image buffer.
*/
- (void)setEraseWithXStart:(NSInteger)x_start
YStart:(NSInteger)y_start
XWidth:(NSInteger)x_width
YHeight:(NSInteger)y_height;
/**
* page 42.
* define the DataMatrix 2D bar code.Currently,only ECC200 error correction is supported.
* DataMatrix ECC200
*
* @param xm []Module sizex6x8
* @param row []10-144
* @param col []10-144
* @param expression
*/
- (void)setDmatrixWithExpression:(NSString *)expression
XPos:(NSInteger)x_pos
YPos:(NSInteger)y_pos
Width:(NSInteger)width
Height:(NSInteger)height
XM:(NSString *)xm
Row:(NSString *)row
Col:(NSString *)col;
/**
* page 44.
* define a 2D Maxicode. Maxicode
*
* @param mode 2,3,4,5
* @param iClass [option],Class of Service ,3-digit number(for mode 2,3)
* @param country [option],Country code, 3-digit number (for mode 2,3)
* @param post [option],
Mode 2: (USA) 5-digit+ 4-digit number.
Mode 3: (Canada) 6 alphanumeric post code included by double quotes.
* @param lm Expression length (double quote is ignored) , 1-138, (this parameter is just for mode 4 and 5.)
*/
- (void)setMaxicode:(NSString *)text
XPos:(NSInteger)x_pos
YPos:(NSInteger)y_pos
Mode:(NSInteger)mode
Class:(NSInteger)iClass
Country:(NSInteger)country
Post:(NSString *)post
LM:(NSInteger)lm;
/**
*
* page 46.
* define a PDF417 2D barcode.
[Option]
P Data compression method
0: Auto encoding
1: Binary mode
E Error correction level. Range: 0~8 Center pattern in barcode area
0: The pattern will print upper left justified the area
1: The pattern is printed middle of area
Ux,y,c Human readable
x: Human readable characters in the specified x-coordinate
y: Human readable characters in the specified y-coordinate
c: Maximum characters of human readable character per line
W Module width in dot. Range: 2~9
H Bar height in dot. Range: 4~99
R Maximum number of rows
C Maximum number of columns
T Truncation.
0: Not truncated
1: Truncated
* @param option
*/
- (void)printPDF417WithXPos:(NSInteger)x_pos
YPos:(NSInteger)y_pos
Width:(NSInteger)width
Height:(NSInteger)height
Rotate:(NSInteger)rotate
Option:(NSString *)option
Expression:(NSString *)expression;
/** page 50 */
- (void)printAztecWithXPos:(NSInteger)XPos
YPos:(NSInteger)YPos
rotate:(NSInteger)rotate
size:(NSInteger)size
ecp:(NSInteger)ecp
flg:(NSInteger)flg
menu:(NSInteger)menu
multi:(NSInteger)multi
rev:(NSInteger)rev
aztecData:(NSString *)aztecData;
/**
* page 52.
* print Bitmap format image.
*/
- (void)putBMPWithFilename:(NSString *)filename
XPos:(NSInteger)x_pos
YPos:(NSInteger)y_pos;
/**
* page 54.
* print PCX format images.
*/
- (void)putPCXWithFilename:(NSString *)filename
XPos:(NSInteger)x_pos
YPos:(NSInteger)y_pos;
/**
* page 63.
* reverse a region in image buffer.
*/
- (void)setReverseWithXStart:(NSInteger)x_start
YStart:(NSInteger)y_start
XWidth:(NSInteger)x_width
YHeight:(NSInteger)y_height;
#pragma mark Device Reconfiguration Commands
/**
* page 32.
* setting the counter number in the program and its increments.
*
* @param counterNumber which number of counter0-50
* @param step counting interval -99999999 ~ 99999999
*/
- (void)setCounterWithCounterNumber:(NSInteger)counterNumber
Step:(NSInteger)step;
- (void)setCutterON;
- (void)setCutterOFF;
- (void)setCutterBATCH;
/**
* set number of printing labels per cut
*
* @param pieces (0 ~ 65535)
*/
- (void)setCutterPieces:(NSInteger)pieces;
- (void)setPARTIAL_CUTTER_OFF;
- (void)setPARTIAL_CUTTER_BATCH;
/**
* set number of printing labels per cut
*
* @param pieces (0 ~ 65535)
*/
- (void)setPARTIAL_CUTTER_Pieces:(NSInteger)pieces;
- (void)setBackOFF;
- (void)setBackON;
/**
* This setting is used to enable/disable the KEY1/KEY2/KEY3 function.
*
* @param index KEY1,KEY2,KEY3
* @param switcher ON/OFF
*/
- (void)setKEY:(NSInteger)index Switch:(NSString *)switcher;
/**
* This setting is used to enable/disable the LED function.
LED1 Power on/off
LED2 Printer on-line/off-line
LED3 Error/normal
*
* @param index LED1,LED2,LED3
* @param switcher ON/OFF
*/
- (void)setLED:(NSInteger)index Switch:(NSString *)switcher;
- (void)setPeelON;
- (void)setPeelOFF;
/**
* This command is used to enable/disable feeding of labels to gap/black mark position for tearing off.
* This setting will be saved in printer memory when turning off the power.
*/
- (void)setTearON;
- (void)setTearOFF;
- (void)setStriperON;
- (void)setStriperOFF;
/**
* This setting is used to enable/disable head open sensor.
*/
- (void)setHeadON;
- (void)setHeadOFF;
- (void)setRibbonON;
- (void)setRibbonOFF;
/**
* This setting defines communication parameters for printer serial port.
*
* @param baud 24,48,96,19,38,57,115( 2400 bps,4800 bps,9600 bps,38400 bps,15200 bps)
* @param parity N,E,O(NO/Even/Odd parity check)
* @param data 7,8(bits Data)
* @param stop 1,2(stop bit)
*/
- (void)setCOM1WithBaud:(NSInteger)baud
Parity:(NSString *)parity
Data:(NSString *)data
Stop:(NSString *)stop;
/**
* This command will print one label and feed label gap to tear br position for tearing away.
* This setting will be saved in printer memory.
*
* @param key OFF/ON/AUTO/<num>
*/
- (void)setPrintKey:(NSString *)key;
- (void)setReprintON;
- (void)setReprintOFF;
@end
NS_ASSUME_NONNULL_END

@ -0,0 +1,51 @@
/*!
* \~chinese
* @header PTPrinter.h
* @abstract
*
* \~english
* @header PTPrinter.h
* @abstract Printer properties
*/
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "PTRouter.h"
/// 打印机的连接模块
typedef NS_ENUM(NSInteger, PTPrinterModule) {
PTPrinterModuleUnknown = 0, /// 未知类型
PTPrinterModuleBLE = 1, /// 蓝牙
PTPrinterModuleWiFi = 2, /// 无线
PTPrinterModuleBoth = 3, /// 蓝牙和无线
};
@interface PTPrinter : NSObject<NSCoding>
/// 打印机名称
@property(strong,nonatomic,readwrite) NSString *name;
/// 打印机mac地址
@property(strong,nonatomic,readwrite) NSString *mac;
/// 打印机蓝牙模块
@property(assign,nonatomic,readwrite) PTPrinterModule module;
/// 发现蓝牙时获取到的广播信息
@property(strong,nonatomic,readwrite) NSDictionary *advertisement;
/// 蓝牙外设UUID
@property(strong,nonatomic,readwrite) NSString *uuid;
/// 发现外设时获取到的信号强度值,单位分贝
@property(strong,nonatomic,readwrite) NSNumber *rssi;
/// 信号强度等级分0-5级
@property(strong,nonatomic,readwrite) NSNumber *strength;
/// 由信号强度计算的距离
@property(strong,nonatomic,readwrite) NSNumber *distance;
/// 蓝牙外设
@property(strong,nonatomic,readwrite) CBPeripheral *peripheral;
/// 外设的ip地址
@property(strong,nonatomic,readwrite) NSString *ip;
/// 端口
@property(strong,nonatomic,readwrite) NSString *port;
- (instancetype)initWithPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI;
@end

@ -0,0 +1,96 @@
/*!
* \~chinese
* @header PTRouter.h
* @abstract
*
* \~english
* @header PTRouter.h
* @abstract Router properties
*/
#import <Foundation/Foundation.h>
@interface PTRouter : NSObject
/*!
* \~chinese
* 广
*
* \~english
* Broadcast address
*/
@property(strong,nonatomic,readwrite) NSString *broadcastIP;
/*!
* \~chinese
*
*
* \~english
* Local address
*/
@property(strong,nonatomic,readwrite) NSString *localIP;
/*!
* \~chinese
*
*
* \~english
* Netmask
*/
@property(strong,nonatomic,readwrite) NSString *netmask;
/*!
* \~chinese
*
*
* \~english
* Interface
*/
@property(strong,nonatomic,readwrite) NSString *interface;
/*!
* \~chinese
*
*
* \~english
* Gateway
*/
@property(strong,nonatomic,readwrite) NSString *gateway;
/*!
* \~chinese
*
*
* \~english
* Whether to connect to the router
*/
@property(assign,nonatomic,readwrite) BOOL connected;
/*!
* \~chinese
* mac
*
* \~english
* Mac
*/
@property(strong,nonatomic,readwrite) NSString *MAC;
/*!
* \~chinese
*
*
* \~english
* ssid
*/
@property(strong,nonatomic,readwrite) NSString *SSID;
/*!
* \~chinese
*
*
* \~english
* SSIDDATA
*/
@property(strong,nonatomic,readwrite) NSString *SSIDDATA;
@end

@ -0,0 +1,51 @@
#if TARGET_OS_IOS
#import <UIKit/UIKit.h>
#elif TARGET_OS_MAC
#import <Cocoa/Cocoa.h>
#endif
#import <Foundation/NSObjCRuntime.h>
//! Project version number for PrinterSDK.
FOUNDATION_EXPORT double PrinterSDKVersionNumber;
//! Project version string for PrinterSDK.
FOUNDATION_EXPORT const unsigned char PrinterSDKVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <PrinterSDK/PublicHeader.h>
/*! *\~chinese ESC指令 *\~english ESC command */
#import <PrinterSDK/PTCommandESC.h>
/*! *\~chinese TSPL指令 *\~english TSPL command */
#import <PrinterSDK/PTCommandTSPL.h>
/*! *\~chinese ZPL指令 *\~english ZPL command */
#import <PrinterSDK/PTCommandZPL.h>
/*! *\~chinese CPCL指令 *\~english CPCL command */
#import <PrinterSDK/PTCommandCPCL.h>
#import <PrinterSDK/PTLabel.h>
#import <PrinterSDK/PTCommandCommon.h>
#import <PrinterSDK/PTOldCommandCPCL.h>
#import <PrinterSDK/PTOldCommandTSPL.h>
/*! *\~chinese 图片处理 *\~english image manager */
#import <PrinterSDK/PTBitmap.h>
#import <PrinterSDK/PTBitmap+GrayLevel.h>
#import <PrinterSDK/PTEncode.h>
// Dispatch
/*! *\~chinese 通讯 *\~english Communication */
#import <PrinterSDK/PTDispatcher.h>
#import <PrinterSDK/PTPrinter.h>
#import <PrinterSDK/PTRouter.h>

@ -0,0 +1,12 @@
#ifndef PublicDefine_h
#define PublicDefine_h
#ifdef DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d\t %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(...)
#endif
#endif /* PublicDefine_h */

@ -0,0 +1,6 @@
framework module PrinterSDK {
umbrella header "PrinterSDK.h"
export *
module * { export * }
}

@ -17,7 +17,12 @@ A new flutter plugin project.
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.platform = :ios, '8.0'
s.summary
# 第三方.a文件
s.vendored_libraries = 'Classes/**/*.a'
# 第三方framework
s.ios.vendored_frameworks='Frameworks/PrinterSDK.framework'
s.vendored_frameworks = 'PrinterSDK.framework'
# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
end

@ -25,13 +25,22 @@ class HyPrinter {
return devices;
}
static Future<bool> blutIsOn() async {
var result = await flutterBlue.isOn;
return result;
}
///0
///-1
///-2
///-3sdk
///-4
static Future<int> connect(String address) async {
int result = await _channel.invokeMethod('connect', {'address': address});
int result = -4;
await Future.delayed(const Duration(milliseconds: 2000), () async {
result = await _channel.invokeMethod('connect', {'address': address});
});
// int result = await _channel.invokeMethod('connect', {'address': address});
return result;
}
@ -106,14 +115,26 @@ class HyPrinter {
return result;
}
static Future<int> printAsOrder(String code, String fbaCode, String channel,
String country, String count) async {
/// 'code': code,
// 'fbaCode': fbaCode, fba/fba
// 'channel': channel,
// 'country': country,
// 'count': count,
// 'hasPlan':hasPlan
static Future<int> printAsOrder(
{required String code,
required String fbaCode,
required String channel,
required String country,
required String count,
required bool hasPlan}) async {
int result = await _channel.invokeMethod('printAsOrder', {
'code': code,
'fbaCode': fbaCode,
'channel': channel,
'country': country,
'count': count,
'hasPlan': hasPlan
});
return result;
}

Loading…
Cancel
Save