Author Topic: Siglent SDS800X HD - Using SCPI with python via telnet to measure with 2 gates  (Read 510 times)

0 Members and 1 Guest are viewing this topic.

Offline eTobeyTopic starter

  • Frequent Contributor
  • **
  • Posts: 594
  • Country: de
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: [Select]
import telnetlib
class 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 = 5024
user = ""
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: [Select]
Lese Daten...
Welcome to the SCPI instrument 'Siglent SDS824X HD'

>>


« Last Edit: April 26, 2024, 06:35:00 am by eTobey »
"Sometimes, after talking with a person, you want to pet a dog, wave at a monkey, and take off your hat to an elephant." (Maxim Gorki)
 
The following users thanked this post: egonotto

Offline dobsonr741

  • Frequent Contributor
  • **
  • Posts: 674
  • Country: us
Re: Using SCPI with python via telnet to connect with a siglent scope
« Reply #1 on: April 25, 2024, 08:03:21 pm »
The output does not match your code.
 
The following users thanked this post: egonotto

Online XiMMiX

  • Newbie
  • Posts: 3
  • Country: nl
Re: Using SCPI with python via telnet to connect with a siglent scope
« Reply #2 on: April 25, 2024, 08:54:54 pm »
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.
 
The following users thanked this post: egonotto, eTobey

Offline eTobeyTopic starter

  • Frequent Contributor
  • **
  • Posts: 594
  • Country: de
Re: Using SCPI with python via telnet to connect with a siglent scope
« Reply #3 on: April 25, 2024, 09:07:58 pm »
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.

This is actually not my kommando ;-). Just got that from the internet, and did not notice this. Should have actually looked more closer there.  ;D

Thank you  :-+
"Sometimes, after talking with a person, you want to pet a dog, wave at a monkey, and take off your hat to an elephant." (Maxim Gorki)
 
The following users thanked this post: egonotto

Offline eTobeyTopic starter

  • Frequent Contributor
  • **
  • Posts: 594
  • Country: de
Re: Using SCPI with python via telnet to connect with a siglent scope
« Reply #4 on: April 26, 2024, 06:33:59 am »
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: [Select]
import telnetlib
import time

class 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 adjusting
        return
       
host = "169.254.143.210"
port = 5024
user = ""
passwd = ""

gate_1A = -35
gate_1B = 35

gate_2A = 400
gate_2B = 8000

pop = POP3Telnet(host, port)

# Read and discard useless Messages
pop.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 time
    pop.kommando(":HISTOR:TIME?")
    print("{} {} ".format(x, pop.lese_daten().decode().strip('\n').replace(' ','')), end="")
   
    # Measure first gate measure no. 2
    pop.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. 1
    pop.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 frames
    pop.kommando(":HISTOR:FRAM {}".format(x+1))   # set next frame
    pop.kommando(":HISTOR:FRAM?")
    if float(pop.lese_daten().decode()) == x: # no more frames!
        break


pop.kommando("QUIT")
pop.close()
« Last Edit: April 26, 2024, 06:59:36 am by eTobey »
"Sometimes, after talking with a person, you want to pet a dog, wave at a monkey, and take off your hat to an elephant." (Maxim Gorki)
 
The following users thanked this post: egonotto

Offline electronics hobbyist

  • Regular Contributor
  • *
  • Posts: 148
  • Country: cn
    • sds800x-hd-review-demonstration-thread
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.   :-+

Offline eTobeyTopic starter

  • Frequent Contributor
  • **
  • Posts: 594
  • Country: de
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.   :-+

While 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?
"Sometimes, after talking with a person, you want to pet a dog, wave at a monkey, and take off your hat to an elephant." (Maxim Gorki)
 
The following users thanked this post: egonotto

Offline electronics hobbyist

  • Regular Contributor
  • *
  • Posts: 148
  • Country: cn
    • sds800x-hd-review-demonstration-thread

While 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?

The 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.   ;D

Offline eTobeyTopic starter

  • Frequent Contributor
  • **
  • Posts: 594
  • Country: de
sending multiple commands, so the speed of 2 times per second is okay, you can executing the script When sleep.   ;D
I 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.
"Sometimes, after talking with a person, you want to pet a dog, wave at a monkey, and take off your hat to an elephant." (Maxim Gorki)
 
The following users thanked this post: egonotto


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf