Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

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

  1. #1

    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) 
    	{ }
    	
    	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)
    	{ }
    	
    	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;
    };

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,416
    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?

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,555
    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.

  4. #4
    Thank you for your help.

    Please see attached code.
    Attached Files Attached Files
    Last edited by jimmie; 08-23-2019 at 04:14 PM. Reason: Adding attachments.

  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,416
    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(Serial1) 
    	{ }
    	
    	Leddar16( unsigned long Baud, unsigned char Addr = DEFAULT_ADDRESS, HardwareSerial& Port = Serial1, 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(Seria1l)
    	{ }
    And hopefully it should work OK for you.

    The Stream class will not work as the code does do things like: SerialPort.begin(...)

  6. #6
    Thank you very much @kurtE.

    Will try it.

  7. #7
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,416
    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(Seria1l) 
    	{ }
    	
    	LeddarOne( unsigned long Baud, unsigned char Addr = DEFAULT_ADDRESS, HardwareSerial& Port = Serial1, 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(Serial1)
    	{ }

  8. #8
    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...Implementation

    Thanks in advance for all your help.

  9. #9
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,416
    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.

  10. #10
    Thank you KurtE for your prompt answer and attempt to help.

    This issue is most likely "Ethernet-library" related.

    I have posted about a potential bug in the Ethernet library in:

    https://forum.pjrc.com/threads/57490...682#post214682
    Last edited by jimmie; 09-04-2019 at 03:46 AM. Reason: added link

  11. #11
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •