202 lines
7.4 KiB
C#
202 lines
7.4 KiB
C#
using CMS_CORE_Library.Models;
|
|
using Thermo.Active.Model.DTOModels;
|
|
using Thermo.Active.NC;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Http;
|
|
using static CMS_CORE_Library.Models.DataStructures;
|
|
using static Thermo.Active.Config.ServerConfig;
|
|
using static Thermo.Active.Model.Constants;
|
|
using Thermo.Active.Model.DTOModels.ThRecipe;
|
|
using Thermo.Active.Config;
|
|
using Thermo.Active.Utils;
|
|
|
|
namespace Thermo.Active.Controllers.WebApi
|
|
{
|
|
[RoutePrefix("api/prod")]
|
|
public class ProdController : ApiController
|
|
{
|
|
|
|
/// <summary>
|
|
/// Request mode SETUP
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Route("mode/manual"), HttpPut]
|
|
public IHttpActionResult RequestManual()
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.errorCode != 0)
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | RequestManual | {libraryError.exception}");
|
|
return InternalServerError();
|
|
}
|
|
|
|
// 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()
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.errorCode != 0)
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | RequestAuto | {libraryError.exception}");
|
|
return InternalServerError();
|
|
}
|
|
|
|
// 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()
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.errorCode != 0)
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | RequestSetup | {libraryError.exception}");
|
|
return InternalServerError();
|
|
}
|
|
|
|
// 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("prod/start"), HttpPut]
|
|
public IHttpActionResult StartProd(int requestQty, bool newWorkOrder)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.errorCode != 0)
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | StartProd | {libraryError.exception}");
|
|
return InternalServerError();
|
|
}
|
|
|
|
// 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("prod/get"), HttpPut]
|
|
public IHttpActionResult GetProd()
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.errorCode != 0)
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | StartProd | {libraryError.exception}");
|
|
return InternalServerError();
|
|
}
|
|
|
|
// 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("prod/history"), HttpPut]
|
|
public IHttpActionResult GetHistory(int indexStart, int numRecord)
|
|
{
|
|
using (NcAdapter ncAdapter = new NcAdapter())
|
|
{
|
|
// Try connection
|
|
CmsError libraryError = ncAdapter.Connect();
|
|
if (libraryError.errorCode != 0)
|
|
{
|
|
ThermoActiveLogger.LogError($"NC Not connected! | StartProd | {libraryError.exception}");
|
|
return InternalServerError();
|
|
}
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
}
|
|
} |