#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
'Activity module
Sub Process_Globals
Private ast As AsyncStreamsText
Dim timerstreams As Timer
Dim AStream As AsyncStreams
End Sub
Sub Globals
Dim myBuffer As String
Dim txtInput As EditText
Dim txtLog As EditText
Dim btnSend As Button
Dim ticksOfInactivity As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
'timerstreams.Initialize("timerStreams", 100)
Activity.LoadLayout("2")
'If AStream.IsInitialized = False Then
If ast.IsInitialized = False Then
'AStream.Initialize(Main.Serial1.InputStream, Main.Serial1.OutputStream, "AStream")
ast.Initialize(Me,"ast", Main.serial1.InputStream, Main.serial1.OutputStream)
End If
txtLog.Width = 100%x
End Sub
Sub AStream_NewData (Buffer() As Byte)
'myBuffer = myBuffer & LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
'ticksOfInactivity=0
' timerstreams.enabled=True
LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
'If Buffer.Length >= 6 Then
'myBuffer = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
'LogMessage("You",myBuffer)
'End If
End Sub
Sub AStream_Error
ToastMessageShow("Connection is broken.", True)
btnSend.Enabled = False
txtInput.Enabled = False
End Sub
Sub AStream_Terminated
AStream_Error
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
AStream.Close
End If
End Sub
Sub txtInput_EnterPressed
If btnSend.Enabled = True Then btnSend_Click
End Sub
Sub btnSend_Click
AStream.Write(txtInput.Text.GetBytes("UTF8"))
txtInput.SelectAll
txtInput.RequestFocus
LogMessage("Me", txtInput.Text)
End Sub
Sub LogMessage(From As String, Msg As String)
txtLog.Text = txtLog.Text & From & ": " & Msg & CRLF
txtLog.SelectionStart = txtLog.Text.Length
End Sub