| | |
| | | public static bool boRefresh = false; |
| | | //演示模式 |
| | | public static bool boDemo = false; |
| | | //滚筒反转 |
| | | public static bool boDrumReversal = false; |
| | | |
| | | public static List<PlcPositionInfo> listPositionInfo = new List<PlcPositionInfo>(); |
| | | |
| | | private static readonly ISqlSugarClient _db = SqlSugarSetup.ITenant.GetConnectionScope(SqlSugarConst.MainConfigId); |
| | | private static readonly SysCacheService sysCacheService = App.GetRequiredService<SysCacheService>(); |
| | | private static readonly IHubContext<PlcHub, IPlcHub> _plcHubContext = App.GetService<IHubContext<PlcHub, IPlcHub>>(); |
| | | private static readonly SysConfigService _sysConfigService = App.GetService<SysConfigService>(); |
| | | |
| | | private static List<WcsPlc> listPlc = new List<WcsPlc>(); |
| | |
| | | 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; |
| | | } |
| | | /// <summary> |
| | | /// 初始化PLC连接 |
| | |
| | | public static void Init() |
| | | { |
| | | cts.Cancel(); |
| | | listPlc = _db.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.StackingMachine || s.Type == PLCTypeEnum.ConveyorLine || s.Type == PLCTypeEnum.BoxConveyorLine).ToList(); |
| | | listPlc = _db.Queryable<WcsPlc>() |
| | | .Where(s => s.Type == PLCTypeEnum.StackingMachine || s.Type == PLCTypeEnum.ConveyorLine || s.Type == PLCTypeEnum.BoxConveyorLine) |
| | | .Where(s => s.Enable == YesNoEnum.Y) |
| | | .ToList(); |
| | | listPlcDevice = _db.Queryable<WcsDevice>().ToList(); |
| | | listPlcPosition = _db.Queryable<WcsPosition>().ToList(); |
| | | listAlarmInfo = _db.Queryable<WcsAlarmInfo>().ToList(); |
| | |
| | | var plc = new PLCUtil(modPlc); |
| | | listPlcUtil.Add(plc); |
| | | } |
| | | _plcHubContext.Clients.All.UpdateService(new PLCServiceModel() |
| | | HubUtil.UpdateService(new PLCServiceModel() |
| | | { |
| | | BoRunningState = boRunningState, |
| | | BoOffline = boOffline, |
| | |
| | | { |
| | | //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; |
| | |
| | | } |
| | | } |
| | | |
| | | Thread.Sleep(10000); |
| | | Thread.Sleep(1000); |
| | | } |
| | | catch (OperationCanceledException) |
| | | { |
| | |
| | | { |
| | | //连接状态变更 通知前端 |
| | | Console.WriteLine($"通知前端变更{modPlc.Text} {modPlc.IsConn}"); |
| | | _plcHubContext.Clients.All.PublicPlcConn(modPlc); |
| | | HubUtil.PublicPlcConn(modPlc); |
| | | } |
| | | sysCacheService.Set("PLCCONN:" + modPlc.Id, modPlc); |
| | | } |
| | | else |
| | | { |
| | | sysCacheService.Set("PLCCONN:" + modPlc.Id, modPlc); |
| | | _plcHubContext.Clients.All.PublicPlcConn(modPlc); |
| | | HubUtil.PublicPlcConn(modPlc); |
| | | } |
| | | } |
| | | Thread.Sleep(1000); |
| | |
| | | listLog.Add(modLog); |
| | | } |
| | | _db.Insertable(listLog).ExecuteCommand(); |
| | | _plcHubContext.Clients.All.PublicAlarm(listPulish); |
| | | HubUtil.PublicAlarm(listPulish); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | { |
| | | if (modPlcUtil == null) |
| | | continue; |
| | | 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 plcIp = modPlcUtil.PlcIP; |
| | | var listDevice = listPlcDevice.Where(s => s.PlcId == modPlcUtil.PlcId ).ToList(); //&& s.DeviceType == DeviceTypeEnum.Show |
| | | 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); |
| | |
| | | { |
| | | var value = Convert.ToInt32(item.Value); |
| | | var height = Math.Round(value / 790000d * 200).ToInt(); |
| | | if (modDevice.BoxHeight != height) |
| | | var modPosition = listPlcPosition.FirstOrDefault(s => s.DeviceId == modDevice.Id && s.Text == "目的工位"); |
| | | string EndLocat = ""; |
| | | if (modPosition != null) |
| | | { |
| | | var (result2, value2) = modPlcUtil.GetPlcDBValue(modPosition.PosType, modDevice.DbNumber, modPosition.PlcPos); |
| | | if (result2.IsSucceed) |
| | | EndLocat = Convert.ToString(value2); |
| | | } |
| | | if (modDevice.BoxHeight != height || modDevice.EndLocat != EndLocat) |
| | | { |
| | | modDevice.EndLocat = EndLocat; |
| | | modDevice.BoxHeight = Math.Round(value / 790000d * 200).ToInt(); |
| | | var modInfo = new PlcPositionInfo() |
| | | { |
| | | Type = modPlc.Type, |
| | | StationNum = modDevice.StationNum, |
| | | BoxHeight = modDevice.BoxHeight |
| | | BoxHeight = modDevice.BoxHeight, |
| | | EndLocat = EndLocat, |
| | | }; |
| | | _plcHubContext.Clients.All.PublicPosition(modInfo); |
| | | HubUtil.PublicPosition(modInfo); |
| | | UpdatePosition(modInfo); |
| | | } |
| | | } |
| | | 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 == 0 || value == 720) |
| | | { |
| | | modDevice.BoHaveItem = value; |
| | | //下发状态 |
| | | var modInfo = new PlcPositionInfo() { Type = modPlc.Type, StationNum = modDevice.StationNum, BoHaveItem = value }; |
| | | _plcHubContext.Clients.All.PublicPosition(modInfo); |
| | | UpdatePosition(modInfo); |
| | | bl = false; |
| | | } |
| | | else |
| | | { |
| | | bl = true; |
| | | } |
| | | |
| | | var modInfo = new PlcPositionInfo() { Type = modPlc.Type, StationNum = modDevice.StationNum.PadLeft(3, '0'), BoHaveItem = bl }; |
| | | HubUtil.PublicPosition(modInfo); |
| | | UpdatePosition(modInfo); |
| | | |
| | | // liudl 注释:和电气工程师确认页面展示交互字后启用。 |
| | | //var value = Convert.ToBoolean(item.Value); |
| | | //if (!value == modDevice.BoHaveItem) |
| | | //{ |
| | | // modDevice.BoHaveItem = value; |
| | | // //下发状态 |
| | | // var modInfo = new PlcPositionInfo() { Type = modPlc.Type, StationNum = modDevice.StationNum.PadLeft(3,'0'), BoHaveItem = value }; |
| | | // HubUtil.PublicPosition(modInfo); |
| | | // UpdatePosition(modInfo); |
| | | //} |
| | | } |
| | | break; |
| | | default: |
| | |
| | | } |
| | | } |
| | | } |
| | | Thread.Sleep(1000); |
| | | Thread.Sleep(300); |
| | | } |
| | | catch (Exception ex) |
| | | { |