Use PyVISA to Program Test Tools with Python - Workbench Wednesdays

요약

이 비디오에서는 파이썬 코드를 사용하여 테스트 장비를 자동화하는 방법을 설명합니다. Raspberry Pi를 사용하여 USB, LAN 또는 직렬 포트가 있는 도구를 제어하는 방법을 보여줍니다. VISA 드라이버와 SCPI 명령을 사용하여 장비와 통신하고, 실제 예제를 통해 자동화 측정 설정을 구축하고 문제 해결 팁을 제공합니다.

  • 파이썬과 VISA 드라이버를 사용하여 테스트 장비 자동화
  • SCPI 명령을 사용하여 장비 제어
  • 자동화 설정 구축 및 문제 해결

소개

이 비디오는 파이썬 코드를 사용하여 테스트 장비를 자동화하는 방법을 소개합니다. 자동화를 통해 반복적인 작업을 가속화하고, 테스트 도구가 기본적으로 수행하지 못하는 측정을 수행할 수 있습니다. 모든 코드와 설치 세부 정보는 element14 커뮤니티 링크에서 확인할 수 있습니다.

자동화 설정

자동화 설정에는 Raspberry Pi, USB, LAN 또는 직렬 포트가 있는 도구가 필요합니다. Raspberry Pi는 Linux에서 잘 작동하며, 파이썬을 실행하는 모든 장치에서 사용할 수 있습니다. 멀티컴프 프로 벤치 DMM을 사용하여 예제를 설명하며, DMM을 컴퓨터의 가상 직렬 포트를 통해 연결합니다. 파이썬 스크립트는 Pi-VISA 모듈을 로드하여 DMM과 통신합니다.

VISA 및 SCPI

VISA(Virtual Instrument Software Architecture)는 소프트웨어가 물리적 연결에 관계없이 장비와 통신하는 데 도움이 되는 API입니다. Pi-VISA 모듈은 VISA 드라이버와 인터페이스하는 파이썬 래퍼입니다. VISA 드라이버는 SCPI(Standard Commands for Programmable Instruments) 사양에 따라 명령을 보냅니다. SCPI 명령은 계층 구조로 구성되며, 대소문자를 혼합하여 사용합니다.

GPIB, LXI, RS232 및 USB TMC

GPIB(General Purpose Instrument Bus)는 오래된 장비 연결 표준이며, LXI(LAN Extensions for Instruments)는 이더넷을 사용하는 최신 표준입니다. USB TMC(USB Test and Measurement Class)는 USB를 통해 장비를 연결하는 데 사용됩니다. VISA는 LAN도 지원하며, 리소스 문자열은 일반적으로 TCP/IP 주소와 포트를 포함합니다.

자동화 측정 예제

이전 비디오에서 소개된 The Intern을 사용하여 연산 증폭기 회로의 주파수 응답을 자동 측정합니다. DMM, 함수 발생기, 전원 공급 장치 및 오실로스코프를 사용하여 회로를 측정합니다. 파이썬 스크립트는 장비에 연결하고 구성하며, 주파수를 설정하고 전압과 위상차를 측정합니다. 데이터는 CSV 파일에 기록되어 그래프로 표시할 수 있습니다.

문제 해결 팁

장비가 응답하지 않을 때 쿼리 지연을 활성화하고, 라인 종결자를 변경합니다. 일부 장비는 "Operation Complete" 명령을 지원하지 않을 수 있습니다. USB TMC 장치는 Linux에서 잘 작동하지만, Windows에서는 추가 구성이 필요할 수 있습니다. 장비가 로컬 모드 또는 원격 모드에서 작동하는지 확인합니다.

결론

자동화는 어려울 수 있지만, 문제 해결을 통해 장비와 연결되면 명확한 해결책을 찾을 수 있습니다. element14 커뮤니티에서 도움을 받을 수 있습니다.

유튜브 영상을 몇 초 만에 요약하세요

무료 Summ 앱으로 어떤 영상이든 이런 요약을 원하는 언어로 받아보세요.

App Store에서 다운로드
Google Play에서 다운로드

스크립트

“Use PyVISA to Program Test Tools with Python - Workbench Wednesdays”의 전체 스크립트입니다. 타임스탬프를 클릭하면 해당 장면부터 영상이 열려요. 다른 영상이 필요하다면 유튜브 스크립트 추출기를 이용하세요.

0:00 hello and welcome back to workbench Wednesdays my name is James and in this video I show how a few lines of python code can automate a bunch of test equipment learning how to do this can help you speed up repetitive tasks and perform measurements your test tools do not do natively and it's just fun to write a simple test script that makes all kinds of cool Test action happen all of the code and details of what to install are available in the link below on the element 14 Community with that let's go automate thank you foreign heads up getting into this automation

