问题描述
使用海康相机读码器后文件判断错误问题
在程序初始化的时候,由于未连接相机导致初始化失败:
m_stDeviceList.nDeviceNum = 0;
int nRet = MvCodeReader.MV_CODEREADER_EnumDevices_NET(ref m_stDeviceList, MvCodeReader.MV_CODEREADER_GIGE_DEVICE);
if (0 != nRet)
{
Addlog(1, "初始化设备失败请查看读码器连接是否正常!");
return;
}
这个时候在监控里看到Environment.CurrentDirectory路径已经变成海康的相机调试软件安装地址了,但其实现在的运行地址是AppDomain.CurrentDomain.BaseDirectory的地址。
解决方案:
直接将sharpnvironment.CurrentDirectory 重新赋值
sharpnvironment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
或者直接使用 AppDomain.CurrentDomain.BaseDirectory;