Hi All, new to B4A, have one program under my belt but having problems on the second one using asyncstreams. I'm creating a program to write a number 0 to 255 to a device server, no response from server is required. I've got it working except for one problem, it only transmits the last character, i.e. if I transmit 128 the device server reacts as if it got only the 8. I'm pretty hard headed and have searched the forum over and over but I'm bleeding now and need a bit of help. :BangHead: Thanks!
By the way, who ever came up with B4A is a frigging Genius!!
My Code:
Sub Process_Globals
Dim AStreams As AsyncStreams
End Sub
Sub Globals
Dim Socket1 As Socket
Dim EditText1 As EditText
Dim Button1 As Button
Dim Button2 As Button
Dim Timer1 As Timer
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("jetdirectcontrol")
End Sub
Sub Button1_Click
Socket1.Initialize("Socket1")
Socket1.Connect("192.168.1.146" , 9100, 0)
Log ("Socket Connect")
End Sub
Sub Socket1_Connected (Successful As Boolean)
If Successful = False Then
Msgbox(LastException.Message, "Error connecting")
Return
Else
AStreams.Initialize(Socket1.InputStream, Socket1.OutputStream, "AStreams")
End If
Log ("Connected No Error")
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF-8")
ToastMessageShow(msg, False)
Log(msg)
End Sub
Sub AStreams_Error
ToastMessageShow(LastException.Message, True)
End Sub
Sub EditText1_EnterPressed
If AStreams.IsInitialized = False Then Return
If EditText1.Text.Length > 0 Then
Dim buffer() As Byte
buffer = EditText1.Text.GetBytes("UTF8")
AStreams.Write(buffer)
EditText1.SelectAll
Log("Sending: " & EditText1.Text)
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button2_Click
Socket1.Close
AStreams.Close
Log ("Socket Disconnected")
Activity.Finish
Log ("Program Closed")
End Sub
By the way, who ever came up with B4A is a frigging Genius!!
My Code:
Sub Process_Globals
Dim AStreams As AsyncStreams
End Sub
Sub Globals
Dim Socket1 As Socket
Dim EditText1 As EditText
Dim Button1 As Button
Dim Button2 As Button
Dim Timer1 As Timer
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("jetdirectcontrol")
End Sub
Sub Button1_Click
Socket1.Initialize("Socket1")
Socket1.Connect("192.168.1.146" , 9100, 0)
Log ("Socket Connect")
End Sub
Sub Socket1_Connected (Successful As Boolean)
If Successful = False Then
Msgbox(LastException.Message, "Error connecting")
Return
Else
AStreams.Initialize(Socket1.InputStream, Socket1.OutputStream, "AStreams")
End If
Log ("Connected No Error")
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF-8")
ToastMessageShow(msg, False)
Log(msg)
End Sub
Sub AStreams_Error
ToastMessageShow(LastException.Message, True)
End Sub
Sub EditText1_EnterPressed
If AStreams.IsInitialized = False Then Return
If EditText1.Text.Length > 0 Then
Dim buffer() As Byte
buffer = EditText1.Text.GetBytes("UTF8")
AStreams.Write(buffer)
EditText1.SelectAll
Log("Sending: " & EditText1.Text)
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button2_Click
Socket1.Close
AStreams.Close
Log ("Socket Disconnected")
Activity.Finish
Log ("Program Closed")
End Sub