@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,1339 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RTNEscPrintModule.swift
|
|
3
|
+
// Created by chancetio on 2025/1/24.
|
|
4
|
+
//
|
|
5
|
+
|
|
6
|
+
import Foundation
|
|
7
|
+
|
|
8
|
+
@objcMembers
|
|
9
|
+
public class NativeXPrinterESC: NSObject {
|
|
10
|
+
|
|
11
|
+
public func clearNVImage(connectInfo: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void){
|
|
12
|
+
DispatchQueue.main.async {
|
|
13
|
+
completion(NativeErrorInfo(code: PrinterErrors.NOT_YET_IMPLEMENTED_ERROR, message: "Not yet implemented", error: nil))
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public func selectInternationCharacterSets(connectInfo: String, n: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
18
|
+
DispatchQueue.main.async {
|
|
19
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
20
|
+
completion(
|
|
21
|
+
NativeErrorInfo(code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
22
|
+
message: "not found printer:\(connectInfo)", error: nil)
|
|
23
|
+
)
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
guard let convertN = n.toESCInternationCharacterSet() else {
|
|
27
|
+
completion(
|
|
28
|
+
NativeErrorInfo(
|
|
29
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
30
|
+
message: "n is error",
|
|
31
|
+
error: nil
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
printer.writeCommand(with: POSCommand.selectInternationCharacterSets(convertN))
|
|
38
|
+
completion(nil)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public func isConnect(connectInfo: String, resolve: @escaping (_ value: [String: Any]) -> Void, reject: @escaping (_ error: NativeErrorInfo) -> Void) {
|
|
43
|
+
DispatchQueue.main.async {
|
|
44
|
+
var status = false
|
|
45
|
+
if let printer = Printers.shared.getPrinter(connectInfo: connectInfo) {
|
|
46
|
+
status = printer.isConnect()
|
|
47
|
+
} else {
|
|
48
|
+
status = false
|
|
49
|
+
}
|
|
50
|
+
var result: [String: Any] = [:]
|
|
51
|
+
result["status"] = status
|
|
52
|
+
resolve(result)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public func initializePrinter(connectInfo: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
57
|
+
DispatchQueue.main.async {
|
|
58
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
59
|
+
completion(
|
|
60
|
+
NativeErrorInfo(
|
|
61
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
62
|
+
message: "not found printer:\(connectInfo)",
|
|
63
|
+
error: nil
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
printer.writeCommand(with: POSCommand.initializePrinter())
|
|
69
|
+
completion(nil)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public func setCharSet(connectInfo: String, charSet: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
74
|
+
DispatchQueue.main.async {
|
|
75
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
76
|
+
completion(
|
|
77
|
+
NativeErrorInfo(
|
|
78
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
79
|
+
message: "not found printer:\(connectInfo)",
|
|
80
|
+
error: nil
|
|
81
|
+
)
|
|
82
|
+
)
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
guard let charSet = charSet.toCharSet() else {
|
|
86
|
+
completion(
|
|
87
|
+
NativeErrorInfo(
|
|
88
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
89
|
+
message: "charSet is error",
|
|
90
|
+
error: nil
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
printer.charSet = charSet
|
|
97
|
+
completion(nil)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public func printString(connectInfo: String, data: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
102
|
+
DispatchQueue.main.async {
|
|
103
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
104
|
+
completion(
|
|
105
|
+
NativeErrorInfo(
|
|
106
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
107
|
+
message: "not found printer:\(connectInfo)",
|
|
108
|
+
error: nil
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
guard let data = data.data(using: printer.charSet) else {
|
|
114
|
+
completion(
|
|
115
|
+
NativeErrorInfo(
|
|
116
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
117
|
+
message: "data is error",
|
|
118
|
+
error: nil
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
printer.writeCommand(with: data)
|
|
124
|
+
completion(nil)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public func printTextSize(connectInfo: String, payload: RCTESCPrintTextSizeRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
129
|
+
DispatchQueue.main.async {
|
|
130
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
131
|
+
completion(
|
|
132
|
+
NativeErrorInfo(
|
|
133
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
134
|
+
message: "not found printer:\(connectInfo)",
|
|
135
|
+
error: nil
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
guard let textWidth = payload.textWidth.toESCTextWidth() else {
|
|
141
|
+
completion(
|
|
142
|
+
NativeErrorInfo(
|
|
143
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
144
|
+
message: "textWidth is error",
|
|
145
|
+
error: nil
|
|
146
|
+
)
|
|
147
|
+
)
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
guard let textHeight = payload.textHeight.toESCTextHeight() else {
|
|
151
|
+
completion(
|
|
152
|
+
NativeErrorInfo(
|
|
153
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
154
|
+
message: "textHeight is error",
|
|
155
|
+
error: nil
|
|
156
|
+
)
|
|
157
|
+
)
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
printer.writeCommand(with: POSCommand.printTextSize(payload.data, textWid: textWidth, textHei: textHeight))
|
|
162
|
+
completion(nil)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public func printTextAttribute(connectInfo: String, data: String, attribute: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
167
|
+
DispatchQueue.main.async {
|
|
168
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
169
|
+
completion(
|
|
170
|
+
NativeErrorInfo(
|
|
171
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
172
|
+
message: "not found printer:\(connectInfo)",
|
|
173
|
+
error: nil
|
|
174
|
+
)
|
|
175
|
+
)
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
guard let attribute = attribute.toESCTextAttribute() else {
|
|
179
|
+
completion(
|
|
180
|
+
NativeErrorInfo(
|
|
181
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
182
|
+
message: "attribute is error",
|
|
183
|
+
error: nil
|
|
184
|
+
)
|
|
185
|
+
)
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
printer.writeCommand(with: POSCommand.printTextAttribute(data, attribute: attribute))
|
|
190
|
+
completion(nil)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
public func printTextAlignment(connectInfo: String, data: String, alignment: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
195
|
+
DispatchQueue.main.async {
|
|
196
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
197
|
+
completion(
|
|
198
|
+
NativeErrorInfo(
|
|
199
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
200
|
+
message: "not found printer:\(connectInfo)",
|
|
201
|
+
error: nil
|
|
202
|
+
)
|
|
203
|
+
)
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
guard let alignment = alignment.toESCAlignment() else {
|
|
207
|
+
completion(
|
|
208
|
+
NativeErrorInfo(
|
|
209
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
210
|
+
message: "alignment is error",
|
|
211
|
+
error: nil
|
|
212
|
+
)
|
|
213
|
+
)
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
printer.writeCommand(with: POSCommand.printTextAlignment(data, alignment: alignment))
|
|
218
|
+
completion(nil)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
public func printText(connectInfo: String, payload: RCTESCPrintTextRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
223
|
+
DispatchQueue.main.async {
|
|
224
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
225
|
+
completion(
|
|
226
|
+
NativeErrorInfo(
|
|
227
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
228
|
+
message: "not found printer:\(connectInfo)",
|
|
229
|
+
error: nil
|
|
230
|
+
)
|
|
231
|
+
)
|
|
232
|
+
return
|
|
233
|
+
}
|
|
234
|
+
guard let alignment = payload.alignment.toESCAlignment() else {
|
|
235
|
+
completion(
|
|
236
|
+
NativeErrorInfo(
|
|
237
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
238
|
+
message: "alignment is error",
|
|
239
|
+
error: nil
|
|
240
|
+
)
|
|
241
|
+
)
|
|
242
|
+
return
|
|
243
|
+
}
|
|
244
|
+
guard let attribute = payload.attribute.toESCTextAttribute() else {
|
|
245
|
+
completion(
|
|
246
|
+
NativeErrorInfo(
|
|
247
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
248
|
+
message: "attribute is error",
|
|
249
|
+
error: nil
|
|
250
|
+
)
|
|
251
|
+
)
|
|
252
|
+
return
|
|
253
|
+
}
|
|
254
|
+
guard let textWidth = payload.textWidth.toESCTextWidth() else {
|
|
255
|
+
completion(
|
|
256
|
+
NativeErrorInfo(
|
|
257
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
258
|
+
message: "textWidth is error",
|
|
259
|
+
error: nil
|
|
260
|
+
)
|
|
261
|
+
)
|
|
262
|
+
return
|
|
263
|
+
}
|
|
264
|
+
guard let textHeight = payload.textHeight.toESCTextHeight() else {
|
|
265
|
+
completion(
|
|
266
|
+
NativeErrorInfo(
|
|
267
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
268
|
+
message: "textHeight is error",
|
|
269
|
+
error: nil
|
|
270
|
+
)
|
|
271
|
+
)
|
|
272
|
+
return
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
printer.writeCommand(with: POSCommand.printText(payload.data, alignment: alignment, attribute: attribute, textWid: textWidth, textHei: textHeight))
|
|
276
|
+
completion(nil)
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public func printBitmap(connectInfo: String, payload: RCTESCPrintBitmapRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
281
|
+
DispatchQueue.main.async {
|
|
282
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
283
|
+
completion(
|
|
284
|
+
NativeErrorInfo(
|
|
285
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
286
|
+
message: "not found printer:\(connectInfo)",
|
|
287
|
+
error: nil
|
|
288
|
+
)
|
|
289
|
+
)
|
|
290
|
+
return
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
guard let image = Utils.loadAndScaleBitmap(bitmapContent: payload.bitmapContent, bitmapPath: payload.bitmapPath, width: Int(payload.width)) else {
|
|
294
|
+
completion(
|
|
295
|
+
NativeErrorInfo(
|
|
296
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
297
|
+
message: "bitmap is error",
|
|
298
|
+
error: nil
|
|
299
|
+
)
|
|
300
|
+
)
|
|
301
|
+
return
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
guard let alignment = payload.alignment.toESCAlignment() else {
|
|
305
|
+
completion(
|
|
306
|
+
NativeErrorInfo(
|
|
307
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
308
|
+
message: "alignment is error",
|
|
309
|
+
error: nil
|
|
310
|
+
)
|
|
311
|
+
)
|
|
312
|
+
return
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
guard let model = payload.model.toESCBmpModel() else {
|
|
316
|
+
completion(
|
|
317
|
+
NativeErrorInfo(
|
|
318
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
319
|
+
message: "model is error",
|
|
320
|
+
error: nil
|
|
321
|
+
)
|
|
322
|
+
)
|
|
323
|
+
return
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
guard let bmpType = payload.type?.toESCBmpType() else {
|
|
327
|
+
completion(
|
|
328
|
+
NativeErrorInfo(
|
|
329
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
330
|
+
message: "type is error",
|
|
331
|
+
error: nil
|
|
332
|
+
)
|
|
333
|
+
)
|
|
334
|
+
return
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
var comand = Data()
|
|
338
|
+
comand.append(POSCommand.selectAlignment(alignment))
|
|
339
|
+
comand.append(POSCommand.printRasteBmp(withM: model, andImage: image, andType: bmpType))
|
|
340
|
+
printer.writeCommand(with: comand)
|
|
341
|
+
completion(nil)
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
public func compressionPrintBitmap(connectInfo: String, payload: RCTESCPrintBitmapRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
346
|
+
DispatchQueue.main.async {
|
|
347
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
348
|
+
completion(
|
|
349
|
+
NativeErrorInfo(
|
|
350
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
351
|
+
message: "not found printer:\(connectInfo)",
|
|
352
|
+
error: nil
|
|
353
|
+
)
|
|
354
|
+
)
|
|
355
|
+
return
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
guard let image = Utils.loadAndScaleBitmap(bitmapContent: payload.bitmapContent, bitmapPath: payload.bitmapPath, width: Int(payload.width)) else {
|
|
359
|
+
completion(
|
|
360
|
+
NativeErrorInfo(
|
|
361
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
362
|
+
message: "bitmap is error",
|
|
363
|
+
error: nil
|
|
364
|
+
)
|
|
365
|
+
)
|
|
366
|
+
return
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
guard let alignment = payload.alignment.toESCAlignment() else {
|
|
370
|
+
completion(
|
|
371
|
+
NativeErrorInfo(
|
|
372
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
373
|
+
message: "alignment is error",
|
|
374
|
+
error: nil
|
|
375
|
+
)
|
|
376
|
+
)
|
|
377
|
+
return
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
guard let model = payload.model.toESCBmpModel() else {
|
|
381
|
+
completion(
|
|
382
|
+
NativeErrorInfo(
|
|
383
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
384
|
+
message: "model is error",
|
|
385
|
+
error: nil
|
|
386
|
+
)
|
|
387
|
+
)
|
|
388
|
+
return
|
|
389
|
+
}
|
|
390
|
+
guard let bmpType = payload.type?.toESCBmpType() else {
|
|
391
|
+
completion(
|
|
392
|
+
NativeErrorInfo(
|
|
393
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
394
|
+
message: "type is error",
|
|
395
|
+
error: nil
|
|
396
|
+
)
|
|
397
|
+
)
|
|
398
|
+
return
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
var data = Data()
|
|
402
|
+
data.append(POSCommand.selectAlignment(alignment))
|
|
403
|
+
data.append(POSCommand.compressionPrintBmp(withM: model, andImage: image, andType: bmpType))
|
|
404
|
+
printer.writeCommand(with: data)
|
|
405
|
+
completion(nil)
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
public func printBarCode(connectInfo: String, payload: RCTESCPrintBarCodeRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
410
|
+
DispatchQueue.main.async {
|
|
411
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
412
|
+
completion(
|
|
413
|
+
NativeErrorInfo(
|
|
414
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
415
|
+
message: "not found printer:\(connectInfo)",
|
|
416
|
+
error: nil
|
|
417
|
+
)
|
|
418
|
+
)
|
|
419
|
+
return
|
|
420
|
+
}
|
|
421
|
+
guard let codeType = payload.codeType.toESCBarCodeType() else {
|
|
422
|
+
completion(
|
|
423
|
+
NativeErrorInfo(
|
|
424
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
425
|
+
message: "codeType is error",
|
|
426
|
+
error: nil
|
|
427
|
+
)
|
|
428
|
+
)
|
|
429
|
+
return
|
|
430
|
+
}
|
|
431
|
+
guard let alignment = payload.alignment.toESCAlignment() else {
|
|
432
|
+
completion(
|
|
433
|
+
NativeErrorInfo(
|
|
434
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
435
|
+
message: "alignment is error",
|
|
436
|
+
error: nil
|
|
437
|
+
)
|
|
438
|
+
)
|
|
439
|
+
return
|
|
440
|
+
}
|
|
441
|
+
guard let textPosition = payload.textPosition.toESCTextPosition() else {
|
|
442
|
+
completion(
|
|
443
|
+
NativeErrorInfo(
|
|
444
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
445
|
+
message: "textPosition is error",
|
|
446
|
+
error: nil
|
|
447
|
+
)
|
|
448
|
+
)
|
|
449
|
+
return
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
var command = Data()
|
|
453
|
+
command.append(POSCommand.setBarcodeWidth(Int32(payload.width)))
|
|
454
|
+
command.append(POSCommand.setBarcodeHeight(Int32(payload.height)))
|
|
455
|
+
command.append(POSCommand.selectAlignment(alignment))
|
|
456
|
+
command.append(POSCommand.selectHRICharactersPrintPosition(textPosition))
|
|
457
|
+
command.append(POSCommand.printBarcode(withM: codeType, andContent: payload.data, useEnCodeing: printer.charSet.rawValue))
|
|
458
|
+
printer.writeCommand(with: command)
|
|
459
|
+
completion(nil)
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
public func lineFeed(connectInfo: String, lineCount: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
464
|
+
DispatchQueue.main.async {
|
|
465
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
466
|
+
completion(
|
|
467
|
+
NativeErrorInfo(
|
|
468
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
469
|
+
message: "not found printer:\(connectInfo)",
|
|
470
|
+
error: nil
|
|
471
|
+
)
|
|
472
|
+
)
|
|
473
|
+
return
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
printer.writeCommand(with: POSCommand.printAndFeed(Int32(lineCount)))
|
|
477
|
+
completion(nil)
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
public func feedDot(connectInfo: String, dotCount: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
482
|
+
DispatchQueue.main.async {
|
|
483
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
484
|
+
completion(
|
|
485
|
+
NativeErrorInfo(
|
|
486
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
487
|
+
message: "not found printer:\(connectInfo)",
|
|
488
|
+
error: nil
|
|
489
|
+
)
|
|
490
|
+
)
|
|
491
|
+
return
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
printer.writeCommand(with: POSCommand.printAndFeedForwardWhitN(Int32(dotCount)))
|
|
495
|
+
completion(nil)
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
public func printerCheck(connectInfo: String, type: String, timeout: Double, resolve: @escaping (_ value: [String: Any]) -> Void, reject: @escaping (_ error: NativeErrorInfo) -> Void) {
|
|
500
|
+
DispatchQueue.main.async {
|
|
501
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
502
|
+
reject(
|
|
503
|
+
NativeErrorInfo(
|
|
504
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
505
|
+
message: "not found printer:\(connectInfo)",
|
|
506
|
+
error: nil
|
|
507
|
+
)
|
|
508
|
+
)
|
|
509
|
+
return
|
|
510
|
+
}
|
|
511
|
+
guard let type = type.toESCPrinterCheckType() else {
|
|
512
|
+
reject(
|
|
513
|
+
NativeErrorInfo(
|
|
514
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
515
|
+
message: "type is error",
|
|
516
|
+
error: nil
|
|
517
|
+
)
|
|
518
|
+
)
|
|
519
|
+
return
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
printer.printerCheck(type: type) { data in
|
|
523
|
+
var status = "UNKNOWN"
|
|
524
|
+
if let data = data {
|
|
525
|
+
if let firstByte = data.first {
|
|
526
|
+
switch Int(firstByte) {
|
|
527
|
+
case -2:
|
|
528
|
+
status = "START_READ_LOOP_RETURN"
|
|
529
|
+
case -3:
|
|
530
|
+
status = "DISCONNECT"
|
|
531
|
+
case -4:
|
|
532
|
+
status = "TIMEOUT"
|
|
533
|
+
default:
|
|
534
|
+
break
|
|
535
|
+
}
|
|
536
|
+
} else {
|
|
537
|
+
status = "TIMEOUT"
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
var result: [String: Any] = [:]
|
|
541
|
+
result["status"] = status
|
|
542
|
+
resolve(result)
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
public func printerStatus(connectInfo: String, resolve: @escaping (_ value: [String: Any]) -> Void, reject: @escaping (_ error: NativeErrorInfo) -> Void) {
|
|
548
|
+
DispatchQueue.main.async {
|
|
549
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
550
|
+
reject(
|
|
551
|
+
NativeErrorInfo(
|
|
552
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
553
|
+
message: "not found printer:\(connectInfo)",
|
|
554
|
+
error: nil
|
|
555
|
+
)
|
|
556
|
+
)
|
|
557
|
+
return
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
printer.printerStatus { data in
|
|
561
|
+
var status = "UNKNOWN"
|
|
562
|
+
var debugCode: Int?
|
|
563
|
+
if let data = data {
|
|
564
|
+
if let firstByte = data.first {
|
|
565
|
+
debugCode = Int(firstByte)
|
|
566
|
+
switch debugCode {
|
|
567
|
+
case 0x12:
|
|
568
|
+
status = "NORMAL"
|
|
569
|
+
case 0x16:
|
|
570
|
+
status = "COVER_OPEN"
|
|
571
|
+
case 0x32:
|
|
572
|
+
status = "PAPER_EMPTY"
|
|
573
|
+
case 0x36:
|
|
574
|
+
status = "COVER_OPEN_AND_PAPER_EMPTY"
|
|
575
|
+
case 0x1a:
|
|
576
|
+
status = "PRESS_FEED"
|
|
577
|
+
default:
|
|
578
|
+
status = "OTHER_ERROR"
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
var result: [String: Any] = [:]
|
|
583
|
+
result["status"] = status
|
|
584
|
+
result["debugCode"] = status
|
|
585
|
+
resolve(result)
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
public func printerStatusII(connectInfo: String, resolve: @escaping (_ value: [String: Any]) -> Void, reject: @escaping (_ error: NativeErrorInfo) -> Void) {
|
|
591
|
+
DispatchQueue.main.async {
|
|
592
|
+
reject(NativeErrorInfo(code: PrinterErrors.NOT_YET_IMPLEMENTED_ERROR, message: "Not yet implemented", error: nil))
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
public func printQRCode(connectInfo: String, payload: RCTESCPrintQRCodeRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
597
|
+
DispatchQueue.main.async {
|
|
598
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
599
|
+
completion(
|
|
600
|
+
NativeErrorInfo(
|
|
601
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
602
|
+
message: "not found printer:\(connectInfo)",
|
|
603
|
+
error: nil
|
|
604
|
+
)
|
|
605
|
+
)
|
|
606
|
+
return
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
guard let ecLevel = payload.ecLevel.toESCECLevel() else {
|
|
610
|
+
completion(
|
|
611
|
+
NativeErrorInfo(
|
|
612
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
613
|
+
message: "ecLevel is error",
|
|
614
|
+
error: nil
|
|
615
|
+
)
|
|
616
|
+
)
|
|
617
|
+
return
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
guard let alignment = payload.alignment.toESCAlignment() else {
|
|
621
|
+
completion(
|
|
622
|
+
NativeErrorInfo(
|
|
623
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
624
|
+
message: "alignment is error",
|
|
625
|
+
error: nil
|
|
626
|
+
)
|
|
627
|
+
)
|
|
628
|
+
return
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
printer.writeCommand(with: POSCommand.printQRCode(Int32(payload.moduleSize), level: ecLevel, code: payload.data, useEnCodeing: printer.charSet.rawValue))
|
|
632
|
+
completion(nil)
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
public func cutPaper(connectInfo: String, model: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
637
|
+
DispatchQueue.main.async {
|
|
638
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
639
|
+
completion(
|
|
640
|
+
NativeErrorInfo(
|
|
641
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
642
|
+
message: "not found printer:\(connectInfo)",
|
|
643
|
+
error: nil
|
|
644
|
+
)
|
|
645
|
+
)
|
|
646
|
+
return
|
|
647
|
+
}
|
|
648
|
+
guard let model = model.toESCCutModel() else {
|
|
649
|
+
completion(
|
|
650
|
+
NativeErrorInfo(
|
|
651
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
652
|
+
message: "alignment is error",
|
|
653
|
+
error: nil
|
|
654
|
+
)
|
|
655
|
+
)
|
|
656
|
+
return
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
printer.writeCommand(with: POSCommand.selectCutPageModelAndCutpage(model))
|
|
660
|
+
completion(nil)
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
public func cutHalfAndFeed(connectInfo: String, distance: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
665
|
+
DispatchQueue.main.async {
|
|
666
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
667
|
+
completion(
|
|
668
|
+
NativeErrorInfo(
|
|
669
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
670
|
+
message: "not found printer:\(connectInfo)",
|
|
671
|
+
error: nil
|
|
672
|
+
)
|
|
673
|
+
)
|
|
674
|
+
return
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
printer.writeCommand(with: POSCommand.selectCutPageModelAndCutpage(withM: 66, andN: Int32(distance)))
|
|
678
|
+
completion(nil)
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
public func setPrintArea(connectInfo: String, payload: RCTESCSetPrintAreaRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
683
|
+
DispatchQueue.main.async {
|
|
684
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
685
|
+
completion(
|
|
686
|
+
NativeErrorInfo(
|
|
687
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
688
|
+
message: "not found printer:\(connectInfo)",
|
|
689
|
+
error: nil
|
|
690
|
+
)
|
|
691
|
+
)
|
|
692
|
+
return
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
let x = Int32(payload.x)
|
|
696
|
+
let y = Int32(payload.y)
|
|
697
|
+
let width = Int32(payload.width)
|
|
698
|
+
let height = Int32(payload.height)
|
|
699
|
+
|
|
700
|
+
let xL = x % 256
|
|
701
|
+
var xH = x / 256
|
|
702
|
+
if xH > 255 {
|
|
703
|
+
xH = 255
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
let yL = y % 256
|
|
707
|
+
var yH = y / 256
|
|
708
|
+
if yH > 255 {
|
|
709
|
+
yH = 255
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
var dxH = width / 256
|
|
713
|
+
if dxH > 255 {
|
|
714
|
+
dxH = 255
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
var dyH = height / 256
|
|
718
|
+
if dyH > 255 {
|
|
719
|
+
dyH = 255
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
printer.writeCommand(with: POSCommand.setPrintAreaUnderPageModelWithxL(xL, andxH: xH, andyL: yL, andyH: yH, anddxL: width % 256, anddxH: dxH, anddyL: height % 256, anddyH: dyH))
|
|
723
|
+
completion(nil)
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
public func setPageModel(connectInfo: String, isOpen: Bool, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
728
|
+
DispatchQueue.main.async {
|
|
729
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
730
|
+
completion(
|
|
731
|
+
NativeErrorInfo(
|
|
732
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
733
|
+
message: "not found printer:\(connectInfo)",
|
|
734
|
+
error: nil
|
|
735
|
+
)
|
|
736
|
+
)
|
|
737
|
+
return
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
if isOpen {
|
|
741
|
+
printer.writeCommand(with: POSCommand.selectPagemode())
|
|
742
|
+
} else {
|
|
743
|
+
printer.writeCommand(with: POSCommand.selectStabdardMode())
|
|
744
|
+
}
|
|
745
|
+
completion(nil)
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
public func printPageModelData(connectInfo: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
750
|
+
DispatchQueue.main.async {
|
|
751
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
752
|
+
completion(
|
|
753
|
+
NativeErrorInfo(
|
|
754
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
755
|
+
message: "not found printer:\(connectInfo)",
|
|
756
|
+
error: nil
|
|
757
|
+
)
|
|
758
|
+
)
|
|
759
|
+
return
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
printer.writeCommand(with: POSCommand.printUnderPageModel())
|
|
763
|
+
completion(nil)
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
public func setPrintDirection(connectInfo: String, direction: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
768
|
+
DispatchQueue.main.async {
|
|
769
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
770
|
+
completion(
|
|
771
|
+
NativeErrorInfo(
|
|
772
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
773
|
+
message: "not found printer:\(connectInfo)",
|
|
774
|
+
error: nil
|
|
775
|
+
)
|
|
776
|
+
)
|
|
777
|
+
return
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
guard let direction = direction.toESCDirection() else {
|
|
781
|
+
completion(
|
|
782
|
+
NativeErrorInfo(
|
|
783
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
784
|
+
message: "direction is error",
|
|
785
|
+
error: nil
|
|
786
|
+
)
|
|
787
|
+
)
|
|
788
|
+
return
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
printer.writeCommand(with: POSCommand.selectPrintDirectionUnderPageMode(direction))
|
|
792
|
+
completion(nil)
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
public func setAbsoluteHorizontal(connectInfo: String, position: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
797
|
+
DispatchQueue.main.async {
|
|
798
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
799
|
+
completion(
|
|
800
|
+
NativeErrorInfo(
|
|
801
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
802
|
+
message: "not found printer:\(connectInfo)",
|
|
803
|
+
error: nil
|
|
804
|
+
)
|
|
805
|
+
)
|
|
806
|
+
return
|
|
807
|
+
}
|
|
808
|
+
var nH = Int32(position) / 256
|
|
809
|
+
if nH > 255 {
|
|
810
|
+
nH = 255
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
printer.writeCommand(with: POSCommand.setAbsolutePrintPositionWithNL(Int32(position) % 256, andNH: nH))
|
|
814
|
+
completion(nil)
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
public func setRelativeHorizontal(connectInfo: String, position: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
819
|
+
DispatchQueue.main.async {
|
|
820
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
821
|
+
completion(
|
|
822
|
+
NativeErrorInfo(
|
|
823
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
824
|
+
message: "not found printer:\(connectInfo)",
|
|
825
|
+
error: nil
|
|
826
|
+
)
|
|
827
|
+
)
|
|
828
|
+
return
|
|
829
|
+
}
|
|
830
|
+
var nH = Int32(position) / 256
|
|
831
|
+
if nH > 255 {
|
|
832
|
+
nH = 255
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
printer.writeCommand(with: POSCommand.setRelativeHorizontalPrintPositionWithnL(Int32(position) % 256, andnH: nH))
|
|
836
|
+
completion(nil)
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
public func setAbsoluteVertical(connectInfo: String, position: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
841
|
+
DispatchQueue.main.async {
|
|
842
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
843
|
+
completion(
|
|
844
|
+
NativeErrorInfo(
|
|
845
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
846
|
+
message: "not found printer:\(connectInfo)",
|
|
847
|
+
error: nil
|
|
848
|
+
)
|
|
849
|
+
)
|
|
850
|
+
return
|
|
851
|
+
}
|
|
852
|
+
var nH = Int32(position) / 256
|
|
853
|
+
if nH > 255 {
|
|
854
|
+
nH = 255
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
printer.writeCommand(with: POSCommand.setAbsolutePositionUnderPageModelWithnL(Int32(position) % 256, andnH: nH))
|
|
858
|
+
completion(nil)
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
public func setRelativeVertical(connectInfo: String, position: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
863
|
+
DispatchQueue.main.async {
|
|
864
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
865
|
+
completion(
|
|
866
|
+
NativeErrorInfo(
|
|
867
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
868
|
+
message: "not found printer:\(connectInfo)",
|
|
869
|
+
error: nil
|
|
870
|
+
)
|
|
871
|
+
)
|
|
872
|
+
return
|
|
873
|
+
}
|
|
874
|
+
var nH = Int32(position) / 256
|
|
875
|
+
if nH > 255 {
|
|
876
|
+
nH = 255
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
printer.writeCommand(with: POSCommand.setVertivalRelativePositionUnderPageModelWithNL(Int32(position) % 256, andNH: nH))
|
|
880
|
+
completion(nil)
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
public func setTextStyle(connectInfo: String, payload: RCTESCSetTextStyleRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
885
|
+
DispatchQueue.main.async {
|
|
886
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
887
|
+
completion(
|
|
888
|
+
NativeErrorInfo(
|
|
889
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
890
|
+
message: "not found printer:\(connectInfo)",
|
|
891
|
+
error: nil
|
|
892
|
+
)
|
|
893
|
+
)
|
|
894
|
+
return
|
|
895
|
+
}
|
|
896
|
+
guard let attribute = payload.attribute.toESCTextAttribute() else {
|
|
897
|
+
completion(
|
|
898
|
+
NativeErrorInfo(
|
|
899
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
900
|
+
message: "attribute is error",
|
|
901
|
+
error: nil
|
|
902
|
+
)
|
|
903
|
+
)
|
|
904
|
+
return
|
|
905
|
+
}
|
|
906
|
+
guard let textWidth = payload.textWidth.toESCTextWidth() else {
|
|
907
|
+
completion(
|
|
908
|
+
NativeErrorInfo(
|
|
909
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
910
|
+
message: "textWidth is error",
|
|
911
|
+
error: nil
|
|
912
|
+
)
|
|
913
|
+
)
|
|
914
|
+
return
|
|
915
|
+
}
|
|
916
|
+
guard let textHeight = payload.textHeight.toESCTextHeight() else {
|
|
917
|
+
completion(
|
|
918
|
+
NativeErrorInfo(
|
|
919
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
920
|
+
message: "textHeight is error",
|
|
921
|
+
error: nil
|
|
922
|
+
)
|
|
923
|
+
)
|
|
924
|
+
return
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
var command = Data()
|
|
928
|
+
command.append(POSCommand.setTextSize(textWidth, height: textHeight))
|
|
929
|
+
// command.append(POSCommand.printTextAttribute(<#T##data: String!##String!#>, attribute: <#T##Int32#>)(textWidth, height: textHeight))
|
|
930
|
+
printer.writeCommand(with: command)
|
|
931
|
+
completion(nil)
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
public func setAlignment(connectInfo: String, alignment: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
936
|
+
DispatchQueue.main.async {
|
|
937
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
938
|
+
completion(
|
|
939
|
+
NativeErrorInfo(
|
|
940
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
941
|
+
message: "not found printer:\(connectInfo)",
|
|
942
|
+
error: nil
|
|
943
|
+
)
|
|
944
|
+
)
|
|
945
|
+
return
|
|
946
|
+
}
|
|
947
|
+
guard let alignment = alignment.toESCAlignment() else {
|
|
948
|
+
completion(
|
|
949
|
+
NativeErrorInfo(
|
|
950
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
951
|
+
message: "alignment is error",
|
|
952
|
+
error: nil
|
|
953
|
+
)
|
|
954
|
+
)
|
|
955
|
+
return
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
printer.writeCommand(with: POSCommand.selectAlignment(alignment))
|
|
959
|
+
completion(nil)
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
public func downloadNVImage(connectInfo: String, imagePaths: String, imageWidth: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
964
|
+
DispatchQueue.main.async {
|
|
965
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
966
|
+
completion(
|
|
967
|
+
NativeErrorInfo(
|
|
968
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
969
|
+
message: "not found printer:\(connectInfo)",
|
|
970
|
+
error: nil
|
|
971
|
+
)
|
|
972
|
+
)
|
|
973
|
+
return
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
let imagePathList = imagePaths.components(separatedBy: ",")
|
|
977
|
+
var command = Data()
|
|
978
|
+
for (index, imagePath) in imagePathList.enumerated() {
|
|
979
|
+
guard let image = UIImage(contentsOfFile: imagePath) else {
|
|
980
|
+
completion(
|
|
981
|
+
NativeErrorInfo(
|
|
982
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
983
|
+
message: "imagePath error: \(imagePath)",
|
|
984
|
+
error: nil
|
|
985
|
+
)
|
|
986
|
+
)
|
|
987
|
+
return
|
|
988
|
+
}
|
|
989
|
+
command.append(POSCommand.definedFlashBmp(withN: Int32(index), andBmp: image, andBmpType: Dithering, andPrint: RasterNolmorWH, andPaperHeight: Int32(imageWidth)))
|
|
990
|
+
}
|
|
991
|
+
printer.writeCommand(with: command)
|
|
992
|
+
completion(nil)
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
public func printNVImage(connectInfo: String, index: Double, model: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
997
|
+
DispatchQueue.main.async {
|
|
998
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
999
|
+
completion(
|
|
1000
|
+
NativeErrorInfo(
|
|
1001
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
1002
|
+
message: "not found printer:\(connectInfo)",
|
|
1003
|
+
error: nil
|
|
1004
|
+
)
|
|
1005
|
+
)
|
|
1006
|
+
return
|
|
1007
|
+
}
|
|
1008
|
+
guard let model = model.toESCBmpModel() else {
|
|
1009
|
+
completion(
|
|
1010
|
+
NativeErrorInfo(
|
|
1011
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
1012
|
+
message: "model is error",
|
|
1013
|
+
error: nil
|
|
1014
|
+
)
|
|
1015
|
+
)
|
|
1016
|
+
return
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
printer.writeCommand(with: POSCommand.printBmpInFLASH(withN: Int32(index), andM: Int32(model.rawValue)))
|
|
1020
|
+
completion(nil)
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
public func selectBitmapModel(connectInfo: String, payload: RCTESCSelectBitmapModelRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
1025
|
+
DispatchQueue.main.async {
|
|
1026
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
1027
|
+
completion(
|
|
1028
|
+
NativeErrorInfo(
|
|
1029
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
1030
|
+
message: "not found printer:\(connectInfo)",
|
|
1031
|
+
error: nil
|
|
1032
|
+
)
|
|
1033
|
+
)
|
|
1034
|
+
return
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
guard let url = URL(string: payload.bitmapPath), let bitmap = try? Data(contentsOf: url) else {
|
|
1038
|
+
completion(
|
|
1039
|
+
NativeErrorInfo(
|
|
1040
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
1041
|
+
message: "bitmapPath is error",
|
|
1042
|
+
error: nil
|
|
1043
|
+
)
|
|
1044
|
+
)
|
|
1045
|
+
return
|
|
1046
|
+
}
|
|
1047
|
+
guard let model = payload.model.toESCSelectBitmapModel() else {
|
|
1048
|
+
completion(
|
|
1049
|
+
NativeErrorInfo(
|
|
1050
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
1051
|
+
message: "model is error",
|
|
1052
|
+
error: nil
|
|
1053
|
+
)
|
|
1054
|
+
)
|
|
1055
|
+
return
|
|
1056
|
+
}
|
|
1057
|
+
let width = Int32(payload.width)
|
|
1058
|
+
printer.writeCommand(with: POSCommand.selectBmpModel(withM: model, andnL: width % 256, andnH: width / 256, andNSData: bitmap))
|
|
1059
|
+
completion(nil)
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
public func setLineSpacing(connectInfo: String, space: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
1064
|
+
DispatchQueue.main.async {
|
|
1065
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
1066
|
+
completion(
|
|
1067
|
+
NativeErrorInfo(
|
|
1068
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
1069
|
+
message: "not found printer:\(connectInfo)",
|
|
1070
|
+
error: nil
|
|
1071
|
+
)
|
|
1072
|
+
)
|
|
1073
|
+
return
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
printer.writeCommand(with: POSCommand.setDefultLineSpace(Int32(space)))
|
|
1077
|
+
completion(nil)
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
public func setTurnUpsideDownMode(connectInfo: String, on: Bool, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
1082
|
+
DispatchQueue.main.async {
|
|
1083
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
1084
|
+
completion(
|
|
1085
|
+
NativeErrorInfo(
|
|
1086
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
1087
|
+
message: "not found printer:\(connectInfo)",
|
|
1088
|
+
error: nil
|
|
1089
|
+
)
|
|
1090
|
+
)
|
|
1091
|
+
return
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
printer.writeCommand(with: POSCommand.selectOrCancleInvertPrintModel(on ? 1 : 0))
|
|
1095
|
+
completion(nil)
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
public func selectCodePage(connectInfo: String, page: Double, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
1100
|
+
DispatchQueue.main.async {
|
|
1101
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
1102
|
+
completion(
|
|
1103
|
+
NativeErrorInfo(
|
|
1104
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
1105
|
+
message: "not found printer:\(connectInfo)",
|
|
1106
|
+
error: nil
|
|
1107
|
+
)
|
|
1108
|
+
)
|
|
1109
|
+
return
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
printer.writeCommand(with: POSCommand.setCodePage(Int32(page)))
|
|
1113
|
+
completion(nil)
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
public func selectCharacterFont(connectInfo: String, font: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
1118
|
+
DispatchQueue.main.async {
|
|
1119
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
1120
|
+
completion(
|
|
1121
|
+
NativeErrorInfo(
|
|
1122
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
1123
|
+
message: "not found printer:\(connectInfo)",
|
|
1124
|
+
error: nil
|
|
1125
|
+
)
|
|
1126
|
+
)
|
|
1127
|
+
return
|
|
1128
|
+
}
|
|
1129
|
+
guard let font = font.toESCFontType() else {
|
|
1130
|
+
completion(
|
|
1131
|
+
NativeErrorInfo(
|
|
1132
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
1133
|
+
message: "font is error",
|
|
1134
|
+
error: nil
|
|
1135
|
+
)
|
|
1136
|
+
)
|
|
1137
|
+
return
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
printer.writeCommand(with: POSCommand.selectHRIFont(font))
|
|
1141
|
+
completion(nil)
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
public func printPDF417(connectInfo: String, payload: RCTESCPrintPDF417Request, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
1146
|
+
DispatchQueue.main.async {
|
|
1147
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
1148
|
+
completion(
|
|
1149
|
+
NativeErrorInfo(
|
|
1150
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
1151
|
+
message: "not found printer:\(connectInfo)",
|
|
1152
|
+
error: nil
|
|
1153
|
+
)
|
|
1154
|
+
)
|
|
1155
|
+
return
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
let cellWidth = Int32(payload.cellWidth)
|
|
1159
|
+
let cellHeightRatio = Int32(payload.cellHeightRatio)
|
|
1160
|
+
let numberOfColumns = Int32(payload.numberOfColumns)
|
|
1161
|
+
let numberOfRows = Int32(payload.numberOfRows)
|
|
1162
|
+
let eclType = Int32(payload.eclType)
|
|
1163
|
+
let eclValue = Int32(payload.eclValue)
|
|
1164
|
+
guard let alignment = payload.alignment.toESCAlignment() else {
|
|
1165
|
+
completion(
|
|
1166
|
+
NativeErrorInfo(
|
|
1167
|
+
code: PrinterErrors.PARAMS_ERROR,
|
|
1168
|
+
message: "alignment is error",
|
|
1169
|
+
error: nil
|
|
1170
|
+
)
|
|
1171
|
+
)
|
|
1172
|
+
return
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
var command = Data()
|
|
1176
|
+
command.append(POSCommand.setPdf417Columns(numberOfColumns))
|
|
1177
|
+
command.append(POSCommand.setpdf417Width(ofModule: cellWidth))
|
|
1178
|
+
command.append(POSCommand.setpdf417RowHeight(cellHeightRatio))
|
|
1179
|
+
command.append(POSCommand.selectAlignment(alignment))
|
|
1180
|
+
command.append(POSCommand.storethepdf417WithpL(Int32(payload.data.count) % 256, andpH: Int32(payload.data.count) / 256, andContent: payload.data, usEnCoding: printer.charSet.rawValue))
|
|
1181
|
+
command.append(POSCommand.printPdf417InStore())
|
|
1182
|
+
printer.writeCommand(with: command)
|
|
1183
|
+
completion(nil)
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
public func printTable(connectInfo: String, payload: RCTESCPrintTableRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
1188
|
+
DispatchQueue.main.async {
|
|
1189
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
1190
|
+
completion(
|
|
1191
|
+
NativeErrorInfo(
|
|
1192
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
1193
|
+
message: "not found printer:\(connectInfo)",
|
|
1194
|
+
error: nil
|
|
1195
|
+
)
|
|
1196
|
+
)
|
|
1197
|
+
return
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
let titles = payload.titles
|
|
1201
|
+
let numberOfSingleBytesPerCol: [NSNumber] =
|
|
1202
|
+
payload.numberOfSingleBytesPerCol.map { NSNumber(value: $0) }
|
|
1203
|
+
let align = payload.align
|
|
1204
|
+
|
|
1205
|
+
var tableAlign = TableAlignType.FIRST_LEFT_ALIGN
|
|
1206
|
+
if align.count > 0 {
|
|
1207
|
+
tableAlign = align[0] == 1 ? TableAlignType.ALL_RIGHT_ALIGN : TableAlignType.FIRST_LEFT_ALIGN
|
|
1208
|
+
}
|
|
1209
|
+
var command = Data()
|
|
1210
|
+
command.append(PTable.addAutoTableH(titles, titleLength: numberOfSingleBytesPerCol, align: tableAlign))
|
|
1211
|
+
let rows = payload.rows
|
|
1212
|
+
rows?.forEach { row in
|
|
1213
|
+
if let tableRowTitle = row.title?.data(using: printer.charSet) {
|
|
1214
|
+
command.append(tableRowTitle)
|
|
1215
|
+
}
|
|
1216
|
+
let tableRowData = row.data
|
|
1217
|
+
command.append(PTable.addAutoTableH(tableRowData, titleLength: numberOfSingleBytesPerCol, align: tableAlign))
|
|
1218
|
+
if let tableRowRemark = row.remark?.data(using: printer.charSet) {
|
|
1219
|
+
command.append(tableRowRemark)
|
|
1220
|
+
}
|
|
1221
|
+
if let tableRowBarcode = row.barcode, let codeType = tableRowBarcode.codeType.toESCTableBarCodeType(), let textPosition = tableRowBarcode.textPosition.toESCTableTextPosition() {
|
|
1222
|
+
command.append(PTable.addBarcodeRow(tableRowBarcode.data, type: codeType, hri: textPosition))
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
printer.writeCommand(with: command)
|
|
1226
|
+
completion(nil)
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
public func setGateway(connectInfo: String, gateway: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
1231
|
+
DispatchQueue.main.async {
|
|
1232
|
+
completion(NativeErrorInfo(code: PrinterErrors.NOT_YET_IMPLEMENTED_ERROR, message: "Not yet implemented", error: nil))
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
public func setIp(connectInfo: String, ip: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
1237
|
+
DispatchQueue.main.async {
|
|
1238
|
+
completion(NativeErrorInfo(code: PrinterErrors.NOT_YET_IMPLEMENTED_ERROR, message: "Not yet implemented", error: nil))
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
public func setMask(connectInfo: String, mask: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
1243
|
+
DispatchQueue.main.async {
|
|
1244
|
+
completion(NativeErrorInfo(code: PrinterErrors.NOT_YET_IMPLEMENTED_ERROR, message: "Not yet implemented", error: nil))
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
public func wifiConfig(connectInfo: String, payload: RCTESCWifiConfigRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
1249
|
+
DispatchQueue.main.async {
|
|
1250
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
1251
|
+
completion(
|
|
1252
|
+
NativeErrorInfo(
|
|
1253
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
1254
|
+
message: "not found printer:\(connectInfo)",
|
|
1255
|
+
error: nil
|
|
1256
|
+
)
|
|
1257
|
+
)
|
|
1258
|
+
return
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
guard let encrypt = payload.encrypt.toESCWifiEncrypt() else {
|
|
1262
|
+
completion(NativeErrorInfo(code: PrinterErrors.PARAMS_ERROR, message: "encrypt is error", error: nil))
|
|
1263
|
+
return
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
// TODO: need test
|
|
1267
|
+
POSWIFIManager.sharedInstance().setWiFiConfigWithIP(printer.deviceIP, mask: payload.mask, gateway: payload.gateway, ssid: payload.ssid, password: payload.password, encrypt: encrypt)
|
|
1268
|
+
completion(nil)
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
public func setNetAll(connectInfo: String, payload: RCTESCSetNetAllRequest, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
1273
|
+
DispatchQueue.main.async {
|
|
1274
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
1275
|
+
completion(
|
|
1276
|
+
NativeErrorInfo(
|
|
1277
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
1278
|
+
message: "not found printer:\(connectInfo)",
|
|
1279
|
+
error: nil
|
|
1280
|
+
)
|
|
1281
|
+
)
|
|
1282
|
+
return
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
// TODO: need test
|
|
1286
|
+
POSWIFIManager.sharedInstance().setIPConfigWithIP(payload.ip, mask: payload.mask, gateway: payload.gateway, dhcp: payload.dhcpIsOpen)
|
|
1287
|
+
completion(nil)
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
public func setBluetooth(connectInfo: String, name: String, pin: String, completion: @escaping (_ error: NativeErrorInfo?) -> Void) {
|
|
1292
|
+
DispatchQueue.main.async {
|
|
1293
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
1294
|
+
completion(
|
|
1295
|
+
NativeErrorInfo(
|
|
1296
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
1297
|
+
message: "not found printer:\(connectInfo)",
|
|
1298
|
+
error: nil
|
|
1299
|
+
)
|
|
1300
|
+
)
|
|
1301
|
+
return
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
printer.setBluetooth(name: name, pin: pin)
|
|
1305
|
+
completion(nil)
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
public func getSerialNumber(connectInfo: String, resolve: @escaping (_ value: [String: Any]) -> Void, reject: @escaping (_ error: NativeErrorInfo) -> Void) {
|
|
1310
|
+
DispatchQueue.main.async {
|
|
1311
|
+
guard let printer = Printers.shared.getPrinter(connectInfo: connectInfo) else {
|
|
1312
|
+
reject(
|
|
1313
|
+
NativeErrorInfo(
|
|
1314
|
+
code: PrinterErrors.PRINTER_NOT_FOUND_ERROR,
|
|
1315
|
+
message: "not found printer:\(connectInfo)",
|
|
1316
|
+
error: nil
|
|
1317
|
+
)
|
|
1318
|
+
)
|
|
1319
|
+
return
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
printer.printerSN { data in
|
|
1323
|
+
if data != nil {
|
|
1324
|
+
var result: [String: Any] = [:]
|
|
1325
|
+
result["data"] = data
|
|
1326
|
+
resolve(result)
|
|
1327
|
+
} else {
|
|
1328
|
+
reject(
|
|
1329
|
+
NativeErrorInfo(
|
|
1330
|
+
code: PrinterErrors.COMMON_ERROR,
|
|
1331
|
+
message: "get sn failed",
|
|
1332
|
+
error: nil
|
|
1333
|
+
)
|
|
1334
|
+
)
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
}
|