@@ -146,7 +146,7 @@ namespace HBLConsole.Communication | |||||
/// <summary> | /// <summary> | ||||
/// 判断是否有这个串口 | /// 判断是否有这个串口 | ||||
/// </summary> | /// </summary> | ||||
public bool IsHavePort => SerialPort.GetPortNames().GetIndex(PortName) > 0; | |||||
public bool IsHavePort => SerialPort.GetPortNames().Contains(PortName); | |||||
/// <summary> | /// <summary> | ||||
/// 打开端口 | /// 打开端口 | ||||
@@ -154,14 +154,17 @@ namespace HBLConsole.Communication | |||||
/// <returns></returns> | /// <returns></returns> | ||||
public void Open() | public void Open() | ||||
{ | { | ||||
if (!IsHavePort) return; | |||||
if (comPort.IsOpen) comPort.Close(); | |||||
comPort.PortName = portName; | |||||
comPort.BaudRate = (int)baudRate; | |||||
comPort.Parity = parity; | |||||
comPort.DataBits = (int)dataBits; | |||||
comPort.StopBits = stopBits; | |||||
comPort.Open(); | |||||
lock (lck4Serial) | |||||
{ | |||||
if (!IsHavePort) return; | |||||
if (comPort.IsOpen) comPort.Close(); | |||||
comPort.PortName = portName; | |||||
comPort.BaudRate = (int)baudRate; | |||||
comPort.Parity = parity; | |||||
comPort.DataBits = (int)dataBits; | |||||
comPort.StopBits = stopBits; | |||||
comPort.Open(); | |||||
} | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -183,6 +186,7 @@ namespace HBLConsole.Communication | |||||
} | } | ||||
#endregion | #endregion | ||||
private object lck4Serial = new object(); | |||||
#region 写入数据 | #region 写入数据 | ||||
/// <summary> | /// <summary> | ||||
/// 写入数据 | /// 写入数据 | ||||
@@ -190,9 +194,12 @@ namespace HBLConsole.Communication | |||||
/// <param name="buffer"></param> | /// <param name="buffer"></param> | ||||
public void Write(byte[] buffer, int offset, int count) | public void Write(byte[] buffer, int offset, int count) | ||||
{ | { | ||||
if (!IsHavePort) return; | |||||
if (!(comPort.IsOpen)) comPort.Open(); | |||||
comPort.Write(buffer, offset, count); | |||||
lock (lck4Serial) | |||||
{ | |||||
if (!IsHavePort) return; | |||||
if (!(comPort.IsOpen)) comPort.Open(); | |||||
comPort.Write(buffer, offset, count); | |||||
} | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
@@ -201,9 +208,13 @@ namespace HBLConsole.Communication | |||||
/// <param name="buffer">写入端口的字节数组</param> | /// <param name="buffer">写入端口的字节数组</param> | ||||
public void Write(byte[] buffer) | public void Write(byte[] buffer) | ||||
{ | { | ||||
if (!IsHavePort) return; | |||||
if (!(comPort.IsOpen)) comPort.Open(); | |||||
comPort.Write(buffer, 0, buffer.Length); | |||||
lock (lck4Serial) | |||||
{ | |||||
if (!IsHavePort) return; | |||||
if (!(comPort.IsOpen)) comPort.Open(); | |||||
comPort.Write(buffer, 0, buffer.Length); | |||||
} | |||||
} | } | ||||
public void Start() | public void Start() | ||||
@@ -244,10 +244,10 @@ namespace HBLConsole.MORKIC | |||||
//开始心跳刷新,根据咖啡机及冰淇淋机来判断 | //开始心跳刷新,根据咖啡机及冰淇淋机来判断 | ||||
ThreadOperate.GetInstance.StartLong(new Action(() => | ThreadOperate.GetInstance.StartLong(new Action(() => | ||||
{ | { | ||||
GeneralConfig.Healthy = true; | |||||
//GeneralConfig.Healthy = | |||||
// MorkIStatus.GetInstance().CanDo && | |||||
// MorkCStatus.GetInstance().CanDo; | |||||
//GeneralConfig.Healthy = true; | |||||
GeneralConfig.Healthy = | |||||
MorkIStatus.GetInstance().CanDo && | |||||
MorkCStatus.GetInstance().CanDo; | |||||
Thread.Sleep(100); | Thread.Sleep(100); | ||||
}), "MORK-IC心跳刷新"); | }), "MORK-IC心跳刷新"); | ||||
@@ -51,7 +51,7 @@ namespace HBLDevice.IceCream | |||||
{ | { | ||||
commProxy.SendData(commandHandler.GetHeartDW()); | commProxy.SendData(commandHandler.GetHeartDW()); | ||||
SendCallback?.Invoke(BitConverter.ToString(commandHandler.GetHeartDW())); | SendCallback?.Invoke(BitConverter.ToString(commandHandler.GetHeartDW())); | ||||
Thread.Sleep(2000); | |||||
Thread.Sleep(500); | |||||
}), "冰淇淋询问线程"); | }), "冰淇淋询问线程"); | ||||
ThreadOperate.GetInstance.StartLong(new Action(() => | ThreadOperate.GetInstance.StartLong(new Action(() => | ||||
@@ -77,7 +77,7 @@ namespace HBLDevice.IceCream | |||||
Fault = (MORKI_FAULT)BitConverter.ToInt16(new byte[] { heartUpMsg.GZ_L, heartUpMsg.GZ_H }, 0); | Fault = (MORKI_FAULT)BitConverter.ToInt16(new byte[] { heartUpMsg.GZ_L, heartUpMsg.GZ_H }, 0); | ||||
CXB = heartUpMsg.CXB; | CXB = heartUpMsg.CXB; | ||||
MessageLog.GetInstance.Show(string.Format("当前模式为:{0}", CurrentMode)); | |||||
//MessageLog.GetInstance.Show(string.Format("当前模式为:{0}", CurrentMode)); | |||||
} | } | ||||
private void ProcessModeUp(ICMSG_MODE_UP modeUpMsg) | private void ProcessModeUp(ICMSG_MODE_UP modeUpMsg) | ||||
@@ -34,6 +34,8 @@ namespace HBLDevice.IceCream | |||||
public MORKI_MODE MS; | public MORKI_MODE MS; | ||||
public byte DLTJ; | public byte DLTJ; | ||||
public byte CXB; | public byte CXB; | ||||
public byte DLBS_H; | |||||
public byte DLBS_L; | |||||
public short CalcCode; | public short CalcCode; | ||||
@@ -34,7 +34,7 @@ namespace HBLDevice.IceCream | |||||
public static Dictionary<IC_CMD, int> MSG_LENGTH = new Dictionary<IC_CMD, int>() { | public static Dictionary<IC_CMD, int> MSG_LENGTH = new Dictionary<IC_CMD, int>() { | ||||
{ IC_CMD.HEART,16}, | |||||
{ IC_CMD.HEART,18}, | |||||
{ IC_CMD.MODE,2}, | { IC_CMD.MODE,2}, | ||||
}; | }; | ||||