Dim bb As BytesBuilder
bb.Initialize
Do Until bb.Length >= 100
Wait For fel_DataAvailable (Buffer() As Byte)
bb.Append(Buffer)
Loop
Log("there are 100 bytes or more")
It depends on the event name that you set and what you are trying to do.This method I tried but stopped at the end
→ Wait For fel_DataAvailable (Buffer() As Byte)
Is it okay?
The code I posted was just a small example. I really don't know what you are trying to do. It is up to you to decide what to do if data is not arriving.How can I do it?
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private usbserial As felUsbSerial
Private manager As UsbManager
Private r_id As Int = 0x6001
Private r_vd As Int = 0x403
Private Button1 As Button
Private Timer1 As Timer
Private Button2 As Button
Private TimerOutSec As Int
Private bbL As List
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Main")
manager.Initialize
Timer1.Initialize("Timer1",1)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
U.Connect
End Sub
Sub Button1_Click
Dim UsbAccessory() As UsbAccessory = manager.GetAccessories
Dim UsbDevices() As UsbDevice = manager.GetDevices
If UsbDevices.Length = 0 Then
ToastMessageShow("No connected usb devices.", True)
Else
For z = 0 To UsbDevices.Length - 1
Dim UsbDvc As UsbDevice
UsbDvc = UsbDevices(z)
If (UsbDvc.ProductId = r_id) And (UsbDvc.VendorId = r_vd) Then
If manager.HasPermission(UsbDvc) = False Then
manager.RequestPermission(UsbDvc)
Log(manager.USB_CLASS_HUB)
Else
usbserial.Initialize("serial", UsbDvc, -1)
usbserial.BaudRate = 57600
usbserial.Parity = usbserial.PARITY_NONE
usbserial.DataBits = usbserial.DATA_BITS_8
usbserial.StopBits = usbserial.STOP_BITS_1
usbserial.StartReading
End If
End If
Next
End If
End Sub
Sub Button2_Click
TimerOutSec = 500
bbL.Initialize
Dim SendByte() as byte
usbserial.Write(SendByte)
SecondSub
Wait For SecondSub_Complete ' ←Start again here
If bbL.Size > 0 Then
Dim bc As BytesBuilder
'↓Processing data
For i = 0 To bbL.Size - 1
Log(bc.HexFromBytes(bbL.Get(i)))
Next
'↑Processing data
End If
End Sub
Sub SecondSub
Timer1.Enabled = True
Do While True
Wait For (usbserial) serial_DataAvailable (Buffer() As Byte) '←This code cannot leave this loop
bbL.Add(Buffer)
TimerOutSec = 500
Loop
End Sub
Sub Timer1_Tick
TimerOutSec = TimerOutSec - 1
If TimerOutSec <= 0 Then
Timer1.Enabled = False
CallSubDelayed(Me, "SecondSub_Complete") '←Return to the main program "SecondSub_Complete"
End If
End Sub