Showing
3 changed files
with
149 additions
and
73 deletions
Too many changes to show.
To preserve performance only 3 of 14 files are displayed.
| ... | ... | @@ -95,68 +95,6 @@ BOOL CBlueFlashToolApp::InitInstance() |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
| 98 | - | |
| 99 | -//获取应用程序的根目录 | |
| 100 | -//return value:应用程序的根目录 | |
| 101 | -CString GetCurrPath() | |
| 102 | -{ | |
| 103 | - CString strPath =""; | |
| 104 | - char cCurDirectory[_MAX_PATH]; | |
| 105 | - memset(cCurDirectory,'\0',_MAX_PATH); | |
| 106 | - ::GetModuleFileName(NULL, cCurDirectory, _MAX_PATH); | |
| 107 | - //GetCurrentDirectory(256, cCurDirectory); //不能使用这个函数,如果中间你调用文件对话框,对改变你的当前路径 | |
| 108 | - strPath.Format(cCurDirectory); | |
| 109 | - CString strAppName =AfxGetApp()->m_pszAppName; | |
| 110 | - strAppName+=".exe"; | |
| 111 | - //把最后的exe文件名去掉 | |
| 112 | - int length1,length2; | |
| 113 | - length1=strPath.GetLength(); | |
| 114 | - length2=strAppName.GetLength(); | |
| 115 | - strPath.Delete(length1-length2,length2); | |
| 116 | - //strPath.Replace("\\","\\\\"); | |
| 117 | - return strPath; | |
| 118 | -} | |
| 119 | -//判断某文件是否存在 | |
| 120 | -//return value: ture:存在,false:不存在! | |
| 121 | -//Parameters: | |
| 122 | -//strAbsolutefilePath:文件的绝对路径 | |
| 123 | -bool IsExistFile(CString strAbsolutefilePath) | |
| 124 | -{ | |
| 125 | - CFileFind findFile; | |
| 126 | - //BOOL iFlag = false; | |
| 127 | - BOOL iFlag = findFile.FindFile(strAbsolutefilePath); | |
| 128 | - return (bool)iFlag; | |
| 129 | -} | |
| 130 | - | |
| 131 | - | |
| 132 | -BOOL QuerySingleSerialPortEx(int nPort) | |
| 133 | -{ | |
| 134 | - CString strComm; | |
| 135 | - strComm.Format("COM%d",nPort); | |
| 136 | - if (nPort >= 10) | |
| 137 | - {//微软的技术手册规定打开端口号大于9的串口时应该使用"\\.\COM10"格式的文件名,更多的信息请参考msdn。 | |
| 138 | - strComm.Format("\\\\.\\COM%d",nPort); | |
| 139 | - } | |
| 140 | - BOOL bValid = TRUE; | |
| 141 | - HANDLE hComm; | |
| 142 | - | |
| 143 | - hComm = CreateFile(strComm,GENERIC_READ | GENERIC_WRITE,0,NULL,\ | |
| 144 | - OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL| FILE_FLAG_OVERLAPPED, NULL); | |
| 145 | - int nError = GetLastError(); | |
| 146 | - | |
| 147 | - if(INVALID_HANDLE_VALUE == hComm) | |
| 148 | - {//***********如果没有该设备,或者被其他应用程序占用******** | |
| 149 | - if(2 == nError) | |
| 150 | - bValid = -1; | |
| 151 | - else if(5 == nError) | |
| 152 | - bValid = FALSE; | |
| 153 | - else | |
| 154 | - bValid = FALSE; | |
| 155 | - } | |
| 156 | - CloseHandle(hComm); //重要 关闭文件句柄 = 关闭串口 | |
| 157 | - return bValid; | |
| 158 | -} | |
| 159 | - | |
| 160 | 98 | // 加载程序默认配置 |
| 161 | 99 | bool CBlueFlashToolApp::LoadConfigs(void) |
| 162 | 100 | { |
| ... | ... | @@ -304,3 +242,129 @@ bool CBlueFlashToolApp::SaveConfigs(void) |
| 304 | 242 | |
| 305 | 243 | return true; |
| 306 | 244 | } |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | +//获取应用程序的根目录 | |
| 249 | +//return value:应用程序的根目录 | |
| 250 | +CString GetCurrPath() | |
| 251 | +{ | |
| 252 | + CString strPath =""; | |
| 253 | + char cCurDirectory[_MAX_PATH]; | |
| 254 | + memset(cCurDirectory,'\0',_MAX_PATH); | |
| 255 | + ::GetModuleFileName(NULL, cCurDirectory, _MAX_PATH); | |
| 256 | + //GetCurrentDirectory(256, cCurDirectory); //不能使用这个函数,如果中间你调用文件对话框,对改变你的当前路径 | |
| 257 | + strPath.Format(cCurDirectory); | |
| 258 | + CString strAppName =AfxGetApp()->m_pszAppName; | |
| 259 | + strAppName+=".exe"; | |
| 260 | + //把最后的exe文件名去掉 | |
| 261 | + int length1,length2; | |
| 262 | + length1=strPath.GetLength(); | |
| 263 | + length2=strAppName.GetLength(); | |
| 264 | + strPath.Delete(length1-length2,length2); | |
| 265 | + //strPath.Replace("\\","\\\\"); | |
| 266 | + return strPath; | |
| 267 | +} | |
| 268 | +//判断某文件是否存在 | |
| 269 | +//return value: ture:存在,false:不存在! | |
| 270 | +//Parameters: | |
| 271 | +//strAbsolutefilePath:文件的绝对路径 | |
| 272 | +bool IsExistFile(CString strAbsolutefilePath) | |
| 273 | +{ | |
| 274 | + CFileFind findFile; | |
| 275 | + //BOOL iFlag = false; | |
| 276 | + BOOL iFlag = findFile.FindFile(strAbsolutefilePath); | |
| 277 | + return (bool)iFlag; | |
| 278 | +} | |
| 279 | + | |
| 280 | + | |
| 281 | +BOOL QuerySingleSerialPortEx(int nPort) | |
| 282 | +{ | |
| 283 | + CString strComm; | |
| 284 | + strComm.Format("COM%d",nPort); | |
| 285 | + if (nPort >= 10) | |
| 286 | + {//微软的技术手册规定打开端口号大于9的串口时应该使用"\\.\COM10"格式的文件名,更多的信息请参考msdn。 | |
| 287 | + strComm.Format("\\\\.\\COM%d",nPort); | |
| 288 | + } | |
| 289 | + BOOL bValid = TRUE; | |
| 290 | + HANDLE hComm; | |
| 291 | + | |
| 292 | + hComm = CreateFile(strComm,GENERIC_READ | GENERIC_WRITE,0,NULL,\ | |
| 293 | + OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL| FILE_FLAG_OVERLAPPED, NULL); | |
| 294 | + int nError = GetLastError(); | |
| 295 | + | |
| 296 | + if(INVALID_HANDLE_VALUE == hComm) | |
| 297 | + {//***********如果没有该设备,或者被其他应用程序占用******** | |
| 298 | + if(2 == nError) | |
| 299 | + bValid = -1; | |
| 300 | + else if(5 == nError) | |
| 301 | + bValid = FALSE; | |
| 302 | + else | |
| 303 | + bValid = FALSE; | |
| 304 | + } | |
| 305 | + CloseHandle(hComm); //重要 关闭文件句柄 = 关闭串口 | |
| 306 | + return bValid; | |
| 307 | +} | |
| 308 | + | |
| 309 | +//利用API查询指定范围内的串口状态信息,并分别返回指定范围内系统存在的串口, | |
| 310 | +//当前未被占用的可用串口,已被占用的串口和系统不存在的串口 | |
| 311 | +void QuerySerialPortStatusEx(CStringArray& cStrAryExistPort,\ | |
| 312 | + CStringArray& cStrAryNoneOpenedPort,CStringArray& cStrAryAlreadyOpenedPort,\ | |
| 313 | + CStringArray& cStrAryNotExistPort,int nStartPort,int nLastPort) | |
| 314 | +{ | |
| 315 | + CString strTmp,strComm,strFree; | |
| 316 | + //对输入的参数进行检查 | |
| 317 | + if(nStartPort < 1) nStartPort = 1; | |
| 318 | + if(nStartPort > 65535) nStartPort = 65535; | |
| 319 | + if(nLastPort < 1) nLastPort = 1; | |
| 320 | + if(nLastPort > 65535) nLastPort = 65535; | |
| 321 | + int n1 = nStartPort,n2=nLastPort; | |
| 322 | + nStartPort = min(n1,n2); | |
| 323 | + nLastPort = max(n1,n2); | |
| 324 | + | |
| 325 | + cStrAryExistPort.RemoveAll(); | |
| 326 | + cStrAryNoneOpenedPort.RemoveAll(); | |
| 327 | + cStrAryAlreadyOpenedPort.RemoveAll(); | |
| 328 | + cStrAryNotExistPort.RemoveAll(); | |
| 329 | + | |
| 330 | + HANDLE hComm; | |
| 331 | + int nAccum = 0; | |
| 332 | + for (int i = nStartPort;i<=nLastPort;i++) | |
| 333 | + { | |
| 334 | + strComm.Format("COM%d",i); | |
| 335 | + if (i>=10) | |
| 336 | + {//微软的技术手册规定打开端口号大于9的串口时应该使用"\\.\COM10"格式的文件名,更多的信息请参考msdn。 | |
| 337 | + strComm.Format("\\\\.\\COM%d",i); //注:"\\.\COM10"格式对于10以下的串口也是有效的 | |
| 338 | + } | |
| 339 | + // 这里的CreateFile函数起了很大的作用,可以用来创建系统设备文件,如果该设备不存在或者被占用,则会返回一个错误,即下面的 INVALID_HANDLE_VALUE ,据此可以判断可使用性。详细参见MSDN中的介绍。 | |
| 340 | + hComm = CreateFile(strComm,GENERIC_READ | GENERIC_WRITE,0,NULL,\ | |
| 341 | + OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL| FILE_FLAG_OVERLAPPED, NULL); | |
| 342 | + int nLastError = GetLastError(); | |
| 343 | + strComm.TrimLeft("\\\\.\\"); | |
| 344 | + | |
| 345 | + if(hComm == INVALID_HANDLE_VALUE) | |
| 346 | + {//***********如果没有该设备,或者被其他应用程序在用******** | |
| 347 | + if (2 == nLastError) | |
| 348 | + {//串口不存在 | |
| 349 | + cStrAryNotExistPort.Add(strComm); | |
| 350 | + } | |
| 351 | + else if(5 == nLastError) | |
| 352 | + {//串口已被占用 | |
| 353 | + cStrAryExistPort.Add(strComm); | |
| 354 | + cStrAryAlreadyOpenedPort.Add(strComm); | |
| 355 | + } | |
| 356 | + else | |
| 357 | + {//其他错误 | |
| 358 | + cStrAryExistPort.Add(strComm); | |
| 359 | + } | |
| 360 | + } | |
| 361 | + else | |
| 362 | + {//串口存在且未被占用 | |
| 363 | + cStrAryExistPort.Add(strComm); | |
| 364 | + cStrAryNoneOpenedPort.Add(strComm); | |
| 365 | + nAccum++; | |
| 366 | + } | |
| 367 | + CloseHandle(hComm); //关闭文件句柄 - 必要 | |
| 368 | + } | |
| 369 | + | |
| 370 | +} | ... | ... |
| ... | ... | @@ -65,6 +65,8 @@ typedef struct |
| 65 | 65 | extern app_main_data_struct g_AppMainData; |
| 66 | 66 | extern CIniFile g_globalini; |
| 67 | 67 | BOOL QuerySingleSerialPortEx(int nPort); |
| 68 | +void QuerySerialPortStatusEx(CStringArray& cStrAryExistPort, CStringArray& cStrAryNoneOpenedPort,CStringArray& cStrAryAlreadyOpenedPort, CStringArray& cStrAryNotExistPort,int nStartPort,int nLastPort); | |
| 69 | +bool IsExistFile(CString strAbsolutefilePath); | |
| 68 | 70 | |
| 69 | 71 | |
| 70 | 72 | class CBlueFlashToolApp : public CWinApp | ... | ... |
| ... | ... | @@ -6,14 +6,23 @@ |
| 6 | 6 | --------------------Configuration: BlueFlashTool - Win32 Debug-------------------- |
| 7 | 7 | </h3> |
| 8 | 8 | <h3>Command Lines</h3> |
| 9 | -Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP3FFF.tmp" with contents | |
| 9 | +Creating command line "rc.exe /l 0x804 /fo"Debug/BlueFlashTool.res" /d "_DEBUG" /d "_AFXDLL" "H:\BlueFlashTool\BlueFlashTool.rc"" | |
| 10 | +Creating temporary file "C:\Users\ADMINI~1\AppData\Local\Temp\RSP186D.tmp" with contents | |
| 10 | 11 | [ |
| 11 | 12 | /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FR"Debug/" /Fp"Debug/BlueFlashTool.pch" /Yu"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c |
| 12 | -"C:\code\BlueFlashTool\BlueFlashTool.cpp" | |
| 13 | -"C:\code\BlueFlashTool\BlueFlashToolDlg.cpp" | |
| 13 | +"H:\BlueFlashTool\BlueFlashTool.cpp" | |
| 14 | +"H:\BlueFlashTool\BlueFlashToolDlg.cpp" | |
| 15 | +"H:\BlueFlashTool\mscomm.cpp" | |
| 16 | +"H:\BlueFlashTool\SysConfig.cpp" | |
| 14 | 17 | ] |
| 15 | -Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP3FFF.tmp" | |
| 16 | -Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP4000.tmp" with contents | |
| 18 | +Creating command line "cl.exe @C:\Users\ADMINI~1\AppData\Local\Temp\RSP186D.tmp" | |
| 19 | +Creating temporary file "C:\Users\ADMINI~1\AppData\Local\Temp\RSP186E.tmp" with contents | |
| 20 | +[ | |
| 21 | +/nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FR"Debug/" /Fp"Debug/BlueFlashTool.pch" /Yc"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c | |
| 22 | +"H:\BlueFlashTool\StdAfx.cpp" | |
| 23 | +] | |
| 24 | +Creating command line "cl.exe @C:\Users\ADMINI~1\AppData\Local\Temp\RSP186E.tmp" | |
| 25 | +Creating temporary file "C:\Users\ADMINI~1\AppData\Local\Temp\RSP186F.tmp" with contents | |
| 17 | 26 | [ |
| 18 | 27 | /nologo /subsystem:windows /incremental:yes /pdb:"Debug/BlueFlashTool.pdb" /debug /machine:I386 /out:"Debug/BlueFlashTool.exe" /pdbtype:sept |
| 19 | 28 | .\Debug\BlueFlashTool.obj |
| ... | ... | @@ -23,17 +32,18 @@ Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP4000.tmp" with co |
| 23 | 32 | .\Debug\SysConfig.obj |
| 24 | 33 | .\Debug\BlueFlashTool.res |
| 25 | 34 | ] |
| 26 | -Creating command line "link.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP4000.tmp" | |
| 35 | +Creating command line "link.exe @C:\Users\ADMINI~1\AppData\Local\Temp\RSP186F.tmp" | |
| 27 | 36 | <h3>Output Window</h3> |
| 37 | +Compiling resources... | |
| 38 | +Compiling... | |
| 39 | +StdAfx.cpp | |
| 28 | 40 | Compiling... |
| 41 | +BlueFlashTool.cpp | |
| 29 | 42 | BlueFlashToolDlg.cpp |
| 43 | +mscomm.cpp | |
| 44 | +SysConfig.cpp | |
| 30 | 45 | Generating Code... |
| 31 | -Skipping... (no relevant changes detected) | |
| 32 | -BlueFlashTool.cpp | |
| 33 | 46 | Linking... |
| 34 | -Creating command line "bscmake.exe /nologo /o"Debug/BlueFlashTool.bsc" .\Debug\StdAfx.sbr .\Debug\BlueFlashTool.sbr .\Debug\BlueFlashToolDlg.sbr .\Debug\mscomm.sbr .\Debug\SysConfig.sbr" | |
| 35 | -Creating browse info file... | |
| 36 | -<h3>Output Window</h3> | |
| 37 | 47 | |
| 38 | 48 | |
| 39 | 49 | ... | ... |
Please
register
or
login
to post a comment