Android Question Print via the local network

vecino

Well-Known Member
Licensed User
Hello, is it possible to print to a local network?
No internet. It is a local network with cable and wifi.
 

Peter Simpson

Expert
Licensed User
I personally use 2 lines as I don't always use UTF8. Actually for a customers Bluetooth printer app I used ISO-8859-1 because of currency symbols I think, or was it 2 dots. Anyway I'm more than sure @Erel knows of an easier way to switch between UTF8 and ISO=8859-1 but only using 1 one instead of 2.

But hey, what can one say except that it's now time for a cycle ride, then a game of snooker, then I'll do some coding ;)
 
Upvote 0

sakissoft

Member
Licensed User
Now i have other problem.
When printing sometimes(after close wifi maybe or set screen off) i get this message: "sub astreams_newdata not found"

Why?

Must be insert astreams.close after any printing?

Remember : i want to use 2 smartphones for print on my epson tm20 l (like as pda for restaurand orders)

Thanks

Any idea?
 
Last edited:
Upvote 0

Mark Thorndyke

Member
Licensed User
Hi,
Back again after a few years out of this but now back in action - and should be taking into a new role at work in coming weeks (and new subscriptions for Erel!)
Anyway, doing some testing in advanced and found this helpful for printing over a network.
What I have found though it needs some form of test to make sure a printer is connected (or if network is a wee bit slow to respond)
With the new (to me on returning) Wait For function and Resumable Subs the below works to confirm a connection - maybe this could help others out.
Thanks for above!

B4X:
Sub NetworkPrinter_Connected (Successful As Boolean) As ResumableSub
    If Successful Then
        AStreams.Initialize(NetworkPrinter.InputStream, NetworkPrinter.OutputStream, "AStreams")
    End If
    Return Successful
End Sub

Sub ConnectPrinters(ipAddress As String, portNo As Int, timeOut As Int, timeToConnect As Int)As ResumableSub
    NetworkPrinter.Connect(ipAddress, portNo, timeOut)
    Dim timeCounter As Int = 0
    Dim connected As Boolean = False
    Do Until timeCounter = timeToConnect Or connected = True
        Sleep(1000)
        connected = NetworkPrinter.Connected
        timeCounter = timeCounter + 1
        Log(timeCounter)
    Loop
    Return connected
End Sub

Sub SendToPrinter (printerOutput As String)
    Wait For (ConnectPrinters("192.168.0.2", 9100, 0, 5)) Complete (connectedResult As Boolean)
    If connectedResult Then
        Log("Initialised")
        Log(printerOutput)
        AStreams.Write(printerOutput.GetBytes("UTF8"))
        NetworkPrinter.Close
    Else
        Log("Printer not initialised")
    End If
End If
 
Last edited:
Upvote 0

Bladimir Silva Toro

Active Member
Licensed User
What I personally do is ping the IP addresses of the printer before making the connection.

I have an Epson TM T20II connected to a LAN network via Ethernet port.

B4X:
        ProgressDialogShow("Conectado a Impresora. Favor Espere...")
        Dim p As Phone
        Wait For (p.ShellAsync("ping", Array As String("-c", "1",Principal.DirIpImpLANBodega))) Complete (Success As Boolean, ExitValue As Int, StdOut As String, StdErr As String)
        If Success And ExitValue=0 Then
            TMT20II.Connect(Principal.DirIpImpLANBodega, 9100, 0) '100=Printer address, 9100=Port number (please look up port number)
        Else
            ProgressDialogHide
            Msgbox("Impresora NO Conectada a la Red. Vuelva a Intentarlo","Mensaje!!!")
        End If

Testing is done by connecting the printer to the wireless network but the process is slow
 
Upvote 0

Mark Thorndyke

Member
Licensed User
For info, I've seen members posting up regarding printing to Zebra printers. As I'm testing to use in an industrial environment with labels, I have been able to print to a network based Honeywell successfully. The only thing to note is again network speed related. I amended my code about to wait for the stream to complete with another Wait For, otherwise the printer would flash away receiving data while the code completed and closed the steam. Hope that's of use for people

B4X:
         AStreams.Write(printerOutput.GetBytes("UTF8"))
        Wait For (AStreams.OutputQueueSize = 0) Completed
        AStreams.SendAllAndClose
        NetworkPrinter.Close
 
Upvote 0
Top