@sincpro/printer-expo 0.1.2 → 1.0.1
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/README.md +589 -415
- package/android/.editorconfig +20 -0
- package/android/README.md +103 -0
- package/android/build.gradle +36 -34
- package/android/libs/pdf/Bixolon_pdf.aar +0 -0
- package/android/libs/{jniLibs/x86_64/libbxl_common.so → sincpro-printer-sdk.aar} +0 -0
- package/android/src/main/java/sincpro/expo/printer/entrypoint/PrinterModule.kt +387 -0
- package/build/SincproPrinter.d.ts +191 -0
- package/build/SincproPrinter.d.ts.map +1 -0
- package/build/SincproPrinter.js +120 -0
- package/build/SincproPrinter.js.map +1 -0
- package/build/index.d.ts +11 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +13 -3
- package/build/index.js.map +1 -1
- package/build/types/bluetooth.types.d.ts +19 -0
- package/build/types/bluetooth.types.d.ts.map +1 -0
- package/build/types/bluetooth.types.js +5 -0
- package/build/types/bluetooth.types.js.map +1 -0
- package/build/types/index.d.ts +7 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +7 -0
- package/build/types/index.js.map +1 -0
- package/build/types/printer.types.d.ts +118 -0
- package/build/types/printer.types.d.ts.map +1 -0
- package/build/types/printer.types.js +5 -0
- package/build/types/printer.types.js.map +1 -0
- package/build/types/receipt.types.d.ts +96 -0
- package/build/types/receipt.types.d.ts.map +1 -0
- package/build/types/receipt.types.js +5 -0
- package/build/types/receipt.types.js.map +1 -0
- package/expo-module.config.json +2 -5
- package/package.json +6 -7
- package/android/libs/BixolonLabelPrinterLibrary_V2.0.9.jar +0 -0
- package/android/libs/jniLibs/arm64-v8a/libbxl_common.so +0 -0
- package/android/libs/jniLibs/armeabi-v7a/libbxl_common.so +0 -0
- package/android/libs/jniLibs/x86/libbxl_common.so +0 -0
- package/android/libs/libcommon_V1.4.0.jar +0 -0
- package/android/src/main/java/expo/sincpro/ExpoBixolonModule.kt +0 -271
- package/android/src/main/java/expo/sincpro/bixolon/BixolonQRPrinter.kt +0 -423
- package/android/src/main/java/expo/sincpro/managers/BluetoothManager.kt +0 -139
- package/android/src/main/java/expo/sincpro/managers/ConnectionManager.kt +0 -124
- package/android/src/main/java/expo/sincpro/managers/PermissionManager.kt +0 -122
- package/android/src/main/java/expo/sincpro/managers/PrinterManager.kt +0 -396
- package/android/src/main/jniLibs/arm64-v8a/libbxl_common.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libbxl_common.so +0 -0
- package/android/src/main/jniLibs/x86/libbxl_common.so +0 -0
- package/android/src/main/jniLibs/x86_64/libbxl_common.so +0 -0
- package/build/BixolonPrinter.d.ts +0 -4
- package/build/BixolonPrinter.d.ts.map +0 -1
- package/build/BixolonPrinter.js +0 -12
- package/build/BixolonPrinter.js.map +0 -1
- package/build/ExpoBixolon.types.d.ts +0 -45
- package/build/ExpoBixolon.types.d.ts.map +0 -1
- package/build/ExpoBixolon.types.js +0 -2
- package/build/ExpoBixolon.types.js.map +0 -1
- package/build/ExpoBixolonModule.d.ts +0 -24
- package/build/ExpoBixolonModule.d.ts.map +0 -1
- package/build/ExpoBixolonModule.js +0 -3
- package/build/ExpoBixolonModule.js.map +0 -1
- package/build/QrCodePrinter.d.ts +0 -45
- package/build/QrCodePrinter.d.ts.map +0 -1
- package/build/QrCodePrinter.js +0 -118
- package/build/QrCodePrinter.js.map +0 -1
- package/ios/ExpoBixolon.podspec +0 -29
- package/ios/ExpoBixolonModule.swift +0 -33
- package/ios/ExpoBixolonView.swift +0 -36
- package/src/BixolonPrinter.ts +0 -16
- package/src/ExpoBixolon.types.ts +0 -60
- package/src/ExpoBixolonModule.ts +0 -38
- package/src/QrCodePrinter.ts +0 -201
- package/src/index.ts +0 -3
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
package expo.sincpro.bixolon
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import android.util.Log
|
|
5
|
-
import com.bixolon.labelprinter.BixolonLabelPrinter
|
|
6
|
-
|
|
7
|
-
class BixolonQRPrinter(private val context: Context) {
|
|
8
|
-
|
|
9
|
-
companion object {
|
|
10
|
-
private const val TAG = "BixolonQRPrinter"
|
|
11
|
-
|
|
12
|
-
const val QR_CODE_MODEL1 = BixolonLabelPrinter.QR_CODE_MODEL1
|
|
13
|
-
const val QR_CODE_MODEL2 = BixolonLabelPrinter.QR_CODE_MODEL2
|
|
14
|
-
|
|
15
|
-
const val ECC_LEVEL_7 = BixolonLabelPrinter.ECC_LEVEL_7
|
|
16
|
-
const val ECC_LEVEL_15 = BixolonLabelPrinter.ECC_LEVEL_15
|
|
17
|
-
const val ECC_LEVEL_25 = BixolonLabelPrinter.ECC_LEVEL_25
|
|
18
|
-
const val ECC_LEVEL_30 = BixolonLabelPrinter.ECC_LEVEL_30
|
|
19
|
-
|
|
20
|
-
const val ROTATION_NONE = BixolonLabelPrinter.ROTATION_NONE
|
|
21
|
-
const val ROTATION_90_DEGREES = BixolonLabelPrinter.ROTATION_90_DEGREES
|
|
22
|
-
const val ROTATION_180_DEGREES = BixolonLabelPrinter.ROTATION_180_DEGREES
|
|
23
|
-
const val ROTATION_270_DEGREES = BixolonLabelPrinter.ROTATION_270_DEGREES
|
|
24
|
-
|
|
25
|
-
const val FONT_SIZE_10 = BixolonLabelPrinter.FONT_SIZE_10
|
|
26
|
-
const val FONT_SIZE_12 = BixolonLabelPrinter.FONT_SIZE_12
|
|
27
|
-
const val FONT_SIZE_15 = BixolonLabelPrinter.FONT_SIZE_15
|
|
28
|
-
const val FONT_SIZE_18 = BixolonLabelPrinter.FONT_SIZE_18
|
|
29
|
-
const val FONT_SIZE_24 = BixolonLabelPrinter.FONT_SIZE_24
|
|
30
|
-
|
|
31
|
-
const val TEXT_ALIGNMENT_NONE = 0
|
|
32
|
-
const val TEXT_ALIGNMENT_LEFT = 1
|
|
33
|
-
const val TEXT_ALIGNMENT_CENTER = 2
|
|
34
|
-
const val TEXT_ALIGNMENT_RIGHT = 3
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private var bixolonPrinter: BixolonLabelPrinter? = null
|
|
38
|
-
private var isInitialized = false
|
|
39
|
-
private var isConnected = false
|
|
40
|
-
private var currentAddress: String? = null
|
|
41
|
-
|
|
42
|
-
fun initialize(): Boolean {
|
|
43
|
-
try {
|
|
44
|
-
Log.d(TAG, "Initializing Bixolon printer")
|
|
45
|
-
|
|
46
|
-
if (bixolonPrinter == null) {
|
|
47
|
-
bixolonPrinter = BixolonLabelPrinter(context)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
isInitialized = true
|
|
51
|
-
Log.d(TAG, "Bixolon printer initialized successfully")
|
|
52
|
-
return true
|
|
53
|
-
|
|
54
|
-
} catch (e: Exception) {
|
|
55
|
-
Log.e(TAG, "Error initializing Bixolon printer: ${e.message}")
|
|
56
|
-
return false
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
fun connectBluetooth(address: String): Boolean {
|
|
61
|
-
try {
|
|
62
|
-
Log.d(TAG, "Connecting to Bixolon printer via Bluetooth: $address")
|
|
63
|
-
|
|
64
|
-
if (!isInitialized || bixolonPrinter == null) {
|
|
65
|
-
Log.e(TAG, "Printer not initialized")
|
|
66
|
-
return false
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
bixolonPrinter!!.connect(address, 0)
|
|
70
|
-
isConnected = bixolonPrinter!!.isConnected()
|
|
71
|
-
currentAddress = address
|
|
72
|
-
|
|
73
|
-
if (isConnected) {
|
|
74
|
-
Log.d(TAG, "Successfully connected to Bixolon printer via Bluetooth")
|
|
75
|
-
} else {
|
|
76
|
-
Log.e(TAG, "Failed to establish connection to Bixolon printer")
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return isConnected
|
|
80
|
-
|
|
81
|
-
} catch (e: Exception) {
|
|
82
|
-
Log.e(TAG, "Error connecting to Bixolon printer: ${e.message}")
|
|
83
|
-
isConnected = false
|
|
84
|
-
return false
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
fun connectWiFi(address: String, port: Int): Boolean {
|
|
89
|
-
try {
|
|
90
|
-
Log.d(TAG, "Connecting to Bixolon printer via WiFi: $address:$port")
|
|
91
|
-
|
|
92
|
-
if (!isInitialized) {
|
|
93
|
-
Log.e(TAG, "Printer not initialized")
|
|
94
|
-
return false
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
isConnected = true
|
|
98
|
-
currentAddress = address
|
|
99
|
-
Log.d(TAG, "Successfully connected to Bixolon printer via WiFi")
|
|
100
|
-
return true
|
|
101
|
-
|
|
102
|
-
} catch (e: Exception) {
|
|
103
|
-
Log.e(TAG, "Error connecting to Bixolon printer: ${e.message}")
|
|
104
|
-
return false
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
fun connectUSB(): Boolean {
|
|
109
|
-
try {
|
|
110
|
-
Log.d(TAG, "Connecting to Bixolon printer via USB")
|
|
111
|
-
|
|
112
|
-
if (!isInitialized) {
|
|
113
|
-
Log.e(TAG, "Printer not initialized")
|
|
114
|
-
return false
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
isConnected = true
|
|
118
|
-
Log.d(TAG, "Successfully connected to Bixolon printer via USB")
|
|
119
|
-
return true
|
|
120
|
-
|
|
121
|
-
} catch (e: Exception) {
|
|
122
|
-
Log.e(TAG, "Error connecting to Bixolon printer: ${e.message}")
|
|
123
|
-
return false
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
fun disconnect(): Boolean {
|
|
128
|
-
try {
|
|
129
|
-
Log.d(TAG, "Disconnecting from Bixolon printer")
|
|
130
|
-
|
|
131
|
-
if (bixolonPrinter != null) {
|
|
132
|
-
bixolonPrinter!!.disconnect()
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
isConnected = false
|
|
136
|
-
currentAddress = null
|
|
137
|
-
Log.d(TAG, "Successfully disconnected from Bixolon printer")
|
|
138
|
-
return true
|
|
139
|
-
|
|
140
|
-
} catch (e: Exception) {
|
|
141
|
-
Log.e(TAG, "Error disconnecting from Bixolon printer: ${e.message}")
|
|
142
|
-
return false
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
fun setBufferMode(doubleBuffering: Boolean) {
|
|
147
|
-
try {
|
|
148
|
-
Log.d(TAG, "Setting buffer mode: $doubleBuffering")
|
|
149
|
-
bixolonPrinter!!.setBufferMode(doubleBuffering)
|
|
150
|
-
Log.d(TAG, "Buffer mode set successfully")
|
|
151
|
-
} catch (e: Exception) {
|
|
152
|
-
Log.e(TAG, "Error setting buffer mode: ${e.message}")
|
|
153
|
-
throw e
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
fun clearBuffer() {
|
|
158
|
-
try {
|
|
159
|
-
Log.d(TAG, "Clearing buffer")
|
|
160
|
-
bixolonPrinter!!.clearBuffer()
|
|
161
|
-
Log.d(TAG, "Buffer cleared successfully")
|
|
162
|
-
} catch (e: Exception) {
|
|
163
|
-
Log.e(TAG, "Error clearing buffer: ${e.message}")
|
|
164
|
-
throw e
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
fun initializePrinter() {
|
|
169
|
-
try {
|
|
170
|
-
Log.d(TAG, "Initializing printer to reset all settings")
|
|
171
|
-
bixolonPrinter!!.initializePrinter()
|
|
172
|
-
Log.d(TAG, "Printer initialized successfully")
|
|
173
|
-
} catch (e: Exception) {
|
|
174
|
-
Log.e(TAG, "Error initializing printer: ${e.message}")
|
|
175
|
-
throw e
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
fun initializeForNewPrint() {
|
|
180
|
-
try {
|
|
181
|
-
Log.d(TAG, "Initialize printer for new print job")
|
|
182
|
-
|
|
183
|
-
bixolonPrinter!!.initializePrinter()
|
|
184
|
-
Log.d(TAG, "Printer initialized")
|
|
185
|
-
Thread.sleep(200)
|
|
186
|
-
|
|
187
|
-
bixolonPrinter!!.clearBuffer()
|
|
188
|
-
Log.d(TAG, "Buffer cleared")
|
|
189
|
-
Thread.sleep(100)
|
|
190
|
-
|
|
191
|
-
Log.d(TAG, "Printer ready for new print job")
|
|
192
|
-
|
|
193
|
-
} catch (e: Exception) {
|
|
194
|
-
Log.e(TAG, "Error initializing printer: ${e.message}")
|
|
195
|
-
throw e
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
fun clearAllMemory() {
|
|
200
|
-
try {
|
|
201
|
-
Log.d(TAG, "Clearing all memory and buffer completely")
|
|
202
|
-
|
|
203
|
-
try {
|
|
204
|
-
bixolonPrinter!!.endTransactionPrint()
|
|
205
|
-
Log.d(TAG, "Ended existing transaction")
|
|
206
|
-
Thread.sleep(100)
|
|
207
|
-
} catch (e: Exception) {
|
|
208
|
-
Log.d(TAG, "No existing transaction to end: ${e.message}")
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
bixolonPrinter!!.initializePrinter()
|
|
212
|
-
Log.d(TAG, "Printer initialized")
|
|
213
|
-
Thread.sleep(200)
|
|
214
|
-
|
|
215
|
-
bixolonPrinter!!.clearBuffer()
|
|
216
|
-
Log.d(TAG, "Buffer cleared")
|
|
217
|
-
Thread.sleep(100)
|
|
218
|
-
|
|
219
|
-
Log.d(TAG, "All memory cleared successfully following SDK best practices")
|
|
220
|
-
|
|
221
|
-
} catch (e: Exception) {
|
|
222
|
-
Log.e(TAG, "Error clearing all memory: ${e.message}")
|
|
223
|
-
throw e
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
fun drawText(
|
|
228
|
-
data: String,
|
|
229
|
-
horizontalPosition: Int,
|
|
230
|
-
verticalPosition: Int,
|
|
231
|
-
fontSize: Int,
|
|
232
|
-
horizontalMultiplier: Int,
|
|
233
|
-
verticalMultiplier: Int,
|
|
234
|
-
rightSpace: Int,
|
|
235
|
-
rotation: Int,
|
|
236
|
-
bold: Boolean,
|
|
237
|
-
reverse: Boolean,
|
|
238
|
-
alignment: Int
|
|
239
|
-
) {
|
|
240
|
-
try {
|
|
241
|
-
Log.d(TAG, "Draw text: $data at position ($horizontalPosition, $verticalPosition)")
|
|
242
|
-
|
|
243
|
-
val maxWidth = 832
|
|
244
|
-
val maxHeight = 1200
|
|
245
|
-
|
|
246
|
-
val safeX = horizontalPosition.coerceIn(0, maxWidth - 50)
|
|
247
|
-
val safeY = verticalPosition.coerceIn(0, maxHeight - 50)
|
|
248
|
-
|
|
249
|
-
if (safeX != horizontalPosition || safeY != verticalPosition) {
|
|
250
|
-
Log.w(TAG, "Coordinates adjusted from ($horizontalPosition, $verticalPosition) to ($safeX, $safeY)")
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
bixolonPrinter!!.drawText(
|
|
254
|
-
data,
|
|
255
|
-
safeX,
|
|
256
|
-
safeY,
|
|
257
|
-
fontSize,
|
|
258
|
-
horizontalMultiplier,
|
|
259
|
-
verticalMultiplier,
|
|
260
|
-
rightSpace,
|
|
261
|
-
rotation,
|
|
262
|
-
bold,
|
|
263
|
-
reverse,
|
|
264
|
-
alignment
|
|
265
|
-
)
|
|
266
|
-
Log.d(TAG, "Text drawn successfully at safe coordinates ($safeX, $safeY)")
|
|
267
|
-
} catch (e: Exception) {
|
|
268
|
-
Log.e(TAG, "Error drawing text: ${e.message}")
|
|
269
|
-
throw e
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
fun beginTransactionPrint() {
|
|
274
|
-
try {
|
|
275
|
-
Log.d(TAG, "Start transaction")
|
|
276
|
-
bixolonPrinter!!.beginTransactionPrint()
|
|
277
|
-
Log.d(TAG, "Transaction print started successfully")
|
|
278
|
-
} catch (e: Exception) {
|
|
279
|
-
Log.e(TAG, "Error beginning transaction print: ${e.message}")
|
|
280
|
-
throw e
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
fun drawQrCode(
|
|
285
|
-
data: String,
|
|
286
|
-
horizontalPosition: Int,
|
|
287
|
-
verticalPosition: Int,
|
|
288
|
-
model: Int,
|
|
289
|
-
eccLevel: Int,
|
|
290
|
-
size: Int,
|
|
291
|
-
rotation: Int
|
|
292
|
-
) {
|
|
293
|
-
try {
|
|
294
|
-
Log.d(TAG, "Draw QR: $data at position ($horizontalPosition, $verticalPosition)")
|
|
295
|
-
bixolonPrinter!!.drawQrCode(
|
|
296
|
-
data,
|
|
297
|
-
horizontalPosition,
|
|
298
|
-
verticalPosition,
|
|
299
|
-
model,
|
|
300
|
-
eccLevel,
|
|
301
|
-
size,
|
|
302
|
-
rotation
|
|
303
|
-
)
|
|
304
|
-
Log.d(TAG, "QR code drawn successfully")
|
|
305
|
-
} catch (e: Exception) {
|
|
306
|
-
Log.e(TAG, "Error drawing QR code: ${e.message}")
|
|
307
|
-
throw e
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
fun print(copies: Int, speed: Int) {
|
|
312
|
-
try {
|
|
313
|
-
Log.d(TAG, "Print command")
|
|
314
|
-
bixolonPrinter!!.print(copies, speed)
|
|
315
|
-
Log.d(TAG, "Print command sent successfully")
|
|
316
|
-
Thread.sleep(400)
|
|
317
|
-
} catch (e: Exception) {
|
|
318
|
-
Log.e(TAG, "Error printing label: ${e.message}")
|
|
319
|
-
throw e
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
fun endTransactionPrint() {
|
|
324
|
-
try {
|
|
325
|
-
Log.d(TAG, "End transaction")
|
|
326
|
-
bixolonPrinter!!.endTransactionPrint()
|
|
327
|
-
Log.d(TAG, "Transaction print ended successfully")
|
|
328
|
-
Thread.sleep(200)
|
|
329
|
-
} catch (e: Exception) {
|
|
330
|
-
Log.e(TAG, "Error ending transaction print: ${e.message}")
|
|
331
|
-
throw e
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
fun printQRCode(data: String, size: Int): Boolean {
|
|
336
|
-
try {
|
|
337
|
-
Log.d(TAG, "Printing QR code: $data with size: $size")
|
|
338
|
-
|
|
339
|
-
val actualConnectionStatus = bixolonPrinter?.isConnected() ?: false
|
|
340
|
-
Log.d(TAG, "Connection status - isConnected: $isConnected, actual: $actualConnectionStatus")
|
|
341
|
-
|
|
342
|
-
if (!isConnected || bixolonPrinter == null) {
|
|
343
|
-
Log.e(TAG, "Printer not connected - isConnected: $isConnected, bixolonPrinter: ${bixolonPrinter != null}")
|
|
344
|
-
return false
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
if (!bixolonPrinter!!.isConnected()) {
|
|
348
|
-
Log.e(TAG, "Printer connection lost during operation")
|
|
349
|
-
return false
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
val horizontalPosition = 200
|
|
353
|
-
val verticalPosition = 100
|
|
354
|
-
val model = QR_CODE_MODEL2
|
|
355
|
-
val eccLevel = ECC_LEVEL_7
|
|
356
|
-
val rotation = ROTATION_NONE
|
|
357
|
-
|
|
358
|
-
Log.d(TAG, "Starting QR code print transaction")
|
|
359
|
-
|
|
360
|
-
beginTransactionPrint()
|
|
361
|
-
|
|
362
|
-
drawQrCode(
|
|
363
|
-
data,
|
|
364
|
-
horizontalPosition,
|
|
365
|
-
verticalPosition,
|
|
366
|
-
model,
|
|
367
|
-
eccLevel,
|
|
368
|
-
size,
|
|
369
|
-
rotation
|
|
370
|
-
)
|
|
371
|
-
|
|
372
|
-
print(1, 1)
|
|
373
|
-
|
|
374
|
-
endTransactionPrint()
|
|
375
|
-
|
|
376
|
-
Log.d(TAG, "QR code printed successfully with Bixolon library")
|
|
377
|
-
Log.d(TAG, " Content: $data")
|
|
378
|
-
Log.d(TAG, " Size: $size")
|
|
379
|
-
Log.d(TAG, " Position: ($horizontalPosition, $verticalPosition)")
|
|
380
|
-
Log.d(TAG, " Model: $model")
|
|
381
|
-
Log.d(TAG, " ECC Level: $eccLevel")
|
|
382
|
-
Log.d(TAG, " Rotation: $rotation")
|
|
383
|
-
|
|
384
|
-
return true
|
|
385
|
-
|
|
386
|
-
} catch (e: Exception) {
|
|
387
|
-
Log.e(TAG, "Error printing QR code: ${e.message}")
|
|
388
|
-
Log.e(TAG, "Stack trace: ${e.stackTrace.joinToString("\n")}")
|
|
389
|
-
return false
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
fun isConnected(): Boolean {
|
|
394
|
-
return try {
|
|
395
|
-
isConnected && bixolonPrinter != null && bixolonPrinter!!.isConnected()
|
|
396
|
-
} catch (e: Exception) {
|
|
397
|
-
Log.e(TAG, "Error checking connection: ${e.message}")
|
|
398
|
-
isConnected
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
fun getPrinterStatus(): Int {
|
|
403
|
-
return try {
|
|
404
|
-
if (isConnected) 1 else 0
|
|
405
|
-
} catch (e: Exception) {
|
|
406
|
-
Log.e(TAG, "Error getting printer status: ${e.message}")
|
|
407
|
-
-1
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
fun getPrinterInformation(): String {
|
|
412
|
-
return try {
|
|
413
|
-
if (isInitialized) {
|
|
414
|
-
"Model: Bixolon Label Printer, Connected: $isConnected, Address: $currentAddress"
|
|
415
|
-
} else {
|
|
416
|
-
"Printer not initialized"
|
|
417
|
-
}
|
|
418
|
-
} catch (e: Exception) {
|
|
419
|
-
Log.e(TAG, "Error getting printer information: ${e.message}")
|
|
420
|
-
"Error getting printer information"
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
package expo.sincpro.managers
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import android.util.Log
|
|
5
|
-
import android.bluetooth.BluetoothAdapter
|
|
6
|
-
import android.bluetooth.BluetoothDevice
|
|
7
|
-
import android.bluetooth.BluetoothManager
|
|
8
|
-
import expo.sincpro.bixolon.BixolonQRPrinter
|
|
9
|
-
|
|
10
|
-
class BluetoothManager(private val context: Context) {
|
|
11
|
-
private val TAG = "BluetoothManager"
|
|
12
|
-
private val bluetoothManager = context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
|
13
|
-
private val bluetoothAdapter = bluetoothManager.adapter
|
|
14
|
-
|
|
15
|
-
fun isBluetoothEnabled(): Boolean {
|
|
16
|
-
return try {
|
|
17
|
-
val isEnabled = bluetoothAdapter != null && bluetoothAdapter.isEnabled
|
|
18
|
-
Log.d(TAG, "Bluetooth enabled: $isEnabled")
|
|
19
|
-
isEnabled
|
|
20
|
-
} catch (e: Exception) {
|
|
21
|
-
Log.e(TAG, "Error checking Bluetooth status: ${e.message}")
|
|
22
|
-
false
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
fun discoverBluetoothDevices(): List<Map<String, Any>> {
|
|
27
|
-
try {
|
|
28
|
-
Log.d(TAG, "Starting Bluetooth device discovery")
|
|
29
|
-
|
|
30
|
-
if (bluetoothAdapter == null) {
|
|
31
|
-
throw Exception("Bluetooth not supported on this device")
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (!bluetoothAdapter.isEnabled) {
|
|
35
|
-
throw Exception("Bluetooth is not enabled")
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
val pairedDevices = bluetoothAdapter.bondedDevices
|
|
39
|
-
val deviceList = mutableListOf<Map<String, Any>>()
|
|
40
|
-
|
|
41
|
-
for (device in pairedDevices) {
|
|
42
|
-
val deviceInfo = mapOf(
|
|
43
|
-
"name" to (device.name ?: "Unknown Device"),
|
|
44
|
-
"address" to device.address,
|
|
45
|
-
"type" to when (device.type) {
|
|
46
|
-
BluetoothDevice.DEVICE_TYPE_CLASSIC -> "CLASSIC"
|
|
47
|
-
BluetoothDevice.DEVICE_TYPE_LE -> "LE"
|
|
48
|
-
BluetoothDevice.DEVICE_TYPE_DUAL -> "DUAL"
|
|
49
|
-
else -> "UNKNOWN"
|
|
50
|
-
},
|
|
51
|
-
"isPrinter" to isPrinterDevice(device.name)
|
|
52
|
-
)
|
|
53
|
-
deviceList.add(deviceInfo)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
Log.d(TAG, "Found ${deviceList.size} Bluetooth devices")
|
|
57
|
-
return deviceList
|
|
58
|
-
|
|
59
|
-
} catch (e: Exception) {
|
|
60
|
-
Log.e(TAG, "Error discovering Bluetooth devices: ${e.message}")
|
|
61
|
-
throw e
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
fun startBluetoothDiscovery(): Boolean {
|
|
66
|
-
try {
|
|
67
|
-
Log.d(TAG, "Starting Bluetooth discovery")
|
|
68
|
-
|
|
69
|
-
if (bluetoothAdapter == null) {
|
|
70
|
-
throw Exception("Bluetooth not supported on this device")
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!bluetoothAdapter.isEnabled) {
|
|
74
|
-
throw Exception("Bluetooth is not enabled")
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return if (bluetoothAdapter.startDiscovery()) {
|
|
78
|
-
Log.d(TAG, "Bluetooth discovery started")
|
|
79
|
-
true
|
|
80
|
-
} else {
|
|
81
|
-
throw Exception("Failed to start Bluetooth discovery")
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
} catch (e: Exception) {
|
|
85
|
-
Log.e(TAG, "Error starting Bluetooth discovery: ${e.message}")
|
|
86
|
-
throw e
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
fun stopBluetoothDiscovery(): Boolean {
|
|
91
|
-
try {
|
|
92
|
-
Log.d(TAG, "Stopping Bluetooth discovery")
|
|
93
|
-
|
|
94
|
-
if (bluetoothAdapter != null && bluetoothAdapter.isDiscovering) {
|
|
95
|
-
bluetoothAdapter.cancelDiscovery()
|
|
96
|
-
Log.d(TAG, "Bluetooth discovery stopped")
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return true
|
|
100
|
-
|
|
101
|
-
} catch (e: Exception) {
|
|
102
|
-
Log.e(TAG, "Error stopping Bluetooth discovery: ${e.message}")
|
|
103
|
-
throw e
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
fun connectBluetooth(bixolonQRPrinter: BixolonQRPrinter, address: String): Boolean {
|
|
108
|
-
return try {
|
|
109
|
-
Log.d(TAG, "Attempting Bluetooth connection to $address using Bixolon SDK")
|
|
110
|
-
|
|
111
|
-
val success = bixolonQRPrinter.connectBluetooth(address)
|
|
112
|
-
|
|
113
|
-
if (success) {
|
|
114
|
-
Log.d(TAG, "Bluetooth connection established successfully using Bixolon SDK")
|
|
115
|
-
true
|
|
116
|
-
} else {
|
|
117
|
-
Log.e(TAG, "Failed to connect using Bixolon SDK")
|
|
118
|
-
false
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
} catch (e: Exception) {
|
|
122
|
-
Log.e(TAG, "Error connecting via Bluetooth: ${e.message}")
|
|
123
|
-
false
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
private fun isPrinterDevice(deviceName: String?): Boolean {
|
|
128
|
-
if (deviceName == null) return false
|
|
129
|
-
|
|
130
|
-
val printerKeywords = listOf(
|
|
131
|
-
"printer", "print", "bixolon", "label", "thermal", "receipt",
|
|
132
|
-
"impresora", "etiqueta", "termica", "ticket", "pos", "terminal"
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
return printerKeywords.any { keyword ->
|
|
136
|
-
deviceName.lowercase().contains(keyword.lowercase())
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
package expo.sincpro.managers
|
|
2
|
-
|
|
3
|
-
import android.util.Log
|
|
4
|
-
import expo.sincpro.bixolon.BixolonQRPrinter
|
|
5
|
-
|
|
6
|
-
class ConnectionManager(private val bixolonQRPrinter: BixolonQRPrinter) {
|
|
7
|
-
private val TAG = "ConnectionManager"
|
|
8
|
-
private var isInitialized = false
|
|
9
|
-
private var isConnected = false
|
|
10
|
-
private var currentAddress: String? = null
|
|
11
|
-
private var currentPort: Int = 0
|
|
12
|
-
|
|
13
|
-
fun initialize(): Boolean {
|
|
14
|
-
return try {
|
|
15
|
-
Log.d(TAG, "Initializing printer with Bixolon libraries")
|
|
16
|
-
|
|
17
|
-
val bixolonInitialized = bixolonQRPrinter.initialize()
|
|
18
|
-
|
|
19
|
-
if (bixolonInitialized) {
|
|
20
|
-
isInitialized = true
|
|
21
|
-
Log.d(TAG, "Printer initialized successfully with Bixolon libraries")
|
|
22
|
-
true
|
|
23
|
-
} else {
|
|
24
|
-
Log.e(TAG, "Failed to initialize Bixolon printer")
|
|
25
|
-
false
|
|
26
|
-
}
|
|
27
|
-
} catch (e: Exception) {
|
|
28
|
-
Log.e(TAG, "Error initializing printer: ${e.message}")
|
|
29
|
-
throw e
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
fun connect(interfaceType: String, address: String, port: Int, bluetoothManager: BluetoothManager): Boolean {
|
|
34
|
-
return try {
|
|
35
|
-
Log.d(TAG, "Attempting to connect to printer via $interfaceType at $address:$port")
|
|
36
|
-
|
|
37
|
-
if (!isInitialized) {
|
|
38
|
-
throw Exception("Printer not initialized. Call initialize() first.")
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
currentAddress = address
|
|
42
|
-
currentPort = port
|
|
43
|
-
|
|
44
|
-
var connectionSuccess = false
|
|
45
|
-
when (interfaceType.lowercase()) {
|
|
46
|
-
"bluetooth" -> {
|
|
47
|
-
Log.d(TAG, "Connecting via Bluetooth to $address")
|
|
48
|
-
connectionSuccess = bluetoothManager.connectBluetooth(bixolonQRPrinter, address)
|
|
49
|
-
}
|
|
50
|
-
"wifi" -> {
|
|
51
|
-
Log.d(TAG, "Connecting via WiFi to $address:$port")
|
|
52
|
-
connectionSuccess = bixolonQRPrinter.connectWiFi(address, port)
|
|
53
|
-
}
|
|
54
|
-
"usb" -> {
|
|
55
|
-
Log.d(TAG, "Connecting via USB")
|
|
56
|
-
connectionSuccess = bixolonQRPrinter.connectUSB()
|
|
57
|
-
}
|
|
58
|
-
else -> {
|
|
59
|
-
throw Exception("Unsupported interface type: $interfaceType")
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (!connectionSuccess) {
|
|
64
|
-
throw Exception("Failed to connect via $interfaceType")
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
isConnected = true
|
|
68
|
-
Log.d(TAG, "Connected successfully to printer via $interfaceType")
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
bixolonQRPrinter.clearAllMemory()
|
|
72
|
-
Log.d(TAG, "Memory cleared after connection")
|
|
73
|
-
} catch (e: Exception) {
|
|
74
|
-
Log.w(TAG, "Warning: Could not clear memory after connection: ${e.message}")
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
true
|
|
78
|
-
} catch (e: Exception) {
|
|
79
|
-
Log.e(TAG, "Error connecting to printer: ${e.message}")
|
|
80
|
-
throw e
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
fun disconnect(): Boolean {
|
|
85
|
-
return try {
|
|
86
|
-
Log.d(TAG, "Disconnecting from printer")
|
|
87
|
-
|
|
88
|
-
bixolonQRPrinter.disconnect()
|
|
89
|
-
|
|
90
|
-
isConnected = false
|
|
91
|
-
currentAddress = null
|
|
92
|
-
currentPort = 0
|
|
93
|
-
|
|
94
|
-
true
|
|
95
|
-
} catch (e: Exception) {
|
|
96
|
-
Log.e(TAG, "Error disconnecting from printer: ${e.message}")
|
|
97
|
-
throw e
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
fun executeCommand(command: String): Boolean {
|
|
102
|
-
return try {
|
|
103
|
-
Log.d(TAG, "Executing direct command: $command")
|
|
104
|
-
|
|
105
|
-
if (!isConnected) {
|
|
106
|
-
throw Exception("Printer not connected")
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
val commandBytes = command.toByteArray()
|
|
110
|
-
|
|
111
|
-
Log.d(TAG, "Command '$command' sent successfully to printer")
|
|
112
|
-
true
|
|
113
|
-
|
|
114
|
-
} catch (e: Exception) {
|
|
115
|
-
Log.e(TAG, "Error executing command: ${e.message}")
|
|
116
|
-
throw e
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
fun isInitialized(): Boolean = isInitialized
|
|
121
|
-
fun isConnected(): Boolean = isConnected
|
|
122
|
-
fun getCurrentAddress(): String? = currentAddress
|
|
123
|
-
fun getCurrentPort(): Int = currentPort
|
|
124
|
-
}
|