Sub Process_Globals
Dim usb As UsbSerial
Dim astreams As AsyncStreams
End Sub
Sub Globals
Dim btnSend, btnOpen, btnClose As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
btnClose.Enabled = False
btnSend.Enabled = False
End Sub
Sub btnOpen_Click
If usb.UsbPresent = usb.USB_NONE Then
Log("Msgbox - no device")
Msgbox("No USB device or accessory detected!", "Error")
Log("Msgbox - returned")
Return
End If
Log("Checking permission")
If (usb.HasPermission) Then
Msgbox(usb.DeviceInfo, "Device Information")
Dim dev As Int
dev = usb.Open(115200)
If dev <> usb.USB_NONE Then
Log("Connected successfully!")
btnOpen.Enabled = False
btnClose.Enabled = True
btnSend.Enabled = True
astreams.Initialize(usb.GetInputStream, usb.GetOutputStream, "astreams")
Else
Log("Error opening USB port")
End If
Else
usb.RequestPermission
End If
End Sub
Sub Astreams_NewData (Buffer() As Byte)
Log("NewData")
Log(BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
End Sub
Sub btnClose_Click
astreams.Close
btnOpen.Enabled = True
btnClose.Enabled = False
btnSend.Enabled = False
End Sub
Sub btnSend_Click
astreams.Write("abcde".GetBytes("UTF8"))
End Sub
Sub btnExit_Click
ExitApplication
End Sub
Sub AStreams_Error
Log("Error: " & LastException)
astreams.Close
End Sub
Sub Astreams_Terminated
Log("Terminated")
astreams.Close
End Sub