#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: YOYOUART
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: True
#End Region
'Activity module
'YOYO UART
Sub Process_Globals
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 period As Int
Dim TimerLoop As Timer
Dim TimerRX As Timer
Dim btnSend As Button
'Dim btnSetUp As Button
Dim Label1 As Label
Dim Label10 As Label
Dim Label3 As Label
Dim Label4 As Label
Dim Label5 As Label
Dim Label6 As Label
Dim Label7 As Label
Dim Label8 As Label
Dim Label9 As Label
Dim rbtn_loop As RadioButton
Dim rbtn_Single As RadioButton
Dim txtRX As EditText
Dim txtSend As EditText
'Dim PeriodMap As Map
Dim p_uart As Panel
Dim panel1 As Panel
Dim lbStatus As Label
Dim YOYO As IOIO
Dim led As DigitalOutput
Dim uart1 As Uart
Dim in1 As InputStream
Dim out1 As OutputStream
Dim go As Boolean
Dim LedFlag As Boolean
Dim looped As Boolean
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim panels(5) As Panel
Activity.LoadLayout("1")
Activity.Title="Tom's UART TEST"
If FirstTime Then
go=False
looped=False
rbtn_Single.Checked=True
YOYO.Initialize
YOYO.WaitForConnect()
TimerLoop.Initialize("TimerLoop",10)
TimerRX.Initialize("TimerRX",100)
led = YOYO.OpenDigitalOutput( 0,led.OP_NORMAL ,True) ' Enable LED_PIN for output
uart1= YOYO.OpenUart(3,uart1.IP_FLOATING,4,uart1.OP_NORMAL,9600,uart1.PARITY_NONE,uart1.STOPBIT_ONE)
in1=uart1.InputStream
out1=uart1.OutputStream
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub rbtn_Single_CheckedChange(Checked As Boolean)
If Checked Then
looped= False
End If
End Sub
Sub rbtn_loop_CheckedChange(Checked As Boolean)
If Checked Then
looped=True
End If
End Sub
Sub btnSetUp_Click()
If go=True Then
go=False
'btnSetUp.Text="SET/GO"
'btnSetUp.Background=black
TimerLoop.Enabled=False
TimerRX.Enabled=False
Else
go=True
'btnSetUp.Text="STOP"
uart1.Close
in1.Close
out1.Close
uart1= YOYO.OpenUart(3,uart1.IP_FLOATING,4,uart1.OP_NORMAL,9600,uart1.PARITY_NONE,uart1.STOPBIT_ONE)
in1=uart1.InputStream
out1=uart1.OutputStream
If rbtn_Single.Checked=False Then
TimerLoop.Initialize("TimerLoop",100)
TimerLoop.Enabled=True
End If
TimerRX.Enabled=True
Msgbox("READY TO GO","")
End If
End Sub
Sub btnSend_Click
'If rbtn_Single.Checked=True Then
If uart1.IsInitialized Then
'getSetUPValue
'uart1.Close
'IN1.Close
'OUT1.Close
'uart1= YOYO.OpenUart(RXPIN,RXPINTYPE,TXPIN,TXPINTYPE,BAUDRATE,uart1.PARITY_NONE,uart1.STOPBIT_ONE)
'in1=uart1.InputStream
'out1=uart1.OutputStream
If txtSend.Text.Length > 0 Then
Dim buffer() As Byte
Dim ST As String
ST=txtSend.Text & CRLF
buffer =ST.GetBytes("UTF8")
out1.WriteBytes(buffer,0,buffer.Length)
out1.Flush
txtSend.SelectAll
End If
End If
End Sub
Sub TimerLoop_Tick
If LedFlag= True Then
LedFlag=False
Else
LedFlag=True
End If
led.Write(LedFlag)
If rbtn_Single.Checked=False Then
If txtSend.Text.Length > 0 Then
Dim buffer() As Byte
Dim ST As String
ST=txtSend.Text & CRLF
buffer =ST.GetBytes("UTF8")
out1.WriteBytes(buffer,0,buffer.Length)
out1.Flush
txtSend.SelectAll
End If
End If
End Sub
Sub TimerRX_Tick()
If in1.BytesAvailable>0 Then
TimerRX.Enabled=False
'*** need to assign the exact buffer size as in BytesAvailable or it won't work
Dim buffer(in1.BytesAvailable) As Byte
Dim count As Int
count = in1.ReadBytes(buffer, 0,buffer.Length)
lbStatus.Text="Read " & count & " bytes. @ " & DateTime.Time(DateTime.Now)& " "& DateTime.Date(DateTime.Now)
txtRX.Text=BytesToString(buffer, 0, count, "UTF8")
End If
TimerRX.Enabled=True
End Sub