176 lines
6.4 KiB
C#
176 lines
6.4 KiB
C#
using CMS_CORE_Library.Models;
|
|
using System.Collections.Generic;
|
|
using System.Web.Http;
|
|
using Thermo.Active.NC;
|
|
using Thermo.Active.Utils;
|
|
|
|
namespace Thermo.Active.Controllers.WebApi
|
|
{
|
|
[RoutePrefix("api/prod")]
|
|
public class ProdController : ApiController
|
|
{
|
|
/// <summary>
|
|
/// Oggetto adapter condiviso da WebAPI
|
|
/// </summary>
|
|
protected static NcAdapter ncAdapter = new NcAdapter();
|
|
|
|
/// <summary>
|
|
/// Request mode SETUP
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("mode/manual"), HttpPut]
|
|
public IHttpActionResult RequestManual()
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | RequestManual | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// scrivo sul PLC il comando strobe richiesta AUTO!
|
|
libraryError = ncAdapter.StrobeMode(Model.DTOModels.ThProd.Mode.MANUAL);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"RequestManual error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
/// <summary>
|
|
/// Request mode AUTO
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("mode/auto"), HttpPut]
|
|
public IHttpActionResult RequestAuto()
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | RequestAuto | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// scrivo sul PLC il comando strobe richiesta AUTO!
|
|
libraryError = ncAdapter.StrobeMode(Model.DTOModels.ThProd.Mode.AUTO);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"RequestAuto error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
/// <summary>
|
|
/// Request mode SETUP
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("mode/setup"), HttpPut]
|
|
public IHttpActionResult RequestSetup()
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | RequestSetup | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// scrivo sul PLC il comando strobe richiesta AUTO!
|
|
libraryError = ncAdapter.StrobeMode(Model.DTOModels.ThProd.Mode.SETUP);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"RequestSetup error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Request start production
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("start"), HttpPut]
|
|
public IHttpActionResult StartProd(int requestQty, bool newWorkOrder)
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | StartProd | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// scrivo sul PLC il comando strobe richiesta AUTO!
|
|
libraryError = ncAdapter.UpdateProdInfoData((short)requestQty, newWorkOrder);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"StartProd error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok();
|
|
}
|
|
/// <summary>
|
|
/// Request production current data
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("get"), HttpPut]
|
|
public IHttpActionResult GetProd()
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | StartProd | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// scrivo sul PLC il comando strobe richiesta AUTO!
|
|
libraryError = ncAdapter.ReadProdInfoData(out ThermoModels.ProdInfoModel prodInfoDat);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"GetProd error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok(prodInfoDat);
|
|
}
|
|
/// <summary>
|
|
/// Request production data from indexStart record for numRecord items (DESCENDING)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("history"), HttpPut]
|
|
public IHttpActionResult GetHistory(int indexStart, int numRecord)
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | StartProd | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// scrivo sul PLC il comando strobe richiesta AUTO!
|
|
libraryError = ncAdapter.GetHistProdInfoData(out List<ThermoModels.ProdInfoModel> prodInfoDataList, indexStart, numRecord);
|
|
if (libraryError.IsError())
|
|
{
|
|
ThermoActiveLogger.LogError($"GetHistory error | {libraryError.exception}");
|
|
return BadRequest(libraryError.localizationKey);
|
|
}
|
|
|
|
// ritorno solo fatto!
|
|
return Ok(prodInfoDataList);
|
|
}
|
|
}
|
|
} |