Tengo una impresora Zebra M7Z320. tablet Samsung Galaxy Tab3, el código es así:
Pero sale en desorden, en ocaciones.
Sub Process_Globals
PrintBuffer AsString
Dim btAdmin AsBluetoothAdmin
Dim cmp20 AsSerial
Dim printer AsTextWriter
End Sub
Sub Globals
Dim Toggla AsToggle
Dim btnImprimir AsButton
End Sub
Sub btnImprimir_Click
Imprimir
End Sub
Sub Imprimir
Toggla.TurnBluetoothOn
btAdmin.Initialize("BlueTooth")
cmp20.Initialize("Printer")
StartPrinter
End Sub
Sub Printer_Connected (Success AsBoolean)
If Success Then
ImprimirDatos
Else
If Msgbox2("", "Error de Impresora ","ReImprimir","Cancelar","",Null) = DialogResponse.POSITIVE Then
StartPrinter
EndIf
EndIf
EndSub
Sub StartPrinter
Dim PairedDevices AsMap
Dim L AsList
Dim Res AsInt
ToastMessageShow("Imprimiendo ...",True)
PairedDevices.Initialize
Try
PairedDevices = cmp20.GetPairedDevices
Catch
Msgbox("Emparejando con la impresora ...","Error de Impresora")
printer.Close
cmp20.Disconnect
EndTry
If PairedDevices.Size = 0Then
Msgbox("Error Conectando con la impresora - No encontrada ...","")
Return
EndIf
If PairedDevices.Size = 1Then
Try
cmp20.ConnectInsecure(btAdmin,PairedDevices.Get(PairedDevices.GetKeyAt(0)),1)
Catch
Msgbox("Conectando ...","Error de Impresora")
printer.Close
cmp20.Disconnect
EndTry
Else
L.Initialize
For i = 0To PairedDevices.Size - 1
L.Add(PairedDevices.GetKeyAt(i))
Next
Res = InputList(L, "Seleccione un Dispositivo", -1)
If Res <> DialogResponse.CANCEL Then
cmp20.Connect(PairedDevices.Get(L.Get(Res)))
EndIf
EndIf
EndSub
Sub ImprimirDatos
printer.Initialize(cmp20.OutputStream)
PrintBuffer = Chr(13) & Chr(10)
printer.Write(PrintBuffer)
printer.Flush
PrintBuffer = Chr(13) & Chr(10)
printer.Write(PrintBuffer)
printer.Flush
PrintBuffer = “line 1” & Chr(13) & Chr(10)
printer.Write(PrintBuffer)
printer.Flush
PrintBuffer = “line 2” & Chr(13) & Chr(10)
printer.Write(PrintBuffer)
printer.Flush
PrintBuffer = “line 3” & Chr(13) & Chr(10)
printer.Write(PrintBuffer)
printer.Flush
printBuffer = ""
Msgbox("Impresión finalizada!","")
printer.Close
cmp20.Disconnect
End Sub