if false cleanup

This commit is contained in:
Samuele Locatelli
2020-06-19 18:32:53 +02:00
parent 6c1b449816
commit 006f9d4b0d
+8 -672
View File
@@ -937,6 +937,8 @@ namespace CMS_CORE_Library.S7Net
public override CmsError PLC_RM154Data(ref List<M154DataModel> data, ref bool MTCOnOff)
{
// FIXME TODO - levare?
MTCOnOff = false;
CmsError libraryError = MEM_RWBoolean(R, 0, M154_SWITCH_ONOFF.MemType, M154_SWITCH_ONOFF.Address, M154_SWITCH_ONOFF.SubAddress, 1, ref MTCOnOff);
@@ -1252,24 +1254,6 @@ namespace CMS_CORE_Library.S7Net
return NO_ERROR;
}
#if false
// no strobe....
// Check ACK
libraryError = MEM_RWBoolean(R, 0, ackCell.MemType, ackCell.Address, ackByte, alarmBitId, ref readValue);
if (libraryError.IsError())
return libraryError;
// if strobe is down and ack is up
if (readValue)
{
// Reset wait ack = 1 and reset the strobe
libraryError = ResetAck(alarmBitId, strobeByte, ackByte, ackCell.MemType);
if (libraryError.IsError())
return libraryError;
}
#endif
return NO_ERROR;
}
/// <summary>
@@ -1566,9 +1550,7 @@ namespace CMS_CORE_Library.S7Net
if (libraryError.IsError())
return libraryError;
// FIXME
// fare guardando mappatura memoria stsato processo
// FIXME TODO - fare guardando mappatura memoria stsato processo
#if false
// Try to get information
@@ -1606,10 +1588,7 @@ namespace CMS_CORE_Library.S7Net
return libraryError;
// FIXME
// fare guardando amppatura variabili status
// FIXME TODO - fare guardando mappatura variabili status
#if false
// Try to get information
try
@@ -1648,8 +1627,7 @@ namespace CMS_CORE_Library.S7Net
// Get the process Active Alarms
public override CmsError PROC_RActiveAlarms(ushort procNumber, ref List<AlarmModel> alarms)
{
// fare guardando bitmap allarmi attivi
// FIXME TODO - fare guardando bitmap allarmi attivi
#if false
alarms = SiemensAlarms
.Where(x => x.Id >= IDMinChannel && x.Id <= IDMaxChannel && x.Parameters[0].Equals(procNumber.ToString()))
@@ -1767,9 +1745,7 @@ namespace CMS_CORE_Library.S7Net
if (processId <= 0)
return PROC_NOT_FOUND_ERROR;
// FIXME
// ha senso?
// FIXME TODO - ha senso?
#if false
try
{
@@ -1897,27 +1873,6 @@ namespace CMS_CORE_Library.S7Net
{
return FUNCTION_NOT_ALLOWED_ERROR;
#if false
try
{
Item item = new Item();
if (processId == 0)
item.Path = "/Channel/ProgramInfo/actBlock[u1,1]"; // Default
else
item.Path = "/Channel/ProgramInfo/actBlock[u" + processId + ",1]";
DataSvc dataSvc = new DataSvc();
dataSvc.Read(item);
line = item.Value.ToString();
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
}
#endregion PROCESS (PATH) High-level data
@@ -1980,12 +1935,10 @@ namespace CMS_CORE_Library.S7Net
{
CmsError libraryError = NO_ERROR;
#if false
// Call ack for prod update
libraryError = PLC_WAck(PROD_UPD_STROBE, PROD_UPD_ACK, 4);
libraryError = PLC_WAck(REQ_CONF_ACK, REQ_CONF_STROBE, 4);
if (libraryError.IsError())
return libraryError;
#endif
return libraryError;
return libraryError;
}
@@ -3104,315 +3057,52 @@ namespace CMS_CORE_Library.S7Net
public override CmsError AXES_RInterpPosition(ushort channel, ref Dictionary<string, double> axes)
{
return FUNCTION_NOT_ALLOWED_ERROR;
#if false
try
{
axes = new Dictionary<string, double>();
// Cycle between axes
// The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions
// axes = InterpAxesPosition.ToDictionary(x => x.Key, x => x.Value); This code throws exceptions
lock (InterpAxesPosition)
{
foreach (var axis in InterpAxesPosition.ToList())
{
axes.Add(axis.Key, axis.Value);
}
}
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
}
public override CmsError AXES_RMachinePosition(ushort channel, ref Dictionary<string, double> axes)
{
return FUNCTION_NOT_ALLOWED_ERROR;
#if false
try
{
axes = new Dictionary<string, double>();
lock (MachineAxesPosition)
{
// Cycle between axes
// The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions
foreach (var axis in MachineAxesPosition.ToList())
{
axes.Add(axis.Key, axis.Value);
}
}
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
}
public override CmsError AXES_RProgrPosition(ushort channel, ref Dictionary<string, double> axes)
{
return FUNCTION_NOT_ALLOWED_ERROR;
#if false
try
{
axes = new Dictionary<string, double>();
lock (ProgrammedAxisPosition)
{
// Cycle between axes
// The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions
foreach (var axis in ProgrammedAxisPosition.ToList())
{
axes.Add(axis.Key, axis.Value);
}
}
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
}
public override CmsError AXES_RFollowingError(ushort channel, ref Dictionary<string, double> axes)
{
return FUNCTION_NOT_ALLOWED_ERROR;
#if false
try
{
axes = new Dictionary<string, double>();
lock (InterpAxesPosition)
{
// Cycle between axes
// The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions
foreach (var axis in InterpAxesPosition.ToList())
{
axes.Add(axis.Key, axis.Value);
}
}
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
}
public override CmsError AXES_RDistanceToGo(ushort channel, ref Dictionary<string, double> axes)
{
return FUNCTION_NOT_ALLOWED_ERROR;
#if false
try
{
axes = new Dictionary<string, double>();
lock (ToGoAxesPosition)
{
// Cycle between axes
// The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions
foreach (var axis in ToGoAxesPosition.ToList())
{
axes.Add(axis.Key, axis.Value);
}
}
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
}
private Dictionary<string, double> AXES_RAxesPos(ushort channel, string positionType)
{
Dictionary<string, double> axes = new Dictionary<string, double>();
#if false
List<AxisModel> axesConf = new List<AxisModel>();
CmsError libraryError = AXES_RAxesNames(channel, ref axesConf);
List<Item> items = new List<Item>();
foreach (var conf in axesConf)
{
// Setup the items to be readed
items.Add(new Item() { Path = string.Format("/Channel/{0}[u{1},{2}]", positionType, channel, conf.Id) });
}
DataSvc dataSvc = new DataSvc();
// Read all the items
dataSvc.Read(items.ToArray());
int i = 0;
foreach (var conf in axesConf)
{
axes.Add(conf.Id.ToString(), Convert.ToDouble(items[i].Value));
i++;
}
#endif
return axes;
}
public override CmsError AXES_RAxesNames(ushort channel, ref List<AxisModel> axesData)
{
return FUNCTION_NOT_ALLOWED_ERROR;
#if false
if (!File.Exists(AXES_FILE_PATH))
return CmsError.InternalError("File" + AXES_FILE_PATH + " not found", new Exception("File" + AXES_FILE_PATH + " not found"));
// Check if the NC is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
List<AxisModel> configuredAxes = new List<AxisModel>();
Item[] ncAxes = new Item[MAX_AXES_FOR_PROCESS * 3];
try
{
// Check if the static object is already populated
if (AxesData.Count == 0)
{
XDocument xmlAxesFile = XDocument.Load(AXES_FILE_PATH);
// Read data from file
configuredAxes = xmlAxesFile
.Root
.Elements()
.Select(x => new AxisModel()
{
Id = Convert.ToInt32(x.Attribute("id").Value),
Name = x.Value,
IsSelectable = false
})
.Where(x => x.Id != 0) // Parse only active axes
.ToList();
}
// Object used for reading data from NC
DataSvc svcData = new DataSvc();
bool[] axesAreVisible = new bool[MAX_AXES_FOR_PROCESS];
// Read from Nc
for (int i = 1; i <= MAX_AXES_FOR_PROCESS; i++)
{
// Set the path to read on which process is the axis
ncAxes[i - 1] = new Item("/Nck/MachineAxis/chanNoAxisIsActive[" + i + "]");
// Set the path in order to find which axes are visible
ncAxes[i - 1 + MAX_AXES_FOR_PROCESS] = new Item("/NC/_N_CH_TEA_ACX/$MC_DISPLAY_AXIS[u" + channel + "," + i + "]");
// Set the path of the axes type
ncAxes[i - 1 + (MAX_AXES_FOR_PROCESS * 2)] = new Item("/Nck/Configuration/axisType[" + i + "]");
}
svcData.Read(ncAxes);
for (int i = 0; i < MAX_AXES_FOR_PROCESS; i++)
{
// Set visible field
axesAreVisible[i] = (Convert.ToInt32(ncAxes[i + MAX_AXES_FOR_PROCESS].Value) & 1) == 1;
int processAxes = Convert.ToInt32(ncAxes[i].Value);
// If axis is visible, add it to the output
if (processAxes == channel && axesAreVisible[i])
{
// Check if axes is configurated axes
var axis = configuredAxes.Where(x => x.Id == (i + 1)).FirstOrDefault();
if (axis != null)
{
axis.Type = (AXIS_TYPE)Convert.ToInt32(ncAxes[i + (MAX_AXES_FOR_PROCESS * 2)].Value);
AxesData.Add(axis);
}
}
}
// Get from PLC which axis can be selected
List<byte> ids = new List<byte>();
libraryError = MEM_RWByteList(R, 0, AXES_BUTTON_VISIBLE.MemType, AXES_BUTTON_VISIBLE.Address, AXES_BUTTON_VISIBLE.SubAddress, 0, AXES_BUTTON_VISIBLE.Size, ref ids);
if (libraryError.IsError())
return libraryError;
// Parse the data readed from PLC
foreach (byte id in ids)
{
if (id != 0)
{
// If axis exists, set it as selectable
var tmpAxis = AxesData.Where(x => x.Id == id).FirstOrDefault();
if (tmpAxis != null)
tmpAxis.IsSelectable = true;
}
}
axesData = AxesData;
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
}
public override CmsError AXES_RSelectedAxis(ref byte axisId)
{
return FUNCTION_NOT_ALLOWED_ERROR;
#if false
// Read byte from memory
CmsError libraryError = MEM_RWByte(R, 0, SELECTED_AXIS.MemType, SELECTED_AXIS.Address, SELECTED_AXIS.SubAddress, 1, ref axisId);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
#endif
}
public override CmsError AXES_WSelectAxis(byte axisId)
{
return FUNCTION_NOT_ALLOWED_ERROR;
#if false
// Write byte from memory
CmsError libraryError = MEM_RWByte(W, 0, SELECT_AXIS.MemType, SELECT_AXIS.Address, SELECT_AXIS.SubAddress, 1, ref axisId);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
#endif
}
public override CmsError AXES_ROrigin(int numberOfAxes)
{
return FUNCTION_NOT_ALLOWED_ERROR;
#if false
DataSvc dataSvc = new DataSvc();
List<Item> ncAxes = new List<Item>();
List<AxisModel> axes = new List<AxisModel>();
CmsError libraryError = AXES_RAxesNames(1, ref axes);
for (int i = 1; i <= 4; i++)
{
foreach (var axis in axes)
{
var num = axis.Id + (axes.Last().Id * i);
ncAxes.Add(new Item()
{
Path = "/Channel/UserFrame/linShift[u1, " + num + "]"
});
}
}
dataSvc.Read(ncAxes.ToArray());
return NO_ERROR;
#endif
}
#endregion PROCESS-AXES (PATH) High-level data
@@ -4070,366 +3760,51 @@ namespace CMS_CORE_Library.S7Net
public override CmsError FILES_RGetFileList(string path, ref List<PreviewFileModel> files)
{
#if false
string[] rootFolders = { "WKS.DIR", "MPF.DIR", "SPF.DIR" };
try
{
string tmpPath = FormatPath(path);
FileSvc fileSvc = new FileSvc();
// Preapare folder node
Node folderNode = new Node(BASE_FILE_PATH + tmpPath);
// Read files in the folder
List<Node> nodeArray = fileSvc.List(folderNode).ToList();
// Go through the array of file nodes
foreach (Node element in nodeArray)
{
PreviewFileModel file = new PreviewFileModel();
if (path == "\\\\")
{
if (rootFolders.Contains(element.Name))
{
file = new PreviewFileModel()
{
Path = path + "\\" + element.Name,
IsDirectory = element.IsDirNode,
Name = GetStringUntilOrEmpty(element.Name, "."),
AbsolutePath = element.LogicalPath
};
files.Add(file);
}
}
else
{
file = new PreviewFileModel()
{
Path = path + "\\" + element.Name,
IsDirectory = element.IsDirNode,
Name = element.IsDirNode ? GetStringUntilOrEmpty(element.Name, ".") : element.Name,
AbsolutePath = element.LogicalPath
};
files.Add(file);
}
// ACCESS LEVEL CHECK (REMOVED TEMPORARILY)
//if (element.AccessRights.List == AccessLevel.KEY_0)
//{
// var file = new PreviewFileModel()
// {
// Path = path + "\\" + element.Name,
// IsDirectory = element.IsDirNode,
// Name = element.Name,
// AbsolutePath = element.LogicalPath
// };
// files.Add(file);
//}
}
}
catch (Exception ex)
{
return ManageException(ex);
}
#endif
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError FILES_RGetFileInfo(string path, ref InfoFile fileInfo)
{
#if false
try
{
FileSvc fileSvc = new FileSvc();
// Preapare folder node
Node fileNode = new Node(path);
if (fileNode != null)
{
string filePath = "C://CMS//Active//TMP//" + fileNode.Name;
FileStream str = new FileStream(filePath, FileMode.Create);
CmsError libraryError = FILES_RProgramToFile(path, str);
if (libraryError.IsError())
return libraryError;
fileInfo = new InfoFile()
{
CreationDate = fileNode.Attributes.LastAccess,
LastModDate = fileNode.Attributes.LastAccess,
Name = fileNode.Name,
Content = File.ReadAllLines(filePath).ToList(),
// PreviewBase64 = FindImageBase64String(IMAGES_PATH, fileNode.Name),
AbsolutePath = fileNode.LogicalPath
};
str.Close();
File.Delete(filePath);
}
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError FILES_WSetActiveProgram(int processId, string filePath, ref ActiveProgramDataModel data)
{
#if false
try
{
// string ncPath = FormatPath(filePath);
FileSvc fileSvc = new FileSvc();
// Preapare folder node
Node selectedNode = new Node(filePath);
if (!selectedNode.Exists)
return FILE_NOT_FOUND_ERROR;
// Check if file is stored on NC
if (filePath.StartsWith(BASE_FILE_PATH))
fileSvc.Select(selectedNode, processId);
else
fileSvc.SelectExtern(selectedNode, processId);
return FILES_RActiveProgramData(processId, ref data);
}
catch (Exception ex)
{
return ManageException(ex);
}
#endif
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError FILES_WDeactivateProgram(int processId)
{
#if false
try
{
string[] piArgs = new string[4];
piArgs[0] = "/NC";
piArgs[1] = (200 + processId).ToString();
piArgs[2] = "/MPF0";
piArgs[3] = "_N_SELECT";
PiSvc pi = new PiSvc(piArgs);
pi.Start();
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError FILES_RActiveProgramData(int processId, ref ActiveProgramDataModel programData)
{
#if false
try
{
//Setup variables
DataSvc dataSvc = new DataSvc();
// Read position and tool data
List<Item> itemRead = new List<Item>()
{
new Item($"/Channel/ProgramInfo/workPandProgName[u{processId}]"),
new Item($"/Channel/ProgramInfo/actPartProgram[u{processId}]")
};
//Read Data
dataSvc.Read(itemRead.ToArray());
// Elaborate String
string trimString = ((string)itemRead[0].Value);
trimString = trimString.Replace("_N_", "");
int lastUnderscore = trimString.LastIndexOf("_");
if (lastUnderscore >= 0)
trimString = trimString.Remove(lastUnderscore, 1).Insert(lastUnderscore, ".");
// check if is the NULL Program
if (trimString == "/MPF0")
{
programData = new ActiveProgramDataModel()
{
Path = "",
IsoLines = new List<string>(),
TimeLeft = new DateTime()
};
return NO_ERROR;
}
// Separate string into list of lines
List<string> isoLines = itemRead[1]
.Value
.ToString()
.Split('\n') // Line separator
.Skip(1) // The actPartProgram read starting with the line before the current
.ToList();
programData = new ActiveProgramDataModel()
{
Path = trimString,
IsoLines = isoLines,
TimeLeft = new DateTime()
};
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError FILES_UploadPartProgram(string localPath, string name, ref string newFilePath)
{
#if false
File.Copy(localPath + name, PART_PRG_PATH + name, true);
newFilePath = PART_PRG_PATH + name;
return NO_ERROR;
#endif
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist)
{
#if false
//Check if the NC is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
//Setup variables
FileSvc FileData = new FileSvc();
Node sourceNode = new Node(partProgramPath);
Node destNode = new Node(newPartProgramPath);
//Execute Function
FileData.Copy(sourceNode, destNode, failIfExist);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError FILES_DeleteProgram(string partProgramPath, string partProgramName)
{
#if false
//Check if the NC is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Setup variables
FileSvc FileData = new FileSvc();
Node sourceNode = new Node(partProgramPath);
//Execute Function
FileData.Delete(sourceNode);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError FILES_RProgramToFile(string partProgramPath, FileStream localFile)
{
#if false
// Check if the NC is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Setup variables
string tmpFile = Path.GetTempFileName();
FileSvc FileData = new FileSvc();
Node sourceNode = new Node(partProgramPath);
Node destNode = new Node(tmpFile);
// Execute Function
FileData.Copy(sourceNode, destNode, true);
FileStream tmpFileStream = new FileStream(tmpFile, FileMode.Open);
// Write to local file
WriteLocalFile(ReadLocalFile(tmpFileStream), ref localFile);
tmpFileStream.Close();
// Delete temporary file
File.Delete(tmpFile);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError FILES_WProgramFromFile(string partProgramPath, FileStream localFile)
{
#if false
//Check if the NC is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Setup variables
FileSvc FileData = new FileSvc();
Node sourceNode = new Node(localFile.Name);
Node destNode = new Node(partProgramPath);
//Execute Function
FileData.Copy(sourceNode, destNode, true);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
#endif
return FUNCTION_NOT_ALLOWED_ERROR;
}
@@ -4477,21 +3852,6 @@ namespace CMS_CORE_Library.S7Net
public override CmsError FILES_WUploadCustomMainProgramAndActivate(int processId, string customPartProgramContent, ref ActiveProgramDataModel activeData)
{
#if false
string customMainName = string.Format(CUSTOM_MAIN_PROGRAM, processId);
string newFilePath = "";
CmsError libraryError = FILES_UploadPartProgram(customPartProgramContent, customMainName, ref newFilePath);
if (libraryError.IsError())
return libraryError;
libraryError = FILES_WSetActiveProgram(processId, newFilePath, ref activeData);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
#endif
return FUNCTION_NOT_ALLOWED_ERROR;
}
@@ -4779,30 +4139,8 @@ namespace CMS_CORE_Library.S7Net
#region Subordinate Private Functions
#if false
// Manage the Alarms - Called automatically on changes
private void AlarmsChanged(Guid guid, Alarm[] alarms)
{
try
{
if (alarms != null)
SiemensAlarms = alarms.ToArray();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
#endif
private void NcLanguageChanged(string language)
{
#if false
SiemensAlmSvc.UnSubscribe(AlarmsChanged);
// SiemensAlmSvc.Dispose();
SiemensAlmSvc = new AlarmSvc(language);
SiemensAlmSvc.Subscribe(AlarmsChanged);
#endif
}
private int SetBitValue(int intVal, bool val, int bitIndex)
@@ -5162,8 +4500,6 @@ namespace CMS_CORE_Library.S7Net
// strobe received from PLC
internal static MEMORY_CELL REQ_CONF_STROBE = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, TABLE, 0, 2);
internal static MEMORY_CELL REQ_CONF_ACK = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, TABLE, 2, 2);
internal static MEMORY_CELL PROD_UPD_STROBE = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, TABLE, 0, 2);
internal static MEMORY_CELL PROD_UPD_ACK = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, TABLE, 2, 2);
// aree Moduli
internal static MEMORY_CELL MODULE_DATA = new MEMORY_CELL(MEMORY_TYPE.Siemens_DB, 602, 18, 2304);