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

Discussion in 'Android Questions' started by davepamn, May 26, 2015.

  1. davepamn

    davepamn Active Member Licensed User

    Code:
    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: May 26, 2015
  2. davepamn

    davepamn Active Member Licensed 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")
     
  3. Peter Simpson

    Peter Simpson Expert Licensed User

    Here you go:
    Code:
    'Try this
        Dim BufStr As String = "Hello, here is your buffer text"
        
    Dim Buffer() As Byte = BufStr.GetBytes("UTF8")
        Printer.Write(Buffer)
     
    lemonisdead likes this.
  4. davepamn

    davepamn Active Member Licensed User

    Code:
    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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice