I am connecting to a Tektronix AWG5014C from my PC using the Ethernet port and Python. I am not able to load the waveform data, no matter what I try. I tried different encodings, different endiannes for the data, etc. Nothing works. My code is below. Any help is well appreciated.
import socket
from struct import pack
from time import sleep
def write(socket, cmd:str)->None:
socket.sendall(bytes(cmd + '\n', 'ASCII'))
sleep(.1)
def read(scoket)->str:
MESSAGE_ENDS_WITH = '\r\n'
received = ' '
while received[-len(MESSAGE_ENDS_WITH):] != MESSAGE_ENDS_WITH:
try:
received += socket.recv(1024).decode()
except TimeoutError:
received = ''
break
received = received[1:]
received = received.rstrip(MESSAGE_ENDS_WITH)
sleep(.1)
return received
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.connect(('192.168.0.69', 1111))
socket.settimeout(1)
write(socket, '*CLS') # Clear error buffer.
write(socket, '*IDN?')
print(read(socket)) # 'TEKTRONIX,AWG...'
samples = [1,2,3] # This is my waveform.
# Following line works fine, the new waveform shows up in the AWG with the right name and number of samples:
write(socket, f'WLISt:WAVeform:NEW "deleteme", {len(samples)}, INT')
write(socket,'SYST:ERR?')
print(read(socket)) # '0,"No error"'
send_this = bytes(f'WLISt:WAVeform:DATA "deleteme",', 'ASCII')
send_this += b''.join([pack('<h', sample) for sample in samples])
send_this += b'\n'
print(f'Will send: {send_this}') # Will send: b'WLISt:WAVeform:DATA "deleteme",\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\n'
socket.sendall(send_this)
sleep(.1)
write(socket,'SYST:ERR?')
print(read(socket)) # -109,"Missing parameter; Unexpected termination detected - WLISt:WAVeform:DATA ""deleteme"","
# The waveform data was not updated in the AWG, it has only [0,0,0]