from gpib82357A import *
from math import *


class HP3478A:
    def __init__(self,name="GPIB0::3::INSTR"):
       self.GPIB=gpib82357A(name)

    def reset(self):
        self.GPIB.write("*RST\n")

    def idn(self):
        self.GPIB.write("*IDN\n")
        st=self.GPIB.read() 
        return st
    
    def cmd(self,str) : 
        self.GPIB.cmd(str)

    def write(self,str) : 
        self.GPIB.write(str)

    def read(self) : 
        st=self.GPIB.read()
        return st
        
    def getvoltage(self,str) : #str "DC" or "AC" 
        if (str=='DC'):
            self.GPIB.write('H1?\n')
        else:
            self.GPIB.write('H2?\n')
        st=float(self.GPIB.read())
        return st

    def getresistance(self,str) : #str "2WIRE" or "4WIRE" 
        if (str=='2WIRE'):
            self.GPIB.write('H3?\n')
        else:
            self.GPIB.write('H4?\n')
        st=float(self.GPIB.read()) 
        return st    
        
    def getcurrent(self,str): #str "DC" or "AC" 
        if (str=='DC'):
            self.GPIB.write('H5?\n')
        else:
            self.GPIB.write('H6?\n')
        st=float(self.GPIB.read())
        return st
        
    def display(self,str): #str uppercase ONLY !
        msg="D2%s" %str
        self.GPIB.write(msg)
        
    def dBm(self,R=50):
        Veff=float(self.getvoltage('AC'))
        P=10*log10(Veff*Veff/R/10E-3)
        return P
        
        return st
    def close(self):
        self.GPIB.close()