Android Question How can I read a file asychronously and then send it to a printer using write stream?

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

  1. davepamn

    davepamn Active Member Licensed User

    I need to read a file as a input stream then using an asynchronous stream send the data to a zebra printer.
     
  2. Peter Simpson

    Peter Simpson Expert Licensed User

  3. davepamn

    davepamn Active Member Licensed User

    The Zebra GD200P is a blue tooth printer
     
  4. davepamn

    davepamn Active Member Licensed User

    I created a service called "PrintService"

    As part of the print service, I have an asychronous stream called "printer_astream"

    Code:
    Dim InputFile2 As InputStream=File.OpenInput(File.DirAssets, "RFID.xml")

            
    Dim buffer2() As Byte

            buffer2=
    Bit.InputStreamToBytes(InputFile2)

            PrintService.printer_AStream.Write(buffer2)

            printservice.printer_astream.close
    This code produces a label the first time. However, the second time, the printer does nothing.

    Is there a way to test the state of the stream? It seems like it is in a wait state.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Your code closes the stream too early. AStream.Write is not a blocking method.

    If the printer doesn't send any response then you will need to use a timer to close the stream in a one or two seconds.
     
  6. davepamn

    davepamn Active Member Licensed User

    You mentioned using a timer to close the stream, in one to two seconds. I can do that.

    In the code samples I have been reading, they don't close the stream after writing.
     
    Last edited: May 28, 2015
  7. davepamn

    davepamn Active Member Licensed User

    I was able to get the code to work.

    I opened the serial object and stream in the service object and close the stream when the service is terminated.
     
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