frmmain.frm

来自「16 relay output channels and 16 isolated」· FRM 代码 · 共 647 行 · 第 1/2 页

FRM
647
字号
            BorderStyle     =   1  'Fixed Single
            Caption         =   "&2"
            Height          =   255
            Index           =   2
            Left            =   3960
            TabIndex        =   13
            Top             =   240
            Width           =   615
         End
         Begin VB.Label Label4 
            Alignment       =   2  'Center
            BorderStyle     =   1  'Fixed Single
            Caption         =   "&1"
            Height          =   255
            Index           =   1
            Left            =   4560
            TabIndex        =   12
            Top             =   240
            Width           =   615
         End
         Begin VB.Label Label4 
            Alignment       =   2  'Center
            BorderStyle     =   1  'Fixed Single
            Caption         =   "&0"
            Height          =   255
            Index           =   0
            Left            =   5160
            TabIndex        =   10
            Top             =   240
            Width           =   615
         End
      End
      Begin VB.CheckBox chkDiInterrupt 
         Caption         =   "DI 7 interrupt:"
         Height          =   255
         Index           =   7
         Left            =   3360
         TabIndex        =   8
         Top             =   2520
         Width           =   1335
      End
      Begin VB.CheckBox chkDiInterrupt 
         Caption         =   "DI 6 interrupt:"
         Height          =   255
         Index           =   6
         Left            =   3360
         TabIndex        =   7
         Top             =   2160
         Width           =   1335
      End
      Begin VB.CheckBox chkDiInterrupt 
         Caption         =   "DI 5 interrupt:"
         Height          =   255
         Index           =   5
         Left            =   3360
         TabIndex        =   6
         Top             =   1800
         Width           =   1335
      End
      Begin VB.CheckBox chkDiInterrupt 
         Caption         =   "DI 4 interrupt:"
         Height          =   255
         Index           =   4
         Left            =   3360
         TabIndex        =   5
         Top             =   1440
         Width           =   1335
      End
      Begin VB.CheckBox chkDiInterrupt 
         Caption         =   "DI 3 interrupt:"
         Height          =   255
         Index           =   3
         Left            =   240
         TabIndex        =   4
         Top             =   2520
         Width           =   1335
      End
      Begin VB.CheckBox chkDiInterrupt 
         Caption         =   "DI 2 interrupt:"
         Height          =   255
         Index           =   2
         Left            =   240
         TabIndex        =   3
         Top             =   2160
         Width           =   1335
      End
      Begin VB.CheckBox chkDiInterrupt 
         Caption         =   "DI 1 interrupt:"
         Height          =   255
         Index           =   1
         Left            =   240
         TabIndex        =   2
         Top             =   1800
         Width           =   1335
      End
      Begin VB.CheckBox chkDiInterrupt 
         Caption         =   "DI 0 interrupt:"
         Height          =   255
         Index           =   0
         Left            =   240
         TabIndex        =   1
         Top             =   1440
         Width           =   1335
      End
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub EnableControls(bEnabled As Boolean)
Dim i As Integer

  
  'DI interrupt event controls enable or disable
  For i = 0 To 7
    lstDiSignalCondition(i).Enabled = bEnabled
    chkDiInterrupt(i).Enabled = bEnabled
    txtDiInterrupt(i).Enabled = bEnabled
  Next i
 
End Sub

Private Sub CloseCreatedEvents()
Dim i As Integer

  ' Clear all checked event.
  ' It's better to contain the same event open/close count. The driver
  ' cannot not know which program open and close event, just keep the
  ' open counts for handling the event exporting.
  '
  For i = 0 To 7
    If (chkDiInterrupt(i).value = 1) Then chkDiInterrupt(i).value = 0
  Next i
  
  
End Sub

Private Sub chkDiInterrupt_Click(Index As Integer)
Dim bEnabled As Boolean
Dim EventEnable As PT_EnableEvent
Dim lErrCde As Long
  '
  ' Enable/disable driver to export DI interrupt

  If (chkDiInterrupt(Index).value = 1) Then
    bEnabled = True
  Else
    bEnabled = False
  End If
  
  EventEnable.Count = 1
  EventEnable.Enabled = bEnabled
  EventEnable.EventType = ADS_EVT_DI_INTERRUPT0 + Index
  If lDriverHandle <> 0 Then
  lErrCde = DRV_EnableEvent(lDriverHandle, EventEnable)
  SendMessage Me.hwnd, WM_ADVMSGERR, lErrCde, 0
  End If
  
End Sub


Private Sub cmdCloseDevice_Click()
 Dim lErrCde As Long
   If (lDriverHandle <> 0) Then
   lErrCde = DRV_DeviceClose(lDriverHandle)
   If (lErrCde <> 0) Then
     SendMessage Me.hwnd, WM_ADVMSGERR, lErrCde, 0
     Exit Sub
   End If
   End If

   cmdOpenDevice.Enabled = True
   cmdCloseDevice.Enabled = False
   
End Sub

Private Sub cmdExit_Click()
  Unload Me
  ExitProcess 0
End Sub

Private Sub cmdOpenDevice_Click()
 Dim lErrCde As Long
    lErrCde = DRV_DeviceOpen(mDeviceNum, lDriverHandle)
    If (lErrCde <> 0) Then
      SendMessage Me.hwnd, WM_ADVMSGERR, lErrCde, 0
      Exit Sub
    End If
    Call CloseCreatedEvents
    cmdOpenDevice.Enabled = False
   cmdCloseDevice.Enabled = True
End Sub

Private Sub cmdSelectDevice_Click()
 
 Dim dwData As Long, lBitTracing As Long
 Dim i As Integer
 Dim lErrCde As Long
 Dim lData As Long
  'Close all previouse open events.
  CloseCreatedEvents
  
  lErrCde = DRV_SelectDevice(0, False, mDeviceNum, mDeviceName)
  If (lErrCde <> 0) Then
      SendMessage Me.hwnd, WM_ADVMSGERR, lErrCde, 0
      Exit Sub
  End If
  txtDeviceName.Text = mDeviceName
  
  cmdOpenDevice.Enabled = False
  cmdCloseDevice.Enabled = True
  
  'Check this is correct device to use this demo program
  cmdStop.Enabled = False     'always disable stop command before running

  lErrCde = DRV_DeviceOpen(mDeviceNum, lDriverHandle)
  If (lErrCde <> 0) Then
      SendMessage Me.hwnd, WM_ADVMSGERR, lErrCde, 0
      Exit Sub
  End If
  
  DRV_DeviceGetProperty lDriverHandle, CFG_BoardID, lData, Len(lData)
  
  If (lData = BD_USB4761) Then
    EnableControls True
  Else
    EnableControls False
    Exit Sub
  End If
  
 lBitTracing = 1
 
 DRV_DeviceGetProperty lDriverHandle, CFG_IrqDiTriggerSignals, dwData, Len(dwData)
 
  For i = 0 To 7
    If ((lBitTracing And dwData) = 0) Then
      lstDiSignalCondition(i).ListIndex = 0
    Else
      lstDiSignalCondition(i).ListIndex = 1
    End If
    txtDiInterrupt(i).Text = "0"
    
    lBitTracing = lBitTracing * 2
  Next i
  
  cmdOpenDevice.Enabled = False
  cmdCloseDevice.Enabled = True

End Sub

Private Sub cmdStart_Click()
Dim i As Integer

  '
  ' Clear previous value
  For i = 0 To 7
    txtDiInterrupt(i).Text = "0"
  Next i
  
  '
  ' Create thread to check events
  '
  gbStopThread = False
  
  StartThread Me.hwnd
  '
  'User controls setting
  '
  cmdStop.Enabled = True
  cmdExit.Enabled = False
  cmdStart.Enabled = False
  cmdSelectDevice.Enabled = False

End Sub

Private Sub cmdStop_Click()
  
  gbStopThread = True
  
  cmdStop.Enabled = False
  cmdExit.Enabled = True
  cmdStart.Enabled = True
  cmdSelectDevice.Enabled = True
  
End Sub

Private Sub Form_Load()

  Hook Me.hwnd
  cmdSelectDevice_Click
  
End Sub

Private Sub Form_Unload(Cancel As Integer)

  '
  ' Stop still working events and close device.
  '
 Call CloseCreatedEvents
 Call cmdCloseDevice_Click
End Sub

Private Sub lstDiSignalCondition_Click(Index As Integer)
Dim lValue As Long, i As Integer

  '
  ' Setup Auxiliary DI interrupt signal condition.
  '
  lValue = lstDiSignalCondition(7).ListIndex
  
  For i = 6 To 0 Step -1
    lValue = lValue * 2 + lstDiSignalCondition(i).ListIndex
  Next i
  If lDriverHandle <> 0 Then
  DRV_DeviceGetProperty lDriverHandle, CFG_IrqDiTriggerSignals, lValue, Len(lValue)
  End If
  
End Sub

⌨️ 快捷键说明

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