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

📄 devobj.cls

📁 PCI1713板卡驱动,VB编写,8个通道,每个通道500次采样,对采样数据处理,为稳定现场信号的不稳定性
💻 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 = "DevObj"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
'Dim lpDEVCONFIG_AI As DEVCONFIG_AI
'Dim lpAIGetConfig As PT_AIGetConfig
'Dim gnNumOfSubdevices As Integer
Dim fVoltage(0 To 31) As Single
Dim ErrCount As Integer
Dim hplxflag As Boolean

Dim mDevChannel         As Long      '设备通道个数
Dim mDealFlag           As Long      '数据处理标志
Dim mInputMode          As Long      '通道的输入方式
Dim mInputRange         As Long      '输入量程
Dim mChangeMode         As Long      '码制转换方式
Dim mChangeK            As Single
Dim mChangeV            As Long
Dim mHandle             As Long      'NT下读写端口的句柄

Public Function InitDevRun(objMcgsSave As Object, objMcgsData As Object) As Long
   '*  函数目的  :  MCGS运行环境启动时调用接口一次,对设备构件进行初始化工作
   '*  参数意义  :  objMcgsSave - MCGS存盘数据库对象
   '*              objMcgsData - MCGS实时数据库对象
   
   '*  函数返回  :  InitDevRun = 0 - 设备初始化成功
   '*              InitDevRun = 1 - 设备初始化失败
    ErrCde = DRV_DeviceOpen(0, DeviceHandle)
    'If (ErrCde <> 0) Then
    '  DRV_GetErrorMessage ErrCde, szErrMsg
    '  Response = MsgBox(szErrMsg, vbOKOnly, "Error!!")
    '  Exit Sub
   ' End If
End Function

Public Function RunDevCommand(objMcgsData As Object, ByVal strCommandString As String) As Long
   '*  函数目的  :  MCGS运行环境中,对设备执行指定的设备命令时调用接口一次
   '*  参数意义  :  objMcgsData - MCGS实时数据库对象
   '*              strCommandString - 设备命令字符串
   '*  函数返回  :  RunDevCommand = 0 - 命令正确执行
   '*              RunDevCommand = 2 - 无效的设备命令
   
PROC_EXIT:
   '*  设备命令无效
   RunDevCommand = 2
   
End Function

Public Function CollectDevDat(alngDataFlag As Variant, asngDataValue As Variant, astrDataString As Variant) As Long
   '*  函数目的  :  MCGS运行环境中,根据指定的采集周期,定时调用本接口,对设备进行数据采集工作
   '*  参数意义  :  alngDataFlag - Long型数组,设备对应通道的数据是否需要处理,一般不用
   '*              asngDataValue - Single型数组,设备对应的数值型通道的数值,当通道为字符型时,表示通道的值在astrDataString数组中的位置
   '*              astrDataString - String型数组,设备对应的字符型通道的值
   '*  函数返回  :  CollectDevDat = 0 - 采集数据有效,但只对返回的输入数据进行处理;
   '*              CollectDevDat = 1 - 采集数据有效,但对返回的输入输出数据都进行处理
   '*              CollectDevDat = 2 - 采集数据无效,不须进行处理。
   '*              CollectDevDat =-1 - 设备故障
   '*              CollectDevDat =-100 - 设备故障,但把第0通道的值返回,一般使用0通道的值来表示故障的具体信息
 Dim i As Integer
  Dim j As Integer
  Dim K As Integer
  
  Dim v(0 To 31, 1 To 300) As Single
  Dim sum As Single
  Dim t As Single
  
ErrCde = DRV_DeviceOpen(0, DeviceHandle)     ' Make sure device number = 0

ptMAIConfig.StartChan = 0
ptMAIConfig.NumChan = 7


For i = 0 To 32
usGainCode(i) = 17
'AddData(i) = 0
Next
 ptMAIConfig.GainArray = DRV_GetAddress(usGainCode(0))
 ErrCde = DRV_MAIConfig(DeviceHandle, ptMAIConfig)
 
 

  ptMAIVoltageIn.StartChan = 0
 ptMAIVoltageIn.NumChan = 7
  ptMAIVoltageIn.GainArray = DRV_GetAddress(usGainCode(0))
  ptMAIVoltageIn.TrigMode = 0
  
  ptMAIVoltageIn.VoltageArray = DRV_GetAddress(fVoltage(0))

