Android Question the code execution sequence when callback?

hf

Member
Licensed User
when I click button4 “Button4_Click”,
I can do other thing,such as input text on edittext.
and after a while, Printer_Connected showinfo ("print error")

may i wait for the callback Sub Printer_Connected (Success As Boolean) complte,and I do other thing.


Sub Button4_Click
If h_currdjh<>"" Then
If BTConnection.IsEnabled=False Then
Msgbox("蓝牙已关闭,不能打印!","信息提示")
Return
End If
BTConnection.Connect(pubcs.P_printerMac)
End If
End Sub

Sub Printer_Connected (Success As Boolean)
Dim PrintBuffer As String
Dim prtarray As List=PrintArray(h_currdjh)
If Success Then

Printer.Initialize2(BTConnection.OutputStream,"gbk")
Printer.Writeline(h_currdjh)
PrintBuffer=Chr(29)&"h"&Chr(60) '条码高度
Printer.Write(PrintBuffer)

PrintBuffer=Chr(29)&"w"&Chr(2) '条码款度
Printer.Write(PrintBuffer)

PrintBuffer=Chr(29)&"k"&Chr(23) & h_currdjh & Chr(0)
Printer.WriteLine(PrintBuffer)

Printer.WriteLine(Chr(13))
Printer.WriteLine(Chr(13))
Printer.Flush
Printer.Close
BTConnection.Disconnect
Else
Msgbox("请确认打印机是否连接正确!","print error")
End If
End Sub
 

hf

Member
Licensed User
Please use [code]code here...[/code] tags when posting code.

I'm not sure that I understand the question. However you should never use TextWriter with network or Bluetooth streams. You should use AsyncStreams or AsyncStreamsText.


i use TextWriter ,to print why not use?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
1) I'm going to guess that your code adapted from this post: [https://www.b4x.com/android/forum/t...receipt-printer-with-matching-codepage.76831/]

2) You're getting the "print error" message box

Then it looks like
B4X:
BTConnection.Connect(pubcs.P_printerMac)
is unsuccessful. So you need to figure out why your app (actually, this one line of code) is not connecting to your printer. Are you sure pubcs.P_printerMac contains the correct MAC address for your printer?
 
Upvote 0

hf

Member
Licensed User
1) I'm going to guess that your code adapted from this post: [https://www.b4x.com/android/forum/t...receipt-printer-with-matching-codepage.76831/]

2) You're getting the "print error" message box

Then it looks like
B4X:
BTConnection.Connect(pubcs.P_printerMac)
is unsuccessful. So you need to figure out why your app (actually, this one line of code) is not connecting to your printer. Are you sure pubcs.P_printerMac contains the correct MAC address for your printer?


yes,you said right. i try to change the code .
 
Upvote 0
Top