Tektronix Technical Forums are maintained by community involvement. Feel free to post questions or respond to questions by other members. Should you require a time-sensitive answer, please contact your local Tektronix support center here.

pyVisa too slow with RS232 TDK3034

Post Reply
Posts: 1
Joined: January 28th, 2017, 9:14 am
Country: Poland

pyVisa too slow with RS232 TDK3034

Post by Duzy_Piotr » January 28th, 2017, 9:21 am

Code: Select all

import visa
rm = visa.ResourceManager()
print(list) # list[0] is RS-232 reference
my_instrument = rm.open_resource(list[0])
#it works fine until this point, asking for one line of text only.
#After this oscilloscope is sending lots of data (1000 digits formatted as strings). 
I get:

In python 3.4
"VI_ERROR_TMO (-1073807339): Timeout expired before operation completed."
In python 3.6
VI_ERROR_ASRL_OVERRUN "An overrun error occurred during transfer. A character was not read from the hardware before the next character arrived.
As far as I know, pyVisa is reading too slow when compare to speed of data sending. Same procedure is working when I am using pyVisa/GPIB, or pySerial/COM.

How can I make it faster, or what can I do to get that data by pyVisa/COM?
TDK 3034 Oscilloscope is using RTS/CTS synchronization method. How to set it on Visa? Would that help in this case?


Dave W
Tektronix Applications
Tektronix Applications
Posts: 294
Joined: April 26th, 2010, 12:01 pm
Country: United States

Re: pyVisa too slow with RS232 TDK3034

Post by Dave W » February 1st, 2017, 3:57 pm

Hi Duzy_Piotr,

Using pyVisa with Serial COM requires a little bit of extra configuration code to make work properly. If you want to use flow control you will need to configure pyVisa in your code to use it. This can be done with the following code.

Code: Select all

# Serial Port Settings
baudRate = 9600
flowCtrl = vc.VI_ASRL_FLOW_RTS_CTS
#flowCtrl = vc.VI_ASRL_FLOW_NONE

# Open session to instrument
rm = visa.ResourceManager()
lib = rm.visalib
scope = rm.open_resource(visaResourceAddr)
scope.timeout = 5000

# Some settings depend on which interface is being used
interface = lib.get_attribute(scope.session, vc.VI_ATTR_INTF_TYPE)[0]

if interface == vc.VI_INTF_ASRL:
    lib.set_attribute(scope.session, vc.VI_ATTR_ASRL_FLOW_CNTRL, flowCtrl)
    lib.set_attribute(scope.session, vc.VI_ATTR_ASRL_BAUD, baudRate)
Another issue you will run into is with the CURVE? query. PyVISA over COM relies on termination characters (i.e. '\r' or '\n') to detect the end of a message and terminate a read. If your waveform data contains the ASCII value for these termination characters (which is very likely) your read will terminate prematurely. You will need to disable termination characters during the read to get all the data back. You can do this with the following code.

Code: Select all

# If using RS-232 then need to disable end on termination character while reading the image data
if lib.get_attribute(scope.session, vc.VI_ATTR_INTF_TYPE)[0] == vc.VI_INTF_ASRL:
    lib.set_attribute(scope.session, vc.VI_ATTR_ASRL_END_IN, 0)

# Readback the data
#< CURVE? Query code here>

# Re-enable end on termination character for RS-232
if lib.get_attribute(scope.session, vc.VI_ATTR_INTF_TYPE)[0] == vc.VI_INTF_ASRL:
    lib.set_attribute(scope.session, vc.VI_ATTR_ASRL_END_IN, 1)
There is a PyVISA example on the forums that shows how to fetch screenshot data from the scope using a COM port. The same principles used in this example can be used for fetching waveform data.

Save Hardcopy to PC, PyVisa, TDS, TPS, TBS 1K-2K Series

Hope this helps!

Post Reply

Return to “Programming Support”

Who is online

Users browsing this forum: No registered users and 2 guests