打开串口时输出更多日志

This commit is contained in:
大石头X2 2016-12-27 19:04:48 +08:00
parent 365bb2a26e
commit a56080eb15
3 changed files with 12 additions and 9 deletions

View File

@ -35,6 +35,9 @@ public:
void* State; // 用户状态数据。常用于批量端口操作时记录索引
Port();
#ifndef TINY
virtual ~Port();
#endif
Port& Set(Pin pin); // 设置引脚
bool Empty() const;
@ -57,10 +60,6 @@ public:
virtual String& ToStr(String& str) const;
protected:
//Port() = default;
#ifndef TINY
virtual ~Port();
#endif
// 配置过程由Open调用最后GPIO_Init
virtual void OnOpen(void* param);

View File

@ -16,8 +16,14 @@ SerialPort::SerialPort(COM index, int baudRate)
// 析构时自动关闭
SerialPort::~SerialPort()
{
if(RS485) delete RS485;
delete RS485;
RS485 = nullptr;
delete Ports[0];
Ports[0] = nullptr;
delete Ports[1];
Ports[1] = nullptr;
}
void SerialPort::Init()
@ -70,12 +76,10 @@ void SerialPort::Set(byte parity, byte dataBits, byte stopBits)
// 打开串口
bool SerialPort::OnOpen()
{
debug_printf("Serial%d Open(%d, %d, %d, %d)\r\n", _index + 1, _baudRate, _parity, _dataBits, _stopBits);
debug_printf("Serial%d Open(%d, %d, %d, %d) TX=P%c%d RX=P%c%d\r\n", _index + 1, _baudRate, _parity, _dataBits, _stopBits, _PIN_NAME(Pins[0]), _PIN_NAME(Pins[1]));
// 清空缓冲区
//#if !(defined(STM32F0) || defined(GD32F150))
Tx.Clear();
//#endif
Rx.SetCapacity(0x80);
Rx.Clear();

View File

@ -138,7 +138,7 @@ enum Pin
// 获取组和针脚
#define _PORT(PIN) (1 << ((PIN) & (uint16_t)0x0F))
#define _PIN(PIN) (PIN & 0x000F)
#define _PIN_NAME(pin) ('A' + (pin >> 4)), (pin & 0x0F)
#define _PIN_NAME(pin) (pin==P0 ? '_' : ('A' + (pin >> 4))), (pin==P0 ? '0' : (pin & 0x0F))
/* 串口定义 */
enum COM