Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim AStreams As AsyncStreams
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.
Dim Socket1 As Socket
Dim Timer1 As Timer
Dim Button1 As Button
Dim EditText1 As EditText
Dim EditText2 As EditText
Dim Button2 As Button
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("serialcom")
Socket1.Initialize("Socket1")
Socket1.Connect("192.168.1.152" , 10001, 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 Button1_Click
EditText1.Text = (0011110101010100000011000)
If AStreams.IsInitialized = False Then Return
If EditText1.Text.Length > 0 Then
Dim buffer() As Byte
buffer = EditText1.Text.GetBytes("UTF8")
AStreams.Write(Array As Byte(EditText1.Text))
EditText1.SelectAll
Log("Sending: " & EditText1.Text)
End If
EditText1.Text = (0011110101010100000011000)
If AStreams.IsInitialized = False Then Return
If EditText1.Text.Length > 0 Then
Dim buffer() As Byte
buffer = EditText1.Text.GetBytes("UTF8")
AStreams.Write(Array As Byte(EditText1.Text))
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")
Log ("Astreams Disconnected")
Activity.Finish
Log ("Program Closed")
End Sub