wav_coherent.py 1.68 KB
Newer Older
1 2 3 4 5 6 7 8
# -*- coding: utf-8 -*-
"""
Created on Wed Feb  6 13:07:39 2019

@author: Usuario
"""

#import serial 
9
import time
10 11 12 13 14 15 16 17 18 19 20
#
#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")
21 22
        a = a.split(',')[1]
        a = a.split('\r')[0]
23
        
24
    return a
25

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
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)

41 42 43 44 45 46 47 48 49 50 51

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'
52 53
        
        
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
        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

73
    
74 75
    wavCoh=serial.Serial('COM11', timeout=1, rtscts=True)
    wavCoh.close()
76
    set_unit(wavCoh, b'F')
77 78 79
    print(read_measurement(wavCoh))
    

80 81
    read_measurement_forever(wavCoh)
        
82 83 84 85
#    print(a[12:20])
#    check_unit(wavCoh)
#    import os
#    scriptDirectory = os.path.dirname(os.path.realpath(__file__))