diff --git a/Aucma.Scada.Business/AssemblyPlanBusiness.cs b/Aucma.Scada.Business/AssemblyPlanBusiness.cs index 798aea2..6b19aaa 100644 --- a/Aucma.Scada.Business/AssemblyPlanBusiness.cs +++ b/Aucma.Scada.Business/AssemblyPlanBusiness.cs @@ -164,6 +164,7 @@ namespace Aucma.Scada.Business if (appConfig.shellStoreCode == storeCode) { baseBomInfo = _bomInfoService.GetBomInfoByMaterialCode(planInfo.materialCode); + } else { @@ -197,10 +198,13 @@ namespace Aucma.Scada.Business catch (Exception ex) { logHelper.Error("计划下达判断库存异常", ex); + } return result; } + + /// /// 根据生产计划下达执行计划 /// diff --git a/Aucma.Scada.Business/Aucma.Scada.Business.csproj b/Aucma.Scada.Business/Aucma.Scada.Business.csproj index 9f61951..809d2ab 100644 --- a/Aucma.Scada.Business/Aucma.Scada.Business.csproj +++ b/Aucma.Scada.Business/Aucma.Scada.Business.csproj @@ -57,6 +57,7 @@ + diff --git a/Aucma.Scada.Business/GunBusiness.cs b/Aucma.Scada.Business/GunBusiness.cs new file mode 100644 index 0000000..260043a --- /dev/null +++ b/Aucma.Scada.Business/GunBusiness.cs @@ -0,0 +1,121 @@ +using Aucma.Scada.Model.domain; +using HighWayIot.Common; +using HighWayIot.Config; +using HighWayIot.Log4net; +using HighWayIot.Plc; +using HighWayIot.Repository.service; +using System; +using System.Collections.Generic; +using System.IO.Ports; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Aucma.Scada.Business +{ + /// + /// 入库任务处理 + /// + public sealed class GunBusiness + { + private static AppConfig appConfig = AppConfig.Instance; + private static SerialPort serialPort = new SerialPort(); + + #region 单例实现 + private static readonly GunBusiness lazy = new GunBusiness(); + + #region 变量定义 + //箱体码 + private static string ShellCode = string.Empty; + // 内胆码 + private static string LinerCode = string.Empty; + #endregion + + /// + /// 扫码委托 + /// + /// + /// + public delegate void RefreshMaterialCodeStr(string ShellCode, string LinerCode); + public static event RefreshMaterialCodeStr RefreshMaterialCodeStrEvent; + + public static GunBusiness Instance + { + get + { + return lazy; + } + } + #endregion + + + + //初始化串口并启动接收数据 + public static void InstanceSerialPort3() + { + try + { + string port = System.IO.Ports.SerialPort.GetPortNames().FirstOrDefault(); + //实例化串行端口 + + //端口名 注:因为使用的是USB转RS232 所以去设备管理器中查看一下虚拟com口的名字 + serialPort.PortName = port;// portName; + //波特率 霍尼威尔扫码枪115200,普通9600 + serialPort.BaudRate = int.Parse(appConfig.BaudRate); ; + //奇偶校验 + serialPort.Parity = Parity.None; + //停止位 + serialPort.StopBits = StopBits.One; + //数据位 + serialPort.DataBits = 8; + //忽略null字节 + serialPort.DiscardNull = true; + + //接收事件 + serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort1_DataReceived); + + //开启串口 + serialPort.Open(); + } + catch (Exception ex) + { + + + } + } + + private static void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) + { + Thread.Sleep(50); + int nums = serialPort.BytesToRead; + byte[] receiveBytes = new byte[nums]; + serialPort.Read(receiveBytes, 0, nums); + + StringBuilder sb = new StringBuilder(); + + string str = Encoding.ASCII.GetString(receiveBytes).Replace("\r\n", "").Replace("\r", "").Replace("\n", ""); + if (str.Substring(0, 1) == "B") + { + ShellCode = str; + } + else if (str.Substring(0, 1) == "L") + { + LinerCode = str; + } + // 业务处理 + if (!string.IsNullOrEmpty(ShellCode) && !string.IsNullOrEmpty(LinerCode)) + { + // 业务处理,条码绑定 + RefreshMaterialCodeStrEvent?.Invoke(ShellCode, LinerCode); + + // 清空 + ShellCode = string.Empty; + LinerCode = string.Empty; + } + sb.Clear(); + } + + + } +} diff --git a/Aucma.Scada.Business/InStoreTaskHandle.cs b/Aucma.Scada.Business/InStoreTaskHandle.cs index d9c08a6..63c3ec8 100644 --- a/Aucma.Scada.Business/InStoreTaskHandle.cs +++ b/Aucma.Scada.Business/InStoreTaskHandle.cs @@ -210,8 +210,10 @@ namespace Aucma.Scada.Business try { IPlc _plc = null; + _plcDictionary = _pool.GetAll(); if (storeCode == appConfig.shellStoreCode) { + _plc = _plcDictionary[appConfig.shellStoreCode]; if (_plc != null) { @@ -244,6 +246,7 @@ namespace Aucma.Scada.Business int result = 0; try { + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[taskInfo.storeCode]; if (_plc != null) @@ -288,6 +291,7 @@ namespace Aucma.Scada.Business lock (string.Empty) { bool isFlag = true; + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[appConfig.shellStoreCode]; try { @@ -350,6 +354,7 @@ namespace Aucma.Scada.Business int result = 0; try { + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[appConfig.linerStoreCode]; if (_plc != null) @@ -398,6 +403,7 @@ namespace Aucma.Scada.Business lock (string.Empty) { bool isFlag = true; + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[appConfig.linerStoreCode]; try { @@ -459,6 +465,7 @@ namespace Aucma.Scada.Business { try { + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[appConfig.shellStoreCode]; Task.Run(() => @@ -509,6 +516,7 @@ namespace Aucma.Scada.Business { try { + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[appConfig.linerStoreCode]; Task.Run(() => @@ -566,6 +574,7 @@ namespace Aucma.Scada.Business try { var spaceAddress = spaceConfig.GetSpaceAddress(spaceInfo.storeCode, spaceInfo.spaceCode); + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[spaceInfo.storeCode]; // int i = _plc.readInt32ByAddress(plcConfig.in_shell_spaceCode); diff --git a/Aucma.Scada.Business/MainBusiness.cs b/Aucma.Scada.Business/MainBusiness.cs index 53a80fa..34e1b60 100644 --- a/Aucma.Scada.Business/MainBusiness.cs +++ b/Aucma.Scada.Business/MainBusiness.cs @@ -43,12 +43,13 @@ namespace Aucma.Scada.Business /// /// 初始化PLC /// - public void InitPlc() + public async void InitPlc() { //初始化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); - + // 心跳 + await plcPool.StartMelsecPlcAsync(); } /// diff --git a/Aucma.Scada.Business/OutStoreTaskHandle.cs b/Aucma.Scada.Business/OutStoreTaskHandle.cs index 62ffa13..7992e62 100644 --- a/Aucma.Scada.Business/OutStoreTaskHandle.cs +++ b/Aucma.Scada.Business/OutStoreTaskHandle.cs @@ -127,6 +127,7 @@ namespace Aucma.Scada.Business int result = 0; try { + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[appConfig.shellStoreCode]; if (_plc != null) @@ -172,6 +173,7 @@ namespace Aucma.Scada.Business private void ReadShellAnswer_OutStore(RealTaskInfo taskInfo) { bool isFlag = true; + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[appConfig.shellStoreCode]; try { @@ -225,6 +227,7 @@ namespace Aucma.Scada.Business lock (string.Empty) { bool isFlag = true; + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[appConfig.shellStoreCode]; shellTaskCode = taskInfo.taskCode; try @@ -246,7 +249,6 @@ namespace Aucma.Scada.Business isFlag = false; - } Thread.Sleep(500); @@ -283,12 +285,12 @@ namespace Aucma.Scada.Business int result = 0; try { + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[appConfig.linerStoreCode]; if (_plc != null) { - if (_plc.readInt32ByAddress(plcConfig.out_liner_answer) == 1) { logHelper.Info("内胆出库应答字为1,货道号:" + plcConfig.out_shell_spaceCode + ";写" + short.Parse(taskInfo.spaceCode.Substring(5, 1))); @@ -328,6 +330,7 @@ namespace Aucma.Scada.Business private void ReadLinerAnswer_OutStore(RealTaskInfo taskInfo) { bool isFlag = true; + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[appConfig.linerStoreCode]; try { @@ -386,6 +389,7 @@ namespace Aucma.Scada.Business try { bool isFlag = true; + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[appConfig.linerStoreCode]; if (_plc != null) { @@ -568,6 +572,7 @@ namespace Aucma.Scada.Business public BaseSpaceInfo ReadSpaceInfoByPlc(BaseSpaceInfo spaceInfo) { var spaceAddress = spaceConfig.GetSpaceAddress(spaceInfo.storeCode, spaceInfo.spaceCode); + _plcDictionary = _pool.GetAll(); IPlc _plc = _plcDictionary[spaceInfo.storeCode]; if (_plc != null) diff --git a/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.dll b/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.dll index 2dab8e6..6600da3 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 393226b..1da7da6 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.Config.dll b/Aucma.Scada.Business/bin/Debug/HighWayIot.Config.dll index d3ab9df..a7bbf07 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 d466e5a..5032f69 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 3b7e3da..0d3d39c 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 620100e..ab5b3d4 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.HikRobot/bin/Debug/HighWayIot.Config.dll b/Aucma.Scada.HikRobot/bin/Debug/HighWayIot.Config.dll index d3ab9df..a7bbf07 100644 Binary files a/Aucma.Scada.HikRobot/bin/Debug/HighWayIot.Config.dll and b/Aucma.Scada.HikRobot/bin/Debug/HighWayIot.Config.dll differ diff --git a/Aucma.Scada.HikRobot/bin/Debug/HighWayIot.Config.pdb b/Aucma.Scada.HikRobot/bin/Debug/HighWayIot.Config.pdb index d466e5a..5032f69 100644 Binary files a/Aucma.Scada.HikRobot/bin/Debug/HighWayIot.Config.pdb and b/Aucma.Scada.HikRobot/bin/Debug/HighWayIot.Config.pdb differ diff --git a/Aucma.Scada.UI/App.xaml.cs b/Aucma.Scada.UI/App.xaml.cs index 2cd1e10..c1fd503 100644 --- a/Aucma.Scada.UI/App.xaml.cs +++ b/Aucma.Scada.UI/App.xaml.cs @@ -41,6 +41,7 @@ namespace Aucma.Scada.UI { mainBusiness.InitPlc(); mainBusiness.InitHikRobot(); + GunBusiness.InstanceSerialPort3(); } } private void Application_Exit(object sender, ExitEventArgs e) diff --git a/Aucma.Scada.UI/MainWindow.xaml b/Aucma.Scada.UI/MainWindow.xaml index 81713af..72defee 100644 --- a/Aucma.Scada.UI/MainWindow.xaml +++ b/Aucma.Scada.UI/MainWindow.xaml @@ -70,6 +70,7 @@