“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]