First commit CMS-Connect M154
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using CMS_CORE_Library.Models;
|
||||
using Step.Config;
|
||||
using Step.Core;
|
||||
using Step.Database.Controllers;
|
||||
using Step.Model.DTOModels;
|
||||
using Step.Model.DTOModels.AlarmModels;
|
||||
using Step.Model.DTOModels.Scada;
|
||||
@@ -807,65 +808,109 @@ public static class ThreadsFunctions
|
||||
}
|
||||
|
||||
foreach (M154DataModel m154 in data)
|
||||
{
|
||||
string stringVal = "Path_" + m154.Process + "_";
|
||||
string val = "";
|
||||
// Check if command is MTC
|
||||
if (m154.Parameters[0] == "MTC")
|
||||
{
|
||||
if(ServerStartupConfig.CMSConnectReady)
|
||||
{
|
||||
// Convert tag string in Pascal Case and add to result string
|
||||
switch (m154.Parameters[1].ToLower())
|
||||
|
||||
if (m154.Parameters.Count() >= 2 && m154.Parameters[0] == "SOUR")
|
||||
{
|
||||
case "currprog":
|
||||
stringVal += "CurrProg";
|
||||
break;
|
||||
|
||||
case "partid":
|
||||
stringVal += "PartId";
|
||||
break;
|
||||
|
||||
default:
|
||||
stringVal += m154.Parameters[1];
|
||||
break;
|
||||
}
|
||||
// Set value
|
||||
if (m154.Parameters.Count() > 2)
|
||||
val = m154.Parameters[2];
|
||||
|
||||
// Create MTC Directory if not exist
|
||||
if (!Directory.Exists(ServerStartupConfig.MTCFolderPath))
|
||||
Directory.CreateDirectory(ServerStartupConfig.MTCFolderPath);
|
||||
|
||||
string outputFileName = ServerStartupConfig.MTCFolderPath + "\\DATA\\CmsGeneralStatus.mtc";
|
||||
// Create file if not exits
|
||||
if (!File.Exists(outputFileName))
|
||||
using (var f = File.Create(outputFileName)) { };
|
||||
// Read file
|
||||
List<string> fileLines = File.ReadAllLines(outputFileName).ToList();
|
||||
string[] parametersInLine;
|
||||
bool found = false;
|
||||
for (int i = 0; i < fileLines.Count() && !found; i++)
|
||||
{
|
||||
// Get tag & value from row
|
||||
parametersInLine = fileLines[i].Split('|');
|
||||
if (parametersInLine[0] == stringVal)
|
||||
// Convert tag string in Pascal Case and add to result string
|
||||
switch (m154.Parameters[1].ToLower())
|
||||
{
|
||||
found = true;
|
||||
fileLines[i] = stringVal + "|" + val;
|
||||
}
|
||||
}
|
||||
// If tag doesn't exists, append new line
|
||||
if (!found)
|
||||
fileLines.Add(stringVal + "|" + val);
|
||||
case "currprog":
|
||||
if (m154.Parameters.Count() < 3)
|
||||
return;
|
||||
RedisController.WriteProductionName(m154.Process, m154.Parameters[2]);
|
||||
break;
|
||||
|
||||
// Write file
|
||||
File.WriteAllLines(outputFileName, fileLines.ToArray());
|
||||
case "repstarget":
|
||||
if (m154.Parameters.Count() < 3)
|
||||
return;
|
||||
RedisController.WriteProductionRepsTarget(m154.Process, m154.Parameters[2]);
|
||||
break;
|
||||
|
||||
case "repsdone":
|
||||
if (m154.Parameters.Count() < 3)
|
||||
return;
|
||||
RedisController.WriteProductionRepsDone(m154.Process, m154.Parameters[2]);
|
||||
break;
|
||||
|
||||
default:
|
||||
string notif = m154.Parameters[1];
|
||||
if (m154.Parameters.Count() > 2)
|
||||
notif += m154.Parameters[2];
|
||||
RedisController.WriteProductionNotification(m154.Process, notif);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Write ack
|
||||
libraryError = ncHandler.WriteM154Ack((int)m154.Process);
|
||||
if (libraryError.IsError())
|
||||
ManageLibraryError(libraryError);
|
||||
}
|
||||
else //MTC
|
||||
{
|
||||
string stringVal = "Path_" + m154.Process + "_";
|
||||
string val = "";
|
||||
|
||||
// Check if command is MTC
|
||||
if (m154.Parameters[0] == "MTC")
|
||||
{
|
||||
// Convert tag string in Pascal Case and add to result string
|
||||
switch (m154.Parameters[1].ToLower())
|
||||
{
|
||||
case "currprog":
|
||||
stringVal += "CurrProg";
|
||||
break;
|
||||
|
||||
case "partid":
|
||||
stringVal += "PartId";
|
||||
break;
|
||||
|
||||
default:
|
||||
stringVal += m154.Parameters[1];
|
||||
break;
|
||||
}
|
||||
// Set value
|
||||
if (m154.Parameters.Count() > 2)
|
||||
val = m154.Parameters[2];
|
||||
|
||||
// Create MTC Directory if not exist
|
||||
if (!Directory.Exists(ServerStartupConfig.MTCFolderPath))
|
||||
Directory.CreateDirectory(ServerStartupConfig.MTCFolderPath);
|
||||
|
||||
string outputFileName = ServerStartupConfig.MTCFolderPath + "\\DATA\\CmsGeneralStatus.mtc";
|
||||
// Create file if not exits
|
||||
if (!File.Exists(outputFileName))
|
||||
using (var f = File.Create(outputFileName)) { };
|
||||
// Read file
|
||||
List<string> fileLines = File.ReadAllLines(outputFileName).ToList();
|
||||
string[] parametersInLine;
|
||||
bool found = false;
|
||||
for (int i = 0; i < fileLines.Count() && !found; i++)
|
||||
{
|
||||
// Get tag & value from row
|
||||
parametersInLine = fileLines[i].Split('|');
|
||||
if (parametersInLine[0] == stringVal)
|
||||
{
|
||||
found = true;
|
||||
fileLines[i] = stringVal + "|" + val;
|
||||
}
|
||||
}
|
||||
// If tag doesn't exists, append new line
|
||||
if (!found)
|
||||
fileLines.Add(stringVal + "|" + val);
|
||||
|
||||
// Write file
|
||||
File.WriteAllLines(outputFileName, fileLines.ToArray());
|
||||
|
||||
// Write ack
|
||||
libraryError = ncHandler.WriteM154Ack((int)m154.Process);
|
||||
if (libraryError.IsError())
|
||||
ManageLibraryError(libraryError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user