Pages: [1]   Go Down
Author Topic: HardwareSerial  (Read 1599 times)
0 Members and 1 Guest are viewing this topic.
Reading, PA
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm stumped by the stack trace. I can't figure out what's wrong with the code. I even slept on it. I removed all the bulk of the library and left only the parts in .h and .cpp that are causing the error. Does anybody see it?

LCD.h
Code:
#ifndef LCD_h
#define LCD_h

#include "WProgram.h"

class LCD
{
public:
  LCD();
  LCD(HardwareSerial LCDHardwareSerial);
  HardwareSerial hardwareSerial;
};
#endif

LCD.cpp
Code:
#include "WProgram.h"
#include "LCD.h"

HardwareSerial hardwareSerial;

LCD::LCD()
{
  hardwareSerial = Serial;
  hardwareSerial.begin(9600);
}

LCD::LCD(HardwareSerial LCDHardwareSerial)
{
  hardwareSerial = LCDHardwareSerial;
  hardwareSerial.begin(9600);
}

Stack trace
Code:
C:\Program Files\Arduino\libraries\LCD\LCD.cpp:10: error: no matching function for call to 'HardwareSerial::HardwareSerial()'
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:50: note: candidates are: HardwareSerial::HardwareSerial(ring_buffer*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:32: note:                 HardwareSerial::HardwareSerial(const HardwareSerial&)
C:\Program Files\Arduino\libraries\LCD\LCD.cpp: In constructor 'LCD::LCD()':
C:\Program Files\Arduino\libraries\LCD\LCD.cpp:12: error: no matching function for call to 'HardwareSerial::HardwareSerial()'
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:50: note: candidates are: HardwareSerial::HardwareSerial(ring_buffer*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:32: note:                 HardwareSerial::HardwareSerial(const HardwareSerial&)
C:\Program Files\Arduino\libraries\LCD\LCD.cpp: In constructor 'LCD::LCD(HardwareSerial)':
C:\Program Files\Arduino\libraries\LCD\LCD.cpp:18: error: no matching function for call to 'HardwareSerial::HardwareSerial()'
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:50: note: candidates are: HardwareSerial::HardwareSerial(ring_buffer*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)
C:\Program Files\Arduino\hardware\arduino\cores\arduino/HardwareSerial.h:32: note:                 HardwareSerial::HardwareSerial(const HardwareSerial&)

Thanks,
Stauffski
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 485
Posts: 18798
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That's not a stack trace, that's a linker compiler error.

This line:

Code:
HardwareSerial hardwareSerial;

Calls the default constructor for HardwareSerial which takes no arguments. However the HardwareSerial class has no such constructor.
Logged


Offline Offline
God Member
*****
Karma: 4
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm stumped by the stack trace. I can't figure out what's wrong with the code. I even slept on it. I removed all the bulk of the library and left only the parts in .h and .cpp that are causing the error. Does anybody see it?



I see several problems.

1) You should pass the HardwareSerial argument by reference (using a & sign) to avoid copying
2) You should declare the HardwareSerial class member as a reference, so it references back to the original global (again using a & sign)
3) You should pass the necessary arguments to the constructor of the HardwareSerial class.

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
3) You should pass the necessary arguments to the constructor of the HardwareSerial class.
No. The HardwareSerial class already creates all the valid instances of HardwareSerial, as Serial, Serial1, Serial2, and Serial3. There should be no calls to the HardwareSerial class' constructor.
Logged

Pages: [1]   Go Up
Jump to: