📄 dabmdma.frm
字号:
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 3 'Fixed Dialog
Caption = "PCI-1712 Bus Mastering DMA(AO)"
ClientHeight = 3690
ClientLeft = 45
ClientTop = 330
ClientWidth = 5205
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3690
ScaleWidth = 5205
ShowInTaskbar = 0 'False
StartUpPosition = 3 'Windows Default
Begin VB.Timer CheckTimer
Enabled = 0 'False
Interval = 10
Left = 3480
Top = 0
End
Begin VB.CommandButton btExit
Caption = "Exit"
Height = 495
Left = 3480
TabIndex = 14
Top = 2760
Width = 1335
End
Begin VB.ComboBox Combo1
Height = 315
ItemData = "DABMDMA.frx":0000
Left = 360
List = "DABMDMA.frx":0002
TabIndex = 9
Text = "Device List"
Top = 600
Width = 2895
End
Begin VB.TextBox EditAccuracy
Height = 285
Left = 1440
TabIndex = 7
Text = "500"
Top = 3000
Width = 735
End
Begin VB.TextBox EditOffset
Height = 285
Left = 1440
TabIndex = 6
Text = "0.00"
Top = 2520
Width = 735
End
Begin VB.TextBox EditMagnitude
Height = 285
Left = 1440
TabIndex = 5
Text = "5.00"
Top = 2040
Width = 735
End
Begin VB.ComboBox CmbSelectWaveform
Height = 315
ItemData = "DABMDMA.frx":0004
Left = 1440
List = "DABMDMA.frx":0011
TabIndex = 4
Text = "Sine"
Top = 1560
Width = 1215
End
Begin VB.CommandButton btStop
Caption = "Stop"
Height = 495
Left = 3480
TabIndex = 3
Top = 2160
Width = 1335
End
Begin VB.CommandButton btRun
Caption = "Run"
Height = 495
Left = 3480
TabIndex = 2
Top = 1560
Width = 1335
End
Begin VB.CommandButton btSetting
Caption = "Setting"
Height = 375
Left = 3480
TabIndex = 1
Top = 600
Width = 1335
End
Begin VB.Frame Frame1
Caption = "Waveform"
Height = 2295
Left = 360
TabIndex = 8
Top = 1200
Width = 2655
Begin VB.Label Label5
Caption = "accuracy"
Height = 255
Left = 120
TabIndex = 13
Top = 1800
Width = 735
End
Begin VB.Label Label4
Caption = "offset"
Height = 255
Left = 120
TabIndex = 12
Top = 1320
Width = 735
End
Begin VB.Label Label3
Caption = "magnitude"
Height = 255
Left = 120
TabIndex = 11
Top = 840
Width = 735
End
Begin VB.Label Label2
Caption = "waveform"
Height = 255
Left = 120
TabIndex = 10
Top = 360
Width = 855
End
End
Begin VB.Label Label1
Caption = "Select a device from list"
Height = 255
Index = 0
Left = 360
TabIndex = 0
Top = 240
Width = 1815
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub btExit_Click()
End
End Sub
Private Sub btRun_Click()
SetState (STATE_Run)
'Step 1: Device open
ErrCde = DRV_DeviceOpen(DeviceNum, DriverHandle)
If ErrCde <> SUCCESS Then
DRV_GetErrorMessage ErrCde, ErrMsg
MsgBox ErrMsg, "Device Open"
SetState (STATE_Ready)
Exit Sub
End If
'Step 2: Allocate memory used by driver
ReDim Buf(Conv)
'Step 3: Allocate memory for real voltage
ReDim VoltageBuf(Conv)
'Step 4: Allocate memory for binary data
ReDim BinaryBuf(Conv)
'Step 5: Allocate DMA buffer for DMA transfer
ptAllocateDMABuffer.CyclicMode = CyclicMode
ptAllocateDMABuffer.RequestBufSize = Conv * 2
ptAllocateDMABuffer.ActualBufSize = DRV_GetAddress(ActualBufSize)
ptAllocateDMABuffer.buffer = DRV_GetAddress(buffer)
ErrCde = DRV_AllocateDMABuffer(DriverHandle, ptAllocateDMABuffer)
If ErrCde <> SUCCESS Then
DRV_GetErrorMessage ErrCde, ErrMsg
MsgBox ErrMsg, "Driver Message"
DRV_DeviceClose DriverHandle
SetState (STATE_Ready)
Exit Sub
End If
' set real voltage to VoltageBuf
SetRealBuffer (Conv)
'Step 6: call FAOScale for transfer voltage to binary data
ptFAOScale.VoltArray = DRV_GetAddress(VoltageBuf(0))
ptFAOScale.BinArray = DRV_GetAddress(Buf(0))
ptFAOScale.chan = OutputChannel
ptFAOScale.Count = Conv
ErrCde = DRV_FAOScale(DriverHandle, ptFAOScale)
If ErrCde <> 0 Then
DRV_GetErrorMessage ErrCde, ErrMsg
MsgBox ErrMsg, "Driver Message"
DRV_FreeDMABuffer DriverHandle, pBuffer
DRV_DeviceClose DriverHandle
SetState (STATE_Ready)
Exit Sub
End If
'Step 7: Enable event feature
ptEnableEvent.EventType = ADS_EVT_AO_INTERRUPT
ptEnableEvent.Enabled = EventMode
ptEnableEvent.Count = 1
ErrCde = DRV_EnableEvent(DriverHandle, ptEnableEvent)
If ErrCde <> 0 Then
DRV_GetErrorMessage ErrCde, ErrMsg
MsgBox ErrMsg, "Driver Message"
DRV_FreeDMABuffer DriverHandle, pBuffer
DRV_DeviceClose DriverHandle
SetState (STATE_Ready)
Exit Sub
End If
ptEnableEvent.EventType = ADS_EVT_AO_BUFCHANGE
ErrCde = DRV_EnableEvent(DriverHandle, ptEnableEvent)
If ErrCde <> 0 Then
DRV_GetErrorMessage ErrCde, ErrMsg
MsgBox ErrMsg, "Driver Message"
DRV_FreeDMABuffer DriverHandle, pBuffer
DRV_DeviceClose DriverHandle
SetState (STATE_Ready)
Exit Sub
End If
ptEnableEvent.EventType = ADS_EVT_AO_TERMINATED
ErrCde = DRV_EnableEvent(DriverHandle, ptEnableEvent)
If ErrCde <> 0 Then
DRV_GetErrorMessage ErrCde, ErrMsg
MsgBox ErrMsg, "Driver Message"
DRV_FreeDMABuffer DriverHandle, pBuffer
DRV_DeviceClose DriverHandle
SetState (STATE_Ready)
Exit Sub
End If
ptEnableEvent.EventType = ADS_EVT_AO_UNDERRUN
ErrCde = DRV_EnableEvent(DriverHandle, ptEnableEvent)
If ErrCde <> 0 Then
DRV_GetErrorMessage ErrCde, ErrMsg
MsgBox ErrMsg, "Driver Message"
DRV_FreeDMABuffer DriverHandle, pBuffer
DRV_DeviceClose DriverHandle
SetState (STATE_Ready)
Exit Sub
End If
'Step 8: call FAOIntStart for start action
' Default steting - conversion number = 16384
' start channel = 0, pacer rate = 32768 Hz
' cyclic , enable event
ptFAODmaStart.buffer = DRV_GetAddress(Buf(0))
ptFAODmaStart.TrigSrc = TriggerSource
ptFAODmaStart.SampleRate = PacerRate
ptFAODmaStart.chan = OutputChannel
ptFAODmaStart.Count = Conv
ErrCde = DRV_FAODmaStart(DriverHandle, ptFAODmaStart)
If ErrCde <> 0 Then
DRV_GetErrorMessage ErrCde, ErrMsg
MsgBox ErrMsg, "Driver Message"
DRV_FreeDMABuffer DriverHandle, pBuffer
DRV_DeviceClose DriverHandle
SetState (STATE_Ready)
Exit Sub
End If
RepeatCount = 0
' if event feature is enabled , then create one thread.
If EventMode = MODE_EventEnable Then
End If
CheckTimer.Enabled = True
End Sub
Private Sub btSetting_Click()
SetState (STATE_Setting)
Form1.Hide
Setting.Show
PacerRate1 = PacerRate
Conv1 = Conv
OutputChannel1 = OutputChannel
CyclicMode1 = CyclicMode
TriggerSource1 = TriggerSource
EventMode1 = EventMode
Setting.Hz.Text = Str(PacerRate)
Setting.convno.Text = Str(Conv)
Setting.EditOutputChannel.Text = Str(OutputChannel)
If CyclicMode = MODE_Cyclic Then
Setting.cyclic.value = True
Else
Setting.noncyclic.value = True
End If
If TriggerSource = MODE_Internal Then
Setting.internal.value = True
Else
Setting.external.value = True
End If
If EventMode = MODE_EventEnable Then
Setting.enable.value = True
Else
Setting.disable.value = True
End If
End Sub
Private Sub btStop_Click()
SetState (STATE_Ready)
CheckTimer.Enabled = False
'Step 1: Stop D/A conversion for high speed
ErrCde = DRV_FAOTerminate(DriverHandle)
If ErrCde <> 0 Then
DRV_GetErrorMessage ErrCde, ErrMsg
MsgBox ErrMsg, "Driver Message"
DRV_FreeDMABuffer DriverHandle, pBuffer
DRV_DeviceClose DriverHandle
Exit Sub
End If
'Step 2: Free buffer
DRV_FreeDMABuffer DriverHandle, DRV_GetAddress(pBuffer)
'Step 4: Close driver
DRV_DeviceClose DriverHandle
End Sub
Private Sub CheckTimer_Timer()
Dim EventType As Long
ptCheckEvent.EventType = DRV_GetAddress(EventType)
ptCheckEvent.Milliseconds = 1000
ErrCde = DRV_CheckEvent(DriverHandle, ptCheckEvent)
If ErrCde <> 0 Then
DRV_GetErrorMessage ErrCde, ErrMsg
MsgBox ErrMsg, "Driver Message"
DRV_FreeDMABuffer DriverHandle, pBuffer
DRV_DeviceClose DriverHandle
SetState (STATE_Ready)
Exit Sub
End If
If (EventType = ADS_EVT_AO_TERMINATED) Then
btStop_Click
End If
End Sub
Private Sub CmbSelectWaveform_Click()
If CmbSelectWaveform.Text = "Sine" Then
Waveform = 0
End If
If CmbSelectWaveform.Text = "Triangle" Then
Waveform = 1
End If
If CmbSelectWaveform.Text = "Square" Then
Waveform = 2
End If
End Sub
Private Sub Combo1_Click()
If state = STATE_Begin Then
SetState (STATE_Ready)
End If
DeviceNum = devicelist(Combo1.ListIndex).dwDeviceNum
End Sub
Private Sub EditAccuracy_Change()
Accuracy = Int(Val(EditAccuracy.Text))
End Sub
Private Sub EditMagnitude_Change()
Magnitude = Val(EditMagnitude.Text)
End Sub
Private Sub EditOffset_Change()
offset = Val(EditOffset.Text)
End Sub
Private Sub Form_Load()
SetState (STATE_Begin)
RemoveX Me.HWND
Waveform = 0
Magnitude = 2.5
offset = 2.5
Accuracy = 1024
PacerRate = 32768
Conv = 32768
OutputChannel = 0
CyclicMode = MODE_Cyclic
TriggerSource = MODE_Internal
EventMode = MODE_EventEnable
If Waveform = WAVE_Sine Then
Form1.CmbSelectWaveform = "Sine"
End If
If Waveform = WAVE_Triangle Then
Form1.CmbSelectWaveform = "Triangle"
End If
If Waveform = WAVE_Square Then
Form1.CmbSelectWaveform = "Square"
End If
Form1.EditMagnitude = Magnitude
Form1.EditOffset = offset
Form1.EditAccuracy = Accuracy
Dim tt As Long
Dim tempStr As String
tt = DRV_GetAddress(devicelist(0))
ErrCde = DRV_DeviceGetList(tt, 255, 0)
If (ErrCde <> 0) Then
DRV_GetErrorMessage ErrCde, ErrMsg
MsgBox ErrMsg, vbOKOnly, "Error!!"
Exit Sub
End If
ErrCde = DRV_DeviceGetNumOfList(gnNumOfDevices)
If (ErrCde <> 0) Then
DRV_GetErrorMessage ErrCde, ErrMsg
Response = MsgBox(ErrMsg, vbOKOnly, "Error!!")
Exit Sub
End If
For i = 0 To (gnNumOfDevices - 1)
tempStr = ""
For ii = 0 To 49
tempStr = tempStr + Chr(devicelist(i).szDeviceName(ii))
Next ii
Form1.Combo1.AddItem tempStr
Next i
ErrMsg = String(255, 0)
szBuffer = String(255, 0)
szDescript = String(255, 0)
End Sub
Private Sub Form_Terminate()
If state <> STATE_Run Then
End
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -