Android Question Print via the local network

vecino

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

DonManfred

Expert
Licensed User
Longtime User
See Serial-Library. If your printer can be accessed by wifi then it should be possible to send print commands with the serial lib to this printer.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Hi, thanks for responding.
The printer is connected via a LAN cable.
Is it possible then with serial library?
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
A Epson TM-T20 II and other 'chinese' unbranded :)
I need to connect via LAN cable.
 
Upvote 0

picenainformatica

Active Member
Licensed User
Longtime User
Try to connect on port 9100. Send ASCII text directly on output stream. Be sure to close connection after send complete.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Epson TM-T20 II

@vecino I would use the Network library and the RandonAccessFile library, see the code below.
B4X:
Sub Process_Globals
    Dim TMT20II As Socket 'Network library
    Dim AStreams As AsyncStreams 'RandomAccessFile library
End Sub

Sub Activity_Create(FirstTime As Boolean)
    TMT20II.Initialize("TMT20II")
    TMT20II.Connect("192.168.0.100", 9100, 0) '100=Printer address, 9100=Port number (please look up port number)
End Sub

Sub TMT20II_Connected (Successful As Boolean)
    Log(Successful)
    If Successful Then
        AStreams.Initialize(TMT20II.InputStream, TMT20II.OutputStream, "AStreams")
        CallSub(Null, SendToPrinter)
    End If
End Sub

Sub SendToPrinter
    Dim SendMsg As String

    SendMsg = Chr(27) & Chr(61) & Chr(1) 'Select EPSON printer
    AStreams.Write(SendMsg.GetBytes("UTF8"))

    SendMsg = "Hello, this is a test print" 'Send this line to the EPSON printer
    AStreams.Write(SendMsg.GetBytes("UTF8"))

    SendMsg = Chr(27) & Chr(100) & Chr(2) 'Line feed
    AStreams.Write(SendMsg.GetBytes("UTF8"))

    SendMsg = Chr(27) & Chr(109) 'Partial cut receipt paper
    AStreams.Write(SendMsg.GetBytes("UTF8"))
End Sub

'You need to add more AStreams subs here.

Once connected to the printer, you can use AsyncStreams to send escape codes and data stream directly to the receipt printer over the LAN.

Please note: I have not actually done this before, but I can't see why the above code would not work. The code should work just fine IMO...
 
Last edited:
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Fantastic, Great !!!
Thank you very much :)

I have a question. How I can know the port?
I made a loop, testing port 1, 2, 3, 4, 5, etc.
It was finally port 9100
 
Upvote 0

sakissoft

Member
Licensed User
Longtime User
Epson TM-T20 II

@vecino I would use the Network library and the RandonAccessFile library, see the code below.
B4X:
Sub Process_Globals
    Dim TMT20II As Socket 'Network library
    Dim AStreams As AsyncStreams 'RandomAccessFile library
End Sub

Sub Activity_Create(FirstTime As Boolean)
    TMT20II.Initialize("TMT20II")
    TMT20II.Connect("192.168.0.100", 169, 0) '100=Printer address, 169=Port number (please look up port number)
End Sub

Sub TMT20II_Connected (Successful As Boolean)
    Log(Successful)
    If Successful Then
        AStreams.Initialize(TMT20II.InputStream, TMT20II.OutputStream, "AStreams")
        CallSub(Null, SendToPrinter)
    End If
End Sub

Sub SendToPrinter
    Dim SendMsg As String

    SendMsg = Chr(27) & Chr(61) & Chr(1) 'Select EPSON printer
    AStreams.Write(SendMsg.GetBytes("UTF8"))

    SendMsg = "Hello, this is a test print" 'Send this line to the EPSON printer
    AStreams.Write(SendMsg.GetBytes("UTF8"))

    SendMsg = Chr(27) & Chr(100) & Chr(2) 'Line feed
    AStreams.Write(SendMsg.GetBytes("UTF8"))

    SendMsg = Chr(27) & Chr(109) 'Partial cut receipt paper
    AStreams.Write(SendMsg.GetBytes("UTF8"))
End Sub

'You need to add more AStreams subs here.

Once connected to the printer, you can use AsyncStreams to send escape codes and data stream directly to the receipt printer over the LAN.

Please note: I have not actually done this before, but I can't see why the above code would not work. The code should work just fine IMO...


Ok . This sample printing Ok only latin characters but GREEK characters NO.
I try alls greek codepage programmatically but ...nothing

Any idea...?
 
Upvote 0

sakissoft

Member
Licensed User
Longtime User
I try alls greeks codepages with code from epson esc pos (pdf) but nothing. But i don't try with configuration utility. I try this
Thanks rboeck
 
Upvote 0

sakissoft

Member
Licensed User
Longtime User
OK
must Be Remove this :

SendMsg = Chr(27) & Chr(61) & Chr(1) 'Select EPSON printer
AStreams.Write(SendMsg.GetBytes("UTF8"))

and alls codepages (and GREEK) is worked !!

:)
 
Upvote 0
Top