B4R Question NewPing

Discussion in 'B4R Questions' started by Johan Schoeman, May 30, 2019.

  1. Johan Schoeman

    Johan Schoeman Expert Licensed User

    I am referring to @Erel's posting here:
    https://www.b4x.com/android/forum/threads/inline-c-c.65714/#post-456033

    When compiling the B4R project I get an error due to this line of code:
    Code:
    b4r_main::_us = sonar.ping_median(20,500);
    Code:
    Trying Ole32.dll
    Found library 
    'Ole32' at Ole32.dll
    Loading configuration...
    Initializing packages...
    Preparing boards...
    Verifying...
    C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-
    in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\----------2\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10805 -build-path C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin -warnings=null -prefs=build.path=C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\src\src.ino
    C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-
    in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\----------2\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10805 -build-path C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin -warnings=null -prefs=build.path=C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\src\src.ino
    Using board 
    'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
    Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
    Detecting libraries used...
    "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\src.ino.cpp" -o "nul"
    Using cached library dependencies 
    for file: C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\B4RArduino.cpp
    Using cached library dependencies 
    for file: C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\B4RCore.cpp
    Using cached library dependencies 
    for file: C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\B4RStream.cpp
    Using cached library dependencies 
    for file: C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\Scheduler.cpp
    "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\b4r_main.cpp" -o "nul"
    "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\NewPing\src" "C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\b4r_main.cpp" -o "nul"
    Using cached library dependencies 
    for file: C:\Program Files (x86)\Arduino\libraries\NewPing\src\NewPing.cpp
    Generating function prototypes...
    "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\NewPing\src" "C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\src.ino.cpp" -o "C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\preproc\ctags_target_for_gcc_minus_e.cpp"
    "C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\preproc\ctags_target_for_gcc_minus_e.cpp"
    Compiling sketch...
    Using previously compiled 
    file: C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\B4RArduino.cpp.o
    Using previously compiled 
    file: C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\B4RCore.cpp.o
    Using previously compiled 
    file: C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\B4RStream.cpp.o
    Using previously compiled 
    file: C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\Scheduler.cpp.o
    "C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os  -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\libraries\NewPing\src" "C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\b4r_main.cpp" -o "C:\Users\------~1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\b4r_main.cpp.o"
    C:\Users\------~
    1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\b4r_main.cpp: In function 'void read_cm(B4R::Object*)':
    b4r_main.cpp:28: error: request for member 'ping_median' in 'sonar', which is of pointer type 'NewPing*' (maybe you meant to use '->' ?)
       b4r_main::_us = sonar.ping_median(20,500);
                             ^
    Using library NewPing at version 
    1.9.1 in folder: C:\Program Files (x86)\Arduino\libraries\NewPing
    exit status 1
    Picked up _JAVA_OPTIONS: -Xmx512M
    Code:
    B4R Version: 2.60
    Parsing code.    (
    0.00s)
    Building folders structure.    (
    0.02s)
    Compiling code.    (
    0.01s)
    Building project    (
    0.04s)
    Compiling & deploying Ino project (Arduino/Genuino Uno - COM39)    Error
    Loading configuration...
    Initializing packages...
    Preparing boards...
    Verifying...
    C:\Users\------~
    1\DOCUME~1\B4R\B4RNEW~1\Objects\bin\sketch\b4r_main.cpp: In function 'void read_cm(B4R::Object*)':
    b4r_main.cpp:28: error: request for member 'ping_median' in 'sonar', which is of pointer type 'NewPing*' (maybe you meant to use '->' ?)
       b4r_main::_us = sonar.ping_median(20,500);
                             ^
    exit status 1
    Picked up _JAVA_OPTIONS: -Xmx512M
    If I change....
    Code:
    b4r_main::_us = sonar.ping_median(20,500);
    ....to....
    Code:
    b4r_main::_us = sonar->ping_median(20,500);
    thus, sonar.ping_median replace with sonar->ping_median

    ....it is working. Can it be because I am maybe making using of a different NewPing Arduino library as what @Erel's sample code is based on?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is a mistake in the code. I took the code from the post above and fixed one of the lines and missed the previous one (see the comment).
     
    Johan Schoeman likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice