4

I am trying to read waveform data from DSO_X 2024a via TCP/IP, and I need a specific number of points. How do I get float results from the scope?

Code

import visa
rm = visa.ResourceManager()
Scope=rm.get_instrument(addrSRC)
print(Scope.ask("*IDN?"))
print(Scope.write(":SYSTem:PRESet"))
print(Scope.write(':WAVeform:POINts 5000'))
print(Scope.write(':WAVeform:SOURce CHANnel3'))

print(Scope.write(':WAVeform:FORMat WORD'))
print(Scope.ask(':WAVeform:FORMat?'))
data_bytes = Scope.query_ascii_values(':WAVeform:DATA?')
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ilan
  • 123
  • 1
  • 7

1 Answers1

3

To check that it's working I find it's best to change the format of the waveform to ASCII and then use the normal ".ask()":

import visa

rm = visa.ResourceManager()
myScope = rm.get_instrument(instAddress)
# example instAddress ='GPIB0::12::INSTR'
# you can find out the address using <rm.list_resources()>

print(myScope.ask("*IDN?"))
myScope.write("WGEN:FREQ 50000") #connect the wavegen to channel 1
myScope.write("WGEN:FUNC SIN")
myScope.write("WGEN:OUTP ON")
myScope.write("WGEN:VOLT 2")

myScope.write(":TIMebase:SCALe 3.0E-5")
myScope.write(":WAVeform:SOURce CHANnel1")
myScope.write(":WAVeform:FORMat ASCII")
myScope.write(":WAVeform:POINts 1000")

data = myScope.ask("WAV:DATA?")

print(data)

The output is something like this:

"#800026879 1.75879e-001,-2.88945e-001,-7.66332e-001..."
Zircatron
  • 126
  • 7
  • `NameError: name 'instAddress' is not defined` – hola Apr 22 '18 at 11:09
  • I've edited the post to clear this up. instAddress need to be the instrument address name and this can be found by running – Zircatron Apr 23 '18 at 12:31
  • ask doesn't exist anymore so this doesn't work. – Landon Mar 02 '21 at 05:00
  • 1
    @Landon Please provide more useful comments. Example: FYI, ask() as been repllaced by query() https://pyvisa.readthedocs.io/en/1.8/migrating.html – Zircatron Mar 02 '21 at 12:20
  • @Zircatron Sorry but the reason I left that out is because I've tested this code after replacing ask with query and I don't get 1000 numbers. The length of data is only 116 and if you put the numbers in an array (ignoring the first 11 characters) you only get 9 elements: [0.005297277, 0.005297277, 0.005297277, 0.005297277, 0.005297277, 0.005297277, 0.005297277, 4.023314e-07, 5.0] – Landon Mar 02 '21 at 16:59
  • @Zircatron This behavior leads me to believe that query is not a direct supplicant for ask as it appears to be externally choking the data stream. To prove my point, if you set number of points to less than 9, e.g., 7, then the choking has no impact: [0.005297277, 0.005297277, 0.005297277, 0.005297277, 0.005297277, 0.005297277, 0.005297277] – Landon Mar 02 '21 at 17:03
  • @Landon This is a 3 year old question and it worked at the time and in the context of the question. I think my point still stands that only saying that something doesn't work isn't very helpful. I am happy to help but please make a new post. – Zircatron Mar 02 '21 at 22:40