Commit d266bc7a by liulongfei

添加启动算法

parent e455f67a
......@@ -347,7 +347,7 @@ namespace VIZ.ElectricRabbit.Module
// 更新差值
double center = left + (right - left) / 2d;
this.DifferenceValue = center - this.SettingViewModel.SafeAxis;
this.AlgorithmCenterX = msg.center_x;
this.AlgorithmCenterX = msg.center_x - this.SettingViewModel.SafeAxis;
this.AlgorithmDifferenceValue = this.SettingViewModel.SafeAxis - msg.center_x;
// 更新FPS
......
using log4net;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using VIZ.ElectricRabbit.Domain;
using VIZ.ElectricRabbit.Storage;
using VIZ.Framework.Common;
using VIZ.Framework.Core;
using VIZ.Framework.Domain;
using VIZ.Framework.Module;
namespace VIZ.ElectricRabbit.Module
{
/// <summary>
/// 应用程序启动 -- 初始化算法
/// </summary>
public class AppSetup_InitAlgorithm : AppSetupBase
{
/// <summary>
/// 日志
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(AppSetup_InitAlgorithm));
/// <summary>
/// 算法路径
/// </summary>
private readonly static string CLIENT_ALGORITHM_PATH = ApplicationDomainEx.IniStorage.GetValue<ClientConfig, string>(p => p.CLIENT_ALGORITHM_PATH);
/// <summary>
/// 描述
/// </summary>
public override string Detail { get; } = "应用程序启动 -- 初始化算法";
/// <summary>
/// 算法进程
/// </summary>
private Process AlgorithmProcess;
/// <summary>
/// 执行启动
/// </summary>
/// <param name="context">应用程序启动上下文</param>
/// <returns>是否成功执行</returns>
public override bool Setup(AppSetupContext context)
{
// 如果未配置,那么不处理
if (string.IsNullOrWhiteSpace(CLIENT_ALGORITHM_PATH))
return true;
this.AlgorithmProcess = this.CreateSetupProcess(CLIENT_ALGORITHM_PATH);
this.AlgorithmProcess?.Start();
return true;
}
/// <summary>
/// 执行关闭
/// </summary>
/// <param name="context">应用程序启动上下文</param>
public override void Shutdown(AppSetupContext context)
{
this.AlgorithmProcess?.Kill();
}
/// <summary>
/// 创建启动进程
/// </summary>
/// <param name="path">进程路径</param>
/// <returns>进程对象</returns>
private Process CreateSetupProcess(string path)
{
StringBuilder sb = new StringBuilder();
string fileName = null;
string arguments = null;
if (System.IO.Path.GetExtension(path).ToLower() == ".py")
{
// 如果是 .py 文件那么 采用 CMD 启动python程序
fileName = "python";
arguments = $"\"{path}\"";
}
else
{
// 否则采用直接启动的方式启动
fileName = path;
arguments = $"{sb}";
}
Process proc = new Process();
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.FileName = fileName;
proc.StartInfo.Arguments = arguments;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
return proc;
}
}
}
\ No newline at end of file
......@@ -129,6 +129,7 @@
<Compile Include="SettingView\View\SettingView.xaml.cs">
<DependentUpon>SettingView.xaml</DependentUpon>
</Compile>
<Compile Include="Setup\Provider\AppSetup_InitAlgorithm.cs" />
<Compile Include="Setup\Provider\AppSetup_SerialPort.cs" />
<Compile Include="Setup\Provider\AppSetup_InitUDP.cs" />
<Compile Include="Setup\Provider\AppSetup_InitOpenCV.cs" />
......
......@@ -78,5 +78,11 @@ namespace VIZ.ElectricRabbit.Storage
/// </summary>
[Ini(Section = "Client", DefaultValue = "COM1", Type = typeof(string))]
public string CLIENT_OUTPUT_SERIAL_PORT { get; set; }
/// <summary>
/// 算法路径
/// </summary>
[Ini(Section = "Client", DefaultValue = "", Type = typeof(string))]
public string CLIENT_ALGORITHM_PATH { get; set; }
}
}
......@@ -25,6 +25,8 @@ namespace VIZ.ElectricRabbit
AppSetup.AppendSetup(new AppSetup_InitUDP());
// 初始化串口
AppSetup.AppendSetup(new AppSetup_SerialPort());
// 初始化算法
AppSetup.AppendSetup(new AppSetup_InitAlgorithm());
// 执行启动流程
AppSetupContext context = AppSetup.Setup();
......
......@@ -35,4 +35,6 @@ CLIENT_RIGHT_COLOR=#00000000
; 箭头安全颜色(格式:#AARRGGBB)
CLIENT_SAFE_COLOR=#00000000
; 输出串口号
CLIENT_OUTPUT_SERIAL_PORT=COM3
\ No newline at end of file
CLIENT_OUTPUT_SERIAL_PORT=COM3
; 算法路径
CLIENT_ALGORITHM_PATH=
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment