Posted 3 months ago by Porta, Noteim
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.
  1. import socket
  2. from struct import pack
  3. from time import sleep
  4.  
  5. def write(socket, cmd:str)->None:
  6.     socket.sendall(bytes(cmd + '\n', 'ASCII'))
  7.     sleep(.1)
  8.  
  9. def read(scoket)->str:
  10.     MESSAGE_ENDS_WITH = '\r\n'
  11.     received = ' '
  12.     while received[-len(MESSAGE_ENDS_WITH):] != MESSAGE_ENDS_WITH:
  13.         try:
  14.             received += socket.recv(1024).decode()
  15.         except TimeoutError:
  16.             received = ''
  17.             break
  18.     received = received[1:]
  19.     received = received.rstrip(MESSAGE_ENDS_WITH)
  20.     sleep(.1)
  21.     return received
  22.  
  23. socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  24. socket.connect(('192.168.0.69', 1111))
  25. socket.settimeout(1)
  26.  
  27. write(socket, '*CLS') # Clear error buffer.
  28.  
  29. write(socket, '*IDN?')
  30. print(read(socket)) # 'TEKTRONIX,AWG...'
  31.  
  32. samples = [1,2,3] # This is my waveform.
  33.  
  34. # Following line works fine, the new waveform shows up in the AWG with the right name and number of samples:
  35. write(socket, f'WLISt:WAVeform:NEW "deleteme", {len(samples)}, INT')
  36. write(socket,'SYST:ERR?')
  37. print(read(socket)) # '0,"No error"'
  38.  
  39. send_this = bytes(f'WLISt:WAVeform:DATA "deleteme",', 'ASCII')
  40. send_this += b''.join([pack('<h', sample) for sample in samples])
  41. send_this += b'\n'
  42. 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'
  43. socket.sendall(send_this)
  44. sleep(.1)
  45.  
  46. write(socket,'SYST:ERR?')
  47. print(read(socket)) # -109,"Missing parameter; Unexpected termination detected - WLISt:WAVeform:DATA ""deleteme"","
  48.  
  49. # The waveform data was not updated in the AWG, it has only [0,0,0]
Posted 2 months ago by F., Massimiliano
Hi, can you provide the output in the Python console, after launching the script?
specially, what does "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'"
shows?

do you get errors from AWG5000 or from SYST:ERR, or from Python?

are you located in EMEA region?

You must be signed in to post in this forum.