123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.IO;
- using System.Collections.Concurrent;
- using System.Threading;
- using System.Timers;
- namespace BEMSDataGateway
- {
-
- public partial class Form1 : Form
- {
- //event 부분 추가 . 20161209
- //EventWaitHandle ewhLoginSuccess = new EventWaitHandle(false, EventResetMode.ManualReset, "Login.Success");
- //EventWaitHandle ewhLoginFail = new EventWaitHandle(false, EventResetMode.ManualReset, "Login.Fail");
- //EventWaitHandle ewhDisconnect = new EventWaitHandle(false, EventResetMode.ManualReset, "Connect.Fail");
- bool startOk = false;
- public bool bConnect;
- ////서로 다른 두 스레드(ResponseFunc와 Form)의 충돌을 피하기 위해 델리게이트 사용.
- ////ResponseFunc에서 오류 발생시 델리게이트를 통해 Log를 출력함
- //delegate void CrossThreadSafetySetErrorCodeTxt(string text);
- //private void SetText(string text)
- //{
- // if (this.LogTxt.InvokeRequired)
- // {
- // CrossThreadSafetySetErrorCodeTxt d = new CrossThreadSafetySetErrorCodeTxt(SetText);
- // this.Invoke(d, text );
- // //this.Invoke(d, text);
- // }
- // else
- // {
- // this.LogTxt.Text = text;
- // }
- //}
- // public delegate void ErrorFunc(int nErrorCode);
- //결과 학인 콜백 함수 이름변경(ErrorFunc -> ResponseFunc) 및 static 삭제 swpark 2016.12.01
- public delegate int ErrorFunc(int nErrorCode);//선언위치 변경 swpark 20161209
- public ErrorFunc _errfunc;// 선언위치변경 swpark 20161209
- public static int ResponseFunc(int nErrorCode)
- {
- LogFileCreate LFC = new LogFileCreate();
- Form1 F1 = new Form1();
- // nErrorCode 정보
- // 1 : 서버 연결 성공
- // 2 : 연결 끊어짐
- // 3 : 프로젝트 다운로드 완료
- // 4 : 로그인 성공
- // 5 : 로그인 실패
- // 100~ : 기타 오류
- switch (nErrorCode)
- {
- case 1:
- LFC.Log("서버에 연결 성공 = " + nErrorCode);
- //this.SetText("서버에 연결 성공 = " + Convert.ToString(DateTime.Now) + Environment.NewLine);
- break;
- case 2:
- LFC.Log("서버에 의해서 소켓 연결이 끊어졌습니다 = " + nErrorCode);
- //CloseConnection();
- //SetText("서버에 의해서 소켓 연결이 끊어졌습니다 = " + Convert.ToString(DateTime.Now) + Environment.NewLine);
- //CloseConnection();
- break;
- case 3:
- LFC.Log("프로젝트 다운로드를 완료했습니다. = " + nErrorCode);
-
- UserLogin("bems_gw", "1", true);
- //this.SetText("프로젝트 다운로드를 완료했습니다. = " + Convert.ToString(DateTime.Now) + Environment.NewLine);
- break;
- case 4:
- //System.Threading.Thread.Sleep(2000);
- LFC.Log("서버 로그인에 성공했습니다. = " + nErrorCode);
- My_TimerThread.check = false;
- F1.ReadTag();
-
- //this.SetText("서버 로그인에 성공했습니다.. = " + Convert.ToString(DateTime.Now) + Environment.NewLine);
- break;
- case 5:
- LFC.Log("알 수 없는 에러로 연결이 끊겼습니다. = " + nErrorCode);
- //this.SetText("알 수 없는 에러로 연결이 끊겼습니다. = " + Convert.ToString(DateTime.Now) + Environment.NewLine);
- //CloseConnection();
- break;
- default:
- LFC.Log("서버 로그인에 실패했습니다. 연결을 종료합니다. = " + nErrorCode);
-
- //this.SetText("서버 로그인에 실패했습니다. 연결을 종료합니다. = " + Convert.ToString(DateTime.Now) + Environment.NewLine);
- //CloseConnection();
- break;
- }
-
- return nErrorCode;
- }
- //public delegate void MonitoringTag(string szTag, float fValue);
- //public delegate void MonitoringPacket([MarshalAs(UnmanagedType.LPArray, SizeConst = 8192)] byte[] bPacket);
- // 접속정보 전달용 구조체 (마샬링)
- public struct runMode
- {
- public UInt32 uNetType;
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
- public String szRunIp;
- public UInt32 uRunPort;
- public UInt32 uRunScan;
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
- public String szServer2;
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
- public String szHaIp;
- public UInt32 uHaPort;
- public UInt32 uHaScan;
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
- public String szUser;
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
- public String szPassword;
- }
- public struct DBInfo
- {
- public UInt32 uDbType;//0 : MDB. 1 : MSSQL
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
- public String szDBPath;//MDB 파일 위치 값이 없으면 실행파일위치에서 하위 Project\DB\iCos4.mdb 를 읽어옴
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
- public String szSqlIP; //MSSQL IP주소
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
- public String szSqlDB; //MSSQL DB명
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
- public String szSqlID; //MSSQL ID
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
- public String szSqlPW; //MSSQL PASSWORD
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
- public String szDbAddr; //
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 255)]
- public String szDbTable; //DB 테이블명
- }
- // 접속 초기화 함수
- [DllImport("ICosSocket.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern bool InitSocket(string szUser, string szPassword, bool bLogout);
- //접속정보 설정
- [DllImport("ICosSocket.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern void SetNetwork(ref runMode tRunMode);
- // DB정보 설정
- [DllImport("ICosSocket.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern void SetDBInfo(ref DBInfo tDBInfo);
- // 태그값 등록 함수
- [DllImport("ICosSocket.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern void RegTag(int nTagCnt, string szTag);
- // 태그값 등록해제 함수
- [DllImport("ICosSocket.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern void UnregTag(int nTagCnt, string szTag);
- // 디바이스 태그 DB 설정
- [DllImport("ICosSocket.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern void SetDeviceDB(int nDBType, string szDBPath);
- // 디바이스 태그 값 가져오기
- [DllImport("ICosSocket.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern float GetTagValue(string szTag);
- // 디바이스 태그 값 쓰기
- [DllImport("ICosSocket.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern float SetTagValue(string szTag, float fValue);
- // 로그인 전용 함수
- [DllImport("ICosSocket.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern bool UserLogin(string szUser, string szPassword, bool bLogout);
- // 로그아웃 전용 함수
- [DllImport("ICosSocket.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern bool UserLogout(string szUser);
- // 접속 초기화 함수
- [DllImport("ICosSocket.dll")]
- public static extern void CloseConnection();
- // 결과확인 함수 포인터 전달 함수
- [DllImport("ICosSocket.dll", EntryPoint = "SetErrorFunc")]
- public static extern void SetErrorFunc(ErrorFunc x);
- //[DllImport("ICosSocket.dll", EntryPoint = "SetPacketFunc")]
- //public static extern void SetPacketFunc(MonitoringPacket x);
- //[DllImport("ICosSocket.dll", EntryPoint = "SetMonitoringFunc")]
- //public static extern void SetMonitoringFunc(MonitoringTag x);
- // 변수추가 szText swpark 2016.12.01
- //public static void MonitoringTag(string szTag, float fValue, string szText)
- //{
- // string str;
- // str = szTag + " : " + fValue.ToString();
- //}
- // iCos4 네트워크 상태
- // NetworkStatus 정보
- // 0 : 연결안됨
- // 1 : 정상상태
- [DllImport("ICosSocket.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern int GetNetworkStatus();
- public string iCosFourConn()
- {
- string strRet = "";
- string Result_Conn_iCos = "";
- Readini Ri = new Readini();
- Ri.ReadData(); // ini의 설정값을 불러옴.
- LogTxt.Text += "iCos 에 접속중입니다. 기다려주세요...." + Environment.NewLine;
- runMode tRunMode = new runMode();
- tRunMode.szRunIp = Ri.IP1;
- tRunMode.szHaIp = Ri.DGW_IP;
- tRunMode.szServer2 = Ri.Ip2;
- tRunMode.uNetType = 7; //TYPE_CLIENT_ONLY
- tRunMode.uRunPort = 6000;
- tRunMode.uRunScan = 3000;
- tRunMode.uHaPort = 2;
- tRunMode.uHaScan = 1;
- tRunMode.szUser = "bems_gw";
- tRunMode.szPassword = "1";
- try
- {
- SetNetwork(ref tRunMode);
- //ErrorFunc _errfunc = new ErrorFunc(ResponseFunc); //응답처리함수 swpark 2016.12.01
- _errfunc = new ErrorFunc(ResponseFunc);
-
- SetErrorFunc(_errfunc); //콜백 함수 넘겨주는 방식 변경 (웹서버용 함수) swpark 2016.12.01
- //SetMonitoringPointValueFunc(_monitorvalue);//모니터링값 수신 함수 콜백 연결 웹서버용
-
-
- bool bRet = InitSocket("bems_gw", "1", true);
-
- strRet = bRet.ToString();
- LogTxt.Text += "iCos 접속 함수 동작 시작 : " + Convert.ToString(strRet) + " = " + Convert.ToString(DateTime.Now) + Environment.NewLine;
- Result_Conn_iCos = "SUCCESS";
- }
- catch(Exception e)
- {
- LogTxt.Text += "iCos 접속완료 여부 : 실패하였습니다. = " + Convert.ToString(DateTime.Now) + e + Environment.NewLine ;
- Result_Conn_iCos = "FAIL";
- }
- return Result_Conn_iCos;
-
- }
-
- public void iCosFourReadDB()
- {
- SetDeviceDB(0, "C:\\DGW2.0\\Release\\Project\\DB\\iCos4.mdb");
- }
- string[] ReturnTag = new string[2];
- public void ReadTag()
- {
- timerstart_readTag();
- }
- System.Timers.Timer timer2 = new System.Timers.Timer();
- public void timerstart_readTag()
- {
- timer2.Interval = 3000;
- timer2.Elapsed += new ElapsedEventHandler(timer2_Elapsed);
- timer2.Start();
- }
- bool Check_reconn = false;
- public void timer2_Elapsed(object sender, ElapsedEventArgs e) // 1분마다 실행되는 데이터 수집 로직
- {
- if (Check_reconn == false)
- {
- Check_reconn = true;
- System.Threading.Thread.Sleep(5000);
- Parsing Ps = new Parsing();
- ReturnTag = Ps.TagParsing();
- RegTag(Convert.ToInt32(ReturnTag[1]), ReturnTag[0]);
- LogFileCreate LFC = new LogFileCreate();
- LFC.Log("포인트 등록완료");
- Check_reconn = false;
- timer2.Stop();
- timer2.Enabled = false;
-
- }
- }
- public void UnReg()
- {
- Parsing Ps = new Parsing();
- ReturnTag = Ps.TagParsing();
- UnregTag(Convert.ToInt32(ReturnTag[1]), ReturnTag[0]);
- }
- //public void GetValue()
- //{
- // float fval;
- // fval = GetTagValue("ch.ctrl.tag1");
- // //string strRet;
- // //strRet = fval.ToString();
- // //MessageBox.Show(strRet);
- //}
-
- My_TimerThread TTs = new My_TimerThread();
- static string SelecDir;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- ProStopBtn.Enabled = false;
- PointSetBtn.Enabled = false;
- PointUnRegBtn.Enabled = false;
- ProStartBtn.Enabled = false;
- ProStopBtn.Enabled = false;
-
- Shown += Form1_Shown;
- }
- System.Timers.Timer timer_NetStat = new System.Timers.Timer();
- LogFileCreate LFC = new LogFileCreate();
- public void Timer_netStat()
- {
- timer_NetStat.Interval = 5000;
- timer_NetStat.Elapsed += new ElapsedEventHandler(net_state_Thread);
- timer_NetStat.Start();
- }
- private delegate void myDelegate(string theValue);
- private void Wirte_Communicaion_State(string theValue)
- {
- try
- {
- LFC.Log(theValue + "= 들어온 통신상태");
- if (theValue == "1")
- {
- Net_Stat.BackColor = Color.LightSkyBlue;
- Net_Stat.Text = "통신중";
- }
- else if (theValue == "0")
- {
- Net_Stat.BackColor = Color.Red;
- Net_Stat.Text = "통신끊김";
- }
- }
- catch(Exception E)
- {
- LFC.Log(Convert.ToString(E));
- LogTxt.Text += Convert.ToString(E)+ Environment.NewLine;
- }
- }
- public void net_state_Thread(object sender, ElapsedEventArgs e)
- {
- try
- {
- //Net_Stat.BackColor = Color.LemonChiffon;
- int nNet;
- nNet = GetNetworkStatus();
- string strRet;
- strRet = nNet.ToString();
-
- this.Invoke(new myDelegate(Wirte_Communicaion_State), new object[] { strRet });
- }
- catch (Exception E)
- {
- LFC.Log(Convert.ToString(E));
- LogTxt.Text += Convert.ToString(E) + Environment.NewLine;
- }
- }
-
- private void Form1_Shown(object sender, EventArgs e)
- {
-
- LogFileCreate LFC = new LogFileCreate();
- string ReturnValue = iCosFourConn();
- iCosFourReadDB();
- LFC.Log("접속 함수 동작 시작 = " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- LogTxt.Text += "접속 함수 동작 시작 = " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Environment.NewLine;
- if (ReturnValue == "SUCCESS")
- {
- LogTxt.Text += "접속 성공 = " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Environment.NewLine;
- PointSetBtn.Enabled = true;
- PointUnRegBtn.Enabled = true;
- ProStartBtn.Enabled = true;
- }
- SetDeviceDB(0, "");
- //ReadTag();
-
- try
- {
- //Creating_Setting_File CSF = new Creating_Setting_File();
- //CSF.Create_Setting_Point_File();
- EndTxt.Clear();
- //TTs.timer1start();
- ProStartBtn.Enabled = false; // 시작버튼 비활성화.
- StartTxt.Text = Convert.ToString(DateTime.Now);
- LogTxt.Text += "프로그램 시작 " + Convert.ToString(DateTime.Now) + Environment.NewLine;
- ProStopBtn.Enabled = true;
- FileSettingBtn.Enabled = false;
- FileMatchBtn.Enabled = false;
- FileExpBtn.Enabled = false;
- FirstCheck FC = new FirstCheck();
- FC.Check_DailyData();
- OneMinute_Insert OMI = new OneMinute_Insert();
- OMI.Today_PeakMinMax();
- OMI.Year_PeakMinMax();
- My_TimerThread MTT = new My_TimerThread();
- MTT.timer2start();
- //Timer_netStat();
- }
- catch (Exception eProStart)
- {
- LogTxt.Text += "프로그램 오류 " + Convert.ToString("DB에 접속되지 않았습니다.") + " " + eProStart + " = " + Convert.ToString(DateTime.Now) + Environment.NewLine;
- }
- }
- //private static DateTime Delay(int MS)
- //{
- // DateTime ThisMoment = DateTime.Now;
- // TimeSpan duration = new TimeSpan(0, 0, 0, 0, MS);
- // DateTime AfterWards = ThisMoment.Add(duration);
- // while (AfterWards >= ThisMoment)
- // {
- // System.Windows.Forms.Application.DoEvents();
- // ThisMoment = DateTime.Now;
- // }
- // return DateTime.Now;
- //}
- private void ProStartBtn_Click(object sender, EventArgs e)
- {
- if (toolStripStatusLabel1.Text != "")
- {
- try
- {
-
- //Creating_Setting_File CSF = new Creating_Setting_File();
- //CSF.Create_Setting_Point_File();
-
- EndTxt.Clear();
- //TTs.timer1start();
- ProStartBtn.Enabled = false; // 시작버튼 비활성화.
- StartTxt.Text = Convert.ToString(DateTime.Now);
- LogTxt.Text += "프로그램 시작 " + Convert.ToString(DateTime.Now) + Environment.NewLine;
- ProStopBtn.Enabled = true;
- FileSettingBtn.Enabled = false;
- FileMatchBtn.Enabled = false;
- FileExpBtn.Enabled = false;
-
- FirstCheck FC = new FirstCheck();
- FC.Check_DailyData();
- OneMinute_Insert OMI = new OneMinute_Insert();
- OMI.Today_PeakMinMax();
- OMI.Year_PeakMinMax();
- My_TimerThread MTT = new My_TimerThread();
- MTT.timer2start();
- }
- catch (Exception eProStart)
- {
- LogTxt.Text += "프로그램 오류 " + Convert.ToString("DB에 접속되지 않았습니다.") + " " + eProStart + " = " + Convert.ToString(DateTime.Now) + Environment.NewLine;
- }
- }
- else
- MessageBox.Show("경로를 설정해주세요");
- }
- private void ProStopBtn_Click(object sender, EventArgs e)
- {
- CloseConnection();
- TTs.timer2Stop();
- FileSettingBtn.Enabled = true;
- FileMatchBtn.Enabled = true;
- FileExpBtn.Enabled = true;
-
- ProStartBtn.Enabled = true;
- EndTxt.Text = Convert.ToString(DateTime.Now);
- LogTxt.Text += "프로그램 중단 " + " = " + Convert.ToString(DateTime.Now) + Environment.NewLine;
- ProStopBtn.Enabled = false;
- }
- private void ProSetBtn_Click(object sender, EventArgs e)
- {
- SettingForm SF = new SettingForm();
- SF.ShowDialog();
- }
- private void ProPathBtn_Click_1(object sender, EventArgs e)
- {
- FolderBrowserDialog();
- }
- /// <summary>
- /// 셋팅파일 불러오기 버튼
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void FileSettingBtn_Click(object sender, EventArgs e)
- {
- string FSBLocation = Environment.CurrentDirectory + "\\Login.ini";
- try
- {
- System.Diagnostics.Process.Start(FSBLocation);
- }
- catch
- {
- FileError(FSBLocation);
- }
- }
- /// <summary>
- /// 매칭파일 불러오기 버튼
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void FileMatchBtn_Click(object sender, EventArgs e)
- {
- string FSBLocation = Environment.CurrentDirectory + "\\SettingFile.csv";
- try
- {
- System.Diagnostics.Process.Start(FSBLocation);
- }
- catch
- {
- FileError(FSBLocation);
- }
- }
- /// <summary>
- /// 수식파일 불러오기 버튼
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void FileExpBtn_Click(object sender, EventArgs e)
- {
- string FSBLocation = Environment.CurrentDirectory + "\\Expression.csv";
- try
- {
- System.Diagnostics.Process.Start(FSBLocation);
- }
- catch
- {
- FileError(FSBLocation);
- }
- }
- public void FileError(string Error)
- {
- if ((!Error.Contains("Login.ini")) || (!Error.Contains("expression.csv")) || (!Error.Contains("Matching.csv")))
- {
- MessageBox.Show("파일을 찾을 수 없습니다.");
- }
- }
- public string FolderBrowserDialog()
- {
-
- LogFileCreate LFC = new LogFileCreate();
- FolderBrowserDialog folderDig = new FolderBrowserDialog();
- folderDig.ShowNewFolderButton = true;
-
- // Show the FolderBrowserDialog.
- DialogResult result = folderDig.ShowDialog();
- if (result == DialogResult.OK)
- {
- SelecDir = folderDig.SelectedPath;
- Environment.SpecialFolder root = folderDig.RootFolder;
- toolStripStatusLabel1.Text = "프로젝트 경로 : " + Environment.CurrentDirectory;
- LogTxt.Text += "경로설정완료 " + SelecDir + " " + Convert.ToString(DateTime.Now) + Environment.NewLine;
- LFC.Log("경로 설정 완료" + SelecDir);
- }
- return SelecDir;
- }
-
- private void EraseLog_Click(object sender, EventArgs e)
- {
- LogTxt.Clear();
- }
-
- // 프로그램 종료시 이벤트
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- LogFileCreate LFC = new LogFileCreate();
- if (MessageBox.Show("프로그램을 종료하시겠습니까?", "종료", MessageBoxButtons.YesNo) != DialogResult.Yes)
- {
- LFC.Log("사용자에 의해 프로그램 종료가 취소되었습니다. = " + Convert.ToString(DateTime.Now));
- e.Cancel = true;
- }
- else
- {
- LFC.Log("사용자에 의해 프로그램이 종료되었습니다. = " + Convert.ToString(DateTime.Now));
- }
-
- }
- private void PointSetBtn_Click(object sender, EventArgs e)
- {
- //iCosFourDBSET();
- ReadTag();
- //UnReg();
- }
- private void Conn_iCos_Btn_Click(object sender, EventArgs e)
- {
-
- //Thread thread_tLS = new Thread(threadLoginSuccess);
- //thread_tLS.IsBackground = true;
- //thread_tLS.Start();
- //Thread thread_tLF = new Thread(threadLoginFail);
- //thread_tLF.IsBackground = true;
- //thread_tLF.Start();
- //Thread thread_tCF = new Thread(threadConnectFail);
- //thread_tCF.IsBackground = true;
- //thread_tCF.Start();
- LogFileCreate LFC = new LogFileCreate();
- string ReturnValue = iCosFourConn();
- iCosFourReadDB();
- LFC.Log("접속 함수 동작 시작 = " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- LogTxt.Text += "접속 함수 동작 시작 = " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Environment.NewLine;
- if (ReturnValue == "SUCCESS")
- {
- LogTxt.Text += "접속 성공 = " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Environment.NewLine;
- PointSetBtn.Enabled = true;
- PointUnRegBtn.Enabled = true;
- ProStartBtn.Enabled = true;
-
- }
- SetDeviceDB(0, "");
- }
- //서로 다른 두 스레드(ResponseFunc와 Form)의 충돌을 피하기 위해 델리게이트 사용.
- //ResponseFunc에서 오류 발생시 델리게이트를 통해 Log를 출력함
- delegate void CrossThreadSafetySetErrorCodeTxt(string text);
- private void SetText(string text)
- {
- if (this.LogTxt.InvokeRequired)
- {
- CrossThreadSafetySetErrorCodeTxt d = new CrossThreadSafetySetErrorCodeTxt(SetText);
- this.Invoke(d, text);
- //this.Invoke(d, text);
- }
- else
- {
- this.LogTxt.Text = text;
- }
- }
- //void threadLoginSuccess(object state)
- //{
- // //int count = 0;
- // while (ewhLoginSuccess.WaitOne()) // 이벤트 대기
- // {
- // ewhLoginSuccess.Reset(); // ManualReset으로 설정했으므로 Reset 명시
-
- // this.SetText("로그인 성공 = " + Convert.ToString(DateTime.Now) + Environment.NewLine);
- // }
- //}
- //void threadLoginFail(object state)
- //{
- // //int count = 0;
- // while (ewhLoginFail.WaitOne()) // 이벤트 대기
- // {
- // ewhLoginFail.Reset(); // ManualReset으로 설정했으므로 Reset 명시
- // this.SetText("로그인 실패 = " + Convert.ToString(DateTime.Now) + Environment.NewLine);
- // }
- //}
- //void threadConnectFail(object state)
- //{
- // //int count = 0;
- // while (ewhDisconnect.WaitOne()) // 이벤트 대기
- // {
- // ewhDisconnect.Reset(); // ManualReset으로 설정했으므로 Reset 명시
- // this.SetText("연결 종료 = " + Convert.ToString(DateTime.Now) + Environment.NewLine);
- // }
- //}
- private void PointUnRegBtn_Click(object sender, EventArgs e)
- {
- UnReg();
- }
- private void Btn_TagSetFile_Click(object sender, EventArgs e)
- {
- Creating_Setting_File CSF = new Creating_Setting_File();
- CSF.Create_Point_File();
- }
- private void Btn_SettingFile_Click(object sender, EventArgs e)
- {
- Creating_Setting_File CSF = new Creating_Setting_File();
- CSF.Create_Setting_Point_File();
- }
-
- private void AllValueCheck_btn_Click(object sender, EventArgs e)
- {
- string[] sArray = File.ReadAllLines("TagSetFile.csv", Encoding.Default);
- LogTxt.Text += "*********** 현재 시간 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "**********" + Environment.NewLine;
- try
- {
- for (int i = 0; i < sArray.Length; i++) //
- {
- string[] tmp = sArray[i].Split(','); // tmp[0] = index, tmp[1] = Tag명.
- LogTxt.Text += tmp[1] + " 의 값 : " + GetTagValue(tmp[1]) + Environment.NewLine;
- }
- LogTxt.Text += "**************************************************************" + Environment.NewLine;
- //LogTxt.Text += "일괄 조회 종료";
- }
- catch (Exception er)
- {
- MessageBox.Show("오류 발생 = " + er);
- }
- }
- }
-
-
- }
|