You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Printing gets stuck after 2-3 print jobs. I tried using the reset command and Thread.sleep(100) but the issue persists. I noticed that the printer specifically gets stuck while printing barcodes, whereas normal printing works without any problems.
this is my code
class PrintLabelTask(private val context: Context) {
var printama: Printama? =null
fun printLabel(view:ConstraintLayout){
if (printama != null && printama!!.isConnected){
print()
}else{
Log.e("ConnectBluetooth","::::")
Printama.with(context).connect{
printama = it
print()
}
}
}
private fun print(){
if (printama != null && printama?.isConnected == true){
Log.e("threadName",Thread.currentThread().name)
printama?.printText("\u001B\u0040")
printama?.setBold()
printama?.printTextlnWideBold("REDUCED", Printama.CENTER)
printama?.printTextln("\u001B\u0061\u0001"+"WARBURTON HALF & HALF")
val totalPageLength = 32
val txtFrom = "From "
val txtTo = "|To "
var fromValue = "1.99"
var toValue = "90p"
val currencySign = "$"
val totalTextLength = txtFrom.length+(fromValue.length+1) + txtTo.length + toValue.length
if (totalTextLength < totalPageLength){
val availableLength = totalPageLength - totalTextLength
val extraSpace = (availableLength/10).toInt()
fromValue = " ".repeat(extraSpace-1) + fromValue + " ".repeat(extraSpace)
toValue = "".repeat(extraSpace) + toValue + " ".repeat(extraSpace)
}
printama?.printTextBold(txtFrom)
printama?.setDeleteLine()
printama?.printText("\u001B\u0021\u0020"+currencySign+fromValue)
printama?.printTextBold(txtTo)
printama?.printTextln("\u001B\u0021\u0020"+toValue+"\u001B\u0021\u0000")
printama?.printLine()
generateBarcode("2090023000900").let { printama?.printImage(it) }
printama?.feedPaper()
Thread.sleep(100)
}
}
private fun generateBarcode(text:String): Bitmap? {
return try {
val height = 72
val width = 424
val bitMatrix = MultiFormatWriter().encode(text, BarcodeFormat.CODE_128, width, height)
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565)
for (x in 0 until width) {
for (y in 0 until height) {
bitmap.setPixel(x, y, if (bitMatrix[x, y]) android.graphics.Color.BLACK else android.graphics.Color.WHITE)
}
}
bitmap
}catch (e:Exception){
Log.e("BarcodeException", e.printStackTrace().toString())
null
}
}
}
The text was updated successfully, but these errors were encountered:
Printing gets stuck after 2-3 print jobs. I tried using the reset command and Thread.sleep(100) but the issue persists. I noticed that the printer specifically gets stuck while printing barcodes, whereas normal printing works without any problems.
this is my code
The text was updated successfully, but these errors were encountered: