@sincpro/printer-expo 0.1.2 → 1.0.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/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 -5
- package/src/SincproPrinter.ts +208 -0
- package/src/index.ts +15 -3
- package/src/types/bluetooth.types.ts +20 -0
- package/src/types/index.ts +7 -0
- package/src/types/printer.types.ts +141 -0
- package/src/types/receipt.types.ts +115 -0
- 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/src/BixolonPrinter.ts +0 -16
- package/src/ExpoBixolon.types.ts +0 -60
- package/src/ExpoBixolonModule.ts +0 -38
- package/src/QrCodePrinter.ts +0 -201
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
package expo.sincpro
|
|
2
|
-
|
|
3
|
-
import android.util.Log
|
|
4
|
-
import expo.modules.kotlin.modules.Module
|
|
5
|
-
import expo.modules.kotlin.modules.ModuleDefinition
|
|
6
|
-
import expo.sincpro.bixolon.BixolonQRPrinter
|
|
7
|
-
import expo.sincpro.managers.BluetoothManager
|
|
8
|
-
import expo.sincpro.managers.ConnectionManager
|
|
9
|
-
import expo.sincpro.managers.PermissionManager
|
|
10
|
-
import expo.sincpro.managers.PrinterManager
|
|
11
|
-
|
|
12
|
-
class ExpoBixolonModule : Module() {
|
|
13
|
-
private val TAG = "ExpoBixolonModule"
|
|
14
|
-
|
|
15
|
-
private var bixolonQRPrinter: BixolonQRPrinter? = null
|
|
16
|
-
private var bluetoothManager: BluetoothManager? = null
|
|
17
|
-
private var connectionManager: ConnectionManager? = null
|
|
18
|
-
private var printerManager: PrinterManager? = null
|
|
19
|
-
private var permissionManager: PermissionManager? = null
|
|
20
|
-
|
|
21
|
-
override fun definition() = ModuleDefinition {
|
|
22
|
-
Name("ExpoBixolon")
|
|
23
|
-
|
|
24
|
-
AsyncFunction("initializePrinter") {
|
|
25
|
-
try {
|
|
26
|
-
Log.d(TAG, "Initializing printer with Bixolon libraries")
|
|
27
|
-
|
|
28
|
-
if (bixolonQRPrinter == null) {
|
|
29
|
-
bixolonQRPrinter = BixolonQRPrinter(appContext.reactContext!!)
|
|
30
|
-
connectionManager = ConnectionManager(bixolonQRPrinter!!)
|
|
31
|
-
printerManager = PrinterManager(bixolonQRPrinter!!)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return@AsyncFunction connectionManager!!.initialize()
|
|
35
|
-
} catch (e: Exception) {
|
|
36
|
-
Log.e(TAG, "Error initializing printer: ${e.message}")
|
|
37
|
-
throw e
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
AsyncFunction("connectPrinter") { interfaceType: String, address: String, port: Int ->
|
|
42
|
-
try {
|
|
43
|
-
if (connectionManager == null || !connectionManager!!.isInitialized()) {
|
|
44
|
-
throw Exception("Printer not initialized. Call initializePrinter() first.")
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (bluetoothManager == null) {
|
|
48
|
-
bluetoothManager = BluetoothManager(appContext.reactContext!!)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return@AsyncFunction connectionManager!!.connect(interfaceType, address, port, bluetoothManager!!)
|
|
52
|
-
} catch (e: Exception) {
|
|
53
|
-
Log.e(TAG, "Error connecting to printer: ${e.message}")
|
|
54
|
-
throw e
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
AsyncFunction("disconnectPrinter") {
|
|
59
|
-
try {
|
|
60
|
-
if (connectionManager == null) {
|
|
61
|
-
return@AsyncFunction true
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return@AsyncFunction connectionManager!!.disconnect()
|
|
65
|
-
} catch (e: Exception) {
|
|
66
|
-
Log.e(TAG, "Error disconnecting from printer: ${e.message}")
|
|
67
|
-
throw e
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
AsyncFunction("executeCommand") { command: String ->
|
|
72
|
-
try {
|
|
73
|
-
if (connectionManager == null || !connectionManager!!.isConnected()) {
|
|
74
|
-
throw Exception("Printer not connected")
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return@AsyncFunction connectionManager!!.executeCommand(command)
|
|
78
|
-
} catch (e: Exception) {
|
|
79
|
-
Log.e(TAG, "Error executing command: ${e.message}")
|
|
80
|
-
throw e
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
AsyncFunction("testPlainText") { text: String ->
|
|
85
|
-
try {
|
|
86
|
-
if (connectionManager == null || !connectionManager!!.isConnected()) {
|
|
87
|
-
throw Exception("Printer not connected")
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return@AsyncFunction printerManager!!.printPlainText(text)
|
|
91
|
-
} catch (e: Exception) {
|
|
92
|
-
Log.e(TAG, "Error sending plain text: ${e.message}")
|
|
93
|
-
throw e
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
AsyncFunction("printInvoice") { invoiceText: String ->
|
|
98
|
-
try {
|
|
99
|
-
if (connectionManager == null || !connectionManager!!.isConnected()) {
|
|
100
|
-
throw Exception("Printer not connected")
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return@AsyncFunction printerManager!!.printInvoice(invoiceText)
|
|
104
|
-
} catch (e: Exception) {
|
|
105
|
-
Log.e(TAG, "Error printing invoice: ${e.message}")
|
|
106
|
-
throw e
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
AsyncFunction("printQRCode") { text: String, size: Int ->
|
|
111
|
-
try {
|
|
112
|
-
if (connectionManager == null || !connectionManager!!.isConnected()) {
|
|
113
|
-
throw Exception("Printer not connected")
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return@AsyncFunction printerManager!!.printQRCode(text, size)
|
|
117
|
-
} catch (e: Exception) {
|
|
118
|
-
Log.e(TAG, "Error printing QR code: ${e.message}")
|
|
119
|
-
throw e
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
AsyncFunction("printQRCodeAdvanced") {
|
|
124
|
-
data: String,
|
|
125
|
-
horizontalPosition: Int,
|
|
126
|
-
verticalPosition: Int,
|
|
127
|
-
model: String,
|
|
128
|
-
eccLevel: String,
|
|
129
|
-
size: Int,
|
|
130
|
-
rotation: String
|
|
131
|
-
->
|
|
132
|
-
try {
|
|
133
|
-
if (connectionManager == null || !connectionManager!!.isConnected()) {
|
|
134
|
-
throw Exception("Printer not connected")
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return@AsyncFunction printerManager!!.printQRCodeAdvanced(data, size)
|
|
138
|
-
} catch (e: Exception) {
|
|
139
|
-
Log.e(TAG, "Error printing QR code: ${e.message}")
|
|
140
|
-
throw e
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
AsyncFunction("printFormattedText") { text: String, fontSize: Int? ->
|
|
145
|
-
try {
|
|
146
|
-
if (connectionManager == null || !connectionManager!!.isConnected()) {
|
|
147
|
-
throw Exception("Printer not connected")
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
val actualFontSize = fontSize ?: 10
|
|
151
|
-
return@AsyncFunction printerManager!!.printFormattedText(text, actualFontSize)
|
|
152
|
-
} catch (e: Exception) {
|
|
153
|
-
Log.e(TAG, "Error printing formatted text: ${e.message}")
|
|
154
|
-
throw e
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
AsyncFunction("printTextSimple") { text: String ->
|
|
159
|
-
try {
|
|
160
|
-
if (connectionManager == null || !connectionManager!!.isConnected()) {
|
|
161
|
-
throw Exception("Printer not connected")
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return@AsyncFunction printerManager!!.printTextSimple(text)
|
|
165
|
-
} catch (e: Exception) {
|
|
166
|
-
Log.e(TAG, "Error printing simple text: ${e.message}")
|
|
167
|
-
throw e
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
AsyncFunction("printTextInPages") { text: String ->
|
|
172
|
-
try {
|
|
173
|
-
if (connectionManager == null || !connectionManager!!.isConnected()) {
|
|
174
|
-
throw Exception("Printer not connected")
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return@AsyncFunction printerManager!!.printTextInPages(text)
|
|
178
|
-
} catch (e: Exception) {
|
|
179
|
-
Log.e(TAG, "Error printing text in pages: ${e.message}")
|
|
180
|
-
throw e
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
AsyncFunction("requestBluetoothPermissions") {
|
|
186
|
-
try {
|
|
187
|
-
if (permissionManager == null) {
|
|
188
|
-
permissionManager = PermissionManager(appContext.reactContext!!)
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return@AsyncFunction permissionManager!!.requestBluetoothPermissions(appContext.currentActivity)
|
|
192
|
-
} catch (e: Exception) {
|
|
193
|
-
Log.e(TAG, "Error requesting Bluetooth permissions: ${e.message}")
|
|
194
|
-
return@AsyncFunction false
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
AsyncFunction("checkBluetoothPermissions") {
|
|
199
|
-
try {
|
|
200
|
-
if (permissionManager == null) {
|
|
201
|
-
permissionManager = PermissionManager(appContext.reactContext!!)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return@AsyncFunction permissionManager!!.checkBluetoothPermissions()
|
|
205
|
-
} catch (e: Exception) {
|
|
206
|
-
Log.e(TAG, "Error checking Bluetooth permissions: ${e.message}")
|
|
207
|
-
throw e
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
AsyncFunction("discoverBluetoothDevices") {
|
|
212
|
-
try {
|
|
213
|
-
if (bluetoothManager == null) {
|
|
214
|
-
bluetoothManager = BluetoothManager(appContext.reactContext!!)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (permissionManager == null) {
|
|
218
|
-
permissionManager = PermissionManager(appContext.reactContext!!)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (!permissionManager!!.hasRequiredPermissions()) {
|
|
222
|
-
throw Exception("Required permissions not granted. Call requestBluetoothPermissions() first.")
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return@AsyncFunction bluetoothManager!!.discoverBluetoothDevices()
|
|
226
|
-
} catch (e: Exception) {
|
|
227
|
-
Log.e(TAG, "Error discovering Bluetooth devices: ${e.message}")
|
|
228
|
-
throw e
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
AsyncFunction("startBluetoothDiscovery") {
|
|
233
|
-
try {
|
|
234
|
-
if (bluetoothManager == null) {
|
|
235
|
-
bluetoothManager = BluetoothManager(appContext.reactContext!!)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return@AsyncFunction bluetoothManager!!.startBluetoothDiscovery()
|
|
239
|
-
} catch (e: Exception) {
|
|
240
|
-
Log.e(TAG, "Error starting Bluetooth discovery: ${e.message}")
|
|
241
|
-
throw e
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
AsyncFunction("stopBluetoothDiscovery") {
|
|
246
|
-
try {
|
|
247
|
-
if (bluetoothManager == null) {
|
|
248
|
-
bluetoothManager = BluetoothManager(appContext.reactContext!!)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return@AsyncFunction bluetoothManager!!.stopBluetoothDiscovery()
|
|
252
|
-
} catch (e: Exception) {
|
|
253
|
-
Log.e(TAG, "Error stopping Bluetooth discovery: ${e.message}")
|
|
254
|
-
throw e
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
AsyncFunction("isBluetoothEnabled") {
|
|
259
|
-
try {
|
|
260
|
-
if (bluetoothManager == null) {
|
|
261
|
-
bluetoothManager = BluetoothManager(appContext.reactContext!!)
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return@AsyncFunction bluetoothManager!!.isBluetoothEnabled()
|
|
265
|
-
} catch (e: Exception) {
|
|
266
|
-
Log.e(TAG, "Error checking Bluetooth status: ${e.message}")
|
|
267
|
-
throw e
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
@@ -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
|
-
}
|