using HighWayIot.Common; 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; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Aucma.Scada.Business { public sealed class TaskHandleBusiness { private static readonly Lazy lazy = new Lazy(() => new TaskHandleBusiness()); public static TaskHandleBusiness Instance { get { return lazy.Value; } } public delegate void OutStoreFinsih(string storeCode,string taskCode); public event OutStoreFinsih OutStoreFinsihEvent; private IPlc _plc = new SiemensPlc(); private LogHelper logHelper = LogHelper.Instance; private AppConfig appConfig = AppConfig.Instance; private PlcConfig plcConfig = PlcConfig.Instance; private TaskHandleBusiness() { } public void Inite() { _plc.Connect("127.0.0.1", 124); } public bool SendOutStoreTask(RealTaskInfo realTaskInfo) { bool result = false; try { //写入货道号 _plc.writeStringByAddress(plcConfig.out_shell_spaceCode, realTaskInfo.spaceCode); //写入出库数量 _plc.writeInt32ByAddress(plcConfig.out_shell_amount, realTaskInfo.planAmount); //写入任务号 _plc.writeStringByAddress(plcConfig.out_shell_task, realTaskInfo.taskCode); //写入应答字 _plc.writeInt32ByAddress("", 1); result = true; } catch(Exception ex) { logHelper.Error("出库任务下发异常", ex); } return result; } private void ReadPlc() { if(_plc.readInt32ByAddress("") == 1) // 读取PLC出库应答字,出库完成后读取任务号 { string taskCode = _plc.readStringByAddress("", (ushort)12); OutStoreFinsihEvent?.Invoke(appConfig.shellStoreCode, taskCode); } } } }