public int ReadOutput(ushort usAddress, ushort[] usReadSentData, uint unTimeout) { if (!IsOpen()) { LogTextOut("DeviceNet, ReadOutput(), DeviceNet is not opened"); return(-1000); } int nRet = -2000; try { nRet = XWin32Hilscher.DevReadSendData(0, usAddress, (ushort)(usReadSentData.Length * 2), usReadSentData); if (nRet != XWin32Hilscher.DRV_NO_ERROR) { LogTextOut(String.Format("DeviceNet, DevReadSendData() Error({0})", nRet)); return(nRet); } nRet = 1; } catch (Exception e) { LogTextOut(e.ToString()); } return(nRet); }
public int Close() { int nRet = XWin32Hilscher.DevSetHostState(0, XWin32Hilscher.HOST_NOT_READY, 0); if (nRet != XWin32Hilscher.DRV_NO_ERROR) { LogTextOut(String.Format("DeviceNet, DevSetHostState() Error({0})", nRet)); return(nRet); } nRet = XWin32Hilscher.DevExitBoard(0); if (nRet != XWin32Hilscher.DRV_NO_ERROR) { LogTextOut(String.Format("DeviceNet, DevExitBoard() Error({0})", nRet)); return(nRet); } nRet = XWin32Hilscher.DevCloseDriver(0); if (nRet != XWin32Hilscher.DRV_NO_ERROR) { LogTextOut(String.Format("DeviceNet, DevCloseDriver() Error({0})", nRet)); return(nRet); } // Set Open Flag bOpen = false; return(1); }
public int WriteOutput(ushort usAddress, ushort[] usWriteData, uint unTimeout) { if (!IsOpen()) { LogTextOut("DeviceNet, WriteOutput(), DeviceNet is not opened"); return(-1000); } int nRet = -2000; try { XWin32Hilscher.COMSTATE comState = new XWin32Hilscher.COMSTATE(); nRet = XWin32Hilscher.DevExchangeIOErr(0, usAddress, (ushort)(usWriteData.Length * 2), usWriteData, 0, 0, null, out comState, unTimeout); if (nRet != XWin32Hilscher.DRV_NO_ERROR) { LogTextOut(String.Format("DeviceNet, WriteOutput(), DevExchangeIOErr Error {0}", nRet)); return(nRet); } switch (comState.usMode) { case XWin32Hilscher.STATE_MODE_3: // Cyclic transfer of the state field including the state error flag (usStateFlag) if (comState.usStateFlag != 0) { LogTextOut("DeviceNet, DevExchangeIOErr(), COMSTATE.usStateFlag Error"); return(-3000); } break; case XWin32Hilscher.STATE_MODE_4: if (comState.usStateFlag != 0) // Event driven transfer of the state field including the usStateFlag { LogTextOut("DeviceNet, DevExchangeIOErr(), COMSTATE.usStateFlag Error"); return(-4000); } break; default: LogTextOut("DeviceNet, DevExchangeIOErr(), Invalid COMSTATE.usMode Error"); return(-5000); } nRet = 1; } catch (Exception e) { LogTextOut(e.ToString()); } return(nRet); }
public int Open(ushort usMaxInputAddress, ushort usMaxOutputAddress) { if (IsOpen()) { LogTextOut("DeviceNet, Open(), Already, Board is Opened"); return(-1000); } int nRet = -2000; try { nRet = XWin32Hilscher.DevOpenDriver(0); if (nRet != XWin32Hilscher.DRV_NO_ERROR) { LogTextOut(String.Format("DeviceNet, DevOpenDriver() Error({0})", nRet)); return(nRet); } XWin32Hilscher.BOARD_INFO tBoardInfo = new XWin32Hilscher.BOARD_INFO(); nRet = XWin32Hilscher.DevGetBoardInfo(0, (ushort)Marshal.SizeOf(tBoardInfo), out tBoardInfo); if (nRet != XWin32Hilscher.DRV_NO_ERROR) { LogTextOut(String.Format("DeviceNet, DevGetBoardInfo() Error({0})", nRet)); return(nRet); } XWin32Hilscher.BOARD[] tBoardList = new XWin32Hilscher.BOARD[XWin32Hilscher.MAX_DEV_BOARDS] { tBoardInfo.tBoard0, tBoardInfo.tBoard1, tBoardInfo.tBoard2, tBoardInfo.tBoard3 }; for (int i = 0; i < XWin32Hilscher.MAX_DEV_BOARDS; i++) { if (tBoardList[i].usAvailable != 0) { nRet = XWin32Hilscher.DevInitBoard(tBoardList[i].usBoardNumber, IntPtr.Zero); if (nRet != XWin32Hilscher.DRV_NO_ERROR) { LogTextOut(String.Format("DeviceNet, DevInitBoard() Error(){0}", nRet)); return(nRet); } } } } catch (Exception ex) { LogTextOut(String.Format("DeviceNet, DevInitBoard() Error(){0}", ex.Message)); return(nRet); } #region аж╪╝ nRet = XWin32Hilscher.DevReset(0, XWin32Hilscher.COLDSTART, 8000); if (nRet != XWin32Hilscher.DRV_NO_ERROR) { MessageBox.Show("DeviceNet, Open(), DevReset() Error"); return(nRet); } nRet = XWin32Hilscher.DevSetHostState(0, XWin32Hilscher.HOST_READY, 0); if (nRet != XWin32Hilscher.DRV_NO_ERROR) { MessageBox.Show("DeviceNet, Open(), DevSetHostState() Error"); return(nRet); } #endregion this.usMaxInputAddress = usMaxInputAddress; usInputBuffer = new ushort[usMaxInputAddress / 2 + 1]; this.usMaxOutputAddress = usMaxOutputAddress; usOutputBuffer = new ushort[usMaxOutputAddress / 2 + 1]; bOpen = true; return(1); }