添加项目文件。
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using HardwareControl.Core;
|
||||
using HardwareControl.Core.HardwareServiceImpl.HardwareService;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace HardwareWeb.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/camera")]
|
||||
public class CameraController : ControllerBase
|
||||
{
|
||||
private readonly IUsbCameraService _cameraService;
|
||||
|
||||
public CameraController(IUsbCameraService cameraService)
|
||||
{
|
||||
_cameraService = cameraService;
|
||||
}
|
||||
|
||||
[HttpPost("connect")]
|
||||
public async Task<IActionResult> Connect(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _cameraService.ConnectAsync(ct);
|
||||
return Ok(new { connected = _cameraService.IsConnected });
|
||||
}
|
||||
catch (HardwareException ex)
|
||||
{
|
||||
return StatusCode(500, new
|
||||
{
|
||||
error = ex.Kind.ToString(),
|
||||
message = ex.Message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("disconnect")]
|
||||
public async Task<IActionResult> Disconnect(CancellationToken ct)
|
||||
{
|
||||
await _cameraService.DisconnectAsync(ct);
|
||||
return Ok(new { connected = _cameraService.IsConnected });
|
||||
}
|
||||
|
||||
[HttpGet("status")]
|
||||
public IActionResult GetStatus()
|
||||
{
|
||||
return Ok(new
|
||||
{
|
||||
connected = _cameraService.IsConnected,
|
||||
deviceName = _cameraService.DeviceName,
|
||||
format = _cameraService.FrameFormat,
|
||||
framesReceived = _cameraService.FramesReceived,
|
||||
lastFrameAt = _cameraService.LastFrameAt
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user