Android Question The Epson TM-T20II printer,How to receive Printer status?

eric19740521

Member
Licensed User
Longtime User
1200Wx1200H


The Epson TM-T20II printer,How to receive Printer status?
I need receive Printer status from a mobile application in B4A?



I need to know if I can implement this solution to a client.
Thank you very much for your reply.


B4X:
#Region  Project Attributes
    
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: true
    #IncludeTitle: false
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    'Dim TMT20II As Socket 'Network library
    Dim AStreams As AsyncStreams 'RandomAccessFile library
    
    'Dim print_ok As Boolean
    
    'Dim client As Socket
    Dim client2 As Socket
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private Button1 As Button
    Private Button2 As Button
    Private Button3 As Button
    'Private Button4 As Button       
    
    Private EditText1 As EditText


    Private EditText2 As EditText

    Private Panel1 As Panel
    Private Panel2 As Panel
    Private Panel3 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:


    Activity.LoadLayout("main")
    
    
    
    '調整 主功能頁面畫面
    Panel1.Visible=True
    Panel1.Width=100%x
    Panel1.Left=0
    'Panel1.top= 5
    'Panel1.Height=100%y - Panel_Pdt.Height -50
    
    Panel3.Visible=True
    Panel3.Width=100%x
    Panel3.Left=0
    Panel3.top=  100%y  -Panel3.Height
    'Panel3.Height=100%y - Panel_Pdt.Height -50
        
    
    Panel2.Visible=True
    Panel2.Width=100%x
    Panel2.Left=0
    Panel2.top= Panel1.Height
    Panel2.Height=100%y - Panel1.Height -Panel3.Height
            
    
    
    
    
    
    
    
    EditText1.Text ="192.168.1.100"
    
    
    EditText2.Text =""
    EditText2.Text =    EditText2.Text & "Hello, this is a 測試列印01" & Chr(13) & Chr(10)
    EditText2.Text =    EditText2.Text & "Hello, this is a 測試列印02" & Chr(13) & Chr(10)
    EditText2.Text =    EditText2.Text & "Hello, this is a 測試列印03" & Chr(13) & Chr(10)
    EditText2.Text =    EditText2.Text & "Hello, this is a 測試列印04" & Chr(13) & Chr(10)
    EditText2.Text =    EditText2.Text & "Hello, this is a 測試列印05" & Chr(13) & Chr(10)
    EditText2.Text =    EditText2.Text & "Hello, this is a 測試列印06" & Chr(13) & Chr(10)
    EditText2.Text =    EditText2.Text & "Hello, this is a 測試列印07" & Chr(13) & Chr(10)
    
    
    
    
    
'    Button1.Enabled = False
'    Button2.Enabled = False
'    Button3.Enabled = False


    'TMT20II.Initialize("TMT20II")
    'TMT20II.Connect(EditText1.Text, 9100, 0) '100=Printer address, 9100=Port number (please look up port number)

        
    Log("程式初始化完成~")
End Sub

Sub Activity_Pause(UserClosed As Boolean)
    If UserClosed Then
        Log("closing")
        'AStreams.Close
        'client.Close

    End If
End Sub




Sub Button3_Click
    
    client2.Close
    AStreams.Close
    client2.Initialize("client2")
    client2.Connect(EditText1.Text, 9100, 0)
    
    
    
End Sub

Sub client2_Connected(Connected As Boolean)
    If Connected = True Then
        'ToastMessageShow("Conectado",True)
        AStreams.Initialize(client2.InputStream,client2.OutputStream,"Astreams")
        
        Dim SendMsg As String


        Log("client2_Connected")
        'ToastMessageShow( "列印中...", False)
    
        SendMsg = SendMsg  & Chr(27) & Chr(61) & Chr(1) 'Select EPSON printer
        SendMsg = SendMsg  & Chr(13) & Chr(10)'Line feed
        
        
        AStreams.Write(SendMsg.GetBytes("UTF8"))
    
        SendMsg = SendMsg  & Chr(16) & Chr(4)& "1"        ' DLE EOT 1


        AStreams.Write(SendMsg.GetBytes("UTF8"))
    
    
    
        Dim rcv_bytes As Long
        Dim oqs As Int
        'Dim rcv_msg As String
    
        rcv_bytes = AStreams.StreamReceived
        oqs = AStreams.OutputQueueSize

        If oqs > 0 Then

            ToastMessageShow("Output Queue size: " & oqs, False)

            Log("Output Queue size: " & oqs)
        End If
        If rcv_bytes > 0 Then

            ToastMessageShow("Received bytes: " & rcv_bytes, False)
            
            Log("Received bytes: " & rcv_bytes)


        End If
        
        'Log(BytesToString(rcv_bytes, 0, rcv_bytes.Length, "UTF8"))
    
    
    Else
        ToastMessageShow("Servidor no disponible",True)
    End If
  
End Sub

Sub Astreams_Error
    Log("error")
    'client.Close
    'AStreams.Close
End Sub
Sub Astreams_NewData (Buffer() As Byte)
    Dim msg As String
    msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
    
    Log(msg )
    
    ToastMessageShow(msg, False)

End Sub
Sub Astreams_ObjectSent (Key As String)
    Log("Object sent: " & Key)
End Sub
Sub AStreams_NewText(text As String)
    'cmd = text.Trim
    Log(text.Trim)
End Sub
 

eric19740521

Member
Licensed User
Longtime User
MbedAndroid,thx


I search a lot of related information

connect this to the bill machine??
I think it ,
Best to use
java 's library to communicate with the printer
 
Upvote 0
Top