开发者

Python, sending command to GPIB instrument

开发者 https://www.devze.com 2022-12-10 13:19 出处:网络
开发者_如何学PythonI need to send a command to a GPIB instrument and I can do it like this: power.write(\"volt 0.01\").

开发者_如何学PythonI need to send a command to a GPIB instrument and I can do it like this: power.write("volt 0.01").

This command sets the output of my power source to 0.01V, however, I'm trying to take an I-V curve and want to set the source to different values and take a measurement at each value. I basically need some sort of loop to do this for me. I tried the following:

k=0
while k<= 1:
    power.write("volt k")
    k=k+0.01

This doesn't work because k gets send as 'k', not as a number. How do I fix this?


Instead of power.write("volt k"), use:

power.write("volt " + str(k))
                 ^
          observe space here!

If you want to control the output precision, you can use the following:

power.write("volt %0.2f" % k)

That is, if k is 4.85866 then using %0.2f means volt 4.86 is sent to the device. If using %0.4f then volt 4.8587 is sent to the device. Note the rounding!


Instead of power.write("volt k"), use:

power.write("volt %0.2f" % k)
0

精彩评论

暂无评论...
验证码 换一张
取 消