提交修改
This commit is contained in:
parent
8ce450a4f5
commit
1402d31de2
|
@ -37,7 +37,7 @@
|
|||
<!-- 按处方还药或者按取药记录还药 1:处方(ReturnDrugWindow2)2:药品(ReturnDrugWindow)-->
|
||||
<add key="returnDrugMode" value="2" />
|
||||
<!-- 自动退出时间,单位秒,为0时不自动退出 -->
|
||||
<add key="autoExit" value="80"/>
|
||||
<add key="autoExit" value="5"/>
|
||||
|
||||
<!-- 无操作退出录像时间,单位秒,为0时不退出录像 -->
|
||||
<add key="stopRecord" value="180"/>
|
||||
|
@ -117,8 +117,8 @@
|
|||
<add key="HIKPassword" value="HKC123456"/>
|
||||
|
||||
<!--交接柜网口地址及端口-->
|
||||
<add key="modbusIp" value="127.0.0.1"/>
|
||||
<add key="modbusPort" value="4002"/>
|
||||
<add key="modbusIp" value="10.1.100.13"/>
|
||||
<add key="modbusPort" value="502"/>
|
||||
|
||||
<!--温湿度串口-->
|
||||
<add key="wsdSerialPort" value="COM1"/>
|
||||
|
|
|
@ -19,15 +19,15 @@ namespace DM_Weight.Finger
|
|||
public class FingerprintUtil
|
||||
{
|
||||
|
||||
private static ILog logger = LogManager.GetLogger(typeof(FingerprintUtil));
|
||||
public static zkemkeeper.CZKEMClass axCZKEM1= new zkemkeeper.CZKEMClass();
|
||||
public static bool bIsConnected = false;
|
||||
private ILog logger = LogManager.GetLogger(typeof(FingerprintUtil));
|
||||
public zkemkeeper.CZKEMClass axCZKEM1= new zkemkeeper.CZKEMClass();
|
||||
public bool bIsConnected = false;
|
||||
|
||||
private static string fingerIp = ConfigurationManager.AppSettings["fingerIp"].ToString();
|
||||
private static int fingerPort = 4370;
|
||||
private static int machineNumber = Convert.ToInt32(ConfigurationManager.AppSettings["machineNumber"].ToString());
|
||||
private static int machineType = Convert.ToInt32(ConfigurationManager.AppSettings["machineType"].ToString());
|
||||
private static IEventAggregator _eventAggregator;
|
||||
private string fingerIp = ConfigurationManager.AppSettings["fingerIp"].ToString();
|
||||
private int fingerPort = 4370;
|
||||
private int machineNumber = Convert.ToInt32(ConfigurationManager.AppSettings["machineNumber"].ToString());
|
||||
private int machineType = Convert.ToInt32(ConfigurationManager.AppSettings["machineType"].ToString());
|
||||
private IEventAggregator _eventAggregator;
|
||||
public FingerprintUtil(IEventAggregator eventAggregator)
|
||||
{
|
||||
_eventAggregator = eventAggregator;
|
||||
|
@ -38,7 +38,7 @@ namespace DM_Weight.Finger
|
|||
//});
|
||||
}
|
||||
|
||||
public static void ConnectionMain()
|
||||
public void ConnectionMain()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -55,9 +55,6 @@ namespace DM_Weight.Finger
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
logger.Info($"连接指纹机2");
|
||||
|
||||
_eventAggregator.GetEvent<FingerprintEvent>().Publish(new FingerprintMsg()
|
||||
{
|
||||
Message = "CONNECT",
|
||||
|
@ -72,10 +69,11 @@ namespace DM_Weight.Finger
|
|||
/// <summary>
|
||||
/// 用于退出登录重连指纹机
|
||||
/// </summary>
|
||||
public static void FingerDisconnect()
|
||||
public void FingerDisconnect()
|
||||
{
|
||||
try
|
||||
{
|
||||
logger.Info("重连指纹机");
|
||||
axCZKEM1.Disconnect();
|
||||
axCZKEM1.OnAttTransactionEx -= new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
|
||||
axCZKEM1.OnEnrollFingerEx -= new zkemkeeper._IZKEMEvents_OnEnrollFingerExEventHandler(axCZKEM1_OnEnrollFingerEx);
|
||||
|
@ -89,7 +87,7 @@ namespace DM_Weight.Finger
|
|||
}
|
||||
|
||||
//If your fingerprint(or your card) passes the verification,this event will be triggered
|
||||
private static void axCZKEM1_OnAttTransactionEx(string sEnrollNumber, int iIsInValid, int iAttState, int iVerifyMethod, int iYear, int iMonth, int iDay, int iHour, int iMinute, int iSecond, int iWorkCode)
|
||||
private void axCZKEM1_OnAttTransactionEx(string sEnrollNumber, int iIsInValid, int iAttState, int iVerifyMethod, int iYear, int iMonth, int iDay, int iHour, int iMinute, int iSecond, int iWorkCode)
|
||||
{
|
||||
FingerprintMsg message = new FingerprintMsg()
|
||||
{
|
||||
|
@ -102,7 +100,7 @@ namespace DM_Weight.Finger
|
|||
}
|
||||
|
||||
//When you are enrolling your finger,this event will be triggered.
|
||||
private static void axCZKEM1_OnEnrollFinger(int iEnrollNumber, int iFingerIndex, int iActionResult, int iTemplateLength)
|
||||
private void axCZKEM1_OnEnrollFinger(int iEnrollNumber, int iFingerIndex, int iActionResult, int iTemplateLength)
|
||||
{
|
||||
FingerprintMsg message = new FingerprintMsg()
|
||||
{
|
||||
|
@ -119,7 +117,7 @@ namespace DM_Weight.Finger
|
|||
_eventAggregator.GetEvent<FingerprintEvent>().Publish(message);
|
||||
}
|
||||
|
||||
private static void axCZKEM1_OnEnrollFingerEx(string iEnrollNumber, int iFingerIndex, int iActionResult, int iTemplateLength)
|
||||
private void axCZKEM1_OnEnrollFingerEx(string iEnrollNumber, int iFingerIndex, int iActionResult, int iTemplateLength)
|
||||
{
|
||||
FingerprintMsg message = new FingerprintMsg()
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Common.Logging;
|
||||
using DM_Weight.Finger;
|
||||
using Mina.Core.Future;
|
||||
using Mina.Filter.Codec;
|
||||
using Mina.Transport.Socket;
|
||||
|
@ -18,8 +19,10 @@ namespace DM_Weight.Port
|
|||
AsyncSocketConnector acceptor = new AsyncSocketConnector();
|
||||
IConnectFuture iConnectFuture;
|
||||
string ip = ConfigurationManager.AppSettings["fingerIp"].ToString();
|
||||
public FingerHelper()
|
||||
FingerprintUtil _fingerprintUtil;
|
||||
public FingerHelper(FingerprintUtil fingerprintUtil)
|
||||
{
|
||||
_fingerprintUtil = fingerprintUtil;
|
||||
acceptor.ExceptionCaught += (o, e) => logger.Error(e.Exception);
|
||||
|
||||
//acceptor.FilterChain.AddLast("logger", new LoggingFilter());
|
||||
|
@ -38,6 +41,7 @@ namespace DM_Weight.Port
|
|||
logger.Info("SessionClosed");
|
||||
Task.Delay(50).Wait();
|
||||
SocketConnect();
|
||||
_fingerprintUtil.FingerDisconnect();
|
||||
};
|
||||
this.SocketConnect();
|
||||
}
|
||||
|
@ -45,7 +49,7 @@ namespace DM_Weight.Port
|
|||
{
|
||||
iConnectFuture = acceptor.Connect(new IPEndPoint(IPAddress.Parse(ip), 4370)).Await();
|
||||
|
||||
Console.WriteLine(iConnectFuture.Connected.ToString());
|
||||
logger.Info($"再次连接结果:{iConnectFuture.Connected.ToString()}");
|
||||
}
|
||||
|
||||
public void SendMessage(MyBaseMessage baseMessage)
|
||||
|
|
|
@ -81,10 +81,10 @@ namespace DM_Weight.Port
|
|||
BoxOperate = false;
|
||||
this.SetModusIpMaster();
|
||||
// return TimeSpan.FromSeconds (1);
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
FingerprintUtil.FingerDisconnect();
|
||||
});
|
||||
//Task.Factory.StartNew(() =>
|
||||
//{
|
||||
// FingerprintUtil.FingerDisconnect();
|
||||
//});
|
||||
}).Execute<bool[]>(() =>
|
||||
{
|
||||
bool[] flags = new bool[18];
|
||||
|
@ -120,10 +120,10 @@ namespace DM_Weight.Port
|
|||
logger.Info($"打开箱子出错,第{retryCount}次重试,异常信息{exception}");
|
||||
Thread.Sleep(50);
|
||||
this.SetModusIpMaster();
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
FingerprintUtil.FingerDisconnect();
|
||||
});
|
||||
//Task.Factory.StartNew(() =>
|
||||
//{
|
||||
// FingerprintUtil.FingerDisconnect();
|
||||
//});
|
||||
//return TimeSpan.FromSeconds (1);
|
||||
})).Execute(() =>
|
||||
{
|
||||
|
@ -173,6 +173,7 @@ namespace DM_Weight.Port
|
|||
private static SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
|
||||
public static void SpeakAsync(string textinfo)
|
||||
{
|
||||
speechSynthesizer.Rate = 2;
|
||||
speechSynthesizer.SpeakAsync(textinfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using DM_Weight.Models;
|
||||
using DM_Weight.Finger;
|
||||
using DM_Weight.Models;
|
||||
using DM_Weight.msg;
|
||||
using DM_Weight.util;
|
||||
using DM_Weight.ViewModels;
|
||||
|
@ -31,9 +32,11 @@ namespace DM_Weight.Port
|
|||
string ip = ConfigurationManager.AppSettings["modbusIp"].ToString();
|
||||
int port =Convert.ToInt32(ConfigurationManager.AppSettings["modbusPort"]);
|
||||
IEventAggregator _eventAggregator;
|
||||
public SocketHelper(IEventAggregator eventAggregator)
|
||||
public DateTime dateTime { get; set; } = DateTime.Now;
|
||||
FingerprintUtil _fingerprintUtil;
|
||||
public SocketHelper(IEventAggregator eventAggregator, FingerprintUtil fingerprintUtil)
|
||||
{
|
||||
_eventAggregator=eventAggregator;
|
||||
_eventAggregator = eventAggregator;
|
||||
acceptor.ExceptionCaught += (o, e) =>
|
||||
{
|
||||
logger.Error($"网口通信超时:{e.Exception}");
|
||||
|
@ -54,17 +57,16 @@ namespace DM_Weight.Port
|
|||
{
|
||||
OpenStatus = (bool)e.Message;
|
||||
logger.Info("MessageReceived>>>>>>>>>>>>>>>>" + OpenStatus);
|
||||
if(OpenStatus)
|
||||
{
|
||||
HomeWindow.idleTimer.Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
HomeWindow.idleTimer.AutoReset = true;
|
||||
HomeWindow.idleTimer.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0") * 1000;
|
||||
HomeWindow.idleTimer.Start();
|
||||
//if(OpenStatus)
|
||||
//{
|
||||
// HomeWindow.idleTimer.Stop();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// HomeWindow.idleTimer.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0") * 1000;
|
||||
// HomeWindow.idleTimer.Start();
|
||||
|
||||
}
|
||||
//}
|
||||
};
|
||||
|
||||
|
||||
|
@ -73,15 +75,44 @@ namespace DM_Weight.Port
|
|||
logger.Info("SessionClosed");
|
||||
//Task.Delay(50).Wait();
|
||||
SocketConnect();
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
_fingerprintUtil.FingerDisconnect();
|
||||
});
|
||||
};
|
||||
this.SocketConnect();
|
||||
_fingerprintUtil = fingerprintUtil;
|
||||
}
|
||||
int i = 0;
|
||||
public void SocketConnect()
|
||||
{
|
||||
|
||||
Thread.Sleep(50);
|
||||
i++;
|
||||
iConnectFuture = acceptor.Connect(new IPEndPoint(IPAddress.Parse(ip), port)).Await();
|
||||
logger.Info($"第{i}次连接结果:{iConnectFuture.Connected.ToString()}");
|
||||
if (!iConnectFuture.Connected)
|
||||
{
|
||||
if (i <= 3)
|
||||
{
|
||||
//没连上会再连两次
|
||||
SocketConnect();
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error($"尝试{i}次连接后均连接不上");
|
||||
AlertMsg alertMsg = new AlertMsg
|
||||
{
|
||||
Message = $"网口连接断开!",
|
||||
Type = MsgType.ERROR
|
||||
};
|
||||
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
|
||||
logger.Info(iConnectFuture.Connected.ToString());
|
||||
}
|
||||
|
||||
public void SendMessage(MyBaseMessage baseMessage)
|
||||
|
|
|
@ -862,6 +862,7 @@ namespace DM_Weight.ViewModels
|
|||
try
|
||||
{
|
||||
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = (short)(DrawerNo) });
|
||||
_socketHelper.dateTime = DateTime.Now;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -871,12 +872,14 @@ namespace DM_Weight.ViewModels
|
|||
Type = MsgType.ERROR,
|
||||
};
|
||||
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
||||
logger.Info($"网口连接异常,正在重试{ex.Message}");
|
||||
return;
|
||||
}
|
||||
_socketHelper.OpenStatus = true;
|
||||
Thread.Sleep(200);
|
||||
int i = 10;
|
||||
new PromiseUtil<int>().taskAsyncLoop(500, 0, async (options, next, stop) =>
|
||||
int i = 40;
|
||||
int iException = 0;
|
||||
new PromiseUtil<int>().taskAsyncLoop(200, 0, async (options, next, stop) =>
|
||||
{
|
||||
|
||||
_socketHelper.IsMultiThread = true;
|
||||
|
@ -896,30 +899,43 @@ namespace DM_Weight.ViewModels
|
|||
if (i == 0)
|
||||
{
|
||||
ModbusHelper.SpeakAsync("请及时关闭药箱");
|
||||
i = 10;
|
||||
i = 40;
|
||||
}
|
||||
next();
|
||||
}
|
||||
else
|
||||
{
|
||||
_socketHelper.OpenStatus = false;
|
||||
_socketHelper.IsMultiThread = false;
|
||||
_socketHelper.dateTime = DateTime.Now;
|
||||
stop();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_socketHelper.OpenStatus = false;
|
||||
_socketHelper.IsMultiThread = false;
|
||||
_socketHelper.dateTime = DateTime.Now;
|
||||
stop();
|
||||
}
|
||||
iException = 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_socketHelper.OpenStatus = false;
|
||||
iException++;
|
||||
if (iException >= 3)
|
||||
{
|
||||
_socketHelper.OpenStatus = false;
|
||||
}
|
||||
// _socketHelper.OpenStatus = false;
|
||||
AlertMsg alertMsg = new AlertMsg
|
||||
{
|
||||
Message = $"网口连接异常,正在重试{ex.Message}",
|
||||
Type = MsgType.ERROR,
|
||||
};
|
||||
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
||||
logger.Info($"网口连接异常,正在重试{ex.Message}");
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -570,48 +570,31 @@ namespace DM_Weight.ViewModels
|
|||
FindDrawerCount();
|
||||
|
||||
int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0");
|
||||
//int stopRecord = Convert.ToInt32(ConfigurationManager.AppSettings["stopRecord"] ?? "0");
|
||||
//if (autoExit > 0)
|
||||
//{
|
||||
// System.Timers.Timer timer = new System.Timers.Timer();
|
||||
// timer.Interval = 100;
|
||||
// timer.Elapsed += (sender, e) =>
|
||||
// {
|
||||
// // 串口无人操作
|
||||
// bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
|
||||
// bool allTrue = Array.TrueForAll(boolArrs, b => b==false);
|
||||
// logger.Info($"进入自动退出定时方法{allTrue}");
|
||||
// //false是关着,true是开着
|
||||
// if (allTrue)
|
||||
// {
|
||||
// //PerformanceCounter pc = new PerformanceCounter("System", "% Idle Time", true);
|
||||
// //float systemIdleTime = pc.NextValue();
|
||||
// //Console.WriteLine($"systemIdleTime:{systemIdleTime}");
|
||||
|
||||
// //// 获取系统空闲时间
|
||||
// //TimeSpan idleTime = SystemInformation.IdleTime;
|
||||
// //// 打印空闲时间
|
||||
// //Console.WriteLine("系统空闲时间: " + idleTime.ToString());
|
||||
// long lTime = CheckComputerFreeState.GetLastInputTime();
|
||||
// logger.Info($"自动退出时间{lTime}");
|
||||
// // 30秒内无人操作鼠标键盘
|
||||
// //if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit)
|
||||
// if (lTime > autoExit)
|
||||
// {
|
||||
// logger.Info($"设备{autoExit}秒内无人操作,用户【{Operator?.Nickname}】自动退出登录");
|
||||
// _chkFunction.HIKStopDVRRecord();
|
||||
// Operator = null;
|
||||
// Reviewer = null;
|
||||
// Application.Current.Dispatcher.Invoke(() =>
|
||||
// {
|
||||
// _regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
||||
// timer.Stop();
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// timer.Start();
|
||||
//}
|
||||
if (autoExit > 0)
|
||||
{
|
||||
System.Timers.Timer timer = new System.Timers.Timer();
|
||||
timer.Interval = autoExit* 1000;
|
||||
timer.Elapsed += (sender, e) =>
|
||||
{
|
||||
// 串口无人操作
|
||||
if (!_socketHelper.OpenStatus)
|
||||
{
|
||||
// 无人操作鼠标键盘
|
||||
if ((DateTime.Now - _socketHelper.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit)
|
||||
{
|
||||
logger.Info($"设备内无人操作,用户【{Operator?.Nickname}】自动退出登录");
|
||||
Operator = null;
|
||||
Reviewer = null;
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
||||
timer.Stop();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
timer.Start();
|
||||
}
|
||||
#region 温度查询定时
|
||||
//int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]);
|
||||
//if (interval > 0)
|
||||
|
@ -624,7 +607,7 @@ namespace DM_Weight.ViewModels
|
|||
// //WDTimer.AutoReset = true;
|
||||
// //WDTimer.Enabled = true;
|
||||
//}
|
||||
Task.Factory.StartNew(async () =>
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
|
@ -639,7 +622,7 @@ namespace DM_Weight.ViewModels
|
|||
AddTime = DateTime.Now
|
||||
}).ExecuteCommand();
|
||||
logger.Info($"保存温湿度信息:{temp.Temp},{temp.Humi}");
|
||||
await Task.Delay(1200000);//20分钟查一次
|
||||
Task.Delay(1200000);//20分钟查一次
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -688,14 +671,14 @@ namespace DM_Weight.ViewModels
|
|||
Reviewer = null;
|
||||
try
|
||||
{
|
||||
if (_socketHelper.IsMultiThread)
|
||||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
||||
});
|
||||
}
|
||||
else
|
||||
//if (_socketHelper.IsMultiThread)
|
||||
//{
|
||||
// Application.Current.Dispatcher.BeginInvoke(() =>
|
||||
// {
|
||||
// _regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
||||
// });
|
||||
//}
|
||||
//else
|
||||
{
|
||||
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace DM_Weight.ViewModels
|
|||
}
|
||||
private HkcChangeShifts listHkcChangeShifts=new HkcChangeShifts();
|
||||
|
||||
//private FingerprintUtil _fingerprintUtil;
|
||||
private FingerprintUtil _fingerprintUtil;
|
||||
|
||||
private PortUtil _portUtil;
|
||||
|
||||
|
@ -114,17 +114,17 @@ namespace DM_Weight.ViewModels
|
|||
// _regionManager = regionManager;
|
||||
// _eventAggregator = eventAggregator;
|
||||
//}
|
||||
public LoginWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil)
|
||||
public LoginWindowViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, PortUtil portUtil,FingerprintUtil fingerprintUtil)
|
||||
{
|
||||
//_fingerprintUtil = fingerprintUtil;
|
||||
_fingerprintUtil = fingerprintUtil;
|
||||
_portUtil = portUtil;
|
||||
_regionManager = regionManager;
|
||||
_eventAggregator = eventAggregator;
|
||||
//FingerMsg = !_fingerprintUtil.bIsConnected;
|
||||
FingerMsg = !FingerprintUtil.bIsConnected;
|
||||
FingerMsg = !_fingerprintUtil.bIsConnected;
|
||||
//FingerMsg = !FingerprintUtil.bIsConnected;
|
||||
_eventAggregator.GetEvent<FingerprintEvent>().Subscribe(LoginEvent);
|
||||
logger.Info($"LoginWindowViewModel;FingerMsg:{FingerprintUtil.bIsConnected}");
|
||||
//_fingerprintUtil.FingerDisconnect();
|
||||
logger.Info($"LoginWindowViewModel;FingerMsg:{_fingerprintUtil.bIsConnected}");
|
||||
_fingerprintUtil.FingerDisconnect();
|
||||
}
|
||||
private DelegateCommand? _loginCommand;
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace DM_Weight.ViewModels
|
|||
}
|
||||
if (_socketHelper.IsMultiThread)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(new Action(() => {
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action(() => {
|
||||
this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
|
||||
SnackbarMessageQueue.Enqueue(msg.Message);
|
||||
}));
|
||||
|
|
|
@ -662,6 +662,7 @@ namespace DM_Weight.ViewModels
|
|||
try
|
||||
{
|
||||
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = (short)(DrawerNo - 1) });
|
||||
_socketHelper.dateTime = DateTime.Now;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -709,8 +710,9 @@ namespace DM_Weight.ViewModels
|
|||
// }
|
||||
//});
|
||||
Thread.Sleep(200);
|
||||
int i = 10;
|
||||
new PromiseUtil<int>().taskAsyncLoop(500, 0, async (options, next, stop) =>
|
||||
int i = 40;
|
||||
int iException = 0;
|
||||
new PromiseUtil<int>().taskAsyncLoop(200, 0, async (options, next, stop) =>
|
||||
{
|
||||
_socketHelper.IsMultiThread = true;
|
||||
try
|
||||
|
@ -730,30 +732,41 @@ namespace DM_Weight.ViewModels
|
|||
if (i == 0)
|
||||
{
|
||||
ModbusHelper.SpeakAsync("请及时关闭药箱");
|
||||
i = 10;
|
||||
i = 40;
|
||||
}
|
||||
next();
|
||||
}
|
||||
else
|
||||
{
|
||||
_socketHelper.IsMultiThread = false;
|
||||
_socketHelper.OpenStatus = false;
|
||||
_socketHelper.dateTime=DateTime.Now;
|
||||
stop();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_socketHelper.IsMultiThread = false;
|
||||
_socketHelper.OpenStatus = false;
|
||||
_socketHelper.dateTime = DateTime.Now;
|
||||
stop();
|
||||
}
|
||||
iException = 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_socketHelper.OpenStatus = false;
|
||||
iException++;
|
||||
if (iException >= 3)
|
||||
{
|
||||
_socketHelper.OpenStatus = false;
|
||||
}
|
||||
AlertMsg alertMsg = new AlertMsg
|
||||
{
|
||||
Message = $"网口连接异常,正在重试{ex.Message}",
|
||||
Type = MsgType.ERROR,
|
||||
};
|
||||
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
||||
next();
|
||||
}
|
||||
});
|
||||
//StateTimer.Start();
|
||||
|
|
|
@ -32,54 +32,56 @@ namespace DM_Weight.Views
|
|||
{
|
||||
private readonly ILog logger = LogManager.GetLogger(typeof(HomeWindow));
|
||||
int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0");
|
||||
public static System.Timers.Timer idleTimer;//= new System.Timers.Timer(60000);
|
||||
//public static System.Timers.Timer idleTimer;//= new System.Timers.Timer(60000);
|
||||
IEventAggregator _eventAggregator;
|
||||
SocketHelper _socketHelper;
|
||||
public HomeWindow(IEventAggregator eventAggregator, SocketHelper socketHelper)
|
||||
{
|
||||
InitializeComponent();
|
||||
if (autoExit > 0)
|
||||
{
|
||||
idleTimer = new System.Timers.Timer(autoExit * 1000);
|
||||
idleTimer.Elapsed += OnTimerElapsed;
|
||||
this.MouseDown += OnUserActivity;
|
||||
this.MouseMove += OnUserActivity;
|
||||
this.KeyDown += OnUserActivity;
|
||||
idleTimer.Start();
|
||||
_eventAggregator = eventAggregator;
|
||||
}
|
||||
//if (autoExit > 0)
|
||||
//{
|
||||
// idleTimer = new System.Timers.Timer(autoExit * 1000);
|
||||
// idleTimer.Elapsed += OnTimerElapsed;
|
||||
// idleTimer.AutoReset = true;
|
||||
// idleTimer.Enabled= true;
|
||||
// this.MouseDown += OnUserActivity;
|
||||
// this.MouseMove += OnUserActivity;
|
||||
// this.KeyDown += OnUserActivity;
|
||||
// idleTimer.Start();
|
||||
// _eventAggregator = eventAggregator;
|
||||
//}
|
||||
_socketHelper = socketHelper;
|
||||
}
|
||||
private void OnUserActivity(object sender, EventArgs e)
|
||||
{
|
||||
idleTimer.Stop();
|
||||
|
||||
idleTimer.AutoReset = true;
|
||||
idleTimer.Interval =autoExit * 1000;
|
||||
idleTimer.Start();
|
||||
}
|
||||
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
// 串口无人操作
|
||||
//bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
|
||||
//bool allTrue = Array.TrueForAll(boolArrs, b => b == false);
|
||||
logger.Info($"进入自动退出定时方法{ModbusHelper.BoxOperate}");
|
||||
//if (ModbusHelper.BoxOperate)
|
||||
if (!_socketHelper.OpenStatus)
|
||||
{
|
||||
if (idleTimer.Enabled)
|
||||
{
|
||||
idleTimer.Stop();
|
||||
//无人操作,自动退出
|
||||
_eventAggregator.GetEvent<LoginOutEvent>().Publish();
|
||||
}
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// idleTimer.Interval = autoExit * 1000;
|
||||
// idleTimer.AutoReset = true;
|
||||
//}
|
||||
}
|
||||
//private void OnUserActivity(object sender, EventArgs e)
|
||||
//{
|
||||
// idleTimer.Stop();
|
||||
// idleTimer.Interval =autoExit * 1000;
|
||||
// idleTimer.Start();
|
||||
//}
|
||||
//private void OnTimerElapsed(object sender, ElapsedEventArgs e)
|
||||
//{
|
||||
// idleTimer.Stop();
|
||||
// // 串口无人操作
|
||||
// //bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
|
||||
// //bool allTrue = Array.TrueForAll(boolArrs, b => b == false);
|
||||
// logger.Info($"进入自动退出定时方法{ModbusHelper.BoxOperate}");
|
||||
// //if (ModbusHelper.BoxOperate)
|
||||
// if (!_socketHelper.OpenStatus)
|
||||
// {
|
||||
// if (idleTimer.Enabled)
|
||||
// {
|
||||
// idleTimer.Stop();
|
||||
// //无人操作,自动退出
|
||||
// _eventAggregator.GetEvent<LoginOutEvent>().Publish();
|
||||
// }
|
||||
// }
|
||||
// idleTimer.Start();
|
||||
// //else
|
||||
// //{
|
||||
// // idleTimer.Interval = autoExit * 1000;
|
||||
// // idleTimer.AutoReset = true;
|
||||
// //}
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue