from ctypes import *
from secg40 import *
import sys
import time

device = SECG40(get_lib_path())

if device.connect(-1, 5000) == False:
    print('Error: device is not connected')
    sys.exit()

print('TestDCOffset -----------------------------------------------------')
# DC Offset Related APIs
DCOffset = device.get_dc_offset()
print('Initial DC Offset: ', DCOffset, ' mV')

DCVarMode = device.get_dc_offset_variable_mode()
if 0 != DCVarMode:
    print('Initial DC Offset Variable Mode: On')
else:
    print('Initial DC Offset Variable Mode: Off')

DCComMode = device.get_dc_offset_common_mode()
if 0 != DCComMode:
    print('Initial DC Offset Common Mode: On')
else:
    print('Initial DC Offset Common Mode: Off')

# Under "Non-Variable Mode", only "300mV" and "-300mV" 2 value can be set
DCOffset = 300
device.set_dc_offset(DCOffset)
device.set_output_function(OutputFunction_E.Output_Sine.value)
print('Output Sine signal with 300mV DC offset')
time.sleep(5)

DCOffset = -300
device.set_dc_offset(DCOffset)
print('Output Sine signal with -300mV DC offset')
time.sleep(5)

# Under "Variable Mode", between "-1000mV"  and "1000mV" integer value van be set
device.set_dc_offset_variable_mode(1)
DCVarMode = device.get_dc_offset_variable_mode()
if 0 != DCVarMode:
    print('Turn On DC Offset Variable Mode.')

DCOffset = 150
device.set_dc_offset(DCOffset)  # Output Sine signal with 150mV DC offset
print('Output Sine signal with 150mV DC offset')
time.sleep(5)

DCOffset = -150
device.set_dc_offset(DCOffset)  # Output Sine signal with -150mV DC offset
print('Output Sine signal with -150mV DC offset')
time.sleep(5)

device.set_output_function(OutputFunction_E.Output_Off.value)
device.set_dc_offset(0)
# Common Mode only work without Variable Mode
device.set_dc_offset_variable_mode(0)

device.set_dc_offset_common_mode(1)
DCComMode = device.get_dc_offset_common_mode()
if 0 != DCComMode:
    print('Turn On DC Offset Common Mode.')

DCOffset = 300
device.set_dc_offset(DCOffset)
device.set_output_function(OutputFunction_E.Output_Sine.value)
print('Output Sine signal with 300mV DC offset in common mode')
time.sleep(5)

device.close()
