| | |
| | | public static bool boOffline = false; |
| | | //自刷新 |
| | | public static bool boRefresh = false; |
| | | //演示模式 |
| | | public static bool boDemo = false; |
| | | |
| | | public static List<PlcPositionInfo> listPositionInfo = new List<PlcPositionInfo>(); |
| | | |
| | |
| | | |
| | | private static List<WcsPlc> listPlc = new List<WcsPlc>(); |
| | | private static List<WcsDevice> listPlcDevice = new List<WcsDevice>(); |
| | | private static List<WcsPosition> listPlcStation = new List<WcsPosition>(); |
| | | private static List<WcsPosition> listPlcPosition = new List<WcsPosition>(); |
| | | private static List<WcsAlarmInfo> listAlarmInfo = new List<WcsAlarmInfo>(); |
| | | |
| | | private static List<PLCUtil> listPlcUtil = new List<PLCUtil>(); |
| | |
| | | { |
| | | get { return listPlcUtil; } |
| | | } |
| | | // 交互点集合 |
| | | public static List<WcsDevice> plcDevices |
| | | { |
| | | get { return listPlcDevice; } |
| | | } |
| | | public static List<WcsPosition> plcPositions |
| | | { |
| | | get { return listPlcPosition; } |
| | | } |
| | | public static event EventHandler DeviceValueChangeEvent; |
| | | static PLCTaskAction() |
| | | { |
| | |
| | | boRunningState = _sysConfigService.GetConfigValue<bool>("sys_RunningState").Result; |
| | | boOffline = _sysConfigService.GetConfigValue<bool>("sys_Offline").Result; |
| | | boRefresh = _sysConfigService.GetConfigValue<bool>("sys_Refresh").Result; |
| | | boDemo = _sysConfigService.GetConfigValue<bool>("sys_demo").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(); |
| | | listPlcStation = _db.Queryable<WcsPosition>().ToList(); |
| | | listPlcPosition = _db.Queryable<WcsPosition>().ToList(); |
| | | listAlarmInfo = _db.Queryable<WcsAlarmInfo>().ToList(); |
| | | //等待几秒钟,把已有线程取消掉再连接 |
| | | //Thread.Sleep(5000); |
| | |
| | | dto.Value = value; |
| | | dto.Type = _modplc.Type; |
| | | dto.PLCUtil = modPlcUtil; |
| | | dto.listStation = listPlcStation.Where(s => s.DeviceId == modDevice.Id).ToList(); |
| | | dto.listStation = listPlcPosition.Where(s => s.DeviceId == modDevice.Id).ToList(); |
| | | dto.listDevice = listDevice.Where(s => s.StationNum == modDevice.StationNum && s.Level == DeviceLevelEnum.Station).ToList(); |
| | | //这里触发值变更事件 |
| | | //DeviceValueChangeEvent?.Invoke(dto, EventArgs.Empty); |
| | | DeviceValueChangeEvent?.Invoke(dto, EventArgs.Empty); |
| | | } |
| | | else if (!modPlcUtil.Connected) |
| | | { |
| | |
| | | { |
| | | //报警点位 |
| | | var listAlarm = listAlarmInfo.Where(s => s.PlcIP == modUtil.PlcIP.ToString()).ToList(); |
| | | Console.WriteLine("报警点位数:" + listAlarm.Count); |
| | | //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}个"); |
| | | //Console.WriteLine($"读取点位{listaddress.Count}个"); |
| | | var result = modUtil.GetPlcBatchDBValue(listaddress); |
| | | Console.WriteLine("err" + result.Err); |
| | | //Console.WriteLine("err" + result.Err); |
| | | var listPulish = new List<WcsAlarmInfo>(); |
| | | //测试报警 |
| | | //foreach (var modAlarm in listAlarm) |
| | |
| | | foreach (var item in result.Value) |
| | | { |
| | | var value = Convert.ToBoolean(item.Value); |
| | | Console.WriteLine(item.Key + "+" + value); |
| | | //Console.WriteLine(item.Key + "+" + value); |
| | | var modAlarm = listAlarm.FirstOrDefault(s => s.AlarmCode == item.Key); |
| | | if (value && modAlarm.Status == YesNoEnum.N) |
| | | { |