pry 2 years ago
parent
commit
2472d55e99
6 changed files with 35 additions and 22 deletions
  1. +26
    -15
      HBLConsole.Communication/Serial/SerialPortClient.cs
  2. +4
    -4
      HBLConsole.MORKIC/Control_MORKIC.cs
  3. +1
    -1
      HBLDevice.IceCream/IceCreamMachine.cs
  4. +1
    -1
      HBLDevice.IceCream/MorkIStatus.cs
  5. +2
    -0
      HBLDevice.IceCream/Protocal/ICMSG_Heart_UP.cs
  6. +1
    -1
      HBLDevice.IceCream/Protocal/MessageDefine.cs

+ 26
- 15
HBLConsole.Communication/Serial/SerialPortClient.cs View File

@@ -146,7 +146,7 @@ namespace HBLConsole.Communication
/// <summary>
/// 判断是否有这个串口
/// </summary>
public bool IsHavePort => SerialPort.GetPortNames().GetIndex(PortName) > 0;
public bool IsHavePort => SerialPort.GetPortNames().Contains(PortName);

/// <summary>
/// 打开端口
@@ -154,14 +154,17 @@ namespace HBLConsole.Communication
/// <returns></returns>
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>
@@ -183,6 +186,7 @@ namespace HBLConsole.Communication
}
#endregion

private object lck4Serial = new object();
#region 写入数据
/// <summary>
/// 写入数据
@@ -190,9 +194,12 @@ namespace HBLConsole.Communication
/// <param name="buffer"></param>
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>
@@ -201,9 +208,13 @@ namespace HBLConsole.Communication
/// <param name="buffer">写入端口的字节数组</param>
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()


+ 4
- 4
HBLConsole.MORKIC/Control_MORKIC.cs View File

@@ -244,10 +244,10 @@ namespace HBLConsole.MORKIC
//开始心跳刷新,根据咖啡机及冰淇淋机来判断
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);
}), "MORK-IC心跳刷新");



+ 1
- 1
HBLDevice.IceCream/IceCreamMachine.cs View File

@@ -51,7 +51,7 @@ namespace HBLDevice.IceCream
{
commProxy.SendData(commandHandler.GetHeartDW());
SendCallback?.Invoke(BitConverter.ToString(commandHandler.GetHeartDW()));
Thread.Sleep(2000);
Thread.Sleep(500);
}), "冰淇淋询问线程");

ThreadOperate.GetInstance.StartLong(new Action(() =>


+ 1
- 1
HBLDevice.IceCream/MorkIStatus.cs View File

@@ -77,7 +77,7 @@ namespace HBLDevice.IceCream
Fault = (MORKI_FAULT)BitConverter.ToInt16(new byte[] { heartUpMsg.GZ_L, heartUpMsg.GZ_H }, 0);
CXB = heartUpMsg.CXB;

MessageLog.GetInstance.Show(string.Format("当前模式为:{0}", CurrentMode));
//MessageLog.GetInstance.Show(string.Format("当前模式为:{0}", CurrentMode));
}

private void ProcessModeUp(ICMSG_MODE_UP modeUpMsg)


+ 2
- 0
HBLDevice.IceCream/Protocal/ICMSG_Heart_UP.cs View File

@@ -34,6 +34,8 @@ namespace HBLDevice.IceCream
public MORKI_MODE MS;
public byte DLTJ;
public byte CXB;
public byte DLBS_H;
public byte DLBS_L;

public short CalcCode;



+ 1
- 1
HBLDevice.IceCream/Protocal/MessageDefine.cs View File

@@ -34,7 +34,7 @@ namespace HBLDevice.IceCream

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},
};



Loading…
Cancel
Save