49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using AgroBase.Models;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace AgroBase.Services
|
|
{
|
|
public class OAKCameraService
|
|
{
|
|
public static List<OAKCameraModel> GetConnectedCameras()
|
|
{
|
|
var cameras = new List<OAKCameraModel>()
|
|
{
|
|
new OAKCameraModel()
|
|
{
|
|
Id = "Sem video",
|
|
Index = -1,
|
|
Model = "",
|
|
Usb_Speed = ""
|
|
}
|
|
};
|
|
|
|
try
|
|
{
|
|
string output = PythonService.RunScriptWithCallback(PythonService.ScriptListOAK, new string[] { });
|
|
|
|
if (string.IsNullOrWhiteSpace(output))
|
|
{
|
|
Console.WriteLine("Nenhuma saída do script Python.");
|
|
return cameras;
|
|
}
|
|
|
|
// Converte o JSON para uma lista de objetos OakCamera
|
|
List<OAKCameraModel> _cameras = JsonConvert.DeserializeObject<OAKCameraModel[]>(output).ToList();
|
|
|
|
cameras.AddRange(_cameras);
|
|
|
|
return cameras;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Erro ao executar script Python: {ex.Message}");
|
|
return cameras;
|
|
}
|
|
}
|
|
}
|
|
}
|