private void AtpPlcMap_Load(object sender, EventArgs e) { if (m_hParent != null) { AUtil.PostMessage(m_hParent, ASDef._WM_CHANGE_DI, 0xFF, 0xFF); } }
public int Receive(ref byte[] pbyData) { int nLen = -1; if (m_bConnect == false) { // 2012.12.03 //AUtil.SendMessage(m_hParent, _WM_AUDP_SOCKET_RECONNECT, 0, m_nID); AUtil.PostMessage(m_hParent, _WM_AUDP_SOCKET_RECONNECT, 0, m_nID); return(-99); } try { byte[] pbyBuf = new byte[1024]; nLen = m_UdpServer.ReceiveFrom(pbyBuf, ref m_EP_Remote); if (nLen > 0) { pbyData = new byte[nLen]; Array.Copy(pbyBuf, pbyData, nLen); } } catch { return(-100); } return(nLen); }
// 2015.02.25 //public int GetWordOldDI(int nAddress) { return m_pnOldDI[nAddress]; } public int SetBitDO(int nAddress, int n, bool bVal) { int nR = -1; int nTemp; lock (m_AClientSocketPlcSiemensWrite) { // 2014.10.09 nTemp = m_pnOldDO[nAddress]; m_pnOldDO[nAddress] = m_pnDO[nAddress]; if (bVal == true) { m_pnDO[nAddress] |= (1 << n); } else { m_pnDO[nAddress] &= (0xFFFF ^ (1 << n)); } AClientSocketPlcSiemens._stCfgSocketPlcSiemens stCfg; stCfg = new AClientSocketPlcSiemens._stCfgSocketPlcSiemens(); stCfg.nORG = 1; stCfg.nDBNR = m_stWriteAddress.nDB; stCfg.nStart = m_stWriteAddress.nDW * 2 + nAddress * 2; stCfg.nLen = 1; m_AClientSocketPlcSiemensWrite.m_pnDataWrite[0] = m_pnDO[nAddress]; // 2011.04.28 for (int i = 0; i < _RETRY; i++) { nR = m_AClientSocketPlcSiemensWrite.WritePlc(stCfg); if (nR == 1) { break; } } } if (nR == 1) { AUtil.PostMessage(m_hParent, _WM_SOCKET_WRITE_OK, 0, m_nID); /* 2015.02.25 * if (m_pnOldDO[nAddress] != m_pnDO[nAddress]) * { * AUtil.PostMessage(m_hParent, ASDef._WM_CHANGE_DO + m_nID, nAddress, m_pnDO[nAddress]); * } */ } else { m_pnDO[nAddress] = m_pnOldDO[nAddress]; m_pnOldDO[nAddress] = nTemp; AUtil.PostMessage(m_hParent, _WM_SOCKET_WRITE_NG, nR, m_nID); } return(nR); }
private void btn3_Click(object sender, EventArgs e) { WriteData(); int nType = cmbType.SelectedIndex; int nPoint = cmbPoint.SelectedIndex; AUtil.PostMessage(m_hParent, _WM_LIGHT2, nType, nPoint); }
private void tmrTimeOut_Tick(object sender, EventArgs e) { tmrTimeOut.Enabled = false; m_bPW = false; txtPw.Text = ""; // 2014.03.26 AUtil.PostMessage(m_hParent, ASDef._WM_PASSWORD_CHECK, m_nID, 0); Close(); }
public int SetWordDOLen(int nStartAddress, int nLen, int[] pnVal) { int nR = -1; lock (m_AClientSocketPlcSiemensWrite) { // 2014.10.09 AClientSocketPlcSiemens._stCfgSocketPlcSiemens stCfg; stCfg = new AClientSocketPlcSiemens._stCfgSocketPlcSiemens(); stCfg.nORG = 1; stCfg.nDBNR = m_stWriteAddress.nDB; stCfg.nStart = m_stWriteAddress.nDW * 2 + nStartAddress * 2; stCfg.nLen = nLen; for (int i = 0; i < nLen; i++) { m_pnOldDO[nStartAddress + i] = m_pnDO[nStartAddress + i]; m_pnDO[nStartAddress + i] = pnVal[i]; m_AClientSocketPlcSiemensWrite.m_pnDataWrite[i] = m_pnDO[nStartAddress + i]; } // 2011.04.28 for (int i = 0; i < _RETRY; i++) { nR = m_AClientSocketPlcSiemensWrite.WritePlc(stCfg); if (nR == 1) { break; } } } if (nR == 1) { AUtil.PostMessage(m_hParent, _WM_SOCKET_WRITE_OK, 0, m_nID); } else { AUtil.PostMessage(m_hParent, _WM_SOCKET_WRITE_NG, nR, m_nID); } /* 2015.02.25 * for (int i = 0; i < nLen; i++) * { * if (m_pnOldDO[nStartAddress + i] != m_pnDO[nStartAddress + i]) * { * AUtil.PostMessage(m_hParent, ASDef._WM_CHANGE_DO + m_nID, nStartAddress + i, m_pnDO[nStartAddress + i]); * } * } */ return(nR); }
private void AFrmPW_FormClosing(object sender, FormClosingEventArgs e) { tmrTimeOut.Enabled = false; // 2014.03.26 if (m_bPW == true) { AUtil.PostMessage(m_hParent, ASDef._WM_PASSWORD_CHECK, m_nID, 1); } else { AUtil.PostMessage(m_hParent, ASDef._WM_PASSWORD_CHECK, m_nID, 0); } }
private void Run() { int nR; while (!m_bStop) { try { lock (m_AUdpServerSocketRbt) { nR = m_AUdpServerSocketRbt.ReadShift(); if (nR > 0) { int n = m_AUdpServerSocketRbt.SendToRobot( m_pstRobotShift[nR - 1].dX, m_pstRobotShift[nR - 1].dY, m_pstRobotShift[nR - 1].dZ, m_pstRobotShift[nR - 1].dAX, m_pstRobotShift[nR - 1].dAY, m_pstRobotShift[nR - 1].dAZ); // 2015.03.01 if (++m_nReadCount > 9999) { m_nReadCount = 0; } AUtil.PostMessage(m_hParent, _WM_AUDP_SOCKET_ROBOT_OK, m_nID, nR); } else if (nR < 0) { AUtil.PostMessage(m_hParent, _WM_AUDP_SOCKET_ROBOT_NG, m_nID, nR); } } } catch { } // 2015.04.13 Thread.Sleep(m_nDelayTime); //AUtil.Delay(m_nDelayTime, true); } m_AUdpServerSocketRbt.Close(); }
private void OnBeginRead(IAsyncResult ar) { // 2013.11.22 종료시 예외 처리 발생 try { NetworkStream ns = (NetworkStream)ar.AsyncState; int BUFFER_SIZE = 4096; byte[] pbyReceived = new byte[BUFFER_SIZE]; ns.EndRead(ar); int nRead = 0; while (ns.DataAvailable) { nRead += ns.Read(pbyReceived, 0, BUFFER_SIZE); m_strReadData += Encoding.ASCII.GetString(pbyReceived); pbyReceived = new byte[BUFFER_SIZE]; } m_strReadData = m_strReadData.Trim(new char[] { '\0' }); // Want to update Form here with result // 2013.12.04 Server프로그램 종료시 계속 호출로 if (nRead == 0) { AUtil.PostMessage(m_hParent, _WM_ASOCKET_RECONNECT, 0, m_nID); return; } // 2013.09.16 if (m_NetworkStream.CanRead) { m_NetworkStream.BeginRead(pbyReceived, 0, 0, new AsyncCallback(OnBeginRead), m_NetworkStream); m_bConnect = true; } AUtil.PostMessage(m_hParent, _WM_ASOCKET_RECEIVE, nRead, m_nID); } catch { // 2013.11.22 AUtil.PostMessage(m_hParent, _WM_ASOCKET_RECONNECT, 0, m_nID); } }
public int Send(byte[] pbyData, int nLen) { if (m_bConnect == false) { // 2012.12.03 //AUtil.SendMessage(m_hParent, _WM_AUDP_SOCKET_RECONNECT, 0, m_nID); AUtil.PostMessage(m_hParent, _WM_AUDP_SOCKET_RECONNECT, 0, m_nID); return(-99); } try { m_UdpServer.SendTo(pbyData, nLen, SocketFlags.None, m_EP_Remote); } catch { return(-100); } return(1); }
public int Send(byte[] pbyData, int nLen, int nTime) { if (m_bConnect == false) { // 2012.12.03 //AUtil.SendMessage(m_hParent, _WM_ASOCKET_RECONNECT, 0, m_nID); AUtil.PostMessage(m_hParent, _WM_ASOCKET_RECONNECT, 0, m_nID); return(-99); } try { m_NetworkStream.WriteTimeout = nTime; m_NetworkStream.Write(pbyData, 0, nLen); } catch { return(-100); } return(1); }
public int Receive(ref byte[] pbyData, int nTime) { int nLen = -1; if (m_bConnect == false) { // 2012.12.03 //AUtil.SendMessage(m_hParent, _WM_ASOCKET_RECONNECT, 0, m_nID); AUtil.PostMessage(m_hParent, _WM_ASOCKET_RECONNECT, 0, m_nID); return(-99); } try { // 2015.04.08 WaitforAvailableData(nTime); // 2015.03.14 if (m_NetworkStream.DataAvailable == false) { return(0); } byte[] pbyBuf = new byte[4096]; m_NetworkStream.ReadTimeout = nTime; nLen = m_NetworkStream.Read(pbyBuf, 0, pbyBuf.Length); if (nLen > 0) { pbyData = new byte[nLen]; Array.Copy(pbyBuf, pbyData, nLen); } } catch { return(-100); } return(nLen); }
private void btnSave_Click(object sender, EventArgs e) { AUtil.WritePrivateProfileString("DelTime", "OK", txtOk.Text, ASDef._INI_FILE); AUtil.WritePrivateProfileString("DelTime", "NG", txtNg.Text, ASDef._INI_FILE); // 2011.08.17 AUtil.WritePrivateProfileString("DelTime", "TOTAL_OK", txtTotalOK.Text, ASDef._INI_FILE); // 2011.08.17 AUtil.WritePrivateProfileString("DelTime", "TOTAL_NG", txtTotalNG.Text, ASDef._INI_FILE); AUtil.WritePrivateProfileString("DelTime", "LOG", txtLog.Text, ASDef._INI_FILE); AUtil.WritePrivateProfileString("DelTime", "TIME", dTDel.Text, ASDef._INI_FILE); // 2017.06.08 AVisionProBuild.m_strResultPath = txtPath.Text; AUtil.WritePrivateProfileString("PATH", "ResultPath", txtPath.Text, ASDef._INI_FILE); AUtil.PostMessage(m_hParent, ASDef._WM_LOAD_FILEDEL, 0, 0); // 2015.02.11 string strTxt = "FileDel Change: "; AVisionProBuild.WriteLogFile(strTxt, ".Setup.txt"); strTxt = "OK: " + txtOk.Text; AVisionProBuild.WriteLogFile(strTxt, ".Setup.txt"); strTxt = "NG: " + txtNg.Text; AVisionProBuild.WriteLogFile(strTxt, ".Setup.txt"); strTxt = "TotalOK: " + txtTotalOK.Text; AVisionProBuild.WriteLogFile(strTxt, ".Setup.txt"); strTxt = "TotalNG: " + txtTotalNG.Text; AVisionProBuild.WriteLogFile(strTxt, ".Setup.txt"); strTxt = "LOG: " + txtLog.Text; AVisionProBuild.WriteLogFile(strTxt, ".Setup.txt"); strTxt = "TIME: " + dTDel.Text; AVisionProBuild.WriteLogFile(strTxt, ".Setup.txt"); // 2017.06.08 strTxt = "Path: " + AVisionProBuild.m_strResultPath; AVisionProBuild.WriteLogFile(strTxt, ".Setup.txt"); }
public int SetWordDBDW(int nDB, int nDW, int nVal) { int nR = -1; lock (m_AClientSocketPlcSiemensWrite) { // 2014.10.09 AClientSocketPlcSiemens._stCfgSocketPlcSiemens stCfg; stCfg = new AClientSocketPlcSiemens._stCfgSocketPlcSiemens(); stCfg.nORG = 1; stCfg.nDBNR = nDB; stCfg.nStart = nDW * 2; stCfg.nLen = 1; m_AClientSocketPlcSiemensWrite.m_pnDataWrite[0] = nVal; // 2011.04.28 for (int i = 0; i < _RETRY; i++) { nR = m_AClientSocketPlcSiemensWrite.WritePlc(stCfg); if (nR == 1) { break; } } } if (nR == 1) { AUtil.PostMessage(m_hParent, _WM_SOCKET_WRITE_OK, 0, m_nID); } else { AUtil.PostMessage(m_hParent, _WM_SOCKET_WRITE_NG, nR, m_nID); } return(nR); }
public void Run() { int nR = 0; AClientSocketPlcSiemens._stCfgSocketPlcSiemens stCfg; stCfg = new AClientSocketPlcSiemens._stCfgSocketPlcSiemens(); stCfg.nORG = 1; //DB stCfg.nDBNR = m_stReadAddress.nDB; //DB stCfg.nStart = m_stReadAddress.nDW * 2; //DW stCfg.nLen = ASDef._MAX_PLC_DI; // 2011.07.18 #if _USE_PC_RUN int nPcRun = 0; #endif while (!m_bStop) { try { // 2014.08.10 if (m_bReConnecting == true) { // 2015.04.13 Thread.Sleep(1000); //AUtil.Delay(1000, true); continue; } lock (m_AClientSocketPlcSiemensFetch) { // 2014.11.12 for (int j = 0; j < _RETRY; j++) { nR = m_AClientSocketPlcSiemensFetch.ReadPlc(stCfg); if (nR == 1) { for (int i = 0; i < ASDef._MAX_PLC_DI; i++) { // 2015.02.25 //m_pnOldDI[i] = m_pnDI[i]; m_pnDI[i] = m_AClientSocketPlcSiemensFetch.m_pnDataRead[i]; } // 2015.03.01 if (++m_nReadCount > 9999) { m_nReadCount = 0; } break; } } } if (nR == 1) { AUtil.PostMessage(m_hParent, _WM_SOCKET_FETCH_OK, 0, m_nID); /* 2015.02.25 * for (int i = 0; i < ASDef._MAX_PLC_DI; i++) * { * if (m_pnOldDI[i] != m_pnDI[i]) * { * //AUtil.SendMessage(m_hParent, ASDef._WM_CHANGE_DI + m_nID, i, m_pnDI[i]); * AUtil.PostMessage(m_hParent, ASDef._WM_CHANGE_DI + m_nID, i, m_pnDI[i]); * } * } */ #if _USE_PC_RUN if (AVisionProBuild.Auto) { if (nPcRun > 4) { nPcRun = 0; if (((GetWordDO(ASDef._DO_PC_RUN) >> ASDef._DO_BIT_PC_RUN) & 0x01) == 0x01) { // 2014.07.17 if (SetBitDO(Convert.ToInt32(ASDef._DO_PC_RUN), Convert.ToInt32(ASDef._DO_BIT_PC_RUN), false) == 1) { // 2015.02.11 AVisionProBuild.WriteLogFile("O_Off:PC Run", ".PcRun.txt"); } } else { // 2014.07.17 if (SetBitDO(Convert.ToInt32(ASDef._DO_PC_RUN), Convert.ToInt32(ASDef._DO_BIT_PC_RUN), true) == 1) { // 2015.02.11 AVisionProBuild.WriteLogFile("O:PC Run", ".PcRun.txt"); } } } else { nPcRun++; } } #endif } else { AUtil.PostMessage(m_hParent, _WM_SOCKET_FETCH_NG, nR, m_nID); } } catch { } // 2015.04.13 Thread.Sleep(m_nDelayTime); //AUtil.Delay(m_nDelayTime, true); } }
// 2014.10.12 private void FrmPartOffset_FormClosed(object sender, FormClosedEventArgs e) { AUtil.PostMessage(m_PMain.Handle, _WM_PARTOFFSET_CLOSE, 0, 0); }
public void Run(ref ICogImage cogImage, int nFlipRotation) { // 2013.05.03 try { m_nAcqCount++; if (nFlipRotation == 0) { //Acquire(cogDisplay); // 2015.04.08 m_bRan = false; m_cogAcqFifoTool.Run(); // 2015.04.08 WaitRanEvent(); if (m_cogAcqFifoTool.OutputImage != null) { cogImage = m_cogAcqFifoTool.OutputImage; #if !_USE_TRIGGER_ACQ // 2017.11.16 by kdi. m_cogImageTrigger = cogImage; AUtil.PostMessage(m_hMain, _WM_ACQFIFO_COMPLETE, m_nPoint, m_nSection); #endif } #if !_USE_TRIGGER_ACQ else { cogImage = null; //var property = m_cogAcqFifoTool.RunStatus.Exception.GetType().GetProperty("HResult", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); //var value = property.GetValue(m_cogAcqFifoTool.RunStatus.Exception, null); int nHResult = System.Runtime.InteropServices.Marshal.GetHRForException(m_cogAcqFifoTool.RunStatus.Exception); //if (m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE) == true || // m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE2) == true || // m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE3) == true // ) //** to do: // 1. 네트워크 단절 에러와 일반 예외 값이 동일한지 확인 필요 // 동일한 값을 가진다면, 이 조건을 적용할 수 없음 if ((UInt32)nHResult == (UInt32)0x80131600) // Application Exception { // ip address System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse(m_cogAcqFifoTool.Operator.FrameGrabber.OwnedGigEAccess.CurrentIPAddress); int intAddress = BitConverter.ToInt32(ipaddress.GetAddressBytes(), 0); //AUtil.PostMessage(m_hMain, ASDef._WM_CAMERA_IS_DISCONNECTED, m_nPoint, intAddress); AUtil.PostMessage(m_hMain, clsCamera._WM_CAMERA_IS_DISCONNECTED, m_nPoint, intAddress); } string strMsg = ""; strMsg = string.Format("AAcqFifo.Run: Error. {0}", m_cogAcqFifoTool.RunStatus.Message); m_strError = strMsg; AVisionProBuild.WriteLogFile(strMsg, ".AcqFifo.err.txt"); } #endif return; } // 2015.04.08 m_bRan = false; //DateTime Now = DateTime.Now; m_cogAcqFifoTool.Run(); // 2015.04.08 WaitRanEvent(); //TimeSpan span = DateTime.Now - Now; if (m_cogAcqFifoTool.OutputImage != null) { // 2011.07.29 CogIPOneImageFlipRotate cogIPOneImageFlipRotate = new CogIPOneImageFlipRotate(); cogIPOneImageFlipRotate.OperationInPixelSpace = (CogIPOneImageFlipRotateOperationConstants)nFlipRotation; // 2012.04.25 ICogImage cogImageFR = cogIPOneImageFlipRotate.Execute(m_cogAcqFifoTool.OutputImage, CogRegionModeConstants.PixelAlignedBoundingBox, null); Bitmap Bmp = cogImageFR.ToBitmap(); if ((Bmp.Flags & (16 | 32 | 64 | 128 | 256)) != 0) { cogImage = new CogImage24PlanarColor(Bmp); } else { cogImage = new CogImage8Grey(Bmp); } #if !_USE_TRIGGER_ACQ // 2017.11.16 by kdi. m_cogImageTrigger = cogImage; AUtil.PostMessage(m_hMain, _WM_ACQFIFO_COMPLETE, m_nPoint, m_nSection); #endif // 2012.06.06 if (Bmp != null) { Bmp.Dispose(); Bmp = null; } } #if !_USE_TRIGGER_ACQ else { cogImage = null; int nHResult = System.Runtime.InteropServices.Marshal.GetHRForException(m_cogAcqFifoTool.RunStatus.Exception); //if (m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE) == true || // m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE2) == true || // m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE3) == true // ) //** to do: // 1. 네트워크 단절 에러와 일반 예외 값이 동일한지 확인 필요 // 동일한 값을 가진다면, 이 조건을 적용할 수 없음 if ((UInt32)nHResult == (UInt32)0x80131600) // Application Exception { // 2018.04.09 //AUtil.PostMessage(m_hMain, ASDef._WM_CAMERA_IS_DISCONNECTED, m_nPoint, 0); AUtil.PostMessage(m_hMain, clsCamera._WM_CAMERA_IS_DISCONNECTED, m_nPoint, 0); } string strMsg = ""; strMsg = string.Format("AAcqFifo.Run: Error. {0}", m_cogAcqFifoTool.RunStatus.Message); m_strError = strMsg; AVisionProBuild.WriteLogFile(strMsg, ".AcqFifo.err.txt"); } #endif /* * ICogImage cogImageFR = cogIPOneImageFlipRotate.Execute(m_cogAcqFifoTool.OutputImage, CogRegionModeConstants.PixelAlignedBoundingBox, null); * * lock (m_cogImageFile) * { * string strFName = "c:\\" + AVisionProBuild.MakeName("Flip", DateTime.Now) + ".bmp"; * m_cogImageFile.Open(strFName, CogImageFileModeConstants.Write); * m_cogImageFile.Append(cogImageFR); * m_cogImageFile.Close(); * m_cogImageFile.Open(strFName, CogImageFileModeConstants.Read); * cogImage = m_cogImageFile[0]; * m_cogImageFile.Close(); * File.Delete(strFName); * } */ } catch (CogException ex) { cogImage = null; m_cogImageTrigger = cogImage; #if !_USE_TRIGGER_ACQ if (ex.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE) == true || ex.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE2) == true) { // 2018.04.09 //AUtil.PostMessage(m_hMain, ASDef._WM_CAMERA_IS_DISCONNECTED, m_nPoint, 0); AUtil.PostMessage(m_hMain, clsCamera._WM_CAMERA_IS_DISCONNECTED, m_nPoint, 0); } string strMsg = ""; strMsg = string.Format("AAcqFifo.Run: CogException. {0}", ex.Message); m_strError = strMsg; AVisionProBuild.WriteLogFile(strMsg, ".AcqFifo.err.txt"); #endif } catch { cogImage = null; } }
/* * // 2011.07.07 * public void Run(ADisplay aDisplay, int nFlipRotation) * { * Run(aDisplay.Display, nFlipRotation); * } * * // 2011.07.07 * public void Run(CogDisplay cogDisplay, int nFlipRotation) * { * * if (nFlipRotation == 0) * { * //Acquire(cogDisplay); * // 2015.04.08 * m_bRan = false; * * m_cogAcqFifoTool.Run(); * * // 2015.04.08 * WaitRanEvent(); * * cogDisplay.Image = m_cogAcqFifoTool.OutputImage; * return; * } * * // 2015.04.08 * m_bRan = false; * * m_cogAcqFifoTool.Run(); * * // 2015.04.08 * WaitRanEvent(); * * // 2011.07.29 * CogIPOneImageFlipRotate cogIPOneImageFlipRotate = new CogIPOneImageFlipRotate(); * cogIPOneImageFlipRotate.OperationInPixelSpace = (CogIPOneImageFlipRotateOperationConstants)nFlipRotation; * * ICogImage cogImage = cogIPOneImageFlipRotate.Execute(m_cogAcqFifoTool.OutputImage, CogRegionModeConstants.PixelAlignedBoundingBox, null); * * lock (m_cogImageFile) * { * string strFName = "c:\\" + AVisionProBuild.MakeName("Flip", DateTime.Now) + ".bmp"; * m_cogImageFile.Open(strFName, CogImageFileModeConstants.Write); * m_cogImageFile.Append(cogImage); * m_cogImageFile.Close(); * m_cogImageFile.Open(strFName, CogImageFileModeConstants.Read); * cogDisplay.Image = m_cogImageFile[0]; * m_cogImageFile.Close(); * File.Delete(strFName); * } * } */ private void OnAcqFifoComplete(object sender, Cognex.VisionPro.CogCompleteEventArgs e) { int nPending, nReady, nTicket, nTriggerNumber; bool bUsy; bool bFirst = true; bool bOK = false; for (int nRetry = 0; nRetry < 2; nRetry++) // 2016.02.22 by kdi. { try { m_cogAcqFifoTool.Operator.GetFifoState(out nPending, out nReady, out bUsy); if (nReady > 0) { // 2014.12.16 m_cogImageTrigger = m_cogAcqFifoTool.Operator.CompleteAcquire(-1, out nTicket, out nTriggerNumber); m_nNumAqcs += 1; //AUtil.PostMessage(m_hMain, _WM_ACQFIFO_COMPLETE, m_nPoint, nTriggerNumber); AUtil.PostMessage(m_hMain, _WM_ACQFIFO_COMPLETE, m_nPoint, m_nSection); m_nCompleteCount++; if (m_nNumAqcs > 4) { GC.Collect(); m_nNumAqcs = 0; } bOK = true; break; // 2016.02.22 by kdi } if (m_nNumAqcs > 4) { GC.Collect(); m_nNumAqcs = 0; } //break; } catch (CogException ex) { // 2016.02.22 by kdi. MessageBox.Show("The following error has occured:" + ex.Message); if (ex.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE) == true || ex.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE2) == true) { // 2018.04.09 //AUtil.PostMessage(m_hMain, ASDef._WM_CAMERA_IS_DISCONNECTED, m_nPoint, 0); AUtil.PostMessage(m_hMain, clsCamera._WM_CAMERA_IS_DISCONNECTED, m_nPoint, 0); } string strMsg = ""; strMsg = string.Format("OnAcqFifoComplete: CogException. {0}", ex.Message); m_strError = strMsg; AVisionProBuild.WriteLogFile(strMsg, ".AcqFifo.err.txt"); // 취득 실패 시, 재시도 1회 if (bFirst == true) { bFirst = false; } } catch (System.Exception ex) { // 2016.02.22 by kdi. MessageBox.Show("The following error has occured:" + ex.Message); string strMsg = ""; strMsg = string.Format("OnAcqFifoComplete: Exception. {0}", ex.Message); m_strError = strMsg; AVisionProBuild.WriteLogFile(strMsg, ".AcqFifo.err.txt"); // 취득 실패 시, 재시도 1회 if (bFirst == true) { bFirst = false; } } } if (bOK == false) { AUtil.PostMessage(m_hMain, _WM_ACQFIFO_COMPLETE_NG, m_nPoint, m_nSection); } }
// 2019.05.21 public void Run(ref ICogVisionData cogVisionData) { try { m_nAcqCount++; //Acquire(cogDisplay); m_bRan = false; m_cogAcqFifoTool.Run(); WaitRanEvent(); if (m_cogAcqFifoTool.OutputVisionData != null) { cogVisionData = m_cogAcqFifoTool.OutputVisionData; } #if !_USE_TRIGGER_ACQ else { cogVisionData = null; //var property = m_cogAcqFifoTool.RunStatus.Exception.GetType().GetProperty("HResult", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); //var value = property.GetValue(m_cogAcqFifoTool.RunStatus.Exception, null); int nHResult = System.Runtime.InteropServices.Marshal.GetHRForException(m_cogAcqFifoTool.RunStatus.Exception); //if (m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE) == true || // m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE2) == true || // m_cogAcqFifoTool.RunStatus.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE3) == true // ) //** to do: // 1. 네트워크 단절 에러와 일반 예외 값이 동일한지 확인 필요 // 동일한 값을 가진다면, 이 조건을 적용할 수 없음 if ((UInt32)nHResult == (UInt32)0x80131600) // Application Exception { // ip address System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse(m_cogAcqFifoTool.Operator.FrameGrabber.OwnedGigEAccess.CurrentIPAddress); int intAddress = BitConverter.ToInt32(ipaddress.GetAddressBytes(), 0); //AUtil.PostMessage(m_hMain, ASDef._WM_CAMERA_IS_DISCONNECTED, m_nPoint, intAddress); AUtil.PostMessage(m_hMain, clsCamera._WM_CAMERA_IS_DISCONNECTED, m_nPoint, intAddress); } string strMsg = ""; strMsg = string.Format("AAcqFifo.Run: Error. {0}", m_cogAcqFifoTool.RunStatus.Message); m_strError = strMsg; AVisionProBuild.WriteLogFile(strMsg, ".AcqFifo.err.txt"); } #endif return; } catch (CogException ex) { cogVisionData = null; #if !_USE_TRIGGER_ACQ if (ex.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE) == true || ex.Message.Contains(_CONST_CAMERA_DISCONNECTION_MESSAGE2) == true) { //AUtil.PostMessage(m_hMain, ASDef._WM_CAMERA_IS_DISCONNECTED, m_nPoint, 0); AUtil.PostMessage(m_hMain, clsCamera._WM_CAMERA_IS_DISCONNECTED, m_nPoint, 0); } string strMsg = ""; strMsg = string.Format("AAcqFifo.Run: CogException. {0}", ex.Message); m_strError = strMsg; AVisionProBuild.WriteLogFile(strMsg, ".AcqFifo.err.txt"); #endif } catch { cogVisionData = null; } }