⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clspci1755.cls

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 CLS
📖 第 1 页 / 共 2 页
字号:
'  return: error code.
'
  FdiCheck = DRV_FDICheck(mDriverHandle, dwStatus, dwRetrieved)
End Function

Public Function FdoCheck(ByRef dwStatus As Long, ByRef dwRetrieved As Long) As Long
'Get Fast DO function transferring status
'  dwStatus: return buffer for checking status
'  dwRetrieved: return buffer for current conversion count in buffer.
'  return: error code.
'
  FdoCheck = DRV_FDOCheck(mDriverHandle, dwStatus, dwRetrieved)
End Function

Public Function IsLoBufferReady(dwStatus As Long) As Boolean
'Check Fast DI function's lower half buffer data ready or not?
'  dwStatus: Fast DI status, gotted from FdiCheck()
'  return: true/false
'

  If ((dwStatus And dsReadyBuffer) = dsLoBufferReady) Then
    IsLoBufferReady = True
    DRV_ClearFlag mDriverHandle, ADS_EVT_DI_OVERRUN
  Else
    IsLoBufferReady = False
  End If
End Function

Public Function IsHiBufferReady(dwStatus As Long) As Boolean
'Check Fast DI function's Higher half buffer ready or not.
'  dwStatus: Fast DI status, gotted from FDICheck()
'  return: true/false
'
  If ((dwStatus And dsReadyBuffer) = dsHiBufferReady) Then
    IsHiBufferReady = True
    DRV_ClearFlag mDriverHandle, ADS_EVT_DI_OVERRUN
  Else
    IsHiBufferReady = False
  End If
End Function
  
Public Function IsBufferOverrun(dwStatus As Long) As Boolean
'Check Fast DI function's data overruning or not.
'  dwStatus: Fast DI status, gotted from FdiCheck()
'  return: true/false
'
  If ((dwStatus And dsUnderrun) <> 0) Then
    IsBufferOverrun = True
    DRV_ClearFlag mDriverHandle, ADS_EVT_DI_OVERRUN
  Else
    IsBufferOverrun = False
  End If
End Function

Public Function IsLoBufferTransferred(dwStatus As Long) As Boolean
'Check Fast DO function's lower half buffer transferred or not.
'  dwStatus: Fast DO status, gotted from FdoCheck()
'  return: true/false
'
  
  If ((dwStatus And dsReadyBuffer) = dsLoBufferTransferred) Then
    IsLoBufferTransferred = True
    DRV_ClearFlag mDriverHandle, ADS_EVT_DO_UNDERRUN
  Else
    IsLoBufferTransferred = False
  End If
 
End Function

Public Function IsHiBufferTransferred(dwStatus As Long) As Boolean
'Check Fast DO function's higher half buffer transferred or not.
'  dwStatus: Fast DO status, gotted from FdoCheck()
'  return: true/false
'

  If ((dwStatus And dsReadyBuffer) = dsHiBufferTransferred) Then
    IsHiBufferTransferred = True
    DRV_ClearFlag mDriverHandle, ADS_EVT_DO_UNDERRUN
  Else
    IsHiBufferTransferred = False
  End If
End Function

Public Function IsBufferUnderrun(dwStatus As Long) As Boolean
'Check Fast DO function underruning or not?
'  dwStatus: Fast DO status, gotted from FdoCheck()
'  return: true/false
'

  If ((dwStatus And dsUnderrun) <> 0) Then
    IsBufferUnderrun = True
    DRV_ClearFlag mDriverHandle, ADS_EVT_DO_UNDERRUN
  Else
    IsBufferUnderrun = False
  End If
End Function

Public Function IsFastFunctionRunning(dwStatus As Long) As Boolean
'Check Fast DI/DO function is running or not?
'  dwStatus: Fast DO/DI status, gotted from FdoCheck() or FDICheck
'
  IsFastFunctionRunning = ((dwStatus And dsRunning) <> 0)
End Function

Public Function FdoStart(bCyclic As Boolean, dwCount As Long, pBuf As Long) As Boolean
'This function will start high speed digital output according to user's
'property setting.
'  bCyclic: cyclic or single retrieveing cycle
'  dwCount: Transferring data counts
'  pBuf: Data buffer for returnning data.
'  Return: success (true) or fail (false)
'
Dim lErrCde As Long
  
  If ChkErr(DRV_FDOStart(mDriverHandle, bCyclic, dwCount, pBuf)) Then
    FdoStart = False
  Else
    FdoStart = True
  End If
  
