using System;
using Dll_CSharp_VSensorLaser;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Demo.Testdll
{
    public class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //获取相对路径
                string path = System.IO.Directory.GetCurrentDirectory();
                //实例化设备
                VSensorLaserDLL VSensor = new VSensorLaserDLL();
                //当前SDK版本
                string version = "";
                VSensor.GetSdkVersionString(ref version);
                Console.WriteLine("sdk version: {0}\n", version);
                //获取设备列表
                List<VSensorLaserCameraInfoCLR> list = new List<VSensorLaserCameraInfoCLR>(20);
                for (int i = 0; i < 20; i++)
                {
                    list.Add(new VSensorLaserCameraInfoCLR());
                }
                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();
                }
                //注册回调函数
                CallbackFuncGetResult delLambda = delegate (VSensorLaserResultCLR result)
                {
                    VSensor.Save3DCloud(path + @"\callback.ply", result, 0);
                    VSensor.SaveGrayMap(path + @"\callback.bmp", result);
                };
                VSensor.RegisterCallbackFuncGetResult(delLambda);
                //设置投影等级
                status = VSensor.SetProjectLight(1);
                if (status != 0)
                {
                    Console.WriteLine("set project light failed, status = {0}\n", status);
                    Console.ReadLine();
                }
                //设置为采集模式
                status = VSensor.SetCaptureMode(1);
                if (status != 0)
                {
                    Console.WriteLine("set capture mode failed, status = {0}\n", status);
                    Console.ReadLine();
                }
                //单次采集测试
                Console.WriteLine("single restruction ...\n");
                status = VSensor.SingleRestruction(0);
                if (status != 0)
                {
                    Console.WriteLine("single restruction 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();
        }
    }
}
