开药箱修改关后才能再次打开,去掉定时
This commit is contained in:
parent
90d67f92f6
commit
a82c9f1cd1
|
@ -20,7 +20,7 @@ namespace DM_Weight.Finger
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly ILog logger = LogManager.GetLogger(typeof(FingerprintUtil));
|
private readonly ILog logger = LogManager.GetLogger(typeof(FingerprintUtil));
|
||||||
public zkemkeeper.CZKEMClass axCZKEM1; //= new zkemkeeper.CZKEMClass();
|
public zkemkeeper.CZKEMClass axCZKEM1= new zkemkeeper.CZKEMClass();
|
||||||
public bool bIsConnected = false;
|
public bool bIsConnected = false;
|
||||||
|
|
||||||
private string fingerIp = ConfigurationManager.AppSettings["fingerIp"].ToString();
|
private string fingerIp = ConfigurationManager.AppSettings["fingerIp"].ToString();
|
||||||
|
@ -42,12 +42,12 @@ namespace DM_Weight.Finger
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
axCZKEM1 = new CZKEMClass();
|
//axCZKEM1 = new CZKEMClass();
|
||||||
bIsConnected = axCZKEM1.Connect_Net(fingerIp, fingerPort);
|
bIsConnected = axCZKEM1.Connect_Net(fingerIp, fingerPort);
|
||||||
logger.Info($"连接指纹机,IP:{fingerIp},端口:{fingerPort},机器号:{machineNumber},连接结果:{bIsConnected}");
|
logger.Info($"连接指纹机,IP:{fingerIp},端口:{fingerPort},机器号:{machineNumber},连接结果:{bIsConnected}");
|
||||||
if (bIsConnected)
|
if (bIsConnected)
|
||||||
{
|
{
|
||||||
if (axCZKEM1.RegEvent(machineNumber, 65535))
|
if (axCZKEM1.RegEvent(machineNumber, 9))
|
||||||
{
|
{
|
||||||
this.axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
|
this.axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
|
||||||
//this.axCZKEM1.OnEnrollFinger += new zkemkeeper._IZKEMEvents_OnEnrollFingerEventHandler(axCZKEM1_OnEnrollFinger);
|
//this.axCZKEM1.OnEnrollFinger += new zkemkeeper._IZKEMEvents_OnEnrollFingerEventHandler(axCZKEM1_OnEnrollFinger);
|
||||||
|
@ -67,6 +67,24 @@ namespace DM_Weight.Finger
|
||||||
logger.Info($"连接指纹机异常{ex.Message.ToString()}");
|
logger.Info($"连接指纹机异常{ex.Message.ToString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 用于退出登录重连指纹机
|
||||||
|
/// </summary>
|
||||||
|
public void FingerDisconnect()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
axCZKEM1.Disconnect();
|
||||||
|
this.axCZKEM1.OnAttTransactionEx -= new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
|
||||||
|
this.axCZKEM1.OnEnrollFingerEx -= new zkemkeeper._IZKEMEvents_OnEnrollFingerExEventHandler(axCZKEM1_OnEnrollFingerEx);
|
||||||
|
ConnectionMain();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.Info($"指纹机Disconnect异常{ex.Message.ToString()}");
|
||||||
|
ConnectionMain();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//If your fingerprint(or your card) passes the verification,this event will be triggered
|
//If your fingerprint(or your card) passes the verification,this event will be triggered
|
||||||
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)
|
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)
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DM_Weight.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 记录系统中网口通信中用到的ip与端口号
|
||||||
|
/// </summary>
|
||||||
|
public class IpAndPort
|
||||||
|
{
|
||||||
|
public string Ip { get; set; }
|
||||||
|
public int Port { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
using Polly;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Net;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DM_Weight.Models;
|
||||||
|
using DM_Weight.ViewModels;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
|
namespace DM_Weight.Port
|
||||||
|
{
|
||||||
|
public class KeepAliveSocket
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 生成带有心跳检测的socket
|
||||||
|
/// </summary>
|
||||||
|
public class KeepALiveSocket
|
||||||
|
{
|
||||||
|
|
||||||
|
private static ILog socketLogger = LogManager.GetLogger(typeof(CheckOrderNewWindowViewModel));
|
||||||
|
public static Socket MakeKeepALiveSocket(string ip, int port)
|
||||||
|
{
|
||||||
|
uint dummy = 0;
|
||||||
|
byte[] inOptionValues = new byte[Marshal.SizeOf(dummy) * 3];
|
||||||
|
BitConverter.GetBytes((uint)1).CopyTo(inOptionValues, 0);//启用Keep-Alive
|
||||||
|
BitConverter.GetBytes((uint)10000).CopyTo(inOptionValues, Marshal.SizeOf(dummy));//在这个时间间隔内没有数据交互,则发送探测包
|
||||||
|
BitConverter.GetBytes((uint)10000).CopyTo(inOptionValues, Marshal.SizeOf(dummy) * 2);//发探测包时间间隔
|
||||||
|
IPEndPoint iep = new IPEndPoint(IPAddress.Parse(ip), port);
|
||||||
|
Socket _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
_socket = Policy.Handle<Exception>()
|
||||||
|
.Retry(3, (exception, retryCount) => {
|
||||||
|
socketLogger.Info($"建立Socket,第{retryCount}次重试", exception);
|
||||||
|
// return TimeSpan.FromSeconds (1);
|
||||||
|
})
|
||||||
|
.Execute<Socket>(() => {
|
||||||
|
_socket.IOControl(IOControlCode.KeepAliveValues, inOptionValues, null);
|
||||||
|
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
|
||||||
|
_socket.Connect(iep);
|
||||||
|
return _socket;
|
||||||
|
});
|
||||||
|
return _socket;
|
||||||
|
}
|
||||||
|
public static Socket MakeKeepALiveSocket(IpAndPort ipAndPort)
|
||||||
|
{
|
||||||
|
uint dummy = 0;
|
||||||
|
byte[] inOptionValues = new byte[Marshal.SizeOf(dummy) * 3];
|
||||||
|
BitConverter.GetBytes((uint)1).CopyTo(inOptionValues, 0);//启用Keep-Alive
|
||||||
|
BitConverter.GetBytes((uint)10000).CopyTo(inOptionValues, Marshal.SizeOf(dummy));//在这个时间间隔内没有数据交互,则发送探测包
|
||||||
|
BitConverter.GetBytes((uint)10000).CopyTo(inOptionValues, Marshal.SizeOf(dummy) * 2);//发探测包时间间隔
|
||||||
|
IPEndPoint iep = new IPEndPoint(IPAddress.Parse(ipAndPort.Ip), ipAndPort.Port);
|
||||||
|
Socket _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
_socket = Policy.Handle<Exception>()
|
||||||
|
.Retry(3, (exception, retryCount) => {
|
||||||
|
socketLogger.Info($"建立Socket,第{retryCount}次重试", exception);
|
||||||
|
// return TimeSpan.FromSeconds (1);
|
||||||
|
})
|
||||||
|
.Execute<Socket>(() => {
|
||||||
|
_socket.IOControl(IOControlCode.KeepAliveValues, inOptionValues, null);
|
||||||
|
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
|
||||||
|
_socket.Connect(iep);
|
||||||
|
return _socket;
|
||||||
|
});
|
||||||
|
return _socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
using DM_Weight.ViewModels;
|
using DM_Weight.msg;
|
||||||
|
using DM_Weight.ViewModels;
|
||||||
using log4net;
|
using log4net;
|
||||||
using log4net.Repository.Hierarchy;
|
using log4net.Repository.Hierarchy;
|
||||||
using Modbus.Device;
|
using Modbus.Device;
|
||||||
using Polly;
|
using Polly;
|
||||||
|
using Prism.Events;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
|
@ -11,23 +13,28 @@ using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Speech.Synthesis;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using static DM_Weight.Port.KeepAliveSocket;
|
||||||
|
|
||||||
namespace DM_Weight.Port
|
namespace DM_Weight.Port
|
||||||
{
|
{
|
||||||
public class ModbusHelper
|
public class ModbusHelper
|
||||||
{
|
{
|
||||||
|
private static ModbusHelper instance;
|
||||||
private ModbusIpMaster master;
|
private ModbusIpMaster master;
|
||||||
private Socket socket;
|
private Socket socket;
|
||||||
private TcpClient client;
|
private TcpClient client;
|
||||||
private static ModbusHelper instance;
|
|
||||||
//private static readonly object objLock = new object();
|
|
||||||
private readonly ILog logger = LogManager.GetLogger(typeof(CheckOrderNewWindowViewModel));
|
private readonly ILog logger = LogManager.GetLogger(typeof(CheckOrderNewWindowViewModel));
|
||||||
|
string ip = ConfigurationManager.AppSettings["modbusIp"].ToString();
|
||||||
|
int port = Convert.ToInt32(ConfigurationManager.AppSettings["modbusPort"]);
|
||||||
|
public static bool BoxOperate { get; set; }
|
||||||
private ModbusHelper()
|
private ModbusHelper()
|
||||||
{
|
{
|
||||||
socket = MakeKeepALiveSocket();
|
logger.Info("ModbusHelper");
|
||||||
|
socket = KeepALiveSocket.MakeKeepALiveSocket(ip, port);
|
||||||
client = new TcpClient();
|
client = new TcpClient();
|
||||||
client.Client = socket;
|
client.Client = socket;
|
||||||
master = ModbusIpMaster.CreateIp(client);
|
master = ModbusIpMaster.CreateIp(client);
|
||||||
|
@ -35,14 +42,6 @@ namespace DM_Weight.Port
|
||||||
}
|
}
|
||||||
public static ModbusHelper GetInstance()
|
public static ModbusHelper GetInstance()
|
||||||
{
|
{
|
||||||
//if (instance == null)
|
|
||||||
//{
|
|
||||||
// lock (objLock)
|
|
||||||
// {
|
|
||||||
// if (instance == null)
|
|
||||||
// instance = new ModbusHelper();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
{
|
{
|
||||||
instance = new ModbusHelper();
|
instance = new ModbusHelper();
|
||||||
|
@ -51,52 +50,79 @@ namespace DM_Weight.Port
|
||||||
}
|
}
|
||||||
private void SetModusIpMaster()
|
private void SetModusIpMaster()
|
||||||
{
|
{
|
||||||
Debug.WriteLine("SetModusIpMaster");
|
logger.Info("SetModusIpMaster");
|
||||||
socket = MakeKeepALiveSocket();
|
socket = KeepALiveSocket.MakeKeepALiveSocket(ip, port); ;
|
||||||
client = new TcpClient();
|
client = new TcpClient();
|
||||||
client.Client = socket;
|
client.Client = socket;
|
||||||
master = ModbusIpMaster.CreateIp(client);
|
master = ModbusIpMaster.CreateIp(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool[] GetAllBoxState()
|
public bool[] GetAllBoxState()
|
||||||
{
|
{
|
||||||
if (ConfigurationManager.AppSettings["test"] != null && ConfigurationManager.AppSettings["test"].ToString() == "Y")
|
//bool[] bools = { true };
|
||||||
{
|
//if (BoxOperate)
|
||||||
return new bool[] { false,false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
|
//{
|
||||||
}
|
//if (ConfigurationManager.AppSettings["test"] != null && ConfigurationManager.AppSettings["test"].ToString() == "Y")
|
||||||
bool[] bools = Policy.Handle<Exception>()
|
//{
|
||||||
.Retry(3, (exception, retryCount) =>
|
// return new bool[] { false,false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
|
||||||
{
|
//}
|
||||||
this.Dispose();
|
bool[] bools = Policy.Handle<Exception>()
|
||||||
//Debug.WriteLine($"获取所有箱子门状态出错,第{retryCount}次重试", exception);
|
.Retry(3, (exception, retryCount) =>
|
||||||
logger.Info($"获取所有箱子门状态出错,第{retryCount}次重试, 异常信息{exception}");
|
|
||||||
Thread.Sleep(50);
|
|
||||||
this.SetModusIpMaster();
|
|
||||||
// return TimeSpan.FromSeconds (1);
|
|
||||||
}).Execute<bool[]>(() =>
|
|
||||||
{
|
|
||||||
bool[] flags = new bool[18];
|
|
||||||
var result = master.ReadInputRegisters(1, 0x0033, 2);
|
|
||||||
var r1 = Convert.ToString(((int)result[0] >> 14) | ((int)result[1] << 2), 2).PadLeft(18, '0');
|
|
||||||
var r2 = r1.ToCharArray();
|
|
||||||
Debug.WriteLine("r2=>" + string.Join(", ", r2));
|
|
||||||
for (int i = 0; i < 18; i++)
|
|
||||||
{
|
{
|
||||||
flags[i] = r2[17 - i] == '1' ? true : false;
|
this.Dispose();
|
||||||
}
|
//Debug.WriteLine($"获取所有箱子门状态出错,第{retryCount}次重试", exception);
|
||||||
logger.Info($"获取所有箱子门状态返回:{string.Join(',',flags)}");
|
logger.Info($"获取所有箱子门状态出错,第{retryCount}次重试, 异常信息{exception}");
|
||||||
Thread.Sleep(50);
|
Thread.Sleep(50);
|
||||||
return flags;
|
this.SetModusIpMaster();
|
||||||
});
|
BoxOperate = false;
|
||||||
|
// return TimeSpan.FromSeconds (1);
|
||||||
|
}).Execute<bool[]>(() =>
|
||||||
|
{
|
||||||
|
bool[] flags = new bool[18];
|
||||||
|
if(master==null)
|
||||||
|
{
|
||||||
|
this.SetModusIpMaster();
|
||||||
|
}
|
||||||
|
var result = master.ReadInputRegisters(1, 0x0033, 2);
|
||||||
|
var r1 = Convert.ToString(((int)result[0] >> 14) | ((int)result[1] << 2), 2).PadLeft(18, '0');
|
||||||
|
var r2 = r1.ToCharArray();
|
||||||
|
logger.Info("r2=>" + string.Join(", ", r2));
|
||||||
|
//var r2=new char[18] { '0','0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
|
||||||
|
for (int i = 0; i < 18; i++)
|
||||||
|
{
|
||||||
|
flags[i] = r2[17 - i] == '1' ? true : false;
|
||||||
|
}
|
||||||
|
logger.Info($"获取所有箱子门状态返回:{string.Join(',', flags)};");
|
||||||
|
//bool allFalse = Array.TrueForAll(flags, b => b == false);
|
||||||
|
//if (!allFalse)
|
||||||
|
//{
|
||||||
|
// Task.Delay(500);
|
||||||
|
// Task.Factory.StartNew(async () =>
|
||||||
|
// {
|
||||||
|
// SpeakAsync("药箱已打开,请及时关闭");
|
||||||
|
// await Task.Delay(15000);
|
||||||
|
// });
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// BoxOperate = false;
|
||||||
|
//}
|
||||||
|
|
||||||
|
return flags;
|
||||||
|
});
|
||||||
|
//}
|
||||||
return bools;
|
return bools;
|
||||||
}
|
}
|
||||||
public bool OpenBoxDoor(int boxNum)
|
public bool OpenBoxDoor(int boxNum)
|
||||||
{
|
{
|
||||||
if (ConfigurationManager.AppSettings["test"]!=null&& ConfigurationManager.AppSettings["test"].ToString()=="Y")
|
BoxOperate = true;
|
||||||
{
|
//if (ConfigurationManager.AppSettings["test"]!=null&& ConfigurationManager.AppSettings["test"].ToString()=="Y")
|
||||||
return true;
|
//{
|
||||||
}
|
// return true;
|
||||||
bool bFlag=false;
|
//}
|
||||||
|
bool bFlag = false;
|
||||||
|
Thread.Sleep(50);
|
||||||
Policy.Handle<Exception>().Retry(3, ((exception, retryCount) =>
|
Policy.Handle<Exception>().Retry(3, ((exception, retryCount) =>
|
||||||
{
|
{
|
||||||
this.Dispose();
|
this.Dispose();
|
||||||
|
@ -110,6 +136,7 @@ namespace DM_Weight.Port
|
||||||
logger.Info($"正在打开{boxNum}号药箱");
|
logger.Info($"正在打开{boxNum}号药箱");
|
||||||
master.WriteSingleRegister(1, (ushort)boxNum, 14);
|
master.WriteSingleRegister(1, (ushort)boxNum, 14);
|
||||||
logger.Info($"开门指令已发送{(ushort)boxNum}");
|
logger.Info($"开门指令已发送{(ushort)boxNum}");
|
||||||
|
SpeakAsync("药箱已打开,请及时关闭");
|
||||||
//Console.WriteLine($"开门指令已发送{(ushort)boxNum}");
|
//Console.WriteLine($"开门指令已发送{(ushort)boxNum}");
|
||||||
bFlag = true;
|
bFlag = true;
|
||||||
});
|
});
|
||||||
|
@ -122,32 +149,10 @@ namespace DM_Weight.Port
|
||||||
client.Close();
|
client.Close();
|
||||||
master.Dispose();
|
master.Dispose();
|
||||||
}
|
}
|
||||||
public static Socket MakeKeepALiveSocket()
|
private static SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
|
||||||
|
public static void SpeakAsync(string textinfo)
|
||||||
{
|
{
|
||||||
uint dummy = 0;
|
speechSynthesizer.SpeakAsync(textinfo);
|
||||||
byte[] inOptionValues = new byte[Marshal.SizeOf(dummy) * 3];
|
|
||||||
BitConverter.GetBytes((uint)1).CopyTo(inOptionValues, 0);//启用Keep-Alive
|
|
||||||
BitConverter.GetBytes((uint)10000).CopyTo(inOptionValues, Marshal.SizeOf(dummy));//在这个时间间隔内没有数据交互,则发送探测包
|
|
||||||
BitConverter.GetBytes((uint)10000).CopyTo(inOptionValues, Marshal.SizeOf(dummy) * 2);//发探测包时间间隔
|
|
||||||
//IPEndPoint iep = new IPEndPoint(IPAddress.Parse("192.168.1.13"), 502);
|
|
||||||
string modbusIp = ConfigurationManager.AppSettings["modbusIp"].ToString();
|
|
||||||
int modbusPort =Convert.ToInt32(ConfigurationManager.AppSettings["modbusPort"]);
|
|
||||||
IPEndPoint iep = new IPEndPoint(IPAddress.Parse(modbusIp), modbusPort);
|
|
||||||
Socket _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
|
||||||
_socket = Policy.Handle<Exception>()
|
|
||||||
.Retry(3, (exception, retryCount) =>
|
|
||||||
{
|
|
||||||
Console.WriteLine($"建立Socket,第{retryCount}次重试", exception);
|
|
||||||
// return TimeSpan.FromSeconds (1);
|
|
||||||
})
|
|
||||||
.Execute<Socket>(() =>
|
|
||||||
{
|
|
||||||
_socket.IOControl(IOControlCode.KeepAliveValues, inOptionValues, null);
|
|
||||||
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
|
|
||||||
_socket.Connect(iep);
|
|
||||||
return _socket;
|
|
||||||
});
|
|
||||||
return _socket;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -454,72 +454,75 @@ namespace DM_Weight.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<ChannelList> chlList = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5").ToList();//.Select(cl => cl.BelongUser).First();
|
else
|
||||||
if (chlList != null && chlList.Count > 0)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < chlList.Count; i++)
|
List<ChannelList> chlList = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5").ToList();//.Select(cl => cl.BelongUser).First();
|
||||||
|
if (chlList != null && chlList.Count > 0)
|
||||||
{
|
{
|
||||||
ChannelList chl = chlList[i];
|
for (int i = 0; i < chlList.Count; i++)
|
||||||
if (Convert.ToDateTime(chl.EffDate).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
|
|
||||||
{
|
{
|
||||||
switch (chl.DrawerNo)
|
ChannelList chl = chlList[i];
|
||||||
|
if (Convert.ToDateTime(chl.EffDate).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
|
||||||
{
|
{
|
||||||
case 1:
|
switch (chl.DrawerNo)
|
||||||
Button1Color = Brushes.Yellow;
|
{
|
||||||
break;
|
case 1:
|
||||||
case 2:
|
Button1Color = Brushes.Yellow;
|
||||||
Button2Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 2:
|
||||||
case 3:
|
Button2Color = Brushes.Yellow;
|
||||||
Button3Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 3:
|
||||||
case 4:
|
Button3Color = Brushes.Yellow;
|
||||||
Button4Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 4:
|
||||||
case 5:
|
Button4Color = Brushes.Yellow;
|
||||||
Button5Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 5:
|
||||||
case 6:
|
Button5Color = Brushes.Yellow;
|
||||||
Button6Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 6:
|
||||||
case 7:
|
Button6Color = Brushes.Yellow;
|
||||||
Button7Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 7:
|
||||||
case 8:
|
Button7Color = Brushes.Yellow;
|
||||||
Button8Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 8:
|
||||||
case 9:
|
Button8Color = Brushes.Yellow;
|
||||||
Button9Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 9:
|
||||||
case 10:
|
Button9Color = Brushes.Yellow;
|
||||||
Button10Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 10:
|
||||||
case 11:
|
Button10Color = Brushes.Yellow;
|
||||||
Button11Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 11:
|
||||||
case 12:
|
Button11Color = Brushes.Yellow;
|
||||||
Button12Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 12:
|
||||||
case 13:
|
Button12Color = Brushes.Yellow;
|
||||||
Button13Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 13:
|
||||||
case 14:
|
Button13Color = Brushes.Yellow;
|
||||||
Button14Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 14:
|
||||||
case 15:
|
Button14Color = Brushes.Yellow;
|
||||||
Button15Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 15:
|
||||||
case 16:
|
Button15Color = Brushes.Yellow;
|
||||||
Button16Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 16:
|
||||||
case 17:
|
Button16Color = Brushes.Yellow;
|
||||||
Button17Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 17:
|
||||||
case 18:
|
Button17Color = Brushes.Yellow;
|
||||||
Button18Color = Brushes.Yellow;
|
break;
|
||||||
break;
|
case 18:
|
||||||
default:
|
Button18Color = Brushes.Yellow;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -821,6 +824,18 @@ namespace DM_Weight.ViewModels
|
||||||
|
|
||||||
public void OpenBoxAction(string strDrawerNo)
|
public void OpenBoxAction(string strDrawerNo)
|
||||||
{
|
{
|
||||||
|
//bool[] bools = ModbusHelper.GetInstance().GetAllBoxState();
|
||||||
|
//bool allFalse = Array.TrueForAll(bools, b => b == false);
|
||||||
|
//if (!allFalse)
|
||||||
|
//{
|
||||||
|
// Task.Factory.StartNew(() => { ModbusHelper.SpeakAsync("请关闭药箱后再打开"); });
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
if (ModbusHelper.BoxOperate)
|
||||||
|
{
|
||||||
|
Task.Factory.StartNew(() => { ModbusHelper.SpeakAsync("请关闭药箱后再打开"); });
|
||||||
|
return;
|
||||||
|
}
|
||||||
DrawerNo = Convert.ToInt32(strDrawerNo);
|
DrawerNo = Convert.ToInt32(strDrawerNo);
|
||||||
MachineRecord machineRecord = new MachineRecord();
|
MachineRecord machineRecord = new MachineRecord();
|
||||||
machineRecord.MachineId = "DM5";
|
machineRecord.MachineId = "DM5";
|
||||||
|
@ -840,6 +855,25 @@ namespace DM_Weight.ViewModels
|
||||||
//记录开药箱日志
|
//记录开药箱日志
|
||||||
SqlSugarHelper.Db.Insertable(machineRecord).ExecuteCommand();
|
SqlSugarHelper.Db.Insertable(machineRecord).ExecuteCommand();
|
||||||
ModbusHelper.GetInstance().OpenBoxDoor(DrawerNo);
|
ModbusHelper.GetInstance().OpenBoxDoor(DrawerNo);
|
||||||
|
Task.Factory.StartNew(async () =>
|
||||||
|
{
|
||||||
|
bool loop = true;
|
||||||
|
while (loop)
|
||||||
|
{
|
||||||
|
await Task.Delay(9000);
|
||||||
|
bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
|
||||||
|
bool state = Array.TrueForAll(boolsl, b => b == false);
|
||||||
|
if (state)
|
||||||
|
{
|
||||||
|
loop = false;
|
||||||
|
ModbusHelper.BoxOperate = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ModbusHelper.SpeakAsync("药箱已打开,请及时关闭");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,20 +37,20 @@ namespace DM_Weight.ViewModels
|
||||||
private UserList? _userList2;
|
private UserList? _userList2;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
///// <summary>
|
||||||
/// 冰箱温度
|
///// 冰箱温度
|
||||||
/// </summary>
|
///// </summary>
|
||||||
private string _wd = "恒温冷藏抽屉当前温度2.8(非真实数据)";
|
//private string _wd = "恒温冷藏抽屉当前温度2.8(非真实数据)";
|
||||||
public string WD { get => _wd; set => SetProperty(ref _wd, value); }
|
//public string WD { get => _wd; set => SetProperty(ref _wd, value); }
|
||||||
System.Timers.Timer WDTimer;
|
//System.Timers.Timer WDTimer;
|
||||||
|
|
||||||
System.Timers.Timer WSDTimer;
|
//System.Timers.Timer WSDTimer;
|
||||||
|
|
||||||
/// <summary>
|
///// <summary>
|
||||||
/// 是否有冰箱抽屉
|
///// 是否有冰箱抽屉
|
||||||
/// </summary>
|
///// </summary>
|
||||||
private string hasFridge = ConfigurationManager.AppSettings["hasFridge"].ToString().Equals("1") ? "Visible" : "Collapsed";
|
//private string hasFridge = ConfigurationManager.AppSettings["hasFridge"].ToString().Equals("1") ? "Visible" : "Collapsed";
|
||||||
public string HasFridge { get => hasFridge; set => SetProperty(ref hasFridge, value); }
|
//public string HasFridge { get => hasFridge; set => SetProperty(ref hasFridge, value); }
|
||||||
|
|
||||||
private int loginMode = Convert.ToInt32(ConfigurationManager.AppSettings["loginMode"]?.ToString() ?? "1");
|
private int loginMode = Convert.ToInt32(ConfigurationManager.AppSettings["loginMode"]?.ToString() ?? "1");
|
||||||
public bool MultiLogin
|
public bool MultiLogin
|
||||||
|
@ -148,7 +148,7 @@ namespace DM_Weight.ViewModels
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
SetProperty(ref _selectedChildMenu, value);
|
SetProperty(ref _selectedChildMenu, value);
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,10 +287,10 @@ namespace DM_Weight.ViewModels
|
||||||
//}
|
//}
|
||||||
if (SelectedMenu != null && SelectedMenu.PremissionName == "退出")
|
if (SelectedMenu != null && SelectedMenu.PremissionName == "退出")
|
||||||
{
|
{
|
||||||
bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
|
//bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
|
||||||
bool allTrue = Array.TrueForAll(boolArrs, b => b);
|
//bool allTrue = Array.TrueForAll(boolArrs, b => b);
|
||||||
//false是关着,true是开着
|
//false是关着,true是开着
|
||||||
if (!allTrue)
|
if (!ModbusHelper.BoxOperate)
|
||||||
{
|
{
|
||||||
logger.Info($"用户【{Operator?.Nickname}】退出登录");
|
logger.Info($"用户【{Operator?.Nickname}】退出登录");
|
||||||
Operator = null;
|
Operator = null;
|
||||||
|
@ -300,12 +300,8 @@ namespace DM_Weight.ViewModels
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//还有药箱开着不能退出
|
//还有药箱开着不能退出
|
||||||
AlertMsg alertMsg = new AlertMsg
|
_portUtil.SpeakAsync("请关闭药箱后再退出");
|
||||||
{
|
SelectedMenu = _premissionDmList[0];
|
||||||
Message = "请关闭药箱后再退出系统",
|
|
||||||
Type = MsgType.ERROR
|
|
||||||
};
|
|
||||||
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -346,7 +342,8 @@ namespace DM_Weight.ViewModels
|
||||||
private PortUtil _portUtil;
|
private PortUtil _portUtil;
|
||||||
//private CHKFunction _chkFunction;
|
//private CHKFunction _chkFunction;
|
||||||
IEventAggregator _eventAggregator;
|
IEventAggregator _eventAggregator;
|
||||||
public HomeWindowViewModel(IRegionManager iRegionManager, PortUtil portUtil, IDialogService dialogService, IUnityContainer container, IEventAggregator eventAggregator)
|
//private ModbusHelper _modbusHelper;
|
||||||
|
public HomeWindowViewModel(IRegionManager iRegionManager, PortUtil portUtil, IUnityContainer container, IDialogService dialogService, IEventAggregator eventAggregator)
|
||||||
{
|
{
|
||||||
_portUtil = portUtil;
|
_portUtil = portUtil;
|
||||||
_regionManager = iRegionManager;
|
_regionManager = iRegionManager;
|
||||||
|
@ -354,6 +351,7 @@ namespace DM_Weight.ViewModels
|
||||||
_container = container;
|
_container = container;
|
||||||
this._eventAggregator = eventAggregator;
|
this._eventAggregator = eventAggregator;
|
||||||
//_chkFunction = cHKFunction;
|
//_chkFunction = cHKFunction;
|
||||||
|
//_modbusHelper = modbusHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DelegateCommand<string> OpenFingerDialog
|
public DelegateCommand<string> OpenFingerDialog
|
||||||
|
@ -546,10 +544,10 @@ namespace DM_Weight.ViewModels
|
||||||
{
|
{
|
||||||
Operator = null;
|
Operator = null;
|
||||||
Reviewer = null;
|
Reviewer = null;
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
//Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
//{
|
||||||
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
||||||
});
|
//});
|
||||||
AlertMsg alertMsg = new AlertMsg
|
AlertMsg alertMsg = new AlertMsg
|
||||||
{
|
{
|
||||||
Message = $"用户{UserList.Nickname}或还未设置权限,请联系管理员",
|
Message = $"用户{UserList.Nickname}或还未设置权限,请联系管理员",
|
||||||
|
@ -611,17 +609,40 @@ namespace DM_Weight.ViewModels
|
||||||
// timer.Start();
|
// timer.Start();
|
||||||
//}
|
//}
|
||||||
#region 温度查询定时
|
#region 温度查询定时
|
||||||
int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]);
|
//int interval = Convert.ToInt32(ConfigurationManager.AppSettings["Interval"]);
|
||||||
if (interval > 0)
|
//if (interval > 0)
|
||||||
{
|
//{
|
||||||
WSDTimer = new System.Timers.Timer();
|
// WSDTimer = new System.Timers.Timer();
|
||||||
|
|
||||||
WSDTimer.Elapsed += new System.Timers.ElapsedEventHandler(GetWSD);
|
// WSDTimer.Elapsed += new System.Timers.ElapsedEventHandler(GetWSD);
|
||||||
WSDTimer.Interval = interval;
|
// WSDTimer.Interval = interval;
|
||||||
WSDTimer.Start();
|
// WSDTimer.Start();
|
||||||
//WDTimer.AutoReset = true;
|
// //WDTimer.AutoReset = true;
|
||||||
//WDTimer.Enabled = true;
|
// //WDTimer.Enabled = true;
|
||||||
}
|
//}
|
||||||
|
Task.Factory.StartNew(async () =>
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
TemperatureHumidityInfo temp = _portUtil.GetWSD();
|
||||||
|
if (temp != null)
|
||||||
|
{
|
||||||
|
SqlSugarHelper.Db.Insertable(new TemperatureHumidityInfo()
|
||||||
|
{
|
||||||
|
GroupNo = temp.GroupNo,
|
||||||
|
Temp = temp.Temp,
|
||||||
|
Humi = temp.Humi,
|
||||||
|
AddTime = DateTime.Now
|
||||||
|
}).ExecuteCommand();
|
||||||
|
logger.Info($"保存温湿度信息:{temp.Temp},{temp.Humi}");
|
||||||
|
await Task.Delay(1200000);//20分钟查一次
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.Info("温湿度信息返回空");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
#endregion
|
#endregion
|
||||||
//if (stopRecord > 0)
|
//if (stopRecord > 0)
|
||||||
//{
|
//{
|
||||||
|
@ -663,7 +684,7 @@ namespace DM_Weight.ViewModels
|
||||||
Reviewer = null;
|
Reviewer = null;
|
||||||
//Application.Current.Dispatcher.Invoke(() =>
|
//Application.Current.Dispatcher.Invoke(() =>
|
||||||
//{
|
//{
|
||||||
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
|
||||||
//});
|
//});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,9 +120,10 @@ namespace DM_Weight.ViewModels
|
||||||
_portUtil = portUtil;
|
_portUtil = portUtil;
|
||||||
_regionManager = regionManager;
|
_regionManager = regionManager;
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
FingerMsg = !_fingerprintUtil.bIsConnected;
|
FingerMsg = _fingerprintUtil.bIsConnected;
|
||||||
_eventAggregator.GetEvent<FingerprintEvent>().Subscribe(LoginEvent);
|
_eventAggregator.GetEvent<FingerprintEvent>().Subscribe(LoginEvent);
|
||||||
logger.Info("LoginWindowViewModel");
|
logger.Info($"LoginWindowViewModel;FingerMsg:{FingerMsg}");
|
||||||
|
_fingerprintUtil.FingerDisconnect();
|
||||||
}
|
}
|
||||||
private DelegateCommand? _loginCommand;
|
private DelegateCommand? _loginCommand;
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ namespace DM_Weight.ViewModels
|
||||||
public class OpenBoxNewWindowViewModel : BindableBase, INavigationAware, IRegionMemberLifetime
|
public class OpenBoxNewWindowViewModel : BindableBase, INavigationAware, IRegionMemberLifetime
|
||||||
{
|
{
|
||||||
//定时查询药箱状态
|
//定时查询药箱状态
|
||||||
System.Timers.Timer StateTimer = new System.Timers.Timer(15000);
|
//System.Timers.Timer StateTimer = new System.Timers.Timer(5000);
|
||||||
|
|
||||||
|
|
||||||
private readonly ILog logger = LogManager.GetLogger(typeof(CheckOrderNewWindowViewModel));
|
private readonly ILog logger = LogManager.GetLogger(typeof(CheckOrderNewWindowViewModel));
|
||||||
private int _drawerType = -1;
|
private int _drawerType = -1;
|
||||||
|
@ -54,8 +54,8 @@ namespace DM_Weight.ViewModels
|
||||||
|
|
||||||
|
|
||||||
//开公共药箱按钮的显示状态
|
//开公共药箱按钮的显示状态
|
||||||
private bool _publicEnable = true;
|
//private bool _publicEnable = true;
|
||||||
public bool PublicEnable { get => _publicEnable; set => SetProperty(ref _publicEnable, value); }
|
//public bool PublicEnable { get => _publicEnable; set => SetProperty(ref _publicEnable, value); }
|
||||||
|
|
||||||
//公共药箱按钮显示内容
|
//公共药箱按钮显示内容
|
||||||
private string _publicContent;
|
private string _publicContent;
|
||||||
|
@ -110,11 +110,10 @@ namespace DM_Weight.ViewModels
|
||||||
public static ChannelList iList = new ChannelList();
|
public static ChannelList iList = new ChannelList();
|
||||||
//第几个抽屉号
|
//第几个抽屉号
|
||||||
//public static int iNumber = 1;
|
//public static int iNumber = 1;
|
||||||
private PortUtil _portUtil;
|
//private PortUtil _portUtil;
|
||||||
IEventAggregator _eventAggregator;
|
IEventAggregator _eventAggregator;
|
||||||
public OpenBoxNewWindowViewModel(PortUtil portUtil, IEventAggregator eventAggregator)
|
public OpenBoxNewWindowViewModel(IEventAggregator eventAggregator)
|
||||||
{
|
{
|
||||||
_portUtil = portUtil;
|
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
}
|
}
|
||||||
#region 抽屉按钮
|
#region 抽屉按钮
|
||||||
|
@ -581,32 +580,32 @@ namespace DM_Weight.ViewModels
|
||||||
//int listSelfState = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5")
|
//int listSelfState = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5")
|
||||||
// .WhereIf(cl => cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).Select(cl => cl.DrawerState).First();
|
// .WhereIf(cl => cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).Select(cl => cl.DrawerState).First();
|
||||||
|
|
||||||
int listDrawerState = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.DrawerType == this.DrawerType)
|
//int listDrawerState = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.DrawerType == this.DrawerType)
|
||||||
.WhereIF(this.DrawerType == 0, cl => cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).Select(cl => cl.DrawerState).First();
|
// .WhereIF(this.DrawerType == 0, cl => cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).Select(cl => cl.DrawerState).First();
|
||||||
if (DrawerType == 1) //公共药箱
|
//if (DrawerType == 1) //公共药箱
|
||||||
{
|
//{
|
||||||
if (listDrawerState == 0)
|
// if (listDrawerState == 0)
|
||||||
{
|
// {
|
||||||
SelfContent = "还公共药箱";
|
// SelfContent = "还公共药箱";
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
SelfContent = "取公共药箱";
|
// SelfContent = "取公共药箱";
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
//}
|
||||||
else
|
//else
|
||||||
{
|
//{
|
||||||
if (listDrawerState == 0)
|
// if (listDrawerState == 0)
|
||||||
{
|
// {
|
||||||
SelfContent = "还名下药箱";
|
// SelfContent = "还名下药箱";
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
SelfContent = "取名下药箱";
|
// SelfContent = "取名下药箱";
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
public DelegateCommand<string> OpenBoxDelegate
|
public DelegateCommand<string> OpenBoxDelegate
|
||||||
|
@ -619,6 +618,14 @@ namespace DM_Weight.ViewModels
|
||||||
}
|
}
|
||||||
private void SearchBox()
|
private void SearchBox()
|
||||||
{
|
{
|
||||||
|
//bool[] bools = ModbusHelper.GetInstance().GetAllBoxState();
|
||||||
|
//bool allFalse = Array.TrueForAll(bools, b => b == false);
|
||||||
|
//if (!allFalse)
|
||||||
|
if (ModbusHelper.BoxOperate)
|
||||||
|
{
|
||||||
|
Task.Factory.StartNew(() => { ModbusHelper.SpeakAsync("请关闭药箱后再打开"); });
|
||||||
|
return;
|
||||||
|
}
|
||||||
iList = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.DrawerType == this.DrawerType && cl.DrawerNo == DrawerNo)
|
iList = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.DrawerType == this.DrawerType && cl.DrawerNo == DrawerNo)
|
||||||
.WhereIF(this.DrawerType == 0, cl => cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).First();
|
.WhereIF(this.DrawerType == 0, cl => cl.BelongUser == HomeWindowViewModel.Operator.UserBarcode).First();
|
||||||
// .Select(cl => cl.DrawerNo).ToList();
|
// .Select(cl => cl.DrawerNo).ToList();
|
||||||
|
@ -648,44 +655,76 @@ namespace DM_Weight.ViewModels
|
||||||
channelList.DrawerState = SelfContent.Substring(0, 1) == "取" ? 0 : 1;
|
channelList.DrawerState = SelfContent.Substring(0, 1) == "取" ? 0 : 1;
|
||||||
SqlSugarHelper.Db.Updateable(channelList).UpdateColumns(it => new { it.EffDate, it.DrawerState }).ExecuteCommand();
|
SqlSugarHelper.Db.Updateable(channelList).UpdateColumns(it => new { it.EffDate, it.DrawerState }).ExecuteCommand();
|
||||||
|
|
||||||
StateTimer.Elapsed += OnTimerElapsed;
|
//StateTimer.Elapsed += OnTimerElapsed;
|
||||||
if (StateTimer.Enabled)
|
//if (StateTimer.Enabled)
|
||||||
|
//{
|
||||||
|
// StateTimer.Stop();
|
||||||
|
// logger.Info($"停止定时查询状态方法");
|
||||||
|
// Thread.Sleep(100);
|
||||||
|
//}
|
||||||
|
//else
|
||||||
{
|
{
|
||||||
StateTimer.Stop();
|
ModbusHelper.SpeakAsync($"正在打开{DrawerNo}号药箱");
|
||||||
logger.Info($"停止定时查询状态方法");
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_portUtil.SpeakAsync($"正在打开{DrawerNo}号药箱");
|
|
||||||
}
|
}
|
||||||
|
//ModbusHelper.GetInstance().OpenBoxDoor(DrawerNo - 1);
|
||||||
ModbusHelper.GetInstance().OpenBoxDoor(DrawerNo - 1);
|
ModbusHelper.GetInstance().OpenBoxDoor(DrawerNo - 1);
|
||||||
Thread.Sleep(15000);
|
|
||||||
StateTimer.Start();
|
Task.Factory.StartNew(async() =>
|
||||||
|
{
|
||||||
|
bool loop = true;
|
||||||
|
while (loop)
|
||||||
|
{
|
||||||
|
await Task.Delay(9000);
|
||||||
|
bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
|
||||||
|
bool state = Array.TrueForAll(boolsl, b => b == false);
|
||||||
|
if(state)
|
||||||
|
{
|
||||||
|
loop = false;
|
||||||
|
ModbusHelper.BoxOperate = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ModbusHelper.SpeakAsync("药箱已打开,请及时关闭");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//StateTimer.Start();
|
||||||
SelfStatus = 0;
|
SelfStatus = 0;
|
||||||
PublicEnable = true;
|
//PublicEnable = true;
|
||||||
SelfEnable = true;
|
//SelfEnable = true;
|
||||||
DrawerType = -1;
|
DrawerType = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
|
//private void OnTimerElapsed(object sender, ElapsedEventArgs e)
|
||||||
|
//{
|
||||||
|
// bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
|
||||||
|
// bool allTrue = Array.TrueForAll(boolArrs, b => b == false);
|
||||||
|
// logger.Info($"进入定时查询状态方法{allTrue}");
|
||||||
|
// if (allTrue)
|
||||||
|
// {
|
||||||
|
// //药箱全部关闭,停止查询
|
||||||
|
// StateTimer.Stop();
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// _portUtil.SpeakAsync("药箱已打开,请及时关闭");
|
||||||
|
// //Console.Beep(800, 1100);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
void DoMyPrismEvent(DeviceMsg msg)
|
||||||
{
|
{
|
||||||
bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
|
switch (msg.EventType)
|
||||||
bool allTrue = Array.TrueForAll(boolArrs, b => b == false);
|
|
||||||
logger.Info($"进入定时查询状态方法{allTrue}");
|
|
||||||
if (allTrue)
|
|
||||||
{
|
{
|
||||||
//药箱全部关闭,停止查询
|
case EventType.DRAWERCLOSE:
|
||||||
StateTimer.Stop();
|
SelfEnable = false;
|
||||||
}
|
break;
|
||||||
else
|
|
||||||
{
|
|
||||||
_portUtil.SpeakAsync("药箱已打开,请及时关闭");
|
|
||||||
//Console.Beep(800, 1100);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void OnNavigatedTo(NavigationContext navigationContext)
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
||||||
{
|
{
|
||||||
|
_eventAggregator.GetEvent<PortUtilEvent>().Subscribe(DoMyPrismEvent);
|
||||||
RequestData();
|
RequestData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -696,6 +735,7 @@ namespace DM_Weight.ViewModels
|
||||||
|
|
||||||
public void OnNavigatedFrom(NavigationContext navigationContext)
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
||||||
{
|
{
|
||||||
|
_eventAggregator.GetEvent<PortUtilEvent>().Unsubscribe(DoMyPrismEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,6 +198,14 @@ namespace DM_Weight.ViewModels
|
||||||
{
|
{
|
||||||
if (DrawerNo > 0)
|
if (DrawerNo > 0)
|
||||||
{
|
{
|
||||||
|
//bool[] bools = ModbusHelper.GetInstance().GetAllBoxState();
|
||||||
|
//bool allFalse = Array.TrueForAll(bools, b => b == false);
|
||||||
|
//if (!allFalse)
|
||||||
|
if (ModbusHelper.BoxOperate)
|
||||||
|
{
|
||||||
|
Task.Factory.StartNew(() => { ModbusHelper.SpeakAsync("请关闭药箱后再打开"); });
|
||||||
|
return;
|
||||||
|
}
|
||||||
IsEnable = false;
|
IsEnable = false;
|
||||||
Status = 1;
|
Status = 1;
|
||||||
//_portUtil.SpeakAsync("正在打开药箱");
|
//_portUtil.SpeakAsync("正在打开药箱");
|
||||||
|
@ -213,12 +221,31 @@ namespace DM_Weight.ViewModels
|
||||||
Type = 55,
|
Type = 55,
|
||||||
InvoiceId = $"打开{DrawerNo}号药箱",
|
InvoiceId = $"打开{DrawerNo}号药箱",
|
||||||
}).ExecuteCommand();
|
}).ExecuteCommand();
|
||||||
bool bFlag = ModbusHelper.GetInstance().OpenBoxDoor(DrawerNo - 1);
|
ModbusHelper.GetInstance().OpenBoxDoor(DrawerNo - 1);
|
||||||
if (bFlag)
|
//if (bFlag)
|
||||||
{
|
{
|
||||||
IsEnable = true;
|
IsEnable = true;
|
||||||
Status = 0;
|
Status = 0;
|
||||||
}
|
}
|
||||||
|
Task.Factory.StartNew(async () =>
|
||||||
|
{
|
||||||
|
bool loop = true;
|
||||||
|
while (loop)
|
||||||
|
{
|
||||||
|
await Task.Delay(9000);
|
||||||
|
bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
|
||||||
|
bool state = Array.TrueForAll(boolsl, b => b == false);
|
||||||
|
if (state)
|
||||||
|
{
|
||||||
|
loop = false;
|
||||||
|
ModbusHelper.BoxOperate = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ModbusHelper.SpeakAsync("药箱已打开,请及时关闭");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,10 +55,10 @@ namespace DM_Weight.Views
|
||||||
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
|
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
// 串口无人操作
|
// 串口无人操作
|
||||||
bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
|
//bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
|
||||||
bool allTrue = Array.TrueForAll(boolArrs, b => b == false);
|
//bool allTrue = Array.TrueForAll(boolArrs, b => b == false);
|
||||||
logger.Info($"进入自动退出定时方法{allTrue}");
|
logger.Info($"进入自动退出定时方法{ModbusHelper.BoxOperate}");
|
||||||
if (allTrue&&idleTimer.Enabled)
|
if (ModbusHelper.BoxOperate && idleTimer.Enabled)
|
||||||
{
|
{
|
||||||
idleTimer.Stop();
|
idleTimer.Stop();
|
||||||
//无人操作,自动退出
|
//无人操作,自动退出
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Grid Grid.Column="0">
|
<Grid Grid.Column="0" Margin="6">
|
||||||
<Grid.Resources>
|
<Grid.Resources>
|
||||||
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignPaperLightButton}">
|
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignPaperLightButton}">
|
||||||
<Setter Property="Foreground" Value="#00a0ea" />
|
<Setter Property="Foreground" Value="#00a0ea" />
|
||||||
|
|
Loading…
Reference in New Issue