Skip to content

Commit

Permalink
added sweep
Browse files Browse the repository at this point in the history
  • Loading branch information
dpeana committed Nov 15, 2022
1 parent 7df8a5c commit d2bd9a2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 17 deletions.
46 changes: 29 additions & 17 deletions AWGCommandScripts/WindowsScripts/AWGCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,58 @@

# Example command: python AWGCommand.py start 140

server_ip = "192.168.1.179"
server_port = 5080

arg_message = sys.argv[1]

if len(sys.argv)>2:
freq = sys.argv[2]
data = sys.argv[2]
else:
freq = '140'
data = '140'

freq_add = '2;'+freq
freq_drop = '14;'+freq
freq_add = '2;'+data
freq_drop = '14;'+data
channel0 = '12;0'
channel1 = '12;1'

if arg_message == '1chan_start': # Set channel0 to freq MHz, channel1 is off (only works if AWG.ini is configured T,F,F,F)
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(channel0, "utf-8"), ("192.168.1.179", 5080))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(freq_add, "utf-8"), ("192.168.1.179", 5080))
if arg_message == '1chan_freq': # Set channel0 to freq MHz, channel1 is off (only works if AWG.ini is configured T,F,F,F)
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(channel0, "utf-8"), (server_ip, server_port))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(freq_add, "utf-8"), (server_ip, server_port))

elif arg_message == '2chan_start': # Set channel0 to freq MHz, channel1 is freq MHz
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(channel0, "utf-8"), ("192.168.1.179", 5080))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(freq_add, "utf-8"), ("192.168.1.179", 5080))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(channel1, "utf-8"), ("192.168.1.179", 5080))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(freq_add, "utf-8"), ("192.168.1.179", 5080))
elif arg_message == '2chan_freq': # Set channel1 to freq MHz, channel1 is freq MHz (only works if AWG.ini is configured T,T,F,F)
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(channel0, "utf-8"), (server_ip, server_port))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(freq_add, "utf-8"), (server_ip, server_port))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(channel1, "utf-8"), (server_ip, server_port))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(freq_add, "utf-8"), (server_ip, server_port))

elif arg_message == 'start': # Start server
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('6', "utf-8"), ("192.168.1.179", 5080))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('6', "utf-8"), (server_ip, server_port))

elif arg_message == 'stop': # Stop server
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('7', "utf-8"), ("192.168.1.179", 5080))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('7', "utf-8"), (server_ip, server_port))

elif arg_message == 'bootup': # Kill server
try:
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('1', "utf-8"), ("192.168.1.179", 5080)) # Kills any running instance of server
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('1', "utf-8"), (server_ip, server_port)) # Kills any running instance of server
subprocess.check_output('ssh awglics@192.168.1.179 ". run_server.sh"') # Starts new server
except:
subprocess.check_output('ssh awglics@192.168.1.179 ". run_server.sh"') # Starts new server

elif arg_message == 'kill': # Kill server
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('1', "utf-8"), ("192.168.1.179", 5080))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('1', "utf-8"), (server_ip, server_port))

elif arg_message == 'sweep': # Give it array of good values AND total number of roi's. e.g. if out of 6 atoms, [0,1,4] are bad, give it the command 'python AWGCommand.py sweep 6;2;3;5'
data_arr = data.split(';')
message = '13'
roi_correction = 0
for i in range(1,len(data_arr)):
message += ';'+str(int(data_arr[i]) - roi_correction)+';'+str(i-1)
roi_correction += 1
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(message, "utf-8"), (server_ip, server_port))

else:
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(arg_message, "utf-8"), ("192.168.1.179", 5080))
socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes(arg_message, "utf-8"), (server_ip, server_port))

############ For reference: ############

Expand Down
28 changes: 28 additions & 0 deletions AWGCommandScripts/WindowsScripts/sample_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import socket
import sys
import subprocess
import time

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.sendto(bytes('12;0', "utf-8"), ("192.168.1.179", 5080))
sock.sendto(bytes('2;120', "utf-8"), ("192.168.1.179", 5080))
sock.sendto(bytes('6', "utf-8"), ("192.168.1.179", 5080))

# socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('12;0', "utf-8"), ("192.168.1.179", 5080))
# time.sleep(1)
# socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('2;120', "utf-8"), ("192.168.1.179", 5080))
# time.sleep(1)
# socket.socket(socket.AF_INET, socket.SOCK_DGRAM).sendto(bytes('6', "utf-8"), ("192.168.1.179", 5080))
# time.sleep(1)
############ For reference: ############

# EXIT: 1
# FREQ: 2
# ADD: 3
# MODIFY: 4
# START: 6
# STOP: 7
# CHAN: 12
# SWEEP: 13
# DUMP: 14
# RESTORE 15

0 comments on commit d2bd9a2

Please sign in to comment.