Siglent SDG1032X bug in user-defined waveforms - Page 1
Forum section: electronics / testgear

author: kvd
author_rank: Contributor
timestamp: February 02, 2023, 08:09:17 pm
content: I think I discovered a bug in the SDG1032X firmware (version 1.01.01.33R3) in the receiving of user-defined waveforms from a computer by SCPI over sockets. In short, any \x0a byte in the waveform data which is sent to the device is regarded as a termination character. It does not matter if this \x0a byte is the high or low byte. Importing a waveform with a \x0a byte in it will mark the end of the waveform and cause corrupt waveforms in the SDG.The attached Python script shows the issue. It generates square waveforms 100 points long for high value of 2559/32767 and 2560/32767. The value 2560/32767 does have a \x0a high byte and shows the issue. For the 2559/32767 value it does not need correction. For the 2560/32767 value an uncorrected and a corrected waveform is generated. (Note that sometimes after uploading an incomplete waveform, the SDG hangs and needs to be restarted).In the screenshots it can be seen that the 2560_uncorrected waveform is read incompletely. It only has 51 datapoints instead of 100.The issue can be 'solved' by before sending the bytes to the SDG, scanning the bytes and replacing any \x0a with \x0b. This results in an error of 100*1/32767=0.3% if the \x0a is low byte, 100*256/32767=0.8% if \x0a is in the high byte.This issue not only occurs with SCPI over sockets, but also using PyVISA. PyVISA seems to be aware of this issue and solves it in a different way, although with larger error.I think the issue could have been solved if the LENGTH parameter in the WVDT command was supported for the SDG1032X. Then the SDG could read until the given number of bytes have been received, not until it encounters a termination character (which may be part of the waveform).Anyone has also noticed the issue and maybe solved it in another/better way?Koenimport socketimport timeimport sysimport binasciiimport matplotlib.pyplot as pltdef open_socket():try:s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.connect(('169.254.1.177', 5025))s.settimeout(0.5)except socket.error:print('Failed to connect')sys.exit()return sdef close_socket(s):s.close()time.sleep(.300)def send_command(s, cmd):try:s.sendall(cmd)time.sleep(1)except socket.error:print('Command failed')sys.exit()try:response = s.recv(4096)except socket.timeout:response = b''return responsedef corrected(signal):d = (signal*32767).astype(np.int16)return d.tobytes().replace(b'\n',b'\x0b')def uncorrected(signal):d = (signal*32767).astype(np.int16)return d.tobytes()s = open_socket()qstr = send_command(s, b'*IDN?\n')print(qstr.decode('utf-8'))# create a signal of 100 times a value without problemsvalue_ok = 2559/32767signal_ok = np.array(*100)data_ok_uncorrected = uncorrected(signal_ok)qstr = send_command(s, b"C1:WVDT WVNM,2559_UNCORR,FREQ,1000.0,AMPL,1.0,OFST,0.0, PHASE,0.0,WAVEDATA," + data_ok_uncorrected + b'\n')# create a signal of 100 times a value with the problemvalue_not_ok = 2560/32767signal_not_ok = np.array(*100)data_not_ok_corrected = corrected(signal_not_ok)qstr = send_command(s, b"C1:WVDT WVNM,2560_CORR,FREQ,1000.0,AMPL,1.0,OFST,0.0, PHASE,0.0,WAVEDATA," + data_not_ok_corrected + b'\n')data_not_ok_uncorrected = uncorrected(signal_not_ok)qstr = send_command(s, b"C1:WVDT WVNM,2560_UNCORR,FREQ,1000.0,AMPL,1.0,OFST,0.0, PHASE,0.0,WAVEDATA," + data_not_ok_uncorrected + b'\n')close_socket(s)plt.plot(signal_ok)plt.plot(signal_not_ok)

author: kvd
author_rank: Contributor
timestamp: February 05, 2023, 07:13:44 pm
content: Another way to get a user-defined waveform from the computer into the SDG is by writing it into a .csv file, putting it on a usb-stick and recalling it on the SDG.This works, no errors there, only needs some usb-stick swapping.

author: kvd
author_rank: Contributor
timestamp: February 05, 2023, 07:24:38 pm
content: This code generates an FM stereo multiplexed signal, left 1kHz and right 2kHz with the 19kHz pilot tone, and writes it into a csv file which can be read by the SDG. This same signal could not be read by the SDG over SCPI and sockets because of the \x0a character in the waveform data.==============# Using HavesineExampleFile.csv fromhttps://siglentna.com/wp-content/uploads/2017/12/EasyWaveCSV.zipas an example.import matplotlib.pyplot as pltimport numpy as npimport csvSAMPLES = 16384# time axist = np.linspace(0,1,SAMPLES,endpoint=False)f1 = 1f2 = 2f19 = 19f38 = 38s1 = np.sin(f1*2*np.pi*t)s2 = np.sin(f2*2*np.pi*t)s19 = np.sin(f19*2*np.pi*t)s38 = np.sin(f38*2*np.pi*t)# FM signalratio = .9left = s1right = s2tone = s19mono = (left + right) / 2stereo = s38 * (left - right) / 2signal = ratio * (mono + stereo) + (1 - ratio) * tonewith open('L1_R2.csv','w') as f:writer = csv.writer(f)writer.writerow(['data length', f'{SAMPLES}'])writer.writerow(['frequency','1000'])writer.writerow(['amp','2.5'])writer.writerow(['offset','0'])writer.writerow(['phase','0'])writer.writerow(['',''])writer.writerow(['',''])writer.writerow(['',''])writer.writerow(['',''])writer.writerow(['',''])writer.writerow(['',''])writer.writerow(['',''])writer.writerow(['xpos','value'])for i in range(SAMPLES):writer.writerow([t,signal])plt.plot(signal)