INT_PT002/INT_PT002/Forms/FormMain.cs

1142 lines
40 KiB
C#
Raw Normal View History

2023-02-09 08:20:49 +00:00
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using INT_PT002.DataStore;
using SmartX;
namespace INT_PT002.Forms
{
public partial class FormMain : Form
{
#region Field
public bool IsCommunicationLogOpen;
public int DecimalPlaces3;
public int DecimalPlaces4;
private int CommunicationCheckCount;
public int EquipmentColumn;
2023-02-09 08:20:49 +00:00
// 파일 위치
private string m_PathLaunchFolder;
private string m_PathSystemFileFolder;
private string m_PathDataBackupFolder;
// 장비 구동 상태
private Define.E_EquipmentStatus m_EquipmentStatus;
// SystemConfiguration
public SystemConfiguration SystemConfig;
2023-03-06 04:52:55 +00:00
// Current Recipe
public Recipe CurrentRecipe;
2023-02-09 08:20:49 +00:00
// Leak Data
private LeakData CurrentLeakData;
2023-02-09 08:20:49 +00:00
public FormMainDisplay1 ChildFormMainDisplay;
2023-02-13 00:43:01 +00:00
public FormMenu ChildFormMenu;
2023-02-09 08:20:49 +00:00
#endregion
#region Constructor
public FormMain()
{
InitializeComponent();
}
#endregion
#region Property
public string PathLaunchFolder
{
get { return this.m_PathLaunchFolder; }
set { this.m_PathLaunchFolder = value; }
}
public string PathSystemFileFolder
{
get { return this.m_PathSystemFileFolder; }
set { this.m_PathSystemFileFolder = value; }
}
public string PathDataBackupFolder
{
get { return this.m_PathDataBackupFolder; }
set { this.m_PathDataBackupFolder = value; }
}
public Define.E_EquipmentStatus EquipmentStatus
{
get { return this.m_EquipmentStatus; }
private set { this.m_EquipmentStatus = value; }
}
#endregion
#region Method
private void DefaultSetting()
{
this.IsCommunicationLogOpen = false;
this.DecimalPlaces3 = 3;
this.DecimalPlaces4 = 4;
this.CommunicationCheckCount = 0;
this.EquipmentColumn = 10;
2023-02-09 08:20:49 +00:00
this.EquipmentStatus = Define.E_EquipmentStatus.Stop;
this.PathLaunchFolder = "SD Card\\";
this.PathSystemFileFolder = this.PathLaunchFolder + "SystemFile\\";
this.PathDataBackupFolder = this.PathLaunchFolder + "DataBackup\\";
this.SystemConfig = new SystemConfiguration();
2023-03-06 04:52:55 +00:00
this.CurrentRecipe = new Recipe();
2023-02-09 08:20:49 +00:00
this.CurrentLeakData = new LeakData(this.EquipmentColumn);
2023-02-09 08:20:49 +00:00
// SystemFile 폴더 생성
if (Directory.Exists(this.PathSystemFileFolder) == false)
Directory.CreateDirectory(this.PathSystemFileFolder);
// DataBackup 폴더 생성
if (Directory.Exists(this.PathDataBackupFolder) == false)
Directory.CreateDirectory(this.PathDataBackupFolder);
}
private void CreateForm()
{
this.ChildFormMainDisplay = new FormMainDisplay1(this);
2023-02-13 00:43:01 +00:00
this.ChildFormMenu = new FormMenu(this);
2023-02-09 08:20:49 +00:00
this.smartForm1.MainForm = this;
this.smartForm1.AddChildForm(this.ChildFormMainDisplay);
2023-02-13 00:43:01 +00:00
this.smartForm1.AddChildForm(this.ChildFormMenu);
2023-02-09 08:20:49 +00:00
}
private void TransferSystemParameter9039()
2023-02-09 08:20:49 +00:00
{
StringBuilder sb = new StringBuilder();
2023-03-06 04:52:55 +00:00
sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.LCD_DATA_PERIOD.ToString()));
sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.CHATTERING.ToString()));
sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.JUDGMENT_DELAY_MSEC.ToString()));
sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.BUZZER_OP.ToString()));
sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.SB_DIFF_FILTER.ToString()));
sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.SB_DATA_MODE.ToString()));
sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.SB_DATA_PERIOD.ToString()));
sb.Append(Helper.StringBlankFillDigits4(this.SystemConfig.SB_DIFF_MODE.ToString()));
2023-02-09 08:20:49 +00:00
this.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._9039_ParameterAll, sb.ToString());
}
public void TransferRecipeParameter9043(int number)
{
StringBuilder sb = new StringBuilder();
Recipe item = new Recipe();
this.LoadRecipeFile(ref item, number - 1);
sb.Append(Helper.StringBlankFillDigits4(item.NUMBER.ToString()));
sb.Append(Helper.StringBlankFillDigits4(item.VACUUM_RELIEF.ToString()));
sb.Append(Helper.StringBlankFillDigits4(item.VACUUM_HOLD1.ToString()));
sb.Append(Helper.StringBlankFillDigits4(item.VACUUM_HOLD2.ToString()));
sb.Append(Helper.StringBlankFillDigits4(item.VACUUM_BLOWOFF.ToString()));
sb.Append(Helper.StringBlankFillDigits6(item.DISP_JUDG_STD_LEVEL));
sb.Append(Helper.StringBlankFillDigits6(item.DISP_JUDG_MIN_LEVEL));
sb.Append(Helper.StringBlankFillDigits6(item.DISP_JUDG_EMPTY_LEVEL));
sb.Append(Helper.StringBlankFillDigits4(item.DISP_HOLD_DELAY_MSEC.ToString()));
sb.Append(Helper.StringBlankFillDigits8(item.DIFF_LR_SECOND));
sb.Append(Helper.StringBlankFillDigits8(item.DIFF_LR_TOTAL));
sb.Append(Helper.StringBlankFillDigits8(item.DIFF_LR_MEAN));
sb.Append(Helper.StringBlankFillDigits4(item.DIFF_HOLD_DELAY_MSEC.ToString()));
sb.Append(Helper.StringBlankFillDigits6(item.VACUUM_GUAGE_LEVEL));
this.TransferDataStream(CommunicationCommand.Write, CommunicationID.MainBoard, CommunicationAddress._9043_RecipeParameter, sb.ToString());
}
2023-02-09 08:20:49 +00:00
public void FormChange(int index)
{
this.smartForm1.Show(index);
}
#region SystemConfiguration File
private void CreateSystemConfigurationFile()
{
StructSystemConfigurationItem structItem;
this.SystemConfig.Initialize();
2023-03-06 04:52:55 +00:00
structItem.RECIPE_NUMBER = this.SystemConfig.RECIPE_NUMBER;
structItem.CHART1_DRAW_STEP = this.SystemConfig.CHART1_DRAW_STEP;
structItem.CHART2_DRAW_STEP = this.SystemConfig.CHART2_DRAW_STEP;
structItem.LCD_DATA_PERIOD = this.SystemConfig.LCD_DATA_PERIOD;
structItem.CHATTERING = this.SystemConfig.CHATTERING;
structItem.JUDGMENT_DELAY_MSEC = this.SystemConfig.JUDGMENT_DELAY_MSEC;
structItem.BUZZER_OP = this.SystemConfig.BUZZER_OP;
structItem.SB_DIFF_FILTER = this.SystemConfig.SB_DIFF_FILTER;
structItem.SB_DIFF_MODE = this.SystemConfig.SB_DIFF_MODE;
structItem.SB_DATA_MODE = this.SystemConfig.SB_DATA_MODE;
structItem.SB_DATA_PERIOD = this.SystemConfig.SB_DATA_PERIOD;
2023-02-09 08:20:49 +00:00
this.smartFileIO.StructType.Write(structItem, 0, SmartFile.WriteMode.Overwrite);
}
public void SaveSystemConfigurationFile(SystemConfiguration item)
{
string fullFilePath = "";
bool fileCheck = false;
StructSystemConfigurationItem structItem;
fullFilePath = this.PathSystemFileFolder + "system.cfg";
this.smartFileIO.FilePathName = fullFilePath;
FileInfo fileInfo = new FileInfo(fullFilePath);
fileCheck = fileInfo.Exists;
if (fileCheck == true)
2023-02-13 00:43:01 +00:00
{
2023-02-09 08:20:49 +00:00
this.smartFileIO.Open();
2023-02-13 00:43:01 +00:00
this.smartFileIO.StructType.SetStructType(typeof(StructSystemConfigurationItem));
}
2023-02-09 08:20:49 +00:00
else
{
this.smartFileIO.Open();
2023-02-13 00:43:01 +00:00
this.smartFileIO.StructType.SetStructType(typeof(StructSystemConfigurationItem));
2023-02-09 08:20:49 +00:00
this.CreateSystemConfigurationFile();
}
2023-03-06 04:52:55 +00:00
structItem.RECIPE_NUMBER = item.RECIPE_NUMBER;
structItem.CHART1_DRAW_STEP = item.CHART1_DRAW_STEP;
structItem.CHART2_DRAW_STEP = item.CHART2_DRAW_STEP;
structItem.LCD_DATA_PERIOD = item.LCD_DATA_PERIOD;
structItem.CHATTERING = item.CHATTERING;
structItem.JUDGMENT_DELAY_MSEC = item.JUDGMENT_DELAY_MSEC;
structItem.BUZZER_OP = item.BUZZER_OP;
structItem.SB_DIFF_FILTER = item.SB_DIFF_FILTER;
structItem.SB_DIFF_MODE = item.SB_DIFF_MODE;
structItem.SB_DATA_MODE = item.SB_DATA_MODE;
structItem.SB_DATA_PERIOD = item.SB_DATA_PERIOD;
2023-02-09 08:20:49 +00:00
this.smartFileIO.StructType.Write(structItem, 0, SmartFile.WriteMode.Overwrite);
this.smartFileIO.Close();
}
public void LoadSystemConfigurationFile()
{
string fullFilePath = "";
bool fileCheck = false;
StructSystemConfigurationItem structItem;
fullFilePath = this.PathSystemFileFolder + "system.cfg";
this.smartFileIO.FilePathName = fullFilePath;
FileInfo fileInfo = new FileInfo(fullFilePath);
fileCheck = fileInfo.Exists;
if (fileCheck == true)
2023-02-13 00:43:01 +00:00
{
2023-02-09 08:20:49 +00:00
this.smartFileIO.Open();
2023-02-13 00:43:01 +00:00
this.smartFileIO.StructType.SetStructType(typeof(StructSystemConfigurationItem));
}
2023-02-09 08:20:49 +00:00
else
{
this.smartFileIO.Open();
2023-02-13 00:43:01 +00:00
this.smartFileIO.StructType.SetStructType(typeof(StructSystemConfigurationItem));
2023-02-09 08:20:49 +00:00
this.CreateSystemConfigurationFile();
}
structItem = (StructSystemConfigurationItem)this.smartFileIO.StructType.Read(0);
2023-03-06 04:52:55 +00:00
this.SystemConfig.RECIPE_NUMBER = structItem.RECIPE_NUMBER;
this.SystemConfig.CHART1_DRAW_STEP = structItem.CHART1_DRAW_STEP;
this.SystemConfig.CHART2_DRAW_STEP = structItem.CHART2_DRAW_STEP;
this.SystemConfig.LCD_DATA_PERIOD = structItem.LCD_DATA_PERIOD;
this.SystemConfig.CHATTERING = structItem.CHATTERING;
this.SystemConfig.JUDGMENT_DELAY_MSEC = structItem.JUDGMENT_DELAY_MSEC;
this.SystemConfig.BUZZER_OP = structItem.BUZZER_OP;
this.SystemConfig.SB_DIFF_FILTER = structItem.SB_DIFF_FILTER;
this.SystemConfig.SB_DIFF_MODE = structItem.SB_DIFF_MODE;
this.SystemConfig.SB_DATA_MODE = structItem.SB_DATA_MODE;
this.SystemConfig.SB_DATA_PERIOD = structItem.SB_DATA_PERIOD;
this.smartFileIO.Close();
}
#endregion
#region Recipe File
private void CreateRecipeFile()
{
StructRecipe structItem;
this.CurrentRecipe.Initialize();
for (int i = 0; i < 1000; i++)
{
structItem.NUMBER = i + 1;
structItem.NAME = string.Format("INTECH {0}", i + 1);
structItem.LOT = string.Format("LOT {0}", i + 1);
structItem.DISP_JUDG_STD_LEVEL = this.CurrentRecipe.DISP_JUDG_STD_LEVEL;
structItem.DISP_JUDG_MIN_LEVEL = this.CurrentRecipe.DISP_JUDG_MIN_LEVEL;
structItem.DISP_JUDG_EMPTY_LEVEL = this.CurrentRecipe.DISP_JUDG_EMPTY_LEVEL;
structItem.DISP_HOLD_DELAY_MSEC = this.CurrentRecipe.DISP_HOLD_DELAY_MSEC;
structItem.DIFF_LR_SECOND = this.CurrentRecipe.DIFF_LR_SECOND;
structItem.DIFF_LR_TOTAL = this.CurrentRecipe.DIFF_LR_TOTAL;
structItem.DIFF_LR_MEAN = this.CurrentRecipe.DIFF_LR_MEAN;
structItem.DIFF_HOLD_DELAY_MSEC = this.CurrentRecipe.DIFF_HOLD_DELAY_MSEC;
structItem.VACUUM_RELIEF = this.CurrentRecipe.VACUUM_RELIEF;
structItem.VACUUM_HOLD1 = this.CurrentRecipe.VACUUM_HOLD1;
structItem.VACUUM_HOLD2 = this.CurrentRecipe.VACUUM_HOLD2;
structItem.VACUUM_BLOWOFF = this.CurrentRecipe.VACUUM_BLOWOFF;
structItem.VACUUM_GUAGE_LEVEL = this.CurrentRecipe.VACUUM_GUAGE_LEVEL;
this.smartFileIO.StructType.WriteBuffer(structItem, i, SmartFile.WriteMode.Append);
2023-03-06 04:52:55 +00:00
}
this.smartFileIO.StructType.WriteBufferSave();
}
public void SaveRecipeFile(Recipe item, int index)
{
bool fileCheck = false;
string fullFilePath = "";
StructRecipe structItem;
fullFilePath = this.PathSystemFileFolder + "RecipeItem.int";
this.smartFileIO.FilePathName = fullFilePath;
FileInfo fileInfo = new FileInfo(fullFilePath);
fileCheck = fileInfo.Exists;
this.smartFileIO.Open();
this.smartFileIO.StructType.SetStructType(typeof(StructRecipe));
if (this.smartFileIO.StructType.GetCount() != 1000)
this.CreateRecipeFile();
structItem.NUMBER = item.NUMBER;
structItem.NAME = item.NAME;
structItem.LOT = item.LOT;
structItem.DISP_JUDG_STD_LEVEL = item.DISP_JUDG_STD_LEVEL;
structItem.DISP_JUDG_MIN_LEVEL = item.DISP_JUDG_MIN_LEVEL;
structItem.DISP_JUDG_EMPTY_LEVEL = item.DISP_JUDG_EMPTY_LEVEL;
structItem.DISP_HOLD_DELAY_MSEC = item.DISP_HOLD_DELAY_MSEC;
structItem.DIFF_LR_SECOND = item.DIFF_LR_SECOND;
structItem.DIFF_LR_TOTAL = item.DIFF_LR_TOTAL;
structItem.DIFF_LR_MEAN = item.DIFF_LR_MEAN;
structItem.DIFF_HOLD_DELAY_MSEC = item.DIFF_HOLD_DELAY_MSEC;
structItem.VACUUM_RELIEF = item.VACUUM_RELIEF;
structItem.VACUUM_HOLD1 = item.VACUUM_HOLD1;
structItem.VACUUM_HOLD2 = item.VACUUM_HOLD2;
structItem.VACUUM_BLOWOFF = item.VACUUM_BLOWOFF;
structItem.VACUUM_GUAGE_LEVEL = item.VACUUM_GUAGE_LEVEL;
this.smartFileIO.StructType.Write(structItem, index, SmartFile.WriteMode.Overwrite);
this.smartFileIO.Close();
}
public void LoadRecipeFile(ref Recipe item, int index)
{
string fullFilePath = "";
bool fileCheck = false;
StructRecipe structItem;
fullFilePath = this.PathSystemFileFolder + "RecipeItem.cfg";
this.smartFileIO.FilePathName = fullFilePath;
FileInfo fileInfo = new FileInfo(fullFilePath);
fileCheck = fileInfo.Exists;
this.smartFileIO.Open();
this.smartFileIO.StructType.SetStructType(typeof(StructRecipe));
if (this.smartFileIO.StructType.GetCount() != 1000)
this.CreateRecipeFile();
structItem = (StructRecipe)this.smartFileIO.StructType.Read(index);
item.NUMBER = structItem.NUMBER;
item.NAME = structItem.NAME;
item.LOT = structItem.LOT;
item.DISP_JUDG_STD_LEVEL = structItem.DISP_JUDG_STD_LEVEL;
item.DISP_JUDG_MIN_LEVEL = structItem.DISP_JUDG_MIN_LEVEL;
item.DISP_JUDG_EMPTY_LEVEL = structItem.DISP_JUDG_EMPTY_LEVEL;
item.DISP_HOLD_DELAY_MSEC = structItem.DISP_HOLD_DELAY_MSEC;
item.DIFF_LR_SECOND = structItem.DIFF_LR_SECOND;
item.DIFF_LR_TOTAL = structItem.DIFF_LR_TOTAL;
item.DIFF_LR_MEAN = structItem.DIFF_LR_MEAN;
item.DIFF_HOLD_DELAY_MSEC = structItem.DIFF_HOLD_DELAY_MSEC;
2023-02-09 08:20:49 +00:00
2023-03-06 04:52:55 +00:00
item.VACUUM_RELIEF = structItem.VACUUM_RELIEF;
item.VACUUM_HOLD1 = structItem.VACUUM_HOLD1;
item.VACUUM_HOLD2 = structItem.VACUUM_HOLD2;
item.VACUUM_BLOWOFF = structItem.VACUUM_BLOWOFF;
item.VACUUM_GUAGE_LEVEL = structItem.VACUUM_GUAGE_LEVEL;
2023-02-09 08:20:49 +00:00
this.smartFileIO.Close();
}
#endregion
#region Uart Communication
private void OpenSmartUartLink()
{
string fullPath = "";
try
{
if (this.smartSerialPortLink.IsOpen == false)
this.smartSerialPortLink.Open();
}
catch
{
}
#region Test 용 통신 로그
fullPath = this.PathDataBackupFolder + "Communicationlog.txt";
this.smartFileCommunicationLog.FilePathName = fullPath;
this.smartFileCommunicationLog.Open();
this.IsCommunicationLogOpen = true;
2023-02-09 08:20:49 +00:00
#endregion
}
public void CloseSmartUartLink()
{
this.smartSerialPortLink.Close();
}
private bool SizeCheck(string cmd, string strTemp)
{
bool ret = false;
string dataSize = "";
int size = 0;
if (strTemp == null || strTemp.Length == 0)
{
ret = false;
return ret;
}
try
{
if (cmd == "P")
dataSize = strTemp.Substring(14, strTemp.Length - 16);
else // "S"
dataSize = strTemp.Substring(10, strTemp.Length - 12);
size = int.Parse(strTemp.Substring(6, 4).Trim());
}
catch
{
ret = false;
return ret;
}
if (dataSize.Length == size)
ret = true;
else
{
ret = false;
}
return ret;
}
private bool ChksumCheck(string strTemp)
{
bool ret = false;
string chkSum = "", dataChksum = "";
if (strTemp == null || strTemp.Length == 0)
ret = false;
else
{
chkSum = strTemp.Substring(strTemp.Length - 2, 2);
dataChksum = this.Checksumcalculator(strTemp.Substring(0, strTemp.Length - 2));
if (chkSum == dataChksum)
ret = true;
else
ret = false;
}
return ret;
}
private string Checksumcalculator(string strTemp)
{
string chkSum = "";
byte[] temp;
int value = 0, first = 0, second = 0;
char char1, char2;
if (strTemp == null || strTemp.Length == 0)
chkSum = "cc";
else
{
temp = new UTF8Encoding().GetBytes(strTemp);
for (int i = 0; i < temp.Length; i++)
value += temp[i];
first = (value & 0x00f0) >> 4;
if (first > 9)
char1 = (char)(first + 0x37);
else
char1 = (char)(first + 0x30);
second = value & 0x000f;
if (second > 9)
char2 = (char)(second + 0x37);
else
char2 = (char)(second + 0x30);
chkSum = char1.ToString() + char2.ToString();
}
return chkSum;
}
private string Checksumcalculator(byte[] strTemp)
{
string chkSum = "";
byte[] temp;
int value = 0, first = 0, second = 0;
char char1, char2;
if (strTemp == null || strTemp.Length == 0)
chkSum = "cc";
else
{
temp = strTemp;
for (int i = 0; i < temp.Length; i++)
value += temp[i];
first = (value & 0x00f0) >> 4;
if (first > 9)
char1 = (char)(first + 0x37);
else
char1 = (char)(first + 0x30);
second = value & 0x000f;
if (second > 9)
char2 = (char)(second + 0x37);
else
char2 = (char)(second + 0x30);
chkSum = char1.ToString() + char2.ToString();
}
return chkSum;
}
public int TransferData(string command, string id)
{
int ret = 0;
string chkSum = "cc";
StringBuilder sb = new StringBuilder();
sb.Append(command);
sb.Append(id);
chkSum = this.Checksumcalculator(sb.ToString());
sb.Append(chkSum);
if (this.smartSerialPortLink.IsOpen == true)
this.smartSerialPortLink.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);
// 통신 확인 로그
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.StringType.Write(string.Format("Send ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, sb.ToString()));
return ret;
}
public int TransferDataStream(string command, string id, string address, string data)
{
int ret = 0;
string chkSum = "cc";
StringBuilder sb = new StringBuilder();
sb.Append(command);
sb.Append(id);
2023-03-06 04:52:55 +00:00
sb.Append(Helper.StringBlankFillDigits4(data.Length.ToString()));
2023-02-09 08:20:49 +00:00
sb.Append(address);
sb.Append(data);
chkSum = this.Checksumcalculator(sb.ToString());
sb.Append(chkSum);
if (this.smartSerialPortLink.IsOpen == true)
this.smartSerialPortLink.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);
// 통신 확인 로그
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.StringType.Write(string.Format("Send ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, sb.ToString()));
return ret;
}
public int TransferDataStream4(string command, string id, string address, string data)
{
int ret = 0;
string chkSum = "cc";
StringBuilder sb = new StringBuilder();
sb.Append(command);
sb.Append(id);
2023-03-06 04:52:55 +00:00
sb.Append(Helper.StringBlankFillDigits4("4"));
2023-02-09 08:20:49 +00:00
sb.Append(address);
2023-03-06 04:52:55 +00:00
sb.Append(Helper.StringBlankFillDigits4(data));
2023-02-09 08:20:49 +00:00
chkSum = this.Checksumcalculator(sb.ToString());
sb.Append(chkSum);
if (this.smartSerialPortLink.IsOpen == true)
this.smartSerialPortLink.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);
// 통신 확인 로그
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.StringType.Write(string.Format("Send ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, sb.ToString()));
return ret;
}
public int TransferDataStream6(string command, string id, string address, string data)
{
int ret = 0;
string chkSum = "cc";
StringBuilder sb = new StringBuilder();
sb.Append(command);
sb.Append(id);
2023-03-06 04:52:55 +00:00
sb.Append(Helper.StringBlankFillDigits4("6"));
2023-02-09 08:20:49 +00:00
sb.Append(address);
2023-03-06 04:52:55 +00:00
sb.Append(Helper.StringBlankFillDigits6(data));
2023-02-09 08:20:49 +00:00
chkSum = this.Checksumcalculator(sb.ToString());
sb.Append(chkSum);
if (this.smartSerialPortLink.IsOpen == true)
this.smartSerialPortLink.WriteFrame(sb.ToString(), SmartSerialPort.CODETYPES.ASCIICODE);
// 통신 확인 로그
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.StringType.Write(string.Format("Send ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, sb.ToString()));
return ret;
}
private void ReceiveData()
{
int ret = 0;
string strTemp = "";
byte[] readByte;
SmartSerialPort.FRAMEDATAREADSTATUS receiveDataState = SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY;
try
{
receiveDataState = this.smartSerialPortLink.ReadQueue(out readByte);
strTemp = Encoding.Default.GetString(readByte, 0, readByte.Length);
}
catch
{
return;
}
if ((receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.EMPTY) || (receiveDataState == SmartSerialPort.FRAMEDATAREADSTATUS.FAILDATA))
{
return;
}
try
{
switch (strTemp[0])
{
case 'C':
if ((ret = this.ReceiveCommandC(strTemp)) != 0)
return;
break;
case 'P':
if ((ret = this.ReceiveCommandP(strTemp)) != 0)
return;
break;
case 'S':
if ((ret = this.ReceiveCommandS(strTemp)) != 0)
return;
break;
default:
break;
}
}
catch
{
}
}
private int ReceiveCommandC(string strTemp)
{
int ret = 0;
string cmd = "", data = "";
if (this.ChksumCheck(strTemp) == false)
{
// 로그
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Command Data CHKSUM Error", DateTime.Now, strTemp));
return ret = -1;
}
// 로그
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));
cmd = strTemp.Substring(0, 3);
switch (cmd)
{
case "CI0":
this.EquipmentStatus = Define.E_EquipmentStatus.Stop;
this.ChildFormMainDisplay.UpdateEquipmentStatusDisplay(this.EquipmentStatus);
this.TransferSystemParameter9039();
2023-02-09 08:20:49 +00:00
break;
case "CBS":
this.EquipmentStatus = DataStore.Define.E_EquipmentStatus.Start;
this.ChildFormMainDisplay.UpdateEquipmentStatusDisplay(this.EquipmentStatus);
break;
case "CBT":
this.EquipmentStatus = Define.E_EquipmentStatus.Stop;
this.ChildFormMainDisplay.UpdateEquipmentStatusDisplay(this.EquipmentStatus);
break;
default:
break;
}
return ret;
}
private int ReceiveCommandP(string strTemp)
{
int ret = 0;
string cmd = "", address = "", lane = "", receiveData = "";
// SIZE 확인
if (this.SizeCheck("P", strTemp) == false)
{
// 로그
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Stream Data SIZE Error", DateTime.Now, strTemp));
return ret = -1;
}
// CHKSUM 확인
if (this.ChksumCheck(strTemp) == false)
{
// 로그
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Stream Data CHKSUM Error", DateTime.Now, strTemp));
return ret = -1;
}
// 로그
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));
cmd = strTemp.Substring(0, 3);
lane = strTemp.Substring(5, 1);
address = strTemp.Substring(10, 4);
receiveData = strTemp.Substring(14, strTemp.Length - 16);
switch (cmd)
{
case "PR0":
if ((ret = this.ReceiveCommandPR0(lane, address, receiveData)) != 0)
return ret = -1;
break;
case "PW0":
if ((ret = this.ReceiveCommandPW0(lane, address, receiveData)) != 0)
return ret = -1;
break;
default:
break;
}
return ret;
}
private int ReceiveCommandS(string strTemp)
{
int ret = 0;
string cmd = "", lane = "", receiveData = "";
// SIZE 확인
if (this.SizeCheck("S", strTemp) == false)
{
// 로그
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Stream Data SIZE Error", DateTime.Now, strTemp));
return ret = -1;
}
// CHKSUM 확인
if (this.ChksumCheck(strTemp) == false)
{
// 로그
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1} : Receive Stream Data CHKSUM Error", DateTime.Now, strTemp));
return ret = -1;
}
// 로그
if (this.IsCommunicationLogOpen == true)
this.smartFileCommunicationLog.StringType.Write(string.Format("Receive ({0:yyyy-MM-dd HH:mm:ss}): {1}", DateTime.Now, strTemp));
cmd = strTemp.Substring(0, 3);
lane = strTemp.Substring(5, 1);
receiveData = strTemp.Substring(10, strTemp.Length - 12);
switch (cmd)
{
case "SLA":
if ((ret = this.ReceiveCommandSLA(lane, receiveData)) != 0)
2023-02-09 08:20:49 +00:00
return ret;
break;
case "SLB":
if ((ret = this.ReceiveCommandSLB(lane, receiveData)) != 0)
return ret;
break;
case "SLC":
if ((ret = this.ReceiveCommandSLC(lane, receiveData)) != 0)
return ret;
break;
case "SLD":
if ((ret = this.ReceiveCommandSLD(lane, receiveData)) != 0)
return ret;
break;
case "SLE":
if ((ret = this.ReceiveCommandSLE(lane, receiveData)) != 0)
2023-02-09 08:20:49 +00:00
return ret;
break;
case "ST0":
if ((ret = this.ReceiveCommandST0(lane, receiveData)) != 0)
return ret;
break;
case "SA0":
if ((ret = this.ReceiveCommandSA0(lane, receiveData)) != 0)
return ret;
break;
default:
break;
}
return ret;
}
// 파라미터 읽기 응답
private int ReceiveCommandPR0(string lane, string address, string receiveData)
{
int ret = 0, iValue = 0;
try
{
switch (address)
{
case "2001":
#region Value Assign
iValue = int.Parse(receiveData);
if (iValue <= 0 || iValue > 1000)
return ret = -1;
this.SystemConfig.RECIPE_NUMBER = iValue;
#endregion
this.LoadRecipeFile(ref this.CurrentRecipe, this.SystemConfig.RECIPE_NUMBER - 1);
this.ChildFormMenu.UpdateDisplayRecipeData(this.CurrentRecipe);
break;
2023-02-09 08:20:49 +00:00
default:
break;
}
}
catch
{
ret = -1;
}
return ret;
}
// 파라미터 쓰기 응답
private int ReceiveCommandPW0(string lane, string address, string receiveData)
{
int ret = 0;
DataStore.Define.E_ResponseData response = DataStore.Define.E_ResponseData.NAK;
try
{
switch (address)
{
case "9039":
if (response == Define.E_ResponseData.ACK)
this.TransferRecipeParameter9043(this.SystemConfig.RECIPE_NUMBER);
break;
case "9043":
if (response == Define.E_ResponseData.ACK)
this.TransferDataStream(CommunicationCommand.Read, CommunicationID.MainBoard, CommunicationAddress._2001_ProductNumber, "");
2023-02-09 08:20:49 +00:00
break;
default:
break;
}
}
catch
{
ret = -1;
}
return ret;
}
// 판정 데이터
private int ReceiveCommandSLA(string lane, string receiveData)
2023-02-09 08:20:49 +00:00
{
int ret = 0;
try
{
switch (lane)
{
case "Z":
#region Value Assign
for (int i = 0; i < this.EquipmentColumn; i++)
this.CurrentLeakData.CollJudgment[i] = Helper.StringToJudgmentStatus(receiveData.Substring(i * 1, 1));
2023-02-09 08:20:49 +00:00
#endregion
this.ChildFormMainDisplay.UpdateDisplayJudgmentData(this.CurrentLeakData);
2023-02-09 08:20:49 +00:00
break;
default:
break;
}
}
catch
{
ret = -1;
}
return ret;
}
// 진행상태
private int ReceiveCommandSLB(string lane, string receiveData)
2023-02-09 08:20:49 +00:00
{
int ret = 0;
try
{
switch (lane)
{
case "Z":
2023-02-09 08:20:49 +00:00
#region Value Assign
this.CurrentLeakData.ProcessStatus = Helper.StringToProcessStatus(receiveData.Substring(0, 1));
2023-02-09 08:20:49 +00:00
#endregion
this.ChildFormMainDisplay.UpdateProcessStatusDisplay(this.CurrentLeakData.ProcessStatus);
2023-02-09 08:20:49 +00:00
break;
default:
2023-02-09 08:20:49 +00:00
break;
}
}
catch
{
ret = -1;
}
return ret;
}
// 차압 센서 데이터
private int ReceiveCommandSLC(string lane, string receiveData)
{
int ret = 0;
try
{
switch (lane)
{
case "Z":
2023-02-09 08:20:49 +00:00
#region Value Assign
for (int i = 0; i < this.EquipmentColumn; i++)
{
this.CurrentLeakData.CollDiffData[i].MAdc = receiveData.Substring(i * 32, 8).Trim();
this.CurrentLeakData.CollDiffData[i].SecBufDiff = receiveData.Substring((i * 32) + 8, 8).Trim();
this.CurrentLeakData.CollDiffData[i].SecBufSum = receiveData.Substring((i * 32) + 16, 8).Trim();
this.CurrentLeakData.CollDiffData[i].DiffMean = receiveData.Substring((i * 32) + 24, 8).Trim();
}
2023-02-09 08:20:49 +00:00
#endregion
this.ChildFormMainDisplay.UpdateDisplayDiffData(this.CurrentLeakData.CollDiffData);
2023-02-09 08:20:49 +00:00
break;
default:
2023-02-09 08:20:49 +00:00
break;
}
}
catch
{
ret = -1;
}
return ret;
}
// 변위 센서 데이터
private int ReceiveCommandSLD(string lane, string receiveData)
{
int ret = 0;
try
{
switch (lane)
{
2023-02-09 08:20:49 +00:00
case "Z":
#region Value Assign
for (int i = 0; i < this.EquipmentColumn; i++)
2023-02-09 08:20:49 +00:00
{
this.CurrentLeakData.CollDispData[i].RData = receiveData.Substring(i * 24, 6).Trim();
this.CurrentLeakData.CollDispData[i].MData = receiveData.Substring((i * 24) + 6, 6).Trim();
this.CurrentLeakData.CollDispData[i].MDataDiff = receiveData.Substring((i * 24) + 12, 6).Trim();
this.CurrentLeakData.CollDispData[i].STD = receiveData.Substring((i * 24) + 18, 6).Trim();
2023-02-09 08:20:49 +00:00
}
#endregion
this.ChildFormMainDisplay.UpdateDisplayDispData(this.CurrentLeakData.CollDispData);
2023-02-09 08:20:49 +00:00
break;
default:
break;
}
}
catch
{
ret = -1;
}
return ret;
}
// 압력 데이터
private int ReceiveCommandSLE(string lane, string receiveData)
{
int ret = 0;
return ret;
}
2023-02-09 08:20:49 +00:00
// IO테스트-IN
private int ReceiveCommandST0(string lane, string receiveData)
{
int ret = 0;
switch (lane)
{
case "0":
#region Value Assign
//for (int i = 0; i < 15; i++)
// this.CollectionIOTest_InputData[i] = receiveData.Substring(i, 1);
#endregion
//if (this.SystemConfig.CurrentForm == DataStore.FormStore.FormIOTest)
// this.ChildFormIOTest.UpdateInputRead(this.CollectionIOTest_InputData);
break;
default:
break;
}
return ret;
}
// 알람
private int ReceiveCommandSA0(string lane, string receiveData)
{
int ret = 0;
switch (lane)
{
case "0":
#region Value Assign
//this.CurrentAlarmList.SetAlarm(receiveData.Substring(0, 8));
#endregion
//this.ChildFormMainDisplay.UpdateDisplayAlarmView(this.CurrentAlarmList);
break;
default:
break;
}
return ret;
}
#endregion
#endregion
#region Override Member
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// 변수 초기 셋팅
this.DefaultSetting();
// SystemConfiguration 파일 읽기
this.LoadSystemConfigurationFile();
2023-03-06 04:52:55 +00:00
// Recipe 파일 읽기
this.LoadRecipeFile(ref this.CurrentRecipe, this.SystemConfig.RECIPE_NUMBER - 1);
2023-02-09 08:20:49 +00:00
// Form 생성
this.CreateForm();
// 통신 OPEN
this.OpenSmartUartLink();
this.smartForm1.Show(1);
// 초기 파라미터 전송
this.TransferSystemParameter9039();
2023-02-09 08:20:49 +00:00
// 화면 시계 표시 타이머
this.timer.Enabled = true;
}
#endregion
#region Event Handler
private void smartSerialPortLink_OnReadQueueEvent()
{
this.ReceiveData();
// 통신 확인
if (this.CommunicationCheckCount / 3 == 1)
{
if (this.ChildFormMainDisplay != null)
this.ChildFormMainDisplay.labelCommunicationStatus.Visible = true;
this.CommunicationCheckCount = 0;
}
else
{
if (this.ChildFormMainDisplay != null)
this.ChildFormMainDisplay.labelCommunicationStatus.Visible = false;
this.CommunicationCheckCount += 1;
}
}
private void smartButton1_Click(object sender, EventArgs e)
{
this.smartForm1.Show(2);
}
private void smartButton2_Click(object sender, EventArgs e)
{
this.smartForm1.Show(1);
}
private void timer_Tick(object sender, EventArgs e)
{
this.ChildFormMainDisplay.UpdateDisplayTime();
}
#endregion
}
}