| | |
| | | using LB_SmartVision.Forms.Pages; |
| | | using LB_SmartVision.Forms.Pages.CameraPage; |
| | | using LB_SmartVision.Forms.Pages.CommunicatorPage; |
| | | using LB_SmartVision.Forms.Pages.HistoricalData; |
| | | using LB_SmartVision.Forms.Pages.MESPage; |
| | | using LB_SmartVision.Forms.Pages.MotionControlPage; |
| | | using LB_SmartVision.Forms.Pages.ProcessPage; |
| | |
| | | using LB_VisionProcesses; |
| | | using LB_VisionProcesses.Cameras; |
| | | using LB_VisionProcesses.Cameras.HRCameras; |
| | | using LB_VisionProcesses.Cameras.LBCameras; |
| | | using LB_VisionProcesses.Communicators; |
| | | using LB_VisionProcesses.Communicators.TCom; |
| | | using LB_VisionProcesses.Forms; |
| | |
| | | { |
| | | public partial class VisionForm : Form |
| | | { |
| | | AllProcessesPage AllProcessesPage = new AllProcessesPage(); |
| | | AllProcessesPage AllProcessesPages = new AllProcessesPage(); |
| | | CamerasEditPage CamerasEditPage = new CamerasEditPage(); |
| | | HistoricalDataEditPage HistoricalDataEditPage = new HistoricalDataEditPage(); |
| | | CommunicatorsEditPage CommunicatorsEditPage = new CommunicatorsEditPage(); |
| | | SettingEditPage SettingEditPage = new SettingEditPage(); |
| | | MESEditPage MESEditPage = new MESEditPage(); |
| | |
| | | |
| | | //最开始就清空所有Tab页 |
| | | materialTabControl.TabPages.Clear(); |
| | | materialTabControl.Controls.Add(AllProcessesPage); |
| | | AllProcessesPages.controlsPanel.Dock = DockStyle.Fill; |
| | | materialTabControl.Controls.Add(AllProcessesPages); |
| | | |
| | | HistoricalDataEditPage.LogInfo += LogInfo; |
| | | materialTabControl.Controls.Add(new MyPage(HistoricalDataEditPage)); |
| | | |
| | | CamerasEditPage.LogInfo += LogInfo; |
| | | materialTabControl.Controls.Add(new MyPage(CamerasEditPage)); |
| | |
| | | { |
| | | //materialTabControl.TabPages[i].Font= new Font("Microsoft YaHei UI", 18F, FontStyle.Regular, GraphicsUnit.Point, 0); |
| | | } |
| | | |
| | | materialTabSelector.BaseTabControl = materialTabControl; |
| | | //materialTabSelector.Font = new Font("Microsoft YaHei UI", 18F, FontStyle.Regular, GraphicsUnit.Point, 0); |
| | | } |
| | |
| | | { |
| | | return; |
| | | } |
| | | string strInfo = DateTime.Now.ToString("[yyyy:MM:HH:mm:ss:fff] "); |
| | | string strInfo = DateTime.Now.ToString("[yyyy:MM:dd:HH:mm:ss:fff] "); |
| | | strInfo += strLog; |
| | | if (infoType != LogInfoType.NOSHOW) |
| | | { |
| | |
| | | switch (infoType) |
| | | { |
| | | case LogInfoType.INFO: |
| | | this.rich_Info.SelectionColor = Color.Wheat; |
| | | break; |
| | | { |
| | | this.rich_Info.SelectionColor = Color.Wheat; |
| | | AsyncLogHelper.Info(strLog); |
| | | break; |
| | | } |
| | | case LogInfoType.WARN: |
| | | this.rich_Info.SelectionColor = Color.LightGoldenrodYellow; |
| | | break; |
| | | { |
| | | this.rich_Info.SelectionColor = Color.Yellow; |
| | | AsyncLogHelper.Warn(strLog); |
| | | break; |
| | | } |
| | | case LogInfoType.PASS: |
| | | this.rich_Info.SelectionColor = Color.Green; |
| | | break; |
| | | { |
| | | this.rich_Info.SelectionColor = Color.Green; |
| | | AsyncLogHelper.Info(strLog); |
| | | break; |
| | | } |
| | | case LogInfoType.ERROR: |
| | | this.rich_Info.SelectionColor = Color.Red; |
| | | break; |
| | | { |
| | | this.rich_Info.SelectionColor = Color.Red; |
| | | AsyncLogHelper.Error(strLog); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // 更新 UI 控件,比如显示接收到的消息 |
| | | this.rich_Info.AppendText(strInfo); |
| | | this.rich_Info.AppendText("\r\n"); |
| | |
| | | { |
| | | |
| | | if (this.rich_Info.Lines.Length > 1000) |
| | | { |
| | | this.rich_Info.Clear(); |
| | | |
| | | } |
| | | // 如果已经在 UI 线程上,直接更新 UI |
| | | switch (infoType) |
| | | { |
| | | case LogInfoType.INFO: |
| | | this.rich_Info.SelectionColor = Color.Wheat; |
| | | break; |
| | | { |
| | | this.rich_Info.SelectionColor = Color.Wheat; |
| | | AsyncLogHelper.Info(strLog); |
| | | break; |
| | | } |
| | | case LogInfoType.WARN: |
| | | this.rich_Info.SelectionColor = Color.Yellow; |
| | | break; |
| | | { |
| | | this.rich_Info.SelectionColor = Color.Yellow; |
| | | AsyncLogHelper.Warn(strLog); |
| | | break; |
| | | } |
| | | case LogInfoType.PASS: |
| | | this.rich_Info.SelectionColor = Color.Green; |
| | | break; |
| | | { |
| | | this.rich_Info.SelectionColor = Color.Green; |
| | | AsyncLogHelper.Info(strLog); |
| | | break; |
| | | } |
| | | case LogInfoType.ERROR: |
| | | this.rich_Info.SelectionColor = Color.Red; |
| | | break; |
| | | { |
| | | this.rich_Info.SelectionColor = Color.Red; |
| | | AsyncLogHelper.Error(strLog); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | this.rich_Info.AppendText(strInfo); |
| | | this.rich_Info.AppendText("\r\n"); |
| | | this.rich_Info.SelectionStart = this.rich_Info.Text.Length; |
| | | this.rich_Info.ScrollToCaret(); |
| | | } |
| | | } |
| | | AsyncLogHelper.Info(strLog); |
| | | } |
| | | |
| | | public static bool SaveAllLayout() |
| | |
| | | { |
| | | XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config")); |
| | | string[] paths = { |
| | | @"生产日志\Run_Log", |
| | | @"生产日志\Debug_Log", |
| | | @"生产日志\Error_Log", |
| | | @"生产日志\Run", |
| | | @"生产日志\Debug", |
| | | @"生产日志\Error", |
| | | @"生产日志\Fatal", |
| | | @"生产日志\Warn", |
| | | }; |
| | |
| | | } |
| | | LB_SmartVision.Tool.Tool.ReadStringConfig("User ID", out string User_ID); |
| | | LB_SmartVision.Tool.Tool.ReadStringConfig("Password", out string Password); |
| | | |
| | | GlobalVar.strProductName = DateBaseName; |
| | | |
| | | //加载通讯 |
| | | foreach (BaseCommunicator com in GlobalVar.dicCommunicators.Values) |
| | | { |
| | | com.Disconnect(); |
| | | } |
| | | GlobalVar.dicCommunicators.Clear(); |
| | | if (LoadAllCommunicators(GlobalVar.allCommunicatorsConnectionStringPath)) |
| | | { |
| | | LogInfo("通讯加载成功", LogInfoType.PASS); |
| | | } |
| | | else |
| | | { |
| | | LogInfo("通讯加载失败", LogInfoType.ERROR); |
| | | |
| | | } |
| | | //加载相机 |
| | | foreach (BaseCamera camera in GlobalVar.dicCameras.Values) |
| | | { |
| | | camera.Dispose(); |
| | | } |
| | | GlobalVar.dicCameras.Clear(); |
| | | if (LoadAllCameras(GlobalVar.allCamerasConnectionStringPath)) |
| | | { |
| | | LogInfo("相机加载成功", LogInfoType.PASS); |
| | | } |
| | | else |
| | | { |
| | | LogInfo("相机加载失败", LogInfoType.ERROR); |
| | | |
| | | //必须先加载相机和通讯端口,因为流程加载过程中会用到相机和通讯口 |
| | | |
| | | } |
| | | //加载全局变量 |
| | | IProcess.dicGlobalVars.Clear(); |
| | | if (LoadAllProcessVars(GlobalVar.allProcessVarsPath)) |
| | | { |
| | | LogInfo("全局变量加载成功", LogInfoType.PASS); |
| | | } |
| | | else |
| | | { |
| | | LogInfo("全局变量加载失败", LogInfoType.ERROR); |
| | | } |
| | | |
| | | //加载流程 |
| | | GlobalVar.dicProcesses.Clear(); |
| | | if (LoadAllProcess(GlobalVar.allProcessConnectionStringPath)) |
| | | { |
| | | LogInfo("流程加载成功", LogInfoType.PASS); |
| | | } |
| | | else |
| | | { |
| | | LogInfo("流程加载失败", LogInfoType.ERROR); |
| | | |
| | | } |
| | | //加载触发设置 |
| | | if (LoadAllProcessSetting(GlobalVar.allProcessSettingStringPath)) |
| | | { |
| | | LogInfo("流程设置加载成功", LogInfoType.PASS); |
| | | } |
| | | else |
| | | { |
| | | LogInfo("流程设置加载失败", LogInfoType.ERROR); |
| | | } |
| | | |
| | | //加载流程布局 |
| | | GlobalVar.dicLayout.Clear(); |
| | | if (LoadAllLayout(GlobalVar.allLayoutPath)) |
| | | { |
| | | LogInfo("流程布局加载成功", LogInfoType.PASS); |
| | | } |
| | | else |
| | | { |
| | | LogInfo("流程布局加载失败", LogInfoType.ERROR); |
| | | } |
| | | |
| | | //加载流程表格 |
| | | GlobalVar.dicCsvSetting.Clear(); |
| | | if (LoadAllCsv(GlobalVar.allCsvPath)) |
| | | { |
| | | LogInfo("流程表格加载成功", LogInfoType.PASS); |
| | | } |
| | | else |
| | | { |
| | | LogInfo("流程表格加载失败", LogInfoType.ERROR); |
| | | } |
| | | |
| | | //显示所有产品 |
| | | com_ProductName.Items.Clear(); |
| | | LB_SmartVision.Tool.Tool.ReadStringConfig("产品列表", out string Products); |
| | | List<string> lstProduct = (Products.Split(',')).ToList(); |
| | | foreach (string DatabaseName in lstProduct) |
| | | { |
| | | com_ProductName.Items.Add(DatabaseName); |
| | | } |
| | | com_ProductName.Items.Add("新增"); |
| | | |
| | | com_ProductName.Text = GlobalVar.strProductName; |
| | | this.WindowState = FormWindowState.Maximized; |
| | | } |
| | | |
| | | public void SaveAllSetting() |
| | |
| | | strJson = streamReader.ReadToEnd(); |
| | | streamReader.Close(); |
| | | } |
| | | |
| | | GlobalVar.allCamerasConnectionString = JsonConvert.DeserializeObject<ConcurrentDictionary<string, string>>(strJson); |
| | | if (GlobalVar.allCamerasConnectionString == null) |
| | | { |
| | |
| | | switch (brand) |
| | | { |
| | | case CameraBrand.HRCamera: |
| | | camera = new HRCamera(); |
| | | break; |
| | | { |
| | | camera = new HRCamera(); |
| | | break; |
| | | } |
| | | case CameraBrand.LBCamera: |
| | | //camera = new LBCamera(); |
| | | break; |
| | | { |
| | | //camera = new LBCamera(); |
| | | break; |
| | | } |
| | | default: |
| | | MessageBox.Show($"[{CameraConnectionString.Key}]品牌不支持!", "异常"); |
| | | continue; |
| | | { |
| | | MessageBox.Show($"[{CameraConnectionString.Key}]品牌不支持!", "异常"); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | camera.SN = CameraConnectionString.Key; |
| | | if (!camera.InitDevice(CameraConnectionString.Key, this.Handle)) |
| | | { |
| | |
| | | string CameraBrand = item.Value.Brand.ToString();//"1111" |
| | | |
| | | if (string.IsNullOrEmpty(CameraSN) || string.IsNullOrEmpty(CameraBrand)) |
| | | { |
| | | break; |
| | | |
| | | } |
| | | GlobalVar.allCamerasConnectionString.TryAdd(CameraSN, CameraBrand); |
| | | } |
| | | var settings = new JsonSerializerSettings |
| | |
| | | Communicator.CommunicatorConnections.Add("端口", PORT); |
| | | Communicator.CommunicatorName = CommunicatorName; |
| | | if (!Communicator.Connect()) |
| | | { |
| | | LogInfo($"初始化通讯口[{CommunicatorName}]失败,原因是{Communicator.Msg}", LogInfoType.ERROR); |
| | | } |
| | | else |
| | | { |
| | | LogInfo($"初始化通讯口[{CommunicatorName}]成功", LogInfoType.PASS); |
| | | } |
| | | GlobalVar.dicCommunicators.TryAdd(CommunicatorName, Communicator); |
| | | } |
| | | else |
| | |
| | | string PORT = match.Groups[3].Value; // "1111" |
| | | |
| | | if (string.IsNullOrEmpty(ClassName) || string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(PORT)) |
| | | { |
| | | break; |
| | | } |
| | | |
| | | //利用反射创建实例 |
| | | Type type = IProcess.GetExecutingAssembly().GetType(ClassName); |
| | |
| | | Communicator.CommunicatorConnections.Add("端口", PORT); |
| | | Communicator.CommunicatorName = CommunicatorName; |
| | | if (!Communicator.Connect()) |
| | | { |
| | | LogInfo($"初始化通讯口[{CommunicatorName}]失败,原因是{Communicator.Msg}", LogInfoType.ERROR); |
| | | } |
| | | else |
| | | { |
| | | LogInfo($"初始化通讯口[{CommunicatorName}]成功", LogInfoType.PASS); |
| | | |
| | | } |
| | | GlobalVar.dicCommunicators.TryAdd(CommunicatorName, Communicator); |
| | | } |
| | | else |
| | |
| | | string PORT = item.Value.CommunicatorConnections["端口"].ToString();//"1111" |
| | | |
| | | if (string.IsNullOrEmpty(ClassName) || string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(PORT)) |
| | | { |
| | | break; |
| | | |
| | | } |
| | | string CommunicatorConnectionString = $"({ClassName})[{IP}][{PORT}]"; |
| | | GlobalVar.allCommunicatorsConnectionString.TryAdd(item.Key, CommunicatorConnectionString); |
| | | } |
| | | |
| | | var settings = new JsonSerializerSettings |
| | | { |
| | | Formatting = Formatting.Indented, |
| | |
| | | List<string> lstProcessName = JsonConvert.DeserializeObject<List<string>>(strJson); |
| | | |
| | | if (lstProcessName == null) |
| | | { |
| | | return false; |
| | | |
| | | } |
| | | // 使用方式 |
| | | var sortedKeys = lstProcessName |
| | | .OrderBy(k => k, new NaturalStringComparer()) |
| | | .ToList(); |
| | | GlobalVar.dicProcesses.Clear(); |
| | | foreach (var ProcessName in sortedKeys) |
| | | { |
| | | GlobalVar.dicProcesses.TryAdd(ProcessName |
| | | , new ProcessRunBll(ProcessName, GlobalVar.dicCameras, GlobalVar.dicCommunicators)); |
| | | |
| | | } |
| | | return true; |
| | | } |
| | | catch { return false; } |
| | |
| | | foreach (var process in GlobalVar.dicProcesses.Values) |
| | | { |
| | | if (!process.Save(out string msg)) |
| | | { |
| | | LogInfo($"流程[{process.Name}]保存失败,原因:{msg}", LogInfoType.NOSHOW); |
| | | } |
| | | } |
| | | |
| | | try |
| | |
| | | { |
| | | string title = layout.Title; |
| | | string strImagePath = layout.SaveImageDir; |
| | | if (!AllProcessesPage.dicProcessControls.ContainsKey(title)) |
| | | if (!AllProcessesPages.dicProcessControls.ContainsKey(title)) |
| | | { |
| | | continue; |
| | | } |
| | | RunBll.GetImage(layout, out InputImage, out RecordImage); |
| | | AllProcessesPage.dicProcessControls[title].ShowHoImage(RecordImage); |
| | | AllProcessesPages.dicProcessControls[title].ShowHoImage(RecordImage); |
| | | if (!string.IsNullOrEmpty(layout.SaveImageDir)) |
| | | { |
| | | string fileNameHead = layout.SaveImageHead; |
| | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void VisionForm_FormClosing(object sender, FormClosingEventArgs e) |
| | | { |
| | | SaveAllSetting(); |
| | | if (MessageBox.Show("是否关闭软件?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)// |
| | | { |
| | | e.Cancel = true; |
| | | return; |
| | | } |
| | | //关闭窗体释放资源 |
| | | AsyncLogHelper.Dispose(); |
| | | foreach (BaseCamera camera in GlobalVar.dicCameras.Values) |
| | | { |
| | | camera.Dispose(); |
| | | } |
| | | foreach (BaseCommunicator communicator in GlobalVar.dicCommunicators.Values) |
| | | { |
| | | communicator.Disconnect(); |
| | | } |
| | | FormClosing -= VisionForm_FormClosing; |
| | | } |
| | | } |
| | | } |
| | | |