| | |
| | | using Bro.Common.Model; |
| | | using Bro.Common.Model.Interface; |
| | | using Bro.Common.PubSub; |
| | | using Bro.Common.UI; |
| | | using Bro.Device.AuboRobot; |
| | | using Bro.Device.OmronFins; |
| | | using Bro.Device.SeerAGV; |
| | |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using System; |
| | | using System.Collections.Concurrent; |
| | | using System.Collections.Generic; |
| | | using System.Collections.ObjectModel; |
| | | using System.Collections.Specialized; |
| | | using System.Configuration; |
| | | using System.Diagnostics; |
| | | using System.Drawing; |
| | | using System.Drawing.Imaging; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Runtime.ExceptionServices; |
| | | using System.Threading; |
| | | using System.Threading.Tasks; |
| | | using static Bro.Common.Helper.EnumHelper; |
| | |
| | | if (ProcessState == DeviceState.DSClose) |
| | | return; |
| | | |
| | | List<string> currentTaskIds = Config.AGVBindCollection.Select(u => u.CurrentTaskId).Where(s => !string.IsNullOrWhiteSpace(s)).ToList(); |
| | | TrayTaskCollection.RemoveAll(t => !currentTaskIds.Contains(t.TaskId)); |
| | | |
| | | _bindTaskDoneHandleDict.Values.ToList().ForEach(h => h.WaitOne()); |
| | | |
| | | CloseDevice(PLCDict.Values.ToList()); |
| | | CloseDevice(RobotDict.Values.ToList()); |
| | | CloseDevice(AGVDict.Values.ToList()); |
| | |
| | | return; |
| | | |
| | | InitialProcessMethods(); |
| | | TrayTaskCollection.OnItemChangedWithItemInfo = OnTaskListChanged; |
| | | |
| | | OpenDevices(RobotDict.Values.ToList()); |
| | | OpenDevices(AGVDict.Values.ToList()); |
| | |
| | | |
| | | OpenDevices(PLCDict.Values.ToList()); |
| | | |
| | | //加载AGVUnit状态事件 |
| | | Config.AGVBindCollection.ForEach(b => |
| | | { |
| | | b.OnUnitStateChanged = OnUnitStateChanged; |
| | | |
| | | _bindTaskDoneHandleDict[b.Id] = new AutoResetEvent(true); |
| | | }); |
| | | |
| | | ProcessState = DeviceState.DSOpen; |
| | | |
| | | //QueryRobotIO(); |
| | | |
| | | //Task.Run(() => |
| | | //{ |
| | | // //PLCMonitor(); |
| | | //}); |
| | | |
| | | LogAsync(DateTime.Now, "Process Opened", ""); |
| | | } |
| | |
| | | #region 个别配置的特别处理 |
| | | #endregion |
| | | |
| | | _warningRemains.CollectionChanged -= _warningRemains_CollectionChanged; |
| | | _warningRemains.CollectionChanged += _warningRemains_CollectionChanged; |
| | | WarningRemains.CollectionChanged -= _warningRemains_CollectionChanged; |
| | | WarningRemains.CollectionChanged += _warningRemains_CollectionChanged; |
| | | |
| | | InitialPLCs(); |
| | | InitialAGVs(); |
| | | InitialRobots(); |
| | | InitialCameras(); |
| | | InitialAGVBindUnit(); |
| | | InitialMachineTrayNums(); |
| | | //InitialMachineTrayNums(); |
| | | |
| | | AutoFacRegister(); |
| | | |
| | | LogAsync(DateTime.Now, "Process Initialized", ""); |
| | | } |
| | | |
| | | private void InitialMachineTrayNums() |
| | | { |
| | | machineEmptyTrayDict = Config.PositionCollection.Where(u => u.Description == PathPositionDefinition.UnloadEmptyTray).ToDictionary(p => p.PositionNo, p => 0); |
| | | //private void InitialMachineTrayNums() |
| | | //{ |
| | | // machineEmptyTrayDict = Config.PositionCollection.Where(u => u.Description == PathPositionDefinition.UnloadEmptyTray).ToDictionary(p => p.PositionNo, p => 0); |
| | | |
| | | machineFullTrayDict = Config.PositionCollection.Where(u => u.Description == PathPositionDefinition.LoadFullTray).ToDictionary(p => p.PositionNo, p => 0); |
| | | } |
| | | // machineFullTrayDict = Config.PositionCollection.Where(u => u.Description == PathPositionDefinition.LoadFullTray).ToDictionary(p => p.PositionNo, p => 0); |
| | | //} |
| | | |
| | | private void InitialAGVBindUnit() |
| | | { |
| | |
| | | agv.InitialConfig = c; |
| | | AGVDict[agv.InitialConfig.ID] = agv; |
| | | |
| | | agv.OnMonitorAlarm -= OnMonitorAlarm; |
| | | agv.OnMonitorInvoke -= OnMonitorInvoke; |
| | | |
| | | agv.OnLog = OnDeviceLog; |
| | | agv.OnAGVPositoinChanged = OnAGVPositionChanged; |
| | | agv.OnAGVTaskStatusChanged = OnAGVTaskStatusChanged; |
| | |
| | | |
| | | ProcessConfig pConfig = config as ProcessConfig; |
| | | if (pConfig == null) |
| | | throw new ProcessException("目前只支持ProcessConfig类型的非空内容保存", null); |
| | | throw new ProcessException("目前只支持ProcessConfig类型的非空内容保存"); |
| | | |
| | | string newConfig = JsonConvert.SerializeObject(pConfig, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto }); |
| | | using (StreamWriter writer = new StreamWriter(CONFIG_PATH, false, System.Text.Encoding.UTF8)) |
| | |
| | | if (attr != null) |
| | | { |
| | | _processMethodDict[attr.MethodCode] = m; |
| | | |
| | | #region 初始化HalconTool 根据processMethod的特性来配置 |
| | | //if (attr.DeviceType.EndsWith("Camera")) |
| | | //{ |
| | | // if (StationConfig.ProcessOpConfigDict.Keys.Contains(attr.MethodCode)) |
| | | // { |
| | | // var opConfig = StationConfig.ProcessOpConfigDict[attr.MethodCode] as HalconRelatedCameraOprerationConfigBase; |
| | | |
| | | // if (opConfig != null) |
| | | // { |
| | | // if (!string.IsNullOrWhiteSpace(opConfig.AlgorithemPath)) |
| | | // { |
| | | // string directoryPath = Path.GetDirectoryName(opConfig.AlgorithemPath); |
| | | // string fileName = Path.GetFileNameWithoutExtension(opConfig.AlgorithemPath); |
| | | |
| | | // HDevEngineTool tool = new HDevEngineTool(directoryPath); |
| | | // tool.LoadProcedure(fileName); |
| | | |
| | | // _halconToolDict[attr.MethodCode] = tool; |
| | | // } |
| | | // } |
| | | // } |
| | | //} |
| | | #endregion |
| | | } |
| | | }); |
| | | |
| | | #region 初始化HalconTool 根据配置的接口类型来配置 |
| | | _halconToolDict = new Dictionary<string, HDevEngineTool>(); |
| | | Config.PLCConfigCollection.SelectMany(plcConfig => plcConfig.MonitorSetCollection).Select(ms => ms.OpConfig).ToList().ForEach(c => |
| | | { |
| | | InitialHalconTool(c as IHalconToolPath); |
| | | }); |
| | | |
| | | Config.VisionConfigCollection.ForEach(c => |
| | | { |
| | | InitialHalconTool(c as IHalconToolPath); |
| | | }); |
| | | |
| | | Config.ProcessOpConfigDict.Values.ToList().ForEach(c => |
| | | { |
| | | InitialHalconTool(c as IHalconToolPath); |
| | | }); |
| | | InitialHalconTool(); |
| | | #endregion |
| | | } |
| | | |
| | | private void InitialHalconTool(IHalconToolPath toolPath) |
| | | private void InitialHalconTool() |
| | | { |
| | | //IHalconToolPath toolPath = c as IHalconToolPath; |
| | | if (toolPath != null) |
| | | foreach (HDevEngineTool tool in _halconToolDict.Values) |
| | | { |
| | | toolPath.GetHalconToolPathList().ForEach(path => |
| | | { |
| | | if (!string.IsNullOrWhiteSpace(path) && !_halconToolDict.ContainsKey(path)) |
| | | { |
| | | string directoryPath = Path.GetDirectoryName(path); |
| | | string fileName = Path.GetFileNameWithoutExtension(path); |
| | | |
| | | HDevEngineTool tool = new HDevEngineTool(directoryPath); |
| | | tool.LoadProcedure(fileName); |
| | | |
| | | _halconToolDict[path] = tool; |
| | | } |
| | | }); |
| | | tool?.Dispose(); |
| | | } |
| | | |
| | | _halconToolDict = new Dictionary<string, HDevEngineTool>(); |
| | | |
| | | Config.GetHalconToolPathList().ForEach(path => |
| | | { |
| | | if (!string.IsNullOrWhiteSpace(path) && !_halconToolDict.ContainsKey(path)) |
| | | { |
| | | string directoryPath = Path.GetDirectoryName(path); |
| | | string fileName = Path.GetFileNameWithoutExtension(path); |
| | | |
| | | HDevEngineTool tool = new HDevEngineTool(directoryPath); |
| | | tool.LoadProcedure(fileName); |
| | | |
| | | _halconToolDict[path] = tool; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public List<IDevice> GetDeviceList() |
| | |
| | | res = new ProcessResponse((int)ReturnValue.EXCEPTIONVALUE); |
| | | } |
| | | |
| | | var newEx = new ProcessException("函数" + methodCode + "执行异常", ex); |
| | | var newEx = new ProcessException("函数" + methodCode + "执行异常", ExceptionLevel.Warning, ex); |
| | | } |
| | | else |
| | | { |
| | |
| | | { |
| | | monitorSet.Response.ResultValue = (int)ReturnValue.OKVALUE; |
| | | } |
| | | #endregion |
| | | |
| | | //sw.Stop(); |
| | | //LogAsync(DateTime.Now, methodCode + " 调用耗时: " + sw.ElapsedMilliseconds.ToString() + "ms", ""); |
| | | //TimeRecordCSV(DateTime.Now, methodCode + "调用", (int)sw.ElapsedMilliseconds); |
| | | //sw.Start(); |
| | | |
| | | #region 原有PLC写入结果操作,现转到异步调用后回调去执行 |
| | | //ProcessResponse resValues = res as ProcessResponse; |
| | | |
| | | //if (resValues.ResultValue == (int)PLCReplyValue.IGNORE) |
| | | //{ |
| | | // return; |
| | | //} |
| | | |
| | | //if (monitorSet.ReplyDataAddress != -1 && resValues.DataList.Count > 0) |
| | | //{ |
| | | // PLC_ITEM item = new PLC_ITEM(); |
| | | // item.OP_TYPE = 2; |
| | | // item.ITEM_LENGTH = resValues.DataList.Count; |
| | | // item.ADDRESS = monitorSet.ReplyDataAddress.ToString(); |
| | | // item.ITEM_VALUE = String.Join(",", resValues.DataList); |
| | | // PLC.WriteItem(item, false); |
| | | //} |
| | | |
| | | //if (monitorSet.NoticeAddress != -1) |
| | | //{ |
| | | // //测试模式下始终反馈OK信号 |
| | | // if (StationConfig.IsDemoMode && resValues.ResultValue <= 0) |
| | | // { |
| | | // resValues.ResultValue = (int)ReturnValue.OKVALUE; |
| | | // } |
| | | |
| | | // int repeatTime = 5; |
| | | |
| | | // //LogAsync(DateTime.Now, methodCode + "开始反馈", ""); |
| | | // do |
| | | // { |
| | | // try |
| | | // { |
| | | // PLC.WriteSingleAddress(set.NoticeAddress, resValues.ResultValue, false); |
| | | // repeatTime = 0; |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // repeatTime--; |
| | | |
| | | // if (repeatTime <= 0) |
| | | // { |
| | | // new ProcessException("PLC反馈写入异常", ex); |
| | | // } |
| | | // } |
| | | // } while (repeatTime > 0); |
| | | //} |
| | | #endregion |
| | | } |
| | | |
| | |
| | | else |
| | | { |
| | | //MessageBox.Show("未能获取离线图片!"); |
| | | throw new ProcessException("未能获取离线图片!", null); |
| | | throw new ProcessException("未能获取离线图片!"); |
| | | } |
| | | } |
| | | } |
| | |
| | | #endregion |
| | | |
| | | #region 报警和DownTime |
| | | public ObservableCollection<string> _warningRemains = new ObservableCollection<string>(); |
| | | public ObservableCollection<string> WarningRemains { get; set; } = new ObservableCollection<string>(); |
| | | |
| | | bool warningRemainFlag = false; |
| | | bool WarningRemainFlag |