Sub Process_Globals
Dim BTConnection As Serial
Dim BTPrinter As AsyncStreams
Dim MACAddress As String = "00:17:AC:01:46:A9"
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
If FirstTime Then
BTConnection.Initialize("Printer")
End If
End Sub
Sub btnPrint_Click
StartPrint
End Sub
Sub StartPrint
ProgressDialogShow("Printing")
Try
BTConnection.Connect(MACAddress)
Catch
Msgbox("Unable to connect to printer","Printer Error")
BTPrinter.Close
BTConnection.Disconnect
End Try
End Sub
Sub Printer_Connected (Success As Boolean)
Try
If Success Then
BTPrinter.Initialize(BTConnection.InputStream, BTConnection.OutputStream, "AStreams")
BTPrint("This is a test, this is a test" & CRLF & _
"This is a test, this is a test" & CRLF & _
"This Is a test, this Is a test" & CRLF & _
"This is a test, this is a test" & CRLF & _
"This Is a test, this Is a test" & CRLF & CRLF)
ProgressDialogHide
BTPrinter.Close
BTConnection.Disconnect
Else
ProgressDialogHide
If Msgbox2("Unable to connect to printer", "Printer Error","Try Again","Cancel","",Null) = DialogResponse.POSITIVE Then
BTConnection.Disconnect
StartPrint
Else
BTConnection.Disconnect
End If
End If
Catch
Log(LastException)
End Try
End Sub
Sub BTPrint(pText As String)
Dim lBuffer() As Byte
lBuffer = pText.GetBytes("UTF8")
BTPrinter.Write2(lBuffer, 0, lBuffer.Length)
End Sub
Sub AStreams_Error
Log("AStreams_Error:" & LastException.Message)
End Sub
Sub AStreams_Terminated
Log("AStreams_Terminated")
End Sub