diff --git a/Aucma.Core.Scanner/Helper/MvCodeHelper.cs b/Aucma.Core.Scanner/Helper/MvCodeHelper.cs index b938ce2a..c0fc7856 100644 --- a/Aucma.Core.Scanner/Helper/MvCodeHelper.cs +++ b/Aucma.Core.Scanner/Helper/MvCodeHelper.cs @@ -1,46 +1,62 @@ -using MvCodeReaderSDKNet; +using Admin.Core.Common; +using Admin.Core.IService; +using Admin.Core.Model; +using log4net; +using MvCodeReaderSDKNet; using System.Drawing; using System.Drawing.Drawing2D; using System.Runtime.InteropServices; using System.Text; +using UAParser; +using static System.Runtime.CompilerServices.RuntimeHelpers; namespace Aucma.Core.Scanner { - public class MvCodeHelper + public class MvCodeHelper { - static MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST m_stDeviceList = new MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST(); - static MvCodeReader.MV_CODEREADER_DEVICE_INFO stDevInfo;// 通用设备信息 - private static MvCodeReader m_cMyDevice = new MvCodeReader(); - bool m_bGrabbing = true; - - // ch:用于从驱动获取图像的缓存 | en:Buffer for getting image from driver - byte[] m_BufForDriver = new byte[1024 * 1024 * 20]; - - // 显示 - Bitmap bmp = null; - Graphics gra = null; - Pen pen = new Pen(Color.Blue, 3); // 画笔颜色 - Point[] stPointList = new Point[4]; // 条码位置的4个点坐标 - GraphicsPath WayShapePath = new GraphicsPath(); // 图形路径,内部变量 - GraphicsPath OcrShapePath = new GraphicsPath(); // 图形路径,内部变量 - Matrix stRotateWay = new Matrix(); - Matrix stRotateM = new Matrix(); - Pen penOcr = new Pen(Color.Yellow, 3); - Pen penWay = new Pen(Color.Red, 3); - - #region 连接状态 + #region 委托事件 + + #region 条码绑定上位机委托事件 + /// + /// code1扫码信息刷新 + /// + /// + public delegate void ReceiveCode1(string code1); + public static event ReceiveCode1? ReceiveCode1Event; + /// + /// code2扫码信息刷新,记录表更新 + /// + /// + public delegate void ReceiveCode2(string code2); + public static event ReceiveCode2? ReceiveCode2Event; + #endregion + + #endregion + private static readonly log4net.ILog log = LogManager.GetLogger(typeof(MvCodeHelper)); + // 获取到的所有设备 + public static MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST m_stDeviceList = new MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST(); + + // 连接上的设备和其ip(string)集合 + public static Dictionary m_cMyDevices = new Dictionary(); + + + #region 设备连接状态 /// /// 获取不到任务设备即连接失败 /// /// - public bool ConnectionStatus() + public bool ConnectionStatus(string ip) { - if (0 == m_stDeviceList.nDeviceNum) + // 遍历所有已打开相机 + foreach (KeyValuePair hashmap in m_cMyDevices) { - return false; + if (ip.Equals(hashmap.Value)) + { + return true; + } } - return true; + return false; } #endregion @@ -48,120 +64,219 @@ namespace Aucma.Core.Scanner /// /// 获取设备列表 /// - public static void DeviceListAcq() + public static void DeviceListAcqAndOpen() { - // ch:创建设备列表 | en:Create Device List - System.GC.Collect(); - m_stDeviceList.nDeviceNum = 0; - int nRet = MvCodeReader.MV_CODEREADER_EnumDevices_NET(ref m_stDeviceList, MvCodeReader.MV_CODEREADER_GIGE_DEVICE); - if (0 != nRet) + try { - ShowErrorMsg("Enumerate devices fail!", nRet); - return; - } + log.Info("获取扫码器设备列表,进入DeviceListAcq()方法"); + System.GC.Collect(); + m_stDeviceList.nDeviceNum = 0; + // 获取设备列表 + int nRet = MvCodeReader.MV_CODEREADER_EnumDevices_NET(ref m_stDeviceList, MvCodeReader.MV_CODEREADER_GIGE_DEVICE); + if (0 != nRet) + { + log.Info("获取扫码器列表失败,扫码器错误码:" + nRet); + return; + } - if (0 == m_stDeviceList.nDeviceNum) - { - ShowErrorMsg("None Device!", 0); - return; - } - string strUserDefinedName = ""; - //获取设备列表 - for (int i = 0; i < m_stDeviceList.nDeviceNum; i++) - { - MvCodeReader.MV_CODEREADER_DEVICE_INFO stDevInfo = (MvCodeReader.MV_CODEREADER_DEVICE_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[i], typeof(MvCodeReader.MV_CODEREADER_DEVICE_INFO)); - if (stDevInfo.nTLayerType == MvCodeReader.MV_CODEREADER_GIGE_DEVICE) + if (0 == m_stDeviceList.nDeviceNum) { - IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(stDevInfo.SpecialInfo.stGigEInfo, 0); - MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO stGigEDeviceInfo = (MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO)); + log.Info("获取扫码器数量为0,请检查扫码器连接:"); + return; + } + + MvCodeReader m_cMyDevice = new MvCodeReader(); - if (stGigEDeviceInfo.chUserDefinedName != "") + //打开所有设备 + for (int i = 0; i < m_stDeviceList.nDeviceNum; i++) + { + MvCodeReader.MV_CODEREADER_DEVICE_INFO stDevInfo = (MvCodeReader.MV_CODEREADER_DEVICE_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[i], typeof(MvCodeReader.MV_CODEREADER_DEVICE_INFO)); + if (stDevInfo.nTLayerType == MvCodeReader.MV_CODEREADER_GIGE_DEVICE) { - byte[] byteUserDefinedName = Encoding.GetEncoding("GB2312").GetBytes(stGigEDeviceInfo.chUserDefinedName); - bool bIsValidUTF8 = IsTextUTF8(byteUserDefinedName); - if (bIsValidUTF8) + IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(stDevInfo.SpecialInfo.stGigEInfo, 0); + MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO stGigEDeviceInfo = (MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO)); + + // 获取ip + string ip = ((stGigEDeviceInfo.nCurrentIp & 0xff000000) >> 24) + "." + ((stGigEDeviceInfo.nCurrentIp & 0x00ff0000) >> 16) + "." + ((stGigEDeviceInfo.nCurrentIp & 0x0000ff00) >> 8) + "." + (stGigEDeviceInfo.nCurrentIp & 0x000000ff); + // Console.WriteLine($"打印扫码设备信息,下标:{i};IP:{ip}"); + log.Info("扫码器设备[" + i + "],ip:" + ip); + // 打开第i个设备 + stDevInfo = (MvCodeReader.MV_CODEREADER_DEVICE_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[i], typeof(MvCodeReader.MV_CODEREADER_DEVICE_INFO)); + nRet = m_cMyDevice.MV_CODEREADER_CreateHandle_NET(ref stDevInfo);//创建设备 + if (MvCodeReader.MV_CODEREADER_OK != nRet) + { + log.Error("创建第" + i + "个扫码器设备失败,ip:" + ip); + return; + } + log.Info("创建第" + i + "个扫码器设备成功,ip:" + ip); + + nRet = m_cMyDevice.MV_CODEREADER_OpenDevice_NET();//打开设备 + if (MvCodeReader.MV_CODEREADER_OK != nRet) { - strUserDefinedName = Encoding.UTF8.GetString(byteUserDefinedName); + log.Error("打开第" + i + "个扫码器设备失败,销毁设备,ip:" + ip); + m_cMyDevice.MV_CODEREADER_DestroyHandle_NET(); + return; } else { - strUserDefinedName = Encoding.GetEncoding("GB2312").GetString(byteUserDefinedName); + m_cMyDevices.Add(m_cMyDevice, ip); + log.Info("打开第" + i + "个扫码器设备成功,ip:" + ip); } - Console.WriteLine("GEV: " + strUserDefinedName + " (" + stGigEDeviceInfo.chSerialNumber + ")"); - } - else - { - Console.WriteLine("GEV: " + stGigEDeviceInfo.chManufacturerName + " " + stGigEDeviceInfo.chModelName + " (" + stGigEDeviceInfo.chSerialNumber + ")"); + + // ch:设置触发模式为off || en:set trigger mode as off + if (MvCodeReader.MV_CODEREADER_OK != m_cMyDevice.MV_CODEREADER_SetEnumValue_NET("TriggerMode", 0)) + { + log.Error("设置第" + i + "个扫码器设备触发模式失败,ip:" + ip); + return; + } + log.Info("第" + i + "个扫码器设备设置采集连续模式成功!ip:" + ip); + + // ch:开启抓图 | en:start grab + nRet = m_cMyDevice.MV_CODEREADER_StartGrabbing_NET(); + if (MvCodeReader.MV_CODEREADER_OK != nRet) + { + log.Error("设置第" + i + "个扫码器设备开启抓图失败,ip:" + ip); + return; + } + log.Info("*****************************************************************"); + log.Info("第" + i + "个扫码器设备创建,打开,开启连续抓图设置成功!ip:" + ip); } } } + catch (Exception ex) + { + log.Error("获取打开设备异常:" + ex); + } } - #endregion - #region 扫描信息 + #region 开启扫描 public static void StartGrab() { - Thread m_hReceiveThread = new Thread(ReceiveThreadProcess); - m_hReceiveThread.Start(); - } - public static void ReceiveThreadProcess() - { - int nRet = MvCodeReader.MV_CODEREADER_OK; - - IntPtr pData = IntPtr.Zero; - MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2 stFrameInfoEx2 = new MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2(); - IntPtr pstFrameInfoEx2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2))); - Marshal.StructureToPtr(stFrameInfoEx2, pstFrameInfoEx2, false); - int ik = 0; - while (true) + try { - nRet = m_cMyDevice.MV_CODEREADER_GetOneFrameTimeoutEx2_NET(ref pData, pstFrameInfoEx2, 1000); - // ch:获取一帧图像 | en:Get one image - if (MvCodeReader.MV_CODEREADER_OK == nRet) + // 所有已打开相机开始扫码 + foreach (KeyValuePair hashmap in m_cMyDevices) { - stFrameInfoEx2 = (MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)Marshal.PtrToStructure(pstFrameInfoEx2, typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)); - // 分配条码内存空间 - MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2 stBcrResult = (MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2)Marshal.PtrToStructure(stFrameInfoEx2.UnparsedBcrList.pstCodeListEx2, typeof(MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2)); - - for (int i = 0; i < stBcrResult.nCodeNum; ++i) + Task.Run(() => { - bool bIsValidUTF8 = IsTextUTF8(stBcrResult.stBcrInfoEx2[i].chCode); - if (bIsValidUTF8) - { - string strCode = System.Text.Encoding.Default.GetString(stBcrResult.stBcrInfoEx2[i].chCode); - //Console.WriteLine($"【{ik}】1条码信息[{strCode.Trim().TrimEnd('\0')}]"); - //定义自己的业务处理方式 - ik++; - } - else + // 记录相机上一次扫描到的条码 + string lastStr = string.Empty; + int nRet = MvCodeReader.MV_CODEREADER_OK; + IntPtr pData = IntPtr.Zero; + MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2 stFrameInfoEx2 = new MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2(); + IntPtr pstFrameInfoEx2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2))); + Marshal.StructureToPtr(stFrameInfoEx2, pstFrameInfoEx2, false); + int nCount = 0; + while (true) { - string strCode = System.Text.Encoding.Default.GetString(stBcrResult.stBcrInfoEx2[i].chCode); - //Console.WriteLine($"【{ik}】2条码信息[{strCode.Trim().TrimEnd('\0')}]"); - //定义自己的业务处理方式 - + nRet = hashmap.Key.MV_CODEREADER_GetOneFrameTimeoutEx2_NET(ref pData, pstFrameInfoEx2, 1000); + // ch:获取一帧图像 | en:Get one image + if (MvCodeReader.MV_CODEREADER_OK == nRet) + { + stFrameInfoEx2 = (MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)Marshal.PtrToStructure(pstFrameInfoEx2, typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)); + // 分配条码内存空间 + MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2 stBcrResult = (MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2)Marshal.PtrToStructure(stFrameInfoEx2.UnparsedBcrList.pstCodeListEx2, typeof(MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2)); + for (int i = 0; i < stBcrResult.nCodeNum; ++i) + { + bool bIsValidUTF8 = IsTextUTF8(stBcrResult.stBcrInfoEx2[i].chCode); + if (bIsValidUTF8) + { + // string strCode = System.Text.Encoding.Default.GetString(stBcrResult.stBcrInfoEx2[i].chCode); + string strCode = Encoding.UTF8.GetString(stBcrResult.stBcrInfoEx2[i].chCode); + log.Info("bIsValidUTF8:: Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]"); + } + else + { + byte[] buffer = new byte[22]; + if (stBcrResult.stBcrInfoEx2[i].chCode.Length > 0) + { + Array.Copy(stBcrResult.stBcrInfoEx2[i].chCode, buffer, 22); + } + string strCode = Encoding.GetEncoding("UTF-8").GetString(buffer).Trim().TrimEnd('\0'); + log.Info("相机ip:" + hashmap.Value + " Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode + "]"); + if (!string.IsNullOrEmpty(strCode)) + { + if (strCode != lastStr) + { + // 处理业务 + // 扫码器1,处理扫码器1的业务 + if (hashmap.Value.Equals(Appsettings.app("Middleware", "Scanner1", "Ip"))) + { + ReceiveCode1Event?.Invoke(strCode); + } + else if (hashmap.Value.Equals(Appsettings.app("Middleware", "Scanner2", "Ip"))) + { + // 扫码器2,处理扫码器2的业务 + ReceiveCode2Event?.Invoke(strCode); + } + + } + lastStr = strCode; + } + } + } + } + Thread.Sleep(500); + } - } - //MvCodeReader.MV_CODEREADER_OCR_INFO_LIST stOcrInfo = (MvCodeReader.MV_CODEREADER_OCR_INFO_LIST)Marshal.PtrToStructure(stFrameInfoEx2.UnparsedOcrList.pstOcrList, typeof(MvCodeReader.MV_CODEREADER_OCR_INFO_LIST)); + }); - //for (int i = 0; i < stOcrInfo.nOCRAllNum; i++) - //{ - // string strOcrCharCode = System.Text.Encoding.Default.GetString(stOcrInfo.stOcrRowInfo[i].chOcr); - // Console.WriteLine("Get OcrInfo:" + "ocrNum[" + i.ToString() + "], ocrLen[" + Convert.ToString(stOcrInfo.stOcrRowInfo[i].nOcrLen) + "], ocrChar[" + strOcrCharCode.Trim().TrimEnd('\0') + "]"); - //} } - else + } + catch (Exception ex) + { + log.Error("开启相机扫描异常:" + ex); + } + + } + #endregion + + #region 关闭设备 + public static void CloseDevice() + { + try + { + log.Info("开始关闭所有设备"); + int nRet = MvCodeReader.MV_CODEREADER_OK; + // 关闭所有已打开相机 + foreach (KeyValuePair hashmap in m_cMyDevices) { - Console.WriteLine("没有获取到数据:{0:x8}", nRet); - //重新获取数据 - MvCodeHelper.DeviceListAcq();//获取设备 - MvCodeHelper.OpenDevice();//打开设备 + // ch:停止抓图 | en:Stop grab image + nRet = hashmap.Key.MV_CODEREADER_StopGrabbing_NET(); + if (MvCodeReader.MV_CODEREADER_OK != nRet) + { + log.Error("设备ip:" + hashmap.Value + "停止抓图失败"); + Console.WriteLine("Stop grabbing failed{0:x8}", nRet); + } + // ch:关闭设备 | en:Close device + nRet = hashmap.Key.MV_CODEREADER_CloseDevice_NET(); + if (MvCodeReader.MV_CODEREADER_OK != nRet) + { + log.Error("设备ip:" + hashmap.Value + "关闭失败"); + + } + + // ch:销毁设备 | en:Destroy device + nRet = hashmap.Key.MV_CODEREADER_DestroyHandle_NET(); + if (MvCodeReader.MV_CODEREADER_OK != nRet) + { + log.Error("设备ip:" + hashmap.Value + "销毁失败"); + } + log.Error("设备ip:" + hashmap.Value + "关闭成功!"); } } - } + catch (Exception ex) + { + log.Error("设备关闭异常:" + ex); + } + + + } #endregion + #region 判断字符编码 /// /// 判断字符编码 @@ -235,105 +350,6 @@ namespace Aucma.Core.Scanner #endregion - #region 打开设备 - public static void OpenDevice() - { - if (m_stDeviceList.nDeviceNum == 0) - { - ShowErrorMsg("No stDevInfo, please select", 0); - return ; - } - - // ch:获取选择的设备信息 | en:Get selected stDevInfo information - stDevInfo =(MvCodeReader.MV_CODEREADER_DEVICE_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[0], typeof(MvCodeReader.MV_CODEREADER_DEVICE_INFO)); - - // ch:打开设备 | en:Open stDevInfo - if (null == m_cMyDevice) - { - m_cMyDevice = new MvCodeReader(); - if (null == m_cMyDevice) - { - return; - } - } - - int nRet = m_cMyDevice.MV_CODEREADER_CreateHandle_NET(ref stDevInfo);//创建设备 - if (MvCodeReader.MV_CODEREADER_OK != nRet) - { - ShowErrorMsg("创建设备 fail!", nRet); - return; - } - Console.WriteLine("创建设备成功!"); - nRet = m_cMyDevice.MV_CODEREADER_OpenDevice_NET();//打开设备 - if (MvCodeReader.MV_CODEREADER_OK != nRet) - { - m_cMyDevice.MV_CODEREADER_DestroyHandle_NET(); - ShowErrorMsg("Device open fail!", nRet); - return; - } - Console.WriteLine("打开设备成功!"); - - // ch:设置触发模式为off || en:set trigger mode as off - if (MvCodeReader.MV_CODEREADER_OK != m_cMyDevice.MV_CODEREADER_SetEnumValue_NET("TriggerMode", 0)) - { - Console.WriteLine("Set TriggerMode failed!"); - return; - } - Console.WriteLine("设置采集连续模式成功!"); - - // ch:开启抓图 | en:start grab - nRet = m_cMyDevice.MV_CODEREADER_StartGrabbing_NET(); - if (MvCodeReader.MV_CODEREADER_OK != nRet) - { - Console.WriteLine("Start grabbing failed:{0:x8}", nRet); - return; - } - Console.WriteLine("开启抓图成功!"); - - Console.WriteLine("设备已经开启"); - } - - #endregion - - #region 关闭设备 - public static void CloseDevice() - { - int nRet = MvCodeReader.MV_CODEREADER_OK; - // ch:停止抓图 | en:Stop grab image - nRet = m_cMyDevice.MV_CODEREADER_StopGrabbing_NET(); - if (MvCodeReader.MV_CODEREADER_OK != nRet) - { - Console.WriteLine("Stop grabbing failed{0:x8}", nRet); - } - // ch:关闭设备 | en:Close device - nRet = m_cMyDevice.MV_CODEREADER_CloseDevice_NET(); - if (MvCodeReader.MV_CODEREADER_OK != nRet) - { - Console.WriteLine("Close device failed{0:x8}", nRet); - - } - - // ch:销毁设备 | en:Destroy device - nRet = m_cMyDevice.MV_CODEREADER_DestroyHandle_NET(); - if (MvCodeReader.MV_CODEREADER_OK != nRet) - { - Console.WriteLine("Destroy device failed:{0:x8}", nRet); - } - - - //if (MvCodeReader.MV_CODEREADER_OK != nRet) - //{ - // // ch:销毁设备 | en:Destroy device - // nRet = m_cMyDevice.MV_CODEREADER_DestroyHandle_NET(); - // if (MvCodeReader.MV_CODEREADER_OK != nRet) - // { - // Console.WriteLine("Destroy device failed:{0:x8}", nRet); - // } - //} - Console.WriteLine("设备已经关闭"); - } - #endregion - #region 将Byte转换为结构体类型 //将Byte转换为结构体类型 public static object ByteToStruct(byte[] bytes, Type type) @@ -355,48 +371,7 @@ namespace Aucma.Core.Scanner } #endregion - #region 异常信息展示 - /// - /// 异常信息展示 - /// - /// - /// - private static void ShowErrorMsg(string csMessage, int nErrorNum) - { - string errorMsg; - if (nErrorNum == 0) - { - errorMsg = csMessage; - } - else - { - errorMsg = csMessage + ": Error =" + String.Format("{0:X}", nErrorNum); - } - - switch (nErrorNum) - { - case MvCodeReader.MV_CODEREADER_E_HANDLE: errorMsg += " Error or invalid handle "; break; - case MvCodeReader.MV_CODEREADER_E_SUPPORT: errorMsg += " Not supported function "; break; - case MvCodeReader.MV_CODEREADER_E_BUFOVER: errorMsg += " Cache is full "; break; - case MvCodeReader.MV_CODEREADER_E_CALLORDER: errorMsg += " Function calling order error "; break; - case MvCodeReader.MV_CODEREADER_E_PARAMETER: errorMsg += " Incorrect parameter "; break; - case MvCodeReader.MV_CODEREADER_E_RESOURCE: errorMsg += " Applying resource failed "; break; - case MvCodeReader.MV_CODEREADER_E_NODATA: errorMsg += " No data "; break; - case MvCodeReader.MV_CODEREADER_E_PRECONDITION: errorMsg += " Precondition error, or running environment changed "; break; - case MvCodeReader.MV_CODEREADER_E_VERSION: errorMsg += " Version mismatches "; break; - case MvCodeReader.MV_CODEREADER_E_NOENOUGH_BUF: errorMsg += " Insufficient memory "; break; - case MvCodeReader.MV_CODEREADER_E_UNKNOW: errorMsg += " Unknown error "; break; - case MvCodeReader.MV_CODEREADER_E_GC_GENERIC: errorMsg += " General error "; break; - case MvCodeReader.MV_CODEREADER_E_GC_ACCESS: errorMsg += " Node accessing condition error "; break; - case MvCodeReader.MV_CODEREADER_E_ACCESS_DENIED: errorMsg += " No permission "; break; - case MvCodeReader.MV_CODEREADER_E_BUSY: errorMsg += " Device is busy, or network disconnected "; break; - case MvCodeReader.MV_CODEREADER_E_NETER: errorMsg += " Network error "; break; - } - Console.WriteLine(errorMsg, "PROMPT"); - } - - #endregion } } diff --git a/Aucma.Core.Scanner/Scanner/ScannerService.cs b/Aucma.Core.Scanner/Scanner/ScannerService.cs index ac18eac6..5dd98b3e 100644 --- a/Aucma.Core.Scanner/Scanner/ScannerService.cs +++ b/Aucma.Core.Scanner/Scanner/ScannerService.cs @@ -1,4 +1,5 @@ -using log4net; +using Admin.Core.Common; +using log4net; namespace Aucma.Core.Scanner { @@ -12,9 +13,11 @@ namespace Aucma.Core.Scanner { try { - MvCodeHelper.DeviceListAcq();//获取设备 - MvCodeHelper.OpenDevice();//打开设备 + + MvCodeHelper.DeviceListAcqAndOpen();//获取设备 + MvCodeHelper.StartGrab();//获取数据 + } catch (Exception ex) {