using System;
using Dll_CSharp_VSensor;
using System.Collections.Generic;
namespace Demo.UserSetting
{
    public class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //获取相对路径
                string path = System.IO.Directory.GetCurrentDirectory();
                //实例化设备
                VSensorDLL VSensor = new VSensorDLL();
                //获取设备列表
                List<VSensorCameraInfoCLR> list = new List<VSensorCameraInfoCLR>(20);
                for (int i = 0; i < 20; i++)
                {
                    list.Add(new VSensorCameraInfoCLR());
                }
                int num = 0;
                VSensor.GetDeviceList(ref list, ref num);
                for (int i = 0; i < num; i++)
                {
                    Console.WriteLine("device num {0} : list[{1}] = {2}\n", i, i, list[i].CameraName);
                }
                //连接第一台设备
                int status = VSensor.DeviceConnect(0);
                if (status != 0)
                {
                    Console.WriteLine("connect device failed, status = {0}\n", status);
                    Console.ReadLine();
                }
                //设备参数初始化，仅上电时需要进行此操作，初始化需要等待15s
                Console.WriteLine("waiting for parameter init...\n");
                status = VSensor.DeviceParameterInit();
                if (status != 0)
                {
                    Console.WriteLine("parameter init failed, status = {0}\n", status);
                    Console.ReadLine();
                }
                //重置用户设置数据
                status = VSensor.ResetUserSettingData();
                if (status != 0)
                {
                    Console.WriteLine("reset user setting data failed, status = {0}\n", status);
                    Console.ReadLine();
                }
                //保存用户设置数据
                status = VSensor.SaveUserSettingData(path + @"\setting.ini");
                if (status != 0)
                {
                    Console.WriteLine("save user setting data failed, status = {0}\n", status);
                    Console.ReadLine();
                }
                //加载用户设置数据
                status = VSensor.LoadUserSettingData(path + @"\setting.ini");
                if (status != 0)
                {
                    Console.WriteLine("load user setting data failed, status = {0}\n", status);
                    Console.ReadLine();
                }
                //反初始化设备
                status = VSensor.DeviceUnInit();
                if (status != 0)
                {
                    Console.WriteLine("device release failed, status = {0}\n", status);
                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"ex:{ex}");
            }
            Console.WriteLine("run success");
            Console.ReadLine();
            Console.ReadKey();
        }
    }
}

