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

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.
 

Peter Simpson

Expert
Licensed User

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"

B4X:
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.
 

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:

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.
 
Top