Android Question Bluetooth Printing with AsyncStreams

colboy

Member
Licensed User
Longtime User
I wrote an application a little while ago to print to a Bluetooth printer. It worked, but occasionally it would lock up. I was using a TextWriter, which I subsequently found out was not the way to go, with AsyncStreams being the preferred way to go.

I've just created a small sample application and while it does print, I find that I have to press the print button twice before a label comes out. This was never a problem before, as the label would be printed when the TextWriter was flushed. I've attached the test application as I've seen others needing similar functionality.

I would really appreciate if someone could tell me where I've gone wrong.

Thanks in advance.

Colin
 

Attachments

  • BluetoothTest-Label.zip
    11.6 KB · Views: 405

colboy

Member
Licensed User
Longtime User
I tried with CHR(13) and CHR(10), but I only get the label after sending it twice.
 
Upvote 0

colboy

Member
Licensed User
Longtime User
I tried with CHR(13) and CHR(10), but I only get the label after sending it twice.
This code is the same, but used with the TextWriter and it prints each label fine. Where the other code has *text* here's it's variables, but essentially the same code.

B4X:
        Dim lDescription As String=edtDescription.Text&"                                                  "
        Dim lDesc1 As String=GlobalFunctions.mid(lDescription,1,25)
        Dim lDesc2 As String=GlobalFunctions.mid(lDescription,26,25)
        Printer.WriteLine(lSetZPLMode&Chr(13))
        Printer.WriteLine(lSetNeverTimeout&Chr(13))
        Printer.Write("^XA")
        Printer.Write("^MNN") ' Media Tracking MN(N) Continuous (M) Media Mark Sensing (Was MNN)
        Printer.Write("^MMT") ' MMT Tearoff
        Printer.Write("^LL627")
        Printer.Write("^LH0,0")
        Printer.Write("^FO20,50^AFN,24,0^FDUltimate Inventory System^FS")
        Printer.Write("^FO20,80^AFN,24,0^FDDate / Time:^FS")
        Printer.Write("^FO250,80^ABN,24,0^FD"&GlobalFunctions.GetDate(DateTime.now)&"^FS")
        Printer.Write("^FO20,105^AFN,24,0^FDArea:^FS")
        Printer.Write("^FO250,105^ABN,24,0^FD"&cmbArea.selecteditem&"^FS")
        Printer.Write("^FO20,130^AFN,24,0^FDColumn Loc.:^FS")
        Printer.Write("^FO250,130^ABN,24,0^FD"&cmbColumnLocation.Selecteditem&"^FS")
        Printer.Write("^FO20,155^AFN,24,0^FDInventory Loc.:^FS")
        Printer.Write("^FO250,155^ABN,24,0^FD"&cmbInventoryLocation.Selecteditem&"^FS")
        Printer.Write("^FO20,185^GB600,1,2^FS")
        Printer.Write("^FO20,200^AFN,36,0^FDTag Number:^FS")
        Printer.Write("^FO250,200^ABN,48,0^FD"&lblTagNumber.text&"^FS")
        Printer.Write("^FO20,250^AFN,36,0^FDMaterial/Part:^FS")
        Printer.Write("^FO250,250^ABN,36,0^FD"&edtMaterial.text&"^FS")
        Printer.Write("^FO20,290^AFN,36,0^FDCounted Qty:^FS")
        Printer.Write("^FO250,290^ABN,36,0^FD"&edtCountedQuantity.text&" "&cmbCountedUOM.Selecteditem&"^FS")
        Printer.Write("^FO20,325^AFN,24,0^FDSOP Qty:^FS")
        Printer.Write("^FO250,325^ABN,24,0^FD"&gSAPQuantity&" "&gSAPUom&"^FS")
        Printer.Write("^FO20,350^AFN,24,0^FDPack Qty:^FS")
        Printer.Write("^FO250,350^ABN,24,0^FD"&edtPackQuantity.text&"^FS")
        Printer.Write("^FO20,385^GB600,1,2^FS")
        Printer.Write("^FO20,410^ADN,24,0^FDCounted By:^FS")
        Printer.Write("^FO250,410^ADN,24,0^FD"&btnCounter.text&"^FS")
        Printer.Write("^FO20,440^ADN,24,0^FDChecked By:^FS")
        Printer.Write("^FO250,440^ADN,24,0^FD"&btnChecker.text&"^FS")
        Printer.Write("^FO20,470^ADN,24,0^FDDescription:^FS")
        Printer.Write("^FO250,470^ADN,24,0^FD"&lDesc1&"^FS")
        Printer.Write("^FO250,500^ADN,24,0^FD"&lDesc2&"^FS")
        Printer.Write("^FO20,570^APN,8,0^FDTicket Printed on "&GlobalFunctions.getdate(DateTime.Now)&" at "&GlobalFunctions.gettime(DateTime.Now)&" by "&Main.gUser.Login&"^FS")
        Printer.Write("^XZ")
        Printer.Flush
 
Upvote 0

colboy

Member
Licensed User
Longtime User
If I put the AsyncStream version in a loop and create a variable for the tagnumber, incrementing after the loop is complete, I get a successful run of consecutive numbers, so it seems that either the first or second label is getting lost somewhere.
 
Upvote 0

colboy

Member
Licensed User
Longtime User
I tried that, building the string up first and then sending it down in one call, but I get the same problem. I've also tried Write and Write2, again doesn't seem to make a difference.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…