在Linux下使用Python和USBTMC将信号加载并读入波形发生器?

2024-06-02 13:01:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要把显示的信号加载到波形发生器中。在

通过USBTMC驱动波发生器的代码:

我使用以下代码创建示例代码。在

如何将产生的啁啾信号加载到波发生器中?在


Tags: 代码示例信号usbtmc
1条回答
网友
1楼 · 发布于 2024-06-02 13:01:04

USBTMC是USB测试和测量类。这些命令是SCPI命令。必须加载的驱动程序系统驱动程序是usb_tmchttp://lxr.free-electrons.com/source/drivers/usb/class/usbtmc.c)。插入安捷伦设备后,请在dmesg的输出中检查此项。波形发生器应该出现在/dev/usbtmcx/dev/ttySx(用系统上的数字代替x)

Configuring interface

Recent Linux kernels support USBTMC out of the box. Connect your instrument and check if /dev/usbtmc* exists. Set appropriate permissions to /dev/usbtmc*

Open an interface to the USB instrument t0 = usbtmc('/dev/usbtmc0')

Write to listener: usbtmc_write(t0, '*IDN?')

Blocking read call [binary read], returns uint8 array data = usbtmc_read(t0, 10000) Convert uint8 array to string, char(data)

close usbtmc session usbtmc_close(t0)

http://wiki.octave.org/Instrument_control_package(不是Python;是Octave,仅显示基本用法)。在

在Python中是相似的。见http://scruss.com/blog/tag/usbtmc/。在

首先检查dmesg当您插入Agilent设备并按照https://github.com/python-ivi/python-usbtmc上的说明操作时,dmesg驱动程序已加载(创建udev规则,…,检查/dev/usbtmc0是否出现,等等)

如果一切正常,编写一个简单的测试脚本,看看安捷伦设备是否响应:

import usbtmc
instr =  usbtmc.Instrument(2391, 5973) // The 2391 and 5973 are USB idVendor and idProduct of the Agilent MSO7104A converted to decimal
print(instr.ask("\***IDN?"))
# returns 'AGILENT TECHNOLOGIES,MSO7104A,MY********,06.16.0001'

然后编写一个Python“driver”,将标准TMC命令映射到Python函数(read()write(),…),就像https://gist.github.com/pklaus/2597049中的usbtmc.py。这个在here里。在

一个非常基本的波形发生器控制脚本在http://markjones112358.co.nz/projects/Python-Controlled-Function-Generator/

如果要设置频率,请编写SCPI命令FREQ,后跟所需的值:

^{pr2}$

如果您想设置一个振幅,您可以编写命令VOLT,后跟所需的值:

amplitude = 5
write("VOLT %f" % amplitude)

复杂的部分是创建和下载二进制任意文件。在

不能直接用NumPy矩阵加载Agilent,因为它只接受特殊的二进制文件,所以必须将chirp矩阵转换成二进制文件。见http://cp.literature.agilent.com/litweb/pdf/E4400-90627.pdf第42页,62。也许可以将第62页的示例翻译成Python来生成二进制arb文件

当您创建波形二进制arb文件时,您可以使用SCPI write operationshttps://community.keysight.com/thread/20217(在C中)来传输它

  // Downloading
  oFio.WriteIEEEBlock("SOURce1:DATA:ARBitrary testarb,",z,true); binary write

当使用上面这样的Python驱动程序时,可以将其转换为Python:

binary_write("SOURce1:DATA:ARBitrary testarb,", z, true);(二进制写入)

http://rfmw.em.keysight.com/spdhelpfiles/33500/webhelp/US/Content/__I_SCPI/DATA_Subsystem.htm

(在234页的用户指南http://cp.literature.agilent.com/litweb/pdf/33220-90002.pdf中,ff页也是相关SCPI命令的摘要。在网上搜索。在

https://de.mathworks.com/company/newsletter/articles/downloading-a-custom-waveform-to-an-arbitrary-waveform-generator.html中是一个名为快速控制函数生成器的MATLAB工具箱,它解决了这个问题。在

相关问题 更多 >