简单的修改
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
<add key="PLCIP" value="127.0.0.1" />
|
||||
<add key="PLCPort" value="6000" />
|
||||
<add key="PLCScan" value="600" />
|
||||
<add key="PDAScanCode" value="D1000" />
|
||||
<add key="DownloadTaskMaxRetry" value="3" />
|
||||
<add key="NVRIP" value="192.168.0.15" />
|
||||
<add key="NVRPort" value="8000" />
|
||||
<add key="NVRUserName" value="admin" />
|
||||
@@ -22,5 +24,5 @@
|
||||
<add key="JellyfinPollIntervalMs" value="5000" />
|
||||
<add key="JellyfinPollMaxWaitMs" value="600000" />
|
||||
</appSettings>
|
||||
|
||||
|
||||
</configuration>
|
||||
@@ -42,6 +42,11 @@ namespace FATrace.OEMApp
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PLC数据服务
|
||||
/// </summary>
|
||||
private PLCDataService PLCDataService { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主窗体加载:
|
||||
/// - 初始化海康客户端与基础配置(日志目录与保存路径)
|
||||
@@ -61,6 +66,10 @@ namespace FATrace.OEMApp
|
||||
//HkCameraClient.NVR_Port = ConfigHelper.GetValue("NVRPort");
|
||||
//HkCameraClient.NVR_UserName = ConfigHelper.GetValue("NVRUserName");
|
||||
|
||||
PLCDataService = new PLCDataService();
|
||||
PLCDataService.PlcConnectedEventHandler += PLCDataService_PlcConnectedEventHandler;
|
||||
PLCDataService.ScanCodeEventHandler += PLCDataService_ScanCodeEventHandler;
|
||||
|
||||
HkCameraClient.NVRVideoSavePath = ConfigHelper.GetValue("NVRVideoSavePath");
|
||||
//NVR登录
|
||||
NVRLogin();
|
||||
@@ -109,6 +118,26 @@ namespace FATrace.OEMApp
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PLC数据服务:扫描条码
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="Code"></param>
|
||||
private void PLCDataService_ScanCodeEventHandler(object? sender, string Code)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PLC数据服务:PLC连接
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PLCDataService_PlcConnectedEventHandler(object? sender, string e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void NVRLogin()
|
||||
{
|
||||
HkCameraClient.NVR_IP = ConfigHelper.GetValue("NVRIP");
|
||||
|
||||
@@ -62,11 +62,12 @@ namespace FATrace.OEMApp.Services
|
||||
var maxRetry = ConfigHelper.GetIntOrDefault("DownloadTaskMaxRetry", 3);
|
||||
db.Update<DownloadTask>()
|
||||
.Set(a => a.Status, TaskStatus.Pending)
|
||||
.Set(a => a.Error, null)
|
||||
.Set(a => a.Error, "")
|
||||
.Set(a => a.Progress, 0)
|
||||
.Set(a => a.UpdateTime, DateTime.Now)
|
||||
.Where(a => a.Status == TaskStatus.Failed && a.TryCount < maxRetry)
|
||||
.ExecuteAffrows();
|
||||
|
||||
}
|
||||
catch { }
|
||||
_cts = new CancellationTokenSource();
|
||||
@@ -125,9 +126,9 @@ namespace FATrace.OEMApp.Services
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 后台主循环:定期拉取最早的 Pending 任务并顺序处理。
|
||||
/// 后台主循环:定期拉取最早的 Pending 任务并顺序处理
|
||||
/// </summary>
|
||||
/// <param name="token">取消令牌。</param>
|
||||
/// <param name="token">取消令牌</param>
|
||||
private async Task RunAsync(CancellationToken token)
|
||||
{
|
||||
while (!token.IsCancellationRequested)
|
||||
@@ -211,8 +212,9 @@ namespace FATrace.OEMApp.Services
|
||||
.ExecuteAffrowsAsync();
|
||||
|
||||
// 事件 -> TCS
|
||||
// 订阅两个事件:进度与完成。进度事件写回数据库;完成事件用于唤醒等待。
|
||||
// 订阅两个事件:进度与完成。进度事件写回数据库;完成事件用于唤醒等待
|
||||
var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
|
||||
void OnProgress(object? s, short p)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -19,12 +19,17 @@ namespace FATrace.OEMApp.Services
|
||||
|
||||
public PLCDataService()
|
||||
{
|
||||
|
||||
|
||||
PLCLinkInitial();
|
||||
StartPlcScan();
|
||||
|
||||
PadCodeAddress= ConfigHelper.GetStringOrDefault("PDAScanCode", "D1050");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PAD地址
|
||||
/// </summary>
|
||||
private string PadCodeAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 扫码事件
|
||||
/// </summary>
|
||||
@@ -53,11 +58,11 @@ namespace FATrace.OEMApp.Services
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
PlcConnectedEventHandler.Invoke(this, "OK");
|
||||
if (PlcConnectedEventHandler != null) PlcConnectedEventHandler.Invoke(this, "OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
PlcConnectedEventHandler.Invoke(this, "NG");
|
||||
if (PlcConnectedEventHandler != null) PlcConnectedEventHandler.Invoke(this, "NG");
|
||||
}
|
||||
_PlcConnected = value;
|
||||
}
|
||||
@@ -65,6 +70,37 @@ namespace FATrace.OEMApp.Services
|
||||
}
|
||||
|
||||
|
||||
private string _ScanCode = string.Empty;
|
||||
/// <summary>
|
||||
/// 扫描结果
|
||||
/// </summary>
|
||||
public string ScanCode
|
||||
{
|
||||
get { return _ScanCode; }
|
||||
set
|
||||
{
|
||||
if (_ScanCode != value)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
if (ScanCodeEventHandler != null) ScanCodeEventHandler.Invoke(this, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error($"PLC条码数据为空: 数据改变但是数据为空");
|
||||
}
|
||||
|
||||
_ScanCode = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 扫描结果
|
||||
/// </summary>
|
||||
private OperateResult<string> OperateResultPDAScanCode { get; set; }
|
||||
|
||||
// 扫描控制
|
||||
private CancellationTokenSource? _plcScanCts;
|
||||
private Task? _plcScanTask;
|
||||
@@ -175,6 +211,12 @@ namespace FATrace.OEMApp.Services
|
||||
PLCLinkInitial();
|
||||
}
|
||||
|
||||
//内包扫码
|
||||
OperateResultPDAScanCode = KeyencePlcMcNet!.ReadString(PadCodeAddress, 40);
|
||||
if (OperateResultPDAScanCode.IsSuccess)
|
||||
{
|
||||
ScanCode = RevData(OperateResultPDAScanCode.Content).Replace("\r", "").Replace("\n", "").Trim();
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user