import argparse
import DGSDK
import os

def main(args):
    if not os.path.exists(args.dll):
        raise FileNotFoundError(f'DLL {args.dll} not found')
    # if not os.path.exists(args.file):
        # raise FileNotFoundError(f'Waveform file {args.file} not found')

    print(f"DLL location: {args.dll}")
    print(f"Loading from {args.file}")

    # Set DLL
    DGSDK.dg64SetDLL(args.dll)

    # Get Hardware after connected
    DGSDK.dg64GetHardware(verbose=True)
    
    # Set Input File (.dgw/.dgv /.tdw)
    DGSDK.dg64LoadFile(args.file)

    # Start sending signals
    DGSDK.dg64Start()

    # Stop
    DGSDK.dg64Stop()

    # Disconnected with the hardware and release the resource
    DGSDK.dg64Shutdown()

    
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-dll', '-d', default="D:\\DGSDK_Python_2025\\DGSDK_Python_2025\\DgRun64.dll",
                        help='DGRun DLL File Location')
    parser.add_argument('-file', '-f', default="D:\\DGSDK_Python_2025\\DGSDK_Python_2025\\I2C_addr12.dgw",
                        help='Input waveform files')    
    main(parser.parse_args())