Files
ENIG/Cs_HMI/Project/StateMachine/_BMS.cs
ChiKyun Kim d777adc219 BMS 를 RS232 클래스에서 폴링방식 전용 클래스로 변경
BMS 정보중 현재 사용 전류와 와트를 표시함
사용전류를 통해서 충전여부를 자동 판다시키고, 해당 값은 Manual Charge 플래그에 설정함.
2025-12-18 14:44:00 +09:00

211 lines
7.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using arCtl;
using Project.StateMachine;
using COMM;
using AR;
namespace Project
{
public partial class fMain
{
string lastbms03 = "";
string lastbms04 = "";
string lastbmsA03 = "";
string lastbmsA04 = "";
string lastbms = "";
DateTime lastbmstime03 = DateTime.Now;
DateTime lastbmstime04 = DateTime.Now;
DateTime lastbmstimeA03 = DateTime.Now;
DateTime lastbmstimeA04 = DateTime.Now;
DateTime lastbmstime = DateTime.Now;
private void Bms_Message(object sender, arDev.BMS.MessageEventArgs e)
{
if (e.MsgType == arDev.BMSSerialComm.MessageType.Error) PUB.logbms.AddE(e.Message);
else
{
VAR.TIME[eVarTime.LastRecv_BAT] = DateTime.Now;
var hexstr = e.Data.GetHexString().Trim();
bool addlog = false;
var logtimesec = 30;
if (hexstr.StartsWith("DD 04"))
{
if (lastbms04.Equals(hexstr.Substring(0, 5)) == false)
{
addlog = true;
lastbms04 = "DD 04";
lastbmstime04 = DateTime.Now;
}
else
{
var ts = DateTime.Now - lastbmstime04;
if (ts.TotalSeconds > logtimesec)
{
addlog = true;
lastbms04 = "DD 04";
lastbmstime04 = DateTime.Now;
}
}
}
else if (hexstr.StartsWith("DD 03"))
{
if (lastbms03.Equals(hexstr.Substring(0, 5)) == false)
{
addlog = true;
lastbms03 = "DD 03";
lastbmstime03 = DateTime.Now;
}
else
{
var ts = DateTime.Now - lastbmstime03;
if (ts.TotalSeconds > logtimesec)
{
addlog = true;
lastbms03 = "DD 03";
lastbmstime03 = DateTime.Now;
}
}
}
else if (hexstr.StartsWith("DD A5 04"))
{
if (lastbmsA04.Equals(hexstr.Substring(0, 8)) == false)
{
addlog = true;
lastbmsA04 = "DD A5 04";
lastbmstimeA04 = DateTime.Now;
}
else
{
var ts = DateTime.Now - lastbmstimeA04;
if (ts.TotalSeconds > logtimesec)
{
addlog = true;
lastbmsA04 = "DD A5 04";
lastbmstimeA04 = DateTime.Now;
}
}
}
else if (hexstr.StartsWith("DD A5 03"))
{
if (lastbmsA03.Equals(hexstr.Substring(0, 8)) == false)
{
addlog = true;
lastbmsA03 = "DD A5 03";
lastbmstimeA03 = DateTime.Now;
}
else
{
var ts = DateTime.Now - lastbmstimeA03;
if (ts.TotalSeconds > logtimesec)
{
addlog = true;
lastbmsA03 = "DD A5 03";
lastbmstimeA03 = DateTime.Now;
}
}
}
else if (hexstr.isEmpty() == false)
{
if (lastbms.Equals(hexstr) == false)
{
lastbms = hexstr;
lastbmstime = DateTime.Now;
addlog = true;
}
else
{
var ts = DateTime.Now - lastbmstime;
if (ts.TotalSeconds > logtimesec)
{
addlog = true;
lastbms = hexstr;
lastbmstime = DateTime.Now;
}
}
}
if (addlog)
{
//if (e.MsgType == arDev.arRS232.MessageType.Recv)
// PUB.logbms.Add("RX", e.Data.GetHexString());
//else if (e.MsgType == arDev.arRS232.MessageType.Send)
// PUB.logbms.Add("TX", e.Data.GetHexString());
//else
{
PUB.logbms.Add(e.MsgType.ToString(),e.Message);
}
}
}
}
private void BMS_ChargeDetect(object sender, arDev.ChargetDetectArgs e)
{
//자동충전중이아니고 멈춰있다면 수동 충전으로 전환한다
VAR.TIME[eVarTime.LastRecv_BAT] = DateTime.Now;
if (e.Detected == true) //충전이 감지되었다.
{
if (VAR.BOOL[eVarBool.FLAG_AUTORUN] == false && VAR.BOOL[eVarBool.FLAG_CHARGEONM] == false)
{
VAR.BOOL[eVarBool.FLAG_CHARGEONM] = true;
PUB.Speak(Lang.);
if (PUB.AGV.system1.agv_run == true) PUB.AGV.AGVMoveStop("수동충전감지");
}
}
else PUB.logbms.AddI("Battery Charge Off");
}
private void Bms_BMSDataReceive(object sender, EventArgs e)
{
VAR.TIME[eVarTime.LastRecv_BAT] = DateTime.Now;
//PUB.mapctl.Manager.agv.BatteryLevel = PUB.BMS.Current_Level;
//PUB.mapctl.Manager.agv.BatteryTemp1 = PUB.BMS.Current_temp1;
//PUB.mapctl.Manager.agv.BatteryTemp2 = PUB.BMS.Current_temp2;
// [Sync] Update VirtualAGV Battery
PUB.UpdateAGVBattery(PUB.BMS.Current_Level);
if (PUB.BMS.Current_Level <= PUB.setting.ChargeStartLevel)
{
//배터리 레벨이 기준보다 낮다면 경고를 활성화 한다
if (VAR.BOOL[eVarBool.BATTERY_LOW] == false)
{
VAR.BOOL[eVarBool.BATTERY_LOW] = true;
PUB.log.AddAT("배터리 부족 경고 활성화");
}
}
else
{
//배터리 경고를 해제한다
if (VAR.BOOL[eVarBool.BATTERY_LOW] == true)
{
VAR.BOOL[eVarBool.BATTERY_LOW] = false;
PUB.log.AddAT("배터리 부족 경고 비활성화");
}
}
EEMStatus.MakeBMSInformation_INFO();
}
private void BMS_BMSCellDataReceive(object sender, arDev.BMSCelvoltageEventArgs e)
{
VAR.TIME[eVarTime.LastRecv_BAT] = DateTime.Now;
EEMStatus.MakeBMSInformation_Cell();
}
}
}