Serial data event

FFMan

Member
Licensed User
Longtime User
If i have this code executing, it appears to stop firing of the astreams_newdata event:-

lngLock=DateTime.now
Do While blnNewRec=False
lblMsg.Text="Wait for lock " & DateTime.Time(DateTime.Now-lngLock).SubString(3)
DoEvents
Loop

if i comment out this code, data is processed as expected.

I thought based on a previous post that arriving serial data would be processed in parallel with other code that may be running ?

am i doing something wrong or expecting too much ?
 
Last edited:

ckoehn

Banned
DoEvents will not execute a sub in your program. It apparently only runs waiting system events (my way of looking at it). In the loop you will have to call the sub yourself and then check if there actually is new data available.

I ran into the same thing with B4PPC. If I'm wrong, I'm sure I'll be corrected! :)
Later,
Clint
 
Upvote 0

FFMan

Member
Licensed User
Longtime User
> The data is sent or received in parallel.
so by this do you mean that data can be received by the OS and buffered and it does not matter that data is not from removed the queue immediately ? If this is the case how big is the buffer for serial bluetooth and can it be altered ?

> However the event is raised in the main thread.
so when would the code be executed. are you saying the event will only execute if there is currently no code running (unlike VB that will fire the event regardless of what is running).

> You should not create such loops.

should i consider using a timer instead to process the incoming data. Will a timer event fire regardless of what code is running ? If not, should I consider starting another thread to process incoming data so I can maintain a user interface at the same time ?

I need to get this fundamental piece of design right before i continue.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
AsyncStreams uses two background threads. One thread is reading the incoming data and the other is writing sent data (when such is available).

Whenever new data is read a message is sent to the main thread message queue with a reference to the data. This queue is not limited.

When the main thread is free to handle the message queue, the NewData event is raised. This is a bit similar to Timer behavior. Timers also work by sending messages to the main thread message loop.
 
Upvote 0

FFMan

Member
Licensed User
Longtime User
so if i use the main thread to maintain the user interface, can i just periodically check for and remove data from the queue ? does it matter that the newdata event will not fire ?

is there a way for seeing how many characters are in the incoming queue ?

thanks
 
Upvote 0
Top