Android Question Optional Bluetooth connected device

HarryCor

New Member
Licensed User
Longtime User
I’ve been developing a system, using B4A, which is measuring a subject’s responses to various visual stimuli. The program runs on a phone and there may or may not be a related tablet to which the phone is connected by BlueTooth. The tablet, if present, may be used only for control by the person running the test or it may be used by the subject to give responses via touch or it may be used for both purposes. Alternatively, the whole test may be carried out on the phone without a connected tablet in which case the subject responds via touch on the phone.

I would like to thank Anywhere Software for the support that they and other users give through the documentation and the forum. Almost every question which I have had has been answered already on the forum.

I have come across one specific area which will be understood by many users but I didn’t find it mentioned on the forum.

My original software was developed to use a BT linked phone and tablet. When I decided to make a version which ran on an isolated phone, my first thought was to write a new program for the phone but I realised that it was better to have a program which could use a tablet if it was present but also operate independently on its own. Fortunately this is easy with B4A.

Once a BT connection is established, new data arriving in the phone from the tablet triggers an event like

Sub AStream_NewData (Buffer() As Byte)

Buffer() contains the message from the tablet. This is well documented in B4A literature and there are excellent examples on the forum.

I realised that, when my phone is operating without a tablet, all the functions which would be input from the tablet may be called from within the phone by loading a Byte array with the correct information and calling AStream_NewData(). For example,

Dim Bupher() As Byte

....

Bupher="XY,132,707".GetBytes("UTF8")

AStream_NewData(Bupher)

The command “XY,132,707” which the original program might have received from the tablet is ‘sent’ by code in the phone and used in exactly the same way.

I have found this very useful as I now have one program in the phone which works with or without a connected tablet.

At the start, the phone looks for a tablet to link to. If it finds a tablet then it uses it, otherwise operates independently.

Harry
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I realised that, when my phone is operating without a tablet, all the functions which would be input from the tablet may be called from within the phone by loading a Byte array with the correct information and calling AStream_NewData(). For example,
As you found out an event sub is a regular sub. Nothing special happens when you call AStream_NewData (except of the code being executed).
 
Upvote 0

HarryCor

New Member
Licensed User
Longtime User
I suppose it was just another one of the many pleasant surprises I’ve had while using B4A thanks to your efforts and those of your many expert supporters.

Best wishes and thanks

Harry
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…