Files
GdCpp12/staticOnly/KsMFC/ComPortTools.h

41 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <cstdint>
#include <vector>
#include <string>
// ----- 串口常用函数 -----------
struct sComPort{
int port=0; // 串口编号
std::wstring portName; // 串口名称
// 默认构造函数
sComPort() = default;
// 复制构造函数
sComPort(const sComPort& other)
: port(other.port), portName(other.portName)
{
}
};
/// 查找串口列表,返回串口号列表
/// @param name 串口名字必须包含的字符串例如CH340。如果为nullptr或""则返回所有串口
void COM_InitPortList(std::vector<sComPort> &ports, const wchar_t * name);
#ifdef _AFXDLL
// 搜索所有串口名称添加到ComboBox整形串口号绑定到每一个选项的data里。
// 如果列表不为空且defaultCom在列表中则自动选中否则选择第一项
void COM_PortListToCombo(const std::vector<sComPort>& ports, CComboBox* Box, int defaultCom);
// 刷新串口列表。
// 如果之前选中的串口还在,自动选择
// 如果之前选中的串口不在了,自动选择第一项
void COM_RefreshPortList (const wchar_t* name, CComboBox* Box);
int COM_GetSelectedPort (CComboBox* Box);
void COM_InitBaudList (const int* List, int Num, int default_val, CComboBox* Box);
void COM_InitBaudList(const std::vector<uint32_t>& List, int default_val, CComboBox* Box);
#endif