diff --git a/.vs/HighWayIot/v17/.suo b/.vs/HighWayIot/v17/.suo index 30cc099..11ddda6 100644 Binary files a/.vs/HighWayIot/v17/.suo and b/.vs/HighWayIot/v17/.suo differ diff --git a/Aucma.Scada.Business/MainBusiness.cs b/Aucma.Scada.Business/MainBusiness.cs index 047acbb..f3407ce 100644 --- a/Aucma.Scada.Business/MainBusiness.cs +++ b/Aucma.Scada.Business/MainBusiness.cs @@ -1,5 +1,7 @@ -using HighWayIot.Log4net; +using HighWayIot.Config; +using HighWayIot.Log4net; using HighWayIot.Plc; +using HighWayIot.Plc.Impl; using HighWayIot.Repository.domain; using HighWayIot.Repository.service; using HighWayIot.Repository.service.Impl; @@ -14,6 +16,7 @@ namespace Aucma.Scada.Business public class MainBusiness { private static readonly Lazy lazy = new Lazy(() => new MainBusiness()); + public static MainBusiness Instance { get @@ -21,12 +24,20 @@ namespace Aucma.Scada.Business return lazy.Value; } } - public MainBusiness() + + private AppConfig appConfig = AppConfig.Instance; + + private PlcConfig plcConfig = PlcConfig.Instance; + + private PlcPool plcPool = PlcPool.Instance; + + private MainBusiness() { //初始化扫码器 - //初始化PLC - + //初始化Plc + plcPool.InitPlc("MelsecBinaryPlc", plcConfig.shell_Plc_Ip, plcConfig.shell_Plc_Port, appConfig.shellStoreCode); + plcPool.InitPlc("MelsecBinaryPlc", plcConfig.liner_Plc_Ip, plcConfig.liner_Plc_Port, appConfig.linerStoreCode); //初始化货道信息,保证系统内的库存信息与实物一致 } diff --git a/Aucma.Scada.Business/OutStoreBusiness.cs b/Aucma.Scada.Business/OutStoreBusiness.cs index a792f3c..1351731 100644 --- a/Aucma.Scada.Business/OutStoreBusiness.cs +++ b/Aucma.Scada.Business/OutStoreBusiness.cs @@ -73,6 +73,7 @@ namespace Aucma.Scada.Business private OutStoreBusiness() { assemblyPlanBusiness.NextPassExecutePlanInfoEvent += PlanHandle; + taskHandleBusiness.OutStoreFinsihEvent += TaskFeedback; StartPassDown(); } @@ -261,6 +262,10 @@ namespace Aucma.Scada.Business /// private void PassDownTaskInfo() { + string shellCode = string.Empty; + string linerCode = string.Empty; + string taskCode = string.Empty; + int iFlag= 0; completedTasks = 0; //获取待执行的出库任务下发至PLC,并将任务状态改为执行中 @@ -272,22 +277,61 @@ namespace Aucma.Scada.Business foreach (var item in taskInfoList) { - //taskHandleBusiness.SendOutStoreTask(item); - PrintLogInfoMessage($"下发出库任务:{item.taskCode};仓库{item.storeCode};货道:{item.spaceCode}"); + taskCode = item.taskCode; + if (item.storeCode == appConfig.shellStoreCode) + { + if (taskHandleBusiness.SendShellTask_OutStore(item)) + { + PrintLogInfoMessage($"下发箱壳出库任务:{item.taskCode};仓库{item.storeCode};货道:{item.spaceCode};等待PLC执行反馈"); + item.taskStatus = 2; + iFlag++; + } + else + { + PrintLogInfoMessage($"箱壳出库任务:{item.taskCode};下发失败,请排除PLC连接"); + continue; + } + shellCode = item.materialCode; + } + else if(item.storeCode == appConfig.linerStoreCode) + { + if (taskHandleBusiness.SendLinerTask_OutStore(item)) + { + PrintLogInfoMessage($"下发内胆出库任务:{item.taskCode};仓库{item.storeCode};货道:{item.spaceCode};等待PLC执行反馈"); + item.taskStatus = 2; + iFlag++; + } + else + { + PrintLogInfoMessage($"内胆出库任务:{item.taskCode};下发失败,请排除PLC连接"); + continue; + } + linerCode = item.materialCode; + } + RefreshScanMateriaCodeEvent?.Invoke(item.materialCode, item.materialType, item.spaceName, item.storeCode); } - if (semaphore.Wait(TimeSpan.FromSeconds(20))) + + if(iFlag == taskInfoList.Count) { - // 收到反馈 - PrintLogInfoMessage("收到反馈,继续执行"); - } - else - { - PrintLogInfoMessage("超时未反馈"); - } + _taskInfoService.UpdateRangeTaskInfo(taskInfoList); - //semaphore.Wait(); //一直堵塞直到信号量释放 + //if (semaphore.Wait(TimeSpan.FromSeconds(20))) + //{ + // // 收到反馈 + // PrintLogInfoMessage("收到反馈,继续执行"); + //} + //else + //{ + // PrintLogInfoMessage("超时未反馈"); + //} + + semaphore.Wait(); //一直堵塞直到信号量释放 + + PrintLogInfoMessage($"出库任务:{taskCode};执行完成,绑定箱壳条码:{shellCode};内胆条码:{linerCode}"); + + } } else { @@ -311,17 +355,22 @@ namespace Aucma.Scada.Business if(shellTaskInfo != null) { + taskInfos.Add(shellTaskInfo); //获取与箱壳任务匹配的内胆任务 RealTaskInfo linerTaskInfo = _taskInfoService.GetTaskInfoByTaskCode(shellTaskInfo.taskCode, appConfig.linerStoreCode); - taskInfos.Add(shellTaskInfo); if (linerTaskInfo != null) taskInfos.Add(linerTaskInfo); } - - if(taskInfos.Count > 0) + else { - taskInfos.ForEach(x => x.taskStatus = 2); - _taskInfoService.UpdateRangeTaskInfo(taskInfos); + RealTaskInfo linerInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, 2); + if (linerInfo != null) taskInfos.Add(linerInfo); } + + //if(taskInfos.Count > 0) + //{ + // taskInfos.ForEach(x => x.taskStatus = 2); + // _taskInfoService.UpdateRangeTaskInfo(taskInfos); + //} } catch(Exception ex) { @@ -330,10 +379,27 @@ namespace Aucma.Scada.Business return taskInfos; } + /// + /// PLC任务执行反馈 + /// + /// + /// + private void TaskFeedback(string storeCode, string taskCode) + { + if(storeCode == appConfig.shellStoreCode) + { + ShellTaskFeedback(taskCode); + } + else + { + LinerTaskFeedback(taskCode); + } + } + /// /// 箱壳执行反馈 /// - private void ShellTaskFeedback() + private void ShellTaskFeedback(string taskCode) { Interlocked.Increment(ref completedTasks); @@ -341,13 +407,13 @@ namespace Aucma.Scada.Business PrintLogInfoMessage("箱壳执行完成,自动释放信号量"); - OutStoreFinish("", appConfig.shellStoreCode); + OutStoreFinish(taskCode, appConfig.shellStoreCode); } /// /// 内胆执行反馈 /// - private void LinerTaskFeedback() + private void LinerTaskFeedback(string taskCode) { Interlocked.Increment(ref completedTasks); @@ -355,7 +421,7 @@ namespace Aucma.Scada.Business PrintLogInfoMessage("内胆执行完成,自动释放信号量"); - OutStoreFinish("", appConfig.linerStoreCode); + OutStoreFinish(taskCode, appConfig.linerStoreCode); } /// @@ -386,6 +452,9 @@ namespace Aucma.Scada.Business var taskInfo = _taskInfoService.GetTaskInfoByTaskCode(taskCode, storeCode); if (taskInfo != null) { + //刷新界面 + RefreshScanMateriaCodeEvent?.Invoke(string.Empty, string.Empty, string.Empty, taskInfo.storeCode); + var spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(taskInfo.storeCode, taskInfo.spaceCode); if (spaceInfo != null) diff --git a/Aucma.Scada.Business/TaskHandleBusiness.cs b/Aucma.Scada.Business/TaskHandleBusiness.cs index abc8224..a41392e 100644 --- a/Aucma.Scada.Business/TaskHandleBusiness.cs +++ b/Aucma.Scada.Business/TaskHandleBusiness.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace Aucma.Scada.Business @@ -25,71 +26,348 @@ namespace Aucma.Scada.Business } } - public delegate void OutStoreFinsih(string storeCode,string taskCode); + public delegate void OutStoreFinsih(string storeCode, string taskCode); public event OutStoreFinsih OutStoreFinsihEvent; - private IPlc _plc = new SiemensPlc(); + /// + /// 字典存放PLC连接 + /// + private Dictionary _plcDictionary = new Dictionary(); + private LogHelper logHelper = LogHelper.Instance; private AppConfig appConfig = AppConfig.Instance; private PlcConfig plcConfig = PlcConfig.Instance; + private PlcPool _pool = PlcPool.Instance; + + private string shellTaskCode = string.Empty; + + private string linerTaskCode = string.Empty; private TaskHandleBusiness() { - + //_plcDictionary.Add(appConfig.shellStoreCode, new MelsecBinaryPlc()); + //_plcDictionary.Add(appConfig.linerStoreCode, new MelsecBinaryPlc()); + //var shellPlc = _plcDictionary[appConfig.shellStoreCode].Connect(plcConfig.shell_Plc_Ip, plcConfig.shell_Plc_Port); + //var linerPlc = _plcDictionary[appConfig.linerStoreCode].Connect(plcConfig.liner_Plc_Ip, plcConfig.liner_Plc_Port); + _plcDictionary = _pool.GetAll(); } - public void Inite() - { - _plc.Connect("127.0.0.1", 124); - } - - public bool SendOutStoreTask(RealTaskInfo realTaskInfo) + #region 箱壳出库任务下发处理 + /// + /// 箱壳出库任务下发 + /// + /// + public bool SendShellTask_OutStore(RealTaskInfo taskInfo) { bool result = false; - string spaceCode = string.Empty; - string amount = string.Empty; - string taskCode = string.Empty; - string answer = string.Empty; try { + IPlc _plc = _plcDictionary[taskInfo.storeCode]; - if(realTaskInfo.storeCode == appConfig.shellStoreCode) + if (_plc != null) { - spaceCode = plcConfig.out_shell_spaceCode; - amount = plcConfig.out_shell_amount; - taskCode = plcConfig.out_shell_task; - }else if (realTaskInfo.storeCode == appConfig.linerStoreCode) - { - spaceCode = plcConfig.out_liner_spaceCode; - amount = plcConfig.out_liner_amount; - taskCode = plcConfig.out_liner_task; + if (_plc.IsConnected) + { + //写入货道号 + _plc.writeStringByAddress(plcConfig.out_shell_spaceCode, taskInfo.spaceCode); + //写入出库数量 + _plc.writeInt32ByAddress(plcConfig.out_shell_amount, taskInfo.planAmount); + //写入应答字 + _plc.writeInt32ByAddress(plcConfig.out_shell_answer, 1); + //写入任务号 + _plc.writeStringByAddress(plcConfig.out_shell_task, taskInfo.taskCode); + + //写入完成后读取应答字进行复位 + ReadShellAnswer_OutStore(taskInfo.taskCode); + + result = true; + } + else + { + logHelper.Info($"仓库{taskInfo.storeCode};PLC未连接"); + } + } + else + { + logHelper.Info($"PLC信息为空,通过{taskInfo.storeCode}未获取到该仓库对应的PLC信息"); } - - //写入货道号 - _plc.writeStringByAddress(spaceCode, realTaskInfo.spaceCode); - //写入出库数量 - _plc.writeInt32ByAddress(amount, realTaskInfo.planAmount); - //写入任务号 - _plc.writeStringByAddress(taskCode,realTaskInfo.taskCode); - //写入应答字 - _plc.writeInt32ByAddress(answer, 1); - - result = true; } - catch(Exception ex) + catch (Exception ex) { - logHelper.Error("出库任务下发异常", ex); + logHelper.Error("箱壳出库任务下发异常", ex); + } + + return result; + } + + /// + /// 读取箱壳出库应答 + /// + private void ReadShellAnswer_OutStore(string taskCode) + { + lock (string.Empty) + { + bool isFlag = true; + IPlc _plc = _plcDictionary[appConfig.shellStoreCode]; + try + { + Task.Run(() => + { + if (_plc != null) + { + if (_plc.IsConnected) + { + do + { + //读取PLC应答字为2时,上位机清空写入的出库内容 + if (_plc.readInt32ByAddress(plcConfig.out_shell_answer) == 2) + { + //写入货道号 + _plc.writeStringByAddress(plcConfig.out_shell_spaceCode, string.Empty); + //写入出库数量 + _plc.writeInt32ByAddress(plcConfig.out_shell_amount, 0); + //写入应答字 + _plc.writeInt32ByAddress(plcConfig.out_shell_answer, 0); + //写入任务号 + _plc.writeStringByAddress(plcConfig.out_shell_task, string.Empty); + isFlag = false; + + ReadShellFinish_OutStore(taskCode); + } + + Thread.Sleep(5000); + } while (isFlag); + } + else + { + logHelper.Info($"仓库{appConfig.shellStoreCode};PLC未连接"); + } + } + else + { + logHelper.Info($"PLC信息为空,通过{appConfig.shellStoreCode}未获取到该仓库对应的PLC信息"); + } + }); + } + catch (Exception ex) + { + logHelper.Error("读取箱壳出库应答字异常", ex); + } + } + } + + /// + /// 读取箱壳出库完成 + /// + private void ReadShellFinish_OutStore(string taskCode) + { + lock (string.Empty) + { + bool isFlag = true; + IPlc _plc = _plcDictionary[appConfig.shellStoreCode]; + shellTaskCode = taskCode; + try + { + Task.Run(() => + { + if (_plc != null) + { + if (_plc.IsConnected) + { + do + { + //读取PLC出库任务完成 + if (_plc.readInt32ByAddress(plcConfig.out_shell_finish) == 1) + { + _plc.writeInt32ByAddress(plcConfig.out_shell_finish, 0); + + //string taskCode = _plc.readStringByAddress(plcConfig.out_shell_task, 10); + + OutStoreFinsihEvent?.Invoke(appConfig.shellStoreCode, taskCode); + + isFlag = false; + } + + Thread.Sleep(5000); + } while (isFlag); + } + else + { + logHelper.Info($"仓库{appConfig.shellStoreCode};PLC未连接"); + } + } + else + { + logHelper.Info($"PLC信息为空,通过{appConfig.shellStoreCode}未获取到该仓库对应的PLC信息"); + } + }); + } + catch (Exception ex) + { + logHelper.Error("读取箱壳出库出库完成异常", ex); + } + } + } + #endregion + + #region 内胆出库任务处理 + /// + /// 内胆出库任务下发 + /// + /// + public bool SendLinerTask_OutStore(RealTaskInfo taskInfo) + { + bool result = false; + try + { + IPlc _plc = _plcDictionary[taskInfo.storeCode]; + + if (_plc != null) + { + if (_plc.IsConnected) + { + //写入货道号 + _plc.writeStringByAddress(plcConfig.out_liner_spaceCode, taskInfo.spaceCode); + //写入出库数量 + _plc.writeInt32ByAddress(plcConfig.out_liner_amount, taskInfo.planAmount); + //写入应答字 + _plc.writeInt32ByAddress(plcConfig.out_liner_answer, 1); + //写入任务号 + _plc.writeStringByAddress(plcConfig.out_liner_task, taskInfo.taskCode); + + //写入完成后读取应答字进行复位 + ReadLinerAnswer_OutStore(taskInfo.taskCode); + + result = true; + } + else + { + logHelper.Info($"仓库{taskInfo.storeCode};PLC未连接"); + } + } + else + { + logHelper.Info($"PLC信息为空,通过{taskInfo.storeCode}未获取到该仓库对应的PLC信息"); + } + } + catch (Exception ex) + { + logHelper.Error("内胆出库任务下发异常", ex); } return result; } - private void ReadPlc() + /// + /// 读取内胆出库应答 + /// + private void ReadLinerAnswer_OutStore(string taskCode) { - if(_plc.readInt32ByAddress("") == 1) // 读取PLC出库应答字,出库完成后读取任务号 + lock (string.Empty) { - string taskCode = _plc.readStringByAddress("", (ushort)12); - OutStoreFinsihEvent?.Invoke(appConfig.shellStoreCode, taskCode); + bool isFlag = true; + IPlc _plc = _plcDictionary[appConfig.shellStoreCode]; + linerTaskCode = taskCode; + try + { + Task.Run(() => + { + + if (_plc != null) + { + if (_plc.IsConnected) + { + do + { + //读取PLC应答字为2时,上位机清空写入的出库内容 + if (_plc.readInt32ByAddress(plcConfig.out_liner_answer) == 2) + { + //写入货道号 + _plc.writeStringByAddress(plcConfig.out_liner_spaceCode, string.Empty); + //写入出库数量 + _plc.writeInt32ByAddress(plcConfig.out_liner_amount, 0); + //写入应答字 + _plc.writeInt32ByAddress(plcConfig.out_liner_answer, 0); + //写入任务号 + _plc.writeStringByAddress(plcConfig.out_liner_task, string.Empty); + isFlag = false; + + Thread.Sleep(5000); + + ReadLinerFinish_OutStore(taskCode); + } + } while (isFlag); + } + else + { + logHelper.Info($"仓库{appConfig.linerStoreCode};PLC未连接"); + } + } + else + { + logHelper.Info($"PLC信息为空,通过{appConfig.linerStoreCode}未获取到该仓库对应的PLC信息"); + } + }); + } + catch (Exception ex) + { + logHelper.Error("读取内胆出库应答字异常", ex); + } } } + + /// + /// 读取内胆出库完成 + /// + private void ReadLinerFinish_OutStore(string taskCode) + { + lock (string.Empty) + { + try + { + Task.Run(() => + { + bool isFlag = true; + IPlc _plc = _plcDictionary[appConfig.linerStoreCode]; + if (_plc != null) + { + if (_plc.IsConnected) + { + do + { + //读取PLC出库任务完成 + if (_plc.readInt32ByAddress(plcConfig.out_liner_finish) == 1) + { + _plc.writeInt32ByAddress(plcConfig.out_liner_finish, 0); + + //string taskCode = _plc.readStringByAddress(plcConfig.out_liner_task, 10); + + OutStoreFinsihEvent?.Invoke(appConfig.linerStoreCode, taskCode); + + isFlag = false; + + Thread.Sleep(5000); + } + } while (isFlag); + } + else + { + logHelper.Info($"仓库{appConfig.linerStoreCode};PLC未连接"); + } + } + else + { + logHelper.Info($"PLC信息为空,通过{appConfig.linerStoreCode}未获取到该仓库对应的PLC信息"); + } + }); + } + catch (Exception ex) + { + logHelper.Error("读取内胆出库完成异常", ex); + } + } + } + #endregion + + } } diff --git a/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.dll b/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.dll index 6ae1ca5..d78f9ba 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 1605161..0a0672f 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/bin/Debug/HighWayIot.Common.dll b/Aucma.Scada.Business/bin/Debug/HighWayIot.Common.dll index 3718be0..56eb09e 100644 Binary files a/Aucma.Scada.Business/bin/Debug/HighWayIot.Common.dll and b/Aucma.Scada.Business/bin/Debug/HighWayIot.Common.dll differ diff --git a/Aucma.Scada.Business/bin/Debug/HighWayIot.Common.pdb b/Aucma.Scada.Business/bin/Debug/HighWayIot.Common.pdb index 42fbaf6..56306bb 100644 Binary files a/Aucma.Scada.Business/bin/Debug/HighWayIot.Common.pdb and b/Aucma.Scada.Business/bin/Debug/HighWayIot.Common.pdb differ diff --git a/Aucma.Scada.Business/bin/Debug/HighWayIot.Config.dll b/Aucma.Scada.Business/bin/Debug/HighWayIot.Config.dll index e0e8eda..c9bda2e 100644 Binary files a/Aucma.Scada.Business/bin/Debug/HighWayIot.Config.dll and b/Aucma.Scada.Business/bin/Debug/HighWayIot.Config.dll differ diff --git a/Aucma.Scada.Business/bin/Debug/HighWayIot.Config.pdb b/Aucma.Scada.Business/bin/Debug/HighWayIot.Config.pdb index 5508e12..3c45ae5 100644 Binary files a/Aucma.Scada.Business/bin/Debug/HighWayIot.Config.pdb and b/Aucma.Scada.Business/bin/Debug/HighWayIot.Config.pdb differ diff --git a/Aucma.Scada.Business/bin/Debug/HighWayIot.Plc.dll b/Aucma.Scada.Business/bin/Debug/HighWayIot.Plc.dll index eb09175..08711b7 100644 Binary files a/Aucma.Scada.Business/bin/Debug/HighWayIot.Plc.dll and b/Aucma.Scada.Business/bin/Debug/HighWayIot.Plc.dll differ diff --git a/Aucma.Scada.Business/bin/Debug/HighWayIot.Plc.pdb b/Aucma.Scada.Business/bin/Debug/HighWayIot.Plc.pdb index 00cc086..02accd1 100644 Binary files a/Aucma.Scada.Business/bin/Debug/HighWayIot.Plc.pdb and b/Aucma.Scada.Business/bin/Debug/HighWayIot.Plc.pdb differ diff --git a/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.dll b/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.dll index a02a238..e254c3b 100644 Binary files a/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.dll and b/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.dll differ diff --git a/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.pdb b/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.pdb index c2c4184..e970a13 100644 Binary files a/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.pdb and b/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.pdb differ diff --git a/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.csproj.AssemblyReference.cache b/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.csproj.AssemblyReference.cache index e7d3be8..fd80a0c 100644 Binary files a/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.csproj.AssemblyReference.cache and b/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.csproj.AssemblyReference.cache differ diff --git a/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.dll b/Aucma.Scada.Business/obj/Debug/Aucma.Scada.Business.dll index 6ae1ca5..d78f9ba 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 1605161..0a0672f 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.UI/MainWindow.xaml b/Aucma.Scada.UI/MainWindow.xaml index 58c7df3..e1dd54c 100644 --- a/Aucma.Scada.UI/MainWindow.xaml +++ b/Aucma.Scada.UI/MainWindow.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:Aucma.Scada.UI" mc:Ignorable="d" Title="SCADA" Height="1080" Width="1920" Icon="Icon.png" - WindowState="Maximized" WindowStyle="None" ResizeMode="NoResize" Topmost="False" + WindowState="Maximized" ResizeMode="NoResize" Topmost="False" > diff --git a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.dll b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.dll index 6ae1ca5..d78f9ba 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 1605161..0a0672f 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 b62c88e..41c3b4d 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 f972b29..3f0c952 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/bin/Debug/HighWayIot.Common.dll b/Aucma.Scada.UI/bin/Debug/HighWayIot.Common.dll index 3718be0..56eb09e 100644 Binary files a/Aucma.Scada.UI/bin/Debug/HighWayIot.Common.dll and b/Aucma.Scada.UI/bin/Debug/HighWayIot.Common.dll differ diff --git a/Aucma.Scada.UI/bin/Debug/HighWayIot.Common.pdb b/Aucma.Scada.UI/bin/Debug/HighWayIot.Common.pdb index 42fbaf6..56306bb 100644 Binary files a/Aucma.Scada.UI/bin/Debug/HighWayIot.Common.pdb and b/Aucma.Scada.UI/bin/Debug/HighWayIot.Common.pdb differ diff --git a/Aucma.Scada.UI/bin/Debug/HighWayIot.Config.dll b/Aucma.Scada.UI/bin/Debug/HighWayIot.Config.dll index e0e8eda..c9bda2e 100644 Binary files a/Aucma.Scada.UI/bin/Debug/HighWayIot.Config.dll and b/Aucma.Scada.UI/bin/Debug/HighWayIot.Config.dll differ diff --git a/Aucma.Scada.UI/bin/Debug/HighWayIot.Config.pdb b/Aucma.Scada.UI/bin/Debug/HighWayIot.Config.pdb index 5508e12..3c45ae5 100644 Binary files a/Aucma.Scada.UI/bin/Debug/HighWayIot.Config.pdb and b/Aucma.Scada.UI/bin/Debug/HighWayIot.Config.pdb differ diff --git a/Aucma.Scada.UI/bin/Debug/HighWayIot.Plc.dll b/Aucma.Scada.UI/bin/Debug/HighWayIot.Plc.dll index eb09175..08711b7 100644 Binary files a/Aucma.Scada.UI/bin/Debug/HighWayIot.Plc.dll and b/Aucma.Scada.UI/bin/Debug/HighWayIot.Plc.dll differ diff --git a/Aucma.Scada.UI/bin/Debug/HighWayIot.Plc.pdb b/Aucma.Scada.UI/bin/Debug/HighWayIot.Plc.pdb index 00cc086..02accd1 100644 Binary files a/Aucma.Scada.UI/bin/Debug/HighWayIot.Plc.pdb and b/Aucma.Scada.UI/bin/Debug/HighWayIot.Plc.pdb differ diff --git a/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.dll b/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.dll index a02a238..e254c3b 100644 Binary files a/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.dll and b/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.dll differ diff --git a/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.pdb b/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.pdb index c2c4184..e970a13 100644 Binary files a/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.pdb and b/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.pdb differ diff --git a/Aucma.Scada.UI/bin/Debug/config/Plc.Ini b/Aucma.Scada.UI/bin/Debug/config/Plc.Ini new file mode 100644 index 0000000..b73670d --- /dev/null +++ b/Aucma.Scada.UI/bin/Debug/config/Plc.Ini @@ -0,0 +1,17 @@ +[plcSystem] +PLCIP=127.0.0.1 +PLC˿=6000 +ڵPLCIP=127.0.0.1 +ڵPLC˿=6000 +[shell_outStore_address] +=M101 +=M102 +Ӧ=M103 +=M104 +=M105 +[liner_outStore_address] +=M201 +=M202 +Ӧ=M203 +=M204 +=M205 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 4a17a9c..d36ea11 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 b62c88e..41c3b4d 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 a47cfa8..922c6b7 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 f972b29..3f0c952 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/MainWindow.baml b/Aucma.Scada.UI/obj/Debug/MainWindow.baml index 2c6b31e..22b1e4a 100644 Binary files a/Aucma.Scada.UI/obj/Debug/MainWindow.baml and b/Aucma.Scada.UI/obj/Debug/MainWindow.baml differ diff --git a/Aucma.Scada.UI/obj/Debug/MainWindow.g.cs b/Aucma.Scada.UI/obj/Debug/MainWindow.g.cs index 3be3a92..77014b5 100644 --- a/Aucma.Scada.UI/obj/Debug/MainWindow.g.cs +++ b/Aucma.Scada.UI/obj/Debug/MainWindow.g.cs @@ -1,4 +1,4 @@ -#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "53ECC8664EAD4ED3B35A7728C0718F75FF25D4DA284A78D25AF8ADDDB5DA2F97" +#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "761197E72019FA48DD888520668F10CC0A0310CFF8A6F9336B14C0A351ACC259" //------------------------------------------------------------------------------ // // 此代码由工具生成。 diff --git a/Aucma.Scada.UI/obj/Debug/MainWindow.g.i.cs b/Aucma.Scada.UI/obj/Debug/MainWindow.g.i.cs index 3be3a92..77014b5 100644 --- a/Aucma.Scada.UI/obj/Debug/MainWindow.g.i.cs +++ b/Aucma.Scada.UI/obj/Debug/MainWindow.g.i.cs @@ -1,4 +1,4 @@ -#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "53ECC8664EAD4ED3B35A7728C0718F75FF25D4DA284A78D25AF8ADDDB5DA2F97" +#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "761197E72019FA48DD888520668F10CC0A0310CFF8A6F9336B14C0A351ACC259" //------------------------------------------------------------------------------ // // 此代码由工具生成。 diff --git a/Aucma.Scada.UI/viewModel/MainViewModel.cs b/Aucma.Scada.UI/viewModel/MainViewModel.cs index 7c308c9..70bea0e 100644 --- a/Aucma.Scada.UI/viewModel/MainViewModel.cs +++ b/Aucma.Scada.UI/viewModel/MainViewModel.cs @@ -1,4 +1,5 @@ -using Aucma.Scada.UI.Page.AssemblyPlan; +using Aucma.Scada.Business; +using Aucma.Scada.UI.Page.AssemblyPlan; using Aucma.Scada.UI.Page.InStoreInfo; using Aucma.Scada.UI.Page.InventoryInfo; using Aucma.Scada.UI.Page.OutStoreInfo; @@ -26,6 +27,8 @@ namespace Aucma.Scada.UI.viewModel private readonly InventoryInfoControl inventoryInfoControl = new InventoryInfoControl(); private readonly AssemblyPlanControl assemblyPlanControl = new AssemblyPlanControl(); + private MainBusiness mainBusiness = MainBusiness.Instance; + public MainViewModel() { ControlOnClickCommand = new RelayCommand(obj => ControlOnClick(obj)); diff --git a/HighWayIot.Common/StringChange.cs b/HighWayIot.Common/StringChange.cs index 6e30425..3bc168c 100644 --- a/HighWayIot.Common/StringChange.cs +++ b/HighWayIot.Common/StringChange.cs @@ -168,7 +168,7 @@ namespace HighWayIot.Common byte[] intBytes = new byte[floatBytes.Length / 2]; for (int i = 0; i < intBytes.Length; i++) { - intBytes[i] = floatBytes[i * 2 + 1]; + intBytes[i] = floatBytes[i * 2 ]; } return intBytes; } diff --git a/HighWayIot.Common/bin/Debug/HighWayIot.Common.dll b/HighWayIot.Common/bin/Debug/HighWayIot.Common.dll index 3718be0..56eb09e 100644 Binary files a/HighWayIot.Common/bin/Debug/HighWayIot.Common.dll and b/HighWayIot.Common/bin/Debug/HighWayIot.Common.dll differ diff --git a/HighWayIot.Common/bin/Debug/HighWayIot.Common.pdb b/HighWayIot.Common/bin/Debug/HighWayIot.Common.pdb index 42fbaf6..56306bb 100644 Binary files a/HighWayIot.Common/bin/Debug/HighWayIot.Common.pdb and b/HighWayIot.Common/bin/Debug/HighWayIot.Common.pdb differ diff --git a/HighWayIot.Common/obj/Debug/HighWayIot.Common.csproj.AssemblyReference.cache b/HighWayIot.Common/obj/Debug/HighWayIot.Common.csproj.AssemblyReference.cache index 01ceaa1..d41bfdb 100644 Binary files a/HighWayIot.Common/obj/Debug/HighWayIot.Common.csproj.AssemblyReference.cache and b/HighWayIot.Common/obj/Debug/HighWayIot.Common.csproj.AssemblyReference.cache differ diff --git a/HighWayIot.Common/obj/Debug/HighWayIot.Common.dll b/HighWayIot.Common/obj/Debug/HighWayIot.Common.dll index 3718be0..56eb09e 100644 Binary files a/HighWayIot.Common/obj/Debug/HighWayIot.Common.dll and b/HighWayIot.Common/obj/Debug/HighWayIot.Common.dll differ diff --git a/HighWayIot.Common/obj/Debug/HighWayIot.Common.pdb b/HighWayIot.Common/obj/Debug/HighWayIot.Common.pdb index 42fbaf6..56306bb 100644 Binary files a/HighWayIot.Common/obj/Debug/HighWayIot.Common.pdb and b/HighWayIot.Common/obj/Debug/HighWayIot.Common.pdb differ diff --git a/HighWayIot.Config/PlcConfig.cs b/HighWayIot.Config/PlcConfig.cs index bb39dcf..6bf232b 100644 --- a/HighWayIot.Config/PlcConfig.cs +++ b/HighWayIot.Config/PlcConfig.cs @@ -10,7 +10,7 @@ namespace HighWayIot.Config public sealed class PlcConfig { - private static IniHelper iniHelper = new IniHelper(System.Environment.CurrentDirectory + "/config/Plc.InI"); + private static IniHelper iniHelper = new IniHelper(System.Environment.CurrentDirectory + "/config/Plc.Ini"); private static readonly Lazy lazy = new Lazy(() => new PlcConfig()); @@ -28,6 +28,46 @@ namespace HighWayIot.Config { } + + #region PLC基础参数 + /// + /// 箱壳PLCIP + /// + public string shell_Plc_Ip + { + get { return iniHelper.IniReadValue("plcSystem", "箱壳PLCIP"); } + set { iniHelper.IniWriteValue("plcSystem", "箱壳PLCIP", value); } + } + + /// + /// 箱壳PLC端口 + /// + public int shell_Plc_Port + { + get { return stringChange.ParseToInt(iniHelper.IniReadValue("plcSystem", "箱壳PLC端口")); } + set { iniHelper.IniWriteValue("plcSystem", "箱壳PLC端口", value.ToString()); } + } + + /// + /// 内胆PLCIP + /// + public string liner_Plc_Ip + { + get { return iniHelper.IniReadValue("plcSystem", "内胆PLCIP"); } + set { iniHelper.IniWriteValue("plcSystem", "内胆PLCIP", value); } + } + + /// + /// 内胆PLC端口 + /// + public int liner_Plc_Port + { + get { return stringChange.ParseToInt(iniHelper.IniReadValue("plcSystem", "内胆PLC端口")); } + set { iniHelper.IniWriteValue("plcSystem", "内胆PLC端口", value.ToString()); } + } + #endregion + + #region 箱壳出库地址 /// /// 箱壳——出库货道号 /// @@ -46,6 +86,15 @@ namespace HighWayIot.Config set { iniHelper.IniWriteValue("shell_outStore_address", "出库数量", value); } } + /// + /// 箱壳——出库应答字 + /// + public string out_shell_answer + { + get { return iniHelper.IniReadValue("shell_outStore_address", "出库应答字"); } + set { iniHelper.IniWriteValue("shell_outStore_address", "出库应答字", value); } + } + /// /// 箱壳——出库任务号 /// @@ -55,6 +104,17 @@ namespace HighWayIot.Config set { iniHelper.IniWriteValue("shell_outStore_address", "出库任务号", value); } } + /// + /// 箱壳——出库完成 + /// + public string out_shell_finish + { + get { return iniHelper.IniReadValue("shell_outStore_address", "出库完成"); } + set { iniHelper.IniWriteValue("shell_outStore_address", "出库完成", value); } + } + #endregion + + #region 内胆出库地址 /// /// 内胆——出库货道号 /// @@ -63,7 +123,7 @@ namespace HighWayIot.Config get { return iniHelper.IniReadValue("liner_outStore_address", "出库货道号"); } set { iniHelper.IniWriteValue("liner_outStore_address", "出库货道号", value); } } - + /// /// 内胆——出库数量 /// @@ -73,6 +133,15 @@ namespace HighWayIot.Config set { iniHelper.IniWriteValue("liner_outStore_address", "出库数量", value); } } + /// + /// 内胆——出库应答字 + /// + public string out_liner_answer + { + get { return iniHelper.IniReadValue("liner_outStore_address", "出库应答字"); } + set { iniHelper.IniWriteValue("liner_outStore_address", "出库应答字", value); } + } + /// /// 内胆——出库任务号 /// @@ -82,5 +151,14 @@ namespace HighWayIot.Config set { iniHelper.IniWriteValue("liner_outStore_address", "出库任务号", value); } } + /// + /// 内胆——出库完成 + /// + public string out_liner_finish + { + get { return iniHelper.IniReadValue("liner_outStore_address", "出库完成"); } + set { iniHelper.IniWriteValue("liner_outStore_address", "出库完成", value); } + } + #endregion } } diff --git a/HighWayIot.Config/bin/Debug/HighWayIot.Common.dll b/HighWayIot.Config/bin/Debug/HighWayIot.Common.dll index 3718be0..56eb09e 100644 Binary files a/HighWayIot.Config/bin/Debug/HighWayIot.Common.dll and b/HighWayIot.Config/bin/Debug/HighWayIot.Common.dll differ diff --git a/HighWayIot.Config/bin/Debug/HighWayIot.Common.pdb b/HighWayIot.Config/bin/Debug/HighWayIot.Common.pdb index 42fbaf6..56306bb 100644 Binary files a/HighWayIot.Config/bin/Debug/HighWayIot.Common.pdb and b/HighWayIot.Config/bin/Debug/HighWayIot.Common.pdb differ diff --git a/HighWayIot.Config/bin/Debug/HighWayIot.Config.dll b/HighWayIot.Config/bin/Debug/HighWayIot.Config.dll index e0e8eda..c9bda2e 100644 Binary files a/HighWayIot.Config/bin/Debug/HighWayIot.Config.dll and b/HighWayIot.Config/bin/Debug/HighWayIot.Config.dll differ diff --git a/HighWayIot.Config/bin/Debug/HighWayIot.Config.pdb b/HighWayIot.Config/bin/Debug/HighWayIot.Config.pdb index 5508e12..3c45ae5 100644 Binary files a/HighWayIot.Config/bin/Debug/HighWayIot.Config.pdb and b/HighWayIot.Config/bin/Debug/HighWayIot.Config.pdb differ diff --git a/HighWayIot.Config/obj/Debug/HighWayIot.Config.csproj.AssemblyReference.cache b/HighWayIot.Config/obj/Debug/HighWayIot.Config.csproj.AssemblyReference.cache index 0d3c375..fb1ee6b 100644 Binary files a/HighWayIot.Config/obj/Debug/HighWayIot.Config.csproj.AssemblyReference.cache and b/HighWayIot.Config/obj/Debug/HighWayIot.Config.csproj.AssemblyReference.cache differ diff --git a/HighWayIot.Config/obj/Debug/HighWayIot.Config.dll b/HighWayIot.Config/obj/Debug/HighWayIot.Config.dll index e0e8eda..c9bda2e 100644 Binary files a/HighWayIot.Config/obj/Debug/HighWayIot.Config.dll and b/HighWayIot.Config/obj/Debug/HighWayIot.Config.dll differ diff --git a/HighWayIot.Config/obj/Debug/HighWayIot.Config.pdb b/HighWayIot.Config/obj/Debug/HighWayIot.Config.pdb index 5508e12..3c45ae5 100644 Binary files a/HighWayIot.Config/obj/Debug/HighWayIot.Config.pdb and b/HighWayIot.Config/obj/Debug/HighWayIot.Config.pdb differ diff --git a/HighWayIot.Log4net/obj/Debug/HighWayIot.Log4net.csproj.AssemblyReference.cache b/HighWayIot.Log4net/obj/Debug/HighWayIot.Log4net.csproj.AssemblyReference.cache index 9f24d29..1d2f582 100644 Binary files a/HighWayIot.Log4net/obj/Debug/HighWayIot.Log4net.csproj.AssemblyReference.cache and b/HighWayIot.Log4net/obj/Debug/HighWayIot.Log4net.csproj.AssemblyReference.cache differ diff --git a/HighWayIot.Mqtt/obj/Debug/HighWayIot.Mqtt.csproj.AssemblyReference.cache b/HighWayIot.Mqtt/obj/Debug/HighWayIot.Mqtt.csproj.AssemblyReference.cache index c0ed6b2..73f4408 100644 Binary files a/HighWayIot.Mqtt/obj/Debug/HighWayIot.Mqtt.csproj.AssemblyReference.cache and b/HighWayIot.Mqtt/obj/Debug/HighWayIot.Mqtt.csproj.AssemblyReference.cache differ diff --git a/HighWayIot.Plc/HighWayIot.Plc.csproj b/HighWayIot.Plc/HighWayIot.Plc.csproj index 1977e6e..3f1cd8c 100644 --- a/HighWayIot.Plc/HighWayIot.Plc.csproj +++ b/HighWayIot.Plc/HighWayIot.Plc.csproj @@ -46,9 +46,11 @@ + + diff --git a/HighWayIot.Plc/Impl/MelsecBinaryPlc.cs b/HighWayIot.Plc/Impl/MelsecBinaryPlc.cs new file mode 100644 index 0000000..294e2e3 --- /dev/null +++ b/HighWayIot.Plc/Impl/MelsecBinaryPlc.cs @@ -0,0 +1,444 @@ +using HighWayIot.Common; +using HighWayIot.Log4net; +using HslCommunication; +using HslCommunication.Profinet.Melsec; +using HslCommunication.Profinet.Omron; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HighWayIot.Plc.Impl +{ + /// + /// 三菱Q系列Plc-Binary + /// + public class MelsecBinaryPlc : IPlc + { + private LogHelper log = LogHelper.Instance; + + private StringChange stringChange = StringChange.Instance; + + private MelsecMcNet melsec_net = null; + + public MelsecBinaryPlc() + { + if (!HslCommunication.Authorization.SetAuthorizationCode("ed1415f8-e06a-43ad-95f7-c04f7ae93b41")) + { + log.Info("HslCommunication 11.0.6.0激活失败"); + return; + } + log.Info("HslCommunication 11.0.6.0激活成功"); + this.melsec_net = new MelsecMcNet(); + this.melsec_net.ConnectTimeOut = 2000; + } + + public bool IsConnected { get; set; } + + /// + /// 建立连接 + /// + /// + /// + /// + public bool Connect(string IP, int port) + { + log.PlcLog("欧姆龙NJ系列PLC连接开始"); + melsec_net.IpAddress = IP; + melsec_net.Port = port; + try + { + OperateResult connect = melsec_net.ConnectServer(); + if (connect.IsSuccess) + { + this.IsConnected = true; + log.PlcLog("欧姆龙NJ系列PLC建立连接成功!!!"); + return true; + } + else + { + this.IsConnected = false; + log.PlcLog("欧姆龙NJ系列PLC建立连接失败!!!"); + return false; + } + } + catch (Exception ex) + { + this.IsConnected = false; + log.Error("欧姆龙NJ系列PLC建立连接异常", ex); + return false; + } + } + + /// + /// 断开连接 + /// + /// + public bool DisConnect() + { + return melsec_net.ConnectClose().IsSuccess; + } + + /// + /// 通过地址和长度读取PLC数据 + /// + /// + /// + /// + /// + public byte[] readValueByAddress(int len, string address) + { + //log.PlcLog("开始通过PLC地址和长度读取PLC数据"); + try + { + OperateResult read = melsec_net.Read(address, (ushort)(len)); + if (read.IsSuccess) + { + byte[] result = stringChange.ConvertFloatToINt(read.Content); + log.PlcLog(String.Format("通过地址和长度读取PLC数据成功:{0}", stringChange.bytesToHexStr(result, result.Length))); + return result; + } + else + { + log.PlcLog("通过地址和长度读取PLC数据失败!!!"); + this.IsConnected = false; + return new byte[0]; + } + } + catch (Exception ex) + { + log.Error("通过地址和长度读取PLC数据异常", ex); + this.IsConnected = false; + return new byte[0]; + } + } + + /// + /// 通过PLC地址写入int类型数据 + /// + /// + /// + /// + /// + public bool writeValueByAddress(int value, string address) + { + //log.PlcLog(String.Format("开始通过PLC地址{0}写入int类型数据{1}",address,value)); + try + { + OperateResult operateResult = melsec_net.Write(address, Convert.ToInt32(value)); + if (operateResult.IsSuccess) + { + log.PlcLog(String.Format("开始通过PLC地址{0}写入int类型数据{1}成功", address, value)); + return true; + } + log.PlcLog(String.Format("开始通过PLC地址{0}写入int类型数据{1}失败!!!", address, value)); + this.IsConnected = false; + return false; + } + catch (Exception ex) + { + log.Error("通过PLC地址写入int类型数据", ex); + this.IsConnected = false; + return false; + } + } + + /// + /// 通过PLC地址清零数据 + /// + /// + /// + /// + /// + public bool resetByAddress(string address, int len) + { + //log.PlcLog(String.Format("开发通过PLC地址{0}清零数据", address)); + try + { + byte[] write = new byte[len * 2]; + for (int i = 0; i < len * 2; i++) + { + write[i] = 0; + } + OperateResult operateResult = melsec_net.Write(address, write); + + if (operateResult.IsSuccess) + { + log.PlcLog(String.Format("通过PLC地址{0}清零数据成功", address)); + return true; + } + log.PlcLog(String.Format("通过PLC地址{0}清零数据失败!!!", address)); + return false; + } + catch (Exception ex) + { + log.Error(String.Format("通过PLC地址{0}清零数据异常", address), ex); + return false; + } + } + + /// + /// 通过PLC地址读取EA值 + /// + /// + /// + /// + public string readEaByAddress(string address) + { + //log.PlcLog(String.Format("通过PLC地址{0}读取EA值", address)); + try + { + OperateResult read = melsec_net.Read(address, (ushort)(8)); + + if (read.IsSuccess && read.Content != null) + { + string result = Convert.ToString(read.Content); + log.PlcLog(String.Format("通过PLC地址{0}读取EA值成功:{1}", address, result)); + return result; + } + else + { + log.PlcLog(String.Format("通过PLC地址{0}读取EA值失败!!!", address)); + this.IsConnected = false; + return ""; + } + } + catch (Exception ex) + { + log.Error("通过PLC地址读取EA值异常", ex); + this.IsConnected = false; + return ""; + } + } + + /// + /// 通过PLC地址读取交互信号 + /// + /// + /// + public int readInteractiveSignal(string address) + { + //log.PlcLog(String.Format("开始通过PLC地址{0}读取交互信号", address)); + try + { + OperateResult read = melsec_net.ReadInt16(address); + if (read.IsSuccess) + { + log.PlcLog(String.Format("通过PLC地址{0}读取交互信号成功:{1}", address, read.Content)); + return read.Content; + } + log.PlcLog(String.Format("通过PLC地址{0}读取交互信号失败!!!", address)); + this.IsConnected = false; + return 0; + } + catch (Exception ex) + { + log.Error("通过PLC地址读取交互信号异常", ex); + this.IsConnected = false; + return 0; + } + } + + /// + /// 通过PLC地址读取int32类型数据 + /// + /// + /// + public int readInt32ByAddress(string address) + { + //log.PlcLog(String.Format("开始通过PLC地址{0}读取int32类型数据",address)); + try + { + OperateResult read = melsec_net.ReadInt16(address); + if (read.IsSuccess) + { + log.PlcLog(String.Format("通过PLC地址{0}读取int32类型数据成功:{1}", address, read.Content)); + return read.Content; + } + log.PlcLog(String.Format("通过PLC地址{0}读取int32类型数据失败!!!", address)); + this.IsConnected = false; + return 0; + } + catch (Exception ex) + { + log.Error("通过PLC地址读取int32类型数据异常", ex); + this.IsConnected = false; + return 0; + } + } + + /// + /// 通过PLC地址写入int32类型数据 + /// + /// + /// + /// + /// + public bool writeInt32ByAddress(string address, int value) + { + log.PlcLog(String.Format("开始通过PLC地址{0}写入int32类型数据{1}", address, value)); + try + { + OperateResult write = melsec_net.Write(address, short.Parse(Convert.ToString(value))); + if (write.IsSuccess) + { + log.PlcLog(String.Format("通过PLC地址{0}写入int32类型数据{1}成功", address, value)); + return true; + } + log.PlcLog(String.Format("通过PLC地址{0}写入int32类型数据{1}失败!!!", address, value)); + this.IsConnected = false; + return false; + } + catch (Exception ex) + { + log.Error(String.Format("通过PLC地址{0}写入int32类型数据异常", address), ex); + this.IsConnected = false; + return false; + } + } + + /// + /// 通过PLC地址写入String类型数据 + /// + /// + /// + /// + /// + public bool writeStringByAddress(string address, string value) + { + //log.PlcLog(String.Format("通过PLC地址{0}写入String类型数据{1}",address,value)); + try + { + OperateResult operateResult = melsec_net.Write(address, value); + if (operateResult.IsSuccess) + { + log.PlcLog(String.Format("通过PLC地址{0}写入String类型数据{1}成功", address, value)); + return true; + } + log.PlcLog(String.Format("通过PLC地址{0}写入String类型数据{1}失败!!!", address, value)); + //this.IsConnected = false; + return false; + } + catch (Exception ex) + { + log.Error(String.Format("通过PLC地址{0}写入String类型数据异常", address), ex); + //this.IsConnected = false; + return false; + } + } + + /// + /// 通过PLC地址读取string类型数据 + /// + /// + /// + /// + public string readStringByAddress(string address, ushort length) + { + //log.PlcLog(String.Format("开始通过PLC地址{0}读取string类型数据", address)); + try + { + OperateResult read = melsec_net.ReadString(address, length); + if (read.IsSuccess) + { + log.PlcLog(String.Format("通过PLC地址{0}读取string类型数据成功:{1}", address, read.Content)); + return read.Content; + } + log.PlcLog(String.Format("通过PLC地址{0}读取string类型数据失败!!!", address)); + this.IsConnected = false; + return ""; + } + catch (Exception ex) + { + log.Error("通过PLC地址读取int32类型数据异常", ex); + return ""; + } + } + + /// + /// 通过PLC地址读取Bool类型数据 + /// + /// + /// + /// + public bool readBoolByAddress(string address) + { + //log.PlcLog(String.Format("开始通过PLC地址{0}读取bool类型数据", address)); + try + { + OperateResult read = melsec_net.ReadBool(address); + if (read.IsSuccess) + { + log.PlcLog(String.Format("通过PLC地址{0}读取bool类型数据成功:{1}", address, read.Content)); + return read.Content; + } + log.PlcLog(String.Format("通过PLC地址{0}读取bool类型数据失败!!!", address)); + this.IsConnected = false; + return false; + } + catch (Exception ex) + { + log.Error("通过PLC地址读取int32类型数据异常", ex); + this.IsConnected = false; + return false; + } + } + + /// + /// 通过PLC地址写入Bool类型数据 + /// + /// + /// + /// + public bool writeBoolByAddress(string address, bool value) + { + //log.PlcLog(String.Format("开始通过PLC地址{0}写入bool类型数据{1}", address, value)); + try + { + OperateResult write = melsec_net.Write(address, short.Parse(stringChange.ParseToInt(value ? "1" : "0").ToString())); + if (write.IsSuccess) + { + log.PlcLog(String.Format("通过PLC地址{0}写入bool类型数据{1}成功", address, value)); + return true; + } + log.PlcLog(String.Format("通过PLC地址{0}写入bool类型数据{1}失败!!!", address, value)); + this.IsConnected = false; + return false; + } + catch (Exception ex) + { + log.Error(String.Format("通过PLC地址{0}写入bool类型数据异常", address), ex); + this.IsConnected = false; + return false; + } + } + + /// + /// 写入Double类型 + /// + /// + /// + /// + public bool writeDoubleByAddress(string address, int value) + { + try + { + OperateResult write = melsec_net.Write(address, Convert.ToDouble(value)); + + if (write.IsSuccess) + { + log.PlcLog(String.Format("通过PLC地址{0}写入Double类型数据{1}成功", address, value)); + return true; + } + log.PlcLog(String.Format("通过PLC地址{0}写入Double类型数据{1}失败!!!", address, value)); + return false; + } + catch (Exception ex) + { + log.Error(String.Format("通过PLC地址{0}写入Double类型数据异常", address), ex); + return false; + } + } + } +} diff --git a/HighWayIot.Plc/PlcPool.cs b/HighWayIot.Plc/PlcPool.cs new file mode 100644 index 0000000..cf70fdc --- /dev/null +++ b/HighWayIot.Plc/PlcPool.cs @@ -0,0 +1,107 @@ +using HighWayIot.Log4net; +using HighWayIot.Plc.Impl; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HighWayIot.Plc +{ + public sealed class PlcPool + { + private static readonly Lazy lazy = new Lazy(() => new PlcPool()); + public static PlcPool Instance + { + get + { + return lazy.Value; + } + } + + private LogHelper logHelper = LogHelper.Instance; + + private Dictionary keyValuePairs = new Dictionary(); + + private PlcPool() { } + + /// + /// 初始化Plc + /// + /// + /// + /// + /// + public void InitPlc(string plcType,string ip,int port,string key) + { + IPlc _plc = null; + switch(plcType) + { + case "InovancePlc": + _plc = new InovancePlc(); + break; + case "MelsecBinaryPlc": + _plc = new MelsecBinaryPlc(); + break; + case "OmronNJPlc": + _plc = new OmronNJPlc(); + break; + case "SiemensPlc": + _plc = new SiemensPlc(); + break; + default: + break; + } + var connectResult = _plc.Connect(ip, port); + if (connectResult) + { + keyValuePairs.Add(key, _plc); + } + } + + /// + /// 获取PLC + /// + /// + /// + public IPlc GetPlcByKey(string key) + { + return keyValuePairs[key]; + } + + /// + /// 获取所有PLC信息 + /// + /// + public Dictionary GetAll() + { + return keyValuePairs; + } + + /// + /// 关闭所有连接 + /// + /// + public bool disConnectAll() + { + bool result = false; + try + { + foreach (var kv in keyValuePairs) + { + if (kv.Value != null) + { + kv.Value.DisConnect(); + } + } + result = true; + } + catch(Exception ex) + { + logHelper.Error("关闭PLC连接异常", ex); + } + + return result; + } + } +} diff --git a/HighWayIot.Plc/bin/Debug/HighWayIot.Common.dll b/HighWayIot.Plc/bin/Debug/HighWayIot.Common.dll index 3718be0..56eb09e 100644 Binary files a/HighWayIot.Plc/bin/Debug/HighWayIot.Common.dll and b/HighWayIot.Plc/bin/Debug/HighWayIot.Common.dll differ diff --git a/HighWayIot.Plc/bin/Debug/HighWayIot.Common.pdb b/HighWayIot.Plc/bin/Debug/HighWayIot.Common.pdb index 42fbaf6..56306bb 100644 Binary files a/HighWayIot.Plc/bin/Debug/HighWayIot.Common.pdb and b/HighWayIot.Plc/bin/Debug/HighWayIot.Common.pdb differ diff --git a/HighWayIot.Plc/bin/Debug/HighWayIot.Plc.dll b/HighWayIot.Plc/bin/Debug/HighWayIot.Plc.dll index eb09175..08711b7 100644 Binary files a/HighWayIot.Plc/bin/Debug/HighWayIot.Plc.dll and b/HighWayIot.Plc/bin/Debug/HighWayIot.Plc.dll differ diff --git a/HighWayIot.Plc/bin/Debug/HighWayIot.Plc.pdb b/HighWayIot.Plc/bin/Debug/HighWayIot.Plc.pdb index 00cc086..02accd1 100644 Binary files a/HighWayIot.Plc/bin/Debug/HighWayIot.Plc.pdb and b/HighWayIot.Plc/bin/Debug/HighWayIot.Plc.pdb differ diff --git a/HighWayIot.Plc/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/HighWayIot.Plc/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index 2be310f..f5c0fa6 100644 Binary files a/HighWayIot.Plc/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/HighWayIot.Plc/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.csproj.AssemblyReference.cache b/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.csproj.AssemblyReference.cache index ba15485..bbc3a57 100644 Binary files a/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.csproj.AssemblyReference.cache and b/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.csproj.AssemblyReference.cache differ diff --git a/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.csproj.CoreCompileInputs.cache b/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.csproj.CoreCompileInputs.cache index 7c9f879..d9f1da1 100644 --- a/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.csproj.CoreCompileInputs.cache +++ b/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -887f1b5161fe575aee2d999ec37f9cca0db15a25 +f80abeff4f54f6d92641a5ca021a378fc773b991 diff --git a/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.dll b/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.dll index eb09175..08711b7 100644 Binary files a/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.dll and b/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.dll differ diff --git a/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.pdb b/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.pdb index 00cc086..02accd1 100644 Binary files a/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.pdb and b/HighWayIot.Plc/obj/Debug/HighWayIot.Plc.pdb differ diff --git a/HighWayIot.Repository/bin/Debug/HighWayIot.Common.dll b/HighWayIot.Repository/bin/Debug/HighWayIot.Common.dll index 3718be0..56eb09e 100644 Binary files a/HighWayIot.Repository/bin/Debug/HighWayIot.Common.dll and b/HighWayIot.Repository/bin/Debug/HighWayIot.Common.dll differ diff --git a/HighWayIot.Repository/bin/Debug/HighWayIot.Common.pdb b/HighWayIot.Repository/bin/Debug/HighWayIot.Common.pdb index 42fbaf6..56306bb 100644 Binary files a/HighWayIot.Repository/bin/Debug/HighWayIot.Common.pdb and b/HighWayIot.Repository/bin/Debug/HighWayIot.Common.pdb differ diff --git a/HighWayIot.Repository/bin/Debug/HighWayIot.Config.dll b/HighWayIot.Repository/bin/Debug/HighWayIot.Config.dll index e0e8eda..c9bda2e 100644 Binary files a/HighWayIot.Repository/bin/Debug/HighWayIot.Config.dll and b/HighWayIot.Repository/bin/Debug/HighWayIot.Config.dll differ diff --git a/HighWayIot.Repository/bin/Debug/HighWayIot.Config.pdb b/HighWayIot.Repository/bin/Debug/HighWayIot.Config.pdb index 5508e12..3c45ae5 100644 Binary files a/HighWayIot.Repository/bin/Debug/HighWayIot.Config.pdb and b/HighWayIot.Repository/bin/Debug/HighWayIot.Config.pdb differ diff --git a/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.dll b/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.dll index a02a238..e254c3b 100644 Binary files a/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.dll and b/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.dll differ diff --git a/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.pdb b/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.pdb index c2c4184..e970a13 100644 Binary files a/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.pdb and b/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.pdb differ diff --git a/HighWayIot.Repository/obj/Debug/HighWayIot.Repository.csproj.AssemblyReference.cache b/HighWayIot.Repository/obj/Debug/HighWayIot.Repository.csproj.AssemblyReference.cache index 20c0165..2cf95fd 100644 Binary files a/HighWayIot.Repository/obj/Debug/HighWayIot.Repository.csproj.AssemblyReference.cache and b/HighWayIot.Repository/obj/Debug/HighWayIot.Repository.csproj.AssemblyReference.cache differ diff --git a/HighWayIot.Repository/obj/Debug/HighWayIot.Repository.dll b/HighWayIot.Repository/obj/Debug/HighWayIot.Repository.dll index a02a238..e254c3b 100644 Binary files a/HighWayIot.Repository/obj/Debug/HighWayIot.Repository.dll and b/HighWayIot.Repository/obj/Debug/HighWayIot.Repository.dll differ diff --git a/HighWayIot.Repository/obj/Debug/HighWayIot.Repository.pdb b/HighWayIot.Repository/obj/Debug/HighWayIot.Repository.pdb index c2c4184..e970a13 100644 Binary files a/HighWayIot.Repository/obj/Debug/HighWayIot.Repository.pdb and b/HighWayIot.Repository/obj/Debug/HighWayIot.Repository.pdb differ diff --git a/HighWayIot.Repository/service/Impl/RealTaskInfoServiceImpl.cs b/HighWayIot.Repository/service/Impl/RealTaskInfoServiceImpl.cs index e00e61b..77de48c 100644 --- a/HighWayIot.Repository/service/Impl/RealTaskInfoServiceImpl.cs +++ b/HighWayIot.Repository/service/Impl/RealTaskInfoServiceImpl.cs @@ -150,7 +150,7 @@ namespace HighWayIot.Repository.service.Impl RealTaskInfo taskInfo = null; try { - taskInfo = _mesRepository.GetFirst(x => string.IsNullOrEmpty(storeCode) ? 1==1 : x.storeCode == storeCode && x.taskCode == taskCode); + taskInfo = _mesRepository.GetFirst(x => x.storeCode == storeCode && x.taskCode == taskCode); } catch (Exception ex) { diff --git a/HighWayIot.Rfid/bin/Debug/HighWayIot.Common.dll b/HighWayIot.Rfid/bin/Debug/HighWayIot.Common.dll index 3718be0..56eb09e 100644 Binary files a/HighWayIot.Rfid/bin/Debug/HighWayIot.Common.dll and b/HighWayIot.Rfid/bin/Debug/HighWayIot.Common.dll differ diff --git a/HighWayIot.Rfid/bin/Debug/HighWayIot.Common.pdb b/HighWayIot.Rfid/bin/Debug/HighWayIot.Common.pdb index 42fbaf6..56306bb 100644 Binary files a/HighWayIot.Rfid/bin/Debug/HighWayIot.Common.pdb and b/HighWayIot.Rfid/bin/Debug/HighWayIot.Common.pdb differ diff --git a/HighWayIot.Rfid/obj/Debug/HighWayIot.Rfid.csproj.AssemblyReference.cache b/HighWayIot.Rfid/obj/Debug/HighWayIot.Rfid.csproj.AssemblyReference.cache index 4dd908c..ca8012d 100644 Binary files a/HighWayIot.Rfid/obj/Debug/HighWayIot.Rfid.csproj.AssemblyReference.cache and b/HighWayIot.Rfid/obj/Debug/HighWayIot.Rfid.csproj.AssemblyReference.cache differ diff --git a/HighWayIot.TouchSocket/obj/Debug/HighWayIot.TouchSocket.csproj.AssemblyReference.cache b/HighWayIot.TouchSocket/obj/Debug/HighWayIot.TouchSocket.csproj.AssemblyReference.cache index e547007..f2727e4 100644 Binary files a/HighWayIot.TouchSocket/obj/Debug/HighWayIot.TouchSocket.csproj.AssemblyReference.cache and b/HighWayIot.TouchSocket/obj/Debug/HighWayIot.TouchSocket.csproj.AssemblyReference.cache differ diff --git a/HighWayIot.TouchSocket/obj/Debug/HighWayIot.TouchSocket.csproj.CopyComplete b/HighWayIot.TouchSocket/obj/Debug/HighWayIot.TouchSocket.csproj.CopyComplete deleted file mode 100644 index e69de29..0000000 diff --git a/HighWayIot/bin/Debug/HighWayIot.Common.dll b/HighWayIot/bin/Debug/HighWayIot.Common.dll index 3718be0..56eb09e 100644 Binary files a/HighWayIot/bin/Debug/HighWayIot.Common.dll and b/HighWayIot/bin/Debug/HighWayIot.Common.dll differ diff --git a/HighWayIot/bin/Debug/HighWayIot.Common.pdb b/HighWayIot/bin/Debug/HighWayIot.Common.pdb index 42fbaf6..56306bb 100644 Binary files a/HighWayIot/bin/Debug/HighWayIot.Common.pdb and b/HighWayIot/bin/Debug/HighWayIot.Common.pdb differ diff --git a/HighWayIot/bin/Debug/HighWayIot.Config.dll b/HighWayIot/bin/Debug/HighWayIot.Config.dll index e0e8eda..c9bda2e 100644 Binary files a/HighWayIot/bin/Debug/HighWayIot.Config.dll and b/HighWayIot/bin/Debug/HighWayIot.Config.dll differ diff --git a/HighWayIot/bin/Debug/HighWayIot.Config.pdb b/HighWayIot/bin/Debug/HighWayIot.Config.pdb index 5508e12..3c45ae5 100644 Binary files a/HighWayIot/bin/Debug/HighWayIot.Config.pdb and b/HighWayIot/bin/Debug/HighWayIot.Config.pdb differ diff --git a/HighWayIot/bin/Debug/HighWayIot.Repository.dll b/HighWayIot/bin/Debug/HighWayIot.Repository.dll index a02a238..e254c3b 100644 Binary files a/HighWayIot/bin/Debug/HighWayIot.Repository.dll and b/HighWayIot/bin/Debug/HighWayIot.Repository.dll differ diff --git a/HighWayIot/bin/Debug/HighWayIot.Repository.pdb b/HighWayIot/bin/Debug/HighWayIot.Repository.pdb index c2c4184..e970a13 100644 Binary files a/HighWayIot/bin/Debug/HighWayIot.Repository.pdb and b/HighWayIot/bin/Debug/HighWayIot.Repository.pdb differ diff --git a/HighWayIot/obj/Debug/HighWayIot.csproj.AssemblyReference.cache b/HighWayIot/obj/Debug/HighWayIot.csproj.AssemblyReference.cache index c03d678..2278ca8 100644 Binary files a/HighWayIot/obj/Debug/HighWayIot.csproj.AssemblyReference.cache and b/HighWayIot/obj/Debug/HighWayIot.csproj.AssemblyReference.cache differ