End Function

Public Function FdoStop() As Long
'Stop current running fast DO functions
'  Return: Error code
'
  FdoStop = DRV_FDOStop(mDriverHandle)
End Function

Public Function ClearFlag(EventType As DeviceEvents) As Long
'Clear overrun flag, when buffer overrun occur. And
'In cyclic mode, when user get the data ready from low buffer or high buffer
'  EventType: Event type want to clear, current only deDiOverrun and deDoUnderrun
'             active this action.
'  return: Error code
'

  ClearFlag = DRV_ClearFlag(mDriverHandle, EventType)

End Function

Public Function EventEnable(EventType As DeviceEvents, bEnable As Boolean, Optional dwCount As Long = 1) As Boolean
'Enable/Disable event function
'  EventType: Event type want to enable
'  bEnable: Enable (true) or Disable (false) this event.
'  Return: Success (true) / fail (false)
'
Dim tEnableEvent As PT_EnableEvent

  If bEnable = True Then
    tEnableEvent.Enabled = 1      ' Enable following events
  Else
    tEnableEvent.Enabled = 0      ' Disable following events
  End If
  tEnableEvent.Count = dwCount    ' Accumulated counting for generating event mesage.
  
  tEnableEvent.EventType = EventType

  'Enable/Disable specified event
  If ChkErr(DRV_EnableEvent(mDriverHandle, tEnableEvent)) Then
    EventEnable = False
  Else
    EventEnable = True
  End If
End Function

Public Function EventCheck(dwTimeOut As Long) As DeviceEvents
'Wait device to generate events till the time out (Millisecond)
'  dwTimeOut: Time out value (in millisecond)
'  Return: Current generated event.
'
Dim usEventType As DeviceEvents
Dim tCheckEvent As PT_CheckEvent

  tCheckEvent.EventType = DRV_GetAddress(usEventType)
  tCheckEvent.Milliseconds = dwTimeOut
  
  DRV_CheckEvent mDriverHandle, tCheckEvent
  EventCheck = usEventType

End Function

Public Function DioGetConfig(iDioPort As Integer) As Long
'Retrieves digital input/output configuration data and returns it in PortArray.
'  iDioPort: DIO port number, PCI-1755 support only one port (value 0) only
'  return: Current configuration
'
Dim tDioGetConfig As PT_DioGetConfig
Dim usConfig As Integer

  tDioGetConfig.NumOfPorts = iDioPort
  tDioGetConfig.PortArray = DRV_GetAddress(usConfig)
  
  DRV_DioGetConfig mDriverHandle, tDioGetConfig
  DioGetConfig = usConfig

End Function

Public Function DioReadPortByte(usPort As Integer) As Integer
'Returns digital input data from the specified digital I/O port. The byte is specified
'by port number which is from 0 to the maximum byte of the deviceˇs digital output.
'  usPort: DI port number
'  return: 8-bit data read from device's DI port
'
Dim tDioReadPortByte As PT_DioReadPortByte
Dim usValue As Integer

  tDioReadPortByte.Port = usPort
  tDioReadPortByte.value = DRV_GetAddress(usValue)

  DRV_DioReadPortByte mDriverHandle, tDioReadPortByte
  DioReadPortByte = usValue

End Function

Public Function DioWritePortByte(usPort As Integer, usMask As Integer, usState As Long) As Long
'Writes digital output data to the specified digital port.
'  usPort:  DO port number
'  usMask:  specifies which bit(s) of data should be sent to the digital output port and
'           which bits remain unchanged
'  usState: new digital logic state
'  Return:  Error code
'
Dim tDioWritePortByte As PT_DioWritePortByte

  tDioWritePortByte.Port = usPort
  tDioWritePortByte.Mask = usMask
  tDioWritePortByte.state = usState

  DioWritePortByte = DRV_DioWritePortByte(mDriverHandle, tDioWritePortByte)

End Function

