chipKIT® Development Platform

Inspired by Arduino™

GenericSerial

Created Sat, 25 Jan 2014 11:56:30 +0000 by ChristopheDupriez


ChristopheDupriez

Sat, 25 Jan 2014 11:56:30 +0000

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


majenko

Sat, 25 Jan 2014 23:01:12 +0000

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...?


ahnise

Mon, 15 Jun 2015 18:33:36 +0000

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.


majenko

Mon, 15 Jun 2015 20:57:27 +0000

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.


EmbeddedMan

Wed, 17 Jun 2015 13:10:03 +0000

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