diff --git a/.vs/HighWayIot/FileContentIndex/6b057eb9-b33f-449d-9787-a24cca2e6682.vsidx b/.vs/HighWayIot/FileContentIndex/6b057eb9-b33f-449d-9787-a24cca2e6682.vsidx deleted file mode 100644 index 0bef7fdb..00000000 Binary files a/.vs/HighWayIot/FileContentIndex/6b057eb9-b33f-449d-9787-a24cca2e6682.vsidx and /dev/null differ diff --git a/.vs/HighWayIot/FileContentIndex/ebf823f5-8490-40d9-8696-ab31227d1a2c.vsidx b/.vs/HighWayIot/FileContentIndex/ebf823f5-8490-40d9-8696-ab31227d1a2c.vsidx deleted file mode 100644 index 0c86fe95..00000000 Binary files a/.vs/HighWayIot/FileContentIndex/ebf823f5-8490-40d9-8696-ab31227d1a2c.vsidx and /dev/null differ diff --git a/.vs/HighWayIot/v17/.suo b/.vs/HighWayIot/v17/.suo index b40aa314..0f6f0b34 100644 Binary files a/.vs/HighWayIot/v17/.suo and b/.vs/HighWayIot/v17/.suo differ diff --git a/Aucma.Scada.Business/InStoreBusiness.cs b/Aucma.Scada.Business/InStoreBusiness.cs index 09e48f79..1704664a 100644 --- a/Aucma.Scada.Business/InStoreBusiness.cs +++ b/Aucma.Scada.Business/InStoreBusiness.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Timers; +using static Aucma.Core.Scanner.MvCodeHelper; using static Aucma.Scada.Business.InStoreTaskHandle; namespace Aucma.Scada.Business @@ -115,9 +116,10 @@ namespace Aucma.Scada.Business _productPlanInfoServices = registerServices.GetService(); taskHandle.InStoreFinsihEvent += InStoreFinish; taskHandle.InStoreAnswerEvent += InStoreAnswer; - + MvCodeHelper.RefreshMaterialCodeStrEvent += InStore; MvCodeHelper.RefreshLogMessageEvent += PrintLogInfoMessage; + MvCodeHelper.MessageNoReadEvent += MessageNoRead; StartPassDown(); @@ -191,6 +193,9 @@ namespace Aucma.Scada.Business { try { + // plc报警信息清除 + taskHandle.SendPlcWarnInfo(0); + PrintLogInfoMessage($"扫码成功,物料码:{materialCode}"); string materialType = SubStringMaterialCode(materialCode); // 加防呆,判断任务表是否有任务了 @@ -228,6 +233,9 @@ namespace Aucma.Scada.Business { //报警停线 PrintLogInfoMessage($"物料码:{materialCode};未匹配到可用货道"); + // 下发plc报警信息 + taskHandle.SendPlcWarnInfo(2); + } } catch (Exception ex) @@ -475,6 +483,20 @@ namespace Aucma.Scada.Business logHelper.Info(message); } + /// + /// 未扫描上条码 + /// + /// + private void MessageNoRead() + { + + PrintLogInfoMessage("PrintLogInfoMessage"); + // 下发plc报警信号 + taskHandle.SendPlcWarnInfo(1); + + } + + /// /// 异常日志输出 /// @@ -575,7 +597,7 @@ namespace Aucma.Scada.Business if (list.Count > 0) { - result = list.OrderByDescending(x => x.spaceStock).OrderBy(x => x.spaceCode).First(); + result = list.OrderByDescending(x => x.spaceStock).First(); } } } diff --git a/Aucma.Scada.Business/InStoreTaskHandle.cs b/Aucma.Scada.Business/InStoreTaskHandle.cs index 478b8f48..b3eadf18 100644 --- a/Aucma.Scada.Business/InStoreTaskHandle.cs +++ b/Aucma.Scada.Business/InStoreTaskHandle.cs @@ -116,20 +116,27 @@ namespace Aucma.Scada.Business { Task.Run(() => { - Thread.Sleep(3000); - IPlc _plc = _plcDictionary[appConfig.foamStoreCode]; - - if (_plc != null) + try { - while (true) + Thread.Sleep(3000); + IPlc _plc = _plcDictionary[appConfig.foamStoreCode]; + + if (_plc != null) { - _plc.writeInt32ByAddress("D7020",1); - Thread.Sleep(1000); - _plc.writeInt32ByAddress("D7020", 0); - Thread.Sleep(1000); + while (true) + { + _plc.writeInt32ByAddress("D7020", 1); + Thread.Sleep(1000); + _plc.writeInt32ByAddress("D7020", 0); + Thread.Sleep(1000); + } } - } + } + catch (Exception ex) + { + logHelper.Error(ex.Message.ToString()); + } }); } #region 判断入库是否完成 delete20240224-入库完成信号改回监测在途数 @@ -271,8 +278,7 @@ namespace Aucma.Scada.Business if (_plc != null) { - // 测试方法,模拟plc,正式启用删除 - // _plc.writeInt32ByAddress(plcConfig.in_foam_answer, 1); + if (_plc.readInt32ByAddress(plcConfig.in_foam_answer) == 1) { logHelper.Info("泡后入库应答字为1,货道号:" + plcConfig.in_foam_spaceCode + ";写" + short.Parse(taskInfo.spaceCode.Substring(5, 1))); @@ -359,14 +365,39 @@ namespace Aucma.Scada.Business } } } - #endregion + #endregion - /// - /// 通过PLC获取货道信息 - /// - /// - /// - public BaseSpaceInfo ReadSpaceInfoByPlc(BaseSpaceInfo spaceInfo) + + /// + /// 0正常,清除plc报警信息,1-扫码失败;2-库满,未匹配到可用货道 + /// + /// + #region 泡后库plc报警信息 + public void SendPlcWarnInfo(short flag) + { + try + { + + IPlc _plc = _plcDictionary[appConfig.foamStoreCode]; + + if (_plc != null) + { + _plc.writeInt32ByAddress("D7018", flag); + } + } + catch (Exception ex) + { + logHelper.Error(ex.Message.ToString()); + } + + } + #endregion + /// + /// 通过PLC获取货道信息 + /// + /// + /// + public BaseSpaceInfo ReadSpaceInfoByPlc(BaseSpaceInfo spaceInfo) { var spaceAddress = spaceConfig.GetSpaceAddress(spaceInfo.storeCode, spaceInfo.spaceCode); IPlc _plc = _plcDictionary[spaceInfo.storeCode]; diff --git a/Aucma.Scada.Business/OutStoreBusiness.cs b/Aucma.Scada.Business/OutStoreBusiness.cs index c2f77873..bd67b7ad 100644 --- a/Aucma.Scada.Business/OutStoreBusiness.cs +++ b/Aucma.Scada.Business/OutStoreBusiness.cs @@ -782,7 +782,7 @@ namespace Aucma.Scada.Business if (list.Count > 0) { - result = info.OrderBy(x => x.spaceStock).OrderBy(x => x.spaceCode).First(); + result = info.OrderBy(x => x.spaceStock).First(); } else { diff --git a/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.dll b/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.dll index 7c923d9e..cd33e441 100644 Binary files a/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.dll and b/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.dll differ diff --git a/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.pdb b/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.pdb index b385f384..13977dc1 100644 Binary files a/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.pdb and b/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.pdb differ diff --git a/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.dll b/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.dll index 7c923d9e..cd33e441 100644 Binary files a/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.dll and b/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.dll differ diff --git a/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.pdb b/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.pdb index b385f384..13977dc1 100644 Binary files a/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.pdb and b/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.pdb differ diff --git a/Aucma.Scada.HikRobot/MvCodeHelper.cs b/Aucma.Scada.HikRobot/MvCodeHelper.cs index 543d8bf1..68a09bee 100644 --- a/Aucma.Scada.HikRobot/MvCodeHelper.cs +++ b/Aucma.Scada.HikRobot/MvCodeHelper.cs @@ -14,10 +14,35 @@ namespace Aucma.Core.Scanner { public class MvCodeHelper { + + private static LogHelper logHelper = LogHelper.Instance; private static AppConfig appConfig = AppConfig.Instance; public static bool m_bGrabbing = true; + private static string SheellLastCode; + // 箱壳扫码器ip + private static string ShellScannerIp = appConfig.foamHikRobotIp; + #region 全局变量定义 + + public static DateTime ShellLiveTime = DateTime.Now; + + #endregion + #region 委托事件 + + /// + /// 刷新扫码器状态 + /// + /// + /// + public delegate void RefreshState(bool flag); + public static event RefreshState RefreshStateEvent; + + //NoRead事件通知 + public delegate void MessageNoRead(); + public static event MessageNoRead MessageNoReadEvent; + + public delegate void RefreshMaterialCodeStr(string materialCodeStr); public static event RefreshMaterialCodeStr RefreshMaterialCodeStrEvent; /// @@ -28,266 +53,224 @@ namespace Aucma.Core.Scanner public static event RefreshLogMessage RefreshLogMessageEvent; #endregion - // 获取到的所有设备 - public static MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST m_stDeviceList = new MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST(); + public static void ShellImageCallbackFunc(IntPtr pData, IntPtr pstFrameInfoEx2, IntPtr pUser) + { + var stFrameInfo = (MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)Marshal.PtrToStructure(pstFrameInfoEx2, typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)); - // (成功创建)连接上的设备和其ip(string)集合 - public static Dictionary m_cMyDevices = new Dictionary(); + MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2 stBcrResult = (MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2)Marshal.PtrToStructure(stFrameInfo.UnparsedBcrList.pstCodeListEx2, typeof(MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2)); - #region 设备连接状态 - /// - /// 获取不到任务设备即连接失败 - /// - /// - public static bool ConnectionStatus(string ip) - { - try + // Console.WriteLine("CodeNum[" + Convert.ToString(stBcrResult.nCodeNum) + "]"); + if (stBcrResult.nCodeNum == 0) { - // 遍历所有已打开相机 - foreach (KeyValuePair hashmap in m_cMyDevices) + //更新扫码器存活时间 + ShellLiveTime = DateTime.Now; + Console.WriteLine("箱壳No Read 处理"); + MessageNoReadEvent(); + + } + for (Int32 i = 0; i < stBcrResult.nCodeNum; i++) + { + bool bIsValidUTF8 = IsTextUTF8(stBcrResult.stBcrInfoEx2[i].chCode); + if (bIsValidUTF8) + { + string strCode = Encoding.UTF8.GetString(stBcrResult.stBcrInfoEx2[i].chCode); + Console.WriteLine("Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]"); + } + else { - if (ip.Equals(hashmap.Value)) + string strCode = Encoding.GetEncoding("GB2312").GetString(stBcrResult.stBcrInfoEx2[i].chCode); + Console.WriteLine(DateTime.Now + ":箱壳扫码器==>Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]"); + + if (string.IsNullOrEmpty(SheellLastCode) || SheellLastCode != strCode.Trim().TrimEnd('\0')) + { + //更新扫码器存活时间 + ShellLiveTime = DateTime.Now; + RefreshMaterialCodeStrEvent?.Invoke(strCode.Trim().TrimEnd('\0')); + SheellLastCode = strCode.Trim().TrimEnd('\0'); + } + if (SheellLastCode == strCode.Trim().TrimEnd('\0')) { - return true; + Console.WriteLine("箱壳和上次扫描结果一样,不作处理"); } + } - // 没有连接上,重新获取并创建设备 - Task.Run(() => - { - DeviceListAcq(); - }); - } - catch (Exception ex) + + MvCodeReader.MV_CODEREADER_OCR_INFO_LIST stOcrInfo = (MvCodeReader.MV_CODEREADER_OCR_INFO_LIST)Marshal.PtrToStructure(stFrameInfo.UnparsedOcrList.pstOcrList, typeof(MvCodeReader.MV_CODEREADER_OCR_INFO_LIST)); + + for (int i = 0; i < stOcrInfo.nOCRAllNum; i++) { - logHelper.Error(ex.Message.ToString()); + string strOcrCharCode = Encoding.UTF8.GetString(stOcrInfo.stOcrRowInfo[i].chOcr); + Console.WriteLine("Get OcrInfo:" + "ocrNum[" + i.ToString() + "], ocrLen[" + Convert.ToString(stOcrInfo.stOcrRowInfo[i].nOcrLen) + "], ocrChar[" + strOcrCharCode.Trim().TrimEnd('\0') + "]"); } - return false; } - #endregion - #region 获取并创建设备列表 - /// - /// 获取并创建设备列表 - /// - public static void DeviceListAcq() + + public static void Shell() { - try + ShellLiveTime = DateTime.Now; + MvCodeReader.cbOutputEx2delegate ImageCallback; + + MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2 stFrameInfo = new MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2(); + MvCodeReader device = new MvCodeReader(); + int nRet = MvCodeReader.MV_CODEREADER_OK; + + do { - // RefreshLogMessageEvent?.Invoke("获取扫码器设备列表,进入DeviceListAcq()方法"); - // 扫码器ip - string scannerIp = appConfig.foamHikRobotIp; - if (string.IsNullOrEmpty(scannerIp)) return; - 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) + // ch:枚举设备 | en:Enum device + MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST stDevList = new MvCodeReader.MV_CODEREADER_DEVICE_INFO_LIST(); + nRet = MvCodeReader.MV_CODEREADER_EnumDevices_NET(ref stDevList, MvCodeReader.MV_CODEREADER_GIGE_DEVICE); + if (MvCodeReader.MV_CODEREADER_OK != nRet) { - logHelper.Info("获取扫码器列表失败,扫码器错误码:" + nRet); - RefreshLogMessageEvent?.Invoke("获取扫码器列表失败,扫码器错误码:" + nRet); - - return; - } + // 刷新扫码器状态 + RefreshStateEvent?.Invoke(false); - if (0 == m_stDeviceList.nDeviceNum) - { - - // RefreshLogMessageEvent?.Invoke("获取扫码器数量为0,请检查扫码器连接:"); - return; + RefreshStateEvent?.Invoke(false); + Thread.Sleep(1000 * 10); + Console.WriteLine("Enum device failed:{0:x8}", nRet); + break; } + Console.WriteLine("Enum device count : " + Convert.ToString(stDevList.nDeviceNum)); + if (0 == stDevList.nDeviceNum) + { + // 刷新扫码器状态 + RefreshStateEvent?.Invoke(false); - MvCodeReader m_cMyDevice = new MvCodeReader(); + RefreshStateEvent?.Invoke(false); + Thread.Sleep(1000 * 10); - //创建所有设备 - for (int i = 0; i < m_stDeviceList.nDeviceNum; i++) + break; + } + + MvCodeReader.MV_CODEREADER_DEVICE_INFO stDevInfo; // 通用设备信息 + int nDevIndex = -1; + // ch:打印设备信息 | en:Print device info + for (Int32 i = 0; i < stDevList.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) + stDevInfo = (MvCodeReader.MV_CODEREADER_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[i], typeof(MvCodeReader.MV_CODEREADER_DEVICE_INFO)); + + if (MvCodeReader.MV_CODEREADER_GIGE_DEVICE == stDevInfo.nTLayerType) { - 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); - // 只连接配置的扫码器 - if (!scannerIp.Equals(ip)) continue; - // 创建第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) + MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO stGigEDeviceInfo = (MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO)MvCodeReader.ByteToStruct(stDevInfo.SpecialInfo.stGigEInfo, typeof(MvCodeReader.MV_CODEREADER_GIGE_DEVICE_INFO)); + uint nIp1 = ((stGigEDeviceInfo.nCurrentIp & 0xff000000) >> 24); + uint nIp2 = ((stGigEDeviceInfo.nCurrentIp & 0x00ff0000) >> 16); + uint nIp3 = ((stGigEDeviceInfo.nCurrentIp & 0x0000ff00) >> 8); + uint nIp4 = (stGigEDeviceInfo.nCurrentIp & 0x000000ff); + // Console.WriteLine("\n" + i.ToString() + ": [GigE] User Define Name : " + stGigEDeviceInfo.chUserDefinedName); + // Console.WriteLine("device IP :" + nIp1 + "." + nIp2 + "." + nIp3 + "." + nIp4); + string ipStr = nIp1 + "." + nIp2 + "." + nIp3 + "." + nIp4; + if (ipStr == ShellScannerIp) { - // Console.WriteLine("创建第" + i + "个扫码器设备失败,ip:" + ip); - return; - } - // 打开设备 - nRet = m_cMyDevice.MV_CODEREADER_OpenDevice_NET(); - if (MvCodeReader.MV_CODEREADER_OK != nRet) - { - m_cMyDevice.MV_CODEREADER_DestroyHandle_NET(); - // Console.WriteLine("Device open fail!"); - return; - } - // RefreshLogMessageEvent?.Invoke("创建并打开第" + i + "个扫码器设备成功,ip:" + ip); - //设置触发模式 - nRet = m_cMyDevice.MV_CODEREADER_SetEnumValue_NET("TriggerMode", (uint)MvCodeReader.MV_CODEREADER_TRIGGER_MODE.MV_CODEREADER_TRIGGER_MODE_ON); - if (MvCodeReader.MV_CODEREADER_OK != nRet) - { - // Console.WriteLine("设置触发模式失败"); - return; + nDevIndex = i; + Console.WriteLine("device IP :" + ipStr); + } - //添加到集合 - m_cMyDevices.Add(m_cMyDevice, ip); } } - } - catch (Exception ex) - { - logHelper.Error("获取和创建扫码器设备异常:" + ex.Message.ToString()); - } - } - #endregion - + if (nDevIndex < 0) + { + Console.WriteLine("未找到箱壳扫码器"); + // 刷新扫码器状态 + RefreshStateEvent?.Invoke(false); + Thread.Sleep(1000 * 30); + break; + } + stDevInfo = (MvCodeReader.MV_CODEREADER_DEVICE_INFO)Marshal.PtrToStructure(stDevList.pDeviceInfo[nDevIndex], typeof(MvCodeReader.MV_CODEREADER_DEVICE_INFO)); - #region 光电触发扫码器接收条码处理业务 - public static void StartGrab() - { - try - { - int nRet = MvCodeReader.MV_CODEREADER_OK; - // 3.开启抓图 - int nCount = 0; - 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); - - foreach (KeyValuePair hashmap in m_cMyDevices) + // ch:创建设备 | en:Create device + nRet = device.MV_CODEREADER_CreateHandle_NET(ref stDevInfo); + if (MvCodeReader.MV_CODEREADER_OK != nRet) { - nRet = hashmap.Key.MV_CODEREADER_StartGrabbing_NET(); - while (m_bGrabbing) - { - // 光电触发了有图像 - 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); - // logHelper.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'); - // RefreshLogMessageEvent?.Invoke("相机ip:" + hashmap.Value + " Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode + "]"); - if (!string.IsNullOrEmpty(strCode)) - { - logHelper.Info("扫码器扫描到条码:"+strCode); - // 获取到条码处理业务 - RefreshMaterialCodeStrEvent?.Invoke(strCode); - - } - } - } - } - Thread.Sleep(500); + Console.WriteLine("Create device failed:{0:x8}", nRet); + // 刷新扫码器状态 + RefreshStateEvent?.Invoke(false); + break; + } - } + // ch:打开设备 | en:Open device + nRet = device.MV_CODEREADER_OpenDevice_NET(); + if (MvCodeReader.MV_CODEREADER_OK != nRet) + { + Console.WriteLine("Open device failed:{0:x8}", nRet); + // 刷新扫码器状态 + RefreshStateEvent?.Invoke(false); + break; } - } - catch (Exception ex) - { - Console.WriteLine("扫码异常:" + ex); - } - } - #endregion + // 刷新扫码器状态 + RefreshStateEvent?.Invoke(true); + // ch:注册回调函数 | en:Register image callback + ImageCallback = new MvCodeReader.cbOutputEx2delegate(ShellImageCallbackFunc); + nRet = device.MV_CODEREADER_RegisterImageCallBackEx2_NET(ImageCallback, IntPtr.Zero); + if (MvCodeReader.MV_CODEREADER_OK != nRet) + { + Console.WriteLine("Register image callback failed!"); + // 刷新扫码器状态 + RefreshStateEvent?.Invoke(false); + break; + } - #region 关闭所有设备 - public static void CloseAllDevice() - { - try - { - Console.WriteLine("开始关闭所有设备"); - int nRet = MvCodeReader.MV_CODEREADER_OK; - // 关闭所有已打开相机 - foreach (KeyValuePair hashmap in m_cMyDevices) + // ch:开启抓图 || en: start grab image + nRet = device.MV_CODEREADER_StartGrabbing_NET(); + if (MvCodeReader.MV_CODEREADER_OK != nRet) { - // ch:停止抓图 | en:Stop grab image - nRet = hashmap.Key.MV_CODEREADER_StopGrabbing_NET(); - if (MvCodeReader.MV_CODEREADER_OK != nRet) - { - Console.WriteLine("设备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) - { - Console.WriteLine("设备ip:" + hashmap.Value + "关闭失败"); + Console.WriteLine("Start grabbing failed:{0:x8}", nRet); + // 刷新扫码器状态 + RefreshStateEvent?.Invoke(false); + break; + } - } - // ch:销毁设备 | en:Destroy device - nRet = hashmap.Key.MV_CODEREADER_DestroyHandle_NET(); - if (MvCodeReader.MV_CODEREADER_OK != nRet) + Console.WriteLine("Press enter to exit"); + Console.WriteLine(DateTime.Now.ToString()); + while (true) + { + Thread.Sleep(1000 * 60); + DateTime dateTime = DateTime.Now; + TimeSpan timeSpan = dateTime.Subtract(ShellLiveTime); + if (timeSpan.TotalMinutes >= 10) { - Console.WriteLine("设备ip:" + hashmap.Value + "销毁失败"); + Console.WriteLine("箱壳扫码器超时"); + //CloseShell(); + //Shell(); + break; } - Console.WriteLine("设备ip:" + hashmap.Value + "关闭成功!"); - } - } - catch (Exception ex) - { - Console.WriteLine("设备关闭异常:" + ex); - } - - - } - #endregion - #region 关闭指定设备 - public void CloseDevice(KeyValuePair hashmap) - { - try - { - int nRet = MvCodeReader.MV_CODEREADER_OK; - // ch:停止抓图 | en:Stop grab image - nRet = hashmap.Key.MV_CODEREADER_StopGrabbing_NET(); + } + // Console.ReadLine(); + // 刷新扫码器状态 + RefreshStateEvent?.Invoke(false); + // ch:停止抓图 | en:Stop grabbing + nRet = device.MV_CODEREADER_StopGrabbing_NET(); if (MvCodeReader.MV_CODEREADER_OK != nRet) { - Console.WriteLine("设备ip:" + hashmap.Value + "停止抓图失败"); Console.WriteLine("Stop grabbing failed{0:x8}", nRet); - return; + break; } + // ch:关闭设备 | en:Close device - nRet = hashmap.Key.MV_CODEREADER_CloseDevice_NET(); + nRet = device.MV_CODEREADER_CloseDevice_NET(); if (MvCodeReader.MV_CODEREADER_OK != nRet) { - Console.WriteLine("设备ip:" + hashmap.Value + "关闭失败"); - return; + Console.WriteLine("Close device failed{0:x8}", nRet); + break; } - } - catch (Exception ex) - { - Console.WriteLine("设备关闭异常:" + ex); - } + + // ch:销毁设备 | en:Destroy device + nRet = device.MV_CODEREADER_DestroyHandle_NET(); + if (MvCodeReader.MV_CODEREADER_OK != nRet) + { + Console.WriteLine("Destroy device failed:{0:x8}", nRet); + break; + } + } while (false); + Thread.Sleep(1000); + Shell(); + } - #endregion + + #region 判断字符编码 @@ -363,27 +346,6 @@ namespace Aucma.Core.Scanner #endregion - #region 将Byte转换为结构体类型 - //将Byte转换为结构体类型 - public static object ByteToStruct(byte[] bytes, Type type) - { - int size = Marshal.SizeOf(type); - if (size > bytes.Length) - { - return null; - } - //分配结构体内存空间 - IntPtr structPtr = Marshal.AllocHGlobal(size); - //将byte数组拷贝到分配好的内存空间 - Marshal.Copy(bytes, 0, structPtr, size); - //将内存空间转换为目标结构体 - object obj = Marshal.PtrToStructure(structPtr, type); - //释放内存空间 - Marshal.FreeHGlobal(structPtr); - return obj; - } - #endregion - } diff --git a/Aucma.Scada.UI/Page/AssemblyPlan/PlanInfoEditWindow.xaml b/Aucma.Scada.UI/Page/AssemblyPlan/PlanInfoEditWindow.xaml index 2d5b0a73..9f5dd009 100644 --- a/Aucma.Scada.UI/Page/AssemblyPlan/PlanInfoEditWindow.xaml +++ b/Aucma.Scada.UI/Page/AssemblyPlan/PlanInfoEditWindow.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:Aucma.Scada.UI.Page.AssemblyPlan" xmlns:local1="clr-namespace:Aucma.Scada.UI.Converter.AssemblyPlan" mc:Ignorable="d" - Title="MES生产计划" Height="650" Width="1000" Name="window" WindowStartupLocation="CenterScreen" FontFamily="Microsoft YaHei" Background="#1152AC" + Title="MES生产计划" Height="800" Width="1500" Name="window" WindowStartupLocation="CenterScreen" FontFamily="Microsoft YaHei" Background="#1152AC" ResizeMode="NoResize" > + + diff --git a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.dll b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.dll index 7c923d9e..cd33e441 100644 Binary files a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.dll and b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.dll differ diff --git a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.pdb b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.pdb index b385f384..13977dc1 100644 Binary files a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.pdb and b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.pdb differ diff --git a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.UI.exe b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.UI.exe index d9aba616..aa7a3c4c 100644 Binary files a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.UI.exe and b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.UI.exe differ diff --git a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.UI.pdb b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.UI.pdb index 95780490..757d3897 100644 Binary files a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.UI.pdb and b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.UI.pdb differ diff --git a/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.csproj.AssemblyReference.cache b/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.csproj.AssemblyReference.cache index d4722b0e..443c8e35 100644 Binary files a/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.csproj.AssemblyReference.cache and b/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.csproj.AssemblyReference.cache differ diff --git a/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.exe b/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.exe index d9aba616..aa7a3c4c 100644 Binary files a/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.exe and b/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.exe differ diff --git a/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.g.resources b/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.g.resources index 15ee4a80..50d4f668 100644 Binary files a/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.g.resources and b/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.g.resources differ diff --git a/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.pdb b/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.pdb index 95780490..757d3897 100644 Binary files a/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.pdb and b/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI.pdb differ diff --git a/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI_MarkupCompile.lref b/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI_MarkupCompile.lref index 14ae4818..8d7f198c 100644 --- a/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI_MarkupCompile.lref +++ b/Aucma.Scada.UI/obj/Debug/Aucma.Scada.UI_MarkupCompile.lref @@ -1,4 +1,4 @@ -E:\c#\AUCMA\aucma.scada\foam\Aucma.Scada.UI\obj\Debug\GeneratedInternalTypeHelper.g.cs + FE:\c#\AUCMA\aucma.scada\foam\Aucma.Scada.UI\App.xaml;; FE:\c#\AUCMA\aucma.scada\foam\Aucma.Scada.UI\Page\AssemblyPlan\AssemblyPlanControl.xaml;; FE:\c#\AUCMA\aucma.scada\foam\Aucma.Scada.UI\Page\AssemblyPlan\PlanInfoEditWindow.xaml;; diff --git a/Aucma.Scada.UI/obj/Debug/GeneratedInternalTypeHelper.g.cs b/Aucma.Scada.UI/obj/Debug/GeneratedInternalTypeHelper.g.cs index c65238fb..ffa4e1ed 100644 --- a/Aucma.Scada.UI/obj/Debug/GeneratedInternalTypeHelper.g.cs +++ b/Aucma.Scada.UI/obj/Debug/GeneratedInternalTypeHelper.g.cs @@ -1,2 +1,62 @@ - +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace XamlGeneratedNamespace { + + + /// + /// GeneratedInternalTypeHelper + /// + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")] + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public sealed class GeneratedInternalTypeHelper : System.Windows.Markup.InternalTypeHelper { + + /// + /// CreateInstance + /// + protected override object CreateInstance(System.Type type, System.Globalization.CultureInfo culture) { + return System.Activator.CreateInstance(type, ((System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic) + | (System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.CreateInstance)), null, null, culture); + } + + /// + /// GetPropertyValue + /// + protected override object GetPropertyValue(System.Reflection.PropertyInfo propertyInfo, object target, System.Globalization.CultureInfo culture) { + return propertyInfo.GetValue(target, System.Reflection.BindingFlags.Default, null, null, culture); + } + + /// + /// SetPropertyValue + /// + protected override void SetPropertyValue(System.Reflection.PropertyInfo propertyInfo, object target, object value, System.Globalization.CultureInfo culture) { + propertyInfo.SetValue(target, value, System.Reflection.BindingFlags.Default, null, null, culture); + } + + /// + /// CreateDelegate + /// + protected override System.Delegate CreateDelegate(System.Type delegateType, object target, string handler) { + return ((System.Delegate)(target.GetType().InvokeMember("_CreateDelegate", (System.Reflection.BindingFlags.InvokeMethod + | (System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)), null, target, new object[] { + delegateType, + handler}, null))); + } + + /// + /// AddEventHandler + /// + protected override void AddEventHandler(System.Reflection.EventInfo eventInfo, object target, System.Delegate handler) { + eventInfo.AddEventHandler(target, handler); + } + } +} diff --git a/Aucma.Scada.UI/obj/Debug/Page/AssemblyPlan/PlanInfoEditWindow.baml b/Aucma.Scada.UI/obj/Debug/Page/AssemblyPlan/PlanInfoEditWindow.baml index 53932f84..18a682c8 100644 Binary files a/Aucma.Scada.UI/obj/Debug/Page/AssemblyPlan/PlanInfoEditWindow.baml and b/Aucma.Scada.UI/obj/Debug/Page/AssemblyPlan/PlanInfoEditWindow.baml differ diff --git a/Aucma.Scada.UI/obj/Debug/Page/AssemblyPlan/PlanInfoEditWindow.g.cs b/Aucma.Scada.UI/obj/Debug/Page/AssemblyPlan/PlanInfoEditWindow.g.cs index a94bf5e6..0473748f 100644 --- a/Aucma.Scada.UI/obj/Debug/Page/AssemblyPlan/PlanInfoEditWindow.g.cs +++ b/Aucma.Scada.UI/obj/Debug/Page/AssemblyPlan/PlanInfoEditWindow.g.cs @@ -1,4 +1,4 @@ -#pragma checksum "..\..\..\..\Page\AssemblyPlan\PlanInfoEditWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "A8BCABA5CBE8F206A8C3B8531F1994EAA59CB846EA6698F761A3BEFADAC62040" +#pragma checksum "..\..\..\..\Page\AssemblyPlan\PlanInfoEditWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6DA0971FEEFF86ABE715CAE90CF158E4845B3F2075983251ADE14C38565EE308" //------------------------------------------------------------------------------ // // 此代码由工具生成。 diff --git a/Aucma.Scada.UI/obj/Debug/Page/AssemblyPlan/PlanInfoEditWindow.g.i.cs b/Aucma.Scada.UI/obj/Debug/Page/AssemblyPlan/PlanInfoEditWindow.g.i.cs index a94bf5e6..0473748f 100644 --- a/Aucma.Scada.UI/obj/Debug/Page/AssemblyPlan/PlanInfoEditWindow.g.i.cs +++ b/Aucma.Scada.UI/obj/Debug/Page/AssemblyPlan/PlanInfoEditWindow.g.i.cs @@ -1,4 +1,4 @@ -#pragma checksum "..\..\..\..\Page\AssemblyPlan\PlanInfoEditWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "A8BCABA5CBE8F206A8C3B8531F1994EAA59CB846EA6698F761A3BEFADAC62040" +#pragma checksum "..\..\..\..\Page\AssemblyPlan\PlanInfoEditWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6DA0971FEEFF86ABE715CAE90CF158E4845B3F2075983251ADE14C38565EE308" //------------------------------------------------------------------------------ // // 此代码由工具生成。 diff --git a/Aucma.Scada.UI/obj/Debug/Page/InventoryInfo/BomFoamRearInventory.baml b/Aucma.Scada.UI/obj/Debug/Page/InventoryInfo/BomFoamRearInventory.baml index ccc128c6..16572f5c 100644 Binary files a/Aucma.Scada.UI/obj/Debug/Page/InventoryInfo/BomFoamRearInventory.baml and b/Aucma.Scada.UI/obj/Debug/Page/InventoryInfo/BomFoamRearInventory.baml differ diff --git a/Aucma.Scada.UI/obj/Debug/Page/InventoryInfo/BomFoamRearInventory.g.cs b/Aucma.Scada.UI/obj/Debug/Page/InventoryInfo/BomFoamRearInventory.g.cs index 60afe419..4d0df7f1 100644 --- a/Aucma.Scada.UI/obj/Debug/Page/InventoryInfo/BomFoamRearInventory.g.cs +++ b/Aucma.Scada.UI/obj/Debug/Page/InventoryInfo/BomFoamRearInventory.g.cs @@ -1,4 +1,4 @@ -#pragma checksum "..\..\..\..\Page\InventoryInfo\BomFoamRearInventory.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "051C148C286C0C6F0D9F7368DD7DD9D694A4480FCEB90FF0E65EB555235E1435" +#pragma checksum "..\..\..\..\Page\InventoryInfo\BomFoamRearInventory.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "4118EDE7E02AB173F3E20E151078599BC65473CB5136EAEC887E470925918EE8" //------------------------------------------------------------------------------ // // 此代码由工具生成。 diff --git a/Aucma.Scada.UI/obj/Debug/Page/InventoryInfo/BomFoamRearInventory.g.i.cs b/Aucma.Scada.UI/obj/Debug/Page/InventoryInfo/BomFoamRearInventory.g.i.cs index 60afe419..4d0df7f1 100644 --- a/Aucma.Scada.UI/obj/Debug/Page/InventoryInfo/BomFoamRearInventory.g.i.cs +++ b/Aucma.Scada.UI/obj/Debug/Page/InventoryInfo/BomFoamRearInventory.g.i.cs @@ -1,4 +1,4 @@ -#pragma checksum "..\..\..\..\Page\InventoryInfo\BomFoamRearInventory.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "051C148C286C0C6F0D9F7368DD7DD9D694A4480FCEB90FF0E65EB555235E1435" +#pragma checksum "..\..\..\..\Page\InventoryInfo\BomFoamRearInventory.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "4118EDE7E02AB173F3E20E151078599BC65473CB5136EAEC887E470925918EE8" //------------------------------------------------------------------------------ // // 此代码由工具生成。 diff --git a/Aucma.Scada.UI/viewModel/MainViewModel.cs b/Aucma.Scada.UI/viewModel/MainViewModel.cs index 0dab0dba..47b9af50 100644 --- a/Aucma.Scada.UI/viewModel/MainViewModel.cs +++ b/Aucma.Scada.UI/viewModel/MainViewModel.cs @@ -48,6 +48,7 @@ namespace Aucma.Scada.UI.viewModel FormControlCommand = new RelayCommand(obj => FormControl(obj)); UserContent = inStoreInfoControl; + MvCodeHelper.RefreshStateEvent += Scanner1State; init(); } @@ -238,8 +239,7 @@ namespace Aucma.Scada.UI.viewModel { RefreshMesDb(); RefreshPlc(); - RefreshScanner(); - + } /// /// 数据库状态刷新 @@ -271,18 +271,7 @@ namespace Aucma.Scada.UI.viewModel } } - /// - /// 扫码器状态刷新 - /// - /// - /// - public void RefreshScanner() - { - string ip1 = appConfig.foamHikRobotIp; - bool flag1 = MvCodeHelper.ConnectionStatus(ip1); - Scanner1State(flag1); - - } + #endregion #region MES数据库状态 @@ -440,13 +429,13 @@ namespace Aucma.Scada.UI.viewModel { if (type) { - Scanner1UIStatusWb = "扫码器1连接成功"; + Scanner1UIStatusWb = "泡后库扫码器"; Scanner1UIColor = "Green"; Scanner1UIIcon = "templates/image/Green.png"; } else { - Scanner1UIStatusWb = "扫码器1状态异常"; + Scanner1UIStatusWb = "泡后库扫码器"; Scanner1UIColor = "Red"; Scanner1UIIcon = "templates/image/Red.png"; }