ErrCde = DRV_MAIVoltageIn(DeviceHandle, ptMAIVoltageIn)

    
    For j = 1 To 300 Step 1
      For i = 0 To 6
        v(i, j) = fVoltage(i)
      Next i
    Next j
    For i = 0 To 6
     For K = 1 To 299
        For j = 1 To 300 - K
            If v(i, j) > v(i, j + 1) Then
                t = v(i, j)
                v(i, j) = v(i, j + 1)
               v(i, j + 1) = t
           End If
         Next j
       Next K
    Next i
   
    For i = 0 To 6
        sum = 0
         For j = 31 To 270 Step 1
          sum = sum + v(i, j)
         Next j
         fVoltage(i) = sum / 240
         asngDataValue(i) = fVoltage(i)
    Next i
 
 ' UpDateValue
   CollectDevDat = 0
   
End Function

Public Function GetDevName() As String
   '*  函数目的  :  MCGS运行环境中调用,供Mcgs读取设备的类型名称,在设备根据箱中显示
   '*  参数意义  :  无参数
   '*  函数返回  :  设备的类型名称
   
   GetDevName = "1713"
    
End Function

Public Function GetDevHelp() As Long
   '*  函数目的  :  MCGS组态环境中调用,在设备属性设置窗口的基本属性页中,按“在线帮助”行,调用本接口显示设备构件在线帮助
   '*  参数意义  :  无参数
   '*  函数返回  :  无返回值
   
   MsgBox "显示设备构件的在线帮助!"
   
End Function

Public Function SetDevPage(objMcgsSave As Object) As Long
   '*  函数目的  :  MCGS组态环境中调用,设置设备构件的内部属性。在设备属性设置窗口的基本属性页中,按“内部属性”行,调用本接口
   '*  参数意义  :  objMcgsSave - MCGS存盘数据库对象
   '*  函数返回  :  = 0 - 输入的内部属性设置有效,要保存
   
   MsgBox "MCGS组态环境中,显示设备构件的内部属性!"
   
End Function

Public Function InitNewDev(objMcgsSave As Object) As Long
   '*  函数目的  :  MCGS组态环境中调用,当把设备从设备工具箱中选取到设备窗口中时,调用本接口,设置设备的缺省属性值
   '*  参数意义  :  objMcgsSave -MCGS存盘数据库对象
   '*  函数返回  :  InitNewDev = 0 - 设备初始化成功
   '*              InitNewDev <>0 - 设备初始化失败
   
End Function

Public Function GetChlType(alngChlDataType As Variant, astrChlExplain As Variant) As Long
   '*  函数目的  :  MCGS运行环境中调用,Mcgs调用本接口读取设备各通道的数据类型和通道内容的文字描述,
   '*              在设备属性设置窗口的通道连接属性页中所显示的内容均来自本接口
   '*  参数意义  :  alngChlDataType - Long型数组,存储各通道的数据类型
   '*              astrChlExplain - String型数组,存储各通道内容的文字描述
   '*  函数返回  :  GetChlType = 0 - 调用成功
   '*              GetChlType <>0 - 调用失败
   '*
   '*  数据类型标识  = 1   开关型数据
   '*              = 2   数值型数据
   '*              = 3   字符型数据
   '*  当通道的数据类型为正数时,表示该通道的作用是把设备中读取的数据输入到Mcgs中
   '*  当通道的数据类型为负数时,表示该通道的作用是Mcgs中的数据送到设备来,供设备处理使用
      Dim i As Integer
    
    For i = 0 To 11
        alngChlDataType(i) = 2
        astrChlExplain(i) = "电压输入" + Format$(i + 1, "00")
    Next
End Function
Private Sub Class_Terminate()
        ErrCde = DRV_DeviceClose(DeviceHandle)
       ' End If
        'hplxflag = True
End Sub

'*  ================================================================================
'*  以下为设备构件的属性, 每个设备构件必须有的四个只读属性
'*  ================================================================================
Public Property Get DevType() As Long
   '*  函数目的  :  标明设备的类型 0-父设备 =1 子设备
   
   DevType = 0
   
End Property

Public Property Get DevStyle() As Long
   '*  函数目的  :  标明设备的种类 0-独立设备  =1 和串口父设备对应的子设备
   
   DevStyle = 0
   
End Property

Public Property Get DevChannel() As Long
   '*  函数目的  :  标明设备的通道个数
   
   DevChannel = 32

End Property

Public Property Get DevIONumber() As Long
   '*  函数目的  :  标明设备的所占用系统IO的个数
   
   DevIONumber = 4
   
End Property

⌨️ 快捷键说明

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