//dll 통신 제어 tool using SocketCommDll_4CSharp.LoadControl; using System; using System.Runtime.ExceptionServices; using System.Security; namespace DemoUseDLL.DllSocket_Example { public class DllSocketDaekhon { /// /// dll socket 제어변수 /// private LoadDllTool DllSocket = null; /// /// 인터럽터 처리(DllSocket) /// private static object m_Locking = null; /// /// 생성자 /// /// 연결 상태 정보 호출 대리자 함수 /// 수신시 메세지를 전달 호출 대리자 /// 수신 메세지 저장 Queue 버퍼 사용 유무, 사용은 true public DllSocketDaekhon(DllConnectStatus dllConnecStatus, DllReceiveMessage dllReceive, bool bUseReceiveQueueBuffer) { m_Locking = new object(); DllSocket_Initialize("", dllConnecStatus, dllReceive, bUseReceiveQueueBuffer); } public DllSocketDaekhon(string strDllPath, DllConnectStatus dllConnecStatus, DllReceiveMessage dllReceive, bool bUseReceiveQueueBuffer) { m_Locking = new object(); DllSocket_Initialize(strDllPath, dllConnecStatus, dllReceive, bUseReceiveQueueBuffer); } /// /// 종료자 /// ~DllSocketDaekhon() { DllSocket_Unitialize(); } /// /// DllSocket 종료 처리 /// /// [HandleProcessCorruptedStateExceptions] [SecurityCritical] public bool DllSocket_Unitialize() { try { lock (m_Locking) { if (null != DllSocket) { bool ret = DllSocket.UnloadingDll(); DllSocket = null; return ret; } return true; } } catch (AccessViolationException e) { return true; } } /// /// DllSocket 초기화 /// /// dll path /// DllSocket 연결상태 대리자 /// DllSocket 통신 수신 대라자 /// 수신 메세지를 저장하는 Receive Queue 버퍼 사용 유무 설정 true이면 사용 /// 정상적으로 초기화 되면 true 반환 private bool DllSocket_Initialize(string strDllPath, DllConnectStatus dllConnectStatus, DllReceiveMessage dllReceive, bool bUseReceiveQueueBuffer) { lock (m_Locking) { if (null == DllSocket) { DllSocket = new LoadDllTool(); } if (null != DllSocket) { if (!DllSocket.Initialize(strDllPath + '\0', dllConnectStatus, dllReceive, bUseReceiveQueueBuffer)) { // 원래는 UnloadingDll()이 주석 처리 아니었음. dll 바뀌어서 그런건지 왜 그런건지.. DllSocket.UnloadingDll(); return false; } } return (null != DllSocket); } } /// /// DllSocket 초기화 여부 확인 함수 /// /// public bool DllSocket_IsIntialized() { lock (m_Locking) { if (null == DllSocket) { return false; } return DllSocket.GetDllStatus(); } } /// /// DllSocket ASCII Type, Binary Type, Invalid Type 반환 /// /// ASCII Type(1), Binary Type(0), Invalid Type(-1) public bool DllSocket_IsASCIITypeDll() { lock (m_Locking) { if (null != DllSocket) { return enASCIIBinaryType.ASCIITypeDll == DllSocket.IsASCIITypeDll(); } return false; } } /// /// DllSocket 연결 상태 반환 /// /// 연결이면 true public bool DllSocket_IsConnected() { lock (m_Locking) { return DllSocket.IsConnectedDll(); } } /// /// Dll Socket의 IP Config 설정창 Show/Hide /// /// show와 hide는 true와 false, 단, bToggleModeOnIstrue값이 false이면 적용됩니다. /// show hide toggle 모드 /// 정상처리되면 true public bool DllSocket_IPConfigToggleShow(bool bShowHide, bool bToggleModeOnIstrue) { lock (m_Locking) { if (null != DllSocket) { return DllSocket.ToggleViewHideIPConfigDll(bShowHide, bToggleModeOnIstrue); } return false; } } /// /// 통신 송신 함수(ASCII Type) /// /// 보내려는 문자열 /// 송신 성공이면 true public bool DllSocket_Send(string strSend) { lock (m_Locking) { if (null != DllSocket) { return DllSocket.Send(strSend + '\0'); } return false; } } /// /// 통신 송신 함수(BINARY Type) /// /// 보내려는 바이너리 타입 /// 송신 성공이면 true public bool DllSocket_Send(byte[] byteSend) { lock (m_Locking) { if (null != DllSocket) { return DllSocket.Send(byteSend); } return false; } } /// /// 비젼 데이터는 오른쪽 괄호안과 같이 정보 넘어갑니다.(->DLL->SPC 중계 프로그램->ECS ) /// /// 셀 ID 정보 /// csV 파일이 저장된 경로와 파일 이름 /// Title과 데이터가 합쳐진 문자열 /// 정상적으로 추가되면 true public bool DllSocket_AddToECS(string strCellID, string strFilePathAnaName, string strTitleAndData) { lock (m_Locking) { if (null != DllSocket) { return DllSocket.AddToECS(strCellID + '\0', strFilePathAnaName + '\0', strTitleAndData + '\0'); } return false; } } /// /// 수신받은 Qeueu 첫번째 message를 문자열로 수신받는 함수 /// /// 가장 최근에 수신받은 Message Return이면 true, 가장 과거에 수신받은 Message Return 이면 false /// 함수 호출과 동시에 남겨진 message가 있다면 모두 제거조건이면 true /// 수신받은 메세지를 문자열 형태로 반환 public string DllSocket_GetReceiveMessageInQueue(bool bLastReceiveReturn = false, bool bDeleteRemainQueueBuffer = false) { lock (m_Locking) { if (null != DllSocket) { return DllSocket.GetReceiveMessageInQueueBuffer(bLastReceiveReturn, bDeleteRemainQueueBuffer); } return ""; } } /////////////////////////////////////////////////////////////////////// End Class Functions } /////////////////////////////////////////////////////////////////////////// End namespace }