B4R Question How to define in B4R a conditional switch

tigrot

Well-Known Member
Licensed User
Longtime User
Uso il file precedentemente compilato: C:\MIEIFI~1\COELME~1\arduino\DATALO~1.3\Objects\bin\sketch\B4RCore.cpp.o
Uso il file precedentemente compilato: C:\MIEIFI~1\COELME~1\arduino\DATALO~1.3\Objects\bin\sketch\B4RSerializator.cpp.o
Uso il file precedentemente compilato: C:\MIEIFI~1\COELME~1\arduino\DATALO~1.3\Objects\bin\sketch\B4RStream.cpp.o
Uso il file precedentemente compilato: C:\MIEIFI~1\COELME~1\arduino\DATALO~1.3\Objects\bin\sketch\ByteConverter.cpp.o
Uso il file precedentemente compilato: C:\MIEIFI~1\COELME~1\arduino\DATALO~1.3\Objects\bin\sketch\RandomAccessFile.cpp.o
Uso il file precedentemente compilato: C:\MIEIFI~1\COELME~1\arduino\DATALO~1.3\Objects\bin\sketch\Scheduler.cpp.o
Uso il file precedentemente compilato: C:\MIEIFI~1\COELME~1\arduino\DATALO~1.3\Objects\bin\sketch\b4r_comunica.cpp.o
Uso il file precedentemente compilato: C:\MIEIFI~1\COELME~1\arduino\DATALO~1.3\Objects\bin\sketch\b4r_globalstore.cpp.o
Uso il file precedentemente compilato: C:\MIEIFI~1\COELME~1\arduino\DATALO~1.3\Objects\bin\sketch\b4r_main.cpp.o
Uso il file precedentemente compilato: C:\MIEIFI~1\COELME~1\arduino\DATALO~1.3\Objects\bin\sketch\b4r_queue.cpp.o
"C:\arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10801 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\arduino\hardware\arduino\avr\cores\arduino" "-IC:\arduino\hardware\arduino\avr\variants\mega" "-IC:\arduino\hardware\arduino\avr\libraries\SPI\src" "-IC:\arduino\libraries\SD\src" "-IC:\arduino\libraries\LiquidCrystal\src" "-IC:\Users\hp\Documents\Arduino\libraries\RTClib-master" "-IC:\arduino\hardware\arduino\avr\libraries\Wire\src" "C:\MIEIFI~1\COELME~1\arduino\DATALO~1.3\Objects\bin\sketch\b4r_statica.cpp" -o "C:\MIEIFI~1\COELME~1\arduino\DATALO~1.3\Objects\bin\sketch\b4r_statica.cpp.o"
b4r_statica.cpp:242: error: unterminated #if
#if francese
^
b4r_statica.cpp:184: error: unterminated #if
#if italiano
^
Uso la libreria SPI alla versione 1.0 nella cartella: C:\arduino\hardware\arduino\avr\libraries\SPI
Uso la libreria SD alla versione 1.1.1 nella cartella: C:\arduino\libraries\SD
Uso la libreria LiquidCrystal alla versione 1.0.5 nella cartella: C:\arduino\libraries\LiquidCrystal
Uso la libreria RTClib-master alla versione 1.2.1 nella cartella: C:\Users\hp\Documents\Arduino\libraries\RTClib-master
Uso la libreria Wire alla versione 1.0 nella cartella: C:\arduino\hardware\arduino\avr\libraries\Wire
exit status 1

