from fn_gen import DG2052
from fn_gen.enums import OutputChannel
import fn_gen.errors as fg_err
import logging
import time

if __name__ == "__main__":
    try:
        # logging.basicConfig(filename="dg2052.log", encoding="utf-8", level=logging.DEBUG)
        fn_gen = DG2052("TCPIP::192.168.1.11::INSTR")
        channel = OutputChannel.TWO
        print(fn_gen.whoami())
        print( f"\nOutput{channel.value} Impedance: {fn_gen.get_output_impedance(channel)} Ohm" )
        print( f"Output{channel.value} Load: {fn_gen.get_output_load(channel)} Ohm" )
        print( f"Output{channel.value} Voltage Limits: {fn_gen.get_output_volt_limits(channel)} V" )
        fn_gen.set_square_wave(channel, 500, 2.5, 0, 0)
        print( f"Output{channel.value}: {fn_gen.get_output_signal(channel)} | {fn_gen.get_output_state(channel)}" )
        fn_gen.set_output(channel, True)
        print( f"Output{channel.value} State: {fn_gen.get_output_state(channel)}" )
        time.sleep(5)
        fn_gen.set_output(channel, False)
        print( f"Output{channel.value} State: {fn_gen.get_output_state(channel)}" )
    except fg_err.UndefinedCommunicationMethodError as err:
        print(err)
    except fg_err.ValueOutOfBoundsError as err:
        print(err)
    except fg_err.UndefinedValueError as err:
        print(err)
