Excel 插件‘Aspen process data ‘在VBA中的基本使用

本文介绍了如何在Excel VBA中使用Aspen插件进行过程数据的获取,包括当前值、历史趋势、批次信息和子批次信息。详细讲解了设置References、读取数据的方法,并给出了时间计算函数和查找特定字符串的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

获取当前值Current process data (single value)

References

打开VBA编辑器,找到References勾选需要的插件在这里插入图片描述

需要额外勾选的插件有:
AspenProcessDataAddin
Aspen DataSource Locator
Aspen Process Data

如下图所示
在这里插入图片描述

读取当前值

'create a new IP21 DataSource object 
Private IP21DataSources As New AtProcessData.DataSources

Public Const VAR_Server As String = "IP21-XXXXXXXX"'IP21 server name
Public Const ATTR_IP_INPUT_VALUE As String = "IP_INPUT_VALUE"
'attribute name of 'Current Value' in IP21 server

Public Function ReadTagValue(sTag As String, sAttribut As String) As Variant
    ' Read a tag for a given attribute
    ' return "" if nothing found or error

    Dim resu As Variant 'Variant for output
    Dim oAtDataSource As AtProcessData.DataSource
    Dim oAtTag As AtProcessData.Tag
    Dim oAtAttr As AtProcessData.Attribute

    resu = ""
    Set oAtDataSource = IP21DataSources.Item(VAR_Server)
    'Set DataSource
    Set oAtTag = oAtDataSource.Tags.Add(sTag)
    'Set Tag Name
    Set oAtAttr = oAtTag.Attributes.Add(sAttribut)
    'Set Attribute Name

    oAtTag.Attributes.Query.UseCurrentTime = True
    'Set Time as current time
    oAtTag.Attributes.Read False
    'Enable to read attribute value

    If (oAtAttr.Valid = True) Then
        If oAtAttr.Value = "" Then
        	'If failed to fetch current value, return ''
            ReadTagValue = resu
        	Exit Function
        Else
        	'Get current value
            resu = (oAtAttr.Value)
        End If
    Else
    	'If failed to recognize the attribute name, return ''
        ReadTagValue = resu
        Exit Function
    End If

    oAtDataSource.Tags.RemoveAll
    Set oAtDataSource = Nothing
    Set oAtAttr = Nothing
    Set oAtTag = Nothing

    ReadTagValue = resu
    'return Output value

End Function

Sub test()
Cells(1, 1).Value = ReadTagValue("XXXXXXXXX", ATTR_IP_INPUT_VALUE)
End Sub

Note:
1、获取当前时间值
oAtTag.Attributes.Query.UseCurrentTime = True
2、获取某时间点的值
oAtTag.Attributes.Query.Time = Format(“2021/07/01 00:00:00”, “yyyy/MM/DD HH:mm:ss”)

获取历史趋势Historic process data list

References

打开VBA编辑器,找到References勾选需要的插件在这里插入图片描述

需要额外勾选的插件有:
AspenProcessDataAddin
Aspen DataSource Locator
Aspen Process Data

如下图所示
在这里插入图片描述

获取历史值列表

'create a new IP21 DataSource object
Private IP21DataSources As New AtProcessData.DataSources

Public Const VAR_Server As String = "IP21-XXXXXXX" 'IP21 server name
Public Const ATTR_IP_INPUT_VALUE As String = "IP_INPUT_VALUE" ''attribute name of 'Current Value' in IP21 server
Public Const ValueList_MaxNum As Integer = 500 ' maximum capacity of history value list
Public Const IntervalPeriod As Integer = 2 'interval period between each history data
Dim HistoryCap As Variant 'real capacity of history value list


