PlcConnect.IsSuccess

1114
nodyang@aliyun.com 1 day ago
parent adfcd624fa
commit c419cb2a84

@ -15,6 +15,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Security.Policy; using System.Security.Policy;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Tool; using Tool;
@ -55,6 +57,7 @@ namespace RfidWeb
private void Init() private void Init()
{ {
ShowLed();
_timer = new TimerX(TimeState, null, 2000, 1000); _timer = new TimerX(TimeState, null, 2000, 1000);
_timer.Async=true; _timer.Async=true;
// 如果所有的日志在记录之前需要在控制台显示出来 // 如果所有的日志在记录之前需要在控制台显示出来
@ -81,6 +84,9 @@ namespace RfidWeb
/// <summary>移除过期的缓存项</summary> /// <summary>移除过期的缓存项</summary>
void TimeState(Object state) void TimeState(Object state)
{ {
bool isExit = UserManager.IsExit(); bool isExit = UserManager.IsExit();
this.Invoke(() => this.Invoke(() =>
{ {
@ -110,7 +116,8 @@ namespace RfidWeb
}); });
ThreadPoolX.QueueUserWorkItem(ShowLed); if (!PlcConnect.IsSuccess) return;
ThreadPoolX.QueueUserWorkItem(UpdateLog); ThreadPoolX.QueueUserWorkItem(UpdateLog);
ThreadPoolX.QueueUserWorkItem(ReadBufLog); ThreadPoolX.QueueUserWorkItem(ReadBufLog);
@ -121,12 +128,28 @@ namespace RfidWeb
private void ShowLed() private void ShowLed()
{ {
CacheManager.Act(CacheKeyManager.Home, () =>
var _cancellationTokenSource = new CancellationTokenSource();
var token = _cancellationTokenSource.Token;
Task.Run(async () =>
{
while (!token.IsCancellationRequested)
{ {
// 在这里执行你的轮询逻辑
var result =await PlcConnect.Instance.ReadPlcTypeAsync();
hslLanternSimplePlc.LanternBackground = result.IsSuccess
? Color.LimeGreen : Color.Red;
// 在主线程更新 UI
//Invoke(new Action(() =>
//{
//}));
PlcConnect.IsSuccess = result.IsSuccess;
await Task.Delay(1000, token); // 每隔一秒延时
}
}, token);
bool result = PlcConnect.IsSuccess;
hslLanternSimplePlc.LanternBackground = result ? Color.LimeGreen : Color.Red;
});
} }
private void ReadBufLog() private void ReadBufLog()

@ -104,14 +104,8 @@ namespace Tool
} }
public static bool IsSuccess public static bool IsSuccess;
{
get
{
bool result = PlcConnect.Instance.ReadPlcType().IsSuccess;
return result;
}
}
public static OperateResult WriteTag(string address, UInt32 num) public static OperateResult WriteTag(string address, UInt32 num)

Loading…
Cancel
Save