HardwareSerial class doesn't print text in Beta 1.5.5

Hey Guys,

Following code works well in Arduino 1.0.5 but not not in 1.5.5. Is this a bug or is it correct, that this mustn't work this way since the newer Version(s)? I need to pass a Hardwareserial reference to another class instance. please help me. How can I accomplish that?

void setup() {
    HardwareSerial *hws = &Serial;
    hws->begin(9600);
    hws->println("Irgendein beliebiger Text");
}
void loop() {
}

Do you need to instaniate more than one Serial?

Normally, you just use

  Serial.begin(9600);

or if running on an Atmega2650,

   Serial1.begin(9600);
   Serial2.begin(19200);
   Serial3.begin(57600);

oh scusi. problem solved. solution: there was no problem. don't know what i've done :P

@lar3ry: maybe it is needed to instanciate more than one Serial, because It#s possible to need more than one communication unit. Each of this instances should do a print or listen for incomming messages via its own related HWS. Futhermore, its easier to define related HWSses in main-program-file and pass them to the CommUnits than rewriting 3 redundant classes, in case of using S1, S2 and S3

einspunktnull: not not in 1.5.5.

What problem do you get? When I compile that code for a UNO in 1.5.5 it says:

Sketch uses 1,840 bytes (5%) of program storage space. Maximum is 32,256 bytes. Global variables use 213 bytes (10%) of dynamic memory, leaving 1,835 bytes for local variables. Maximum is 2,048 bytes.

sorry. watch my last reply

@lar3ry: maybe it is needed to instanciate more than one Serial, because It#s possible to need more than one communication unit.

No, that isn't possible. There is only one bit of hardware. That ONE bit of hardware can't communicate with two devices at once, and keep the data from the two devices separate.

No, that isn’t possible. There is only one bit of hardware. That ONE bit of hardware can’t communicate with two devices at once, and keep the data from the two devices separate.

Okay, The Standard Arduino doesn’t support more Serials than one, but if you use the Arduiono Mega or it’s Siblings it is possible, because there are 4 Serials. (Serial, Serial1, Serial2,Serial3)

Okay, The Standard Arduino doesn't support more Serials than one, but if you use the Arduiono Mega or it's Siblings it is possible, because there are 4 Serials. (Serial, Serial1, Serial2,Serial3)

In that case, there are 4 bits of hardware, and the HardwareSerial class already creates one instance for each bit of hardware. You can NOT, meaningfully, create more.

In that case, there are 4 bits of hardware, and the HardwareSerial class already creates one instance for each bit of hardware. You can NOT, meaningfully, create more.

However, maybe my words are not technically correct, sorry, I’m an Arduino noob. In my understanding, I can create 4 Communication class instances and pass 4 different Serial references to them. here’s an example (needed Libfiles are attached), I use the Arduino Mega ADK for this:

#include "SAAP.h" //CommClass

//Two Instances of commclass
//Protocol: command <commaSeparatedValues> endbyte
// ie: a1,2,3; or b; or c1,two,3,four;
SAAP comm1;
SAAP comm2;

void setup()
{
        //params: errFunctionPointer or 0 for defaultCallback, HWSReference, baudrate, readTimout
	comm1.initialize(0, &Serial, 9600, 500);
        comm2.initialize(0, &Serial1, 115200, 300);
        
        //if command with values received call a function, i.e: a1,two,3;
        //params: command commandCallback numValues
	comm1.registerCommand('a', onDev1CommandA, 3);

        //if command with values received call a function, i.e: a1.45,-3.214;
        comm2.registerCommand('x', onDev2CommandX, 2);
	comm1.send("r;");
}

void loop()
{
        //listen for incomming messages
	comm1.receive();
        comm2.receive();
}

void onDev1CommandA(const uint8_t errorNum, const uint8_t command, const uint8_t numValues)
{
	int val1 = comm1.getIntValue();
        String val2 = comm1.getStringValue();
        int val3 = comm1.getIntValue();
        comm1.send("got 3 values form comm1");
        //Do sth. with values
}

void onDev2CommandX(const uint8_t errorNum, const uint8_t command, const uint8_t numValues)
{
	float val1 = comm2.getFloatValue();
        float val2 = comm2.getFloatValue();
        comm2.send("got 2 values form comm2");
        //Do sth. with values
}

SAAP.h (1.55 KB)

SAAP.cpp (4.69 KB)

einspunktnull:

In that case, there are 4 bits of hardware, and the HardwareSerial class already creates one instance for each bit of hardware. You can NOT, meaningfully, create more.

However, maybe my words are not technically correct, sorry, I’m an Arduino noob. In my understanding, I can create 4 Communication class instances and pass 4 different Serial references to them. here’s an example (needed Libfiles are attached), I use the Arduino Mega ADK for this:

The whole point is that THERE. ARE. ALREADY. FOUR. SERIAL.CLASSES. IN. A. MEGA2650. They are instantiated by using the .begin() function for each one.

The whole point is that THERE. ARE. ALREADY. FOUR. SERIAL.CLASSES. IN. A. MEGA2650.

There is ONE HardwareSerial class. There are FOUR [u]instances[/u] defined, when the code is being compiled for a Mega.

PaulS:

The whole point is that THERE. ARE. ALREADY. FOUR. SERIAL.CLASSES. IN. A. MEGA2650.

There is ONE HardwareSerial class. There are FOUR [u]instances[/u] defined, when the code is being compiled for a Mega.

That's exactly what I meant. No idea how that other sentence got there. :~

No idea how that other sentence got there.

I hate when my fingers do something other than what my brain said to do. 8)