B4R Question HX711 inline C error

Discussion in 'B4R Questions' started by Mostez, May 3, 2017.

  1. Mostez

    Mostez Active Member

    I'm trying to include HX711 library into inline C code, but I get this error, any suggestions?, Main and HX711 module:

    Thanks

    Code:
    #Region Project Attributes
        
    #AutoFlushLogs: True
        
    #CheckArrayBounds: True
        
    #StackBufferSize: 300
    #End Region

    Sub Process_Globals
        
    Public Serial1 As Serial
    End Sub

    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("AppStart")
        HX711.Begin(
    16,17)
    End Sub
    Code:
    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'Public variables can be accessed from all modules.
        Private DataPin,CLKpin As Byte
       
    End Sub

    Public Sub Begin(sData As Byte , sCLK As Byte)
        DataPin = sData
        CLKpin = sCLK
        RunNative(
    "begin"Null)
    End Sub

    Public Sub Tare()
        RunNative(
    "tare"Null)
    End Sub


    #If C
    #include <HX711.h>
    void begin(B4R::Object* o) {HX711.begin(b4r_hx711::_datapin,b4r_hx711::_clkpin);}
    void tare(B4R::Object* o) {HX711.tare();}

    #End If

    B4R version: 1.80 BETA #2
    Parsing code. (0.00s)
    Compiling code. (0.01s)
    Building project (0.01s)
    Compiling & deploying Ino project (Arduino/Genuino Mega or Mega 2560 - COM35) Error
    Loading configuration...
    Initializing packages...
    Preparing boards...
    Verifying...
    sketch\b4r_hx711.cpp: In function 'void begin(B4R::Object*)':
    b4r_hx711.cpp:9: error: expected unqualified-id before '.' token
    void begin(B4R::Object* o) {HX711.begin(b4r_hx711::_datapin,b4r_hx711::_clkpin);}
    ^
    sketch\b4r_hx711.cpp: In function 'void tare(B4R::Object*)':
    b4r_hx711.cpp:10: error: expected unqualified-id before '.' token
    void tare(B4R::Object* o) {HX711.tare();}
    ^
    exit status 1
     
  2. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi,

    seems HX711 object is not declared in InlineC code - see the examples of the C library.
    This compiles - but can not test as do not have such a device:
    Code:
    #If C
    #include <HX711.h>

    HX711 scale;

    void begin(B4R::Object* o)
    {
        scale.begin(b4r_hx711::_datapin,b4r_hx711::_clkpin);
    }

    void tare(B4R::Object* o)
    {
        scale.tare();
    }
    #End If
     
  3. Mostez

    Mostez Active Member

    Thanks rwblinn, will try it
     
  4. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    So, the code worked for you?
     
  5. Mostez

    Mostez Active Member

    Yes Johan, it worked perfectly.
     
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