diff --git a/DM_Weight/App.config b/DM_Weight/App.config
index 8ee3593..30bfb61 100644
--- a/DM_Weight/App.config
+++ b/DM_Weight/App.config
@@ -3,7 +3,7 @@
-
+
-
+
diff --git a/DM_Weight/Port/SocketHelper.cs b/DM_Weight/Port/SocketHelper.cs
index e3aafda..85534f0 100644
--- a/DM_Weight/Port/SocketHelper.cs
+++ b/DM_Weight/Port/SocketHelper.cs
@@ -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(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(SessionCloseMethod);
+ iConnectFuture.Session.CloseNow();
+ }
+
public void SendMessage(MyBaseMessage baseMessage)
{
- if(!ConnectedStatus)
+ if (!ConnectedStatus)
{
SocketConnect();
}
diff --git a/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs b/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs
index b129051..eb12c11 100644
--- a/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs
+++ b/DM_Weight/ViewModels/CheckOrderNewWindowViewModel.cs
@@ -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;
diff --git a/DM_Weight/ViewModels/LoginWindowViewModel.cs b/DM_Weight/ViewModels/LoginWindowViewModel.cs
index ea57153..fccd615 100644
--- a/DM_Weight/ViewModels/LoginWindowViewModel.cs
+++ b/DM_Weight/ViewModels/LoginWindowViewModel.cs
@@ -377,6 +377,7 @@ _exitCommand ??= new DelegateCommand(Exit);
void Exit()
{
//_chkFunction.HIKLoginOut();
+ _socketHelper.SocketDisConnect();
Process.GetCurrentProcess().Kill();
Environment.Exit(0);
}