Hello
The following is that I use this code to catch USB Serial data, originally due to the need to receive at least 125 seconds of data, but I can only receive four data.
My USB Seria specification
Baud Rate : 19200
DataBits : 8
#Region Project Attributes
#ApplicationLabel: USB Serial Example
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: false
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Dim usb As UsbSerial
Dim astreams As AsyncStreams
Dim bc As ByteConverter
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(19200)
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(Buffer(0))
End Sub
Sub btnClose_Click
astreams.Close
btnOpen.Enabled = True
btnClose.Enabled = False
btnSend.Enabled = False
End Sub
The following is that I use this code to catch USB Serial data, originally due to the need to receive at least 125 seconds of data, but I can only receive four data.
My USB Seria specification
Baud Rate : 19200
DataBits : 8
#Region Project Attributes
#ApplicationLabel: USB Serial Example
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: false
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Dim usb As UsbSerial
Dim astreams As AsyncStreams
Dim bc As ByteConverter
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(19200)
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(Buffer(0))
End Sub
Sub btnClose_Click
astreams.Close
btnOpen.Enabled = True
btnClose.Enabled = False
btnSend.Enabled = False
End Sub