记一次VSPE蓝屏问题的解决
本文仅仅是针对我遇到的这次蓝屏问题的解决,并不是所有人都会遇到由这种操作导致的蓝屏,也不是VSPE就有这个蓝屏问题。
- VSPE(Virtual Serial Ports Emulator Version 0.938 (June 26, 2010))
蓝屏复现
启动VSPE模拟串口,启动后最小化不关闭该软件。关闭计算机,关机到最后会出现蓝屏。且不生成蓝屏dump文件,怀疑生成dump的程序都已经在蓝屏出现前被关闭了。
蓝屏原因
经过检测是关机的时候没有正常关闭VSPE软件导致VSPE还在后台模拟串口(不停读取真实串口数据)导致。
解决办法
- 利用VSPE提供的API编写注销工具并将该工具放在VSPE程序的根目录下
- 编写脚本,脚本用来在Windows注销时结束VSPE程序及调用自己写的注销工具
- 在Windows 注销时调用脚本
代码
注销工具 VSPEmulator.exe 源码
//
// 用于在强制结束VPSE软件后停止所有模拟串口设备
// 将该代码编译后生成的exe放置于VSPE根目录下
//
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
// include VSPE API header and library
#include "VSPE_API.h"
#pragma comment(lib,"VSPE_API.lib")
int main()
{
// ****************************
// STEP 1 - INITIALIZATION
// ****************************
// 添加KEY
// 32位系统下的KEY免费, 在SetupVSPE.zip压缩包内的VSPE_API_32_KEY.txt文件中
const char* activationKey = "";
bool result;
// activate VSPE API
result = vspe_activate(activationKey);
if(result == false){
printf("VSPE API activation error");
return 1;
}
// initialize VSPE python binding subsystem
result = vspe_initialize();
if(result == false){
printf("Initialization error");
return 1;
}
int count = vspe_getDevicesCount();
printf("Devices count: %d\n", count);
// remove all existing devices
vspe_destroyAllDevices();
// stop current emulation
result = vspe_stopEmulation();
if(result == false)
{
printf("Error: emulation can not be stopped: maybe one of VSPE devices is still used.");
vspe_release();
return 1;
}
vspe_release();
printf("Destroy success.\n");
return 0;
}
将编译后的VSPEmulator.exe拷贝至VPSE根目录下。
KillVspe.bat脚本
taskkill /f /im VSPEmulator.exe
cd /d "C:\Program Files\Eterlogic.com\Virtual Serial Ports Emulator\"
ping 127.0.0.1 -n 3 >nul
VSPE_Destroy.exe
将KillVspe.bat脚本添加到Windows注销组策略(gpedit.msc)中,让Windows关闭时调用此脚本。