1541 lines
58 KiB
C#
1541 lines
58 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Runtime.InteropServices;
|
|
using System.Diagnostics;
|
|
using System.Reflection;
|
|
|
|
using BMS_D1000H.BMSConstData;
|
|
using BMS_D1000H.DataStructs;
|
|
using BMS_D1000H.Functions;
|
|
using BMS_D1000H.Utils.Functions;
|
|
using System.Threading;
|
|
using System.IO;
|
|
|
|
namespace BMS_D1000H
|
|
{
|
|
public partial class fmBMSMain : Form
|
|
{
|
|
#region VARAABLES
|
|
public AssemblyName AppName;
|
|
public int ScreenMode = ScreenID.MAIN_SCREEN_ID;
|
|
string[] TrayName = { "#1", "#2", "#3", "#4", "#5", "#6", "#7", "#8", "#9", "#10" };
|
|
|
|
int InitPassCount = 0;
|
|
int InitPassTimeCount = 0;
|
|
|
|
DateTime disTime;
|
|
int mbReqAddress = 0xFFFF;
|
|
int mbDataCount = 0;
|
|
|
|
int[] TrayStatus;
|
|
int[] disTrayStatus;
|
|
|
|
bool ledflag = false;
|
|
|
|
int ModbusTxFlag = 0;
|
|
int ModbusTimeoutCount = 0;
|
|
|
|
//int ScreenSaveMode = 0;
|
|
int ScreenSaveTime = 0;
|
|
|
|
int bakTimeMin, bakTimeSec;
|
|
int bakModuleQuantity = 0;
|
|
|
|
public fmTrayInfo chfTrayInfo;
|
|
public fmHistory chfHistory;
|
|
public fmPassword chfPassword;
|
|
public fmParamSet chfParamSet;
|
|
public fmParamSetCmd chfParamSetCmd;
|
|
public fmScreenSaver chfScreenSaver;
|
|
public fmSetMenu chfSetMenu;
|
|
public fmNetConfig chfNetConfig;
|
|
public fmNetConfigCmd chfNetConfigCmd;
|
|
public fmSystemSet chfSystemSet;
|
|
public fmSystemSetCmd chfSystemSetCmd;
|
|
|
|
DeviceDataSystem BMSData;
|
|
DeviceDataSystem disBMSData;
|
|
|
|
public DeviceDataTray[] TrayData;
|
|
public DeviceDataTray[] disTrayData;
|
|
|
|
public DeviceParam[] SetTrayParam;
|
|
|
|
DeviceParamSet SetParamCmd;
|
|
|
|
//SmartX.SmartLabel[] TrayVoltageValue;
|
|
//SmartX.SmartLabel[] TrayCurrentValue;
|
|
//SmartX.SmartLabel[] TraySOCValue;
|
|
//SmartX.SmartLabel[] TrayTempValue;
|
|
|
|
SmartX.SmartLabel[] ModuleNo;
|
|
SmartX.SmartLabel[] ModuleAlarmBtn;
|
|
SmartX.SmartLabel[] ModuleSocNo;
|
|
|
|
PictureBox[] MainWarning;
|
|
PictureBox[] MainProtection;
|
|
|
|
PictureBox[] ModuleSocPicture;
|
|
SmartX.SmartProgressBar[] ModuleSocBar;
|
|
|
|
public AlarmFile BmsAlarmFile;
|
|
#endregion
|
|
|
|
#region FORM MAIN INITIALIZE
|
|
public fmBMSMain()
|
|
{
|
|
InitializeComponent();
|
|
|
|
ComponentInit();
|
|
|
|
Control_Reload();
|
|
|
|
TrayStatus = new int[SystemID.MAX_MODULE_SIZE];
|
|
disTrayStatus = new int[SystemID.MAX_MODULE_SIZE];
|
|
|
|
BmsAlarmFile = new AlarmFile();
|
|
|
|
chfTrayInfo = new fmTrayInfo();
|
|
chfHistory = new fmHistory();
|
|
chfPassword = new fmPassword();
|
|
chfParamSet = new fmParamSet();
|
|
chfParamSetCmd = new fmParamSetCmd();
|
|
chfScreenSaver = new fmScreenSaver();
|
|
chfSetMenu = new fmSetMenu();
|
|
chfNetConfig = new fmNetConfig();
|
|
chfNetConfigCmd = new fmNetConfigCmd();
|
|
chfSystemSet = new fmSystemSet();
|
|
chfSystemSetCmd = new fmSystemSetCmd();
|
|
|
|
SetTrayParam = new DeviceParam[SystemID.MAX_MODULE_SIZE];
|
|
|
|
BMSData = new DeviceDataSystem();
|
|
|
|
BMSData.param = new DeviceParam();
|
|
BMSData.param.voltage = new DeviceParamVoltage();
|
|
BMSData.param.current = new DeviceParamCurrent();
|
|
BMSData.param.temperature = new DeviceParamTemperature();
|
|
BMSData.param.soc = new DeviceParamSoc();
|
|
|
|
BMSData.netconfig = new DeviceNetConfig();
|
|
BMSData.netconfig.ip_addr = new ClassAddr();
|
|
BMSData.netconfig.ip_addr.addr = new short[4];
|
|
BMSData.netconfig.subnet_mask = new ClassAddr();
|
|
BMSData.netconfig.subnet_mask.addr = new short[4];
|
|
BMSData.netconfig.gateway_addr = new ClassAddr();
|
|
BMSData.netconfig.gateway_addr.addr = new short[4];
|
|
|
|
BMSData.netconfig.trap = new ClassAddr[4];
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
BMSData.netconfig.trap[i] = new ClassAddr();
|
|
BMSData.netconfig.trap[i].addr = new short[4];
|
|
}
|
|
|
|
BMSData.ModuleQuantity = 10;
|
|
|
|
AppName = Assembly.GetExecutingAssembly().GetName();
|
|
}
|
|
#endregion
|
|
|
|
private void BMSMainDataInit()
|
|
{
|
|
lbMainVoltage.Text = "0.0";
|
|
lbMainCurrent.Text = "0.0";
|
|
lbMainSOC.Text = "0.0";
|
|
lbMainTemp.Text = "0.0";
|
|
}
|
|
|
|
#region Component Init
|
|
private void ComponentInit()
|
|
{
|
|
ModuleNo = new SmartX.SmartLabel[SystemID.MAX_MODULE_SIZE];
|
|
for (int i = 0; i < SystemID.MAX_MODULE_SIZE; i++)
|
|
{
|
|
ModuleNo[i] = new SmartX.SmartLabel();
|
|
ModuleNo[i].BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
|
|
ModuleNo[i].BackPictureBox = sfmMain;
|
|
ModuleNo[i].BackPictureBox1 = null;
|
|
ModuleNo[i].BackPictureBox2 = null;
|
|
ModuleNo[i].BorderColor = System.Drawing.Color.Black;
|
|
ModuleNo[i].BorderStyle = System.Windows.Forms.BorderStyle.None;
|
|
ModuleNo[i].Font = new System.Drawing.Font("Tahoma", 14F, System.Drawing.FontStyle.Bold);
|
|
ModuleNo[i].InitVisible = true;
|
|
ModuleNo[i].LineSpacing = 0F;
|
|
ModuleNo[i].Location = new System.Drawing.Point(5, 55 + (i * 40));
|
|
ModuleNo[i].Name = String.Format("ModuleNo{0}", i);
|
|
ModuleNo[i].Size = new System.Drawing.Size(214, 37);
|
|
ModuleNo[i].TabIndex = i;
|
|
ModuleNo[i].Text = TrayName[i];
|
|
ModuleNo[i].TextHAlign = SmartX.SmartLabel.TextHorAlign.Left;
|
|
ModuleNo[i].TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle;
|
|
ModuleNo[i].Wordwrap = false;
|
|
ModuleNo[i].Click += new System.EventHandler(TrayLabel_Click);
|
|
}
|
|
|
|
ModuleSocNo = new SmartX.SmartLabel[SystemID.MAX_MODULE_SIZE];
|
|
for (int i = 0; i < SystemID.MAX_MODULE_SIZE; i++)
|
|
{
|
|
ModuleSocNo[i] = new SmartX.SmartLabel();
|
|
ModuleSocNo[i].BackPictureBox = sfmMain;
|
|
ModuleSocNo[i].BackPictureBox1 = null;
|
|
ModuleSocNo[i].BackPictureBox2 = null;
|
|
ModuleSocNo[i].BorderColor = System.Drawing.Color.Black;
|
|
ModuleSocNo[i].BorderStyle = System.Windows.Forms.BorderStyle.None;
|
|
ModuleSocNo[i].Font = new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Bold);
|
|
ModuleSocNo[i].InitVisible = true;
|
|
ModuleSocNo[i].LineSpacing = 0F;
|
|
ModuleSocNo[i].Location = new System.Drawing.Point(246 + (i * 55), 85); //new System.Drawing.Point(5, 55 + (i * 40));
|
|
ModuleSocNo[i].Name = String.Format("ModuleSocNo{0}", i);
|
|
ModuleSocNo[i].Size = new System.Drawing.Size(53, 21);
|
|
ModuleSocNo[i].TabIndex = i;
|
|
ModuleSocNo[i].Text = TrayName[i];
|
|
ModuleSocNo[i].TextHAlign = SmartX.SmartLabel.TextHorAlign.Middle;
|
|
ModuleSocNo[i].TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle;
|
|
ModuleSocNo[i].Wordwrap = false;
|
|
}
|
|
|
|
ModuleAlarmBtn = new SmartX.SmartLabel[SystemID.MAX_MODULE_SIZE];
|
|
for (int i = 0; i < SystemID.MAX_MODULE_SIZE; i++)
|
|
{
|
|
ModuleAlarmBtn[i] = new SmartX.SmartLabel();
|
|
ModuleAlarmBtn[i].BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
|
|
ModuleAlarmBtn[i].BackPictureBox = sfmMain;
|
|
ModuleAlarmBtn[i].BackPictureBox1 = null;
|
|
ModuleAlarmBtn[i].BackPictureBox2 = null;
|
|
ModuleAlarmBtn[i].BorderColor = System.Drawing.Color.Black;
|
|
ModuleAlarmBtn[i].BorderStyle = System.Windows.Forms.BorderStyle.None;
|
|
ModuleAlarmBtn[i].Font = new System.Drawing.Font("Tahoma", 14F, System.Drawing.FontStyle.Bold);
|
|
ModuleAlarmBtn[i].InitVisible = true;
|
|
ModuleAlarmBtn[i].LineSpacing = 0F;
|
|
//ModuleAlarmBtn[i].Location = new System.Drawing.Point(57, 55 + ((SystemID.MAX_MODULE_SIZE - i - 1) * 40));
|
|
ModuleAlarmBtn[i].Location = new System.Drawing.Point(57, 55 + (i * 40));
|
|
ModuleAlarmBtn[i].Name = String.Format("ModuleAlarmBtn{0}", i);
|
|
ModuleAlarmBtn[i].Size = new System.Drawing.Size(174, 37);
|
|
ModuleAlarmBtn[i].TabIndex = i;
|
|
ModuleAlarmBtn[i].Text = "";
|
|
ModuleAlarmBtn[i].TextHAlign = SmartX.SmartLabel.TextHorAlign.Left;
|
|
ModuleAlarmBtn[i].TextVAlign = SmartX.SmartLabel.TextVerAlign.Middle;
|
|
ModuleAlarmBtn[i].Wordwrap = false;
|
|
ModuleAlarmBtn[i].Click += new System.EventHandler(TrayLabel_Click);
|
|
}
|
|
|
|
MainWarning = new PictureBox[10];
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
MainWarning[i] = new PictureBox();
|
|
if (i < 5)
|
|
{
|
|
if ((i % 2) == 0)
|
|
MainWarning[i].Image = pbMAlarmNormalA.Image;
|
|
else
|
|
MainWarning[i].Image = pbMAlarmNormalB.Image;
|
|
}
|
|
else
|
|
{
|
|
if ((i % 2) == 0)
|
|
MainWarning[i].Image = pbMAlarmNormalB.Image;
|
|
else
|
|
MainWarning[i].Image = pbMAlarmNormalA.Image;
|
|
}
|
|
MainWarning[i].Location = new System.Drawing.Point(205, (200 + (i * 24)));
|
|
MainWarning[i].Name = String.Format("MainWarning{0}", i);
|
|
MainWarning[i].Size = new System.Drawing.Size(18, 18);
|
|
MainWarning[i].SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
|
}
|
|
MainWarning[0].Location = new System.Drawing.Point(464, 314);
|
|
MainWarning[1].Location = new System.Drawing.Point(464, 338);
|
|
MainWarning[2].Location = new System.Drawing.Point(464, 361);
|
|
MainWarning[3].Location = new System.Drawing.Point(464, 384);
|
|
MainWarning[4].Location = new System.Drawing.Point(464, 408);
|
|
MainWarning[5].Location = new System.Drawing.Point(739, 314);
|
|
MainWarning[6].Location = new System.Drawing.Point(739, 338);
|
|
MainWarning[7].Location = new System.Drawing.Point(739, 361);
|
|
MainWarning[8].Location = new System.Drawing.Point(739, 384);
|
|
MainWarning[9].Location = new System.Drawing.Point(739, 408);
|
|
|
|
MainProtection = new PictureBox[10];
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
switch (i)
|
|
{
|
|
case 0:
|
|
case 1:
|
|
case 4:
|
|
case 6:
|
|
case 7:
|
|
MainProtection[i] = new PictureBox();
|
|
if (i < 5)
|
|
{
|
|
if ((i % 2) == 0)
|
|
MainProtection[i].Image = pbMAlarmNormalA.Image;
|
|
else
|
|
MainProtection[i].Image = pbMAlarmNormalB.Image;
|
|
}
|
|
else
|
|
{
|
|
if ((i % 2) == 0)
|
|
MainProtection[i].Image = pbMAlarmNormalB.Image;
|
|
else
|
|
MainProtection[i].Image = pbMAlarmNormalA.Image;
|
|
}
|
|
MainProtection[i].Location = new System.Drawing.Point(205, (234 + (i * 24)));
|
|
MainProtection[i].Name = String.Format("MainProtection{0}", i);
|
|
MainProtection[i].Size = new System.Drawing.Size(18, 18);
|
|
MainProtection[i].SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
|
break;
|
|
}
|
|
|
|
}
|
|
MainProtection[0].Location = new System.Drawing.Point(496, 314);
|
|
MainProtection[1].Location = new System.Drawing.Point(496, 338);
|
|
//MainProtection[2].Location = new System.Drawing.Point(496, 361);
|
|
//MainProtection[3].Location = new System.Drawing.Point(496, 384);
|
|
MainProtection[4].Location = new System.Drawing.Point(496, 408);
|
|
//MainProtection[5].Location = new System.Drawing.Point(772, 314);
|
|
MainProtection[6].Location = new System.Drawing.Point(772, 338);
|
|
MainProtection[7].Location = new System.Drawing.Point(772, 361);
|
|
//MainProtection[8].Location = new System.Drawing.Point(772, 384);
|
|
//MainProtection[9].Location = new System.Drawing.Point(772, 408);
|
|
|
|
//
|
|
// ModuleSocPictureBox - 246, 109
|
|
//
|
|
ModuleSocPicture = new PictureBox[SystemID.MAX_MODULE_SIZE];
|
|
for (int i = 0; i < SystemID.MAX_MODULE_SIZE; i++)
|
|
{
|
|
ModuleSocPicture[i] = new PictureBox();
|
|
ModuleSocPicture[i].Image = pictureBox1.Image;
|
|
ModuleSocPicture[i].Location = new System.Drawing.Point(246 + (i * 55), 109);
|
|
ModuleSocPicture[i].Name = String.Format("ModuleSocPicture_{0}", i);
|
|
ModuleSocPicture[i].Size = new System.Drawing.Size(53, 143);
|
|
ModuleSocPicture[i].SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
|
}
|
|
|
|
//
|
|
// smartProgressBar1
|
|
//
|
|
ModuleSocBar = new SmartX.SmartProgressBar[SystemID.MAX_MODULE_SIZE];
|
|
for (int i = 0; i < SystemID.MAX_MODULE_SIZE; i++)
|
|
{
|
|
ModuleSocBar[i] = new SmartX.SmartProgressBar();
|
|
ModuleSocBar[i].AutoColorSet = true;
|
|
ModuleSocBar[i].BarBackColor1 = System.Drawing.Color.White;
|
|
ModuleSocBar[i].BarBackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
|
|
ModuleSocBar[i].BarColor1 = System.Drawing.Color.Green;
|
|
ModuleSocBar[i].BarColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128)))));
|
|
ModuleSocBar[i].BarStyle = SmartX.SmartProgressBar.BARTYPE.Normal;
|
|
ModuleSocBar[i].Direction = SmartX.SmartProgressBar.DIR.Vertical;
|
|
ModuleSocBar[i].Font = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Regular);
|
|
ModuleSocBar[i].InitVisible = true;
|
|
ModuleSocBar[i].Location = new System.Drawing.Point(248 + (i * 55), 123);
|
|
ModuleSocBar[i].Maximum = 100;
|
|
ModuleSocBar[i].Minimum = 0;
|
|
ModuleSocBar[i].Name = String.Format("ModuleSocBar_{0}", i + 1);
|
|
ModuleSocBar[i].OutlineColor = System.Drawing.Color.Black;
|
|
ModuleSocBar[i].PercentageText = false;
|
|
ModuleSocBar[i].RoundedCorners = true;
|
|
ModuleSocBar[i].Size = new System.Drawing.Size(48, 125);
|
|
ModuleSocBar[i].TabIndex = 129;
|
|
ModuleSocBar[i].Text = String.Format("ModuleSocBar_{0}", i + 1);
|
|
ModuleSocBar[i].TextAutoRotation = true;
|
|
ModuleSocBar[i].Value = 0;
|
|
}
|
|
|
|
Cursor.Hide();
|
|
}
|
|
#endregion
|
|
|
|
#region Control ReLoad
|
|
private void Control_Reload()
|
|
{
|
|
this.SuspendLayout();
|
|
this.Controls.Clear();
|
|
|
|
//this.Controls.Add(lbBlankRack);
|
|
//this.Controls.Add(lbBlankStatus);
|
|
this.Controls.Add(lbModelName);
|
|
this.Controls.Add(lbModelSpec);
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
if (MainWarning[i] != null)
|
|
this.Controls.Add(MainWarning[i]);
|
|
if (MainProtection[i] != null)
|
|
this.Controls.Add(MainProtection[i]);
|
|
}
|
|
|
|
for (int i = 0; i < SystemID.MAX_MODULE_SIZE; i++)
|
|
{
|
|
//this.Controls.Add(TrayVoltageValue[i]);
|
|
//this.Controls.Add(TrayCurrentValue[i]);
|
|
//this.Controls.Add(TraySOCValue[i]);
|
|
//this.Controls.Add(TrayTempValue[i]);
|
|
this.Controls.Add(ModuleAlarmBtn[i]);
|
|
this.Controls.Add(ModuleNo[i]);
|
|
}
|
|
|
|
for (int i = 0; i < SystemID.MAX_MODULE_SIZE; i++)
|
|
{
|
|
this.Controls.Add(ModuleSocBar[i]);
|
|
}
|
|
|
|
for (int i = 0; i < SystemID.MAX_MODULE_SIZE; i++)
|
|
{
|
|
this.Controls.Add(ModuleSocPicture[i]);
|
|
}
|
|
|
|
this.Controls.Add(this.lbMainTemp);
|
|
|
|
this.Controls.Add(this.btnMute);
|
|
this.Controls.Add(this.btnTrayInfo);
|
|
this.Controls.Add(this.btnHistory);
|
|
this.Controls.Add(this.btnSetting);
|
|
|
|
this.Controls.Add(this.lbW1);
|
|
this.Controls.Add(this.lbW2);
|
|
this.Controls.Add(this.lbP1);
|
|
this.Controls.Add(this.lbP2);
|
|
|
|
this.Controls.Add(this.lbMainSOC);
|
|
this.Controls.Add(this.lbCurrentDateTime);
|
|
this.Controls.Add(this.lbMainAlarmStatus);
|
|
this.Controls.Add(this.lbMainOpStatus);
|
|
this.Controls.Add(this.lbMainCurrent);
|
|
this.Controls.Add(this.lbMainVoltage);
|
|
this.Controls.Add(this.sfmMain);
|
|
|
|
this.ResumeLayout(false);
|
|
|
|
TrayData = new DeviceDataTray[SystemID.MAX_MODULE_SIZE];
|
|
disTrayData = new DeviceDataTray[SystemID.MAX_MODULE_SIZE];
|
|
|
|
for (int i = 0; i < SystemID.MAX_MODULE_SIZE; i++)
|
|
{
|
|
TrayData[i].CellVoltage = new short[SystemID.MAX_TRAY_CELL_SIZE];
|
|
TrayData[i].CellTemperature = new short[SystemID.MAX_TRAY_TEMP_SIZE];
|
|
disTrayData[i].CellVoltage = new short[SystemID.MAX_TRAY_CELL_SIZE];
|
|
disTrayData[i].CellTemperature = new short[SystemID.MAX_TRAY_TEMP_SIZE];
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public int GetModuleQuantity()
|
|
{
|
|
return BMSData.ModuleQuantity;
|
|
}
|
|
|
|
private void SetModuleQuantity()
|
|
{
|
|
if (bakModuleQuantity != BMSData.ModuleQuantity)
|
|
{
|
|
if (BMSData.ModuleQuantity < 10)
|
|
{
|
|
int NcModuleCount = 10 - BMSData.ModuleQuantity;
|
|
|
|
if (NcModuleCount <= 0)
|
|
{
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
ModuleNo[i].Text = String.Format("{0}", TrayName[i]);
|
|
ModuleAlarmBtn[i].BackPictureBox = sfmMain;
|
|
ModuleSocPicture[i].Image = pictureBox1.Image;
|
|
ModuleSocBar[i].Visible = true;
|
|
}
|
|
lbModelSpec.Text = String.Format("48V {0}Ah", 10 * 100);
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < NcModuleCount; i++)
|
|
{
|
|
ModuleNo[(10 - i - 1)].Text = "";
|
|
ModuleAlarmBtn[(10 - i - 1)].BackPictureBox = null;
|
|
ModuleSocNo[(10 - i - 1)].Text = "";
|
|
ModuleSocPicture[(10 - i - 1)].Image = pictureBox2.Image;
|
|
ModuleSocBar[(10 - i - 1)].Visible = false;
|
|
}
|
|
|
|
for (int i = 0; i < BMSData.ModuleQuantity; i++)
|
|
{
|
|
ModuleNo[i].Text = String.Format("{0}", TrayName[i]);
|
|
ModuleAlarmBtn[i].BackPictureBox = sfmMain;
|
|
ModuleSocNo[i].Text = "";
|
|
ModuleSocPicture[i].Image = pictureBox1.Image;
|
|
ModuleSocBar[i].Visible = true;
|
|
}
|
|
lbModelSpec.Text = String.Format("48V {0}Ah", BMSData.ModuleQuantity * 100);
|
|
}
|
|
}
|
|
bakModuleQuantity = BMSData.ModuleQuantity;
|
|
}
|
|
}
|
|
|
|
#region Main Form Load Event
|
|
private void fmBMSMain_Load(object sender, EventArgs e)
|
|
{
|
|
// Main폼에서 자신을 Main폼 임을 설정 합니다.
|
|
sfmMain.MainForm = this;
|
|
|
|
// Main폼에 자식 폼을 추가 합니다.
|
|
// 추가 순서대로 Index가 정해짐... Show(Index)에서 사용 됨
|
|
sfmMain.AddChildForm(chfTrayInfo); // 1
|
|
sfmMain.AddChildForm(chfHistory); // 2
|
|
sfmMain.AddChildForm(chfPassword); // 3
|
|
sfmMain.AddChildForm(chfParamSet); // 4
|
|
sfmMain.AddChildForm(chfParamSetCmd); // 5
|
|
sfmMain.AddChildForm(chfScreenSaver); // 6
|
|
sfmMain.AddChildForm(chfSetMenu); // 7
|
|
sfmMain.AddChildForm(chfNetConfig); // 8
|
|
sfmMain.AddChildForm(chfNetConfigCmd); // 9
|
|
sfmMain.AddChildForm(chfSystemSet); // 10
|
|
sfmMain.AddChildForm(chfSystemSetCmd); // 11
|
|
|
|
BMSMainDataInit();
|
|
|
|
// Main 폼 표시 Index가 %0이면 Main폼을 의미 합니다.
|
|
sfmMain.Show(ScreenID.MAIN_SCREEN_ID);
|
|
|
|
tmLedDisplay.Start();
|
|
tmHistory.Start();
|
|
tmrScreenSaver.Start();
|
|
tmrLog.Start();
|
|
|
|
mDisplayMainData(true);
|
|
mDisplayModuleSocData(true);
|
|
DisplayOpStatus(true);
|
|
DisplayAlarmStatus(true);
|
|
DisplayMainAlarmList(true);
|
|
CheckTrayLed(true);
|
|
|
|
if (BMSCommPortOpen())
|
|
{
|
|
sThrComm.Start();
|
|
sThrDisplay.Start();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Com port Open
|
|
private bool BMSCommPortOpen()
|
|
{
|
|
// Main 폼 표시 Index가 %0이면 Main폼을 의미 합니다.
|
|
//smartForm1.Show(1);
|
|
// 통신 속도 설정
|
|
sModBus.Buad_Rate = (SmartX.SmartModbus.BUADRATE)Convert.ToInt32(38400);
|
|
// 포트 번호 설정
|
|
sModBus.PortNo = (SmartX.SmartModbus.COMPORTNO)(2); // Com2
|
|
// Modbus Slave 주소
|
|
sModBus.SlaveAddress = Convert.ToInt32(1);
|
|
// 통신 패리티 설정
|
|
sModBus.Parity = System.IO.Ports.Parity.None;
|
|
// 스톱비트 설정
|
|
sModBus.StopBits = System.IO.Ports.StopBits.One;
|
|
// Modbos 프로토콜 설정 현재는 RTU방식만 지원됨
|
|
sModBus.ProtocolType = SmartX.SmartModbus.PROTOCOL.RTU;
|
|
// 수신 응답 타임아웃 설정
|
|
sModBus.ReadTimeout = 1000;
|
|
// 포트 열기
|
|
sModBus.PortOpen();
|
|
|
|
if (sModBus.IsOpen != true)
|
|
{
|
|
MessageBox.Show("Modbus Port Open Fail");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
#endregion
|
|
|
|
#region Change Screen Function
|
|
public void ChangeScreen(int Order, int Req, int Mode)
|
|
{
|
|
ScreenSaverTimeReset();
|
|
|
|
if (Mode == ScreenID.PASSWORD_SCREEN_ID)
|
|
{
|
|
chfPassword.order_screen_no = Order;
|
|
chfPassword.req_screen_no = Req;
|
|
}
|
|
ScreenMode = Mode;
|
|
|
|
sfmMain.Show(Mode);
|
|
}
|
|
#endregion
|
|
|
|
#region Display Function
|
|
void mDisplayMain(bool p)
|
|
{
|
|
mDisplayMainData(p);
|
|
mDisplayModuleSocData(p);
|
|
DisplayMainAlarmList(p);
|
|
DisplayOpStatus(p);
|
|
DisplayAlarmStatus(p);
|
|
CheckTrayLed(p);
|
|
}
|
|
#endregion
|
|
|
|
#region Display Main Data
|
|
private void mDisplayMainData(bool p)
|
|
{
|
|
if (p || (disBMSData.BatVoltage != BMSData.BatVoltage))
|
|
{
|
|
lbMainVoltage.Text = String.Format("{0:#0.0}", Convert.ToDouble(BMSData.BatVoltage) / 100);
|
|
disBMSData.BatVoltage = BMSData.BatVoltage;
|
|
}
|
|
if (p || (disBMSData.Current != BMSData.Current))
|
|
{
|
|
lbMainCurrent.Text = String.Format("{0:#0.0}", Convert.ToDouble(BMSData.Current) / 10);
|
|
disBMSData.Current = BMSData.Current;
|
|
}
|
|
//if (p || (disBMSData.RelativeStateOfCharge != BMSData.RelativeStateOfCharge))
|
|
//{
|
|
lbMainSOC.Text = String.Format("{0:#0}", Convert.ToDouble(BMSData.RelativeStateOfCharge) / 10);
|
|
disBMSData.RelativeStateOfCharge = BMSData.RelativeStateOfCharge;
|
|
//}
|
|
|
|
if (p || (disBMSData.MaxTemp != BMSData.MaxTemp))
|
|
{
|
|
lbMainTemp.Text = String.Format("{0:#0.0}", Convert.ToDouble(BMSData.MaxTemp) / 10);
|
|
disBMSData.MaxTemp = BMSData.MaxTemp;
|
|
}
|
|
|
|
//for (int i = 0; i < SystemID.MAX_TRAY_SIZE; i++)
|
|
//{
|
|
// if (p || (disTrayData[i].BatVoltage != TrayData[i].BatVoltage))
|
|
// {
|
|
// TrayVoltageValue[i].Text = String.Format("{0:#0.0}", Convert.ToDouble(TrayData[i].BatVoltage) / 100);
|
|
|
|
// disTrayData[i].BatVoltage = TrayData[i].BatVoltage;
|
|
// }
|
|
// if (p || (disTrayData[i].Current != TrayData[i].Current))
|
|
// {
|
|
// TrayCurrentValue[i].Text = String.Format("{0:#0.0}", Convert.ToDouble(TrayData[i].Current) / 10);
|
|
|
|
// disTrayData[i].Current = TrayData[i].Current;
|
|
// }
|
|
// if (p || (disTrayData[i].RelativeStateOfCharge != TrayData[i].RelativeStateOfCharge))
|
|
// {
|
|
// TraySOCValue[i].Text = String.Format("{0:#0}", Convert.ToDouble(TrayData[i].RelativeStateOfCharge) / 10);
|
|
|
|
// disTrayData[i].RelativeStateOfCharge = TrayData[i].RelativeStateOfCharge;
|
|
// }
|
|
// if (p || (disTrayData[i].MaxTemp != TrayData[i].MaxTemp))
|
|
// {
|
|
// TrayTempValue[i].Text = String.Format("{0:#0.0}", Convert.ToDouble(TrayData[i].MaxTemp) / 10);
|
|
|
|
// disTrayData[i].MaxTemp = TrayData[i].MaxTemp;
|
|
// }
|
|
//}
|
|
}
|
|
#endregion
|
|
|
|
#region DISPLAY MODULE SOC
|
|
private void mDisplayModuleSocData(bool p)
|
|
{
|
|
for (int i = 0; i < BMSData.ModuleQuantity; i++)
|
|
{
|
|
if ((disTrayData[i].RelativeStateOfCharge != TrayData[i].RelativeStateOfCharge)
|
|
|| (disTrayData[i].AlarmStatus != TrayData[i].AlarmStatus))
|
|
{
|
|
if (TrayData[i].AlarmStatus == 2) // Protection
|
|
ModuleSocBar[i].BarColor1 = System.Drawing.Color.Red;
|
|
else if (TrayData[i].AlarmStatus == 1)
|
|
ModuleSocBar[i].BarColor1 = System.Drawing.Color.Yellow;
|
|
else
|
|
ModuleSocBar[i].BarColor1 = System.Drawing.Color.Green;
|
|
|
|
ModuleSocBar[i].Value = TrayData[i].RelativeStateOfCharge / 10;
|
|
|
|
disTrayData[i].RelativeStateOfCharge = TrayData[i].RelativeStateOfCharge;
|
|
disTrayData[i].AlarmStatus = TrayData[i].AlarmStatus;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Display Main Alarm
|
|
public void DisplayMainAlarmList(bool p)
|
|
{
|
|
int i = 0;
|
|
|
|
if (p || (disBMSData.Warning != BMSData.Warning))
|
|
{
|
|
// System Over Voltage Warning
|
|
i = 0;
|
|
if (ConvertTo.GetBit(BMSData.Warning, i) == true)
|
|
MainWarning[i].Image = pbMAlarmWarningA.Image;
|
|
else
|
|
MainWarning[i].Image = pbMAlarmNormalA.Image;
|
|
|
|
// Cell Over Voltage Warning
|
|
i = 1;
|
|
if (ConvertTo.GetBit(BMSData.Warning, i) == true)
|
|
MainWarning[i].Image = pbMAlarmWarningB.Image;
|
|
else
|
|
MainWarning[i].Image = pbMAlarmNormalB.Image;
|
|
|
|
// System Under Voltage Warning
|
|
i = 2;
|
|
if (ConvertTo.GetBit(BMSData.Warning, i) == true)
|
|
MainWarning[i].Image = pbMAlarmWarningA.Image;
|
|
else
|
|
MainWarning[i].Image = pbMAlarmNormalA.Image;
|
|
|
|
// Cell Under Voltage Warning
|
|
i = 3;
|
|
if (ConvertTo.GetBit(BMSData.Warning, i) == true)
|
|
MainWarning[i].Image = pbMAlarmWarningB.Image;
|
|
else
|
|
MainWarning[i].Image = pbMAlarmNormalB.Image;
|
|
|
|
// Charge Over Current Warning
|
|
i = 4;
|
|
if (ConvertTo.GetBit(BMSData.Warning, i) == true)
|
|
MainWarning[i].Image = pbMAlarmWarningA.Image;
|
|
else
|
|
MainWarning[i].Image = pbMAlarmNormalA.Image;
|
|
|
|
// Discharge Over Current Warning
|
|
i = 5;
|
|
if (ConvertTo.GetBit(BMSData.Warning, i) == true)
|
|
MainWarning[i].Image = pbMAlarmWarningA.Image;
|
|
else
|
|
MainWarning[i].Image = pbMAlarmNormalA.Image;
|
|
|
|
// Charge or Discharge High Temperature Warning
|
|
i = 6;
|
|
if ((ConvertTo.GetBit(BMSData.Warning, 8) == true) ||
|
|
(ConvertTo.GetBit(BMSData.Warning, 9) == true))
|
|
MainWarning[i].Image = pbMAlarmWarningB.Image;
|
|
else
|
|
MainWarning[i].Image = pbMAlarmNormalB.Image;
|
|
|
|
// Charge or Discharge Low Temperature Warning
|
|
i = 7;
|
|
if ((ConvertTo.GetBit(BMSData.Warning, 10) == true) ||
|
|
(ConvertTo.GetBit(BMSData.Warning, 11) == true))
|
|
MainWarning[i].Image = pbMAlarmWarningA.Image;
|
|
else
|
|
MainWarning[i].Image = pbMAlarmNormalA.Image;
|
|
|
|
// Charge or Discharge High Temperature Warning
|
|
i = 8;
|
|
if (ConvertTo.GetBit(BMSData.Warning, 12) == true)
|
|
MainWarning[i].Image = pbMAlarmWarningB.Image;
|
|
else
|
|
MainWarning[i].Image = pbMAlarmNormalB.Image;
|
|
|
|
disBMSData.Warning = BMSData.Warning;
|
|
}
|
|
|
|
if (p || (disBMSData.Protection != BMSData.Protection))
|
|
{
|
|
// System Over Voltage Protection
|
|
i = 0;
|
|
if (ConvertTo.GetBit(BMSData.Protection, i) == true)
|
|
MainProtection[i].Image = pbMAlarmProtectA.Image;
|
|
else
|
|
MainProtection[i].Image = pbMAlarmNormalA.Image;
|
|
|
|
// Cell Over Voltage Protection
|
|
i = 1;
|
|
if (ConvertTo.GetBit(BMSData.Protection, i) == true)
|
|
MainProtection[i].Image = pbMAlarmProtectB.Image;
|
|
else
|
|
MainProtection[i].Image = pbMAlarmNormalB.Image;
|
|
|
|
// Charge Over Current Protection
|
|
i = 4;
|
|
if (ConvertTo.GetBit(BMSData.Protection, i) == true)
|
|
MainProtection[i].Image = pbMAlarmProtectA.Image;
|
|
else
|
|
MainProtection[i].Image = pbMAlarmNormalA.Image;
|
|
|
|
// Charge or Discharge High Temperature Protection
|
|
i = 6;
|
|
if ((ConvertTo.GetBit(BMSData.Protection, 8) == true) ||
|
|
(ConvertTo.GetBit(BMSData.Protection, 9) == true))
|
|
MainProtection[i].Image = pbMAlarmProtectB.Image;
|
|
else
|
|
MainProtection[i].Image = pbMAlarmNormalB.Image;
|
|
|
|
// Charge or Discharge Low Temperature Protection
|
|
i = 7;
|
|
if ((ConvertTo.GetBit(BMSData.Protection, 10) == true) ||
|
|
(ConvertTo.GetBit(BMSData.Protection, 11) == true))
|
|
MainProtection[i].Image = pbMAlarmProtectA.Image;
|
|
else
|
|
MainProtection[i].Image = pbMAlarmNormalA.Image;
|
|
|
|
disBMSData.Protection = BMSData.Protection;
|
|
}
|
|
// CommState
|
|
if (p || (disBMSData.TrayCommState != BMSData.TrayCommState)||
|
|
(disBMSData.MainCommState != BMSData.MainCommState))
|
|
{
|
|
// Tray CommFail Warning
|
|
if ((BMSData.TrayCommState != 0)||
|
|
(BMSData.MainCommState != 0))
|
|
MainWarning[9].Image = pbMAlarmWarningA.Image;
|
|
else
|
|
MainWarning[9].Image = pbMAlarmNormalA.Image;
|
|
|
|
disBMSData.TrayCommState = BMSData.TrayCommState;
|
|
disBMSData.MainCommState = BMSData.MainCommState;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Display Status and Alarm
|
|
private void DisplayOpStatus(bool p)
|
|
{
|
|
if (p || (BMSData.OpStatus != disBMSData.OpStatus))
|
|
{
|
|
switch (BMSData.OpStatus)
|
|
{
|
|
case 0: // 대기중
|
|
lbMainOpStatus.Text = "STAND BY";
|
|
lbMainOpStatus.ForeColor = System.Drawing.Color.Black;
|
|
break;
|
|
case 1: // 충전중
|
|
lbMainOpStatus.Text = "CHARGING";
|
|
lbMainOpStatus.ForeColor = System.Drawing.Color.Blue;
|
|
break;
|
|
case 2: // 방전중
|
|
lbMainOpStatus.Text = "DISCHARGING";
|
|
lbMainOpStatus.ForeColor = System.Drawing.Color.Magenta;
|
|
break;
|
|
case 3:
|
|
lbMainOpStatus.Text = "FLOATING";
|
|
lbMainOpStatus.ForeColor = System.Drawing.Color.Black;
|
|
break;
|
|
}
|
|
disBMSData.OpStatus = BMSData.OpStatus;
|
|
}
|
|
}
|
|
|
|
private void DisplayAlarmStatus(bool p)
|
|
{
|
|
if (p || (disBMSData.AlarmStatus != BMSData.AlarmStatus))
|
|
{
|
|
switch (BMSData.AlarmStatus)
|
|
{
|
|
case 0: // 정상
|
|
lbMainAlarmStatus.Text = "NORMAL";
|
|
lbMainAlarmStatus.ForeColor = System.Drawing.Color.Black;
|
|
break;
|
|
case 1: // Warning
|
|
lbMainAlarmStatus.Text = "WARNING";
|
|
lbMainAlarmStatus.ForeColor = System.Drawing.Color.Orange;
|
|
break;
|
|
case 2: // Protected
|
|
lbMainAlarmStatus.Text = "TRIP";
|
|
lbMainAlarmStatus.ForeColor = System.Drawing.Color.Red;
|
|
break;
|
|
}
|
|
disBMSData.AlarmStatus = BMSData.AlarmStatus;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region UI Thread for Display
|
|
private void sThrDisplay_UIThreadFunction(SmartX.ThreadArgs args)
|
|
{
|
|
// Display Thread
|
|
DateTime cTime;
|
|
|
|
cTime = DateTime.Now;
|
|
|
|
//if (disTime != cTime)
|
|
//{
|
|
lbCurrentDateTime.Text = cTime.ToString("yyyy/MM/dd HH:mm:ss");
|
|
disTime = cTime;
|
|
//}
|
|
|
|
//CheckOpStatus();
|
|
|
|
mDisplayMain(false);
|
|
|
|
SetModuleQuantity();
|
|
|
|
Thread.Sleep(10);
|
|
}
|
|
#endregion
|
|
|
|
private void sThrComm_OnEnding(SmartX.ThreadArgs args)
|
|
{
|
|
sModBus.PortClose();
|
|
}
|
|
|
|
#region CHECK OP STATUS AND ALARM
|
|
private short CheckOpStatusExt()
|
|
{
|
|
short result = 0;
|
|
|
|
if (BMSData.Current > 200)
|
|
result = 1;
|
|
else if (BMSData.Current < -200)
|
|
result = 2;
|
|
else
|
|
result = 0;
|
|
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region Check Tray Led
|
|
private void CheckTrayLed(bool p)
|
|
{
|
|
bool LedFlag = false;
|
|
|
|
for (int i = 0; i < BMSData.ModuleQuantity; i++)
|
|
{
|
|
if (p || (disTrayData[i].Protection != TrayData[i].Protection) ||
|
|
(disTrayData[i].Warning != TrayData[i].Warning))
|
|
{
|
|
if (TrayData[i].Protection != 0)
|
|
{
|
|
TrayStatus[i] = 2;
|
|
}
|
|
else if (TrayData[i].Warning != 0)
|
|
{
|
|
TrayStatus[i] = 1;
|
|
}
|
|
else
|
|
{
|
|
TrayStatus[i] = 0;
|
|
}
|
|
}
|
|
disTrayData[i].Protection = TrayData[i].Protection;
|
|
disTrayData[i].Warning = TrayData[i].Warning;
|
|
|
|
if (TrayData[i].Protection != 0) LedFlag = true;
|
|
if (TrayData[i].Warning != 0) LedFlag = true;
|
|
}
|
|
|
|
if (LedFlag)
|
|
{
|
|
tmLedDisplay.Start();
|
|
}
|
|
else
|
|
{
|
|
tmLedDisplay.Stop();
|
|
for (int i = 0; i < BMSData.ModuleQuantity; i++)
|
|
{
|
|
ModuleAlarmBtn[i].BackPictureBox = this.sfmMain;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Form Close Event
|
|
private void fmBMSMain_Closing(object sender, CancelEventArgs e)
|
|
{
|
|
// SmartThread 의상태가 Stopped이 아니라면
|
|
if (sThrComm.State != SmartX.SmartThread.ThreadState.Stopped)
|
|
{
|
|
// WorkThread를 종료
|
|
sThrComm.End();
|
|
}
|
|
|
|
// SmartThread 의상태가 Stopped이 아니라면
|
|
if (sThrDisplay.State != SmartX.SmartThread.ThreadState.Stopped)
|
|
{
|
|
// UIThread를 종료
|
|
sThrDisplay.End();
|
|
}
|
|
|
|
if (sModBus.IsOpen)
|
|
sModBus.PortClose();
|
|
|
|
// SmartTimer1을 중지
|
|
tmLedDisplay.Stop();
|
|
}
|
|
#endregion
|
|
|
|
#region Button Click Event
|
|
private void TrayLabel_Click(object sender, EventArgs e)
|
|
{
|
|
int i = ((SmartX.SmartLabel)(sender)).TabIndex;
|
|
|
|
if (i < BMSData.ModuleQuantity)
|
|
{
|
|
chfTrayInfo.CurrentTrayNo = i;
|
|
ChangeScreen(0, 0, ScreenID.TRAY_SCREEN_ID);
|
|
}
|
|
}
|
|
|
|
private void btnMute_Click(object sender, EventArgs e)
|
|
{
|
|
ScreenSaverTimeReset();
|
|
ModbusTxFlag = 1;
|
|
}
|
|
|
|
private void DoOperation(string oparation)
|
|
{
|
|
string filename = string.Empty;
|
|
string arguments = string.Empty;
|
|
switch (oparation)
|
|
{
|
|
case "Shut Down":
|
|
filename = "shutdown.exe";
|
|
arguments = "-s";
|
|
break;
|
|
case "Restart":
|
|
filename = "shutdown.exe";
|
|
arguments = "-r";
|
|
break;
|
|
case "Logoff":
|
|
filename = "shutdown.exe";
|
|
arguments = "-l";
|
|
break;
|
|
case "Lock":
|
|
filename = "Rundll32.exe";
|
|
arguments = "User32.dll, LockWorkStation";
|
|
break;
|
|
case "Hibernation":
|
|
filename = @"%windir%\system32\rundll32.exe";
|
|
arguments = "PowrProf.dll, SetSuspendState";
|
|
break;
|
|
case "Sleep":
|
|
filename = "Rundll32.exe";
|
|
arguments = "powrprof.dll, SetSuspendState 0,1,0";
|
|
break;
|
|
}
|
|
ProcessStartInfo startinfo = new ProcessStartInfo(filename, arguments);
|
|
Process.Start(startinfo);
|
|
this.Close();
|
|
}
|
|
|
|
|
|
private void btnTrayInfo_Click(object sender, EventArgs e)
|
|
{
|
|
chfTrayInfo.CurrentTrayNo = 0;
|
|
ChangeScreen(0, 0, ScreenID.TRAY_SCREEN_ID);
|
|
}
|
|
|
|
private void btnHistory_Click(object sender, EventArgs e)
|
|
{
|
|
ChangeScreen(0, 0, ScreenID.HISTORY_SCREEN_ID);
|
|
}
|
|
|
|
private void btnSetting_Click(object sender, EventArgs e)
|
|
{
|
|
ChangeScreen(ScreenID.MAIN_SCREEN_ID, ScreenID.SET_MENU_SCREEN_ID, ScreenID.PASSWORD_SCREEN_ID);
|
|
}
|
|
#endregion
|
|
|
|
#region TIMER LED EVENT
|
|
private void tmLedDisplay_Tick(object sender, EventArgs e)
|
|
{
|
|
for (int i = 0; i < BMSData.ModuleQuantity; i++)
|
|
{
|
|
if (TrayStatus[i] == 2)
|
|
{
|
|
if (ledflag)
|
|
{
|
|
ModuleAlarmBtn[i].BackColor = System.Drawing.Color.Red;
|
|
ModuleAlarmBtn[i].BackPictureBox = null;
|
|
}
|
|
else
|
|
{
|
|
ModuleAlarmBtn[i].BackPictureBox = this.sfmMain;
|
|
}
|
|
}
|
|
else if (TrayStatus[i] == 1)
|
|
{
|
|
if (ledflag)
|
|
{
|
|
ModuleAlarmBtn[i].BackColor = System.Drawing.Color.Yellow;
|
|
ModuleAlarmBtn[i].BackPictureBox = null;
|
|
}
|
|
else
|
|
{
|
|
ModuleAlarmBtn[i].BackPictureBox = this.sfmMain;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ModuleAlarmBtn[i].BackPictureBox = this.sfmMain;
|
|
}
|
|
}
|
|
ledflag = !ledflag;
|
|
}
|
|
#endregion
|
|
|
|
#region BMS STAUS REQUEST AND RESPNSE
|
|
private void BmsStatusRequest()
|
|
{
|
|
// Communication Thread
|
|
SmartX.SmartModbus.EXCEPTIONCODE retStatus;
|
|
|
|
// Modbus Slave 주소
|
|
sModBus.SlaveAddress = Convert.ToInt32(1);
|
|
|
|
if (mbReqAddress == 0)
|
|
{
|
|
mbReqAddress = 100;
|
|
mbDataCount = 100;
|
|
SetTime(1);
|
|
}
|
|
else if (mbReqAddress == 100) //
|
|
{
|
|
mbReqAddress = 0x1000; // Module #1
|
|
mbDataCount = 102;
|
|
}
|
|
else if (mbReqAddress == 0x1000)
|
|
{
|
|
mbReqAddress = 0x2000; // Module #2
|
|
mbDataCount = 102;
|
|
}
|
|
else if (mbReqAddress == 0x2000)
|
|
{
|
|
mbReqAddress = 0x3000; // Module #3
|
|
mbDataCount = 102;
|
|
}
|
|
else if (mbReqAddress == 0x3000)
|
|
{
|
|
mbReqAddress = 0x4000; // Module #4
|
|
mbDataCount = 102;
|
|
}
|
|
else if (mbReqAddress == 0x4000)
|
|
{
|
|
mbReqAddress = 0x5000; // Module #5
|
|
mbDataCount = 102;
|
|
}
|
|
else if (mbReqAddress == 0x5000)
|
|
{
|
|
mbReqAddress = 0x6000; // Module #6
|
|
mbDataCount = 102;
|
|
}
|
|
else if (mbReqAddress == 0x6000)
|
|
{
|
|
mbReqAddress = 0x7000; // Module #7
|
|
mbDataCount = 102;
|
|
}
|
|
else if (mbReqAddress == 0x7000)
|
|
{
|
|
mbReqAddress = 0x8000; // Module #8
|
|
mbDataCount = 102;
|
|
}
|
|
else if (mbReqAddress == 0x8000)
|
|
{
|
|
mbReqAddress = 0x9000; // Module #9
|
|
mbDataCount = 102;
|
|
}
|
|
else if (mbReqAddress == 0x9000)
|
|
{
|
|
mbReqAddress = 0xA000; // Module #10
|
|
mbDataCount = 102;
|
|
}
|
|
else
|
|
{
|
|
mbReqAddress = 0;
|
|
mbDataCount = 100;
|
|
}
|
|
|
|
// 읽어올 데이터 할당
|
|
byte[] ReadData = new byte[mbDataCount * 2];
|
|
|
|
// Function code 3(0x03) = Read Holding Register의 기능을 수행 합니다.
|
|
retStatus = sModBus.ReadHoldingRegister(mbReqAddress, mbDataCount, ref ReadData);
|
|
|
|
if (retStatus == SmartX.SmartModbus.EXCEPTIONCODE.SUCCESS)
|
|
{
|
|
switch (mbReqAddress)
|
|
{
|
|
case 0x0000:
|
|
BMSData = csModbusDataProcess.ModBusSystemData_Reg(BMSData, 0, ReadData, mbDataCount);
|
|
if (BMSData.HistoryDelete == 1)
|
|
{
|
|
BmsAlarmFile.DeleteAlarmData();
|
|
BMSData.HistoryDelete = 0;
|
|
}
|
|
break;
|
|
case 100:
|
|
BMSData = csModbusDataProcess.ModBusSystemData_Reg(BMSData, 100, ReadData, mbDataCount);
|
|
break;
|
|
case 0x1000: // Module #1
|
|
TrayData[0] = csModbusDataProcess.ModBusData_Reg(0, ReadData, mbDataCount);
|
|
break;
|
|
case 0x2000: // Module #2
|
|
TrayData[1] = csModbusDataProcess.ModBusData_Reg(0, ReadData, mbDataCount);
|
|
break;
|
|
case 0x3000: // Module #3
|
|
TrayData[2] = csModbusDataProcess.ModBusData_Reg(0, ReadData, mbDataCount);
|
|
break;
|
|
case 0x4000: // Module #4
|
|
TrayData[3] = csModbusDataProcess.ModBusData_Reg(0, ReadData, mbDataCount);
|
|
break;
|
|
case 0x5000: // Module #5
|
|
TrayData[4] = csModbusDataProcess.ModBusData_Reg(0, ReadData, mbDataCount);
|
|
break;
|
|
case 0x6000: // Module #6
|
|
TrayData[5] = csModbusDataProcess.ModBusData_Reg(0, ReadData, mbDataCount);
|
|
break;
|
|
case 0x7000: // Module #7
|
|
TrayData[6] = csModbusDataProcess.ModBusData_Reg(0, ReadData, mbDataCount);
|
|
break;
|
|
case 0x8000: // Module #8
|
|
TrayData[7] = csModbusDataProcess.ModBusData_Reg(0, ReadData, mbDataCount);
|
|
break;
|
|
case 0x9000: // Module #9
|
|
TrayData[8] = csModbusDataProcess.ModBusData_Reg(0, ReadData, mbDataCount);
|
|
break;
|
|
case 0xA000: // Module #10
|
|
TrayData[9] = csModbusDataProcess.ModBusData_Reg(0, ReadData, mbDataCount);
|
|
break;
|
|
}
|
|
ModbusTimeoutCount = 0;
|
|
BMSData.MainCommState = 0;
|
|
}
|
|
else
|
|
{
|
|
ModbusTimeoutCount++;
|
|
if (ModbusTimeoutCount > 10)
|
|
{
|
|
BMSData.MainCommState = 1;
|
|
ModbusTimeoutCount = 20;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public void SetTime(byte dev_addr)
|
|
{
|
|
DateTime tDateTime = new DateTime();
|
|
short[] dDateTime;
|
|
|
|
tDateTime = DateTime.Now;
|
|
dDateTime = new short[6];
|
|
|
|
dDateTime[0] = (short)tDateTime.Year;
|
|
dDateTime[1] = (short)tDateTime.Month;
|
|
dDateTime[2] = (short)tDateTime.Day;
|
|
dDateTime[3] = (short)tDateTime.Hour;
|
|
dDateTime[4] = (short)tDateTime.Minute;
|
|
dDateTime[5] = (short)tDateTime.Second;
|
|
|
|
SetModBusWriteCmd(dev_addr, Convert.ToInt16(200), 6, dDateTime, Convert.ToInt16(200));
|
|
}
|
|
|
|
public void SetModBusWriteCmd(byte dev_addr, short reg_addr, short reg_count, short[] reg_data, short cmd)
|
|
{
|
|
SetParamCmd.Device_Addr = dev_addr;
|
|
SetParamCmd.Reg_Addr = reg_addr;
|
|
SetParamCmd.Reg_Size = reg_count;
|
|
SetParamCmd.Set_Commad = cmd;
|
|
SetParamCmd.Set_Result = 1;
|
|
|
|
SetParamCmd.Reg_data = ConvertTo.ShortToByteArray(reg_data, true);
|
|
}
|
|
|
|
public short GetModbusWriteResult()
|
|
{
|
|
return SetParamCmd.Set_Result;
|
|
}
|
|
|
|
private bool CheckWriteData()
|
|
{
|
|
if (SetParamCmd.Set_Commad != 0)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
// 쓰기관련 Modbus Function Send 처리
|
|
private void BuzzerMuteRequest()
|
|
{
|
|
SmartX.SmartModbus.EXCEPTIONCODE retStatus = SmartX.SmartModbus.EXCEPTIONCODE.SLAVEADDRESS_ERROR;
|
|
int iStartAddress, iDataCnt;
|
|
|
|
// Modbus Slave 주소
|
|
sModBus.SlaveAddress = Convert.ToInt32(1);
|
|
|
|
// 시작 주소 얻기
|
|
iStartAddress = Convert.ToInt32(0x4000);
|
|
// 데이터 개수 얻기
|
|
iDataCnt = Convert.ToInt32(1);
|
|
|
|
// 쓰기 데이터는 하나의 바이트 데이터를 스페이스로 구분하여 입력 합니다.
|
|
// 따라서 입력 텍스트에서 스페이스(공백)을 기준으로 하나의 바이트 데이터로 처리 함
|
|
byte[] writeDatas = new byte[2];
|
|
|
|
// 문자열로 입력된 각각의 항목을 바이트의 수치형으로 변환처리(문자열은 수치화)
|
|
// "33 12 100 201 37 79 88 125" -> 33 12 100 201 37 79 88 125
|
|
writeDatas[0] = 0;
|
|
writeDatas[1] = 1;
|
|
|
|
// Function code 16(0x10)=Write Multiple Register의 기능을 수행 합니다.
|
|
retStatus = sModBus.WriteMultipleRegister(iStartAddress, iDataCnt, writeDatas);
|
|
|
|
// 쓰기명령이 성공했는지 확인
|
|
if (retStatus == SmartX.SmartModbus.EXCEPTIONCODE.SUCCESS)
|
|
{
|
|
ModbusTxFlag = 0;
|
|
}
|
|
}
|
|
|
|
// 쓰기관련 Modbus Function Send 처리
|
|
private void ModBusWriteData()
|
|
{
|
|
SmartX.SmartModbus.EXCEPTIONCODE retStatus = SmartX.SmartModbus.EXCEPTIONCODE.SLAVEADDRESS_ERROR;
|
|
int iStartAddress, iDataCnt;
|
|
|
|
// Modbus Slave 주소
|
|
sModBus.SlaveAddress = Convert.ToInt32(SetParamCmd.Device_Addr);
|
|
|
|
// 시작 주소 얻기
|
|
iStartAddress = Convert.ToInt32(SetParamCmd.Reg_Addr);
|
|
// 데이터 개수 얻기
|
|
iDataCnt = Convert.ToInt32(SetParamCmd.Reg_Size);
|
|
|
|
// Function code 16(0x10)=Write Multiple Register의 기능을 수행 합니다.
|
|
retStatus = sModBus.WriteMultipleRegister(iStartAddress, iDataCnt, SetParamCmd.Reg_data);
|
|
|
|
// 쓰기명령이 성공했는지 확인
|
|
if (retStatus == SmartX.SmartModbus.EXCEPTIONCODE.SUCCESS)
|
|
{
|
|
ModbusTxFlag = 0;
|
|
}
|
|
SetParamCmd.Set_Commad = 0;
|
|
}
|
|
|
|
private void sThrComm_ThreadFunction(SmartX.ThreadArgs args)
|
|
{
|
|
if (ModbusTxFlag == 0)
|
|
{
|
|
if (CheckWriteData())
|
|
ModBusWriteData();
|
|
else
|
|
BmsStatusRequest();
|
|
}
|
|
else if (ModbusTxFlag == 1)
|
|
{
|
|
BuzzerMuteRequest();
|
|
ModbusTxFlag = 0;
|
|
}
|
|
Thread.Sleep(10);
|
|
}
|
|
|
|
private void smartLabel2_Click(object sender, EventArgs e)
|
|
{
|
|
//if (File.Exists(AlarmFile.AlarmFilePath))
|
|
//{
|
|
// File.Delete(AlarmFile.AlarmFilePath);
|
|
//}
|
|
AlarmFile af = new AlarmFile();
|
|
af.CreateDatabase();
|
|
}
|
|
|
|
private void tmHistory_Tick(object sender, EventArgs e)
|
|
{
|
|
BmsAlarmFile.CheckAlarmHistory(BMSData);
|
|
for (int i = 0; i < BMSData.ModuleQuantity; i++)
|
|
{
|
|
BmsAlarmFile.CheckAlarmHistory(TrayData[i], i);
|
|
}
|
|
}
|
|
|
|
public void ScreenSaverTimeReset()
|
|
{
|
|
ScreenSaveTime = 0;
|
|
}
|
|
|
|
#region TIMER EVENT
|
|
private void tmrScreenSaver_Tick(object sender, EventArgs e)
|
|
{
|
|
ScreenSaveTime++;
|
|
|
|
if (ScreenSaveTime > 60)
|
|
{
|
|
if ((BMSData.AlarmStatus != 0)
|
|
|| (BMSData.MainCommState != 0)
|
|
|| (BMSData.TrayCommState != 0)
|
|
|| (BMSData.OpStatus == 1)
|
|
|| (BMSData.OpStatus == 2))
|
|
{
|
|
if (ScreenMode != ScreenID.MAIN_SCREEN_ID)
|
|
ChangeScreen(0, 0, ScreenID.MAIN_SCREEN_ID);
|
|
ScreenSaveTime = 0;
|
|
}
|
|
else
|
|
{
|
|
ChangeScreen(0, 0, ScreenID.SCREEN_SAVER_SCREEN_ID);
|
|
ScreenSaveTime = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void tmrLog_Tick(object sender, EventArgs e)
|
|
{
|
|
DateTime aa = DateTime.Now;
|
|
string a, b;
|
|
int logtime, logmm, logss;
|
|
|
|
if (chfParamSet.GetLogFlag())
|
|
{
|
|
logtime = chfParamSet.GetLogTime();
|
|
a = aa.ToString("mm");
|
|
b = aa.ToString("ss");
|
|
logmm = Convert.ToInt32(a);
|
|
logss = Convert.ToInt32(b);
|
|
|
|
if (logtime == 60)
|
|
{
|
|
if (bakTimeMin != logmm)
|
|
{
|
|
BmsAlarmFile.LoggingData(BMSData, TrayData);
|
|
//BmsAlarmFile.LoggingData(BMSData, TrayData[0], TrayData[1]);
|
|
bakTimeMin = logmm;
|
|
bakTimeSec = logss;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ((bakTimeSec != logss) && ((logss % logtime) == 0))
|
|
{
|
|
BmsAlarmFile.LoggingData(BMSData, TrayData);
|
|
//BmsAlarmFile.LoggingData(BMSData, TrayData[0], TrayData[1]);
|
|
bakTimeMin = logmm;
|
|
bakTimeSec = logss;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region GET BMS DATA FUNCTION
|
|
|
|
public DeviceDataSystem GetBmsSystemData()
|
|
{
|
|
return BMSData;
|
|
}
|
|
|
|
public DeviceNetConfig GetNetConfigData()
|
|
{
|
|
return BMSData.netconfig;
|
|
}
|
|
|
|
public DeviceDataTray GetTrayData(int tno)
|
|
{
|
|
return TrayData[tno];
|
|
}
|
|
|
|
#endregion
|
|
|
|
private void lbCurrentDateTime_Click(object sender, EventArgs e)
|
|
{
|
|
// Initialize Password
|
|
InitPassCount++;
|
|
InitPassTimeCount = 0;
|
|
if (InitPassCount >= 5)
|
|
{
|
|
BmsAlarmFile.InitPasswordData();
|
|
lbCurrentDateTime.Text = "Initialized password !!";
|
|
this.Update();
|
|
System.Threading.Thread.Sleep(1000);
|
|
}
|
|
}
|
|
|
|
private void tmrInitPass_Tick(object sender, EventArgs e)
|
|
{
|
|
if (InitPassCount > 0)
|
|
{
|
|
InitPassTimeCount++;
|
|
if (InitPassTimeCount > 20)
|
|
{
|
|
InitPassCount = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
#region APPLICATION EXIT
|
|
public void ApplicationExit()
|
|
{
|
|
sThrComm.End();
|
|
sThrComm.Dispose();
|
|
|
|
sThrDisplay.End();
|
|
sThrDisplay.Dispose();
|
|
|
|
sModBus.PortClose();
|
|
sModBus.Dispose();
|
|
|
|
Process.Start("explorer.exe", "\\Flash Disk\\Run\\");
|
|
|
|
Application.Exit();
|
|
}
|
|
#endregion
|
|
|
|
private void fmBMSMain_Activated(object sender, EventArgs e)
|
|
{
|
|
this.SuspendLayout();
|
|
this.Controls.Clear();
|
|
|
|
//this.Controls.Add(lbBlankRack);
|
|
//this.Controls.Add(lbBlankStatus);
|
|
this.Controls.Add(lbModelName);
|
|
this.Controls.Add(lbModelSpec);
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
if (MainWarning[i] != null)
|
|
this.Controls.Add(MainWarning[i]);
|
|
if (MainProtection[i] != null)
|
|
this.Controls.Add(MainProtection[i]);
|
|
}
|
|
|
|
for (int i = 0; i < SystemID.MAX_MODULE_SIZE; i++)
|
|
{
|
|
//this.Controls.Add(TrayVoltageValue[i]);
|
|
//this.Controls.Add(TrayCurrentValue[i]);
|
|
//this.Controls.Add(TraySOCValue[i]);
|
|
//this.Controls.Add(TrayTempValue[i]);
|
|
this.Controls.Add(ModuleAlarmBtn[i]);
|
|
this.Controls.Add(ModuleNo[i]);
|
|
}
|
|
|
|
for (int i = 0; i < BMSData.ModuleQuantity; i++)
|
|
{
|
|
this.Controls.Add(ModuleSocBar[i]);
|
|
}
|
|
|
|
for (int i = 0; i < SystemID.MAX_MODULE_SIZE; i++)
|
|
{
|
|
this.Controls.Add(ModuleSocPicture[i]);
|
|
}
|
|
|
|
this.Controls.Add(this.lbMainTemp);
|
|
|
|
this.Controls.Add(this.btnMute);
|
|
this.Controls.Add(this.btnTrayInfo);
|
|
this.Controls.Add(this.btnHistory);
|
|
this.Controls.Add(this.btnSetting);
|
|
|
|
this.Controls.Add(this.lbW1);
|
|
this.Controls.Add(this.lbW2);
|
|
this.Controls.Add(this.lbP1);
|
|
this.Controls.Add(this.lbP2);
|
|
|
|
this.Controls.Add(this.lbMainSOC);
|
|
this.Controls.Add(this.lbCurrentDateTime);
|
|
this.Controls.Add(this.lbMainAlarmStatus);
|
|
this.Controls.Add(this.lbMainOpStatus);
|
|
this.Controls.Add(this.lbMainCurrent);
|
|
this.Controls.Add(this.lbMainVoltage);
|
|
this.Controls.Add(this.sfmMain);
|
|
|
|
this.ResumeLayout(false);
|
|
|
|
this.sfmMain.Refresh();
|
|
ModuleSocBar[0].Refresh();
|
|
}
|
|
}
|
|
} |