JAndle
November 25, 2017, 4:04am
1
I have a need to output things to Serial or Serial1 under different circumstances, so I need a
serial_t *ptrSeriaPort = &Serial;
Is there a type for this that applies to both USB and USART and acn communicate over either one??
@JAndle ,
It looks like they are two different object types: USARTSerial and USBSerial.
Maybe the Elites on the forum can suggest an elegant solution.
In the meantime, I think I found the correct files with the details:
/**
******************************************************************************
* @file spark_wiring_usartserial.h
* @author Satish Nair
* @version V1.0.0
* @date 13-March-2013
* @brief Header for spark_wiring_usartserial.c module
******************************************************************************
Copyright (c) 2013-2015 Particle Industries, Inc. All rights reserved.
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
This file has been truncated. show original
/**
******************************************************************************
* @file spark_wiring_usbserial.h
* @author Satish Nair
* @version V1.0.0
* @date 13-March-2013
* @brief Header for spark_wiring_usbserial.c module
******************************************************************************
Copyright (c) 2013-2015 Particle Industries, Inc. All rights reserved.
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
This file has been truncated. show original
ScruffR
November 25, 2017, 8:40am
3
Would using Stream
as common ancestor help?
JAndle
November 25, 2017, 2:01pm
4
I will see if something like this works:
Stream* pDebug = &Serial, *pDevice = &Serial1;
pDebug->print();
UMD
December 2, 2017, 10:46am
5
@JAndle , I confirm that the following works (using the Logging class) to set up the Logger to output either via Serial or USBSerial1
// Select debug output destination
// -------------------------------
Print *pStream;
if (bUseSerial1)
pStream = &USBSerial1;
else
pStream = &Serial;
auto logHandler1 = new StreamLogHandler(*pStream, LOG_LEVEL_WARN /* Default level */, filters);
logManager->addHandler(logHandler1);