I get this lines for this code:
B4X:
#if italiano
const char string_1[] PROGMEM = "R1=SCHEDA DI TARATURA";
const char string_2[] PROGMEM = "R1A=Generata il:";
const char string_3[] PROGMEM = "R1B=Ore:";
const char string_4[] PROGMEM = "R2=Parametri generali:";
const char string_5[] PROGMEM = "R3=Prodotto in uso           :";
const char string_6[] PROGMEM = "R4=Fotocellula               :";
const char string_7[] PROGMEM = "R5=Reset manuale             :";
const char string_8[] PROGMEM = "R6=Tempo di oscuramento      :";
const char string_9[] PROGMEM = "R7=Stop su errore            :";
const char string_10[] PROGMEM = "R8=Tempo stabilizzazione     :";
const char string_11[] PROGMEM = "R9=Timeout fotocellula       :";
const char string_12[] PROGMEM = "R10=Errore mancata espulsione :";
const char string_13[] PROGMEM = "R11=Tempo sincronismo contatti:";
const char string_14[] PROGMEM = "R12=Inserita";
const char string_15[] PROGMEM = "R13=Disinserita";
const char string_16[] PROGMEM = "R14=Inserito";
const char string_17[] PROGMEM = "R15=Disinserito";
const char string_18[] PROGMEM = "PP1=Parametri prodotto : ";
const char string_19[] PROGMEM = "PP2=Nome:";
const char string_20[] PROGMEM = "PP3=Programma N.        :";
const char string_21[] PROGMEM = "PP4=Sensibilità canale 1:";
const char string_22[] PROGMEM = "PP5=Sensibilità canale 2:";
const char string_23[] PROGMEM = "PP6=Velocità intercett. :";
const char string_24[] PROGMEM = "PP7=Cadenza massima     :";
const char string_25[] PROGMEM = "PP8=Ritardo espulsione  :";
const char string_26[] PROGMEM = "PP9=Durata espulsione   :";
const char string_27[] PROGMEM = "PP10=******* Termine scheda di taratura *******";
const char string_28[] PROGMEM = "DR1=REPORT DEL GIORNO: ";
const char string_29[] PROGMEM = "DR2=ORA        EVENTO";
const char string_30[] PROGMEM = "DR3=&******** Fine Monitoraggio **********";
const char string_31[] PROGMEM = "DR4=SEGNALAZIONE ERRORI";
const char string_32[] PROGMEM = "ERS=&Dispositivo spento-";
const char string_33[] PROGMEM = "ER0=Start monitor-";
const char string_34[] PROGMEM = "ER1=Errore di formato ";
const char string_35[] PROGMEM = "ER2=Entra in programmazione ";
const char string_36[] PROGMEM = "ER3=Canali rumorosi ";
const char string_37[] PROGMEM = "ER4=^Metalim ready ";
const char string_38[] PROGMEM = "ER5=Programmazione remota ";
const char string_39[] PROGMEM = "ER6=Selezionato prodotto N.";
const char string_40[] PROGMEM = "ER7=In aggiornamento";
const char string_41[] PROGMEM = "ER8=Lettura prodotto aggiornato N.";
const char string_42[] PROGMEM = "ER9=Generata nuova scheda di taratura ";
const char string_43[] PROGMEM = "ER10=Aggiornata la scheda di taratura";
const char string_44[] PROGMEM = "ER11=Test periodico ";
const char string_45[] PROGMEM = "ER12=Accesso da terminale- ";
const char string_46[] PROGMEM = "ER13=^Fine programmazione da terminale- ";
const char string_47[] PROGMEM = "ER13A=Uscito da terminale senza modifiche";
const char string_48[] PROGMEM = "ER14=!Allarmi N.:";
const char string_49[] PROGMEM = "ER15=Totale allarmi:";
const char string_50[] PROGMEM = "TP1=Totali per prodotto";
const char string_51[] PROGMEM = "TP2=Prodotto N. ";
const char string_52[] PROGMEM = "TP3=Nome: ";
const char string_53[] PROGMEM = "TP4=Allarmi : ";
const char string_54[] PROGMEM = "TP5= Pezzi prodotti: ";
const char string_55[] PROGMEM = "TP6= Totale allarmi del giorno";
#End if

#if francese
const char string_1[] PROGMEM = "R1=CARTE D'ÉTALONNAGE ";
const char string_2[] PROGMEM = "R1A=Généré:";
const char string_3[] PROGMEM = "R1B=Heures:";
const char string_4[] PROGMEM = "R2=Paramètres généraux:";
const char string_5[] PROGMEM = "R3=Produit utilisé           :";
const char string_6[] PROGMEM = "R4=Photocellule              :";
const char string_7[] PROGMEM = "R5=Réinitialisation manuelle :";
const char string_8[] PROGMEM = "R6=Assombrissement           :";
const char string_9[] PROGMEM = "R7=Arrêt sur erreur          :";
const char string_10[] PROGMEM = "R8=Temps de stabilisation    :";
const char string_11[] PROGMEM = "R9=Temps mort photocellule   :";
const char string_12[] PROGMEM = "R10=Erreur non éjectée        :";
const char string_13[] PROGMEM = "R11=Temps synchronisation     :";
const char string_14[] PROGMEM = "R12=Ajouté ";
const char string_15[] PROGMEM = "R13=Eteint ";
const char string_16[] PROGMEM = "R14=Ajoutée ";
const char string_17[] PROGMEM = "R15=Eteint ";
const char string_18[] PROGMEM = "PP1=Paramètres produit :";
const char string_19[] PROGMEM = "PP2=Nom :";
const char string_20[] PROGMEM = "PP3=Programme N.        :";
const char string_21[] PROGMEM = "PP4=Sensibilité canal 1 :";
const char string_22[] PROGMEM = "PP5=Sensibilité canal 2 :";
const char string_23[] PROGMEM = "PP6=Vitesse interception:";
const char string_24[] PROGMEM = "PP7=Cadence maximale    :";
const char string_25[] PROGMEM = "PP8=Délai d'expulsion   :";
const char string_26[] PROGMEM = "PP9=Durée expulsion     :";
const char string_27[] PROGMEM = "PP10=*******  Carte d'étalonnage Terme  *******";
const char string_28[] PROGMEM = "DR1=RAPPORT DU JOUR  :";
const char string_29[] PROGMEM = "DR2=TEMPS   EVENEMENT ";
const char string_30[] PROGMEM = "DR3=&********Surveillance de fin**********";
const char string_31[] PROGMEM = "DR4=SIGNALISATION D'ERREUR ";
const char string_32[] PROGMEM = "ERS=&Appareil éteint   -";
const char string_33[] PROGMEM = "ER0=Démarrer moniteur -";
const char string_34[] PROGMEM = "ER1=Erreur de format ";
const char string_35[] PROGMEM = "ER2=Entrez la programmation";
const char string_36[] PROGMEM = "ER3=Canaux bruyants ";
const char string_37[] PROGMEM = "ER4=^Metalim prêt ";
const char string_38[] PROGMEM = "ER5=Programmation à distance ";
const char string_39[] PROGMEM = "ER6=Produit sélectionné N.";
const char string_40[] PROGMEM = "ER7=En mise à jour ";
const char string_41[] PROGMEM = "ER8=Lecture du produit mis à jour N.";
const char string_42[] PROGMEM = "ER9=Généré nouvelle carte d'étalonnage ";
const char string_43[] PROGMEM = "ER10=Carte d’ètalonnage mise à jour ";
const char string_44[] PROGMEM = "ER11=Test périodique ";
const char string_45[] PROGMEM = "ER12=Accès depuis le terminal-";
const char string_46[] PROGMEM = "ER13=^Fin de programmation depuis le terminal-";
const char string_47[] PROGMEM = "ER13A= Sortie du terminal sans modification ";
const char string_48[] PROGMEM = "ER14=!Alarmes N°:";
const char string_49[] PROGMEM = "ER15=Alarmes totales:";
const char string_50[] PROGMEM = "TP1=Totaux par produit";
const char string_51[] PROGMEM = "TP2=Produit N°";
const char string_52[] PROGMEM = "TP3=Nom: ";
const char string_53[] PROGMEM = "TP4= Alarmes : ";
const char string_54[] PROGMEM = "TP5= Piéces produites: ";
const char string_55[] PROGMEM = "TP6= Total des alarmes du jour ";
#End if
 
Upvote 0

thetahsk

Active Member
Licensed User
Longtime User

Use the preprocessor directives for conditional compilation.

B4R:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Private Result As Int 'ignore
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    RunNative("Function", Null)
    Log("Result: ", Result)
End Sub

#if C

#define def_2
// #define def_1
#ifdef def_1
void Function (B4R::Object* o) {b4r_main::_result = 1;}
#endif
#ifdef def_2
void Function (B4R::Object* o) {b4r_main::_result = 2;}
#endif
#End if
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
Use the preprocessor directives for conditional compilation.

B4R:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Private Result As Int 'ignore
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    RunNative("Function", Null)
    Log("Result: ", Result)
End Sub

#if C

#define def_2
// #define def_1
#ifdef def_1
void Function (B4R::Object* o) {b4r_main::_result = 1;}
#endif
#ifdef def_2
void Function (B4R::Object* o) {b4r_main::_result = 2;}
#endif
#End if
Thank you. will try tomorrow. I've tried according to Arduino C syntax, with no success...
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
Use the preprocessor directives for conditional compilation.

B4R:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Private Result As Int 'ignore
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    RunNative("Function", Null)
    Log("Result: ", Result)
End Sub

#if C

#define def_2
// #define def_1
#ifdef def_1
void Function (B4R::Object* o) {b4r_main::_result = 1;}
#endif
#ifdef def_2
void Function (B4R::Object* o) {b4r_main::_result = 2;}
#endif
#End if
It works. I don't know how many tries with syntax I have done ! Thank you thetahsk!
 
Upvote 0

thetahsk

Active Member
Licensed User
Longtime User
Just so that I can understand - why is #define def_1 commented out above? What will happen if #define def_1 is uncommented?

You see that the inline C calling functions have both the same name , but returns different values.
So you can decide which function to use.
If both def_1 and def_2 are defined, the compiler didn't know which function to use and creates a redefinition error.
 
Upvote 0
Top