Public Function DioReadBit(usPort As Integer, usBit As Integer) As Integer
'Returns the bit state of digital input from the specified digital I/O port. The byte
'is specified by port number which is from 0 to the maximum byte of the device's
'digital output.
'  usPort: DI port number
'  usBit:  Bit position want to read.
'  Return: This bit's logical status
'
Dim tDioReadBit As PT_DioReadBit
Dim usState As Integer

  tDioReadBit.state = DRV_GetAddress(usState)
  tDioReadBit.Port = usPort
  tDioReadBit.bit = usBit

  DRV_DioReadBit mDriverHandle, tDioReadBit
  
  DioReadBit = usState
End Function
  
Public Function DioWriteBit(usPort As Integer, usBit As Integer, usState As Integer) As Long
'Writes digital output data to the specified digital port. The byte is specified by
'the port number which is from 0 to the maximum byte of the deviceˇs digital output.
'  usPort:  DO port number
'  usBit:   Bit position want to write
'  usState: High/Low logic want to write out
'  Return:  Error code
'
Dim tDioWriteBit As PT_DioWriteBit

  tDioWriteBit.Port = usPort
  tDioWriteBit.bit = usBit
  tDioWriteBit.state = usState
  DioWriteBit = DRV_DioWriteBit(mDriverHandle, tDioWriteBit)

End Function

Public Function DioGetCurrentDOByte(usPort As Integer) As Integer
'Returns digital input data from the specified digital I/O port. The byte is specified
'by port number which is from 0 to the maximum byte of the deviceˇs digital output.
'  usPort: DO port number
'  Return: Current DO port data
'
Dim tDioGetCurrentDOByte As PT_DioGetCurrentDOByte
Dim usValue As Integer

  tDioGetCurrentDOByte.Port = usPort
  tDioGetCurrentDOByte.value = DRV_GetAddress(usValue)
  DRV_DioGetCurrentDOByte mDriverHandle, tDioGetCurrentDOByte
  DioGetCurrentDOByte = usValue
  
End Function

Public Function DioGetCurrentDOBit(usPort As Integer, usBit As Integer) As Integer
'Returns the bit data of digital input from the specified digital I/O port. The byte
'is specified by port number which is from 0 to the maximum byte of the device's
'digital output.
'  usPort:  DO port number
'  usBit:   Bit number want to retrieve
'  Return:  This bit's logical status
'
Dim tDioGetCurrentDOBit As PT_DioGetCurrentDOBit
Dim usState As Integer

  tDioGetCurrentDOBit.Port = usPort
  tDioGetCurrentDOBit.bit = usBit
  tDioGetCurrentDOBit.state = DRV_GetAddress(usState)
  DRV_DioGetCurrentDOBit mDriverHandle, tDioGetCurrentDOBit
  DioGetCurrentDOBit = usState

End Function

Public Function DevicePropertyRead(Property As DeviceProperty, ByRef pBuf As Long, dwBufferLength As Long) As Long
'Get device Property from device driver.
'  Property:       device's property want to retrieve.
'  pBuf:           status return buffer's address
'  dwBufferLength: return buffer's length
'  Return:         Error code
'
  DevicePropertyRead = DRV_DeviceGetProperty(mDriverHandle, Property, pBuf, dwBufferLength)
  
End Function

Public Function DevicePropertyWrite(Property As DeviceProperty, ByRef pBuf As Long, dwBufferLength As Long) As Long
'Write device Property to driver.
'  Property: device's property want to retrie.
'  pBuf:           status return buffer's address
'  dwBufferLength: return buffer's length
'  Return:         Error code
'
  
  DevicePropertyWrite = DRV_DeviceSetProperty(mDriverHandle, Property, pBuf, dwBufferLength)

End Function

Public Function ConvertBufferSizeToCount(lBufferSize As Long) As Long
'Calculate the maximum supported data transfer count according the buffer size
'  lBufferSize: Buffer size reserved for fast function running
'  Return: data count can store to the buffer according to the bus width setting
'
Dim lData As Long, lLength As Long

  lLength = Len(lData)
  DevicePropertyRead dpDioFdioDirection, lData, lLength
  
  Select Case lData
  Case 0, 1
    lLength = 4       '32 bits DI/DO
  Case 2
    lLength = 2       '16 bits DI/DO
  Case 3
    lLength = 1       ' 8 bits DI/DO
  Case Else
    lLength = 8       ' unknow type
  End Select
  
  ConvertBufferSizeToCount = lBufferSize / lLength
  
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -