| | |
| | | using DocumentFormat.OpenXml.Drawing; |
| | | using Furion.Logging; |
| | | using Microsoft.AspNetCore.SignalR; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using System; |
| | | //using WCS.Application.Util; |
| | | |
| | | namespace WCS.Application; |
| | | public static class PLCTaskAction |
| | |
| | | public static bool boRefresh = false; |
| | | //演示模式 |
| | | public static bool boDemo = false; |
| | | //滚筒反转 |
| | | public static bool boDrumReversal = false; |
| | | //出库锁定 |
| | | public static bool boOutLock = false; |
| | | //入库锁定 |
| | | public static bool boEnterLock = false; |
| | | |
| | | public static List<PlcPositionInfo> listPositionInfo = new List<PlcPositionInfo>(); |
| | | |
| | |
| | | boOffline = _sysConfigService.GetConfigValue<bool>("sys_Offline").Result; |
| | | boRefresh = _sysConfigService.GetConfigValue<bool>("sys_Refresh").Result; |
| | | boDemo = _sysConfigService.GetConfigValue<bool>("sys_demo").Result; |
| | | boDrumReversal = _sysConfigService.GetConfigValue<bool>("sys_DrumReversal").Result; |
| | | boOutLock = _sysConfigService.GetConfigValue<bool>("sys_BoOutLock").Result; |
| | | boEnterLock = _sysConfigService.GetConfigValue<bool>("sys_BoEnterLock").Result; |
| | | } |
| | | /// <summary> |
| | | /// 初始化PLC连接 |
| | | /// </summary> |
| | | public static void Init() |
| | | { |
| | | // var strMsg = new HttpService().RequestPackWcs("LN000001"); |
| | | cts.Cancel(); |
| | | listPlc = _db.Queryable<WcsPlc>() |
| | | .Where(s => s.Type == PLCTypeEnum.StackingMachine || s.Type == PLCTypeEnum.ConveyorLine || s.Type == PLCTypeEnum.BoxConveyorLine) |
| | |
| | | } |
| | | if (!modPlcUtil.Connected) |
| | | { |
| | | Thread.Sleep(10000); |
| | | Thread.Sleep(1000); |
| | | modPlcUtil.Open(); |
| | | continue; |
| | | } |
| | |
| | | { |
| | | //Console.WriteLine($"{modPlc.IP}读取{modDevice.DbNumber}.{modDevice.PlcPos}的值为:{value}"); |
| | | //无流程跳出 |
| | | if (value == 0) |
| | | if (value == 0)// && modPlc.Type!= PLCTypeEnum.BoxConveyorLine |
| | | continue; |
| | | var dto = modDevice.Adapt<WcsDeviceDto>(); |
| | | dto.Value = value; |
| | |
| | | HubUtil.PublicPlcConn(modPlc); |
| | | } |
| | | } |
| | | Thread.Sleep(1000); |
| | | Thread.Sleep(10000); |
| | | } |
| | | } |
| | | catch (OperationCanceledException) |
| | |
| | | { |
| | | //报警点位 |
| | | var listAlarm = listAlarmInfo.Where(s => s.PlcIP == modUtil.PlcIP.ToString()).ToList(); |
| | | //Console.WriteLine("报警点位数:" + listAlarm.Count); |
| | | var listaddress = new Dictionary<string, PLCDataTypeEnum>(); |
| | | foreach (var modAlarm in listAlarm) |
| | | { |
| | | listaddress.Add(modAlarm.AlarmCode, PLCDataTypeEnum.Bit); |
| | | } |
| | | //Console.WriteLine($"读取点位{listaddress.Count}个"); |
| | | var result = modUtil.GetPlcBatchDBValue(listaddress); |
| | | //Console.WriteLine("err" + result.Err); |
| | | var listPulish = new List<WcsAlarmInfo>(); |
| | | //测试报警 |
| | | //foreach (var modAlarm in listAlarm) |
| | | //{ |
| | | // result.Value.Add(modAlarm.AlarmCode, true); |
| | | //} |
| | | foreach (var item in result.Value) |
| | | { |
| | | var value = Convert.ToBoolean(item.Value); |
| | | //Console.WriteLine(item.Key + "+" + value); |
| | | var modAlarm = listAlarm.FirstOrDefault(s => s.AlarmCode == item.Key); |
| | | var stationNum = modAlarm.StationNum; |
| | | if (value && modAlarm.Status == YesNoEnum.N) |
| | | { |
| | | //修改报警状态同时记录报警日志 |
| | |
| | | listPulish.Add(modAlarm); |
| | | } |
| | | //取消报警 |
| | | else if (value && modAlarm.Status == YesNoEnum.Y) |
| | | else if (!value && modAlarm.Status == YesNoEnum.Y) |
| | | { |
| | | modAlarm.AlarmTime = null; |
| | | modAlarm.Status = YesNoEnum.N; |
| | |
| | | modLog.Id = 0; |
| | | listLog.Add(modLog); |
| | | } |
| | | _db.Insertable(listLog).ExecuteCommand(); |
| | | if (listLog.Count >= 0) |
| | | _db.Insertable(listLog).ExecuteCommand(); |
| | | HubUtil.PublicAlarm(listPulish); |
| | | } |
| | | } |
| | |
| | | { |
| | | if (modPlcUtil == null) |
| | | continue; |
| | | var plcIp = modPlcUtil.PlcIP; |
| | | var listDevice = listPlcDevice.Where(s => s.PlcId == modPlcUtil.PlcId && s.DeviceType == DeviceTypeEnum.Show).ToList(); |
| | | var modPlc = listPlc.FirstOrDefault(s => s.Id == modPlcUtil.PlcId); var listaddress = new Dictionary<string, PLCDataTypeEnum>(); |
| | | var modPlc = listPlc.FirstOrDefault(s => s.Id == modPlcUtil.PlcId); |
| | | var listaddress = new Dictionary<string, PLCDataTypeEnum>(); |
| | | foreach (var modDevice in listDevice) |
| | | { |
| | | listaddress.Add(modDevice.DbNumber + "." + modDevice.PlcPos, modDevice.PosType); |
| | |
| | | break; |
| | | case PLCTypeEnum.ConveyorLine: |
| | | { |
| | | var value = Convert.ToBoolean(item.Value); |
| | | if (value != modDevice.BoHaveItem) |
| | | var bl = false; |
| | | int value = Convert.ToInt32(item.Value); |
| | | if (value <= 30) |
| | | { |
| | | modDevice.BoHaveItem = value; |
| | | //下发状态 |
| | | var modInfo = new PlcPositionInfo() { Type = modPlc.Type, StationNum = modDevice.StationNum, BoHaveItem = value }; |
| | | bl = false; |
| | | } |
| | | else |
| | | { |
| | | bl = true; |
| | | } |
| | | |
| | | if (bl != modDevice.BoHaveItem) |
| | | { |
| | | modDevice.BoHaveItem = bl; |
| | | var modInfo = new PlcPositionInfo() { Type = modPlc.Type, StationNum = modDevice.StationNum.PadLeft(3, '0'), BoHaveItem = bl }; |
| | | HubUtil.PublicPosition(modInfo); |
| | | UpdatePosition(modInfo); |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | Thread.Sleep(300); |
| | | Thread.Sleep(3000); |
| | | } |
| | | catch (Exception ex) |
| | | { |