Sub ReadTagHistory(sTag As String, sAttribut As String, sStartTime As Date, sEndTime As Date, HistoryOutput() As Double)
    ' Read a list of historic tag value for a given attribute
    ' Output to an externally defined list variable
    ' return "" if nothing found or error
    Dim i As Integer
    Dim oAtDataSource As AtProcessData.DataSource
    Dim oAtTag As AtProcessData.Tag
    Dim oAtAttr As AtProcessData.Attribute
    Dim oHistory As AtProcessData.History
    
    'Set DataSource
    Set oAtDataSource = IP21DataSources.Item(VAR_Server)
    'Set Tag Name
    Set oAtTag = oAtDataSource.Tags.Add(sTag)
    'Set Attribute Name
    Set oAtAttr = oAtTag.Attributes.Add(sAttribut)
    'Set History list object
    Set oHistory = oAtTag.History
    
    'Settings of history data filtter
    oHistory.Query.BeginTime = sStartTime
    oHistory.Query.EndTime = sEndTime
    oHistory.Query.Extrapolate = False
    oHistory.Query.DetermineInterpolationStart = False
    oHistory.Query.Period = IntervalPeriod 'interval period between each history data
    oHistory.Query.PeriodUnits = apdHour ' unit of interval period time
    oHistory.Query.Method = apdValue
    oHistory.Query.Start = apdStartTime
    oHistory.Query.Stepped = False
    oHistory.Query.MaxPoints = ValueList_MaxNum
    oHistory.Query.Type = apdInterpolated
    
    'Get history value
    oHistory.Read False
    oAtTag.Attributes.Read False
    
    'Fill the history value list
    HistoryCap = 0
    If oHistory.Samples.Count = 0 Then
        If oAtAttr.Value = "" Then
        End If
    Else
        For i = 1 To oHistory.Samples.Count
            If oHistory.Samples(i).Value = "" Then
            Else ' If value is not NULL
                HistoryCap = HistoryCap + 1 'add the capacity of history value list
                HistoryOutput(HistoryCap) = oHistory.Samples(i) 'save the value in the list
            End If
        Next
    End If
    
    oAtDataSource.Tags.RemoveAll
    Set oAtDataSource = Nothing
    Set oAtAttr = Nothing
    Set oAtTag = Nothing
    Set oHistory = Nothing

End Sub

Public Function AddHour(ByVal sTime As String, sAddNum As Integer) As String
'Add X hours to a Time string
    Dim dt As Date
    dt = CDate(sTime)
    dt = DateAdd("h", sAddNum, dt)
    AddHour = Format(dt, "YYYY/MM/DD hh:mm:ss")
End Function

Sub test()
    Dim ValueList(ValueList_MaxNum) As Double
    Dim index As Integer
    Dim Start_Time As Date, End_Time As Date
    Start_Time = Format("2021/07/01 00:00:00", "YYYY/MM/DD hh:mm:ss")
    End_Time = Format("2021/07/02 00:00:00", "YYYY/MM/DD hh:mm:ss")
    Call ReadTagHistory("XXXXXXXXX", ATTR_IP_INPUT_VALUE, Start_Time, End_Time, ValueList)
    Cells(1, 2) = "XXXXXXXXX"
    For index = 1 To HistoryCap - 1 'print result except value at End Time
        Cells(index + 1, 1) = AddHour(Start_Time, (index - 1) * IntervalPeriod)
        Cells(index + 1, 2) = ValueList(index)
    Next
End Sub

获取历史值列表运行结果

在这里插入图片描述

Note

时间计算函数——小时增加

输入时间字符串和增加的小时数,输出一个计算后的时间字符串

Public Function AddHour(ByVal sTime As String, s
### 部署 Stable Diffusion 的准备工作 为了成功部署 Stable Diffusion,在本地环境中需完成几个关键准备事项。确保安装了 Python 和 Git 工具,因为这些对于获取源码和管理依赖项至关重要。 #### 安装必要的软件包和支持库 建议创建一个新的虚拟环境来隔离项目的依赖关系。这可以通过 Anaconda 或者 venv 实现: ```bash conda create -n sd python=3.9 conda activate sd ``` 或者使用 `venv`: ```bash python -m venv sd-env source sd-env/bin/activate # Unix or macOS sd-env\Scripts\activate # Windows ``` ### 下载预训练模型 Stable Diffusion 要求有预先训练好的模型权重文件以便能够正常工作。可以从官方资源或者其他可信赖的地方获得这些权重文件[^2]。 ### 获取并配置项目代码 接着要做的就是把最新的 Stable Diffusion WebUI 版本拉取下来。在命令行工具里执行如下指令可以实现这一点;这里假设目标路径为桌面下的特定位置[^3]: ```bash git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git ~/Desktop/stable-diffusion-webui cd ~/Desktop/stable-diffusion-webui ``` ### 设置 GPU 支持 (如果适用) 当打算利用 NVIDIA 显卡加速推理速度时,则需要确认 PyTorch 及 CUDA 是否已经正确设置好。下面这段简单的测试脚本可以帮助验证这一情况[^4]: ```python import torch print(f"Torch version: {torch.__version__}") if torch.cuda.is_available(): print("CUDA is available!") else: print("No CUDA detected.") ``` 一旦上述步骤都顺利完成之后,就可以按照具体文档中的指导进一步操作,比如调整参数、启动服务端口等等。整个过程中遇到任何疑问都可以查阅相关资料或社区支持寻求帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值