@connexup/react-native-xprinter 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/NativeXPrinter.podspec +23 -0
- package/README.md +24 -0
- package/android/build.gradle +73 -0
- package/android/gradle.properties +5 -0
- package/android/libs/printer-lib-3.4.7.aar +0 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/connexup/xprinter/Errors.kt +11 -0
- package/android/src/main/java/com/connexup/xprinter/Util.kt +106 -0
- package/android/src/main/java/com/connexup/xprinter/XPrinterPackage.kt +77 -0
- package/android/src/main/java/com/connexup/xprinter/esc/Convert.kt +211 -0
- package/android/src/main/java/com/connexup/xprinter/esc/XPrinterESCModule.kt +1995 -0
- package/android/src/main/java/com/connexup/xprinter/printer/Convert.kt +46 -0
- package/android/src/main/java/com/connexup/xprinter/printer/DeviceConnection.kt +14 -0
- package/android/src/main/java/com/connexup/xprinter/printer/Printers.kt +153 -0
- package/android/src/main/java/com/connexup/xprinter/printer/XPrinterPrinterModule.kt +295 -0
- package/android/src/main/java/com/connexup/xprinter/tspl/Convert.kt +151 -0
- package/android/src/main/java/com/connexup/xprinter/tspl/XPrinterTSPLModule.kt +1408 -0
- package/android/src/main/java/com/connexup/xprinter/utils/XPrinterUtilsModule.kt +54 -0
- package/ios/ESC/ESCConvert.swift +283 -0
- package/ios/ESC/Models/RCTESCPrintBarCodeRequest.swift +23 -0
- package/ios/ESC/Models/RCTESCPrintBitmapRequest.swift +23 -0
- package/ios/ESC/Models/RCTESCPrintPDF417Request.swift +27 -0
- package/ios/ESC/Models/RCTESCPrintQRCodeRequest.swift +19 -0
- package/ios/ESC/Models/RCTESCPrintTableBarcode.swift +23 -0
- package/ios/ESC/Models/RCTESCPrintTableRequest.swift +19 -0
- package/ios/ESC/Models/RCTESCPrintTableRow.swift +19 -0
- package/ios/ESC/Models/RCTESCPrintTextRequest.swift +21 -0
- package/ios/ESC/Models/RCTESCPrintTextSizeRequest.swift +17 -0
- package/ios/ESC/Models/RCTESCSelectBitmapModelRequest.swift +17 -0
- package/ios/ESC/Models/RCTESCSetNetAllRequest.swift +19 -0
- package/ios/ESC/Models/RCTESCSetPrintAreaRequest.swift +19 -0
- package/ios/ESC/Models/RCTESCSetTextStyleRequest.swift +17 -0
- package/ios/ESC/Models/RCTESCWifiConfigRequest.swift +23 -0
- package/ios/ESC/NativeXPrinterESC.swift +1339 -0
- package/ios/ESC/RCTNativeXPrinterESC.h +10 -0
- package/ios/ESC/RCTNativeXPrinterESC.mm +541 -0
- package/ios/Errors.swift +11 -0
- package/ios/NativeErrorInfo.swift +21 -0
- package/ios/Printer/Connecter.swift +214 -0
- package/ios/Printer/Models/RCTDeviceConnectStatusChangeEvent.swift +19 -0
- package/ios/Printer/Models/RCTNetDevice.swift +21 -0
- package/ios/Printer/Models/RCTUSBDevice.swift +17 -0
- package/ios/Printer/Models/RCTUpdateUdpNetConfigRequest.swift +21 -0
- package/ios/Printer/NativeXPrinterPrinter.swift +209 -0
- package/ios/Printer/Printers.swift +59 -0
- package/ios/Printer/RCTNativeXPrinterPrinter.h +12 -0
- package/ios/Printer/RCTNativeXPrinterPrinter.mm +123 -0
- package/ios/PrinterSDK/Headers/CPCLCommand.h +324 -0
- package/ios/PrinterSDK/Headers/KDS_Log.h +47 -0
- package/ios/PrinterSDK/Headers/LabelDocument.h +32 -0
- package/ios/PrinterSDK/Headers/LabelImageTranster.h +19 -0
- package/ios/PrinterSDK/Headers/POSBLEManager.h +164 -0
- package/ios/PrinterSDK/Headers/POSCommand.h +760 -0
- package/ios/PrinterSDK/Headers/POSImageTranster.h +34 -0
- package/ios/PrinterSDK/Headers/POSPrinter.h +47 -0
- package/ios/PrinterSDK/Headers/POSPrinterSDK.h +13 -0
- package/ios/PrinterSDK/Headers/POSWIFIManager.h +162 -0
- package/ios/PrinterSDK/Headers/PTable.h +50 -0
- package/ios/PrinterSDK/Headers/PrinterProfile.h +28 -0
- package/ios/PrinterSDK/Headers/TSCBLEManager.h +142 -0
- package/ios/PrinterSDK/Headers/TSCCommand.h +701 -0
- package/ios/PrinterSDK/Headers/TSCPrinterSDK.h +15 -0
- package/ios/PrinterSDK/Headers/TSCWIFIManager.h +99 -0
- package/ios/PrinterSDK/Headers/WIFIConnecter.h +131 -0
- package/ios/PrinterSDK/Headers/ZPLCommand.h +372 -0
- package/ios/PrinterSDK/libPrinterSDK.a +0 -0
- package/ios/TSPL/Models/RCTTSPLBarRequest.swift +19 -0
- package/ios/TSPL/Models/RCTTSPLBarcodeRequest.swift +29 -0
- package/ios/TSPL/Models/RCTTSPLBitmapCompressionRequest.swift +25 -0
- package/ios/TSPL/Models/RCTTSPLBitmapRequest.swift +25 -0
- package/ios/TSPL/Models/RCTTSPLBoxRequest.swift +21 -0
- package/ios/TSPL/Models/RCTTSPLEraseRequest.swift +19 -0
- package/ios/TSPL/Models/RCTTSPLPDFBase64Request.swift +21 -0
- package/ios/TSPL/Models/RCTTSPLPutBMPRequest.swift +17 -0
- package/ios/TSPL/Models/RCTTSPLQRCodeRequest.swift +29 -0
- package/ios/TSPL/Models/RCTTSPLReverseRequest.swift +19 -0
- package/ios/TSPL/Models/RCTTSPLTextRequest.swift +25 -0
- package/ios/TSPL/NativeXPrinterTSPL.swift +831 -0
- package/ios/TSPL/RCTNativeXPrinterTSPL.h +10 -0
- package/ios/TSPL/RCTNativeXPrinterTSPL.mm +445 -0
- package/ios/TSPL/TSPLConvert.swift +140 -0
- package/ios/Utils/Models/RCTCheckIsPureWhiteImageRequest.swift +16 -0
- package/ios/Utils/NativeXPrinterUtils.swift +17 -0
- package/ios/Utils/RCTNativeXPrinterUtils.h +10 -0
- package/ios/Utils/RCTNativeXPrinterUtils.mm +38 -0
- package/ios/Utils.swift +126 -0
- package/lib/module/esc/NativeXPrinterESC.js +218 -0
- package/lib/module/esc/NativeXPrinterESC.js.map +1 -0
- package/lib/module/esc/index.js +324 -0
- package/lib/module/esc/index.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/printer/NativeXPrinterPrinter.js +30 -0
- package/lib/module/printer/NativeXPrinterPrinter.js.map +1 -0
- package/lib/module/printer/index.js +110 -0
- package/lib/module/printer/index.js.map +1 -0
- package/lib/module/tspl/NativeXPrinterTSPL.js +143 -0
- package/lib/module/tspl/NativeXPrinterTSPL.js.map +1 -0
- package/lib/module/tspl/index.js +347 -0
- package/lib/module/tspl/index.js.map +1 -0
- package/lib/module/type.js +12 -0
- package/lib/module/type.js.map +1 -0
- package/lib/module/util.js +4 -0
- package/lib/module/util.js.map +1 -0
- package/lib/module/utils/NativeXPrinterUtils.js +5 -0
- package/lib/module/utils/NativeXPrinterUtils.js.map +1 -0
- package/lib/module/utils/index.js +17 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/esc/NativeXPrinterESC.d.ts +343 -0
- package/lib/typescript/src/esc/NativeXPrinterESC.d.ts.map +1 -0
- package/lib/typescript/src/esc/index.d.ts +122 -0
- package/lib/typescript/src/esc/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/printer/NativeXPrinterPrinter.d.ts +61 -0
- package/lib/typescript/src/printer/NativeXPrinterPrinter.d.ts.map +1 -0
- package/lib/typescript/src/printer/index.d.ts +32 -0
- package/lib/typescript/src/printer/index.d.ts.map +1 -0
- package/lib/typescript/src/tspl/NativeXPrinterTSPL.d.ts +261 -0
- package/lib/typescript/src/tspl/NativeXPrinterTSPL.d.ts.map +1 -0
- package/lib/typescript/src/tspl/index.d.ts +128 -0
- package/lib/typescript/src/tspl/index.d.ts.map +1 -0
- package/lib/typescript/src/type.d.ts +9 -0
- package/lib/typescript/src/type.d.ts.map +1 -0
- package/lib/typescript/src/util.d.ts +2 -0
- package/lib/typescript/src/util.d.ts.map +1 -0
- package/lib/typescript/src/utils/NativeXPrinterUtils.d.ts +10 -0
- package/lib/typescript/src/utils/NativeXPrinterUtils.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +9 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/package.json +178 -0
- package/src/esc/NativeXPrinterESC.ts +516 -0
- package/src/esc/index.ts +489 -0
- package/src/index.ts +5 -0
- package/src/printer/NativeXPrinterPrinter.ts +84 -0
- package/src/printer/index.ts +160 -0
- package/src/tspl/NativeXPrinterTSPL.ts +388 -0
- package/src/tspl/index.ts +535 -0
- package/src/type.ts +11 -0
- package/src/util.ts +1 -0
- package/src/utils/NativeXPrinterUtils.ts +14 -0
- package/src/utils/index.ts +27 -0
|
@@ -0,0 +1,831 @@
|
|
|
1
|
+
//
|
|
2
|
+
// NativeXPrinterTSPL.swift
|
|
3
|
+
//
|
|
4
|
+
// Created by chancetio on 2025/9/9.
|
|
5
|
+
//
|
|
6
|
+
|
|
7
|
+
@objcMembers
|
|
8
|
+
public class NativeXPrinterTSPL: NSObject {
|
|
9
|
+
public func sizeInch(connectInfo: String, width: Double, height: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
10
|
+
DispatchQueue.main.async {
|
|
11
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
12
|
+
completion(
|
|
13
|
+
NativeErrorInfo(
|
|
14
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
15
|
+
message: "not found printer:\(connectInfo)",
|
|
16
|
+
error: nil,
|
|
17
|
+
)
|
|
18
|
+
)
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
printer.writeCommand(with: TSCCommand.sizeByinch(withWidth: width, andHeight: height))
|
|
22
|
+
completion(nil)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public func sizeMm(connectInfo: String, width: Double, height: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
27
|
+
DispatchQueue.main.async {
|
|
28
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
29
|
+
completion(
|
|
30
|
+
NativeErrorInfo(
|
|
31
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
32
|
+
message: "not found printer:\(connectInfo)",
|
|
33
|
+
error: nil
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
printer.writeCommand(with: TSCCommand.sizeBymm(withWidth: width, andHeight: height))
|
|
39
|
+
completion(nil)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public func gapInch(connectInfo: String, m: Double, n: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
44
|
+
DispatchQueue.main.async {
|
|
45
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
46
|
+
completion(
|
|
47
|
+
NativeErrorInfo(
|
|
48
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
49
|
+
message: "not found printer:\(connectInfo)",
|
|
50
|
+
error: nil
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
printer.writeCommand(with: TSCCommand.gapByinch(withWidth: m, andHeight: n))
|
|
56
|
+
completion(nil)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public func gapMm(connectInfo: String, m: Double, n: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
61
|
+
DispatchQueue.main.async {
|
|
62
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
63
|
+
completion(
|
|
64
|
+
NativeErrorInfo(
|
|
65
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
66
|
+
message: "not found printer:\(connectInfo)",
|
|
67
|
+
error: nil
|
|
68
|
+
)
|
|
69
|
+
)
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
printer.writeCommand(with: TSCCommand.gapBymm(withWidth: m, andHeight: n))
|
|
73
|
+
completion(nil)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public func speed(connectInfo: String, speed: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
78
|
+
DispatchQueue.main.async {
|
|
79
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
80
|
+
completion(
|
|
81
|
+
NativeErrorInfo(
|
|
82
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
83
|
+
message: "not found printer:\(connectInfo)",
|
|
84
|
+
error: nil
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
printer.writeCommand(with: TSCCommand.speed(speed))
|
|
90
|
+
completion(nil)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public func density(connectInfo: String, density: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
95
|
+
DispatchQueue.main.async {
|
|
96
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
97
|
+
completion(
|
|
98
|
+
NativeErrorInfo(
|
|
99
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
100
|
+
message: "not found printer:\(connectInfo)",
|
|
101
|
+
error: nil
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
printer.writeCommand(with: TSCCommand.density(Int32(density)))
|
|
107
|
+
completion(nil)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public func direction(connectInfo: String, direction: String, isMirror: Bool, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
112
|
+
DispatchQueue.main.async {
|
|
113
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
114
|
+
completion(
|
|
115
|
+
NativeErrorInfo(
|
|
116
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
117
|
+
message: "not found printer:\(connectInfo)",
|
|
118
|
+
error: nil
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
guard let direction = direction.toTSPLDirection() else {
|
|
125
|
+
completion(
|
|
126
|
+
NativeErrorInfo(
|
|
127
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
128
|
+
message: "direction is error",
|
|
129
|
+
error: nil
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
printer.writeCommand(with: TSCCommand.direction(direction))
|
|
136
|
+
completion(nil)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public func cls(connectInfo: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
141
|
+
DispatchQueue.main.async {
|
|
142
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
143
|
+
completion(
|
|
144
|
+
NativeErrorInfo(
|
|
145
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
146
|
+
message: "not found printer:\(connectInfo)",
|
|
147
|
+
error: nil
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
printer.writeCommand(with: TSCCommand.cls())
|
|
153
|
+
completion(nil)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public func box(connectInfo: String, payload: RCTTSPLBoxRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
158
|
+
DispatchQueue.main.async {
|
|
159
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
160
|
+
completion(
|
|
161
|
+
NativeErrorInfo(
|
|
162
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
163
|
+
message: "not found printer:\(connectInfo)",
|
|
164
|
+
error: nil
|
|
165
|
+
)
|
|
166
|
+
)
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
printer.writeCommand(with: TSCCommand.boxWith(x: Int32(payload.x), andY: Int32(payload.y), andEndX: Int32(payload.x)+Int32(payload.width), andEndY: Int32(payload.y)+Int32(payload.height), andThickness: Int32(payload.thickness)))
|
|
171
|
+
completion(nil)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public func bar(connectInfo: String, payload: RCTTSPLBarRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
176
|
+
DispatchQueue.main.async {
|
|
177
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
178
|
+
completion(
|
|
179
|
+
NativeErrorInfo(
|
|
180
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
181
|
+
message: "not found printer:\(connectInfo)",
|
|
182
|
+
error: nil
|
|
183
|
+
)
|
|
184
|
+
)
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
printer.writeCommand(with: TSCCommand.barWith(x: Int32(payload.x), andY: Int32(payload.y), andWidth: Int32(payload.width), andHeigt: Int32(payload.height)))
|
|
189
|
+
completion(nil)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
public func barcode(connectInfo: String, payload: RCTTSPLBarcodeRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
194
|
+
DispatchQueue.main.async {
|
|
195
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
196
|
+
completion(
|
|
197
|
+
NativeErrorInfo(
|
|
198
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
199
|
+
message: "not found printer:\(connectInfo)",
|
|
200
|
+
error: nil
|
|
201
|
+
)
|
|
202
|
+
)
|
|
203
|
+
return
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
guard let codeType = payload.codeType.toTSPLBarcodeType() else {
|
|
207
|
+
completion(
|
|
208
|
+
NativeErrorInfo(
|
|
209
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
210
|
+
message: "codeType is error",
|
|
211
|
+
error: nil
|
|
212
|
+
)
|
|
213
|
+
)
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
guard let readable = payload.readable.toTSPLReadable() else {
|
|
218
|
+
completion(
|
|
219
|
+
NativeErrorInfo(
|
|
220
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
221
|
+
message: "readable is error",
|
|
222
|
+
error: nil
|
|
223
|
+
)
|
|
224
|
+
)
|
|
225
|
+
return
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
guard let rotation = payload.rotation.toTSPLRotation() else {
|
|
229
|
+
completion(
|
|
230
|
+
NativeErrorInfo(
|
|
231
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
232
|
+
message: "rotation is error",
|
|
233
|
+
error: nil
|
|
234
|
+
)
|
|
235
|
+
)
|
|
236
|
+
return
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
printer.writeCommand(with: TSCCommand.barcodeWith(x: Int32(payload.x), andY: Int32(payload.y), andCodeType: codeType, andHeight: Int32(payload.height), andHunabReadable: readable, andRotation: rotation, andNarrow: Int32(payload.narrow), andWide: Int32(payload.wide), andContent: payload.content, usStrEnCoding: NSUTF8StringEncoding))
|
|
240
|
+
completion(nil)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
public func text(connectInfo: String, payload: RCTTSPLTextRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
245
|
+
DispatchQueue.main.async {
|
|
246
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
247
|
+
completion(
|
|
248
|
+
NativeErrorInfo(
|
|
249
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
250
|
+
message: "not found printer:\(connectInfo)",
|
|
251
|
+
error: nil
|
|
252
|
+
)
|
|
253
|
+
)
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
guard let font = payload.font.toTSPLFont() else {
|
|
258
|
+
completion(
|
|
259
|
+
NativeErrorInfo(
|
|
260
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
261
|
+
message: "font is error",
|
|
262
|
+
error: nil
|
|
263
|
+
)
|
|
264
|
+
)
|
|
265
|
+
return
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
guard let rotation = payload.rotation.toTSPLRotation() else {
|
|
269
|
+
completion(
|
|
270
|
+
NativeErrorInfo(
|
|
271
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
272
|
+
message: "rotation is error",
|
|
273
|
+
error: nil
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
return
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
printer.writeCommand(with: TSCCommand.textWith(x: Int32(payload.x), andY: Int32(payload.y), andFont: font, andRotation: rotation, andX_mul: Int32(payload.xRatio), andY_mul: Int32(payload.yRatio), andContent: payload.content, usStrEnCoding: NSUTF8StringEncoding))
|
|
280
|
+
completion(nil)
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
public func offsetInch(connectInfo: String, offset: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
285
|
+
DispatchQueue.main.async {
|
|
286
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
287
|
+
completion(
|
|
288
|
+
NativeErrorInfo(
|
|
289
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
290
|
+
message: "not found printer:\(connectInfo)",
|
|
291
|
+
error: nil
|
|
292
|
+
)
|
|
293
|
+
)
|
|
294
|
+
return
|
|
295
|
+
}
|
|
296
|
+
printer.writeCommand(with: TSCCommand.offSetByinch(withM: offset))
|
|
297
|
+
completion(nil)
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
public func offsetMm(connectInfo: String, offset: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
302
|
+
DispatchQueue.main.async {
|
|
303
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
304
|
+
completion(
|
|
305
|
+
NativeErrorInfo(
|
|
306
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
307
|
+
message: "not found printer:\(connectInfo)",
|
|
308
|
+
error: nil
|
|
309
|
+
)
|
|
310
|
+
)
|
|
311
|
+
return
|
|
312
|
+
}
|
|
313
|
+
printer.writeCommand(with: TSCCommand.offSetBymm(withM: offset))
|
|
314
|
+
completion(nil)
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
public func reference(connectInfo: String, x: Double, y: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
319
|
+
DispatchQueue.main.async {
|
|
320
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
321
|
+
completion(
|
|
322
|
+
NativeErrorInfo(
|
|
323
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
324
|
+
message: "not found printer:\(connectInfo)",
|
|
325
|
+
error: nil
|
|
326
|
+
)
|
|
327
|
+
)
|
|
328
|
+
return
|
|
329
|
+
}
|
|
330
|
+
printer.writeCommand(with: TSCCommand.referenceWith(x: Int32(x), andY: Int32(y)))
|
|
331
|
+
completion(nil)
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
public func qrcode(connectInfo: String, payload: RCTTSPLQRCodeRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
336
|
+
DispatchQueue.main.async {
|
|
337
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
338
|
+
completion(
|
|
339
|
+
NativeErrorInfo(
|
|
340
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
341
|
+
message: "not found printer:\(connectInfo)",
|
|
342
|
+
error: nil
|
|
343
|
+
)
|
|
344
|
+
)
|
|
345
|
+
return
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
guard let ecLevel = payload.ecLevel.toTSPLECLevel() else {
|
|
349
|
+
completion(
|
|
350
|
+
NativeErrorInfo(
|
|
351
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
352
|
+
message: "ecLevel is error",
|
|
353
|
+
error: nil
|
|
354
|
+
)
|
|
355
|
+
)
|
|
356
|
+
return
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
guard let mode = payload.mode.toTSPLQrcodeMode() else {
|
|
360
|
+
completion(
|
|
361
|
+
NativeErrorInfo(
|
|
362
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
363
|
+
message: "mode is error",
|
|
364
|
+
error: nil
|
|
365
|
+
)
|
|
366
|
+
)
|
|
367
|
+
return
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
guard let rotation = payload.rotation.toTSPLRotation() else {
|
|
371
|
+
completion(
|
|
372
|
+
NativeErrorInfo(
|
|
373
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
374
|
+
message: "rotation is error",
|
|
375
|
+
error: nil
|
|
376
|
+
)
|
|
377
|
+
)
|
|
378
|
+
return
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// guard let model = payload.model.toTSPLQrcodeModel() else {
|
|
382
|
+
// completion(
|
|
383
|
+
// NativeErrorInfo(
|
|
384
|
+
// PrinterErrors.PARAMS_ERROR,
|
|
385
|
+
// "model is error"
|
|
386
|
+
// )
|
|
387
|
+
// )
|
|
388
|
+
// return
|
|
389
|
+
// }
|
|
390
|
+
|
|
391
|
+
printer.writeCommand(with: TSCCommand.qrCodeWith(x: Int32(payload.x), andY: Int32(payload.y), andEccLevel: ecLevel, andCellWidth: Int32(payload.cellWidth), andMode: mode, andRotation: rotation, andContent: payload.data, usStrEnCoding: NSUTF8StringEncoding))
|
|
392
|
+
completion(nil)
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
public func pdfBase64(connectInfo: String, payload: RCTTSPLPDFBase64Request, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
397
|
+
DispatchQueue.main.async {
|
|
398
|
+
completion(NativeErrorInfo(code: PrinterErrors.NOT_YET_IMPLEMENTED_ERROR, message: "Not yet implemented", error: nil))
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
public func print(connectInfo: String, count: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
403
|
+
DispatchQueue.main.async {
|
|
404
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
405
|
+
completion(
|
|
406
|
+
NativeErrorInfo(
|
|
407
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
408
|
+
message: "not found printer:\(connectInfo)",
|
|
409
|
+
error: nil
|
|
410
|
+
)
|
|
411
|
+
)
|
|
412
|
+
return
|
|
413
|
+
}
|
|
414
|
+
printer.writeCommand(with: TSCCommand.print(Int32(count)))
|
|
415
|
+
completion(nil)
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
public func feed(connectInfo: String, length: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
420
|
+
DispatchQueue.main.async {
|
|
421
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
422
|
+
completion(
|
|
423
|
+
NativeErrorInfo(
|
|
424
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
425
|
+
message: "not found printer:\(connectInfo)",
|
|
426
|
+
error: nil
|
|
427
|
+
)
|
|
428
|
+
)
|
|
429
|
+
return
|
|
430
|
+
}
|
|
431
|
+
printer.writeCommand(with: TSCCommand.feed(Int32(length)))
|
|
432
|
+
completion(nil)
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
public func backFeed(connectInfo: String, length: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
437
|
+
DispatchQueue.main.async {
|
|
438
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
439
|
+
completion(
|
|
440
|
+
NativeErrorInfo(
|
|
441
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
442
|
+
message: "not found printer:\(connectInfo)",
|
|
443
|
+
error: nil
|
|
444
|
+
)
|
|
445
|
+
)
|
|
446
|
+
return
|
|
447
|
+
}
|
|
448
|
+
printer.writeCommand(with: TSCCommand.backFeed(Int32(length)))
|
|
449
|
+
completion(nil)
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
public func formFeed(connectInfo: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
454
|
+
DispatchQueue.main.async {
|
|
455
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
456
|
+
completion(
|
|
457
|
+
NativeErrorInfo(
|
|
458
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
459
|
+
message: "not found printer:\(connectInfo)",
|
|
460
|
+
error: nil
|
|
461
|
+
)
|
|
462
|
+
)
|
|
463
|
+
return
|
|
464
|
+
}
|
|
465
|
+
printer.writeCommand(with: TSCCommand.formFeed())
|
|
466
|
+
completion(nil)
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
public func limitFeedMm(connectInfo: String, length: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
471
|
+
DispatchQueue.main.async {
|
|
472
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
473
|
+
completion(
|
|
474
|
+
NativeErrorInfo(
|
|
475
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
476
|
+
message: "not found printer:\(connectInfo)",
|
|
477
|
+
error: nil
|
|
478
|
+
)
|
|
479
|
+
)
|
|
480
|
+
return
|
|
481
|
+
}
|
|
482
|
+
printer.writeCommand(with: TSCCommand.limitFeedBymm(length))
|
|
483
|
+
completion(nil)
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
public func limitFeedInch(connectInfo: String, length: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
488
|
+
DispatchQueue.main.async {
|
|
489
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
490
|
+
completion(
|
|
491
|
+
NativeErrorInfo(
|
|
492
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
493
|
+
message: "not found printer:\(connectInfo)",
|
|
494
|
+
error: nil
|
|
495
|
+
)
|
|
496
|
+
)
|
|
497
|
+
return
|
|
498
|
+
}
|
|
499
|
+
printer.writeCommand(with: TSCCommand.limitFeedByinch(length))
|
|
500
|
+
completion(nil)
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
public func getPrinterModel(connectInfo: String, resolve: @escaping (_ value: String) -> Void, reject: @escaping (_ error: NativeErrorInfo) -> Void) {
|
|
505
|
+
DispatchQueue.main.async {
|
|
506
|
+
reject(NativeErrorInfo(code: PrinterErrors.NOT_YET_IMPLEMENTED_ERROR, message: "Not yet implemented", error: nil))
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
public func home(connectInfo: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
511
|
+
DispatchQueue.main.async {
|
|
512
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
513
|
+
completion(
|
|
514
|
+
NativeErrorInfo(
|
|
515
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
516
|
+
message: "not found printer:\(connectInfo)",
|
|
517
|
+
error: nil
|
|
518
|
+
)
|
|
519
|
+
)
|
|
520
|
+
return
|
|
521
|
+
}
|
|
522
|
+
printer.writeCommand(with: TSCCommand.home())
|
|
523
|
+
completion(nil)
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
public func codePage(connectInfo: String, page: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
528
|
+
DispatchQueue.main.async {
|
|
529
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
530
|
+
completion(
|
|
531
|
+
NativeErrorInfo(
|
|
532
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
533
|
+
message: "not found printer:\(connectInfo)",
|
|
534
|
+
error: nil
|
|
535
|
+
)
|
|
536
|
+
)
|
|
537
|
+
return
|
|
538
|
+
}
|
|
539
|
+
printer.writeCommand(with: TSCCommand.codePage(page))
|
|
540
|
+
completion(nil)
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
public func sound(connectInfo: String, level: Double, interval: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
545
|
+
DispatchQueue.main.async {
|
|
546
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
547
|
+
completion(
|
|
548
|
+
NativeErrorInfo(
|
|
549
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
550
|
+
message: "not found printer:\(connectInfo)",
|
|
551
|
+
error: nil
|
|
552
|
+
)
|
|
553
|
+
)
|
|
554
|
+
return
|
|
555
|
+
}
|
|
556
|
+
printer.writeCommand(with: TSCCommand.sound(withLevel: Int32(level), andInterval: Int32(interval)))
|
|
557
|
+
completion(nil)
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
public func bitmap(connectInfo: String, payload: RCTTSPLBitmapRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
562
|
+
DispatchQueue.main.async {
|
|
563
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
564
|
+
completion(
|
|
565
|
+
NativeErrorInfo(
|
|
566
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
567
|
+
message: "not found printer:\(connectInfo)",
|
|
568
|
+
error: nil
|
|
569
|
+
)
|
|
570
|
+
)
|
|
571
|
+
return
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
guard let mode = payload.mode.toTSPLBitmapMode() else {
|
|
575
|
+
completion(
|
|
576
|
+
NativeErrorInfo(
|
|
577
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
578
|
+
message: "mode is error",
|
|
579
|
+
error: nil
|
|
580
|
+
)
|
|
581
|
+
)
|
|
582
|
+
return
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
guard let image = Utils.loadAndScaleBitmap(bitmapContent: payload.bitmapContent, bitmapPath: payload.bitmapPath, width: Int(payload.width)) else {
|
|
586
|
+
completion(
|
|
587
|
+
NativeErrorInfo(
|
|
588
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
589
|
+
message: "bitmap is error",
|
|
590
|
+
error: nil
|
|
591
|
+
)
|
|
592
|
+
)
|
|
593
|
+
return
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
printer.writeCommand(with: TSCCommand.bitmapWith(x: Int32(payload.x), andY: Int32(payload.y), andMode: mode, andImage: image))
|
|
597
|
+
completion(nil)
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
public func bitmapCompression(connectInfo: String, payload: RCTTSPLBitmapCompressionRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
602
|
+
DispatchQueue.main.async {
|
|
603
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
604
|
+
completion(
|
|
605
|
+
NativeErrorInfo(
|
|
606
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
607
|
+
message: "not found printer:\(connectInfo)",
|
|
608
|
+
error: nil
|
|
609
|
+
)
|
|
610
|
+
)
|
|
611
|
+
return
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
guard let mode = payload.mode.toTSPLBitmapCompressionMode() else {
|
|
615
|
+
completion(
|
|
616
|
+
NativeErrorInfo(
|
|
617
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
618
|
+
message: "mode is error",
|
|
619
|
+
error: nil
|
|
620
|
+
)
|
|
621
|
+
)
|
|
622
|
+
return
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
guard let image = Utils.loadAndScaleBitmap(bitmapContent: payload.bitmapContent, bitmapPath: payload.bitmapPath, width: Int(payload.width)) else {
|
|
626
|
+
completion(
|
|
627
|
+
NativeErrorInfo(
|
|
628
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
629
|
+
message: "bitmap is error",
|
|
630
|
+
error: nil
|
|
631
|
+
)
|
|
632
|
+
)
|
|
633
|
+
return
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
printer.writeCommand(with: TSCCommand.zlibBitmapWith(x: Int32(payload.x), andY: Int32(payload.y), andMode: mode, andImage: image))
|
|
637
|
+
completion(nil)
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
public func erase(connectInfo: String, payload: RCTTSPLEraseRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
642
|
+
DispatchQueue.main.async {
|
|
643
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
644
|
+
completion(
|
|
645
|
+
NativeErrorInfo(
|
|
646
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
647
|
+
message: "not found printer:\(connectInfo)",
|
|
648
|
+
error: nil
|
|
649
|
+
)
|
|
650
|
+
)
|
|
651
|
+
return
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
printer.writeCommand(with: TSCCommand.eraseWith(x: Int32(payload.x), andY: Int32(payload.y), andWidth: Int32(payload.width), andHeight: Int32(payload.height)))
|
|
655
|
+
completion(nil)
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
public func reverse(connectInfo: String, payload: RCTTSPLReverseRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
660
|
+
DispatchQueue.main.async {
|
|
661
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
662
|
+
completion(
|
|
663
|
+
NativeErrorInfo(
|
|
664
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
665
|
+
message: "not found printer:\(connectInfo)",
|
|
666
|
+
error: nil
|
|
667
|
+
)
|
|
668
|
+
)
|
|
669
|
+
return
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
printer.writeCommand(with: TSCCommand.reverseWith(x: Int32(payload.x), andY: Int32(payload.y), andWidth: Int32(payload.width), andHeight: Int32(payload.height)))
|
|
673
|
+
completion(nil)
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
public func cut(connectInfo: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
678
|
+
DispatchQueue.main.async {
|
|
679
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
680
|
+
completion(
|
|
681
|
+
NativeErrorInfo(
|
|
682
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
683
|
+
message: "not found printer:\(connectInfo)",
|
|
684
|
+
error: nil
|
|
685
|
+
)
|
|
686
|
+
)
|
|
687
|
+
return
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
printer.writeCommand(with: TSCCommand.cut())
|
|
691
|
+
completion(nil)
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
public func setCutter(connectInfo: String, pieces: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
696
|
+
DispatchQueue.main.async {
|
|
697
|
+
completion(NativeErrorInfo(code: PrinterErrors.NOT_YET_IMPLEMENTED_ERROR, message: "Not yet implemented", error: nil))
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
public func setPeel(connectInfo: String, isOpen: Bool, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
702
|
+
DispatchQueue.main.async {
|
|
703
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
704
|
+
completion(
|
|
705
|
+
NativeErrorInfo(
|
|
706
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
707
|
+
message: "not found printer:\(connectInfo)",
|
|
708
|
+
error: nil
|
|
709
|
+
)
|
|
710
|
+
)
|
|
711
|
+
return
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
printer.writeCommand(with: TSCCommand.setPeel(isOpen))
|
|
715
|
+
completion(nil)
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
public func setPrinterModel(connectInfo: String, model: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
720
|
+
DispatchQueue.main.async {
|
|
721
|
+
completion(NativeErrorInfo(code: PrinterErrors.NOT_YET_IMPLEMENTED_ERROR, message: "Not yet implemented", error: nil))
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
public func setTear(connectInfo: String, isOpen: Bool, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
726
|
+
DispatchQueue.main.async {
|
|
727
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
728
|
+
completion(
|
|
729
|
+
NativeErrorInfo(
|
|
730
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
731
|
+
message: "not found printer:\(connectInfo)",
|
|
732
|
+
error: nil
|
|
733
|
+
)
|
|
734
|
+
)
|
|
735
|
+
return
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
printer.writeCommand(with: TSCCommand.setTear(isOpen))
|
|
739
|
+
completion(nil)
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
public func putBmp(connectInfo: String, payload: RCTTSPLPutBMPRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
744
|
+
DispatchQueue.main.async {
|
|
745
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
746
|
+
completion(
|
|
747
|
+
NativeErrorInfo(
|
|
748
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
749
|
+
message: "not found printer:\(connectInfo)",
|
|
750
|
+
error: nil
|
|
751
|
+
)
|
|
752
|
+
)
|
|
753
|
+
return
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
printer.writeCommand(with: TSCCommand.putBmpWith(x: Int32(payload.x), andY: Int32(payload.y), andFileName: payload.fileName))
|
|
757
|
+
completion(nil)
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
public func blineInch(connectInfo: String, m: Double, n: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
762
|
+
DispatchQueue.main.async {
|
|
763
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
764
|
+
completion(
|
|
765
|
+
NativeErrorInfo(
|
|
766
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
767
|
+
message: "not found printer:\(connectInfo)",
|
|
768
|
+
error: nil
|
|
769
|
+
)
|
|
770
|
+
)
|
|
771
|
+
return
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
printer.writeCommand(with: TSCCommand.blineByinch(withM: m, andN: n))
|
|
775
|
+
completion(nil)
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
public func blineMm(connectInfo: String, m: Double, n: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
780
|
+
DispatchQueue.main.async {
|
|
781
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
782
|
+
completion(
|
|
783
|
+
NativeErrorInfo(
|
|
784
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
785
|
+
message: "not found printer:\(connectInfo)",
|
|
786
|
+
error: nil
|
|
787
|
+
)
|
|
788
|
+
)
|
|
789
|
+
return
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
printer.writeCommand(with: TSCCommand.blineBymm(withM: m, andN: n))
|
|
793
|
+
completion(nil)
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
public func printWithResponse(connectInfo: String, count: Double, timeout: Double, resolve: @escaping (_ value: Double) -> Void, reject: @escaping (_ error: NativeErrorInfo) -> Void) {
|
|
798
|
+
DispatchQueue.main.async {
|
|
799
|
+
DispatchQueue.main.async {
|
|
800
|
+
reject(NativeErrorInfo(code: PrinterErrors.NOT_YET_IMPLEMENTED_ERROR, message: "Not yet implemented", error: nil))
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
public func printerStatus(connectInfo: String, timeout: Double, resolve: @escaping (_ value: [String: Any]) -> Void, reject: @escaping (_ error: NativeErrorInfo) -> Void) {
|
|
806
|
+
DispatchQueue.main.async {
|
|
807
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
808
|
+
reject(
|
|
809
|
+
NativeErrorInfo(
|
|
810
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
811
|
+
message: "not found printer:\(connectInfo)",
|
|
812
|
+
error: nil
|
|
813
|
+
)
|
|
814
|
+
)
|
|
815
|
+
return
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
printer.labelPrinterStatus { data in
|
|
819
|
+
var status: Int?
|
|
820
|
+
if let data = data {
|
|
821
|
+
if let firstByte = data.first {
|
|
822
|
+
status = Int(firstByte)
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
var result: [String: Any] = [:]
|
|
826
|
+
result["status"] = status
|
|
827
|
+
resolve(result)
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}
|