Commit b8d45d0e authored by LorenzoMonti's avatar LorenzoMonti
Browse files

add features in connect tab

parent e7f734bf
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
{
    "gpib": "GPIB::18::INSTR",
    "remote_eth": "TCPIP0::localhost::49153::SOCKET",
    "local_eth": ""
    "local_eth": "TCPIP0::<ip>::INSTR"
}
 No newline at end of file
+28 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ import numpy as np
import pandas as pd
import datetime
import json
from math import log10

  
def set_SPA_for_measure(ms2830a, config_file, manual_command):
        """
@@ -72,6 +74,32 @@ def write_config_file(filename, confDict):
        with open(filename, 'w') as file:
                file.write(json_obj)

#########################
#       FORMULAS        #
#########################

def W2dBm(W):
    """
    Function to convert from W to dBm
    """
    return 10. * log10(W) + 30

def dBm2W(dBm):
    """
    Function to convert from dBm to W
    """
    return 10**((dBm)/10.) / 1000

def getWatts(dBm):
    """
    Function to return a list of watts values
    """
    return map(dBm2W, dBm)

############################
#           UI             #
############################

def clear_message(self, trace_number):
        if(trace_number == 0):
                self.Message1.configure(background="green", font=("Helvetica",24))
+9 −7
Original line number Diff line number Diff line
import Anritsu_MS2830A as SPA
import Utils

import numpy as np
import datetime
if __name__ == '__main__':
    
    config_interface = Utils.read_config_file("../config/config_interface.json")
    config_file = Utils.read_config_file("../config/config_MS2830A.json")
    
    instr = SPA.Anritsu_MS2830A("Anritsu_MS2830A", config_interface["remote_eth"])
    Utils.set_SPA_for_measure(instr, config_file)
    #instr = SPA.Anritsu_MS2830A("Anritsu_MS2830A", config_interface["remote_eth"])
    #Utils.set_SPA_for_measure(instr, config_file)

    trace = instr.get_trace(1) # Get trace
    #trace = instr.get_trace(1) # Get trace
    
    Utils.plot_lineplot(trace)
    Utils.save_data_as_csv(trace)
    #Utils.plot_lineplot(trace)
    #Utils.save_data_as_csv(trace)
    print(list(Utils.getWatts(np.array([64.3, 62.3, 11.78, 44.,0.55]))))
+68 −5
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ except ImportError:
    import tkinter.ttk as ttk
    py3 = True

import Utils
import logging

def connect(self, TNotebook1, config_interface, config_file):

@@ -22,7 +24,7 @@ def connect(self, TNotebook1, config_interface, config_file):
    h_text = 0.029
    w_text = 0.291

    y_button = 0.739
    y_button = 0.699
    h_button = 40
    w_button = 150
    
@@ -34,9 +36,13 @@ def connect(self, TNotebook1, config_interface, config_file):
    self.TNotebook1.tab(0, text="Connection",compound="left",underline="-1",)

    # label
    self.Label0 = tk.Label(self.TNotebook1_t1)
    self.Label0.place(relx=x_label, rely=0.042, height=h_label, width=w_label)
    self.Label0.configure(text='''Interface''')
    self.LabelConnect = tk.Label(self.TNotebook1_t1)
    self.LabelConnect.place(relx=x_label, rely=0.042, height=h_label, width=w_label)
    self.LabelConnect.configure(text='''Interface''')

    self.LabelEntryMenu =  tk.Label(self.TNotebook1_t1)
    self.LabelEntryMenu.place(relx=0.008, rely=0.795, height=h_label, width=w_label)
    self.LabelEntryMenu.configure(text='''Interface selected''')

    options = [interface_key for interface_key, interface_value in config_interface.items()]
    self.selected_interface = tk.StringVar() # Dropmenu variable (store option choice)
@@ -50,3 +56,60 @@ def connect(self, TNotebook1, config_interface, config_file):

    self.drop = tk.OptionMenu( self.TNotebook1_t1 , self.selected_interface, *options)
    self.drop.place(relx=x_text, rely=0.042, relheight=h_text, relwidth=w_text)

    self.Label1Connect = tk.Label(self.TNotebook1_t1)
    self.Label1Connect.place(relx=x_label, rely=0.255, height=h_label, width=w_label)
    self.Label1Connect.configure(text='''GPIB''')

    self.Label2Connect = tk.Label(self.TNotebook1_t1)
    self.Label2Connect.place(relx=x_label, rely=0.326, height=h_label, width=w_label)
    self.Label2Connect.configure(text='''Remote ETH connection''')

    self.Label3Connect = tk.Label(self.TNotebook1_t1)
    self.Label3Connect.place(relx=x_label, rely=0.397, height=h_label, width=w_label)
    self.Label3Connect.configure(text='''Local ETH connection''')

    self.Entry1Connect = tk.Entry(self.TNotebook1_t1)
    self.Entry1Connect.place(relx=x_text, rely=0.255, relheight=h_text, relwidth=w_text)
    self.Entry1Connect.configure(background="white")
    self.Entry1Connect.configure(font="TkTextFont")
    self.Entry1Connect.configure(selectbackground="blue")
    self.Entry1Connect.configure(selectforeground="white")
    self.Entry1Connect.insert(0, config_interface["gpib"])

    self.Entry2Connect = tk.Entry(self.TNotebook1_t1)
    self.Entry2Connect.place(relx=x_text, rely=0.326, relheight=h_text, relwidth=w_text)
    self.Entry2Connect.configure(background="white")
    self.Entry2Connect.configure(font="TkTextFont")
    self.Entry2Connect.configure(selectbackground="blue")
    self.Entry2Connect.configure(selectforeground="white")
    self.Entry2Connect.insert(0, config_interface["remote_eth"])

    self.Entry3Connect = tk.Entry(self.TNotebook1_t1)
    self.Entry3Connect.place(relx=x_text, rely=0.397, relheight=h_text, relwidth=w_text)
    self.Entry3Connect.configure(background="white")
    self.Entry3Connect.configure(font="TkTextFont")
    self.Entry3Connect.configure(selectbackground="blue")
    self.Entry3Connect.configure(selectforeground="white")
    self.Entry3Connect.insert(0, config_interface["local_eth"])

    def write_config():
        config_interface = {
            "gpib": str(self.Entry1Connect.get()),
            "remote_eth": str(self.Entry2Connect.get()),
            "local_eth": str(self.Entry3Connect.get())
        }
        try:
            Utils.write_config_file("../config/config_interface.json", config_interface)
            #self.Text1.insert(tk.END, "Configuration file written successfully \n")
            logging.info(__name__ + ' : Configuration file written successfully')

        except:
            #self.Text1.insert(tk.END, "Error writing configuration file \n")
            logging.error(__name__ + ' : Error writing configuration file')

    self.ButtonConnect = tk.Button(self.TNotebook1_t1)
    self.ButtonConnect.place(relx=0.035, rely=y_button, height=h_button, width=w_button)
    self.ButtonConnect.configure(borderwidth="2")
    self.ButtonConnect.configure(command=write_config)
    self.ButtonConnect.configure(text='''Write configuration''')
 No newline at end of file