Sub btnPrint_Action
sp.Open(cmbPort.Value)
sp.SetParams(9600,8,1,0)
if stream.isInitialized=False then
astream.Initialize(sp.getInputStream,sp.getOutputStream,"AStream")
end if
lblStatus.Text = "Status: Printing"
SendTextToPrinter
lblStatus.text="Status: Printed"
End Sub
Sub SendTextToPrinter()
Dim InputFile As InputStream=File.OpenInput(File.DirAssets, "230Res_M.zpl")
If InputFile.BytesAvailable>0 Then
Dim buffer() As Byte
buffer=Bit.InputStreamToBytes(InputFile)
astream.Write(buffer)
Log("Send zpl data to printer")
End If
Dim sXML As String
Dim sField1 As String ="999999"
sXML="<?xml version=" & Chr(34) & "1.0" & Chr(34) & " standalone=" & Chr(34) & "no" & Chr(34) & "?>"& Chr(13) & Chr(10)
sXML=sXML & "<!DOCTYPE labels SYSTEM " & Chr(34) & "Label.dtd" & Chr(34) & ">"& Chr(13) & Chr(10)
sXML=sXML & "<labels _FORMAT=" & Chr(34) & "E:230RES_M.ZPL" & Chr(34) & " _QUANTITY=" & Chr(34) & "1" & Chr(34)
sXML=sXML & " _PRINTERNAME=" & Chr(34) & "Printer 1" & Chr(34) & " _JOBNAME=" & Chr(34) & "LBL101" & Chr(34) & ">"& Chr(13) & Chr(10)
sXML=sXML & "<label>"& Chr(13) & Chr(10)
sXML=sXML & "<variable name=" & Chr(34) & "Field1" & Chr(34) & ">" & sField1 & "</variable>"& Chr(13) & Chr(10)
sXML=sXML & "</label>"& Chr(13) & Chr(10)
sXML=sXML & "</labels>"& Chr(13) & Chr(10)
Dim buffer2() As Byte =sXML.getbytes("UTF8")
astream.Write(buffer2)
Log("Send xml data to printer")
End Sub
Sub AStream_NewData (Buffer() As Byte)
Dim s As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
LogMessage("You", s)
EndSub
Sub AStream_NewStream(Dir As String, FileName As String)
Log("new stream" & Dir & " filename=" & FileName)
EndSub
Sub LogMessage(From As String, Msg As String)
txtLog.Text = txtLog.Text & From & ": " & Msg & CRLF
txtLog.SetSelection(txtLog.Text.Length, txtLog.Text.Length)
EndSub
Sub AStream_Error
Log("Error: " & LastException)
astream.Close
AStream_Terminated
EndSub
Sub AStream_Terminated
Log("Connection is broken.")
lblStatus.Text = "Status: Close"
end sub