Skip to content
wav_coherent.py 1.68 KiB
Newer Older
# -*- coding: utf-8 -*-
"""
Created on Wed Feb  6 13:07:39 2019

@author: Usuario
"""

#import serial 
#
#wavCoh=serial.Serial('COM10', timeout=1, rtscts=True)
#wavCoh.close()
#%%
    
 
def read_measurement(wm):
    with wm as w:
        w.write(b'VAL?\n')
        #time.sleep(0.2)
        a = w.readline().decode("utf-8")
        a = a.split(',')[1]
        a = a.split('\r')[0]
def read_measurement_forever(wm):
    with wm as w:
        while(True):
            w.write(b'VAL?\n')
            #time.sleep(0.2)
            
            a = w.readline().decode("utf-8")
            try:
                a = a.split(',')[1]
                a = a.split('\r')[0]
                print(a)
            except:
                print("wrong value read")
            time.sleep(1)


def set_unit(wm, unit):
    """
    unit can be: 
        A: wl in air 
        V: wl in vacuum
        F: frequency
        W: wavenumber
    """
    with wm as w:
        string_to_write = b'UNI ' + unit + b'\n'
        w.write(string_to_write)
        
def check_unit(wm):
    with wm as w:
         w.write(b'UNI? \n')
         #time.sleep(0.2)
         unit = w.readline().decode("utf-8")
         
         if unit[5:6] == 'V':
             return 'U'
             
    return unit[5:6]

#%%
if __name__ == '__main__':

    import serial 
    import time

    wavCoh=serial.Serial('COM11', timeout=1, rtscts=True)
    wavCoh.close()
    set_unit(wavCoh, b'F')
    print(read_measurement(wavCoh))
    

    read_measurement_forever(wavCoh)
        
#    print(a[12:20])
#    check_unit(wavCoh)
#    import os
#    scriptDirectory = os.path.dirname(os.path.realpath(__file__))