XP.SCAN模块增加socket通讯,后期重构软件与控制软件在同一电脑进行socket通讯传递进行重构,后期可通过修改IP适配两台电脑的socket通讯重建。
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
namespace XP.Scan.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// CT 重建模式 | CT Reconstruction Mode
|
||||
/// </summary>
|
||||
public enum ReconstructionMode
|
||||
{
|
||||
/// <summary>平面CT重建 | Planar CT reconstruction</summary>
|
||||
Planar = 2001,
|
||||
|
||||
/// <summary>立式CT重建 | Vertical CT reconstruction</summary>
|
||||
Vertical = 2002
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace XP.Scan.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 重建通知服务接口 | Reconstruction notification service interface
|
||||
/// 负责通过 Socket 通知本地重建软件启动重建任务
|
||||
/// </summary>
|
||||
public interface IReconstructionNotifyService
|
||||
{
|
||||
/// <summary>
|
||||
/// 发送重建通知消息
|
||||
/// </summary>
|
||||
/// <param name="configPath">扫描配置文件路径</param>
|
||||
void SendReconstructionNotify(string configPath);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using XP.Common.Logging.Interfaces;
|
||||
using XP.Scan.Models;
|
||||
|
||||
namespace XP.Scan.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 重建通知服务 | Reconstruction notification service
|
||||
/// 通过 TCP Socket 向本地重建软件发送配置路径 + 重建模式码
|
||||
/// </summary>
|
||||
public class ReconstructionNotifyService : IReconstructionNotifyService
|
||||
{
|
||||
private readonly ILoggerService _logger;
|
||||
private readonly string _host;
|
||||
private readonly int _port;
|
||||
private readonly ReconstructionMode _mode;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="loggerService">日志服务</param>
|
||||
/// <param name="host">重建软件 IP 地址(本机默认 127.0.0.1)</param>
|
||||
/// <param name="port">重建软件监听端口</param>
|
||||
/// <param name="mode">CT 重建模式(Planar=2001, Vertical=2002)</param>
|
||||
public ReconstructionNotifyService(
|
||||
ILoggerService loggerService,
|
||||
string host = "127.0.0.1",
|
||||
int port = 11000,
|
||||
ReconstructionMode mode = ReconstructionMode.Planar)
|
||||
{
|
||||
_logger = loggerService.ForModule<ReconstructionNotifyService>();
|
||||
_host = host;
|
||||
_port = port;
|
||||
_mode = mode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送重建通知消息
|
||||
/// 消息格式: configPath + 模式码(2001=平面CT, 2002=立式CT)
|
||||
/// </summary>
|
||||
/// <param name="configPath">扫描配置文件路径</param>
|
||||
public void SendReconstructionNotify(string configPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
var ipAddress = IPAddress.Parse(_host);
|
||||
var remoteEP = new IPEndPoint(ipAddress, _port);
|
||||
|
||||
sender.Connect(remoteEP);
|
||||
|
||||
// 拼接消息: 配置路径 + 重建模式码
|
||||
string message = configPath + ((int)_mode).ToString();
|
||||
byte[] msg = Encoding.UTF8.GetBytes(message);
|
||||
sender.Send(msg);
|
||||
|
||||
_logger.Info($"重建通知已发送 | Reconstruction notify sent: {message}");
|
||||
}
|
||||
catch (SocketException ex)
|
||||
{
|
||||
_logger.Error($"重建通知发送失败(Socket) | Reconstruction notify failed: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error($"重建通知发送异常 | Reconstruction notify error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,6 +175,14 @@
|
||||
<add key="MotionControl:SourceDetectorZLinkage:TriggerThreshold" value="1.0" />
|
||||
<add key="MotionControl:SourceDetectorZLinkage:SpeedPercent" value="100" />
|
||||
|
||||
<!-- 重建通知配置 | Reconstruction Notification Configuration -->
|
||||
<!-- 重建软件 IP(本机安装用 127.0.0.1)| Reconstruction software IP (use 127.0.0.1 for local) -->
|
||||
<add key="Reconstruction:Host" value="127.0.0.1" />
|
||||
<!-- 重建软件监听端口 | Reconstruction software listening port -->
|
||||
<add key="Reconstruction:Port" value="11000" />
|
||||
<!-- 重建模式: Planar(平面CT=2001), Vertical(立式CT=2002) | Mode: Planar=2001, Vertical=2002 -->
|
||||
<add key="Reconstruction:Mode" value="Planar" />
|
||||
|
||||
<!-- 报告输出文件夹路径(绝对路径)| Report output directory (absolute path) -->
|
||||
<add key="Report:OutputDirectory" value="D:\XplorePlane\Report" />
|
||||
<!-- 报告模板文件路径(相对于应用程序目录或绝对路径)| Template file path (relative to app dir or absolute) -->
|
||||
|
||||
Reference in New Issue
Block a user