Android Question [ SOLVED ] TCPIP how connect Pos cash register using lan port

Lello1964

Well-Known Member
Licensed User
Longtime User
I have to connect a Pos cash register using Lan tcpip protocol.
I have tryed using this code :
B4X:
    J.PutString("http://192.168.1.123:1126/1F","")
   Wait For (j) JobDone(j As HttpJob)
   If j.Success Then
       Log(j.GetString)
   End If
   j.Release

where ip is 192.168.1.123 port is 1126 and 1F is the command.

the printer receive command but display error

If i try to send using PUTTY in raw connection type it's OK

Who can help me to solve ?


thanks


Raffaele
 

Lello1964

Well-Known Member
Licensed User
Longtime User
SOLVED

using Network lib

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim BC As ByteConverter
   Dim Socket1  As Socket
   Dim AStreams As AsyncStreams
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("Layout1")
   Socket1.Initialize("Socket1")
   Socket1.Connect("192.168.1.123" ,1126,2000)
End Sub

Sub Socket1_Connected (Successful As Boolean)
   If (Successful) Then
       AStreams.Initialize(Socket1.InputStream, Socket1.OutputStream,"AStreams")
       ToastMessageShow("connected",False)
       Dim cmd As String ="1F"
       Dim bytes() As Byte
       bytes=BC.StringToBytes(cmd,"UTF8")      
       AStreams.Write(bytes)
   Else
       Msgbox(LastException.Message, "Error connecting")
       Socket1.Close
   End If
End Sub
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Try

B4X:
         socket1.Initialize("socket1")      
        'Connect Host / Port
        socket1.Connect(Host, Port, 200)
        Wait For (socket1) Socket1_Connected (Successful As Boolean)
        If (Successful) Then
            Try
                AStreams.Initialize(socket1.InputStream, socket1.OutputStream, "AStreams")
                Wait For (AStreams) AStreams_NewData (Buffer() As Byte)
                Log("AStreams inizializzata")
                Dim msg As String
                msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
                .......
 
Upvote 0

Similar Threads

  • Article
Share My Creation AdzDisplay
Replies
0
Views
1K
Top