Android Question How do I write the byte content of an input stream?

davepamn

Active Member
Licensed User
Longtime User
B4X:
Sub PrinterSerial_Connected(Success As Boolean)

    If Success Then

        SendTextToPrinter

    EndIf

End Sub

Sub SendTextToPrinter

    If printer_AStream.IsInitialized = False Then
                       printer_AStream.Initialize(printer_serial1.InputStream,printer_serial1.OutputStream,"PrinterAStream")

    End If

 

Dim InputFile As InputStream=File.OpenInput(File.DirAssets, "sample3.prn")

Dim buffer() As Byte
InputFile.ReadBytes(buffer,0,InputFile.BytesAvailable)
printer_astream.write(buffer)
end sub
 
Last edited:

davepamn

Active Member
Licensed User
Longtime User
The buffer is utf8

buffer = ("! 0 200 200 406 1\r\n" & "ON-FEED IGNORE\r\n" & "BOX 20 20 380 380 8\r\n" & "T 0 6 137 177 TEST\r\n" & "PRINT\r\n").GetBytes("UTF8")
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
B4X:
Dim InputFile As InputStream=File.OpenInput(File.DirAssets, "sample3.prn")
    If InputFile.BytesAvailable>0 Then

        Dim buffer() As Byte

        buffer=Bit.InputStreamToBytes(InputFile)

        printer_AStream.Write(buffer)

        Log("Send data to printer")

    End If

Here is the code that worked. thanks
 
Upvote 0
Top