Files
2021-02-04 09:03:00 +01:00

3770 lines
135 KiB
C#

using CMS_CORE_Library.Demo.Models;
using CMS_CORE_Library.Models;
using CMS_CORE_Library.Utils;
using Nc_Demo_Application.Server.Service;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Threading;
using static CMS_CORE_Library.Demo.MEMORY_ADDRESS;
using static CMS_CORE_Library.Models.DataStructures;
using static CMS_CORE_Library.Nc;
using static CMS_CORE_Library.ToolConfigurations;
using static CMS_CORE_Library.Utils.Nc_Utils;
namespace CMS_CORE_Library.Demo
{
public class Nc_Demo : Nc
{
private EndpointAddress serverAddress;
private ChannelFactory<ILibraryService> cf;
private ILibraryService serverService;
private DemoEdgesConfiguration DemoEdgesConfiguration = new DemoEdgesConfiguration();
private const string PART_PROGRAM_FOLDER = "C:/CMS/Active/DEMO/part_program/";
private const string JOB_PROGRAM_FOLDER = PART_PROGRAM_FOLDER + "\\job\\";
private Random rand = new Random();
// Magazine config parameters
private List<SiemensMagazineConfigModel> MagazineConfig = new List<SiemensMagazineConfigModel>()
{
new SiemensMagazineConfigModel{Id = 1, Type = SIEMENS_MAGAZINE_TYPE.BOX_MAGAZINE, LoadingIsActive = true, Name = "MAG1", MaxPositions = 8},
new SiemensMagazineConfigModel{Id = 2, Type = SIEMENS_MAGAZINE_TYPE.CHAIN, LoadingIsActive = true, Name = "MAG2", MaxPositions = 10},
new SiemensMagazineConfigModel{Id = 3, Type = SIEMENS_MAGAZINE_TYPE.INVISIBLE_MAGAZINE, LoadingIsActive = true, Name = "MAG3", MaxPositions = 10},
};
////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
#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()
{
MaxBufferPoolSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue
}, 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()
{
if (cf != null)
cf.Close();
Connected = false;
return NO_ERROR;
}
public override CmsError NC_GetTranslatedPlcMessages(string language, ref Dictionary<int, string> messages)
{
try
{
NC_Connect();
messages = new Dictionary<int, string>();
serverService.GetTranslations(language, out messages);
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError NC_GetAvailableLanguages(ref ICollection<CultureInfo> languages)
{
languages.Add(new CultureInfo("en"));
languages.Add(new CultureInfo("it"));
languages.Add(new CultureInfo("fr"));
languages.Add(new CultureInfo("de"));
return NO_ERROR;
}
#endregion Contructor & global methods
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region High level methods
public override CmsError NC_RDateTime(ref DateTime ActualTime)
{
//Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
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(bool hasLetters, ref string MachNumber)
{
//Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
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_WLanguage(CultureInfo Language)
{
return NO_ERROR;
}
public override CmsError NC_RActiveAlarms(ref List<AlarmModel> alarms)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
alarms.Clear();
List<NcAlarmModel> demoAlarms;
// Get Alarms from server
serverService.NcAlarms(out demoAlarms);
// Parse response
foreach (NcAlarmModel demoAlarm in demoAlarms)
{
AddNcAlarmToList((uint)demoAlarm.code, demoAlarm.text, DateTime.Now, alarms);
}
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
// Check if the NC is in running state
public override CmsError NC_RIsRunning(ref bool running)
{
ushort nProcess = 0;
// Get the number of processes
CmsError libraryError = NC_RProcessesNum(ref nProcess);
if (libraryError.IsError())
return libraryError;
ushort i = 1;
running = false;
do
{
PROC_STATUS procStatus = PROC_STATUS.IDLE;
// Read process status
libraryError = PROC_RStatus(i, ref procStatus);
if (libraryError.IsError())
return libraryError;
// If one process is runninc, nc is running
if (procStatus == PROC_STATUS.RUN)
running = true;
i++;
} while (!running || i <= nProcess);
return NO_ERROR;
}
public override CmsError NC_SetScreenVisible(SCREEN_PAGE screen)
{
return NO_ERROR;
}
// Get NC unit of measure
public override CmsError NC_RUnitOfMeasure(ref string unitOfMeasure)
{
byte val = 0;
CmsError libraryError = MEM_RWByte(R, 0, UNIT_OF_MEASURE.MemType, UNIT_OF_MEASURE.Address, 0, ref val);
if (libraryError.IsError())
return libraryError;
if (val == 0)
unitOfMeasure = MILLIMETERS;
else
unitOfMeasure = INCHES;
return NO_ERROR;
}
public override CmsError NC_WMDICommand(int processId, string mdiString)
{
return NO_ERROR;
}
#endregion High level methods
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region PLC High-level data
public override CmsError PLC_RWManageWatchdog()
{
bool plcWatchdog = false;
CmsError libraryError = MEM_RWBoolean(R, 0, NC_WATCHDOG.MemType, NC_WATCHDOG.Address, 0, ref plcWatchdog);
if (libraryError.IsError())
return libraryError;
if (plcWatchdog)
return PLC_NOT_RUNNING_ERROR;
plcWatchdog = true;
return MEM_RWBoolean(W, 0, NC_WATCHDOG.MemType, NC_WATCHDOG.Address, 0, ref plcWatchdog);
}
public override CmsError PLC_RActiveMessages(ref List<PlcAlarmModel> alarms)
{
alarms.Clear();
List<int> readValues = new List<int>();
// Read on data from memory
CmsError libraryError = MEM_RWIntegerList(R, 0,
ALARMS_STATUS.MemType,
ALARMS_STATUS.Address,
(ALARMS_STATUS.Size + ALARMS_DATA.Size) / 4,
ref readValues);
if (libraryError.IsError())
return libraryError;
// Convert integer array into bit array
bool[] statusBits = new BitArray(readValues.ToArray()).Cast<bool>().ToArray();
for (int i = 0; i < ALARMS_STATUS.Size * 8; i++)
{
// If alarm is active
if (statusBits[i])
{
// Calculate matching alarm byte info address
int dataByteAddress = i * 8 + (ALARMS_STATUS.Size * 8);
var processList = new List<int>();
// Get processes on which alarm is active
for (int j = dataByteAddress; j < dataByteAddress + 6; j++)
{
if (statusBits[j])
processList.Add(j + 1 - dataByteAddress);
}
// Add alarm info into active alarms list
alarms.Add(new PlcAlarmModel()
{
Id = (uint)i + 1,
IsWarning = statusBits[dataByteAddress + 7],
RestorationIsActive = statusBits[dataByteAddress + 6],
Process = processList
});
}
}
return NO_ERROR;
}
public override CmsError PLC_WRefreshMessage(uint id)
{
// Check id range
if (id > ALARMS_NUMBER)
return INCORRECT_PARAMETERS_ERROR;
CmsError libraryError;
bool readValue = false;
bool writeValue = true;
int ackByte = ALARM_ACK.Address + (((int)id - 1) / 8);
int strobeByte = ALARM_REFRESH_STROBE.Address + (((int)id - 1) / 8);
int alarmBitId = (((int)id - 1) % 8);
// Check ACK
libraryError = MEM_RWBoolean(R, 0, ALARM_ACK.MemType, ackByte, alarmBitId, ref readValue);
if (libraryError.IsError())
return libraryError;
// If PLC it's performing another request then return
if (readValue)
return NO_ERROR;
// Write data
libraryError = MEM_RWBoolean(W, 0, ALARM_REFRESH_STROBE.MemType, strobeByte, alarmBitId, ref writeValue);
if (libraryError.IsError())
return libraryError;
// Reset wait ack = 1 and reset the strobe
libraryError = ResetStrobe(alarmBitId, strobeByte, ackByte, ALARM_REFRESH_STROBE.MemType);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_WRestoreMessage(uint id)
{
// Call restore message
CmsError libraryError = PLC_WRefreshMessage(id);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_WRefreshAllMessages()
{
int numberOfInteger = (32 / 8) / 4;
List<uint> defaultValue = Enumerable.Repeat(uint.MaxValue, numberOfInteger).ToList();
CmsError libraryError = MEM_RWDWordList(W, 0, ALARM_REFRESH_STROBE.MemType, ALARM_REFRESH_STROBE.Address, numberOfInteger, ref defaultValue);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel)
{
int readValue = 0;
// Read pre power on and post power on data from memory
CmsError libraryError = MEM_RWInteger(R, 0, PRE_POWER_ON.MemType, PRE_POWER_ON.Address, ref readValue);
if (libraryError.IsError())
return libraryError;
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] },
BarriersNotOk = new PowerOnDataModel() { Id = 7, Active = bits[6], Clickable = bits[14] }
};
// 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
};
return NO_ERROR;
}
public override CmsError PLC_WPowerOnData(uint id, bool value)
{
CmsError libraryError;
// 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
libraryError = MEM_RWBoolean(W, 0, PRE_POWER_ON_CLICKED.MemType, PRE_POWER_ON_CLICKED.Address, (int)id, ref value);
else
// Post: memory bit = id - 8
libraryError = MEM_RWBoolean(W, 0, POST_POWER_ON_CLICKED.MemType, POST_POWER_ON_CLICKED.Address, (int)id - 8, ref value);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_RFunctionAccess(ref List<FunctionalityModel> functions)
{
List<int> readValues = new List<int>();
// Read functions access data from memory
CmsError libraryError = MEM_RWIntegerList(R, 0, FUNCTION_ACCESS.MemType, FUNCTION_ACCESS.Address, 4, ref readValues);
if (libraryError.IsError())
return libraryError;
functions = new List<FunctionalityModel>();
// Convert int into to true/false array
bool[] bits = new BitArray(readValues.ToArray()).Cast<bool>().ToArray();
// Convert array into structured data
for (int i = 0; i < bits.Count(); i++)
{
functions.Add(new FunctionalityModel()
{
Id = (uint)i,
IsActive = bits[i]
});
}
return NO_ERROR;
}
public override CmsError PLC_RAxesResetData(ref AxisResetDataModel axisResetData)
{
byte value = 0;
// Read byte from memory
CmsError libraryError = MEM_RWByte(R, 0, AXIS_RESET_PROCEDURE.MemType, AXIS_RESET_PROCEDURE.Address, 1, ref value);
if (libraryError.IsError())
return libraryError;
// Check last bit
if ((value & 128) == 128)
{
// Set to 0 last bit and 7 bit percentage and check if is higher than 100
byte percentage = value - 128 > 100 ? (byte)100 : (byte)(value - 128);
axisResetData = new AxisResetDataModel()
{
IsActive = true,
Percentage = percentage
};
}
return NO_ERROR;
}
public override CmsError PLC_RMachineCounters(ref List<CounterModel> counters)
{
counters = new List<CounterModel>();
List<int> readValues = new List<int>();
// Read on data from memory
CmsError libraryError = MEM_RWIntegerList(R, 0, COUNTERS.MemType, COUNTERS.Address, COUNTERS.Size / 4, ref readValues);
if (libraryError.IsError())
return libraryError;
// Foreach counters
for (int i = 0; i < readValues.Count; i++)
{
// Add counters value into returned value
counters.Add(new CounterModel()
{
Id = (uint)i,
Value = (uint)readValues[i]
});
}
return NO_ERROR;
}
public override CmsError PLC_WResetMachineCounters(uint counter)
{
throw new NotImplementedException();
}
public override CmsError PLC_RNcSoftKeys(ref List<SoftKeysModel> ncSoftKeys)
{
CmsError libraryError = PLC_RSoftKeys(NC_SOFTKEYS_VALUE, NC_SOFTKEYS_CLICKABLE, ref ncSoftKeys);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_RUserSoftKeys(ref List<SoftKeysModel> softKeys)
{
CmsError libraryError = PLC_RSoftKeys(USER_SOFTKEYS_VALUE, USER_SOFTKEYS_CLICKABLE, ref softKeys);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_WNcSoftKey(uint id)
{
// Check id range
if (id > NC_SOFTKEYS_NUMBER)
return INCORRECT_PARAMETERS_ERROR;
CmsError libraryError;
bool readValue = false;
bool writeValue = true;
int ackByte = NC_SOFT_KEYS_ACK.Address + (((int)id - 1) / 8);
int strobeByte = NC_SOFT_KEYS_CLICKED.Address + (((int)id - 1) / 8);
int softkeyBitId = (((int)id - 1) % 8);
// Check ACK
libraryError = MEM_RWBoolean(R, 0, NC_SOFT_KEYS_ACK.MemType, ackByte, softkeyBitId, ref readValue);
if (libraryError.IsError())
return libraryError;
// If PLC it's performing another request then return
if (readValue)
return NO_ERROR;
// Write data
libraryError = MEM_RWBoolean(W, 0, NC_SOFT_KEYS_CLICKED.MemType, strobeByte, softkeyBitId, ref writeValue);
if (libraryError.IsError())
return libraryError;
// Reset wait ack = 1 and reset the strobe
libraryError = ResetStrobe(softkeyBitId, strobeByte, ackByte, NC_SOFT_KEYS_CLICKED.MemType);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_WUserSoftKey(uint id)
{
// Check id range
if (id > USER_SOFTKEYS_NUMBER)
return INCORRECT_PARAMETERS_ERROR;
CmsError libraryError;
bool readValue = false;
bool writeValue = true;
int ackByte = USER_SOFT_KEYS_ACK.Address + (((int)id - 1) / 8);
int strobeByte = USER_SOFT_KEYS_CLICKED.Address + (((int)id - 1) / 8);
int softkeyBitId = (((int)id - 1) % 8);
// Check ACK
libraryError = MEM_RWBoolean(R, 0, USER_SOFT_KEYS_ACK.MemType, ackByte, softkeyBitId, ref readValue);
if (libraryError.IsError())
return libraryError;
// If PLC it's performing another request then return
if (readValue)
return NO_ERROR;
// Write data
libraryError = MEM_RWBoolean(W, 0, USER_SOFT_KEYS_CLICKED.MemType, strobeByte, softkeyBitId, ref writeValue);
if (libraryError.IsError())
return libraryError;
// Reset wait ack = 1 and reset the strobe
libraryError = ResetStrobe(softkeyBitId, strobeByte, ackByte, USER_SOFT_KEYS_CLICKED.MemType);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_RHeadsData(List<HeadDataModel> heads, int number)
{
// Check parameters
if (number > 20)
return INCORRECT_PARAMETERS_ERROR;
heads.Clear();
List<int> readInts = new List<int>();
List<byte> readValues = new List<byte>();
List<uint> readHours = new List<uint>();
// Find the size of a single head
int headsByte = (HEADS_DATA.Size / MAX_HEADS_NUMBER);
double headsInts = Math.Ceiling((double)(headsByte / 4) + 1);
// Read data for N heads
CmsError libraryError = MEM_RWIntegerList(R, 0, HEADS_DATA.MemType, 0, HEADS_DATA.Address, (int)headsInts * number, ref readInts);
if (libraryError.IsError())
return libraryError;
readValues = readInts.SelectMany(BitConverter.GetBytes).ToList();
// Read Worked time heads
libraryError = MEM_RWDWordList(R, 0, HEADS_WORKED_TIMES.MemType, HEADS_WORKED_TIMES.Address, number, ref readHours);
if (libraryError.IsError())
return libraryError;
// Parse and format read data
for (int i = 0; i < number; i++)
{
// Head address = posizion * size of single head in memory
var headOffset = i * headsByte;
heads.Add(new HeadDataModel()
{
Id = (uint)i + 1,
Process = readValues[headOffset],
Override = readValues[headOffset + 1],
Param3 = BitConverter.ToInt16(readValues.ToArray(), headOffset + 2), // Uint16 = 2 byte
Param1 = BitConverter.ToInt32(readValues.ToArray(), headOffset + 4), // Int32 = 4byte
Param2 = BitConverter.ToInt16(readValues.ToArray(), headOffset + 8), // Uint 16 = 2byte
IsActive = (readValues[headOffset + 10] & 1) != 0, // bit 0
IsSelected = (readValues[headOffset + 10] & 2) != 0, // bit 1
OverrideEditable = (readValues[headOffset + 10] & 4) != 0, // bit 2
AbrasiveIsActive = (readValues[headOffset + 10] & 8) != 0, // bit 3
Configured = (readValues[headOffset + 10] & 8) != 0, // bit 3
Rotation = (readValues[headOffset + 10] & 16) == 0 ? ROTATION.CLOCKWHISE : ROTATION.COUNTERCLOCKWHISE, // bit 4
WorkedTime = readHours[i]
});
}
return NO_ERROR;
}
public override CmsError PLC_RWorkedTimeHead(int head, ref uint time)
{
int index = (head - 1) * 4;
// Read Worked time
CmsError libraryError = MEM_RWDWord(R, 0, HEADS_WORKED_TIMES.MemType, HEADS_WORKED_TIMES.Address + index, ref time);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_WResetWorkedTimeHead(int head)
{
int index = (head - 1) * 4;
uint time = 0;
if (head <= 0 || head > MAX_HEADS_NUMBER)
return INCORRECT_PARAMETERS_ERROR;
// Read Worked time
CmsError libraryError = MEM_RWDWord(W, 0, HEADS_WORKED_TIMES.MemType, HEADS_WORKED_TIMES.Address + index, ref time);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_RWorkedTimeMachine(ref uint time)
{
// Read Worked time -> ipotizzo sia il contatore 0
CmsError libraryError = MEM_RWDWord(R, 0, COUNTERS.MemType, COUNTERS.Address, ref time);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_WResetWorkedTimeMachine(uint time)
{
// Write Worked time -> ipotizzo sia il contatore 0
CmsError libraryError = MEM_RWDWord(W, 0, COUNTERS.MemType, COUNTERS.Address, ref time);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_WHeadOverride(uint id, HEAD_OVERRIDE_SIGN sign)
{
if (id > MAX_HEADS_NUMBER)
return INCORRECT_PARAMETERS_ERROR;
CmsError libraryError;
bool readValue = false;
bool writeValue = true;
MEMORY_CELL currentStrobeCell = sign == HEAD_OVERRIDE_SIGN.PLUS ? HEADS_STROBE_INCREMENT : HEADS_STROBE_DECREMENT;
int ackByte = HEADS_ACK.Address + (((int)id - 1) / 8);
int strobeByte = currentStrobeCell.Address + (((int)id - 1) / 8);
int headBit = (((int)id - 1) % 8);
// Check ACK
libraryError = MEM_RWBoolean(R, 0, HEADS_ACK.MemType, ackByte, headBit, ref readValue);
if (libraryError.IsError())
return libraryError;
// If PLC it's performing another request then return
if (readValue)
return NO_ERROR;
// Write strobe data
libraryError = MEM_RWBoolean(W, 0, currentStrobeCell.MemType, strobeByte, headBit, ref writeValue);
if (libraryError.IsError())
return libraryError;
// Reset wait ack = 1 and reset the strobe
libraryError = ResetStrobe(headBit, strobeByte, ackByte, currentStrobeCell.MemType);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_ROperatorInputIsNeeded(ref List<M155InputIsNeededModel> value)
{
byte val = 0;
CmsError libraryError = MEM_RWByte(R, 0, OPERATOR_INPUT_NEEDED.MemType, OPERATOR_INPUT_NEEDED.Address, 0, ref val);
if (libraryError.IsError())
return libraryError;
bool[] bits = ByteToBits(val);
for (uint i = 0; i < 6; i++)
{
if (bits[i])
{
value.Add(new M155InputIsNeededModel()
{
Process = i + 1,
IsNeeded = true,
Buttons = new Dictionary<byte, string>()
{
{ 1, "bottoneDiTest3" },
{ 2, "bottoneDiTest2" },
{ 3, "bottoneDiTest3" }
},
Message = "Messaggio di test",
Type = bits[6] == false ? M155_TYPE.REAL : M155_TYPE.MULTIPLE_BUTTONS
});
}
}
return NO_ERROR;
}
public override CmsError PLC_WOperatorInputResponse(int process, double responseVal)
{
byte approxymatedVal = Convert.ToByte(responseVal >= 255 ? 255 : responseVal);
int procAddress = OPERATOR_INPUT_RESPONSE.Address + process - 1;
return MEM_RWByte(W, 0, MEMORY_TYPE.Demo, procAddress, 0, ref approxymatedVal);
}
public override CmsError PLC_RM154Data(ref List<M154DataModel> data, ref bool MTCOnOff)
{
MTCOnOff = false;
CmsError libraryError = MEM_RWBoolean(R, 0, MTCONNECT_ONOFF.MemType, MTCONNECT_ONOFF.Address, MTCONNECT_ONOFF.SubAddress, ref MTCOnOff);
if (libraryError.IsError())
return libraryError;
byte val = 0;
libraryError = MEM_RWByte(R, 0, MTCONNECT_DATA_NEEDED.MemType, MTCONNECT_DATA_NEEDED.Address, 0, ref val);
if (libraryError.IsError())
return libraryError;
// Convert a byte to an array of booleans
bool[] bits = ByteToBits(val);
string[] parameters;
string tmpStr = "";
for (uint processId = 1; processId <= MAX_PROCESS_NUMBER; processId++)
{
if (bits[processId - 1])
{
// Parse parameters
parameters = ExtractM154ParametersFromNcCodeLine(tmpStr);
data.Add(new M154DataModel()
{
Process = processId,
IsNeeded = bits[processId - 1],
Parameters = new string[]
{
"MTC",
"Partid",
"55"
}
});
}
}
return NO_ERROR;
}
public override CmsError PLC_W154ManageAck(int processId)
{
return NO_ERROR;
}
public override CmsError PLC_RM156Data(ref List<M156InputIsNeededModel> value)
{
return NO_ERROR;
}
public override CmsError PLC_WM156Response(int process, double responseVal)
{
return NO_ERROR;
}
public override CmsError PLC_RM157Data(ref List<M157DataModel> value)
{
return NO_ERROR;
}
public override CmsError PLC_WM157Timer(int process, ushort timerVal)
{
return NO_ERROR;
}
public override CmsError PLC_RScadaValue(string memIndex, SCADA_MEM_TYPE memType, ref object value)
{
if (memType == SCADA_MEM_TYPE.BOOL)
{
if (memIndex.ToUpper() == "FALSE")
{
value = false;
return NO_ERROR;
}
else if (memIndex.ToUpper() == "TRUE")
{
value = true;
return NO_ERROR;
}
}
string[] index = memIndex.Split('.');
if (index.Count() == 0)
{
return INCORRECT_PARAMETERS_ERROR;
}
else if (index.Count() == 1)
{
if (memType == SCADA_MEM_TYPE.INT)
{
// read INT
int val = 0;
CmsError libraryError = MEM_RWInteger(R, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), ref val);
if (libraryError.IsError())
return libraryError;
value = val;
}
else if (memType == SCADA_MEM_TYPE.WORD)
{ // read WORD
ushort val = 0;
CmsError libraryError = MEM_RWWord(R, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), ref val);
if (libraryError.IsError())
return libraryError;
value = val;
}
else
{ // read byte
byte val = 0;
CmsError libraryError = MEM_RWByte(R, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), 0, ref val);
if (libraryError.IsError())
return libraryError;
value = val;
}
}
else if (index.Count() == 2 && memType == SCADA_MEM_TYPE.BOOL)
{ // read BOOL
bool val = false;
CmsError libraryError = MEM_RWBoolean(R, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val);
if (libraryError.IsError())
return libraryError;
value = val;
}
return NO_ERROR;
}
public override CmsError PLC_WScadaValue(string memIndex, SCADA_MEM_TYPE memType, object value)
{
string[] index = memIndex.Split('.');
if (index.Count() == 0)
{
return INCORRECT_PARAMETERS_ERROR;
}
else if (index.Count() == 1)
{
if (memType == SCADA_MEM_TYPE.INT)
{
// WRITE INT
int val = Convert.ToInt32(value);
CmsError libraryError = MEM_RWInteger(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), ref val);
if (libraryError.IsError())
return libraryError;
value = val;
}
else if (memType == SCADA_MEM_TYPE.WORD)
{ // WRITE WORD
ushort val = Convert.ToUInt16(value);
CmsError libraryError = MEM_RWWord(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), ref val);
if (libraryError.IsError())
return libraryError;
value = val;
}
else
{ // WRITE byte
byte val = Convert.ToByte(value);
CmsError libraryError = MEM_RWByte(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), 0, ref val);
if (libraryError.IsError())
return libraryError;
value = val;
}
}
else if (index.Count() == 2 && memType == SCADA_MEM_TYPE.BOOL)
{ // WRITE BOOL
bool val = Convert.ToBoolean(value);
CmsError libraryError = MEM_RWBoolean(W, 0, MEMORY_TYPE.Demo, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val);
if (libraryError.IsError())
return libraryError;
value = val;
}
return NO_ERROR;
}
public override CmsError PLC_RScadaSiemens(ref List<ScadaObjectModel> objects)
{
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError PLC_WAssistedToolingCmd(ushort toolId, ushort familyId, ushort shankId, ushort magazineId, ushort positionId, ASSISTED_TOOLING_ACTION action)
{
List<ushort> values = new List<ushort>()
{
toolId,
magazineId,
positionId,
familyId,
shankId
};
// Write data
CmsError libraryError = MEM_RWWordList(W, 1, ASSISTED_TOOLING_DATA.MemType, ASSISTED_TOOLING_DATA.Address, 3, ref values);
if (libraryError.IsError())
return libraryError;
// Write action
byte val = (byte)action;
libraryError = MEM_RWByte(W, 1, ASSISTED_TOOLING_DATA.MemType, ASSISTED_TOOLING_DATA.Address + 6, 0, ref val);
if (libraryError.IsError())
return libraryError;
// Write strobe to start procedure
bool strobe = true;
libraryError = MEM_RWBoolean(W, 1, ASSISTED_TOOLING_STROBE.MemType, ASSISTED_TOOLING_STROBE.Address, 0, ref strobe);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_RAssistedToolingData(ref AssistedToolingModel data)
{
byte procFinalValue = 0;
// Read procedure final value
CmsError libraryError = MEM_RWByte(R, 0, ASSISTED_TOOLING_FINAL_VALUE.MemType, ASSISTED_TOOLING_FINAL_VALUE.Address, 0, ref procFinalValue);
if (libraryError.IsError())
return libraryError;
// Check if the procedure is finished
if (GetBitValue(procFinalValue, 0))
{
List<ushort> values = new List<ushort>();
// Read actual data
libraryError = MEM_RWWordList(R, 1, ASSISTED_TOOLING_DATA.MemType, ASSISTED_TOOLING_DATA.Address, 3, ref values);
if (libraryError.IsError())
return libraryError;
// Set action
ASSISTED_TOOLING_ACTION action = ASSISTED_TOOLING_ACTION.NONE;
if (GetBitValue(procFinalValue, 1))
action = ASSISTED_TOOLING_ACTION.UNLOAD;
if (GetBitValue(procFinalValue, 2))
action = ASSISTED_TOOLING_ACTION.EXCHANGE;
data = new AssistedToolingModel()
{
IsActive = GetBitValue(procFinalValue, 0),
ToolId = values[0],
MagazineId = values[1],
PositionId = values[2],
Action = action
};
}
return NO_ERROR;
}
public override CmsError PLC_WTerminateAssistedToolingProcedure()
{
return NO_ERROR;
}
public override CmsError PROC_RFeed(ushort ProcNumber, ref float Feed)
{
Feed = Convert.ToSingle(rand.NextDouble() * 100);
return NO_ERROR;
}
private CmsError ResetStrobe(int bitId, int strobeByte, int ackByte, MEMORY_TYPE memType)
{
int n = 5;
bool readValue = false;
bool writeValue = false;
CmsError libraryError;
do
{
// Check ACK
libraryError = MEM_RWBoolean(R, 0, memType, ackByte, bitId, ref readValue);
if (libraryError.IsError())
return libraryError;
// If true reset strobe
if (readValue == true)
{
// Reset strobe
libraryError = MEM_RWBoolean(W, 0, memType, strobeByte, bitId, ref writeValue);
if (libraryError.IsError())
return libraryError;
// Exit from cycle
n = 0;
}
else
{
// Decrement
n--;
// Wait befor next cycle
Thread.Sleep(20);
}
} while (n > 0);
return libraryError;
}
private CmsError PLC_RSoftKeys(MEMORY_CELL softKeyStatusMemory, MEMORY_CELL softKeysClickableMemory, ref List<SoftKeysModel> softKeys)
{
softKeys = new List<SoftKeysModel>();
List<int> readValue = new List<int>();
int memorySizeToRead = (softKeyStatusMemory.Size + softKeysClickableMemory.Size);
// Offset between status and clicable data
int offset = softKeyStatusMemory.Size * 8;
// Read on data from memory
CmsError libraryError = MEM_RWIntegerList(R, 0,
softKeyStatusMemory.MemType,
softKeyStatusMemory.Address,
memorySizeToRead / 4,
ref readValue);
if (libraryError.IsError())
return libraryError;
bool[] bits = new BitArray(readValue.ToArray()).Cast<bool>().ToArray();
// Convert array into structured data
for (ushort i = 0; i < bits.Count() / 2; i++)
{
softKeys.Add(new SoftKeysModel()
{
Id = (uint)i + 1,
Value = bits[i],
Active = bits[i + offset]
});
}
return NO_ERROR;
}
public override CmsError PLC_WExpiredCandy(bool value)
{
bool newVal = false;
//Scrivo il dato
CmsError libraryError = MEM_RWBoolean(W, 0, EXP_CANDY_MEM.MemType, EXP_CANDY_MEM.Address, 0, ref value);
if (libraryError.IsError())
return libraryError;
else
{
//Leggo il dato
libraryError = PLC_RExpiredCandy(ref newVal);
if (libraryError.IsError())
return libraryError;
//Se i 2 dati coincidono ritorno OK
if (value == newVal)
return NO_ERROR;
else
return PLC_NOT_RUNNING_ERROR;
}
}
public override CmsError PLC_RExpiredCandy(ref bool value)
{
CmsError libraryError = MEM_RWBoolean(R, 0, EXP_CANDY_MEM.MemType, EXP_CANDY_MEM.Address, 0, ref value);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_WCandy(long value1)
{
long newVal = 0;
int value = (int)value1;
//Scrivo il dato
CmsError libraryError = MEM_RWInteger(W, 0, CANDY_MEM.MemType, CANDY_MEM.Address, ref value);
if (libraryError.IsError())
return libraryError;
else
{
//Leggo il dato
libraryError = PLC_RCandy(ref newVal);
if (libraryError.IsError())
return libraryError;
//Se i 2 dati coincidono ritorno OK
if (value == newVal)
return NO_ERROR;
else
return PLC_NOT_RUNNING_ERROR;
}
}
public override CmsError PLC_RCandy(ref long value1)
{
int value = (int)value1;
CmsError libraryError = MEM_RWInteger(R, 0, CANDY_MEM.MemType, CANDY_MEM.Address, ref value);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PLC_RActiveClient(ref int clientId)
{
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
byte readValues = 0;
libraryError = MEM_RWByte(R, 0, ACTIVE_CLIENT.MemType, ACTIVE_CLIENT.Address, 0, ref readValues);
if (libraryError.IsError())
return libraryError;
// Convert integer array into bit array
bool[] statusBits = ByteToBits(readValues);
// check which bit is set
for (int i = 0; i < 8; i++)
{
if (statusBits[i])
clientId = i + 1;
}
return NO_ERROR;
}
public override CmsError PLC_RToolMovement(ref MovementBetweenMagazinesModel toolMovement)
{
return NO_ERROR;
}
public override CmsError PLC_WTerminateMovementProcedure(MOVEMENT_RESPONSE resp)
{
return NO_ERROR;
}
#endregion PLC High-level data
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
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;
}
// Get process part program data
public override CmsError PROC_RStatusAndData(ushort procNumber, ref ProcessDataModel processData)
{
processData.Id = procNumber;
// Read part program name
CmsError libraryError = PROC_RSelectedPPName(procNumber, ref processData.PartProgramName);
if (libraryError.IsError())
return libraryError;
ushort readValue = 0;
// Read processes status from memory
libraryError = MEM_RWWord(R, 0, PROCESS_STATUS.MemType, PROCESS_STATUS.Address + 2 * (procNumber - 1), ref readValue);
if (libraryError.IsError())
return libraryError;
byte[] bytes = BitConverter.GetBytes(readValue);
// Convert Byte into true/false array
BitArray bits = new BitArray(new byte[] { bytes[0] }); //1st byte -> 0 : Proccess type (AUX-WORK), 1: Process in alarm status, 2: Run, 3: Hold, 4: Read, 5: PartProgramVisible
// Get part program info visibility
processData.Visible = bits[0];
processData.IsInAlarm = bits[1];
processData.IsSelected = bits[2];
// Populate response structure
processData.Type = bits[3] ? "AUX" : "WORK";
processData.CanLoadProgram = bits[6];
processData.IsInPieceWork = rand.NextDouble() > 0.5f;
// Choose process status
if (bits[4])
processData.Status = "HOLD";
else
{
if (bits[5])
processData.Status = "RUN";
else
processData.Status = "READY";
}
// Get Reps from 2nd byte
processData.Reps = bytes[1];
return NO_ERROR;
}
public override CmsError PROC_RSelectedProcess(ref ushort procNumber)
{
CmsError libraryError;
bool readValue = false;
for (int i = 0; i < MAX_PROCESS_NUMBER; i++)
{
int memoryAddress = SELECTED_PROCESS.Address + i * (2);
// Read memory from plc
libraryError = MEM_RWBoolean(R, 0, SELECTED_PROCESS.MemType, memoryAddress, SELECTED_PROCESS.SubAddress, ref readValue);
if (libraryError.IsError())
return libraryError;
if (readValue)
{
procNumber = (ushort)(i + 1);
return NO_ERROR;
}
}
return NO_ERROR;
}
public override CmsError PROC_WSelectProcess(ushort procNumber)
{
CmsError libraryError;
byte processNum = (byte)procNumber;
// Check parameter
if (processNum > MAX_PROCESS_NUMBER)
return INCORRECT_PARAMETERS_ERROR;
// Write process number
libraryError = MEM_RWByte(W, 0, SELECT_PROCESS.MemType, SELECT_PROCESS.Address, 1, ref processNum);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError PROC_RSelectedProcessData(int processId, ref SelectedProcessData processData)
{
byte val = 0;
CmsError libraryError = MEM_RWByte(R, 1, OFFSET_ID.MemType, OFFSET_ID.Address, 0, ref val);
if (libraryError.IsError())
return libraryError;
processData = new SelectedProcessData()
{
ActiveOffsetId = val
};
val = 0;
libraryError = MEM_RWByte(R, 1, ORIGIN_DATA.MemType, ORIGIN_DATA.Address, 0, ref val);
if (libraryError.IsError())
return libraryError;
processData.Origin = val;
libraryError = MEM_RWByte(R, 1, RAPID_OVERRIDE.MemType, RAPID_OVERRIDE.Address, 0, ref val);
if (libraryError.IsError())
return libraryError;
processData.RapidOverride = val;
libraryError = MEM_RWByte(R, 1, WORK_OVERRIDE.MemType, WORK_OVERRIDE.Address, 0, ref val);
if (libraryError.IsError())
return libraryError;
processData.WorkOverride = val;
processData.ProcessMessage = "Generic Message";
processData.OffsetData = new OffsetModel()
{
RealLength = 5,
UnitOfMeasure = "mm",
RealRadius = 15
};
return NO_ERROR;
}
#endregion PROCESS (PATH) High-level data
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
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.id.ToString(), 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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Get Axes Position from server
serverService.GetAxesPosition(ProcNumber.ToString(), out List<NcAxisModel> demoAxes);
// Parse server response and retrieve programmed position
foreach (NcAxisModel demoAxis in demoAxes)
{
axes.Add(demoAxis.id.ToString(), 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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Get Axes Position from server
serverService.GetAxesPosition(procNumber.ToString(), out List<NcAxisModel> demoAxes);
// Parse Server response and retrieve machine position
foreach (NcAxisModel demoAxis in demoAxes)
{
axes.Add(demoAxis.id.ToString(), 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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Get Axes position from Demo server
serverService.GetAxesPosition(procNumber.ToString(), out List<NcAxisModel> demoAxes);
// Parse response retrieve following error
foreach (NcAxisModel demoAxis in demoAxes)
{
axes.Add(demoAxis.id.ToString(), 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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.GetAxesPosition(procNumber.ToString(), out List<NcAxisModel> demoAxes);
// Parse response and retrieve distance to go
foreach (NcAxisModel demoAxis in demoAxes)
{
axes.Add(demoAxis.id.ToString(), demoAxis.distanceToGo);
}
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError AXES_RAxesNames(ushort process, ref List<AxisModel> axesData)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.GetAxesPosition(process.ToString(), out List<NcAxisModel> demoAxes);
// Parse response get distance to go
foreach (NcAxisModel demoAxis in demoAxes)
{
axesData.Add(new AxisModel()
{
Id = demoAxis.id,
Name = demoAxis.name,
IsSelectable = true
});
}
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError AXES_RSelectedAxis(ref byte axisId)
{
// Read byte from memory
CmsError libraryError = MEM_RWByte(R, 0, SELECTED_AXIS.MemType, SELECTED_AXIS.Address, 1, ref axisId);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError AXES_WSelectAxis(byte axisId)
{
// Write byte from memory
CmsError libraryError = MEM_RWByte(W, 0, SELECT_AXIS.MemType, SELECT_AXIS.Address, 1, ref axisId);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError AXES_ROrigin(int numberOfAxes)
{
return NO_ERROR;
}
#endregion PROCESS-AXES (PATH) High-level data
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
libraryError = CheckBitRange(MemBit);
if (libraryError.IsError())
return libraryError;
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
{
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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Read case
if (bWrite == R)
{
serverService.GetByte(MemIndex.ToString(), out Value);
}
else // Write case
{
BinaryMemoryModel binaryMemoryModel = new 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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Read case
if (bWrite == R)
{
serverService.GetWord(MemIndex.ToString(), out Value);
}
else // Write case
{
BinaryMemoryModel binaryMemoryModel = new 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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Read case
if (bWrite == R)
{
serverService.GetShort(MemIndex.ToString(), out Value);
}
else // Write case
{
BinaryMemoryModel binaryMemoryModel = new 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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Read case
if (bWrite == R)
{
serverService.GetDWord(MemIndex.ToString(), out Value);
}
else // Write case
{
BinaryMemoryModel binaryMemoryModel = new 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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Read case
if (bWrite == R)
{
serverService.GetInteger(MemIndex.ToString(), out Value);
}
else // Write case
{
BinaryMemoryModel binaryMemoryModel = new 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_RWDouble(bool bWrite, int process, MEMORY_TYPE memType, int memIndex, ref double value)
{
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError MEM_RWDouble(bool bWrite, int process, MEMORY_TYPE memType, int memTable, int memIndex, ref double value)
{
return FUNCTION_NOT_ALLOWED_ERROR;
}
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 NC Low-level function: single valiable in memory
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Read case
if (bWrite == R)
{
serverService.GetByteList(MemIndex.ToString(), Number.ToString(), out Value);
}
else // Write case
{
BinaryMemoryModel binaryMemoryModel = new 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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Read case
if (bWrite == R)
{
serverService.GetWordList(MemIndex.ToString(), Number.ToString(), out Value);
}
else // Write case
{
BinaryMemoryModel binaryMemoryModel = new 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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Read case
if (bWrite == R)
{
serverService.GetShortList(MemIndex.ToString(), Number.ToString(), out Value);
}
else // Write case
{
BinaryMemoryModel binaryMemoryModel = new 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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Read case
if (bWrite == R)
{
serverService.GetIntegerList(MemIndex.ToString(), Number.ToString(), out Value);
}
else // Write case
{
BinaryMemoryModel binaryMemoryModel = new 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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Read case
if (bWrite == R)
{
serverService.GetDWordList(MemIndex.ToString(), Number.ToString(), out Value);
}
else // Write case
{
BinaryMemoryModel binaryMemoryModel = new BinaryMemoryModel
{
dWordList = Value
};
serverService.PutDWordList(MemIndex.ToString(), binaryMemoryModel);
}
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
#endregion NC Low-level function: variables List in memory
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#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 NC Low-level function: Parameters
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region File Management
public override CmsError FILES_RGetFileList(string path, ref List<PreviewFileModel> files)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
if (string.IsNullOrEmpty(path))
path = @"\";
serverService.GetFileList(path, out files);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError FILES_RGetFileInfo(string path, ref InfoFile fileInfo)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.GetFileInfo(path, out fileInfo);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError FILES_WSetActiveProgram(int processId, string filePath, ref ActiveProgramDataModel data)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.SetActiveProgramData(processId, filePath, out data);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError FILES_WDeactivateProgram(int processId)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.RemoveActiveProgram(processId.ToString(), out ActiveProgramDataModel program);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError FILES_UploadPartProgram(string localPath, string name, ref string newFilePath)
{
try
{
File.Copy(localPath + name, PART_PROGRAM_FOLDER + name, true);
newFilePath = PART_PROGRAM_FOLDER + name;
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError FILES_RActiveProgramData(int processId, ref ActiveProgramDataModel data)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.GetActiveProgramData(processId.ToString(), out data);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError FILES_RProgramToFile(string partProgramPath, FileStream localFile)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
TransferFileModel fileData = new TransferFileModel
{
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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
TransferFileModel fileData = new TransferFileModel
{
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 libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.DeleteFile(partProgramName);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError FILES_RQueueData(ref List<QueueStatusModel> statusList)
{
// Read all the values
List<int> ints = new List<int>();
CmsError libraryError = MEM_RWIntegerList(R, 0, QUEUE_NEXT.MemType, QUEUE_NEXT.Address, 1, ref ints);
if (libraryError.IsError())
return libraryError;
int processId = 0;
// Loop througth
foreach (var val in ints)
{
byte[] bytes = BitConverter.GetBytes(val);
if (bytes[0] == 1)
{
// Reset next part program bit
byte zero = 0;
libraryError = MEM_RWByte(W, 0, QUEUE_NEXT.MemType, QUEUE_NEXT.Address, //+ (processId * 4)
0, ref zero);
if (libraryError.IsError())
return libraryError;
}
// Create process model
QueueStatusModel tmpStatus = new QueueStatusModel()
{
LoadNextProgram = bytes[0] == 1,
Status = (QUEUE_STATUS)bytes[1],
StartStopQueueEnabled = bytes[2] == 1,
ProcessId = processId + 1
};
statusList.Add(tmpStatus);
processId += 1;
};
return NO_ERROR;
}
public override CmsError FILES_RQueueDataByProcess(ref QueueStatusModel status, int processId)
{
// Read all the values
int ints = 0;
CmsError libraryError = MEM_RWInteger(R, 0, QUEUE_NEXT.MemType, QUEUE_NEXT.Address + ((processId - 1) * 4), ref ints);
if (libraryError.IsError())
return libraryError;
byte[] bytes = BitConverter.GetBytes(ints);
status = new QueueStatusModel()
{
LoadNextProgram = bytes[0] == 1,
Status = (QUEUE_STATUS)bytes[1],
StartStopQueueEnabled = bytes[2] == 1,
ProcessId = processId
};
return NO_ERROR;
}
public override CmsError FILES_WStartQueue()
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
// Write start
byte startValue = 1;
return MEM_RWByte(W, 0, QUEUE_CMD.MemType, QUEUE_CMD.Address, 0, ref startValue);
}
public override CmsError FILES_WStopQueue()
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
// Write stop
byte startValue = 2;
return MEM_RWByte(W, 0, QUEUE_CMD.MemType, QUEUE_CMD.Address, 0, ref startValue);
}
public override CmsError FILES_WLoadNextPartProgram(string localPath, string ncFileName)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError FILES_WUploadJobFilesAndActivate(int processId, string jobExtractedPath, string fileToActivate)
{
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
string JobProcessFolder = PART_PROGRAM_FOLDER + "\\" + processId + "\\";
if (!Directory.Exists(JobProcessFolder))
Directory.CreateDirectory(JobProcessFolder);
foreach (string item in Directory.GetFiles(jobExtractedPath))
{
File.Copy(item, JobProcessFolder + Path.GetFileName(item), true);
}
serverService.SetActiveProgramData(processId, JobProcessFolder + fileToActivate, out ActiveProgramDataModel activeProgramData);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError FILES_RGetProgramType(ref PROGRAM_TYPE_ENUM programType)
{
byte val = 0;
CmsError libraryError = MEM_RWByte(R, 0, PROGRAM_TYPE.MemType, PROGRAM_TYPE.Address, 0, ref val);
if (libraryError.IsError())
return libraryError;
programType = (PROGRAM_TYPE_ENUM)val;
return NO_ERROR;
}
public override CmsError FILES_WCleanUploadFolder()
{
return NO_ERROR;
}
public override CmsError FILES_WUploadCustomMainProgramAndActivate(int processId, string customPartProgramContent, ref ActiveProgramDataModel activeData)
{
return NO_ERROR;
}
#endregion File Management
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Tools Management
public override CmsError TOOLS_RConfiguration(ref ToolTableConfiguration config)
{
try
{
serverService.GetToolManagerConfiguration(out DemoToolManagerConfig demoConf);
if (demoConf.SelectedNc == 0) // Siemens config
{
config.ToolsConfiguration = SiemensToolFieldsConfig;
config.FamiliesConfiguration = SiemensFamilyFieldsConfig;
config.ShanksConfiguration = SiemensShankFieldsConfig;
config.MagazinePosConfiguration = SiemensMagazinePosFieldsConfig;
config.EdgesConfiguration = SiemensEdgesFieldsConfiguration;
config.EdgesConfiguration.EdgesAdditionalParamsConfiguration = new Dictionary<int, List<string>>();
// Remove path and set only names
foreach (int key in DemoEdgesConfiguration.EdgesConfig.Keys)
{
List<string> tmpNames = new List<string>();
foreach (var conf in DemoEdgesConfiguration.EdgesConfig[key])
{
tmpNames.Add(conf.Name);
}
config.EdgesConfiguration.EdgesAdditionalParamsConfiguration.Add(key, tmpNames);
}
}
else // Osai fanuc config
{
config.ToolsConfiguration = NcToolFieldsConfig;
config.FamiliesConfiguration = NcFamilyFieldsConfig;
config.ShanksConfiguration = NcShankFieldsConfig;
config.MagazinePosConfiguration = NcMagazinePosFieldsConfig;
config.EdgesConfiguration = NcOffsetFieldsConfiguration;
}
config.SelfAdaptivePathOptionActive = true;
config.RadiusMetricType = false;
config.MaxTools = demoConf.MaxTools;
config.MaxEdgesPerTools = demoConf.MaxEdgePerTools;
config.MaxToolsPerFamily = demoConf.MaxMultitools;
config.MaxMultitools = NC_MAX_MULTITOOLS_NUMBER; // demoConf.MaxMultitools;
config.MaxToolsPerMultitools = demoConf.MaxToolsPerMultitools;
// Options
config.MultitoolOptionActive = demoConf.MultitoolOption;
config.FamilyOptionActive = demoConf.FamilyOption;
config.MagPositionOptionActive = demoConf.MagPositionOption;
config.MaxOffsets = 1000;
// Get magazine status
Dictionary<int, bool> magazineStatus = new Dictionary<int, bool>();
CmsError libraryError = TOOLS_RMagazineStatus(ref magazineStatus);
if (libraryError.IsError())
return libraryError;
MagazineConfig.ForEach(x => x.LoadingIsActive = magazineStatus[x.Id]);
config.Magazines = MagazineConfig;
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError TOOLS_RToolsData(ref List<SiemensToolModel> toolTable)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
toolTable = new List<SiemensToolModel>();
// Get tools table data
serverService.GetTools(out List<DemoToolsDataModel> demoToolsData);
DemoEdgesConfiguration toolsConfig = new DemoEdgesConfiguration();
serverService.GetMagazinePositionsWithTools(1.ToString(), out List<DemoMagPosDataModel> mag1);
// Parse and cast demo model
foreach (DemoToolsDataModel demoTool in demoToolsData)
{
int magazineId = 0;
int positionId = 0;
foreach (var tool in mag1)
{
if (tool.IsMultiTool)
{
if (tool.Shank != null)
if (tool.Shank.Id == demoTool.Id)
{
magazineId = tool.MagazineId;
positionId = tool.PositionId;
}
}
else
{
if (tool.ChildTools != null)
if (tool.ChildTools.Id == demoTool.Id)
{
magazineId = tool.MagazineId;
positionId = tool.PositionId;
}
}
}
var toolData = new SiemensToolModel()
{
Id = demoTool.Id,
FamilyName = demoTool.FamilyName,
ChildId = demoTool.ChildId,
MagazinePositionType = demoTool.MagazinePositionType,
ToolType = demoTool.ToolType,
LeftSize = demoTool.LeftSize,
RightSize = demoTool.RightSize,
Rotation = (ROTATION)demoTool.Rotation,
Cooling1 = demoTool.Cooling1,
Cooling2 = demoTool.Cooling2,
MaxSpeed = demoTool.MaxSpeed,
IsEnabled = demoTool.IsEnabled,
IsActive = demoTool.IsActive,
InFixedPlace = demoTool.InFixedPlace,
IsInhibited = demoTool.IsInhibited,
IsMeasured = demoTool.IsMeasured,
InChangeTool = demoTool.InChangeTool,
IsInUse = demoTool.IsInUse,
PreAlarm = demoTool.PreAlarm,
MagazineId = magazineId,
PositionId = positionId,
MultitoolId = 0,
EdgesData = new List<EdgeModel>()
};
// Get tool type additional parameters
var toolTypeConfigs = toolsConfig.EdgesConfig[demoTool.ToolType];
//--- Read Edges
// For each demo edge
foreach (var demoEdge in demoTool.EdgesData)
{
// Create new edge model with static data
var tmpEdge = new EdgeModel()
{
Id = demoEdge.Id,
ResidualLife = demoEdge.ResidualLife,
NominalLife = demoEdge.NominalLife,
PreAlmLife = demoEdge.PreAlmLife,
EdgeAdditionalParams = new Dictionary<string, double>()
};
// Populate edges' additional params getting only configured fields for the selected tool type
foreach (var configItem in toolTypeConfigs)
{
tmpEdge.EdgeAdditionalParams.Add(
// Item name
configItem.Name,
// "param" + N; N is configured in the path
demoEdge.EdgeAdditionalParams["param" + configItem.Path]
);
}
// Add new edge to selected tool edges list
toolData.EdgesData.Add(tmpEdge);
}
// Add new tool to tool table
toolTable.Add(toolData);
}
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WAddTool(ref SiemensToolModel tool)
{
CmsError libraryError = CheckToolData(tool);
if (libraryError.IsError())
return libraryError;
try
{
serverService.AddTool(ref tool);
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WUpdateTool(ref SiemensToolModel tool)
{
CmsError libraryError = CheckToolData(tool);
if (libraryError.IsError())
return libraryError;
try
{
serverService.PutTool(ref tool);
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WDeleteTool(int id)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.DeleteTool(id.ToString());
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
private CmsError CheckToolData(SiemensToolModel tool)
{
List<SiemensToolModel> tools = new List<SiemensToolModel>();
CmsError libraryError = TOOLS_RToolsData(ref tools);
if (libraryError.IsError())
return libraryError;
ToolTableConfiguration config = new ToolTableConfiguration();
libraryError = TOOLS_RConfiguration(ref config);
if (tools.Count >= config.MaxTools)
return MAX_TOOL_REACHED_ERROR;
return NO_ERROR;
}
#endregion Tools Management
#region Edges
public override CmsError TOOLS_WAddEdge(int toolId, ref EdgeModel newEdge)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
ToolTableConfiguration config = new ToolTableConfiguration();
libraryError = TOOLS_RConfiguration(ref config);
try
{
// Get tools data in order to get tool type and its config
serverService.GetTools(out List<DemoToolsDataModel> demoToolsData);
// Find tool by id
var demoTool = demoToolsData
.Where(x => x.Id == toolId).FirstOrDefault();
if (demoTool == null)
return INCORRECT_PARAMETERS_ERROR;
if (demoTool.EdgesData.Count >= config.MaxEdgesPerTools)
return MAX_EDGES_PER_TOOL_REACHED_ERROR;
// Get the configuration of the tool type
var toolTypeConfig = DemoEdgesConfiguration.EdgesConfig[demoTool.ToolType];
// Create tmp edge to be sended to the Demo
EdgeModel demoEdge = new EdgeModel
{
Id = newEdge.Id,
PreAlmLife = newEdge.PreAlmLife,
NominalLife = newEdge.NominalLife,
ResidualLife = newEdge.ResidualLife,
EdgeAdditionalParams = new Dictionary<string, double>(),
};
// Convert Siemens additional param names into Demo param names
foreach (var additionalParam in newEdge.EdgeAdditionalParams)
{
// Get path of the additional parameter from configuration
string pathNumber = toolTypeConfig
.Where(x => x.Name == additionalParam.Key)
.Select(x => x.Path).FirstOrDefault();
if (!string.IsNullOrEmpty(pathNumber))
{
// Add new Demo param to the temporary list
demoEdge.EdgeAdditionalParams.Add(
"param" + pathNumber,
additionalParam.Value
);
}
}
serverService.AddEdge(toolId.ToString(), ref demoEdge);
// Set id to the returned model
newEdge.Id = demoEdge.Id;
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WUpdateEdge(int toolId, ref EdgeModel newEdge)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Get tools data in order to get tool type and its config
serverService.GetTools(out List<DemoToolsDataModel> demoToolsData);
// Find tool by id
var demoTool = demoToolsData
.Where(x => x.Id == toolId).FirstOrDefault();
if (demoTool == null)
return INCORRECT_PARAMETERS_ERROR;
// Get the configuration of the tool type
var toolTypeConfig = DemoEdgesConfiguration.EdgesConfig[demoTool.ToolType];
// Create tmp edge to be sended to the Demo
EdgeModel demoEdge = new EdgeModel
{
Id = newEdge.Id,
PreAlmLife = newEdge.PreAlmLife,
NominalLife = newEdge.NominalLife,
ResidualLife = newEdge.ResidualLife,
EdgeAdditionalParams = new Dictionary<string, double>(),
};
// Convert Siemens additional param names into Demo param names
foreach (var additionalParam in newEdge.EdgeAdditionalParams)
{
// Get path of the additional parameter from configuration
string pathNumber = toolTypeConfig
.Where(x => x.Name == additionalParam.Key)
.Select(x => x.Path).FirstOrDefault();
if (!string.IsNullOrEmpty(pathNumber))
{
// Add new Demo param to the temporary list
demoEdge.EdgeAdditionalParams.Add(
"param" + pathNumber,
additionalParam.Value
);
}
}
serverService.PutEdge(toolId.ToString(), ref demoEdge);
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WDeleteEdge(int toolId, int edgeId)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.DeleteEdge(toolId.ToString(), edgeId.ToString());
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
#endregion Edges
#region ToolTable
public override CmsError TOOLS_WOptions(ToolManagerOptionsModel options)
{
return NO_ERROR;
}
public override CmsError TOOLS_RShanksData(ref List<ShankModel> shanks)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
shanks = new List<ShankModel>();
// Get tool table data
serverService.GetShanks(out shanks);
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WAddShank(ref ShankModel shank)
{
List<ShankModel> shanks = new List<ShankModel>();
CmsError libraryError = TOOLS_RShanksData(ref shanks);
if (libraryError.IsError())
return libraryError;
// Get configuration
ToolTableConfiguration config = new ToolTableConfiguration();
libraryError = TOOLS_RConfiguration(ref config);
if (shanks.Count >= config.MaxMultitools)
return MAX_MULTITOOL_REACHED_ERROR;
try
{
serverService.AddShank(ref shank);
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WUpdateShank(ref ShankModel shank)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.PutShank(ref shank);
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WDeleteShank(int id)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.DeleteShank(id.ToString());
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_RFamilyData(ref List<FamilyModel> families)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
families = new List<FamilyModel>();
try
{
// Get families data
serverService.GetFamilies(out List<DemoFamilyModel> demoFamilies);
// Populate output model
foreach (DemoFamilyModel family in demoFamilies)
{
families.Add(new FamilyModel()
{
Name = family.Name,
ChildTools = family.ChildTools.Select(x => new FamilyChildModel()
{
Id = x.Id,
ChildId = x.ChildId,
ToolType = x.Type
}).ToList()
});
}
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WAddFamily(ref FamilyModel family)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.AddFamily(ref family);
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WUpdateFamilyData(string oldName, string newName)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
DemoFamilyModel demoFamilyData = new DemoFamilyModel()
{
Name = newName
};
// Get families data
serverService.PutFamily(oldName, ref demoFamilyData);
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WDeleteFamily(string name)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.DeleteFamily(name);
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_RMagazinePositions(ref List<PositionModel> positions)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
positions = new List<PositionModel>();
try
{
// Get position data from demo
serverService.GetPositions(out positions);
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WUpdatePosition(PositionModel position)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Call demo update
serverService.PutPosition(ref position);
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_RMountedTools(int magazineId, ref List<MountedToolModel> magazinePos)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
// Get shanks data
List<ShankModel> shanks = new List<ShankModel>();
serverService.GetShanks(out shanks);
List<SiemensToolModel> tools = new List<SiemensToolModel>();
libraryError = TOOLS_RToolsData(ref tools);
try
{
magazinePos = new List<MountedToolModel>();
// Get tools equipped in the magazine
serverService.GetMagazinePositionsWithTools(magazineId.ToString(), out List<DemoMagPosDataModel> demoMagazinePositions);
foreach (DemoMagPosDataModel demoPos in demoMagazinePositions)
{
if (demoPos.IsMultiTool == true)
{
if (demoPos.Shank != null)
{
// Create multitool
MountedToolModel pos = new MountedToolModel()
{
PositionId = demoPos.PositionId,
MagazineId = magazineId,
ToolId = demoPos.Shank.Id,
ChildShank = shanks.Where(x => x.Id == demoPos.Shank.Id).First()
};
magazinePos.Add(pos);
}
}
else
{
if (demoPos.ChildTools != null)
{
// Create tool
MountedToolModel pos = new MountedToolModel()
{
PositionId = demoPos.PositionId,
MagazineId = magazineId,
ToolId = demoPos.ChildTools.Id,
ChildTool = tools.Where(x => x.Id == demoPos.ChildTools.Id).First()
};
magazinePos.Add(pos);
}
}
}
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_RAvailableTools(ref List<ShankModel> multiTools, ref List<SiemensToolModel> tools)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.GetToolsAndMultiTools(out List<ShankModel> shanks, out List<SiemensToolModel> demoTools);
// Set multiTool Data
multiTools = shanks;
// Set tool data
tools = demoTools;
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WLoadToolInMagazine(int magazineId, NewToolInMagazineModel newMagazineTool, ref MountedToolModel newMountedTool)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
// Get configuration
ToolTableConfiguration config = new ToolTableConfiguration();
libraryError = TOOLS_RConfiguration(ref config);
// Get mag config
SiemensMagazineConfigModel magConfig = config.Magazines.Where(x => x.Id == magazineId).FirstOrDefault();
if (magConfig == null || !magConfig.LoadingIsActive)
return INCORRECT_PARAMETERS_ERROR;
try
{
serverService.UpdateMagazine(magazineId.ToString(), new List<NewToolInMagazineModel> { newMagazineTool });
List<MountedToolModel> tools = new List<MountedToolModel>();
libraryError = TOOLS_RMountedTools(magazineId, ref tools);
if (libraryError.IsError())
return libraryError;
newMountedTool = tools.Where(x => x.ToolId == newMagazineTool.ToolId).FirstOrDefault();
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WUnloadToolFromMagazine(int magazineId, int positionId)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.UpdateMagazine(magazineId.ToString(), new List<NewToolInMagazineModel> {
new NewToolInMagazineModel
{
PositionId = positionId,
ToolId = 0
}
});
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_WLoadToolIntoShank(int shankId, int positionId, int toolId)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.UpdateToolShank(shankId.ToString(), positionId.ToString(), toolId.ToString());
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.UpdateToolShank(shankId.ToString(), positionId.ToString(), 0.ToString());
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError TOOLS_RMagazineAction(ref MagazineActionModel magazineAction)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Call demo update
serverService.GetMagazinesAction(out magazineAction);
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
}
public override CmsError TOOLS_RStoredData(ref List<NcToolModel> tools, ref List<NcFamilyModel> families, ref List<NcShankModel> shanks)
{
return NO_ERROR;
}
public override CmsError TOOLS_RMagazineBlock(ref List<int> ids)
{
return NO_ERROR;
}
public override CmsError TOOLS_WFreeMagazines()
{
return NO_ERROR;
}
public override CmsError TOOLS_RAdatpivePathStep(ref Byte step)
{
// Check ACK
CmsError libraryError = MEM_RWByte(R, 0, SELF_ADAPTIVE_PATH.MemType, SELF_ADAPTIVE_PATH.Address, 0, ref step);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError TOOLS_WAdatpivePathStep(Byte step)
{
// Check ACK
CmsError libraryError = MEM_RWByte(W, 0, SELF_ADAPTIVE_PATH.MemType, SELF_ADAPTIVE_PATH.Address, 0, ref step);
if (libraryError.IsError())
return libraryError;
return NO_ERROR;
}
public override CmsError TOOLS_WStartTDILoading(ushort magazineId, ushort positionId)
{
return NO_ERROR;
}
public override CmsError TOOLS_WStartTDIUnloading(ushort magazineId, ushort positionId, ushort toolId)
{
return NO_ERROR;
}
public override CmsError TOOLS_WEmptyBallufTablet(SiemensToolModel tool)
{
return NO_ERROR;
}
public override CmsError TOOLS_WEmptyBallufTabletAdditionalData(SiemensToolModel tool)
{
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError TOOLS_WAbortBallufTablet()
{
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError TOOLS_WClearBallufTablet(ushort magazineId, ushort positionId, ushort toolId)
{
return FUNCTION_NOT_ALLOWED_ERROR;
}
#endregion ToolTable
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Nc Tool Manager
public override CmsError TOOLS_RMagazineConfig(ref List<NcMagazineConfigModel> config)
{
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
config = new List<NcMagazineConfigModel>()
{
new NcMagazineConfigModel()
{
Id = 1,
MaxPositions = 10,
Type = NC_MAGAZINE_TYPE.BOX_MAGAZINE
},
new NcMagazineConfigModel()
{
Id = 2,
MaxPositions = 10,
Type = NC_MAGAZINE_TYPE.DISK
},
new NcMagazineConfigModel()
{
Id = 3,
MaxPositions = 1,
Type = NC_MAGAZINE_TYPE.CHAIN
}
};
return NO_ERROR;
}
public override CmsError TOOLS_ROffset(short offsetId, ref OffsetModel offset)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.GetOffsets(out List<OffsetModel> offsetData);
offset = offsetData.Where(x => x.Id == offsetId).FirstOrDefault();
if (offset != null)
{
offset.CustomDouble = new List<double>()
{
3.15,
12.15
};
offset.CustomInt = new List<short>()
{
18,
124
};
}
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError TOOLS_WOffset(short offsetId, ref OffsetModel offset)
{
offset.Id = offsetId;
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
serverService.PutOffset(ref offset);
}
catch (Exception ex)
{
return ManageException(ex);
}
offset.RealLength = offset.Length + offset.WearLength;
offset.RealRadius = offset.RealRadius + offset.WearRadius;
return NO_ERROR;
}
public override CmsError TOOLS_WStartEditData()
{
return NO_ERROR;
}
public override CmsError TOOLS_WStopEditData()
{
return NO_ERROR;
}
public override CmsError TOOLS_WUpdateTools(List<NcToolModel> list)
{
return NO_ERROR;
}
public override CmsError TOOLS_WUpdateFamilies(List<NcFamilyModel> list)
{
return NO_ERROR;
}
public override CmsError TOOLS_WUpdateShanks(List<NcShankModel> list)
{
return NO_ERROR;
}
public override CmsError TOOLS_WUpdateMagazinePositions(List<NcMagazinePositionModel> list)
{
return NO_ERROR;
}
public override CmsError TOOLS_WStartEditTooling(int magazineId)
{
return NO_ERROR;
}
public override CmsError TOOLS_WStopEditTooling(int magazineId)
{
return NO_ERROR;
}
public override CmsError TOOLS_WRestoreBackup()
{
return NO_ERROR;
}
public override CmsError TOOLS_RUpdatedToolsData(ref Dictionary<int, byte> updatedStatus, ref Dictionary<int, uint> updatedLives, ref Dictionary<int, ushort> updatedPresetting, ref Dictionary<int, ushort> updatedDressing)
{
return NO_ERROR;
}
public override CmsError TOOLS_RMagazineStatus(ref Dictionary<int, bool> magazineStatus)
{
//Check if the NC is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
// Read tool manager status
int status = 0;
libraryError = MEM_RWInteger(R, 0, MAGAZINES_ENABLED_CMD.MemType, MAGAZINES_ENABLED_CMD.Address, ref status);
if (libraryError.IsError())
return libraryError;
bool[] bits = IntToBits(status);
for (int i = 0; i < bits.Length; i++)
{
magazineStatus.Add(i + 1, bits[i]);
}
return NO_ERROR;
}
#endregion Nc Tool Manager
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#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)
{
//Catch the .Net exceptions
if (ex is EndpointNotFoundException)
{
Connected = false;
return NOT_CONNECTED_ERROR;
}
else
return CmsError.InternalError(ex.Message, ex);
}
//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_RSelectedPPName(ushort ProcNumber, ref string Name)
{
// Check if the NC Demo is Connected
CmsError libraryError = CheckConnection();
if (libraryError.IsError())
return libraryError;
try
{
// Get status from server
serverService.GetProcessPartProgram(ProcNumber.ToString(), out Name);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
// Create and return CmsError object
private CmsError GetNcError(string message)
{
return CmsError.NcError(message);
}
#endregion Subordinate Private Functions
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Memory addresses
internal static class MEMORY_ADDRESS
{
internal const int STARTING_ADDRESS = 0;
internal static MEMORY_CELL NC_WATCHDOG = new MEMORY_CELL(MEMORY_TYPE.Demo, 0, 1);
internal static MEMORY_CELL FUNCTION_ACCESS = new MEMORY_CELL(MEMORY_TYPE.Demo, 13, 8);
internal static MEMORY_CELL PRE_POWER_ON = new MEMORY_CELL(MEMORY_TYPE.Demo, 21, 1);
internal static MEMORY_CELL PRE_POWER_ON_CLICKABLE = new MEMORY_CELL(MEMORY_TYPE.Demo, 22, 1);
internal static MEMORY_CELL POST_POWER_ON = new MEMORY_CELL(MEMORY_TYPE.Demo, 23, 1);
internal static MEMORY_CELL POST_POWER_ON_CLICKABLE = new MEMORY_CELL(MEMORY_TYPE.Demo, 24, 1);
internal static MEMORY_CELL PRE_POWER_ON_CLICKED = new MEMORY_CELL(MEMORY_TYPE.Demo, 25, 1);
internal static MEMORY_CELL POST_POWER_ON_CLICKED = new MEMORY_CELL(MEMORY_TYPE.Demo, 26, 1);
internal static MEMORY_CELL AXIS_RESET_PROCEDURE = new MEMORY_CELL(MEMORY_TYPE.Demo, 27, 7, 2);
internal static MEMORY_CELL SELECTED_PROCESS = new MEMORY_CELL(MEMORY_TYPE.Demo, 31, 2, 1);
internal static MEMORY_CELL SELECT_PROCESS = new MEMORY_CELL(MEMORY_TYPE.Demo, 30, 1);
internal static MEMORY_CELL PROCESS_STATUS = new MEMORY_CELL(MEMORY_TYPE.Demo, 31, 0, 12);
internal static MEMORY_CELL COUNTERS = new MEMORY_CELL(MEMORY_TYPE.Demo, 43, 0, 40);
internal static MEMORY_CELL SELECTED_AXIS = new MEMORY_CELL(MEMORY_TYPE.Demo, 83, 0, 1);
internal static MEMORY_CELL SELECT_AXIS = new MEMORY_CELL(MEMORY_TYPE.Demo, 84, 0, 1);
internal static MEMORY_CELL NC_SOFTKEYS_VALUE = new MEMORY_CELL(MEMORY_TYPE.Demo, 85, 0, 4);
internal static MEMORY_CELL NC_SOFTKEYS_CLICKABLE = new MEMORY_CELL(MEMORY_TYPE.Demo, 89, 0, 4);
internal static MEMORY_CELL NC_SOFT_KEYS_CLICKED = new MEMORY_CELL(MEMORY_TYPE.Demo, 93, 4);
internal static MEMORY_CELL NC_SOFT_KEYS_ACK = new MEMORY_CELL(MEMORY_TYPE.Demo, 97, 4);
internal static MEMORY_CELL USER_SOFTKEYS_VALUE = new MEMORY_CELL(MEMORY_TYPE.Demo, 101, 0, 16);
internal static MEMORY_CELL USER_SOFTKEYS_CLICKABLE = new MEMORY_CELL(MEMORY_TYPE.Demo, 117, 0, 16);
internal static MEMORY_CELL USER_SOFT_KEYS_CLICKED = new MEMORY_CELL(MEMORY_TYPE.Demo, 133, 16);
internal static MEMORY_CELL USER_SOFT_KEYS_ACK = new MEMORY_CELL(MEMORY_TYPE.Demo, 149, 16);
internal static MEMORY_CELL ALARMS_STATUS = new MEMORY_CELL(MEMORY_TYPE.Demo, 165, 4);
internal static MEMORY_CELL ALARMS_DATA = new MEMORY_CELL(MEMORY_TYPE.Demo, 169, 32);
internal static MEMORY_CELL ALARM_ACK = new MEMORY_CELL(MEMORY_TYPE.Demo, 201, 4);
internal static MEMORY_CELL ALARM_REFRESH_STROBE = new MEMORY_CELL(MEMORY_TYPE.Demo, 205, 4);
internal static MEMORY_CELL HEADS_DATA = new MEMORY_CELL(MEMORY_TYPE.Demo, 209, 220);
internal static MEMORY_CELL HEADS_ACK = new MEMORY_CELL(MEMORY_TYPE.Demo, 429, 4);
internal static MEMORY_CELL HEADS_STROBE_INCREMENT = new MEMORY_CELL(MEMORY_TYPE.Demo, 432, 4);
internal static MEMORY_CELL HEADS_STROBE_DECREMENT = new MEMORY_CELL(MEMORY_TYPE.Demo, 436, 4);
internal static MEMORY_CELL MAGAZINES_ENABLED_CMD = new MEMORY_CELL(MEMORY_TYPE.Demo, 441, 4);
internal static MEMORY_CELL QUEUE_NEXT = new MEMORY_CELL(MEMORY_TYPE.Demo, 445, 1);
internal static MEMORY_CELL QUEUE_STATUS_MEM = new MEMORY_CELL(MEMORY_TYPE.Demo, 446, 1);
internal static MEMORY_CELL QUEUE_START_STOP_ACTIVE = new MEMORY_CELL(MEMORY_TYPE.Demo, 447, 1);
internal static MEMORY_CELL QUEUE_CMD = new MEMORY_CELL(MEMORY_TYPE.Demo, 448, 1);
internal static MEMORY_CELL PROGRAM_TYPE = new MEMORY_CELL(MEMORY_TYPE.Demo, 449, 1);
internal static MEMORY_CELL COUNTERS_DATA = new MEMORY_CELL(MEMORY_TYPE.Demo, 43, 40);
internal static MEMORY_CELL COUNTERS_ACK = new MEMORY_CELL(MEMORY_TYPE.Demo, 3008, 2);
internal static MEMORY_CELL COUNTERS_STROBE = new MEMORY_CELL(MEMORY_TYPE.Demo, 3010, 2);
internal static MEMORY_CELL OPERATOR_INPUT_NEEDED = new MEMORY_CELL(MEMORY_TYPE.Demo, 450, 1);
internal static MEMORY_CELL OPERATOR_INPUT_RESPONSE = new MEMORY_CELL(MEMORY_TYPE.Demo, 451, 1);
internal static MEMORY_CELL MTCONNECT_DATA_NEEDED = new MEMORY_CELL(MEMORY_TYPE.Demo, 457, 1);
internal static MEMORY_CELL MTCONNECT_ONOFF = new MEMORY_CELL(MEMORY_TYPE.Demo, 458, 1);
internal static MEMORY_CELL ORIGIN_DATA = new MEMORY_CELL(MEMORY_TYPE.Demo, 459, 1);
internal static MEMORY_CELL OFFSET_ID = new MEMORY_CELL(MEMORY_TYPE.Demo, 460, 1);
internal static MEMORY_CELL ASSISTED_TOOLING_DATA = new MEMORY_CELL(MEMORY_TYPE.Demo, 461, 7);
internal static MEMORY_CELL ASSISTED_TOOLING_STROBE = new MEMORY_CELL(MEMORY_TYPE.Demo, 468, 1);
internal static MEMORY_CELL ASSISTED_TOOLING_FINAL_VALUE = new MEMORY_CELL(MEMORY_TYPE.Demo, 469, 1);
internal static MEMORY_CELL UNIT_OF_MEASURE = new MEMORY_CELL(MEMORY_TYPE.Demo, 470, 1);
internal static MEMORY_CELL EXP_CANDY_MEM = new MEMORY_CELL(MEMORY_TYPE.Demo, 471, 1);
internal static MEMORY_CELL CANDY_MEM = new MEMORY_CELL(MEMORY_TYPE.Demo, 472, 1);
internal static MEMORY_CELL HEADS_WORKED_TIMES = new MEMORY_CELL(MEMORY_TYPE.Demo, 480, 4);
internal static MEMORY_CELL SELF_ADAPTIVE_PATH = new MEMORY_CELL(MEMORY_TYPE.Demo, 560, 4);
internal static MEMORY_CELL RAPID_OVERRIDE = new MEMORY_CELL(MEMORY_TYPE.Demo, 570, 4);
internal static MEMORY_CELL WORK_OVERRIDE = new MEMORY_CELL(MEMORY_TYPE.Demo, 571, 4);
internal static MEMORY_CELL ACTIVE_CLIENT = new MEMORY_CELL(MEMORY_TYPE.Demo, 561, 1);
}
#endregion Memory addresses
}