I have been trying to develop a class that allows me to do debugging displays to a SoftwareSerial port of my choosing. My intent is to provide the baud rate and pin # to the constructor. I wouldn't be surprised if I'm reinventing something that has been done 1000 times. I look upon it as a learning exercise.
In the code I've provided, I get a compile error saying the 'identifier (mySerial) has not been declared in the current scope'. I understand the error -- I'm just not good enough with classes to solve it. Here is the sketch:
imho it's not a good idea to do a .begin() of a stream in the class.
If you need a Stream in your class,
give the user the oportuinity to hand over a Stream in the constructor.
So the user can decide if he wans to use hwserial, softserial, altserial.
He can change the baudrate, bits/stopbits/parity ... whatever the stream offers.
On the other hand I don't see what your class should do anyway.
Currently you have an object called dbg which can be used to print something.
What have you achieved in comparison of a global object
OK, I think I understand what you've said. I believe it to be essentially the same as what J-M-L Jackson told me? Is that correct?
Also, here is the code I'm trying to run. The output shows up on the Serial Monitor (HW), but I don't see anything on PuTTY, who is monitoring Pin 2 on the Nano (the Tx pin).
I like the idea of passing a Stream reference in, but remember that Stream cannot set signalling parameters like line speed, so these have to be done externally.
Yes, I think so. I need to be able to do 2 things:
understand why what I now have does not work!
be able to write a line of code like this: 'dbg("some text");' anywhere I need it during debugging and have the output go to a pin I have previously chosen to monitor with a terminal program like PuTTY.
Do you think you could help me achieve both objectives?
Thanks -Ray
I'm not really sure what you mean by the term 'trailer', however, I'm not concerned at the moment with EOL terminators or NOT and I'm not currently concerned with data type. I use strings mostly.
It has been too long since I used C++ in any amount. I'm having too much trouble remembering how C++ classes are constructed.
I think I do remember the use of the syntax xxx : yyy.
I believe the colon indicates inheritance.
I'm probably going to have to abandon this effort and just rely on other techniques like preprocessor macros -- it won't be as good, but I can get it developed easier.
Thanks for your help so far -- I'm trying to split my time between programming microcontrollers and my piano lessons and right now the piano is losing.
Thanks for the reply. I'm not able to really understand it at this time.
I'd have to go back to the books -- it's been too long.
I especially have some trouble understanding the line:
"Dbg (Stream &interface) : interface {&interface} {}"
I think it makes use of inheritance and I think the "interface" in the middle is a reserved word, while the other uses of that string of characters are user defined identifiers. If that is correct, then the other 2 (not the middle one) could be something else like "strm1", for example?
Is that correct?