as for scpi i did some tests to see what commands work, but as i wrote, we use python and lan connections
old code ive found
normally the scope ends up in the red run/ stop, now there an added stage this this code, and i want the scope to get out of it
before continuing
you have added lines like : press enter to continue, and the second part would be similar "in a sense" like posted with minor changes the way i see it, i think CHAT GPT was at some point behind it ??
yes my bad its an 1204x-e

here the code, it does read 2-3 externals csv files, for scope / gen configs (ip + port) ex : 192.168.0.101 - 5024
and a list of frequencies and parameters, amplitudes .... and scope params too
French words in messages ....
---------------------------------------------------------
import math
import pandas as pd
import socket
import sys
import time
class Generator:
def __init__(self):
conf = pd.read_csv("config_generator.csv")
self.ip_address = conf['IP_ADDRESS'].iloc[0]
self.port = conf['PORT'].iloc[0]
print(f"SDG 1062X\tIP: {self.ip_address}\tPORT: {self.port}")
self.socket = None
def socket_connect(self):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print('Failed to create socket.')
sys.exit()
try:
s.connect((self.ip_address, self.port))
except socket.error:
print('failed to connect to ip ' + self.ip_address)
self.socket = s
def socket_send(self, cmd, wait=1):
try:
self.socket.sendall(cmd)
self.socket.sendall(b'\n')
time.sleep(wait)
except socket.error:
print('Send failed')
sys.exit()
def socket_close(self):
self.socket.close()
time.sleep(1)
class Scope:
def __init__(self):
conf = pd.read_csv("config_oscilloscope.csv")
self.ip_address = conf['IP_ADDRESS'].iloc[0]
self.port = conf['PORT'].iloc[0]
print(f"SDS 1204X-E\tIP: {self.ip_address}\tPORT: {self.port}")
self.socket = None
def socket_connect(self):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print('Failed to create socket.')
sys.exit()
try:
s.connect((self.ip_address, self.port))
s.setblocking(0) # non-blocking mode, an exception occurs when no data is detected by the receiver
# s.settimeout(3)
except socket.error:
print('failed to connect to ip ' + self.ip_address)
self.socket = s
def socket_query(self, cmd, wait=1):
try:
self.socket.sendall(cmd)
self.socket.sendall(b'\n')
time.sleep(wait)
except socket.error:
print('Send failed')
sys.exit()
data_body = bytes()
while True:
try:
time.sleep(0.01)
server_replay = self.socket.recv(8000)
data_body += server_replay
except BlockingIOError:
time.sleep(wait)
break
return data_body
def socket_close(self):
self.socket.close()
time.sleep(5)
if __name__ == '__main__':
time_start = time.time()
timestamp = time.strftime('%Y%m%d%H%M%S', time.localtime())
print("Connexion avec le générateur et l'oscilloscope...")
with open(f"outputs\\OutputDataSYNC_{timestamp}.csv", 'w') as file:
file.write("Ch1,Ch2,dB,Absolute\n")
df = pd.read_csv("inputs\\FrequencySYNC.csv")
print("Configuration du générateur...")
gen = Generator()
print("Connexion au générateur...")
gen.socket_connect()
gen.socket_send(b'C1:OUTP ON')
print("Configuration de l'oscilloscope...")
scop = Scope()
print("Connexion à l'oscilloscope...")
scop.socket_connect()
gen.socket_send(b'C1:BSWV WVTP,SINE')
gen.socket_send(b'C1:BSWV AMP,10')
scop.socket_query(b'PACU RMS,C1')
scop.socket_query(b'PACU RMS,C2')
time.sleep(2)
print("Début du test...")
count = 1
for index, row in df.iterrows():
freq = f"C1:BSWV FRQ,{row.OUT}"
gen.socket_send(freq.encode(), row.WAIT)
vdiv1 = f"C1:VDIV {row.VDIV1}"
vdiv2 = f"C2:VDIV {row.VDIV2}"
tdiv = f"TDIV {row.TDIV}"
scop.socket_query(vdiv1.encode(), row.WAIT)
scop.socket_query(vdiv2.encode(), row.WAIT)
scop.socket_query(tdiv.encode(), row.WAIT)
out1 = scop.socket_query(b'C1:PAVA? RMS', row.WAIT)
out2 = scop.socket_query(b'C2:PAVA? RMS', row.WAIT)
decoded_out1 = out1.decode()
decoded_out2 = out2.decode()
numerical_part_out1 = decoded_out1.split(',')[1]
numerical_part_out2 = decoded_out2.split(',')[1]
value_out1 = float(numerical_part_out1.rstrip('V\n'))
value_out2 = float(numerical_part_out2.rstrip('V\n'))
value_dB = 20.0 * math.log10(value_out2 / value_out1)
absolute = math.fabs(value_dB)
print(f"{count}\tCh1: {value_out1:.3f}V\tCh2: {value_out2:.3f}V\tAbsolute: {absolute:.3f}dB")
with open(f"outputs\\OutputDataSYNC_{timestamp}.csv", 'a') as file:
file.write(f"{value_out1},{value_out2},{value_dB},{absolute}\n")
count += 1
gen.socket_send(b'C1:OUTP OFF')
scop.socket_query(b'STOP')
gen.socket_close()
df = pd.read_csv(f"outputs\\OutputDataSYNC_{timestamp}.csv")
max_value = df['Absolute'].max()
average = 100 if max_value > 3 else df['Absolute'].mean()
result = "PASSED" if average < 1 else "FAILED"
print(f"\nMoyenne: {average}")
print(f"\nRésultat: {result}")
with open(f"outputs\\OutputResultSYNC_{timestamp}.csv", 'w') as file:
file.write(f"AVERAGE,{average},RESULT,{result}")
time_stop = time.time()
duration = time_stop - time_start
print(f"Temps d'exécution: {duration:.3f} secondes")
while True:
time.sleep(1)
added code after this .... press enter to continue etc .... this is where i would like to re-start the scope / acquisition ... i have to do it manually before the ENTER key press