Siglent SDS800X HD - Using SCPI with python via telnet to measure with 2 gates - Page 1
Forum section: electronics / testgear

author: eTobey
author_rank: Super Contributor
timestamp: April 25, 2024, 07:18:58 pm
content: Hi,i have made a little script to connect to the scope, and read data via SCPI. I have looked at the traffic, and i see, that there is data coming in from the SCPI command (see picture). But it is not printed. But interestingly, the welcome message got printed.Anyone has an idea?Code:import telnetlibclass POP3Telnet:def __init__(self, host, port):self.tel = telnetlib.Telnet(host, port)#self.lese_daten()def close(self):self.tel.close()def lese_daten(self):return self.tel.read_until(b"\n", 1.0)def kommando(self, kom):self.tel.write(("{}\r\n".format(kom)).encode())return self.lese_daten()host = "169.254.143.210"port = 5024user = ""passwd = ""pop = POP3Telnet(host, port)#pop.kommando("USER {}".format(user))#pop.kommando("PASS {}".format(passwd))#print("Lese Daten...")print(pop.lese_daten().decode())print(pop.lese_daten().decode())pop.kommando(":MEAS:ADV:P2:STAT? ALL;")print(pop.lese_daten().decode())pop.kommando("QUIT")print(pop.lese_daten().decode())pop.close()Output:Code:Lese Daten...Welcome to the SCPI instrument 'Siglent SDS824X HD'>>

author: dobsonr741
author_rank: Frequent Contributor
timestamp: April 25, 2024, 08:03:21 pm
content: The output does not match your code.

author: XiMMiX
author_rank: Newbie
timestamp: April 25, 2024, 08:54:54 pm
content: your kommando function doesn't just send the command to the scope, it also returns the first reply by running self.lese_daten().You're not doing anything with the data the kommando function returns.

author: eTobey
author_rank: Super Contributor
timestamp: April 25, 2024, 09:07:58 pm
content: Quote from: XiMMiX on April 25, 2024, 08:54:54 pmThis is actually not my kommando ;-). Just got that from the internet, and did not notice this. Should have actually looked more closer there.Thank you

author: eTobey
author_rank: Super Contributor
timestamp: April 26, 2024, 06:33:59 am
content: I have now finished my script an have changee the title of this topic accordingly:This is a script to measure certain values with 2 gates (Updates might follow):Code:import telnetlibimport timeclass POP3Telnet:def __init__(self, host, port):self.tel = telnetlib.Telnet(host, port)#self.lese_daten()def close(self):self.tel.close()def lese_daten(self):return self.tel.read_until(b"\n", 2)def kommando(self, kom):self.tel.write(("{}\r\n".format(kom)).encode())time.sleep(0.02) # May need adjustingreturnhost = "169.254.143.210"port = 5024user = ""passwd = ""gate_1A = -35gate_1B = 35gate_2A = 400gate_2B = 8000pop = POP3Telnet(host, port)# Read and discard useless Messagespop.lese_daten().decode()pop.lese_daten().decode()pop.kommando(":HISTOR:FRAM 1")for x in range(0,80000):x = x + 1 # starts from 0# print timepop.kommando(":HISTOR:TIME?")print("{} {} ".format(x, pop.lese_daten().decode().strip('\n').replace(' ','')), end="")# Measure first gate measure no. 2pop.kommando(":MEAS:GATE:GA {}E-9".format(gate_1A))pop.kommando(":MEAS:GATE:GB {}E-9".format(gate_1B))pop.kommando(":MEAS:ADV:P2:VAL?")data = pop.lese_daten().decode().strip('\n')if data.find('*') >= 0:print("-", end="")else:print(float(data), end="")print(" ", end="")# Measure second gate measure no. 1pop.kommando(":MEAS:GATE:GB {}E-9".format(gate_2B)) # MOVE FURTHEST GATE FIRST! A cant overtake B !pop.kommando(":MEAS:GATE:GA {}E-9".format(gate_2A))pop.kommando(":MEAS:ADV:P1:VAL?")data = pop.lese_daten().decode().strip('\n')if data.find('*') >= 0:print("-", end="")else:print(float(data), end="")print("")# Move on in framespop.kommando(":HISTOR:FRAM {}".format(x+1)) # set next framepop.kommando(":HISTOR:FRAM?")if float(pop.lese_daten().decode()) == x: # no more frames!breakpop.kommando("QUIT")pop.close()

author: electronics hobbyist
author_rank: Regular Contributor
timestamp: April 26, 2024, 07:03:30 am
content: This is a good way to achieve some functions that cannot be done by oscilloscope through python.It takes a long time for oscilloscope to add functions, while scripting code takes a short time and is very flexible.Others can also add their own needs and scripts.

author: eTobey
author_rank: Super Contributor
timestamp: April 26, 2024, 09:08:57 am
content: Quote from: electronics hobbyist on April 26, 2024, 07:03:30 amWhile not familiar with python, SCPI and the scope, it took me like 4 hours. It might be flexible, but it is very sloooow. About 2 measurments per second.Maybe SCPI speed can be improved?

author: electronics hobbyist
author_rank: Regular Contributor
timestamp: April 26, 2024, 09:30:41 am
content: Quote from: eTobey on April 26, 2024, 09:08:57 amThe first time is 4 hours, when you are familiar with python, you may only need half an hour. I think the main time consumption is the processing time of the oscilloscope after sending multiple commands, so the speed of 2 times per second is okay, you can executing the script When sleep.

author: eTobey
author_rank: Super Contributor
timestamp: April 26, 2024, 11:52:41 am
content: Quote from: electronics hobbyist on April 26, 2024, 09:30:41 amI could not... As it is only 2 meters away from my bed, it its pretty loud and uses a lot of power. It should be able to do more than 2 times per second for this powerconsumption.