Mega Multi-Serial and Software Serial in indexed array?


i'm trying use many serial ports.  i'd 4 , don't want lose usb serial port, i'll use softwareserial well.

i've seen other comments more convenient have array of serial items, rather serial, serial1 etc.  can done using array of pointers.

code: [select]
// declaration
hardwareserial *serials[5];
softwareserial myserial1(5, 6);
..
// setup

serials[0] = &serial;
serials[1] = &serial1;
serials[2] = &serial2;
serials[3] = &serial3;

// hardware serial devices can indexed

for (ix=0; ix<4; ix++)
{
(*serials[ix]).begin(9600);
(*serials[ix]).print("\nmega_serials_test- ");
(*serials[ix]).print(ix);
(*serials[ix]).println();
}

that's , works.  i'd softwareserial in same array.  possible pursuade compiler accept this?  , functions work correctly?  i've tried various things rejected e.g.:
code: [select]
serials[4] = (&hardwareserial) &myserial1;

can done?

i can't verify right more reasonable cast using reinterpret_cast or dynamic_cast don't think softwareserial inherits hardwareserial - both inherit stream

you create abstraction class "abstractserial" create either hardwareserial or softwareserial instance variable @ instantiation - depending on calling parameter - , reimplement same public functions , pass them real object.



Arduino Forum > Using Arduino > Programming Questions > Mega Multi-Serial and Software Serial in indexed array?


arduino

Comments

Popular posts from this blog

Valutazione Template - Joomla! Forum - community, help and support

SD Datastring Convention

First use of Arduino Uno : avrdude error on Blink uploading