Android Question Bluetooth Printing with AsyncStreams

Discussion in 'Android Questions' started by colboy, Dec 6, 2018.

  1. colboy

    colboy Member Licensed 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
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    There is no need to flush anything with AsyncStreams. The data is sent.

    The end of line characters seem to be wrong.

    Code:
    BTSend(lSetNeverTimeout&Chr(13)) '13
    BTSend("^XZ"&Chr(10)) '10?
     
  3. colboy

    colboy Member Licensed User

    I tried with CHR(13) and CHR(10), but I only get the label after sending it twice.
     
  4. colboy

    colboy Member Licensed User

    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.

    Code:
    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
     
  5. colboy

    colboy Member Licensed 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.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

  7. colboy

    colboy Member Licensed 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.
     
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