You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.5 KiB
49 lines
1.5 KiB
using Application.Domain.Entities;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SPService.Applicaiton.Models;
|
|
using System;
|
|
using System.Net.Http;
|
|
|
|
namespace SerialPortService.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly IRepository<Button> _cameraRepo;
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
private readonly DeviceService _spService;
|
|
|
|
public HomeController(IHttpClientFactory httpClientFactory, DeviceService spService, IRepository<Button> cameraRepo)
|
|
{
|
|
this._cameraRepo = cameraRepo;
|
|
this._httpClientFactory = httpClientFactory;
|
|
this._spService = spService;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
return View(new EditButtonModel { Name = "test" });
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult Index(EditButtonModel model)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
try
|
|
{
|
|
var button = new Button().From(model);
|
|
this._spService.ExecInternal(button.SerialPort, button.Baud, button.Data, button.Partity, button.StopBits, button.Message);
|
|
ViewBag.Result = "success";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.PrintStack();
|
|
ModelState.AddModelError("", ex.Message);
|
|
}
|
|
}
|
|
return View(model);
|
|
}
|
|
}
|
|
} |