Update BMS D1000 project files and documentation
This commit is contained in:
@@ -80,63 +80,47 @@ namespace BMS_D1000H.Utils.Functions
|
||||
|
||||
private byte[] WriteDataHeader(DeviceDataSystem sData)
|
||||
{
|
||||
string tt;
|
||||
string sdata;
|
||||
DateTime aLog = DateTime.Now;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
tt = aLog.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
sdata = String.Format(
|
||||
"{0},{1},{2},{3},{4},{5},{6},{7},"
|
||||
, "DATETIME" // 0
|
||||
, "OPERATING" // 1
|
||||
, "ALARM" // 2
|
||||
, "SYSTEM VOLTAGE" // 3
|
||||
, "SYSTEM CURRENT" // 4
|
||||
, "SYSTEM SOC" // 5
|
||||
, "TRIP" // 6
|
||||
, "WARNING" // 7
|
||||
);
|
||||
sb.Append("DATETIME,OPERATING,ALARM,SYSTEM VOLTAGE,SYSTEM CURRENT,SYSTEM SOC,TRIP,WARNING,");
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("VOLTAGE_{0:00},", i + 1);
|
||||
sb.AppendFormat("VOLTAGE_{0:00},", i + 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("CURRENT_{0:00},", i + 1);
|
||||
sb.AppendFormat("CURRENT_{0:00},", i + 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("SOC_{0:00},", i + 1);
|
||||
sb.AppendFormat("SOC_{0:00},", i + 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("MAX_TEMP_{0:00},", i + 1);
|
||||
sb.AppendFormat("MAX_TEMP_{0:00},", i + 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("MIN_TEMP_{0:00},", i + 1);
|
||||
sb.AppendFormat("MIN_TEMP_{0:00},", i + 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("MAX_CVOLT_{0:00},", i + 1);
|
||||
sb.AppendFormat("MAX_CVOLT_{0:00},", i + 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("MIN_CVOLT_{0:00},", i + 1);
|
||||
sb.AppendFormat("MIN_CVOLT_{0:00},", i + 1);
|
||||
}
|
||||
sdata += "\r\n";
|
||||
sb.Append("\r\n");
|
||||
|
||||
Byte[] info =
|
||||
new UTF8Encoding(true).GetBytes(sdata);
|
||||
|
||||
return info;
|
||||
return new UTF8Encoding(true).GetBytes(sb.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -145,249 +129,185 @@ namespace BMS_D1000H.Utils.Functions
|
||||
|
||||
private byte[] WriteData(DeviceDataSystem sData, DeviceDataTray[] tData)
|
||||
{
|
||||
string tt;
|
||||
string sdata;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
DateTime aLog = DateTime.Now;
|
||||
|
||||
tt = aLog.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
sdata = String.Format(
|
||||
"{0},{1},{2},{3},{4},{5},"
|
||||
, tt // {0} DATETIME
|
||||
, String.Format("{0}", StatusStr.operating[sData.OpStatus]) // {1} OPERATING
|
||||
, String.Format("{0}", StatusStr.alarm[sData.AlarmStatus]) // {2} ALARM
|
||||
, String.Format("{0:#0.0}", Convert.ToDouble(sData.BatVoltage) / 100) // {3} SYSTEM VOLTAGE
|
||||
, String.Format("{0:#0.0}", Convert.ToDouble(sData.Current) / 10) // {4} SYSTEM CURRENT
|
||||
, String.Format("{0:#0.0}", Convert.ToDouble(sData.RelativeStateOfCharge) / 10) // {5} SYSTEM SOC
|
||||
sb.AppendFormat("{0:yyyy-MM-dd HH:mm:ss},{1},{2},{3:#0.0},{4:#0.0},{5:#0.0},"
|
||||
, aLog
|
||||
, StatusStr.operating[sData.OpStatus]
|
||||
, StatusStr.alarm[sData.AlarmStatus]
|
||||
, Convert.ToDouble(sData.BatVoltage) / 100
|
||||
, Convert.ToDouble(sData.Current) / 10
|
||||
, Convert.ToDouble(sData.RelativeStateOfCharge) / 10
|
||||
);
|
||||
|
||||
sdata += String.Format("0x{0:X4},", sData.Protection); // Protection
|
||||
sdata += String.Format("0x{0:X4},", sData.Warning); // Warning
|
||||
sb.AppendFormat("0x{0:X4},", sData.Protection);
|
||||
sb.AppendFormat("0x{0:X4},", sData.Warning);
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("{0:#0.0},", Convert.ToDouble(tData[i].BatVoltage) / 100); // Module Voltage
|
||||
sb.AppendFormat("{0:#0.0},", Convert.ToDouble(tData[i].BatVoltage) / 100);
|
||||
}
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("{0:#0.0},", Convert.ToDouble(tData[i].Current) / 10); // Module Current
|
||||
sb.AppendFormat("{0:#0.0},", Convert.ToDouble(tData[i].Current) / 10);
|
||||
}
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("{0:#0},", Convert.ToDouble(tData[i].RelativeStateOfCharge) / 10); // Module SOC
|
||||
sb.AppendFormat("{0:#0},", Convert.ToDouble(tData[i].RelativeStateOfCharge) / 10);
|
||||
}
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("{0:#0.0},", Convert.ToDouble(tData[i].MaxTemp) / 10); // Module Max Temp
|
||||
sb.AppendFormat("{0:#0.0},", Convert.ToDouble(tData[i].MaxTemp) / 10);
|
||||
}
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("{0:#0.0},", Convert.ToDouble(tData[i].MinTemp) / 10); // Module Min Temp
|
||||
sb.AppendFormat("{0:#0.0},", Convert.ToDouble(tData[i].MinTemp) / 10);
|
||||
}
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("{0:#0.000},", Convert.ToDouble(tData[i].MaxCellVoltage) / 1000); // Cell Max Volage
|
||||
sb.AppendFormat("{0:#0.000},", Convert.ToDouble(tData[i].MaxCellVoltage) / 1000);
|
||||
}
|
||||
|
||||
for (int i = 0; i < sData.ModuleQuantity; i++)
|
||||
{
|
||||
sdata += String.Format("{0:#0.000},", Convert.ToDouble(tData[i].MinCellVoltage) / 1000); // Cell Max Volage
|
||||
sb.AppendFormat("{0:#0.000},", Convert.ToDouble(tData[i].MinCellVoltage) / 1000);
|
||||
}
|
||||
sdata += "\r\n";
|
||||
sb.Append("\r\n");
|
||||
|
||||
Byte[] info =
|
||||
new UTF8Encoding(true).GetBytes(sdata);
|
||||
|
||||
return info;
|
||||
return new UTF8Encoding(true).GetBytes(sb.ToString());
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void LoggingData(DeviceDataSystem sData, DeviceDataTray[] tData)
|
||||
{
|
||||
string filename;
|
||||
string path;
|
||||
DateTime aLog = DateTime.Now;
|
||||
FileStream fStream = null;
|
||||
byte[] logData;
|
||||
string filename = String.Format("{0}log{1}.csv", LoggingFilePath, aLog.ToString("yyyyMMdd"));
|
||||
string path = System.IO.Path.GetDirectoryName(filename);
|
||||
|
||||
filename = String.Format("{0}log{1}.csv", LoggingFilePath, aLog.ToString("yyyyMMdd"));
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(path) == false)
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
path = System.IO.Path.GetDirectoryName(filename);
|
||||
bool fileExists = File.Exists(filename);
|
||||
FileMode mode = fileExists ? FileMode.Open : FileMode.CreateNew;
|
||||
|
||||
//if (Directory.Exists(SdCardPath) == true)
|
||||
//{
|
||||
try
|
||||
using (FileStream fStream = new FileStream(filename, mode, FileAccess.ReadWrite))
|
||||
{
|
||||
if (Directory.Exists(path) == false)
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
if (File.Exists(filename))
|
||||
fStream.Seek(0, SeekOrigin.End);
|
||||
if (!fileExists)
|
||||
{
|
||||
fStream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite);
|
||||
if (fStream != null)
|
||||
{
|
||||
fStream.Seek(0, SeekOrigin.End);
|
||||
logData = WriteData(sData, tData);
|
||||
//logData = WriteData(sData, tDataA, tDataB);
|
||||
|
||||
fStream.Write(logData, 0, logData.Length);
|
||||
fStream.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fStream = new FileStream(filename, FileMode.CreateNew, FileAccess.ReadWrite);
|
||||
|
||||
if (fStream != null)
|
||||
{
|
||||
fStream.Seek(0, SeekOrigin.End);
|
||||
logData = WriteDataHeader(sData);
|
||||
//logData = WriteDataHeader(sData, tDataA, tDataB);
|
||||
fStream.Write(logData, 0, logData.Length);
|
||||
logData = WriteData(sData, tData);
|
||||
//logData = WriteData(sData, tDataA, tDataB);
|
||||
fStream.Write(logData, 0, logData.Length);
|
||||
fStream.Close();
|
||||
}
|
||||
byte[] logHeader = WriteDataHeader(sData);
|
||||
fStream.Write(logHeader, 0, logHeader.Length);
|
||||
}
|
||||
byte[] logData = WriteData(sData, tData);
|
||||
fStream.Write(logData, 0, logData.Length);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
//}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void InitPasswordData()
|
||||
{
|
||||
string filepath = PasswordFilePath;
|
||||
FileStream fStream = null;
|
||||
byte[] bData;
|
||||
|
||||
fStream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
||||
|
||||
if (fStream != null)
|
||||
using (FileStream fStream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
||||
{
|
||||
BMS_PASSWORD = "0000";
|
||||
bData = Encoding.ASCII.GetBytes(BMS_PASSWORD);
|
||||
byte[] bData = Encoding.ASCII.GetBytes(BMS_PASSWORD);
|
||||
|
||||
fStream.Seek(0, SeekOrigin.Begin);
|
||||
fStream.Write(bData, 0, bData.Length);
|
||||
fStream.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveNewPasswordData(string new_password)
|
||||
{
|
||||
string filepath = PasswordFilePath;
|
||||
FileStream fStream = null;
|
||||
byte[] bData;
|
||||
|
||||
fStream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
||||
|
||||
if (fStream != null)
|
||||
using (FileStream fStream = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
||||
{
|
||||
BMS_PASSWORD = new_password;
|
||||
bData = Encoding.ASCII.GetBytes(BMS_PASSWORD);
|
||||
byte[] bData = Encoding.ASCII.GetBytes(BMS_PASSWORD);
|
||||
|
||||
fStream.Seek(0, SeekOrigin.Begin);
|
||||
fStream.Write(bData, 0, bData.Length);
|
||||
fStream.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadPasswordData()
|
||||
{
|
||||
long fsize = 0;
|
||||
string filepath = PasswordFilePath;
|
||||
FileStream fStream = null;
|
||||
byte[] bData;
|
||||
|
||||
if (File.Exists(filepath))
|
||||
{
|
||||
fStream = new FileStream(filepath, FileMode.Open, FileAccess.Read);
|
||||
|
||||
if (fStream != null)
|
||||
using (FileStream fStream = new FileStream(filepath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
fsize = fStream.Length;
|
||||
bData = new byte[fsize];
|
||||
long fsize = fStream.Length;
|
||||
byte[] bData = new byte[fsize];
|
||||
|
||||
fStream.Seek(0, SeekOrigin.Begin);
|
||||
fStream.Read(bData, 0, Convert.ToInt32(fsize));
|
||||
fStream.Close();
|
||||
|
||||
BMS_PASSWORD = Encoding.ASCII.GetString(bData, 0, Convert.ToInt32(fsize));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fStream = new FileStream(filepath, FileMode.CreateNew, FileAccess.ReadWrite);
|
||||
|
||||
if (fStream != null)
|
||||
using (FileStream fStream = new FileStream(filepath, FileMode.CreateNew, FileAccess.ReadWrite))
|
||||
{
|
||||
BMS_PASSWORD = "0000";
|
||||
bData = Encoding.ASCII.GetBytes(BMS_PASSWORD);
|
||||
byte[] bData = Encoding.ASCII.GetBytes(BMS_PASSWORD);
|
||||
|
||||
fStream.Seek(0, SeekOrigin.Begin);
|
||||
fStream.Write(bData, 0, bData.Length);
|
||||
fStream.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadAlarmData()
|
||||
{
|
||||
long fsize = 0;
|
||||
string filepath = AlarmHistPath;
|
||||
FileStream fStream = null;
|
||||
byte[] bData = new byte[Marshal.SizeOf(AlarmList)];
|
||||
|
||||
if (File.Exists(AlarmHistPath))
|
||||
{
|
||||
fStream = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite);
|
||||
|
||||
if (fStream != null)
|
||||
using (FileStream fStream = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite))
|
||||
{
|
||||
fsize = fStream.Length;
|
||||
long fsize = fStream.Length;
|
||||
|
||||
if (Marshal.SizeOf(AlarmList) != fsize)
|
||||
{
|
||||
fStream.Close();
|
||||
fStream = null;
|
||||
|
||||
File.Delete(filepath);
|
||||
|
||||
fStream = new FileStream(filepath, FileMode.CreateNew, FileAccess.ReadWrite);
|
||||
|
||||
if (fStream != null)
|
||||
using (FileStream newStream = new FileStream(filepath, FileMode.CreateNew, FileAccess.ReadWrite))
|
||||
{
|
||||
fStream.SetLength(Marshal.SizeOf(AlarmList));
|
||||
fStream.Seek(0, SeekOrigin.Begin);
|
||||
fStream.Write(bData, 0, Marshal.SizeOf(AlarmList));
|
||||
newStream.SetLength(Marshal.SizeOf(AlarmList));
|
||||
newStream.Seek(0, SeekOrigin.Begin);
|
||||
newStream.Write(bData, 0, Marshal.SizeOf(AlarmList));
|
||||
|
||||
fStream.Seek(0, SeekOrigin.Begin);
|
||||
fStream.Read(bData, 0, Marshal.SizeOf(AlarmList));
|
||||
newStream.Seek(0, SeekOrigin.Begin);
|
||||
newStream.Read(bData, 0, Marshal.SizeOf(AlarmList));
|
||||
AlarmList = ConvertTo.ByteToStruct<TAlarmList>(bData);
|
||||
fStream.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fStream.Read(bData, 0, Marshal.SizeOf(AlarmList));
|
||||
fStream.Close();
|
||||
|
||||
AlarmList = ConvertTo.ByteToStruct<TAlarmList>(bData);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fStream = new FileStream(filepath, FileMode.CreateNew, FileAccess.ReadWrite);
|
||||
|
||||
if (fStream != null)
|
||||
using (FileStream fStream = new FileStream(filepath, FileMode.CreateNew, FileAccess.ReadWrite))
|
||||
{
|
||||
fStream.SetLength(Marshal.SizeOf(AlarmList));
|
||||
fStream.Seek(0, SeekOrigin.Begin);
|
||||
@@ -396,7 +316,6 @@ namespace BMS_D1000H.Utils.Functions
|
||||
fStream.Seek(0, SeekOrigin.Begin);
|
||||
fStream.Read(bData, 0, Marshal.SizeOf(AlarmList));
|
||||
AlarmList = ConvertTo.ByteToStruct<TAlarmList>(bData);
|
||||
fStream.Close();
|
||||
}
|
||||
}
|
||||
Make_Run_History(EventID.EVENT_INFO, AlarmID.POWER_ON_RESET, 0, 0, 0);
|
||||
@@ -406,18 +325,12 @@ namespace BMS_D1000H.Utils.Functions
|
||||
{
|
||||
long fsize = Marshal.SizeOf(AlarmList);
|
||||
string filepath = AlarmHistPath;
|
||||
FileStream fStream = null;
|
||||
byte[] bData = new byte[fsize];
|
||||
byte[] bData = ConvertTo.StructureToByte(AlarmList);
|
||||
|
||||
bData = ConvertTo.StructureToByte(AlarmList);
|
||||
|
||||
fStream = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite);
|
||||
|
||||
if (fStream != null)
|
||||
using (FileStream fStream = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite))
|
||||
{
|
||||
fStream.Seek(0, SeekOrigin.Begin);
|
||||
fStream.Write(bData, 0, Convert.ToInt32(fsize));
|
||||
fStream.Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,18 +338,14 @@ namespace BMS_D1000H.Utils.Functions
|
||||
{
|
||||
long fsize = Marshal.SizeOf(AlarmList);
|
||||
string filepath = AlarmHistPath;
|
||||
FileStream fStream = null;
|
||||
byte[] bData = new byte[fsize];
|
||||
|
||||
System.Array.Clear(bData, 0, Convert.ToInt32(fsize));
|
||||
|
||||
fStream = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite);
|
||||
|
||||
if (fStream != null)
|
||||
using (FileStream fStream = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite))
|
||||
{
|
||||
fStream.Seek(0, SeekOrigin.Begin);
|
||||
fStream.Write(bData, 0, Convert.ToInt32(fsize));
|
||||
fStream.Close();
|
||||
|
||||
AlarmList = ConvertTo.ByteToStruct<TAlarmList>(bData);
|
||||
}
|
||||
@@ -447,25 +356,20 @@ namespace BMS_D1000H.Utils.Functions
|
||||
public long GetFileSize(string FilePath)
|
||||
{
|
||||
long fsize = 0;
|
||||
FileStream fStream = null;
|
||||
|
||||
if (File.Exists(FilePath))
|
||||
{
|
||||
// Found
|
||||
fStream = new FileStream(FilePath, FileMode.Open, FileAccess.ReadWrite);
|
||||
|
||||
fsize = fStream.Length;
|
||||
|
||||
fStream.Close();
|
||||
using (FileStream fStream = new FileStream(FilePath, FileMode.Open, FileAccess.ReadWrite))
|
||||
{
|
||||
fsize = fStream.Length;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No File
|
||||
fStream = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
||||
|
||||
fsize = fStream.Length;
|
||||
|
||||
fStream.Close();
|
||||
using (FileStream fStream = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
||||
{
|
||||
fsize = fStream.Length;
|
||||
}
|
||||
}
|
||||
|
||||
return fsize;
|
||||
@@ -560,29 +464,18 @@ namespace BMS_D1000H.Utils.Functions
|
||||
|
||||
public byte[] MakeHistoryCsvHeader()
|
||||
{
|
||||
string str = "";
|
||||
byte[] result;
|
||||
|
||||
str += String.Format("DateTime,");
|
||||
str += String.Format("Event,");
|
||||
str += String.Format("Alarm Name,");
|
||||
str += String.Format("Position,");
|
||||
str += String.Format("Parameter,");
|
||||
str += "\r\n";
|
||||
|
||||
result = new UTF8Encoding(true).GetBytes(str);
|
||||
|
||||
return result;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("DateTime,Event,Alarm Name,Position,Parameter,\r\n");
|
||||
return new UTF8Encoding(true).GetBytes(sb.ToString());
|
||||
}
|
||||
|
||||
public void Save_HistoryCsv(TAlarm hdata)
|
||||
{
|
||||
string wStr = "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
wStr = String.Format("{0:yyyy-MM-dd HH:mm:ss},", hdata.aTime); // DateTime - nHist.aTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
wStr += String.Format("{0},", EventID.event_name[hdata.aFlag]); // Event type - EventID.event_name[nHist.aFlag];
|
||||
wStr += String.Format("{0},", AlarmID.name[hdata.aNameNo]); // Alarm name - hAlarmName[hNo].Text = AlarmID.name[nHist.aNameNo];
|
||||
//wStr += String.Format("{0}-{1},", PosID.pos[hdata.aPos], hdata.ctno); // Alarm position
|
||||
sb.AppendFormat("{0:yyyy-MM-dd HH:mm:ss},", hdata.aTime);
|
||||
sb.AppendFormat("{0},", EventID.event_name[hdata.aFlag]);
|
||||
sb.AppendFormat("{0},", AlarmID.name[hdata.aNameNo]);
|
||||
|
||||
switch (hdata.aNameNo)
|
||||
{
|
||||
@@ -590,38 +483,38 @@ namespace BMS_D1000H.Utils.Functions
|
||||
case AlarmID.COV_WARNING:
|
||||
case AlarmID.CUV_PROTECTION:
|
||||
case AlarmID.CUV_WARNING:
|
||||
wStr += String.Format("'{0}-{1},", PosID.pos[hdata.aPos], hdata.ctno);
|
||||
wStr += String.Format("{0:#0.000},", Convert.ToDouble(hdata.aParam) / 1000);
|
||||
sb.AppendFormat("'{0}-{1},", PosID.pos[hdata.aPos], hdata.ctno);
|
||||
sb.AppendFormat("{0:#0.000},", Convert.ToDouble(hdata.aParam) / 1000);
|
||||
break;
|
||||
case AlarmID.OTC_PROTECTION:
|
||||
case AlarmID.OTC_WARNING:
|
||||
case AlarmID.OTD_PROTECTION:
|
||||
case AlarmID.OTD_WARNING:
|
||||
wStr += String.Format("'{0}-{1},", PosID.pos[hdata.aPos], hdata.ctno);
|
||||
wStr += String.Format("{0:#0.0},", Convert.ToDouble(hdata.aParam) / 10);
|
||||
sb.AppendFormat("'{0}-{1},", PosID.pos[hdata.aPos], hdata.ctno);
|
||||
sb.AppendFormat("{0:#0.0},", Convert.ToDouble(hdata.aParam) / 10);
|
||||
break;
|
||||
case AlarmID.SOV_PROTECTION:
|
||||
case AlarmID.SOV_WARNING:
|
||||
case AlarmID.SUV_PROTECTION:
|
||||
case AlarmID.SUV_WARNING:
|
||||
wStr += String.Format("'{0},", PosID.pos[hdata.aPos]);
|
||||
wStr += String.Format("{0:#0.0},", Convert.ToDouble(hdata.aParam) / 100);
|
||||
sb.AppendFormat("'{0},", PosID.pos[hdata.aPos]);
|
||||
sb.AppendFormat("{0:#0.0},", Convert.ToDouble(hdata.aParam) / 100);
|
||||
break;
|
||||
case AlarmID.OCC_PROTECTION:
|
||||
case AlarmID.OCC_WARNING:
|
||||
case AlarmID.OCD_PROTECTION:
|
||||
case AlarmID.OCD_WARNING:
|
||||
wStr += String.Format("'{0},", PosID.pos[hdata.aPos]);
|
||||
wStr += String.Format("{0:#0.0},", Convert.ToDouble(hdata.aParam) / 10);
|
||||
sb.AppendFormat("'{0},", PosID.pos[hdata.aPos]);
|
||||
sb.AppendFormat("{0:#0.0},", Convert.ToDouble(hdata.aParam) / 10);
|
||||
break;
|
||||
default:
|
||||
wStr += String.Format("'{0},", PosID.pos[hdata.aPos]);
|
||||
wStr += String.Format(",");
|
||||
sb.AppendFormat("'{0},", PosID.pos[hdata.aPos]);
|
||||
sb.Append(",");
|
||||
break;
|
||||
}
|
||||
wStr += "\r\n";
|
||||
sb.Append("\r\n");
|
||||
|
||||
byte[] bAlm = new UTF8Encoding(true).GetBytes(wStr);
|
||||
byte[] bAlm = new UTF8Encoding(true).GetBytes(sb.ToString());
|
||||
|
||||
string filename = String.Format("{0}Alm_{1}.csv", AlarmHistCsvPath, DateTime.Now.ToString("yyyyMMdd"));
|
||||
string path = System.IO.Path.GetDirectoryName(filename);
|
||||
@@ -631,30 +524,18 @@ namespace BMS_D1000H.Utils.Functions
|
||||
if (Directory.Exists(path) == false)
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite);
|
||||
if (fStream != null)
|
||||
{
|
||||
fStream.Seek(0, SeekOrigin.End);
|
||||
fStream.Write(bAlm, 0, bAlm.Length);
|
||||
fStream.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FileStream fStream = new FileStream(filename, FileMode.CreateNew, FileAccess.ReadWrite);
|
||||
bool fileExists = File.Exists(filename);
|
||||
FileMode mode = fileExists ? FileMode.Open : FileMode.CreateNew;
|
||||
|
||||
if (fStream != null)
|
||||
using (FileStream fStream = new FileStream(filename, mode, FileAccess.ReadWrite))
|
||||
{
|
||||
fStream.Seek(0, SeekOrigin.End);
|
||||
if (!fileExists)
|
||||
{
|
||||
fStream.Seek(0, SeekOrigin.End);
|
||||
|
||||
byte[] hdr = MakeHistoryCsvHeader();
|
||||
fStream.Write(hdr, 0, hdr.Length);
|
||||
fStream.Write(bAlm, 0, bAlm.Length);
|
||||
|
||||
fStream.Close();
|
||||
}
|
||||
fStream.Write(bAlm, 0, bAlm.Length);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
|
||||
Reference in New Issue
Block a user