Conditional compilation or equivalent?

positrom2

Active Member
Licensed User
Longtime User
Hi,
I use a B4A program to wirelessly communicate with a microcontroller. I am using three different communication methods, depending on the demands: Bluetooth connection and WiFi via TCP, either local or via the internet. So, I have three versions that shall do all the same with the transmitted data. The problem is how to "synchronize" the changes I am doing on the data evaluation code (of course first done in one of the three versions). Unfortunately, the initializations for those different transmission methods are somehow scattered between some subroutines and definitions.

It would be a big help if there were some kind on conditional compilation to have just one data evaluation code and steering the compilation based on one parameter to choose which communication methods is to be used.
Could anyone suggest a solution?
Thanks, positrom2
 

fared15

Member
Licensed User
Longtime User
can u post ur project to communicate with micro-controller i was wondering to start it but wish if i have some good code base to start
 
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
Erel,
thanks for the reply and recommending first the use of regular conditions. However, there is a subroutine "Sub sock_connected(constatus As Boolean)" which has to be erased for BT connection. I think that is not possible with regular conditions. Below you could see how I am doing the selection right now, manually. I put comment lines into the code with the meaning that depending on the chosen variant the code between pairs of lines ''Outcomment for (here BT, or WiFi local, or WiFi internet)"
shall be outcommented.
B4X:
Sub Globals
...
Dim matrix(10,3) As Int
   Dim lblLog As Label,smb1 As SMB
'Outcomment for BT
   End Sub '<--------------------------Deleting the following sub
Sub sock_connected(constatus As Boolean)
   If constatus = True Then
      Msgbox("Connection Successful","")
      'Out=clientsock.OutputStream
      'inp=clientsock.InputStream
      verbunden = True
      
      Timer1.Enabled = True'
      meinEinBuffer.Initialize(clientsock.InputStream)
      meinAusBuffer.Initialize(clientsock.OutputStream)
      
      'senden
    Else
       Msgbox(LastException.Message, "Error connecting")
   End If   
'Outcomment for BT
End Sub


Classes I am not familiar with (?"a class is a construct that is used to create instances of itself" ?, first sentence in Wikepedia) - and if there were more common solutions I would prefer those...
Would it be possible to put the different initialisations and the common data evaluation code in separate modules like those shown as side-tabs in the IDE (I could not find the name of those modules) and loading the initialisations depending on the chosen connection variant?
Regards, positrom2
 
Upvote 0
Top