I have a small question. I have to pass an argument to my measurement device to set a voltage value. My code to do this is as follow
from visa import *
import sys
inst = instrument("USB0::0x164E::0x0DAD::TW00004282")
inst.write("*rst; status:preset; *cls")
inst.write("CONF:VOLT:AC 1")
The above code configures the voltmeter to AC value 1 without any hassle. But it can only set the value 1. I tried making it more generic using the following code.
from visa import *
import sys
inst = instrument("USB0::0x164E::0x0DAD::TW00004282")
inst.write("*rst; status:preset; *cls")
a = 1
inst.write("CONF:VOLT:AC a")
But this piece of code returned an error.
My original code would look something like
from visa import *
import sys
inst = instrument(sys.argv[1]) #Passing USB address from client side
inst.write("*rst; status:preset; *cls")
a = sys.argv[2] #Passing value of 'a' from the client side
inst.write("CONF:VOLT:AC a")
I would pass the argument value in the end from my client side, which is out of the context of this question.
Now is there another generic way to assign the value of a
and then to pass it write function?
The "a"
within your string is interpreted as a literal a
. You should use:
inst.write("CONF:VOLT:AC %s" % sys.argv[2])
Or better convert it to an int
and check it first:
volt = int(sys.argv[2])
# Check if volt is in a suitable range...
inst.write("CONF:VOLT:AC %d" % volt)