diff --git a/Aucma.Scada.Business/InStoreBusiness.cs b/Aucma.Scada.Business/InStoreBusiness.cs index bf180995..d3850812 100644 --- a/Aucma.Scada.Business/InStoreBusiness.cs +++ b/Aucma.Scada.Business/InStoreBusiness.cs @@ -1,4 +1,5 @@ -using Aucma.Scada.HikRobot; +using Aucma.Core.Scanner; +using Aucma.Scada.HikRobot; using Aucma.Scada.Model.domain; using HighWayIot.Config; using HighWayIot.Log4net; @@ -38,7 +39,7 @@ namespace Aucma.Scada.Business private InStoreTaskHandle taskHandle = InStoreTaskHandle.Instance; - private GrabImage grabImage = GrabImage.Instance; + #endregion @@ -98,8 +99,8 @@ namespace Aucma.Scada.Business taskHandle.InStoreFinsihEvent += InStoreFinish; taskHandle.InStoreAnswerEvent += InStoreAnswer; - grabImage.RefreshMaterialCodeStrEvent += InStore; - grabImage.RefreshLogMessageEvent += PrintLogInfoMessage; + MvCodeHelper.RefreshMaterialCodeStrEvent += InStore; + MvCodeHelper.RefreshLogMessageEvent += PrintLogInfoMessage; StartPassDown(); @@ -205,7 +206,6 @@ namespace Aucma.Scada.Business private void StartPassDown() { - Thread.Sleep(5000); Task.Run(() => { while (true) diff --git a/Aucma.Scada.Business/InStoreTaskHandle.cs b/Aucma.Scada.Business/InStoreTaskHandle.cs index 41197e50..19cbaac2 100644 --- a/Aucma.Scada.Business/InStoreTaskHandle.cs +++ b/Aucma.Scada.Business/InStoreTaskHandle.cs @@ -405,7 +405,7 @@ namespace Aucma.Scada.Business private void RealReadPlcSpace() { - Thread.Sleep(5000); + Thread.Sleep(1000); Task.Run(() => { while (true) diff --git a/Aucma.Scada.Business/MainBusiness.cs b/Aucma.Scada.Business/MainBusiness.cs index 71d6e508..735686b5 100644 --- a/Aucma.Scada.Business/MainBusiness.cs +++ b/Aucma.Scada.Business/MainBusiness.cs @@ -1,7 +1,9 @@ -using Aucma.Scada.HikRobot; +using Aucma.Core.Scanner; +using Aucma.Scada.HikRobot; using HighWayIot.Config; using HighWayIot.Plc; using System; +using System.Threading; using System.Threading.Tasks; namespace Aucma.Scada.Business @@ -29,7 +31,7 @@ namespace Aucma.Scada.Business private PlcPool plcPool = PlcPool.Instance; - private GrabImage grabImage = GrabImage.Instance; + #endregion private MainBusiness() @@ -61,12 +63,14 @@ namespace Aucma.Scada.Business public void InitHikRobot() { try - { - grabImage.InitHikRobot(); + { + MvCodeHelper.DeviceListAcq();//获取创建设备 + MvCodeHelper.StartGrab(); // 开启触发扫码接收数据 } catch (Exception ex) { - Console.WriteLine(ex.Message); + MvCodeHelper.CloseAllDevice(); + InitHikRobot(); } } @@ -77,7 +81,7 @@ namespace Aucma.Scada.Business { try { - grabImage.ExitHikRobot(); + MvCodeHelper.CloseAllDevice(); } catch (Exception ex) { diff --git a/Aucma.Scada.Business/OutStoreBusiness.cs b/Aucma.Scada.Business/OutStoreBusiness.cs index 1e139433..1898301f 100644 --- a/Aucma.Scada.Business/OutStoreBusiness.cs +++ b/Aucma.Scada.Business/OutStoreBusiness.cs @@ -68,7 +68,7 @@ namespace Aucma.Scada.Business private IRecordProductfinishService _recordProductfinishService; - private ICodeBindingRecordServices _codeBindingRecordServices; + #endregion #region 委托事件 @@ -113,7 +113,7 @@ namespace Aucma.Scada.Business _productPlanInfoService = registerServices.GetService(); _recordOutStoreService = registerServices.GetService(); _recordProductfinishService = registerServices.GetService(); - _codeBindingRecordServices = registerServices.GetService(); + assemblyPlanBusiness.NextPassExecutePlanInfoEvent += PlanHandle; taskHandleBusiness.OutStoreAnswerEvent += OutStoreAnswer; taskHandleBusiness.OutStoreFinsihEvent += OutStoreFinish; @@ -143,11 +143,7 @@ namespace Aucma.Scada.Business RealTaskInfo shellTask = OutStore(appConfig.shellStoreCode, shellBomInfo, planInfo.executePlanCode, taskCode); Thread.Sleep(500); RealTaskInfo linerTask = OutStore(appConfig.linerStoreCode, linerBomInfo, planInfo.executePlanCode, taskCode); - // 条码绑定表,绑定箱壳和内胆码 shellTask.materialCode,linerTask.materialCode - if (shellTask != null && linerTask != null) - { - _codeBindingRecordServices.BindingCode(shellTask.materialCode, linerTask.materialCode); - } + Thread.Sleep(500); } diff --git a/Aucma.Scada.Business/OutStoreTaskHandle.cs b/Aucma.Scada.Business/OutStoreTaskHandle.cs index eee542a3..2bf82528 100644 --- a/Aucma.Scada.Business/OutStoreTaskHandle.cs +++ b/Aucma.Scada.Business/OutStoreTaskHandle.cs @@ -2,6 +2,7 @@ using HighWayIot.Config; using HighWayIot.Log4net; using HighWayIot.Plc; +using HighWayIot.Repository.service; using System; using System.Collections.Generic; using System.Linq; @@ -37,6 +38,8 @@ namespace Aucma.Scada.Business private PlcPool _pool = PlcPool.Instance; private PlcSpaceConfig spaceConfig = PlcSpaceConfig.Instance; + private RegisterServices registerServices = RegisterServices.Instance; + private ICodeBindingRecordServices _codeBindingRecordServices; #endregion #region 私有变量 @@ -83,6 +86,7 @@ namespace Aucma.Scada.Business private OutStoreTaskHandle() { + _codeBindingRecordServices = registerServices.GetService(); _plcDictionary = _pool.GetAll(); RealReadShellFinish(); @@ -481,7 +485,9 @@ namespace Aucma.Scada.Business if (shellTask != null && linerTask != null) { - Console.WriteLine($"绑定箱壳:{shellTask.materialCode};内胆:{linerTask.materialCode};条码"); + logHelper.Info($"绑定条码:箱壳:{shellTask.materialCode};内胆:{linerTask.materialCode}"); + // 条码绑定表,绑定箱壳和内胆码 shellTask.materialCode,linerTask.materialCode + _codeBindingRecordServices.BindingCode(shellTask.materialCode, linerTask.materialCode); shellTaskInfos.Remove(shellTask); linerTaskInfos.Remove(linerTask); diff --git a/Aucma.Scada.HikRobot/Aucma.Scada.HikRobot.csproj.user b/Aucma.Scada.HikRobot/Aucma.Scada.HikRobot.csproj.user new file mode 100644 index 00000000..9b86104e --- /dev/null +++ b/Aucma.Scada.HikRobot/Aucma.Scada.HikRobot.csproj.user @@ -0,0 +1,6 @@ + + + + ShowAllFiles + + \ No newline at end of file diff --git a/Aucma.Scada.HikRobot/MvCodeHelper.cs b/Aucma.Scada.HikRobot/MvCodeHelper.cs index c957d480..2d37bc85 100644 --- a/Aucma.Scada.HikRobot/MvCodeHelper.cs +++ b/Aucma.Scada.HikRobot/MvCodeHelper.cs @@ -10,19 +10,21 @@ using static System.Runtime.CompilerServices.RuntimeHelpers; using HighWayIot.Log4net; using HighWayIot.Config; using System.Security.Policy; - namespace Aucma.Core.Scanner { public class MvCodeHelper { - private AppConfig appConfig = AppConfig.Instance; + private static AppConfig appConfig = AppConfig.Instance; public static bool m_bGrabbing = true; - private LogHelper logHelper = LogHelper.Instance; #region 委托事件 public delegate void RefreshMaterialCodeStr(string storeCode, string materialCodeStr); - public event RefreshMaterialCodeStr RefreshMaterialCodeStrEvent; - - + public static event RefreshMaterialCodeStr RefreshMaterialCodeStrEvent; + /// + /// 日志信息刷新 + /// + /// + public delegate void RefreshLogMessage(string message); + public static event RefreshLogMessage RefreshLogMessageEvent; #endregion // 获取到的所有设备 @@ -59,24 +61,25 @@ namespace Aucma.Core.Scanner /// /// 获取并创建设备列表 /// - public void DeviceListAcq() + public static void DeviceListAcq() { try { - logHelper.Info("获取扫码器设备列表,进入DeviceListAcq()方法"); + RefreshLogMessageEvent?.Invoke("获取扫码器设备列表,进入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) { - logHelper.Info("获取扫码器列表失败,扫码器错误码:" + nRet); + RefreshLogMessageEvent?.Invoke("获取扫码器列表失败,扫码器错误码:" + nRet); return; } if (0 == m_stDeviceList.nDeviceNum) { - logHelper.Info("获取扫码器数量为0,请检查扫码器连接:"); + RefreshLogMessageEvent?.Invoke("获取扫码器数量为0,请检查扫码器连接:"); return; } @@ -93,33 +96,32 @@ namespace Aucma.Core.Scanner // 获取ip string ip = ((stGigEDeviceInfo.nCurrentIp & 0xff000000) >> 24) + "." + ((stGigEDeviceInfo.nCurrentIp & 0x00ff0000) >> 16) + "." + ((stGigEDeviceInfo.nCurrentIp & 0x0000ff00) >> 8) + "." + (stGigEDeviceInfo.nCurrentIp & 0x000000ff); - // Console.WriteLine($"打印扫码设备信息,下标:{i};IP:{ip}"); - logHelper.Info("扫码器设备[" + i + "],ip:" + ip); + // Console.WriteLine($"打印扫码设备信息,下标:{i};IP:{ip}"); + Console.Write("扫码器设备[" + 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) { - logHelper.Error("创建第" + i + "个扫码器设备失败,ip:" + ip); + Console.WriteLine("创建第" + i + "个扫码器设备失败,ip:" + ip); return; - } - logHelper.Info("创建第" + i + "个扫码器设备成功,ip:" + ip); + } // 打开设备 nRet = m_cMyDevice.MV_CODEREADER_OpenDevice_NET(); if (MvCodeReader.MV_CODEREADER_OK != nRet) { m_cMyDevice.MV_CODEREADER_DestroyHandle_NET(); - logHelper.Error("Device open fail!"); + 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) { - logHelper.Error("Set TriggerMode On Fail!"); + Console.WriteLine("设置触发模式失败"); return; } - //添加到集合 m_cMyDevices.Add(m_cMyDevice, ip); } @@ -127,14 +129,14 @@ namespace Aucma.Core.Scanner } catch (Exception ex) { - logHelper.Error("获取和创建设备异常:" + ex); + Console.WriteLine("获取和创建设备异常:" + ex); } } #endregion #region 光电触发扫码器接收条码处理业务 - public void StartGrab() + public static void StartGrab() { try { @@ -166,7 +168,7 @@ namespace Aucma.Core.Scanner { // 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') + "]"); + // logHelper.Info("bIsValidUTF8:: Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]"); } else { @@ -176,7 +178,7 @@ namespace Aucma.Core.Scanner Array.Copy(stBcrResult.stBcrInfoEx2[i].chCode, buffer, 22); } string strCode = Encoding.GetEncoding("UTF-8").GetString(buffer).Trim().TrimEnd('\0'); - logHelper.Info("相机ip:" + hashmap.Value + " Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode + "]"); + RefreshLogMessageEvent?.Invoke("相机ip:" + hashmap.Value + " Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode + "]"); if (!string.IsNullOrEmpty(strCode)) { // 获取到条码处理业务 @@ -199,18 +201,18 @@ namespace Aucma.Core.Scanner } catch (Exception ex) { - logHelper.Error("扫码异常:" + ex); + Console.WriteLine("扫码异常:" + ex); } } #endregion #region 关闭所有设备 - public void CloseAllDevice() + public static void CloseAllDevice() { try { - logHelper.Info("开始关闭所有设备"); + Console.WriteLine("开始关闭所有设备"); int nRet = MvCodeReader.MV_CODEREADER_OK; // 关闭所有已打开相机 foreach (KeyValuePair hashmap in m_cMyDevices) @@ -219,14 +221,14 @@ namespace Aucma.Core.Scanner nRet = hashmap.Key.MV_CODEREADER_StopGrabbing_NET(); if (MvCodeReader.MV_CODEREADER_OK != nRet) { - logHelper.Error("设备ip:" + hashmap.Value + "停止抓图失败"); + 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) { - logHelper.Error("设备ip:" + hashmap.Value + "关闭失败"); + Console.WriteLine("设备ip:" + hashmap.Value + "关闭失败"); } @@ -234,14 +236,14 @@ namespace Aucma.Core.Scanner nRet = hashmap.Key.MV_CODEREADER_DestroyHandle_NET(); if (MvCodeReader.MV_CODEREADER_OK != nRet) { - logHelper.Error("设备ip:" + hashmap.Value + "销毁失败"); + Console.WriteLine("设备ip:" + hashmap.Value + "销毁失败"); } - logHelper.Error("设备ip:" + hashmap.Value + "关闭成功!"); + Console.WriteLine("设备ip:" + hashmap.Value + "关闭成功!"); } } catch (Exception ex) { - logHelper.Error("设备关闭异常:" + ex); + Console.WriteLine("设备关闭异常:" + ex); } @@ -258,7 +260,7 @@ namespace Aucma.Core.Scanner nRet = hashmap.Key.MV_CODEREADER_StopGrabbing_NET(); if (MvCodeReader.MV_CODEREADER_OK != nRet) { - logHelper.Error("设备ip:" + hashmap.Value + "停止抓图失败"); + Console.WriteLine("设备ip:" + hashmap.Value + "停止抓图失败"); Console.WriteLine("Stop grabbing failed{0:x8}", nRet); return; } @@ -266,13 +268,13 @@ namespace Aucma.Core.Scanner nRet = hashmap.Key.MV_CODEREADER_CloseDevice_NET(); if (MvCodeReader.MV_CODEREADER_OK != nRet) { - logHelper.Error("设备ip:" + hashmap.Value + "关闭失败"); + Console.WriteLine("设备ip:" + hashmap.Value + "关闭失败"); return; } } catch (Exception ex) { - logHelper.Error("设备关闭异常:" + ex); + Console.WriteLine("设备关闭异常:" + ex); } } #endregion diff --git a/Aucma.Scada.UI/bin/Debug/Log4net.config b/Aucma.Scada.UI/bin/Debug/Log4net.config new file mode 100644 index 00000000..c8d3cfeb --- /dev/null +++ b/Aucma.Scada.UI/bin/Debug/Log4net.config @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Aucma.Scada.UI/bin/Debug/config/log4net.config b/Aucma.Scada.UI/bin/Debug/config/log4net.config new file mode 100644 index 00000000..a9d7efb5 --- /dev/null +++ b/Aucma.Scada.UI/bin/Debug/config/log4net.config @@ -0,0 +1,153 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file