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(1) = usb.USB_NONE Then
MsgboxAsync("Msgbox - no device","No Device")
Log("No USB device or accessory detected!")
Log("Msgbox - returned")
Return
End If
Log("Checking permission")
If (usb.HasPermission(1)) Then
MsgboxAsync(usb.DeviceInfo(1),"Permission")
Dim dev As Int
dev = usb.Open(115200, 1)
If dev <> usb.USB_NONE Then
MsgboxAsync("Connected successfully!","Success")
btnOpen.Enabled = False
btnClose.Enabled = True
btnSend.Enabled = True
astreams.Initialize(usb.GetInputStream, usb.GetOutputStream, "astreams")
Else
MsgboxAsync("Error opening USB port","Bad")
End If
Else
usb.RequestPermission(1)
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
MsgboxAsync("Error: " & LastException,"Error Astreams")
astreams.Close
End Sub
Sub Astreams_Terminated
MsgboxAsync("Terminated","Error Terminated")
astreams.Close
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub