GenericSerial

Let us know what you think about the chipKIT, and what can be done to make it better!
Post Reply
ChristopheDupriez
Posts: 56
Joined: Sat Oct 05, 2013 3:25 pm

GenericSerial

Post by ChristopheDupriez » Sat Jan 25, 2014 12:56 pm

Hi!

USBSerial, HardwareSerial and SoftwareSerial are not inheriting from anything like a GenericSerial interface or class (USBSerial & HardwareSerial are inheriting from Stream which inherits from Print; SoftwareSerial inherits from nothing!).

This is very bad for someone willing to switch its tracing port easily from USB to something else (for instance, to be able to receive traces after putting the MCU to sleep and having then an USB reset): you cannot define a "tracingSerial" property to the libraries using a GenericSerial class.

(By the way, some output buffering + interrupt driven transmission for hardware serial would be nice too!)

Meanwhile, I will prepare a "SwitchableTrace" class with a predefined SwTrace static objects which ease tracing by enforcing the following:
1) a digital input pin may be assigned to check if tracing is desired by user or not at all (this signal can also be used to enable (or not) LEDs and save energy otherwise). By default, 0 meaning "trace always"; 255 means "never trace"
2) a 5volt tolerant digital input pin is used to sense the USB input voltage: if present and tracing is desired, the trace is sent to the USB port. Default is 0 and means "always send to USB"; 255 means "never send trace to USB"
3) all tracing lines should begin by a configurable string (defaut ">") so they can be discarded on receive side if desired.
4) SwTrace should be advised when going to sleep mode so it does not try to use USB any more.

I have now a first version tested for "regular operations" but not with sleeping possibilities: this will be tested in the following week.
SoftwareSerial is also not inheriting from Stream (and then Print) which does not make it very easy to tame: I will forget about it for now.

Any suggestion is very welcome! I you want to test current sources, just ask!

Christophe

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: GenericSerial

Post by majenko » Sun Jan 26, 2014 12:01 am

When we finally get proper Arduino 1.x support the SoftwareSerial will be inheriting from the Stream class.

I did once make a small GenericSerial wrapper class, but it wasn't wonderful, and of course it meant including SoftwareSerial even if you weren't using it.

I wonder what adding ": public Stream" to the class definition of SoftwareSerial would do...?
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

ahnise
Posts: 8
Joined: Thu Jan 15, 2015 1:48 pm

Re: GenericSerial

Post by ahnise » Mon Jun 15, 2015 7:33 pm

Currently using the more recent version of ChipKit, both USBSerial and HardwareSerial inherit from the Stream class. You can pass either as a Stream class to whatever needs to do the printing. I just tested this and it works fine. Not sure about SoftwareSerial.

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: GenericSerial

Post by majenko » Mon Jun 15, 2015 9:57 pm

Not currently with the standard SoftwareSerial, but you can with my TimerSerial, and the new SoftwareSerial library that is being worked on at the moment.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: GenericSerial

Post by EmbeddedMan » Wed Jun 17, 2015 2:10 pm

A 'proper' version of SoftwareSerial is almost done and will be included in an upcoming MPIDE build. Then all three serial methods should be interchangeable.

*Brian

Post Reply