sDAP 2022的脚本使用的是Python,因此在脚本中调用Python包和在Python中使用包一样。由于IronPython的限制,使用IronPython编译器时不支持使用C函数库的Python包,如numpy、scipy等。
首先将Python包放到sDAP安装目录下的Lib目录或%AppData%\sDAP\Scripts\目录下,然后在脚本中导入Python包。
下面的示例调用一个signals包,使用该包中的SeqareWave方法生成一个方波。
import sys
import clr
import System
import signals
# -- Use tab indentation by default (8 spaces) --
# -- Beginning of user code --
# -- This is the entry point of the script, do not modify the method name --
def main():
channel = dap.ActiveDocument.sNewChannel()
channel.ChannelName = 'Sequare wave'
x,y = signals.SquareWave(1,-1,0,200,10)
channel.DataX = System.Array[float](x)
channel.DataY = System.Array[float](y)
dap.ActiveDocument.sShowTimeDomain(channel)
运行结果