I am using a timer to trigger my program to send a byte out on the usb port. This byte causes a datastream to be sent back from a microprocessor which is then displayed on the screen. It works fine when I do it manually via a Button_Click but if I replace the button click with a Timer1_Tick, It sends out the single byte (once a second) but Astreams_NewData does not fire up until I disable the timer externally using another Button_Click. The data is definitely being sent in both directions. It seems that the Timer1_Tick subroutine is blocking the Astreams_NewData. Please can you help?
Here is an extract from my code
Here is an extract from my code
B4X:
Sub Process_Globals
Dim Timer1 As Timer
Dim astreams As AsyncStreams
Dim Scan As Boolean : Scan = False
End Sub
Sub Globals
Dim Ux0 As Float
Dim Ux1 As Float
Dim Uy0 As Float
Dim Uy1 As Float
Dim Ud As Float
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Timer1.Initialize("Timer1",1000)
StartUSB
astreams.Initialize(usb.GetInputStream, usb.GetOutputStream, "astreams")
End If
Timer1_Tick
End Sub
Sub Timer1_Tick
Trigger_Stream
End Sub
Sub Trigger_Stream 'send a byte to usb to trigger datastream
Ux0=GridX0
Ud =GridW/100
Ux1=GridX0+Ud
Message="U"
astreams.Write(Message.GetBytes("UTF8"))
End Sub
Sub Button5_Click 'enable and disable timer1
If Scan Then
Scan=False
Timer1.Enable=False
Else
Scan=True
Timer1.Enable=True
End If
End Sub
Sub Button6_Click 'send a byte to usb to trigger datastream
Trigger_Stream
End Sub
Sub Astreams_NewData (Buffer() As Byte)
.....................................................................
.....................................................................
For y = 0 To Buffer.Length -1
Uy1 = Buffer(y)
cvsGraph.DrawLine(Ux0, Uy0, Ux1, Uy1, Colors.Green, 2)
Ux0 = Ux1
Ux1 = Ux1 + Ud
Uy0 = Uy1
End If
.....................................................................
.....................................................................
End Sub