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