C/C++ Question how to send a stream to an arduino library from object open in B4R ?

candide

Active Member
Licensed User
i am looking at ELM327 library and to make a wrapper for B4R seem simple except for a stream.
when it is in arduino, it is simple :
case stream from serial :
B4X:
SoftwareSerial mySerial(2, 3); // RX, TX
#define ELM_PORT mySerial
ELM327 myELM327;
ELM_PORT.begin(115200);
myELM327.begin(ELM_PORT);

//original library
    bool begin(Stream& stream, char protocol='0', uint16_t payloadLen = 40);

and it is OK... with Serial stream and with wifi stream

but when serial is open in B4R, i am not able to send stream from B4R::Serial to this function.
i tested to send object "Serial"
i tested to send B4RStream* "Serial.Stream"

my B4R code is :
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private ELM As ELM327
    Private ELMserial As SoftwareSerial
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    ELMserial.Initialize(33000, 2, 3)
    Log("AppStart")
    'example of connecting to a local network

'    ELM.begin(ELMserial,0,40)
    ELM.begin1(ELMserial.Stream,0,40)
End Sub
wrapper and arduino libray are:
B4X:
//case wrapper and object sent by B4R project
//    bool B4RELM327::begin(Object* ELMstream, byte protocol, uint16_t payloadLen)
//    {
//       return elm327.begin(ELMstream, protocol, payloadLen);
//    }    
//case wrapper and stream sent by B4R project      
    bool B4RELM327::begin1(B4RStream* ELMstream, byte protocol, uint16_t payloadLen)
    {
       return elm327.begin(ELMstream, protocol, payloadLen);
    }

//original library
    bool begin(Stream& stream, char protocol='0', uint16_t payloadLen = 40);

How we can send a stream from B4R object to Arduino library ? i didn't find the solution....
issue seems to convert B4R::B4RStream to stream.

thanks for your help
 

candide

Active Member
Licensed User
i tested a simplified version with only this parameter:
B4X:
    bool B4RELM327::begin1(B4RStream* ELMstream)
    {
       return elm327.begin(ELMstream->wrappedStream);
    }
modification seems not rejected but wrapper still NOK

Vérification...
D:\B4R\B4R_AP~1\TEST_T~1\ELM327\Objects\bin\sketch\rELMduino.cpp: In member function 'bool B4R::B4RELM327::begin1(B4R::B4RStream*)':
rELMduino.cpp:40:52: error: no matching function for call to 'ELM327::begin(Stream*&)'
return elm327.begin(ELMstream->wrappedStream);
^
D:\B4R\B4R_AP~1\TEST_T~1\ELM327\Objects\bin\sketch\rELMduino.cpp:40:52: note: candidate is:
In file included from D:\B4R\B4R_AP~1\TEST_T~1\ELM327\Objects\bin\sketch\rELMduino.h:21:0,
from D:\B4R\B4R_AP~1\TEST_T~1\ELM327\Objects\bin\sketch\B4RDefines.h:27,
from D:\B4R\B4R_AP~1\TEST_T~1\ELM327\Objects\bin\sketch\rELMduino.cpp:19:
D:\B4R\B4R_AP~1\TEST_T~1\ELM327\Objects\bin\sketch\ELMduino.h:300:7: note: bool ELM327::begin(Stream&, char, uint16_t)
bool begin(Stream& stream, char protocol='0', uint16_t payloadLen = 40);
^
D:\B4R\B4R_AP~1\TEST_T~1\ELM327\Objects\bin\sketch\ELMduino.h:300:7: note: no known conversion for argument 1 from 'Stream*' to 'Stream&'
exit status 1

it seems now a new problem of conversion from 'Stream*' to 'Stream&
not clear for me, how to make it working ?
 
Last edited:

candide

Active Member
Licensed User
Thanks Erel, compilation is OK with this modification!

at last, stream management for this library is this one :
in B4R:
B4X:
    ELM.begin(ELMwifi.Stream, False, 1000, 48, Payload_len)
in wrapper h file :
B4X:
            bool begin(B4RStream* ELMstream, bool debug, uint16_t timeout, byte protocol, uint16_t payloadLen);
in wrapper cpp file :
B4X:
    bool B4RELM327::begin(B4RStream* ELMstream, bool debug, uint16_t timeout, byte protocol, uint16_t payloadLen)
    {
       return elm327.begin(*ELMstream->wrappedStream, debug, timeout, protocol, payloadLen);
    }
in arduino library h file:
B4X:
    bool begin(Stream& stream, const bool& debug = false, const uint16_t& timeout = 1000, const char& protocol = '0', const uint16_t& payloadLen = 40);
in arduino library cpp file :
B4X:
bool ELM327::begin(Stream &stream, const bool& debug, const uint16_t& timeout, const char& protocol, const uint16_t& payloadLen)
{
    elm_port    = &stream;

i don't have full understanding of the routing of stream at each step, but it is a good example.

Thank Erel
 
Top