import System import clr import time import datetime from System import Array from System.Diagnostics import Stopwatch from System.Collections.Generic import List clr.AddReferenceToFileAndPath("C:\\Program Files\\Analog Devices\\ADRV9025 Transceiver Evaluation Software_x64_FULL\\adrvtrx_dll.dll") from adrv9010_dll import AdiEvaluationSystem from adrv9010_dll import Types from adrv9010_dll import FpgaTypes link = AdiEvaluationSystem.Instance connect = False if (not link.IsConnected()): connect = True link.platform.board.Client.Connect("192.168.1.10", 55556) print "Connexion..." if (not link.IsConnected()): raise Exception("ERREUR: Pas connecte au TES.") print "Connecte." RadioCtrl = link.platform.board.Adrv9010Device.RadioCtrl CAPTURE_TIME_MS = 2 RX_CHANNEL_MASK = 4 start_freq = 3000000000 step_freq = 50000000 nb_points = 10 freq_list = [start_freq + (i * step_freq) for i in range(nb_points)] PLL_LO1 = Types.adi_adrv9010_PllName_e.ADI_ADRV9010_LO1_PLL PLL_LO2 = Types.adi_adrv9010_PllName_e.ADI_ADRV9010_LO2_PLL VAL_RX3_ON_LO1 = 0 VAL_RX3_ON_LO2 = 2 results_buffer = [] sw = Stopwatch() def FastRxCapture(mask, time_ms): Rx_data_list = link.platform.board.PerformRx( FpgaTypes.adi_fpga9010_RxTollgateTrigSources_e.ADI_FPGA9010_IMM_TRIG, mask, time_ms, time_ms * 2 + 100 ) return (Rx_data_list[4], Rx_data_list[5]) print "\n=== 1. Initialisation ===" RadioCtrl.RxTxEnableSet(RX_CHANNEL_MASK, 0x01) if len(freq_list) > 0: RadioCtrl.PllFrequencySet(PLL_LO1, freq_list[0]) if len(freq_list) > 1: RadioCtrl.PllFrequencySet(PLL_LO2, freq_list[1]) time.sleep(0.5) print "\n=== 2 ===" RadioCtrl.LoSourceMappingSet(VAL_RX3_ON_LO1) for i in range(len(freq_list)): current_freq = freq_list[i] using_LO1 = (i % 2 == 0) mapping_val = VAL_RX3_ON_LO1 if using_LO1 else VAL_RX3_ON_LO2 if using_LO1: pll_to_move = PLL_LO1 pll_to_move = PLL_LO1 else: pll_to_move = PLL_LO2 next_use_of_this_pll = i + 2 sw.Restart() try: RadioCtrl.LoSourceMappingSet(mapping_val) (I, Q) = FastRxCapture(RX_CHANNEL_MASK, CAPTURE_TIME_MS) sw.Stop() elapsed = sw.Elapsed.TotalMilliseconds results_buffer.append((current_freq, I, Q, elapsed)) if next_use_of_this_pll < len(freq_list): RadioCtrl.PllFrequencySet(pll_to_move, freq_list[next_use_of_this_pll]) src_str = "LO1" if using_LO1 else "LO2" print "Freq %d : %.3f GHz | T=%.2f ms | %s (MapVal=%d)" % (i, current_freq/1e9, elapsed, src_str, mapping_val) except Exception as e: print "ERREUR Freq %d : %s" % (i, str(e)) sw.Stop() print "\n=== 3. Sauvegarde ===" path = 'C:\\Users\\a942666\\Desktop\\Alternance\\Stage\\Code_IronPython_ADRV\\Results' ts = datetime.datetime.now().strftime("%H%M%S") try: for item in results_buffer: f_val, i_dat, q_dat, t_ms = item filename = "PP_Final_%s_Freq_%d.txt" % (ts, f_val/1e6) full_path = System.IO.Path.Combine(path, filename) with open(full_path, 'w') as f: f.write("I\tQ\n") limit = min(len(i_dat), 1000) for k in range(limit): f.write("%d\t%d\n" % (i_dat[k], q_dat[k])) print "Sauvegarde terminee." except Exception as e: print "Erreur Disque: " + str(e) if (connect): link.platform.board.Client.Disconnect()