退出软件断开与板子连接

This commit is contained in:
maqiao 2025-01-18 09:39:33 +08:00
parent 5d04921387
commit 386a663026
4 changed files with 40 additions and 20 deletions

View File

@ -3,7 +3,7 @@
<connectionStrings>
<!-- 数据库连接字符串 -->
<!--<add name="database" connectionString="server=127.0.0.1;database=wpf_dm_program;userid=root;password=qq1223" />-->
<add name="database" connectionString="server=127.0.0.1;port=3306;database=xiangtan_mazuike_xx;userid=root;password=root" />
<add name="database" connectionString="server=127.0.0.1;port=3306;database=xiangtan_mazuike;userid=root;password=root" />
</connectionStrings>
<!--<runtime>
--><!--配置之后Appdomain.CurrentDomain.UnhandledException 事件的 IsTerminating 就变成了 false 啦!也就是说,程序并不会因为这次的异常而崩溃退出。--><!--
@ -37,7 +37,7 @@
<!-- 按处方还药或者按取药记录还药 1:处方ReturnDrugWindow22药品ReturnDrugWindow-->
<add key="returnDrugMode" value="2" />
<!-- 自动退出时间单位秒为0时不自动退出 -->
<add key="autoExit" value="5"/>
<add key="autoExit" value="0"/>
<!-- 无操作退出录像时间单位秒为0时不退出录像 -->
<add key="stopRecord" value="180"/>

View File

@ -4,6 +4,7 @@ using DM_Weight.util;
using DM_Weight.ViewModels;
using log4net;
using Mina.Core.Future;
using Mina.Core.Session;
using Mina.Filter.Codec;
using Mina.Filter.Logging;
using Mina.Transport.Socket;
@ -25,18 +26,18 @@ namespace DM_Weight.Port
private readonly ILog logger = LogManager.GetLogger(typeof(SocketHelper));
AsyncSocketConnector acceptor = new AsyncSocketConnector();
IConnectFuture iConnectFuture;
public bool OpenStatus=false;
public bool OpenStatus = false;
public bool ConnectedStatus = false;
//多线程退出标识
public bool IsMultiThread = false;
string ip = ConfigurationManager.AppSettings["modbusIp"].ToString();
int port =Convert.ToInt32(ConfigurationManager.AppSettings["modbusPort"]);
int port = Convert.ToInt32(ConfigurationManager.AppSettings["modbusPort"]);
IEventAggregator _eventAggregator;
FingerprintUtil _fingerprintUtil;
public DateTime dateTime { get; set; } = DateTime.Now;
public SocketHelper(IEventAggregator eventAggregator, FingerprintUtil fingerprintUtil)
{
_fingerprintUtil= fingerprintUtil;
_fingerprintUtil = fingerprintUtil;
_eventAggregator = eventAggregator;
acceptor.ExceptionCaught += (o, e) =>
{
@ -59,18 +60,22 @@ namespace DM_Weight.Port
OpenStatus = (bool)e.Message;
logger.Info("MessageReceived>>>>>>>>>>>>>>>>" + OpenStatus);
};
acceptor.SessionClosed += (o, e) =>
{
logger.Info("SessionClosed");
//Task.Delay(50).Wait();
SocketConnect();
Task.Factory.StartNew(() =>
{
_fingerprintUtil.FingerDisconnect();
});
};
acceptor.SessionClosed += new EventHandler<IoSessionEventArgs>(SessionCloseMethod);
//acceptor.SessionClosed += (o, e) =>
//{
// logger.Info($"SessionClosed;ExitFlag:{ExitFlag}");
// //Task.Delay(50).Wait();
// if (!ExitFlag)
// {
// SocketConnect();
// Task.Factory.StartNew(() =>
// {
// _fingerprintUtil.FingerDisconnect();
// });
// }
//};
this.SocketConnect();
}
int i = 0;
@ -84,14 +89,13 @@ namespace DM_Weight.Port
{
if (i <= 3)
{
Thread.Sleep(1950);
//没连上会再连两次
SocketConnect();
}
else
{
logger.Error($"尝试{i}次连接后均连接不上");
//AlertMsg alertMsg = new AlertMsg
//{
// Message = $"网口连接断开!",
@ -107,9 +111,24 @@ namespace DM_Weight.Port
ConnectedStatus = iConnectFuture.Connected;
}
private void SessionCloseMethod(System.Object o, IoSessionEventArgs e)
{
logger.Info($"SessionClosed");
SocketConnect();
Task.Factory.StartNew(() =>
{
_fingerprintUtil.FingerDisconnect();
});
}
public void SocketDisConnect()
{
acceptor.SessionClosed -=new EventHandler<IoSessionEventArgs>(SessionCloseMethod);
iConnectFuture.Session.CloseNow();
}
public void SendMessage(MyBaseMessage baseMessage)
{
if(!ConnectedStatus)
if (!ConnectedStatus)
{
SocketConnect();
}

View File

@ -503,7 +503,7 @@ namespace DM_Weight.ViewModels
&& cs.Quantity >= oi._OrderDetail.Quantity).First();
if (cs == null)
{
empChannelStock += $"{oi.OrderNo},{oi._OrderDetail.DrugId},{oi._OrderDetail.SetManuNo},{oi._OrderDetail.SetEffDate};";
empChannelStock += $"{oi.OrderNo},{oi._OrderDetail.DrugId},{oi._OrderDetail.SetManuNo};";
continue;
}
cs.Quantity = cs.Quantity - oi._OrderDetail.Quantity;

View File

@ -377,6 +377,7 @@ _exitCommand ??= new DelegateCommand(Exit);
void Exit()
{
//_chkFunction.HIKLoginOut();
_socketHelper.SocketDisConnect();
Process.GetCurrentProcess().Kill();
Environment.Exit(0);
}