Android Question Print via WIFI to network printer, AsyncStreamsText , printer not released

proinko

Member
Licensed User
Longtime User
hi

the following code works for printing labels to a network printer, but after printing succesfully from one android device, it is not possible to print from another android device (using the same app) . It seems that the printer is not released from the first device. The first device is able to continue printing a lot of labels without problem. How can the printer be released?

The app uses AsyncStreamsText Class

Activity Code

B4X:
Sub Process_Globals

    Private Socket As Socket
    Private AstreamT As AsyncStreamsText
...

Sub PrintLabel
    If Socket.IsInitialized Then
        Socket.Close
    End If
    Socket.Initialize ("Socket")
    Socket.Connect (Starter.IPPrinter,9100,10000)
    wait for Socket_Connected (Succesful As Boolean)
    If Succesful = False Then
        Log(LastException.Message)
        Dim msa As Object=xui.MsgboxAsync("....
        Wait For (msa) Msgbox_Result (rM As Int)
    Else
        If AstreamT.IsInitialized Then
            AstreamT.Close
        End If
        AstreamT.Initialize(Me,"AstreamT",Socket.InputStream,Socket.OutputStream)
        PrintJScript(parameters.....)
    End If
End Sub

Sub AstreamT_NewData (Buffer() As Byte)
    
End Sub

Sub AstreamT_Error
    Log("Error: " & LastException)
    AstreamT.Close
    AstreamT_Terminated
End Sub

Sub AstreamT_Terminated
    Log("Connection is broken.")
    Socket.Close
End Sub

Sub PrintJScript(paremeters ....)
    Dim s As StringBuilder
    s.Initialize
    s.Append("m m")   
    s.Append(CRLF)
    s.Append("J")   
    s.Append(CRLF)
    ...
    s.Append("A 1")
    s.Append(CRLF)

    Dim c As String= s.ToString
    AstreamT.Write(c)
    Socket.close
    Dim msa As Object=xui.MsgboxAsync("....
    Wait For (msa) Msgbox_Result (rM As Int)
End Sub

thanks for your help!
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top