1123 lines
39 KiB
C#
1123 lines
39 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.ServiceModel;
|
|
using System.ServiceModel.Description;
|
|
using CMS_CORE.Demo.Models;
|
|
using CMS_CORE_Library.Demo.Models;
|
|
using Nc_Demo_Application.Server.Service;
|
|
using CMS_CORE.Utils;
|
|
using static CMS_CORE_Library.DataStructures;
|
|
using System.Collections;
|
|
using static CMS_CORE.Nc;
|
|
|
|
namespace CMS_CORE.Demo
|
|
{
|
|
public class Nc_Demo : Nc
|
|
{
|
|
|
|
private EndpointAddress serverAddress;
|
|
private ChannelFactory<ILibraryService> cf;
|
|
private ILibraryService serverService;
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#region Contructor & global methods
|
|
|
|
public Nc_Demo(String IpAddress, ushort RemotePort)
|
|
{
|
|
Ip = IpAddress;
|
|
Port = RemotePort;
|
|
}
|
|
|
|
public override CmsError NC_Connect()
|
|
{
|
|
// Create new connection to the demo server
|
|
String url = "http://" + Ip + ":" + Port + "/api";
|
|
serverAddress = new EndpointAddress(url);
|
|
|
|
cf = new ChannelFactory<ILibraryService>(new WebHttpBinding(), serverAddress);
|
|
cf.Endpoint.EndpointBehaviors.Add(new WebHttpBehavior());
|
|
|
|
serverService = cf.CreateChannel();
|
|
string serialNumber = "";
|
|
|
|
try
|
|
{
|
|
// Get serial number from Demo server
|
|
serverService.GetSerialNumber(out serialNumber);
|
|
Connected = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError NC_Disconnect()
|
|
{
|
|
cf.Close();
|
|
Connected = false;
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
#endregion
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#region High level methods
|
|
|
|
public override CmsError NC_RDateTime(ref DateTime ActualTime)
|
|
{
|
|
//Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Get datetime from Demo server
|
|
string demoDateTime = "";
|
|
serverService.GetDateTime(out demoDateTime);
|
|
|
|
ActualTime = Convert.ToDateTime(demoDateTime);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError NC_RSerialNumber(ref String SN)
|
|
{
|
|
//Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Get serial number from Demo server
|
|
serverService.GetSerialNumber(out SN);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
//Get the NC model Name
|
|
public override CmsError NC_RModelName(ref string ModelName)
|
|
{
|
|
//Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
serverService.GetModel(out ModelName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError NC_RSoftwareVersion(ref String SWV)
|
|
{
|
|
//Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Get software version from Demo server
|
|
serverService.GetSoftwareVersion(out SWV);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError NC_RMachineNumber(ref string MachNumber)
|
|
{
|
|
//Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Get machine number from Demo server
|
|
serverService.GetMachineNumber(out MachNumber);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError NC_RProcessesNum(ref ushort ProcNumber)
|
|
{
|
|
//Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{ // Get Process Cout from Demo server
|
|
serverService.GetProcessNumber(out ProcNumber);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError NC_RLanguage(ref CultureInfo Language)
|
|
{
|
|
//Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Get language from Demo server
|
|
string demoLanguage = "";
|
|
serverService.GetLanguage(out demoLanguage);
|
|
|
|
Language = ConverToSTEPLanguage(demoLanguage);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError NC_RActiveAlarms(ref List<AlarmModel> Alarms)
|
|
{
|
|
Alarms.Clear();
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError Nc_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel)
|
|
{
|
|
try
|
|
{
|
|
int readValue = 0;
|
|
// Read pre power on and post power on data from memory
|
|
CmsError cmsError = MEM_RWInteger(R, 0, MEMORY_ADDRESS.PRE_POWER_ON.MemType, MEMORY_ADDRESS.PRE_POWER_ON.Address, ref readValue);
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
bool[] bits = new bool[32];
|
|
|
|
// Convert int into to true/false array
|
|
bits = new BitArray(new int[] { readValue }).Cast<bool>().ToArray();
|
|
// Create adn set pre power on object
|
|
PrePowerOnModel prePowerOn = new PrePowerOnModel()
|
|
{
|
|
PowerOn = new PowerOnDataModel() { Id = 0, Active = bits[0], Clickable = bits[8] }, // id = N, bits = N, Clickable = N + 8 (Second bit)
|
|
AirPressure = new PowerOnDataModel() { Id = 1, Active = bits[1], Clickable = bits[9] },
|
|
ProtectionStatus = new PowerOnDataModel() { Id = 2, Active = bits[2], Clickable = bits[10] },
|
|
EmergencyButtons = new PowerOnDataModel() { Id = 3, Active = bits[3], Clickable = bits[11] },
|
|
SettingMode = new PowerOnDataModel() { Id = 4, Active = bits[4], Clickable = bits[12] },
|
|
StartingKey = new PowerOnDataModel() { Id = 5, Active = bits[5], Clickable = bits[13] }
|
|
};
|
|
// Create and set post power on object
|
|
PostPowerOnModel postPowerOn = new PostPowerOnModel()
|
|
{
|
|
AxisReset = new PowerOnDataModel() { Id = 8, Active = bits[16], Clickable = bits[24] }, // id = N - 8, bits = N, Clickable = N + 8 (Second bit)
|
|
WaterjetPump = new PowerOnDataModel() { Id = 9, Active = bits[17], Clickable = bits[25] }
|
|
};
|
|
|
|
powerOnModel = new PreAndPostPowerOnModel()
|
|
{
|
|
postPowerOn = postPowerOn,
|
|
prePowerOn = prePowerOn
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError Nc_WPowerOnData(uint id, bool value)
|
|
{
|
|
try
|
|
{
|
|
CmsError cmsError;
|
|
// Check bit range
|
|
if (id > 16)
|
|
return INCORRECT_PARAMETERS_ERROR;
|
|
// Choose Pre-Power-On or Post-Power-Om
|
|
if (id <= 8)
|
|
// Pre: memory bit = id
|
|
cmsError = MEM_RWBoolean(W, 0, MEMORY_ADDRESS.PRE_POWER_ON_CLICKED.MemType, MEMORY_ADDRESS.PRE_POWER_ON_CLICKED.Address, (int)id, ref value);
|
|
else
|
|
// Post: memory bit = id - 8
|
|
cmsError = MEM_RWBoolean(W, 0, MEMORY_ADDRESS.POST_POWER_ON_CLICKED.MemType, MEMORY_ADDRESS.POST_POWER_ON_CLICKED.Address, (int)id - 8, ref value);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
return NO_ERROR;
|
|
}
|
|
#endregion
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#region PLC High-level data
|
|
|
|
public override CmsError PLC_RActiveMessages(ref List<AlarmModel> alarms)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
alarms.Clear();
|
|
|
|
List<NcAlarmModel> demoAlarms;
|
|
// Get Alarms from server
|
|
serverService.GetProcessesAlarms(out demoAlarms);
|
|
// Parse response
|
|
foreach (NcAlarmModel demoAlarm in demoAlarms)
|
|
{
|
|
AddAlarmToList((uint)demoAlarm.code, demoAlarm.text, alarms);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
#endregion
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#region PROCESS (PATH) High-level data
|
|
|
|
public override CmsError PROC_RStatus(ushort ProcNumber, ref PROC_Status Status)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Get status from server
|
|
serverService.GetProcessStatus(ProcNumber.ToString(), out int demoStatus);
|
|
|
|
Status = (PROC_Status)demoStatus;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError PROC_RMode(ushort ProcNumber, ref PROC_Mode Mode)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Get mode from server
|
|
serverService.GetProcessMode(ProcNumber.ToString(), out int demoMode);
|
|
|
|
Mode = (PROC_Mode)demoMode;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError PROC_RActiveAlarms(ushort ProcNumber, ref List<AlarmModel> alarms)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
alarms.Clear();
|
|
serverService.GetProcessAlarms(ProcNumber.ToString(), out List<NcAlarmModel> demoAlarms);
|
|
|
|
// Parse response
|
|
foreach (NcAlarmModel demoAlarm in demoAlarms)
|
|
{
|
|
AddAlarmToList((uint)demoAlarm.code, demoAlarm.text, demoAlarm.processId, alarms);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError PROC_RPPLines(ushort ProcNumber, ref List<string> Lines)
|
|
{
|
|
return FUNCTION_NOT_ALLOWED_ERROR;
|
|
}
|
|
|
|
#endregion
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#region PROCESS-AXES (PATH) High-level data
|
|
|
|
public override CmsError AXES_RInterpPosition(ushort ProcNumber, ref Dictionary<string, double> Axes)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Get axes position from Demo Server
|
|
serverService.GetAxesPosition(ProcNumber.ToString(), out List<NcAxisModel> demoAxes);
|
|
|
|
// Parse server response
|
|
foreach (NcAxisModel demoAxis in demoAxes)
|
|
{
|
|
Axes.Add(demoAxis.name, demoAxis.actual);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError AXES_RProgrPosition(ushort ProcNumber, ref Dictionary<string, double> Axes)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Get Axes Position from server
|
|
serverService.GetAxesPosition(ProcNumber.ToString(), out List<NcAxisModel> demoAxes);
|
|
// Parse server response and get programmed position
|
|
foreach (NcAxisModel demoAxis in demoAxes)
|
|
{
|
|
Axes.Add(demoAxis.name, demoAxis.programmed);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError AXES_RMachinePosition(ushort ProcNumber, ref Dictionary<string, double> Axes)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
try
|
|
{
|
|
// Get Axes Position from server
|
|
serverService.GetAxesPosition(ProcNumber.ToString(), out List<NcAxisModel> demoAxes);
|
|
|
|
// Parse Server response and get machine position
|
|
foreach (NcAxisModel demoAxis in demoAxes)
|
|
{
|
|
Axes.Add(demoAxis.name, demoAxis.machinePosition);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError AXES_RFollowingError(ushort ProcNumber, ref Dictionary<string, double> Axes)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Get Axes position from Demo server
|
|
serverService.GetAxesPosition(ProcNumber.ToString(), out List<NcAxisModel> demoAxes);
|
|
// Parse response get distance to go
|
|
foreach (NcAxisModel demoAxis in demoAxes)
|
|
{
|
|
Axes.Add(demoAxis.name, demoAxis.distanceToGo);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError AXES_RDistanceToGo(ushort ProcNumber, ref Dictionary<string, double> Axes)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
serverService.GetAxesPosition(ProcNumber.ToString(), out List<NcAxisModel> demoAxes);
|
|
// Parse response get distance to go
|
|
foreach (NcAxisModel demoAxis in demoAxes)
|
|
{
|
|
Axes.Add(demoAxis.name, demoAxis.distanceToGo);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
#endregion
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#region NC Low-level function: single valiable in memory
|
|
|
|
public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemBit, ref bool Value)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
cmsError = CheckBitRange(MemBit);
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Read case: Read bit
|
|
if (bWrite == R)
|
|
{
|
|
serverService.GetBoolean(MemIndex.ToString(), MemBit.ToString(), out Value);
|
|
}
|
|
// Write case: write bit
|
|
else
|
|
{
|
|
BinaryMemoryModel binaryMemoryModel = new BinaryMemoryModel();
|
|
binaryMemoryModel.boolean = Value;
|
|
serverService.PutBoolean(MemIndex.ToString(), MemBit.ToString(), binaryMemoryModel);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemByte, ref byte Value)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Read case
|
|
if (bWrite == R)
|
|
{
|
|
serverService.GetByte(MemIndex.ToString(), out Value);
|
|
}
|
|
else // Write case
|
|
{
|
|
BinaryMemoryModel binaryMemoryModel = new BinaryMemoryModel();
|
|
binaryMemoryModel.binary = Value;
|
|
serverService.PutByte(MemIndex.ToString(), binaryMemoryModel);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref ushort Value)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Read case
|
|
if (bWrite == R)
|
|
{
|
|
serverService.GetWord(MemIndex.ToString(), out Value);
|
|
}
|
|
else // Write case
|
|
{
|
|
BinaryMemoryModel binaryMemoryModel = new BinaryMemoryModel();
|
|
binaryMemoryModel.uWord = Value;
|
|
serverService.PutWord(MemIndex.ToString(), binaryMemoryModel);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref short Value)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Read case
|
|
if (bWrite == R)
|
|
{
|
|
serverService.GetShort(MemIndex.ToString(), out Value);
|
|
}
|
|
else // Write case
|
|
{
|
|
BinaryMemoryModel binaryMemoryModel = new BinaryMemoryModel();
|
|
binaryMemoryModel.word = Value;
|
|
serverService.PutShort(MemIndex.ToString(), binaryMemoryModel);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref uint Value)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Read case
|
|
if (bWrite == R)
|
|
{
|
|
serverService.GetDWord(MemIndex.ToString(), out Value);
|
|
}
|
|
else // Write case
|
|
{
|
|
BinaryMemoryModel binaryMemoryModel = new BinaryMemoryModel();
|
|
binaryMemoryModel.dWord = Value;
|
|
serverService.PutDWord(MemIndex.ToString(), binaryMemoryModel);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, ref int Value)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Read case
|
|
if (bWrite == R)
|
|
{
|
|
serverService.GetInteger(MemIndex.ToString(), out Value);
|
|
}
|
|
else // Write case
|
|
{
|
|
BinaryMemoryModel binaryMemoryModel = new BinaryMemoryModel();
|
|
binaryMemoryModel.integer = Value;
|
|
serverService.PutInteger(MemIndex.ToString(), binaryMemoryModel);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------------------------------
|
|
// Siemens Version of Memory-Access Methods
|
|
|
|
public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemBit, ref bool Value)
|
|
{
|
|
return MEM_RWBoolean(bWrite, Process, MemType, MemIndex, MemBit, ref Value);
|
|
}
|
|
public override CmsError MEM_RWByte(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemByte, ref byte Value)
|
|
{
|
|
return MEM_RWByte(bWrite, Process, MemType, MemIndex, MemByte, ref Value);
|
|
}
|
|
|
|
public override CmsError MEM_RWWord(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref ushort Value)
|
|
{
|
|
return MEM_RWWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value);
|
|
}
|
|
|
|
public override CmsError MEM_RWShort(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref short Value)
|
|
{
|
|
return MEM_RWShort(bWrite, Process, MemType, MemIndex, MemIndex, ref Value);
|
|
}
|
|
|
|
public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref uint Value)
|
|
{
|
|
return MEM_RWDWord(bWrite, Process, MemType, MemIndex, MemIndex, ref Value);
|
|
}
|
|
|
|
public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, ref int Value)
|
|
{
|
|
return MEM_RWInteger(bWrite, Process, MemType, MemIndex, MemIndex, ref Value);
|
|
}
|
|
|
|
public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int MemByteStart, int Number, ref List<byte> Value)
|
|
{
|
|
return MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByteStart, Number, ref Value);
|
|
}
|
|
|
|
public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List<ushort> Value)
|
|
{
|
|
return MEM_RWWordList(bWrite, Process, MemType, MemIndex, Number, ref Value);
|
|
}
|
|
|
|
public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List<short> Value)
|
|
{
|
|
return MEM_RWShortList(bWrite, Process, MemType, MemIndex, Number, ref Value);
|
|
}
|
|
|
|
public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List<uint> Value)
|
|
{
|
|
return MEM_RWDWordList(bWrite, Process, MemType, MemIndex, Number, ref Value);
|
|
}
|
|
|
|
public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_Type MemType, int MemTable, int MemIndex, int Number, ref List<int> Value)
|
|
{
|
|
return MEM_RWIntegerList(bWrite, Process, MemType, MemIndex, Number, ref Value);
|
|
}
|
|
|
|
#endregion
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#region NC Low-level function: variables List in memory
|
|
|
|
public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int MemByteStart, int Number, ref List<byte> Value)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Read case
|
|
if (bWrite == R)
|
|
{
|
|
serverService.GetByteList(MemIndex.ToString(), Number.ToString(), out Value);
|
|
}
|
|
else // Write case
|
|
{
|
|
BinaryMemoryModel binaryMemoryModel = new BinaryMemoryModel();
|
|
binaryMemoryModel.byteList = Value;
|
|
serverService.PutByteList(MemIndex.ToString(), binaryMemoryModel);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError MEM_RWWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List<ushort> Value)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Read case
|
|
if (bWrite == R)
|
|
{
|
|
serverService.GetWordList(MemIndex.ToString(), Number.ToString(), out Value);
|
|
}
|
|
else // Write case
|
|
{
|
|
BinaryMemoryModel binaryMemoryModel = new BinaryMemoryModel();
|
|
binaryMemoryModel.wordList = Value;
|
|
serverService.PutWordList(MemIndex.ToString(), binaryMemoryModel);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError MEM_RWShortList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List<short> Value)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Read case
|
|
if (bWrite == R)
|
|
{
|
|
serverService.GetShortList(MemIndex.ToString(), Number.ToString(), out Value);
|
|
}
|
|
else // Write case
|
|
{
|
|
BinaryMemoryModel binaryMemoryModel = new BinaryMemoryModel();
|
|
binaryMemoryModel.shortList = Value;
|
|
serverService.PutShortList(MemIndex.ToString(), binaryMemoryModel);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List<int> Value)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Read case
|
|
if (bWrite == R)
|
|
{
|
|
serverService.GetIntegerList(MemIndex.ToString(), Number.ToString(), out Value);
|
|
}
|
|
else // Write case
|
|
{
|
|
BinaryMemoryModel binaryMemoryModel = new BinaryMemoryModel();
|
|
binaryMemoryModel.integerList = Value;
|
|
serverService.PutIntegerList(MemIndex.ToString(), binaryMemoryModel);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError MEM_RWDWordList(bool bWrite, int Process, MEMORY_Type MemType, int MemIndex, int Number, ref List<uint> Value)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
// Read case
|
|
if (bWrite == R)
|
|
{
|
|
serverService.GetDWordList(MemIndex.ToString(), Number.ToString(), out Value);
|
|
}
|
|
else // Write case
|
|
{
|
|
BinaryMemoryModel binaryMemoryModel = new BinaryMemoryModel();
|
|
binaryMemoryModel.dWordList = Value;
|
|
serverService.PutDWordList(MemIndex.ToString(), binaryMemoryModel);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
#endregion
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#region NC Low-level function: Parameters
|
|
|
|
|
|
public override CmsError NC_RParam(short Index, short Bit, ref bool Value)
|
|
{
|
|
return FUNCTION_NOT_ALLOWED_ERROR;
|
|
}
|
|
|
|
public override CmsError NC_RParam(short Index, ref byte Value)
|
|
{
|
|
return FUNCTION_NOT_ALLOWED_ERROR;
|
|
}
|
|
|
|
public override CmsError NC_RParam(short Index, ref short Value)
|
|
{
|
|
return FUNCTION_NOT_ALLOWED_ERROR;
|
|
}
|
|
|
|
public override CmsError NC_RParam(short Index, ref int Value)
|
|
{
|
|
return FUNCTION_NOT_ALLOWED_ERROR;
|
|
}
|
|
|
|
public override CmsError NC_RParam(short Index, ref double Value)
|
|
{
|
|
return FUNCTION_NOT_ALLOWED_ERROR;
|
|
}
|
|
#endregion
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#region File Management
|
|
|
|
public override CmsError FILES_RProgramToFile(string partProgramPath, FileStream localFile)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
serverService.GetFile(partProgramPath, out string fileContent);
|
|
Nc_Utils.WriteLocalFile(fileContent, ref localFile);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError FILES_WProgramFromFile(string partProgramPath, FileStream localFile)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
FileModel fileData = new FileModel
|
|
{
|
|
fileContent = Nc_Utils.ReadLocalFile(localFile),
|
|
destFileName = partProgramPath
|
|
};
|
|
serverService.PostFile(fileData);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError FILES_CopyProgram(string partProgramPath, string newPartProgramPath, bool failIfExist)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
FileModel fileData = new FileModel
|
|
{
|
|
sourceFileName = partProgramPath,
|
|
destFileName = newPartProgramPath,
|
|
failIfExist = failIfExist
|
|
};
|
|
serverService.CopyFile(fileData);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError FILES_DeleteProgram(string partProgramPath, string partProgramName)
|
|
{
|
|
// Check if the NC Demo is Connected
|
|
CmsError cmsError = CheckConnection();
|
|
if (cmsError.IsError())
|
|
return cmsError;
|
|
|
|
try
|
|
{
|
|
serverService.DeleteFile(partProgramName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return ManageException(ex);
|
|
}
|
|
|
|
return NO_ERROR;
|
|
}
|
|
#endregion
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
#region Subordinate Private Functions
|
|
|
|
//Check if NC is connected
|
|
private CmsError CheckConnection()
|
|
{
|
|
if (!NC_IsConnected())
|
|
return NOT_CONNECTED_ERROR;
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
//Manage the Languages
|
|
private CultureInfo ConverToSTEPLanguage(String Lang)
|
|
{
|
|
CultureInfo Culture = CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(X => X.EnglishName.ToLower() == Lang.ToLower());
|
|
|
|
if (Culture != null)
|
|
return Culture;
|
|
else
|
|
return new CultureInfo("en");
|
|
}
|
|
|
|
//Manage the Exception Launch
|
|
private CmsError ManageException(Exception ex)
|
|
{
|
|
Connected = false;
|
|
|
|
//Catch the .Net exceptions
|
|
if (ex is EndpointNotFoundException)
|
|
return NOT_CONNECTED_ERROR;
|
|
else
|
|
return CmsError.InternalError(ex.Message);
|
|
}
|
|
|
|
//Check Bit In Range
|
|
private CmsError CheckBitRange(int bitnum)
|
|
{
|
|
if (bitnum < 0 || bitnum > 7)
|
|
return BIT_NOT_IN_RANGE_ERROR;
|
|
|
|
return NO_ERROR;
|
|
}
|
|
|
|
public override CmsError PROC_RPPName(ushort ProcNumber, ref string Name)
|
|
{
|
|
return FUNCTION_NOT_ALLOWED_ERROR;
|
|
}
|
|
|
|
// Create and return CmsError object
|
|
private CmsError GetNcError(string message)
|
|
{
|
|
return CmsError.NcError(message);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
internal static class MEMORY_ADDRESS
|
|
{
|
|
internal const int STARTING_ADDRESS = 0;
|
|
|
|
internal static MEMORY_CELL PRE_POWER_ON = new MEMORY_CELL(MEMORY_Type.Demo, 13, 0, 1);
|
|
internal static MEMORY_CELL PRE_POWER_ON_CLICKABLE = new MEMORY_CELL(MEMORY_Type.Demo, 14, 0, 1);
|
|
|
|
internal static MEMORY_CELL POST_POWER_ON = new MEMORY_CELL(MEMORY_Type.Demo, 15, 0, 1);
|
|
internal static MEMORY_CELL POST_POWER_ON_CLICKABLE = new MEMORY_CELL(MEMORY_Type.Demo, 16, 0, 1);
|
|
|
|
internal static MEMORY_CELL PRE_POWER_ON_CLICKED = new MEMORY_CELL(MEMORY_Type.Demo, 17, 0, 1);
|
|
internal static MEMORY_CELL POST_POWER_ON_CLICKED = new MEMORY_CELL(MEMORY_Type.Demo, 18, 0, 1);
|
|
}
|
|
}
|