Using AStreams in a service

lentunti

Member
Licensed User
Longtime User
Hi all,

I have a service that uses a Bluetooth serial connection and uses an AStream to receive data.

I am starting the service using StartServiceAt and setiing it 3 minutes in the future. I am them opening the serial connection and waiting for the AStream_NewData to receive the data. The problem is that I have to Stop the Service in order for it to restart. In doing this, it is stopping before the AStream receives and processes the data.

Am I going about this in the wrong manner?

Thanks for any help.

Regards
Lee
 

mc73

Well-Known Member
Licensed User
Longtime User
If sender is a device you program too, you can set it to send a "endMessage" message. This way, when you receive the "endMessage" you can safely destroy the service (after of course having processed your data). If you cannot send an "endMessage" you can initialize a timer and set it enabled inside the aStreams_newData sub. If a certain duration passes, this will mean that we don't receive new data for this period. This way, you can proceed with processing the received data and so on.
Finally, you can use the aStreams_terminated event, if it fires when your device is closing the communication (if it's closing it).
 
Upvote 0

lentunti

Member
Licensed User
Longtime User
Thank you for the response. The problem is that there might not be a any data sent which means that I cannot put any logic to end processing in the aStreams_newData routine. (It might not even get a serial_connection if it is out of range of the other Bluetooth device).

Again, thanks for any help.

Regards
Lee
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
The problem is that there might not be a any data sent which means that I cannot put any logic to end processing in the aStreams_newData routine. (It might not even get a serial_connection if it is out of range of the other Bluetooth device).
In that case you can have a timer enabled at the connection event if it is successful. Then, in your astreams_newdata you can disable this timer, otherwise once your timer reaches a certain limit, you can close the connection.
Also, in case of no connection, the successful flag of the connection will be false.
 
Upvote 0

BluSky76

Member
Licensed User
Longtime User
Hi,

you know a way to send upiù consecutive commands with pressing a button:

astreams.Write ("First". GetBytes ("UTF8"))

read or wait for an answer and then

astreams.Write ("Second". GetBytes ("UTF8"))

I can only get the answer of the last command. I have to create a sequence of automatic submissions based on the response. Thanks
 
Upvote 0
Top