0:45 stuff turns this video into acronym soup so my goal here is to introduce you to all of the pieces and show a couple of examples first off I am using a Raspberry Pi because well Linux works really well and the pi 400 is an adorable option for this task but anything running Linux and python should work next I am focused on tools with USB Lan or serial ports later I explained all of the words I'm about to use that you have never heard of okay let's start with an example using this multi-comp Pro bench DMM while this DMM does have a USB port connecting to the nine pin serial Port is a little easier especially with a serial to USB cable on the Linux computer we have a python script that loads a module called Pi Visa it has a resource manager that we can use to connect to the DMM through

1:33 the computer's virtual serial Port since the DMM is an actual serial Port we need to set the baud rate now we issue a query which writes the star idn question mark command to the DMM and reads back the response then another query to read the active measurement value running the script we see the identify string and a readout that matches the DMM using a loop and a magic python module now we get a continuous reading with proper units so a handful of commands and we're talking to the DMM using python pretty cool huh now there is a ton going on in that code that we need to unpack so let's start with why is the module even called Pi Visa Visa stands for the virtual instrument

2:18 software architecture it is an API that makes it easier for software to communicate with an instrument regardless of its physical connection the pi Visa module is a python wrapper that interfaces with a Visa driver a Visa driver allows software to send commands formatted according to the standard commands for programmable instruments specification or you can shorten it to Skippy this long string is a single Skippy command from the dmm's programming manual it has a command and parameter section separated by a space the parameter side is usually one value or keyword the braces and pipes indicate a choice of options here it's a numeric value or the words minimum or maximum the commands are a multi-level tree separated by colons for example since

3:03 has voltage and other commands like resistance in it also the square brackets mean that the since root command is optional voltage can refer to AC or DC and then there is a third level range command which is used to set the measurement range notice the mixed case for all of the words capital letters are required and lowercase is optional but the commands themselves are case insensitive last not shown is that this command usually ends with a new line and carriage return character so this short form command sets the DC voltage range to its maximum setting this example shows the asterisk character which indicates a special command such as preset or identify the semicolon is a shortcut to send multiple commands on a

3:49 single line the question mark is used for commands which should return a value the good thing is that commands for instruments from multiple vendors may look very similar the bad thing is that the behaviors themselves are not defined for example on this scope star rst is the same as pressing the front panel's preset button while on the power supply from the same manufacturer that same command reboots the entire instrument which by the way when an instrument reboots you usually lose the Visa connection to it you might also hear of Idi which is another API known as interchangeable virtual instruments it mostly replaced a really old standard called bxi but in general it uses the Visa driver to also send Skippy commands so to talk to instruments the computer

4:36 needs a Visa driver Visa drivers are available from several test measurement manufacturers including ni Roden Schwartz and keysight plus a few others however make sure you read the licensing terms very carefully in the case of at least one of those my interpretation of their licenses you cannot use their visa software unless you use their popular automation software some of their Hardware or pay a 700 licensing fee for that reason in this video I am using an open source Visa driver called Pi Visa Dash Pi which is not confusing at all is it so to be clear I am using the python module Pi Visa as a wrapper to the Visa driver called Pi Visa Dash pi now you can tell Pi Visa which Visa driver to

5:22 use if you have multiple installed when you start getting targeted ads for credit cards please don't blame me anyway next let's talk about gpib LXI rs232 and USB TMC really I'm not just making up letters as I talk these are all real things engineers say as if they're actual words about 500 years ago Hewlett Packard was best known as a test and measurement company back then some of their instruments included an HP instrument bus connector hpib connected entire Labs of equipment together and could be controlled by a desktop calculator the Skippy controllers got smaller over time eventually the connector turned into the IEEE standard 488 and became known as the general purpose instrument

6:07 bus or gpib across the electronics Industry Standalone instruments adopted gpib and then eventually adopted the Skippy command set around the 2000s ethernet became a popular replacement for gpib related around that time a standard emerge called the Lan extensions for instruments or LXI I'm not covering LXI in this video but it turns out most LXI compliant instruments also support visa and Skippy by the way Visa supports Lan as well its resource string is typically TCP IP the address sometimes the port and then either instr or socket or h-slip socket is basically just a telnet connection to the instrument which is an easy way to connect and test commands without installing anything well except these days you probably have to install a

