system
September 10, 2012, 10:49am
1
Hi,
I would write a generic code for my device which listen the instructions from from Serial (USB) and Ethernet (web).
I saw theses classes extend the Stream.h.
Can I do something like:
void parseLine(Stream *inputStream);
Then an error occurs while a call:
Foo::parseLine(_client);
_client is type of EthernetClient
error: cannot convert 'EthernetClient' to 'Stream*' for argument '1' to 'void Core::readUint8(Stream*, uint8_t&)'
Can you help me?
Thx
system
September 10, 2012, 11:16am
2
Can I do something like:
Yes, you can.
Then an error occurs while a call:
Not surprising. You defined the function taking a pointer, but you aren't calling it with a pointer.
Try:
Foo::parseLine(&_client);
system
September 10, 2012, 12:18pm
3
Wünderbar!!! Great thanks, it works.
system
September 10, 2012, 12:44pm
4
Damned!
The skelton function compiles.
But when I write something inside I have a problem.
void readUint8(Stream *inputStream, uint8_t &out)
{
int c;
while ((c=inputStream.read())/*!=-1*/ && '0'<=c && 'c'<='9') {
out = (out *10) + ((uint8_t) (c -'0'));
}
}
error: request for member 'read' in 'inputStream', which is of non-class type 'Stream*'
I include <Stream.h> in my .h…
Well read() is "virtual" in Stream.h but it is called in Stream.cpp
I.E:
int Stream::peekNextDigit()
{
int c;
while (1) {
c = timedPeek();
if (c < 0) return c; // timeout
if (c == '-') return c;
if (c >= '0' && c <= '9') return c;
read(); // discard non-numeric
}
}
This code works.
Why I can't use "inputStream.read()"?
system
September 10, 2012, 12:50pm
5
I add a '*':
while ((c=(*inputStream).read())
It compiles but I don't know why.
A simpler way exists to do that?
Foo::test(Stream **p) {
p.read();
}
Foo::test(&&Serial)?
system
September 10, 2012, 12:54pm
6
The pointer deference operator is ->, not .
while ((c=inputStream->read())