📄 clspci1755.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsPCI1755"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'clsPCI1755:
'PCI-1755 device driver class
'This class render all Advantech PCI-1755 device functions from ADS API32.
'
Option Explicit
'
' Types and Enums
'
'Device supported properties
Public Enum DeviceProperty
dpDeviceNumber = CFG_DeviceNumber
dpBoardID = CFG_BoardID
dpSwitchID = CFG_SwitchID
dpBaseAddress = CFG_BaseAddress
dpInterrupt = CFG_Interrupt
dpBusNumber = CFG_BusNumber
dpSlotNumber = CFG_SlotNumber
dpOnSystem = CFG_OnSystem
dpDioDirection = CFG_DioDirection ' each bit for one Auxiliary DIO channel for PCI-1755.
dpDioFdioDirection = CFG_DioFdioDirection ' 32DI(0)/32DO(1)/ 16 DIO(2) / 8DIO(3) for PCI-1755
dpDioTerminator = CFG_DioTerminator ' Bit 0: DI terminator (DI_TERM),ON (0) or OFF(1) for PCI-1755 // Bit 1: DO terminator (DI_TERM) ON (0) or OFF(1) for PCI-1755
dpDiOperationMode = CFG_DiOperationMode ' normal mode (0), 8255 handshaking(1), Burst handshaking(2) for PCI-1755
dpDiStartMethod = CFG_DiStartMethod ' Software(1), External trigger(2), Pattern match(3)
dpDiStopMethod = CFG_DiStopMethod ' Software(1), External trigger(2), Pattern match(3)
dpDiPacerSource = CFG_DiPacerSource ' 30MHz(1), 15Mhz(2), 10MHz(3), Counter 0 OUT (4), External (5), 12MHz(6), 20MHz(7)
dpDiControlSignals = CFG_DiControlSignals ' Bit 0: External DI start signal control (STRRF), 0 rising edge, 1 falling edge.
' Bit 1: External DI stop signal control (STPRF), 0 rising edge, 1 falling edge.
' Bit 2: DI request signal control (REQRF), 0 rising edge, 1 falling edge.
' Bit 3: DI acknowledge signal control (ACKRF), 0 rising edge, 1 falling edge.
' Bit 4: DI sampling clock signal control (CLKRF), 0 rising edge, 1 falling edge
dpDiPatternMatchValue = CFG_DiPatternMatchValue
dpDoOperationMode = CFG_DoOperationMode ' Normal (0), Handahaking (1), Burst handshaking(2)
dpDoStartMethod = CFG_DoStartMethod ' Software(1), External signal(2)
dpDoStopMethod = CFG_DoStopMethod ' Software(1), External signal(2)
dpDoPacerSource = CFG_DoPacerSource ' 30, 15, 10 Mhz, Counter1, External signal (value range 1-5)
dpDoControlSignals = CFG_DoControlSignals ' Control signals
' Bit 0: External DO start signal control (STRRF), 0 rising edge, 1 falling edge.
' Bit 1: External DO stop signal control (STPRF), 0 rising edge, 1 falling edge.
' Bit 2: DO request signal control (REQRF), 0 rising edge, 1 falling edge.
' Bit 3: DO acknowledge signal control (ACKRF), 0 rising edge, 1 falling edge.
' Bit 4: DO sampling clock signal control (CLKRF), 0 rising edge, 1 falling edge
dpDoPresetValue = CFG_DoPresetValue ' DO status before transfering.
dpCounterCountValue = CFG_CounterCountValue ' 82C54 Counter 0-2 value
' Other ID
dpIrqDiChangeStatusChannel = CFG_IrqDiChangeStatusChannel ' Change status channel number.
dpIrqDiTriggerSignals = CFG_IrqDiTriggerSignals ' Each bit for each Auxiliary DIO channel
End Enum
'Device supported events
Public Enum DeviceEvents
deNoEvent = ADS_EVT_NO_EVENT
deDiLowBufferReady = ADS_EVT_DI_LOBUFREADY 'Fast DI lower half buffer data ready
deDiHighBufferReady = ADS_EVT_DI_HIBUFREADY 'Fast DI higher half buffer data ready
deDiTerminated = ADS_EVT_DI_TERMINATED 'Fast DI function terminated.
deDiOverrun = ADS_EVT_DI_OVERRUN 'Fast DI data overrun.
deDoLowBufferTransferred = ADS_EVT_DO_LOBUFTRANS 'Fast DO lower half buffer data transferred.
deDoHighBufferTransferred = ADS_EVT_DO_HIBUFTRANS 'Fast DO higher half buffer data transferred.
deDoTerminated = ADS_EVT_DO_TERMINATED 'Fast DO function terminated.
deDoUnderrun = ADS_EVT_DO_UNDERRUN 'Fast DO data under run.
deTcTimer = ADS_EVT_TC_TIMER '8254 counter2 timer interrupt.
deDiPatternMatch = ADS_EVT_DI_PATTERNMATCH 'Specified DI pattern matched.
deDiStatusChange = ADS_EVT_DI_STATUSCHANGE 'Specified DI channel status changed.
deDiInterruptOfChannel0 = ADS_EVT_INTERRUPT_DI0 'AUX DIO channel0 interrupt.
deDiInterruptOfChannel1 = ADS_EVT_INTERRUPT_DI1 'AUX DIO channel1 interrupt.
deDiInterruptOfChannel2 = ADS_EVT_INTERRUPT_DI2 'AUX DIO channel2 interrupt.
deDiInterruptOfChannel3 = ADS_EVT_INTERRUPT_DI3 'AUX DIO channel3 interrupt.
deDiInterruptOfChannel4 = ADS_EVT_INTERRUPT_DI4 'AUX DIO channel4 interrupt.
deDiInterruptOfChannel5 = ADS_EVT_INTERRUPT_DI5 'AUX DIO channel5 interrupt.
deDiInterruptOfChannel6 = ADS_EVT_INTERRUPT_DI6 'AUX DIO channel6 interrupt.
deDiInterruptOfChannel7 = ADS_EVT_INTERRUPT_DI7 'AUX DIO channel7 interrupt
End Enum
'Fast DI/DO (DRV_FDICheck, DRV_FDOCheck) returned status
Public Enum FastDIOStatus
dsRunning = 1 'FDI/FDO function is running
dsUnderrun = &H10 'FDO buffer data under-run
dsOverrun = &H10 'FDI buffer data overrun
dsReadyBuffer = &H300
dsLoBufferReady = &H200 'Lower half buffer data ready(Fast DI)
dsHiBufferReady = &H300 'Higher half buffer data ready(Fast DI)
dsLoBufferTransferred = &H200 'Lower half buffer data transferred(Fast DO)
dsHiBufferTransferred = &H300 'Higher half buffer data transferred (Fast DO)
End Enum
'Const
Private Const CorrectDeviceID = BD_PCI1755
Private Const CorrectDeviceID3755 = BD_MIC3755
'Private member variable
Private mDeviceNumber As Long
Private msDeviceName As String * 128
Private mDriverHandle As Long
'Check the return error message
Public Function ChkErr(ByVal lErrCde As Long) As Long
Dim sErrMsg As String * 128
Dim Response As Integer
If (lErrCde <> 0) Then
DRV_GetErrorMessage lErrCde, sErrMsg
Response = MsgBox(sErrMsg, vbOKOnly, "Error!!")
ChkErr = 1
Else
ChkErr = 0
End If
End Function
Private Sub Class_Initialize()
Dim lErrCde As Long
If mDriverHandle = 0 Then
'Select Device
lErrCde = DRV_SelectDevice(0#, False, mDeviceNumber, msDeviceName)
'Open selected device
lErrCde = DRV_DeviceOpen(mDeviceNumber, mDriverHandle)
If (ChkErr(lErrCde)) Then
'
' Device open error, clear the driver handle and
' disable all configuration controls.
'
mDriverHandle = 0
Exit Sub
End If
End If
End Sub
Private Sub Class_Terminate()
' Close Device
If mDriverHandle <> 0 Then
DRV_DeviceClose (mDriverHandle)
mDriverHandle = 0
End If
End Sub
Public Property Get Name() As String
'Get the device name string
If mDriverHandle <> 0 Then
Name = msDeviceName
Else
Name = ""
End If
End Property
Public Property Get Handle() As Long
'Get driver handle
' Return: Device handle
Handle = mDriverHandle
End Property
Public Property Get DeviceNumber() As Long
'Get Device number
' Return: Device number
'
DeviceNumber = mDeviceNumber
End Property
Public Function DoesDeviceCorrect() As Boolean
'Check current selected device is desired type
' Return: True/False
'
Dim lData As Long
DoesDeviceCorrect = False
If (mDriverHandle <> 0) Then
'Get device property
DevicePropertyRead dpBoardID, lData, Len(lData)
If lData = CorrectDeviceID Or lData = CorrectDeviceID3755 Then
DoesDeviceCorrect = True
End If
End If
End Function
Public Sub ChangeDevice()
'Change current selected device
Dim lErrCde As Long
'Close current device
If mDriverHandle <> 0 Then
DRV_DeviceClose (mDriverHandle)
End If
'Open new device
lErrCde = DRV_SelectDevice(0#, False, mDeviceNumber, msDeviceName)
'Open selected device
lErrCde = DRV_DeviceOpen(mDeviceNumber, mDriverHandle)
If (ChkErr(lErrCde)) Then
'
' Device open error, clear the driver handle and
' disable all configuration controls.
'
mDriverHandle = 0
End If
End Sub
Public Function WritePortByte(Port As Integer, ByteData As Integer) As Long
'Writes an 8-bit data to the specified I/O port. The port address is an I/O
'port address on the PC.
' Port: I/O port address
' ByteData: BYTE data to write out
' Return: Error code
'
Dim tData As PT_WritePortByte
tData.ByteData = ByteData
tData.Port = Port
WritePortByte = DRV_WritePortByte(mDriverHandle, tData)
End Function
Public Function WritePortWord(Port As Integer, WordData As Integer) As Long
'Writes a 16-bit data to the specified I/O port. The port address is an I/O
'port address on the PC
' Port: I/O port address
' WordData: WORD data to write out
' Return: Error code
'
Dim tData As PT_WritePortWord
tData.Port = Port
tData.WordData = WordData
WritePortWord = DRV_WritePortWord(mDriverHandle, tData)
End Function
Public Function WritePortDword(Port As Integer, DwordData As Long) As Long
'Writes a 32-bit data to the specified I/O port. The port address is an I/O
'port address on the PC
' Port: I/O port address
' DwordData: DWORD data to write out
' Return: Error code
'
Dim tData As PT_WritePortDword
tData.Port = Port
tData.DwordData = DwordData
WritePortDword = DRV_WritePortDword(mDriverHandle, tData)
End Function
Public Function ReadPortByte(Port As Integer) As Integer
'Reads an 8-bit data from the specified I/O port. The port
'address is an I/O port address on the PC.
' Port: I/O port address
' Return: Byte data read
'
Dim tData As PT_ReadPortByte
Dim iByteData As Integer
tData.Port = Port
tData.ByteData = DRV_GetAddress(iByteData)
DRV_ReadPortByte mDriverHandle, tData
ReadPortByte = iByteData
End Function
Public Function ReadPortWord(Port As Integer) As Integer
'Reads a 16-bit data from the specified I/O port. The port
'address is an I/O port address on the PC.
' Port: I/O port address
' Return: Word data read
'
Dim tData As PT_ReadPortWord
Dim iWordData As Integer
tData.Port = Port
tData.WordData = DRV_GetAddress(iWordData)
DRV_ReadPortWord mDriverHandle, tData
ReadPortWord = iWordData
End Function
Public Function ReadPortDword(Port As Integer) As Long
'Reads a 32-bit data from the specified I/O port. The port
'address is an I/O port address on the PC.
' Port: I/O port address
' Return: DWORD data read
'
Dim tData As PT_ReadPortDword
Dim lData As Long
tData.Port = Port
tData.DwordData = DRV_GetAddress(lData)
DRV_ReadPortDword mDriverHandle, tData
ReadPortDword = lData
End Function
Public Function FdiStart(bCyclic As Boolean, dwCount As Long, pBuf As Long) As Boolean
'This function will start high speed digital input 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)
'
If ChkErr(DRV_FDIStart(mDriverHandle, bCyclic, dwCount, pBuf)) Then
FdiStart = False
Else
FdiStart = True
End If
End Function
Public Function FdiStop() As Long
'Stop Fast DI function
' Return: Error code
'
FdiStop = DRV_FDIStop(mDriverHandle)
End Function
Public Function FdiCheck(ByRef dwStatus As Long, ByRef dwRetrieved As Long) As Long
'Get the Fast DI conversion status.
' dwStatus: return buffer for checking status
' dwRetrieved: return buffer for current conversion count in buffer.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -