<jupyter_start><jupyter_text>Calulate Dealy Time of Applying Magnetic Field**Author**: `<NAME>`  **Update**: `2018-12-12`  **Package**: `pyvisa`, `serial`, `ipywidgets`(*optional*), `plotly`(*optional*)  **Driver**: `NI-VISA`<jupyter_code>import visa
import time
import serial
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
import matplotlib.pyplot as plt
from datetime import datetime
import time


rm = visa.ResourceManager()
res = rm.list_resources()
vna_dict =[]
for x in range(0, len(res)):
    vna_dict.append(res[x])
    print("{}. ".format(x) + res[x] + ", \n")
print("\n")
KEPCO_address = widgets.ToggleButtons(
    options=vna_dict,
    description="Power Sup.",
    disabled=False,
    button_style='success', # 'success', 'info', 'warning', 'danger' or ''
    tooltips=[],
#     icons=['check'] * 3
)
LakeShore_address = widgets.Text()
accordion = widgets.Accordion(children=[KEPCO_address, LakeShore_address])
accordion.set_title(0, 'Power Supply (KEPCO)')
accordion.set_title(1, 'Gauss meter (LakeShore)')
accordion
ser = serial.Serial(LakeShore_address.value, 57600,bytesize=7, parity=serial.PARITY_ODD, stopbits=1)  # Lake Shore 425
LakeShore_address.value
sweep_current = 40
sweep_pts = 1601
KEPCO = rm.open_resource(KEPCO_address.value)

KEPCO.timeout=10000
KEPCO.write("FUNC:MODE CURR")
KEPCO.write("volt 0.000;curr 0.000")
KEPCO.write("volt  20.000;curr {:.4f}".format(sweep_current/(sweep_pts-1)))

Field_data = []
Time = []
origin = datetime.now()
KEPCO.write("OUTPUT ON")
for i in range(200):
    time.sleep(0.005)
    current_time = datetime.now()
    ser.write(b'RDGFIELD?\n')
    Field = ser.readline()
    Field_data.append(Field.decode('utf8'))
    Time.append(current_time.second + (current_time.microsecond-origin.microsecond)/1000000 - origin.second)
    
KEPCO.write("OUTPUT OFF")
KEPCO.write("volt 0.000;curr 0.000")
#ser.close()<jupyter_output><empty_output><jupyter_text>Plot Data<jupyter_code>import plotly as py
from plotly.graph_objs import Scatter, Layout
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)
import plotly.graph_objs as go
trace = go.Scatter(x=Time, y=Field_data, name='Original data')
iplot([trace], filename='test')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14995678478824545, 'fraction_numerical': 0.030682800345721694, 'mean_word_length': 6.101226993865031, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '608782', 'license': 'MIT', 'n_tokens_mistral': 905, 'n_tokens_neox': 835, 'n_words': 166, 'path': 'Notebook/Calulate Dealy Time of Applying Magnetic Field.ipynb', 'repo_name': 'ttt50966/Ipython_DAQ', 'size': '2322'}