B4R Question Hardware Serial on ESP32

Discussion in 'B4R Questions' started by rodmcm, Sep 17, 2018.

  1. rodmcm

    rodmcm Member Licensed User

    I am using the following (Erel Tutorial) to access the second hardware serial on an ESP 32
    It will not compile
    In Arduino you have to define a hardware serial as

    HardwareSerial Serial2(2); // Second Hardware Port

    Is there something else that needs to be done in this snippet

    #if C
    void SerialNative2(B4R::Object* unused) {
    ::Serial2.begin(115200); //<--You can change the baud rate
    b4r_main::_serialnative1->wrappedStream = &::Serial2;
    }
    #end if
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can add this line to the inline code:
    Code:
    HardwareSerial Serial2(2); // Second Hardware Port
     
  3. rodmcm

    rodmcm Member Licensed User

    Yes tried that already ( along with several variations)
    Error codes

    b4r_main.cpp:12: error: missing terminating ' character
    Hardware Serial2 (2); '
    ^
    b4r_main.cpp:12: error: 'Hardware' does not name a type
    C:\RODSFI~1\RODSPL~1\RODTOO~1\B4A\RODSRP~1\Objects\bin\sketch\b4r_main.cpp: In function 'void SerialNative2(B4R::Object*)':
    b4r_main.cpp:15: error: '::Serial2' has not been declared
    ::Serial2.begin(115200);
    ^
    b4r_main.cpp:16: error: '::Serial2' has not been declared
    b4r_main::_serialnative2->wrappedStream = &::Serial2;
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the code?
     
  5. rodmcm

    rodmcm Member Licensed User

    Enclosed
     

    Attached Files:

  6. Erel

    Erel Administrator Staff Member Licensed User

    Correct code:
    Code:
    #if C
    HardwareSerial Serial2(2); // Second Hardware Port
    void SerialNative2(B4R::Object* unused)
    {
    ::Serial2.begin(115200);
    b4r_main::_serialnative2->wrappedStream = &::Serial2;
    }
    #End If
    Don't add any single quote or space.
     
    janderkan and Johan Hormaza like this.
  7. rodmcm

    rodmcm Member Licensed User

    Thanks Erel.. Works fine
    Perhaps this fix could be added to your original tutorial on multiple hardware connections
     
  8. Blueforcer

    Blueforcer Active Member Licensed User

    I treid your snippet but it doesnt compile:
    What ive done wrong?
    here is my very short test code:

    Code:
    Sub Process_Globals
        
    Public Serial1 As Serial
        
    Private SerialNative2 As Stream
    End Sub

    Private Sub AppStart
        Serial1.Initialize(
    115200)
        RunNative(
    "SerialNative2"Null)
    End Sub

    Sub astream_NewData
        
    End Sub

    Sub astream_Error
        
    End Sub

    #if C
    HardwareSerial Serial2(2); // Second Hardware Port
    void SerialNative2(B4R::Object* unused)
    {
    ::Serial2.begin(115200);
    b4r_main::_serialnative2->wrappedStream = &::Serial2;
    }
    #End If
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    What happens if you remove the HardwareSerial line?
     
  10. Blueforcer

    Blueforcer Active Member Licensed User

    This works! Thank you
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Based on the error it was already defined in the framework.
     
    Blueforcer 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