HDevEngineCode.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using CommonMethods;
  7. using ToolBase;
  8. using ViewROI;
  9. using HalconDotNet;
  10. using System.IO;
  11. using Logger;
  12. namespace HDevEngineTool
  13. {
  14. [Serializable]
  15. public class HDevEngineCode : IToolBase
  16. {
  17. public string uniqueName { get; set; } = Guid.NewGuid().ToString();
  18. public string toolName { get; set; } = string.Empty;
  19. [NonSerialized]
  20. public HDevProgramCall ProgramCall;
  21. [NonSerialized]
  22. public HDevEngine MyEngine = new HDevEngine();
  23. [NonSerialized]
  24. public HDevProgram MyProgram = new HDevProgram();
  25. public string CodeText { get; set; } = string.Empty;
  26. public string CodeFilePath { get; set; } = string.Empty;
  27. public override void DispImage()
  28. {
  29. // throw new NotImplementedException();
  30. }
  31. public override void DispMainWindow(HWindowTool_Smart window)
  32. {
  33. // throw new NotImplementedException();
  34. }
  35. public override void Run(SoftwareRunState softwareRunState)
  36. {
  37. if (File.Exists(CodeFilePath))
  38. {
  39. if(MyProgram != null)
  40. {
  41. if(MyProgram.IsLoaded())
  42. {
  43. LoggerClass.WriteLog("程序已加载,准备运行!");
  44. }
  45. }
  46. else
  47. {
  48. FileInfo myFileInfo = new FileInfo(CodeFilePath);
  49. MyEngine.SetProcedurePath(myFileInfo.DirectoryName);
  50. MyProgram.LoadProgram(CodeFilePath);
  51. ProgramCall = new HDevProgramCall(MyProgram);
  52. MyEngine.SetHDevOperators(new HDevOpMultiWindowImpl(FormHDevEngineTool.Instance.myHwindow.SmartWindow.HalconWindow));
  53. }
  54. ProgramCall.Execute();
  55. // HTuple a = MyEngine.GetGlobalCtrlVarTuple("RunTime");
  56. }
  57. }
  58. }
  59. }