6:52 telnet client as USB replace serial ports on PCS a replacement for proprietary gpib card Drive drivers emerge called USB TMC if an instrument supports USB TMC most modern operating systems have a generic driver that works with Visa drivers so other software can talk to them for this case the Visa resource string is usually the vendor ID product ID and the serial number of the instrument fortunately you can use Pi visa and its list resources function to verify what USB TMC devices it can see then you can just copy these resource strings and yeah I don't know why this instrument has all this junk on the end of its string but using this exact name works that said not all USB ports on instruments are USB TMC sometimes they

7:38 are virtual serial ports and sometimes they are custom devices that interface through something like a custom lab USB driver and coming back to the serial ports in the DMM demo I skipped over the resource string it was asrl Dev tty0 the number is the com device identifier from the OS and asrl is a Visa resource name that stands for I give up I'm skipping over gpib because good gpib adapters are extremely expensive and out of scope for this video one thing to know is that there are some inexpensive adapters out there that have dodgy Visa support so be careful if buying one of those okay now let's go and expand the previous example to automate measurements from a previous video [Music]

8:27 foreign ly on workbench Wednesdays we introduced The Intern and manually measured the frequency response of an op-amp circuit while it only took him a few minutes the process was very error prone and slow if we wanted to make circuit changes so now let's teach the intern about getting replaced by automation here is the DMM from before a function generator a power supply and an oscilloscope connected to the tl081 op-amp Circuit the function generator signal goes in the scope measures the in and out and the DMM measures the voltage rail of the power supply like before the DMM is connected with serial the power supply and oscilloscope are connected by Lan and the function generator is connected by its only option USB on the pi 400 we have a python script that connects to the instruments and configures them

9:13 for example on the oscilloscope I preset it then turn on channels 2 and 4 and configure some measurements there is a loop to send each of these Skippy commands now I'm not going to go line by line in this code because you can download the full script on the element14 community with the link below but the core automation stuff are these for Loops that set a frequency and then measure the voltage in and out plus the phase difference each data point gets written to a CSV file that can be opened in a text editor or spreadsheet program and then you can graph the data like we showed in the body plots episode okay here's the full code running while I drink my tea the nice thing about this setup is that I can easily change the op amp circuit or the parameters that the script sweeps I mean now that the code is done

9:59 I have a question yes can you write something in Python to do the graph instead of doing it with that other program well yeah I just wanted to focus on the automation I'm not a python programmer also doesn't that scope do this measurement I saw a video about that somewhere well yeah this scope has that frequency analysis option in fact I think all of my Scopes do I just use this measurement as one example and then why use a function generator the scope also has one of those built in yep you're right I could have done that thanks for your feedback now one more thing I want to talk about is that this automation stuff is not always Plug and Play So when your instruments won't talk to you here's a few things to look for [Music] when the hello world idn fails try two

10:47 things first enable a small query delay to pause between the read and write some instruments need it some do not next change the line Terminators used by pi Visa I found TCP instruments using socket need to be changed to just using the new line character not everything supports commands like operation complete and some instruments like the DMM says it does in the manual but it always returns zero which can complicate error handling when you cannot tell if the instrument is done processing the last command one way around this is just to keep sending commands until they're successful sometimes instruments stop responding especially after you send them a whole bunch of bad commands resetting the tool or physically cycling its connection might help USB devices that require a PC to operate are not usually USB TMC for example this

11:33 oscilloscope's Windows software provides a Skippy interface over TCP but not all USB based instruments have this support speaking of USB TMC the python Visa driver works great with USB devices on Linux it's why I use the pi 400 but Windows is a different story for example here are the same four instruments we've used before all connected by USB device manager and windows can see them however Pi Visa with the python driver cannot even more however when pi Visa uses the RNs Visa driver instead it can see them just fine using this tool zadig or zedig you can change the instruments INF from USB TMC to lib USB but then you also need to install a different version of lib USB so that Pi USB can let Pi Visa connect

12:20 to the new driver okay look I got this process to work once but then I couldn't repeat it for the video so that's why I recommend using Linux instead even if you have to use a virtual machine at least when you're using USB devices other interfaces like Lan work fine with Windows last most instruments can only operate in local or remote mode sometimes they automatically go back to local sometimes they do not when they do not you must press a local button so that the front panel starts working again some of those issues might seem frustrating but that's only because they are however once you get connected to the instrument the issues you run into usually have a clear solution one place you can get help with this kind of stuff is the l14 community and even though I

13:05 say this in every video I really mean it this time remember that is the best place to ask questions because no automation question has a short answer as always thank you for watching for now it is time for me to get back to issuing Skippy commands over a Visa driver through an IBI interface on a TCP connection to my remote Electronics workbench foreign [Music]

Share

다른 영상 요약