需要用到VC串口调试程序,于是写了一个串口调试助手作参考,源码地址:http://download.csdn.net/detail/hc260164797/4360519,欢迎大家拍砖~~
程序界面是
串口设置是,9600波特率,8数据位,1位停止位,无校验位
该程序实现两个线程,一个线程串口读数据,并更新界面,一个座位主界面和串口发送数据。
主要实现函数:
1.枚举所有可用串口:
//枚举串口
void EnumerateSerialPorts(CUIntArray& ports)
{
//Make sure we clear out any elements which may already be in the array
ports.RemoveAll();
//Determine what OS we are running on
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
BOOL bGetVer = GetVersionEx(&osvi);
//On NT use the QueryDosDevice API
if (bGetVer && (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT))
{
//Use QueryDosDevice to look for all devices of the form COMx. This is a better
//solution as it means that no ports have to be opened at all.
TCHAR szDevices[65535];
DWORD dwChars = QueryDosDevice(NULL, szDevices, 65535);
if (dwChars)
{
int i=0;
for (;;)
{