Code could not convert "Serial" from 'usb_Serial_class" to 'HardwareSerial&'

Status
Not open for further replies.

jimmie

Well-known member
Code could not convert "Serial" from 'usb_Serial_class" to 'HardwareSerial&'

I have a .h file as shown below.

In compiling, I am getting the compile error from the highlighted statement:

could not convert 'Serial' from 'usb_serial_class' to 'HardwareSerial&'

I tried changing "Serial" below to "Serial1" but got the same error.

I would appreciate the community's help in resolving this error.

Code:
#ifndef Leddar_h
#define Leddar_h

/* _____STANDARD INCLUDES____________________________________________________ */
#include "Arduino.h"

/* _____PROJECT INCLUDES_____________________________________________________ */


/* _____LIBRARY DEFINITIONS__________________________________________________ */


#define DEFAULT_BAUD_RATE 115200

// Default address for the slave
#define DEFAULT_ADDRESS 0x01

//Error codes
#define ERR_LEDDAR_BAD_CRC -1
#define ERR_LEDDAR_NO_RESPONSE -2
#define ERR_LEDDAR_BAD_RESPONSE -3
#define ERR_LEDDAR_SHORT_RESPONSE -4
#define ERR_LEDDAR_SERIAL_PORT -5

// Number of detections does not match 
#define ERR_LEDDAR_NB_DETECTIONS -6;


/* _____CLASS DEFINITIONS____________________________________________________ */

/// Represents a measurement:
struct Detection
{
	unsigned char Segment;
	unsigned int Distance;
	unsigned int Amplitude;
	
	// Default constructor
	Detection() : Segment(0), Distance(0xFFFF), Amplitude(0) { }
};

/// Class to connect to a 16-channel Leddar module (Evaluation Kit, M16, IS16):
class Leddar16
{
public:
	Leddar16() 
	: BaudRate(DEFAULT_BAUD_RATE), SlaveAddress(DEFAULT_ADDRESS), NbDet(0), TxEn_Pin(0), TxEn_Action(0), SerialPort(Serial) 
	{ }
	
	[COLOR="#FF0000"]Leddar16( unsigned long Baud, unsigned char Addr = DEFAULT_ADDRESS, HardwareSerial& Port = Serial, unsigned char Pin = 0, unsigned char Action = 0) 
	: BaudRate(Baud), SlaveAddress(Addr), NbDet(0), TxEn_Pin(Pin), TxEn_Action(Action)  , SerialPort(Port)[/COLOR]
	{ }
	
	Leddar16( unsigned long Baud, unsigned char Addr, unsigned char Pin , unsigned char Action ) 
	: BaudRate(Baud), SlaveAddress(Addr), NbDet(0), TxEn_Pin(Pin), TxEn_Action(Action)  , SerialPort(Serial)
	{ }
	
	void init();
	char getDetections();
	char sendRequest();
	char parseResponse();
	void clearDetections();

public:
	unsigned char NbDet;
	Detection Detections[50];
	unsigned long TimeStamp;
	unsigned char LEDPower;
	unsigned char Status;   

private:
	unsigned long BaudRate;
	unsigned char SlaveAddress;
	unsigned char TxEn_Pin;
	unsigned char TxEn_Action;
	HardwareSerial& SerialPort;
};
 
Yes I could easily imagine that it will not compile for Serial as Serial is not derived from HardwareSerial

I would think it would compile if it instead was Serial1 as Serial1 is of the class HardwareSerial.

But don't see the actual error message, so not sure what you are seeing in that case. For example did you also update the other constructor to have Serial1?
 
This part restricts the library to only hardware (not usb) serial.

"HardwareSerial& Port = Serial"

Maybe try changing it to this:

"Stream& Port = Serial"

This may lead to other errors if the library attempts to set the baud rate. We can help better (like helping with those types of errors) when you share the complete code.
 
Thank you for your help.

Please see attached code.
 

Attachments

  • Leddar.zip
    13.1 KB · Views: 50
  • Sample.ino
    190 bytes · Views: 59
Last edited:
I did not try to build it, but my guess is you need to change a couple lines in the header file:
Code:
class Leddar16
{
public:
	Leddar16() 
	: BaudRate(DEFAULT_BAUD_RATE), SlaveAddress(DEFAULT_ADDRESS), NbDet(0), TxEn_Pin(0), TxEn_Action(0), SerialPort([COLOR="#FF0000"]Serial1[/COLOR]) 
	{ }
	
	Leddar16( unsigned long Baud, unsigned char Addr = DEFAULT_ADDRESS, HardwareSerial& Port = [COLOR="#FF0000"]Serial1[/COLOR], unsigned char Pin = 0, unsigned char Action = 0) 
	: BaudRate(Baud), SlaveAddress(Addr), NbDet(0), TxEn_Pin(Pin), TxEn_Action(Action)  , SerialPort(Port)
	{ }
	
	Leddar16( unsigned long Baud, unsigned char Addr, unsigned char Pin , unsigned char Action ) 
	: BaudRate(Baud), SlaveAddress(Addr), NbDet(0), TxEn_Pin(Pin), TxEn_Action(Action)  , SerialPort([COLOR="#FF0000"]Seria1l[/COLOR])
	{ }
And hopefully it should work OK for you.

The Stream class will not work as the code does do things like: SerialPort.begin(...)
 
You need to make the same changes to the LeaderOne class:
Code:
class LeddarOne
{
public:
	LeddarOne() 
	: BaudRate(DEFAULT_BAUD_RATE), SlaveAddress(DEFAULT_ADDRESS), NbDet(0), TxEn_Pin(0), TxEn_Action(0), SerialPort([COLOR="#FF0000"]Seria1l[/COLOR]) 
	{ }
	
	LeddarOne( unsigned long Baud, unsigned char Addr = DEFAULT_ADDRESS, HardwareSerial& Port = [COLOR="#FF0000"]Serial1[/COLOR], unsigned char Pin = 0, unsigned char Action = 0) 
	: BaudRate(Baud), SlaveAddress(Addr), NbDet(0), TxEn_Pin(Pin), TxEn_Action(Action)  , SerialPort(Port)
	{ }
	
	LeddarOne( unsigned long Baud, unsigned char Addr, unsigned char Pin, unsigned char Action) 
	: BaudRate(Baud), SlaveAddress(Addr), NbDet(0), TxEn_Pin(Pin), TxEn_Action(Action)  , SerialPort([COLOR="#FF0000"]Serial1[/COLOR])
	{ }
 
Hello KurtE:

I have been working hard on implementing your recommendations above but in order to check my results, I need both Ethernet and SD. I have been unable to resolve the problem of why the SD card is corrupted after writing a few files. When I commented the code for setting up Ethernet, the card worked 100% of the time.

I would appreciate your help in trying to resolve this frustrating issue. I have already posted the problem on the forum but after over 50 views, I did not get any response.

https://forum.pjrc.com/threads/57478-Teensy-4-0-SD-Buggy-Implementation

Thanks in advance for all your help.
 
Sorry,

I did not answer as I do very little with SD and nothing with Ethernet. So not much help there... Hopefully someone who does more with those areas will help out.
 
THANK YOU KurtE.

The SPI library you modified a few days ago solved the SD write problem. All I did was replace the old SD library and the SD card is now working without problems ALONG with the Ethernet code.
 
Status
Not open for further replies.
Back
Top