B4R Question 'pnt' is not a member of 'b4r_serialoscilloscope'

hatzisn

Well-Known Member
Licensed User
Longtime User
Good evening everyone,

I am trying to build a b4xlib that will log values to the Serial Oscilloscope as described in this thread:



Here is the code:


SerialOscilloscope Code Module:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Dim NumOfCHs As Int
End Sub

Sub Initialize(NumOfChannelsUpTo6 As Int)
    NumOfCHs = NumOfChannelsUpTo6
    RunNative("stpanalogpins", NumOfChannelsUpTo6)
End Sub

Sub LogChannels()
    RunNative("chlg", Null)
End Sub




#if c
#include <stdlib.h> // div, div_t

void stpanalogpins(B4R::Object* o) {

    int numchan = b4r_serialoscilloscope::_numofchs;

    // Enable pull-ups to avoid floating inputs
    if (numchan>=1) digitalWrite(A0, HIGH);
    if (numchan>=2) digitalWrite(A1, HIGH);
    if (numchan>=3) digitalWrite(A2, HIGH);
    if (numchan>=4) digitalWrite(A3, HIGH);
    if (numchan>=5) digitalWrite(A6, HIGH);
    if (numchan=6) digitalWrite(A7, HIGH);

    // Init serial
    // Serial.begin(115200);
}



void chlg(B4R::Object* o){

    int numChans = b4r_serialoscilloscope::_numofchs;
    // Print ADC results for active channels
    b4r_serialoscilloscope::pnt(analogRead(A0));
    if(numChans > 1) {
        Serial.write(',');
        b4r_serialoscilloscope::pnt(analogRead(A1));
    }
    if(numChans > 2) {
        Serial.write(',');
        b4r_serialoscilloscope::pnt(analogRead(A2));
    }
    if(numChans > 3) {
        Serial.write(',');
        b4r_serialoscilloscope::pnt(analogRead(A3));
    }
    if(numChans > 4) {
        Serial.write(',');
        b4r_serialoscilloscope::pnt(analogRead(A6));
    }
    if(numChans > 5) {
        Serial.write(',');
        b4r_serialoscilloscope::pnt(analogRead(A7));
    }
    Serial.write('\r'); // print new line
}


// Fast int to ASCII conversion
void pnt(int i) {
    static const char asciiDigits[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
    div_t n;
    int print = 0;
    if(i < 0) {
        Serial.write('-');
        i = -i;
    }
    if(i >= 10000) {
        n = div(i, 10000);
        Serial.write(asciiDigits[n.quot]);
        i = n.rem;
        print = 1;
    }
    if(i >= 1000 || print) {
        n = div(i, 1000);
        Serial.write(asciiDigits[n.quot]);
        i = n.rem;
        print = 1;
    }
    if(i >= 100 || print) {
        n = div(i, 100);
        Serial.write(asciiDigits[n.quot]);
        i = n.rem;
        print = 1;
    }
    if(i >= 10 || print) {
        n = div(i, 10);
        Serial.write(asciiDigits[n.quot]);
        i = n.rem;
    }
    Serial.write(asciiDigits[i]);
}
#End If



I know I could have done it a lot easier but for the shake of practicing I choosed this way.
I get this error for a reason that I am not able to see right now. Can anyone see it? Here is the error:

Using previously compiled file: C:\B4X\MyCode\B4R\MyCode\EMPTYB~1\Objects\bin\sketch\B4RArduino.cpp.o
Using previously compiled file: C:\B4X\MyCode\B4R\MyCode\EMPTYB~1\Objects\bin\sketch\B4RCore.cpp.o
Using previously compiled file: C:\B4X\MyCode\B4R\MyCode\EMPTYB~1\Objects\bin\sketch\B4RStream.cpp.o
Using previously compiled file: C:\B4X\MyCode\B4R\MyCode\EMPTYB~1\Objects\bin\sketch\b4r_main.cpp.o
"C:\\B4X\\Tools\\B4R\\arduino-1.8.13\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\B4X\\Tools\\B4R\\arduino-1.8.13\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\B4X\\Tools\\B4R\\arduino-1.8.13\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "C:\\B4X\\MyCode\\B4R\\MyCode\\EMPTYB~1\\Objects\\bin\\sketch\\b4r_serialoscilloscope.cpp" -o "C:\\B4X\\MyCode\\B4R\\MyCode\\EMPTYB~1\\Objects\\bin\\sketch\\b4r_serialoscilloscope.cpp.o"
"C:\\B4X\\Tools\\B4R\\arduino-1.8.13\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR "-IC:\\B4X\\Tools\\B4R\\arduino-1.8.13\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\B4X\\Tools\\B4R\\arduino-1.8.13\\hardware\\arduino\\avr\\variants\\eightanaloginputs" "C:\\B4X\\MyCode\\B4R\\MyCode\\EMPTYB~1\\Objects\\bin\\sketch\\src.ino.cpp" -o "C:\\B4X\\MyCode\\B4R\\MyCode\\EMPTYB~1\\Objects\\bin\\sketch\\src.ino.cpp.o"
C:\B4X\MyCode\B4R\MyCode\EMPTYB~1\Objects\bin\sketch\b4r_serialoscilloscope.cpp: In function 'void chlg(B4R::Object*)':
b4r_serialoscilloscope.cpp:31:29: error: 'pnt' is not a member of 'b4r_serialoscilloscope'
b4r_serialoscilloscope::pnt(analogRead(A0));
^~~
b4r_serialoscilloscope.cpp:34:33: error: 'pnt' is not a member of 'b4r_serialoscilloscope'
b4r_serialoscilloscope::pnt(analogRead(A1));
^~~
b4r_serialoscilloscope.cpp:38:33: error: 'pnt' is not a member of 'b4r_serialoscilloscope'
b4r_serialoscilloscope::pnt(analogRead(A2));
^~~
b4r_serialoscilloscope.cpp:42:33: error: 'pnt' is not a member of 'b4r_serialoscilloscope'
b4r_serialoscilloscope::pnt(analogRead(A3));
^~~
b4r_serialoscilloscope.cpp:46:33: error: 'pnt' is not a member of 'b4r_serialoscilloscope'
b4r_serialoscilloscope::pnt(analogRead(A6));
^~~
b4r_serialoscilloscope.cpp:50:33: error: 'pnt' is not a member of 'b4r_serialoscilloscope'
b4r_serialoscilloscope::pnt(analogRead(A7));
^~~
exit status 1
DEBUG StatusLogger Stopping LoggerContext[name=1e6f5c3, org.apache.logging.log4j.core.LoggerContext@1afbe45]
DEBUG StatusLogger Stopping LoggerContext[name=1e6f5c3, org.apache.logging.log4j.core.LoggerContext@1afbe4

[/SPOILER]
 

Daestrum

Expert
Licensed User
Longtime User
Try moving the pnt function before the chlg function. As there is no .h file the compiler/linker doesn't know what pnt is when it gets to the
chlg function and tries to use it.
 
Last edited:
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
Thank you all for your answers.

@Daestrum I tried what you suggested and it did not work.

@thetahsk it is not the main module but instead this code is placed in a second module named SerialOscilloscope. I will try your solution too and let you know within the day. Thanks anyway.

For the time being I 've found a workaround and I uploaded the newly created module in the B4R Libraries sub-forum
 
Upvote 0
Top