This commit is contained in:
@@ -69,11 +69,16 @@ namespace CMS_CORE_Application
|
||||
Stopwatch sw = new Stopwatch();
|
||||
List<AlarmModel> procAlarms = new List<AlarmModel>();
|
||||
List<PlcAlarmModel> Msg = new List<PlcAlarmModel>();
|
||||
PreAndPostPowerOnModel powerOn = new PreAndPostPowerOnModel();
|
||||
List<AlarmModel> ncAlarms = new List<AlarmModel>();
|
||||
List<String> Lines = new List<string>();
|
||||
List<SoftKeysModel> keys = new List<SoftKeysModel>();
|
||||
List<HeadDataModel> test = new List<HeadDataModel>();
|
||||
List<HeadDataModel> headsTest = new List<HeadDataModel>();
|
||||
List<AxisModel> axesNames = new List<AxisModel>();
|
||||
List<FunctionalityModel> functionality = new List<FunctionalityModel>();
|
||||
AxisResetDataModel axesReset = new AxisResetDataModel();
|
||||
|
||||
byte axisId = 0;
|
||||
|
||||
N = SetNcByType();
|
||||
|
||||
@@ -84,6 +89,8 @@ namespace CMS_CORE_Application
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
sw.Restart();
|
||||
cmsError = N.PROC_RMode(1, ref mode);
|
||||
if (cmsError.IsError())
|
||||
{
|
||||
@@ -129,23 +136,33 @@ namespace CMS_CORE_Application
|
||||
error = true;
|
||||
SetError(Lines, cmsError);
|
||||
}
|
||||
N.PLC_WRefreshMessage(1023);
|
||||
|
||||
N.PLC_RPowerOnData(ref powerOn);
|
||||
|
||||
N.PLC_WPowerOnData(6, true);
|
||||
N.PLC_RFunctionAccess(ref functionality);
|
||||
|
||||
N.PLC_RAxesResetData(ref axesReset);
|
||||
// N.PLC_WRefreshAllMessages();
|
||||
cmsError = N.PLC_RNcSoftKeys(ref keys);
|
||||
cmsError = N.PLC_WNcSoftKey(1);
|
||||
|
||||
cmsError = N.AXES_RAxesNames(2, ref axesNames);
|
||||
cmsError = N.AXES_WSelectAxis(2);
|
||||
byte axisId = 0;
|
||||
cmsError = N.AXES_RSelectedAxis(ref axisId);
|
||||
|
||||
//cmsError = N.PLC_RHeadsData(test, 1);
|
||||
//cmsError = N.AXES_RAxesNames(2, ref axesNames);
|
||||
//cmsError = N.AXES_WSelectAxis(2);
|
||||
|
||||
//cmsError = N.AXES_RSelectedAxis(ref axisId);
|
||||
//cmsError = N.PLC_WRefreshAllMessages();
|
||||
cmsError = N.PLC_RHeadsData(headsTest, 1);
|
||||
//cmsError = N.PLC_WHeadOverride(19, HEAD_OVERRIDE_SIGN.MINUS);
|
||||
|
||||
//Dictionary<int, string> messages = new Dictionary<int, string>();
|
||||
//cmsError = N.NC_GetTranslatedPlcMessages("en", ref messages);
|
||||
|
||||
//cmsError = N.PROC_RSelectedProcess(ref procnum);
|
||||
cmsError = N.PLC_RUserSoftKeys(ref keys);
|
||||
|
||||
sw.Stop();
|
||||
if (!this.IsDisposed && this.InvokeRequired)
|
||||
{
|
||||
this.Invoke((ThreadStart)delegate ()
|
||||
@@ -171,7 +188,6 @@ namespace CMS_CORE_Application
|
||||
Disconnect.Enabled = true;
|
||||
});
|
||||
}
|
||||
|
||||
error = false;
|
||||
|
||||
if ((200 - (int)sw.ElapsedMilliseconds) < 0)
|
||||
|
||||
@@ -454,6 +454,18 @@ namespace CMS_CORE.Demo
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_WRefreshAllMessages()
|
||||
{
|
||||
int numberOfInteger = (32 / 8) / 4;
|
||||
List<uint> defaultValue = Enumerable.Repeat(uint.MaxValue, numberOfInteger).ToList();
|
||||
|
||||
CmsError cmsError = MEM_RWDWordList(W, 0, MEMORY_ADDRESS.ALARM_REFRESH_STROBE.MemType, MEMORY_ADDRESS.ALARM_REFRESH_STROBE.Address, numberOfInteger, ref defaultValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel)
|
||||
{
|
||||
int readValue = 0;
|
||||
@@ -754,10 +766,10 @@ namespace CMS_CORE.Demo
|
||||
bool readValue = false;
|
||||
bool writeValue = true;
|
||||
|
||||
MEMORY_CELL currentMemoryCell = sign == HEAD_OVERRIDE_SIGN.PLUS ? MEMORY_ADDRESS.HEADS_STROBE_INCREMENT : MEMORY_ADDRESS.HEADS_STROBE_DECREMENT;
|
||||
MEMORY_CELL currentStrobeCell = sign == HEAD_OVERRIDE_SIGN.PLUS ? MEMORY_ADDRESS.HEADS_STROBE_INCREMENT : MEMORY_ADDRESS.HEADS_STROBE_DECREMENT;
|
||||
|
||||
int ackByte = MEMORY_ADDRESS.HEADS_ACK.Address + (((int)id - 1) / 8);
|
||||
int strobeByte = currentMemoryCell.Address + (((int)id - 1) / 8);
|
||||
int strobeByte = currentStrobeCell.Address + (((int)id - 1) / 8);
|
||||
int headBit = (((int)id - 1) % 8);
|
||||
|
||||
// Check ACK
|
||||
@@ -770,12 +782,12 @@ namespace CMS_CORE.Demo
|
||||
return NO_ERROR;
|
||||
|
||||
// Write strobe data
|
||||
cmsError = MEM_RWBoolean(W, 0, currentMemoryCell.MemType, strobeByte, headBit, ref writeValue);
|
||||
cmsError = MEM_RWBoolean(W, 0, currentStrobeCell.MemType, strobeByte, headBit, ref writeValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Reset wait ack = 1 and reset the strobe
|
||||
cmsError = ResetStrobe(headBit, strobeByte, ackByte, currentMemoryCell.MemType);
|
||||
cmsError = ResetStrobe(headBit, strobeByte, ackByte, currentStrobeCell.MemType);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
|
||||
@@ -376,6 +376,11 @@ namespace CMS_CORE.Fanuc
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_WRefreshAllMessages()
|
||||
{
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
// Get pre and post power on data
|
||||
public override CmsError PLC_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel)
|
||||
{
|
||||
|
||||
@@ -454,6 +454,8 @@ namespace CMS_CORE
|
||||
|
||||
public abstract CmsError PLC_WRefreshMessage(uint id);
|
||||
|
||||
public abstract CmsError PLC_WRefreshAllMessages();
|
||||
|
||||
/**
|
||||
* <summary>
|
||||
* Start restore message procedure
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.ServiceModel;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using static CMS_CORE_Library.DataStructures;
|
||||
|
||||
namespace CMS_CORE.Osai
|
||||
@@ -72,7 +73,7 @@ namespace CMS_CORE.Osai
|
||||
ushort nReturn;
|
||||
|
||||
//Setup Binding
|
||||
setupConnection();
|
||||
SetupConnection();
|
||||
|
||||
//Setup the Url String and the Endpoint
|
||||
Url = "http://" + Ip + ":" + Port;
|
||||
@@ -403,7 +404,7 @@ namespace CMS_CORE.Osai
|
||||
CmsError cmsError = MEM_RWIntegerList(R, 0,
|
||||
MEMORY_ADDRESS.ALARMS_STATUS.MemType,
|
||||
MEMORY_ADDRESS.ALARMS_STATUS.Address,
|
||||
(MEMORY_ADDRESS.ALARMS_STATUS.Size + MEMORY_ADDRESS.ALARMS_DATA.Size) / 4,
|
||||
(MEMORY_ADDRESS.ALARMS_STATUS.Size + MEMORY_ADDRESS.ALARMS_DATA.Size) / 4, // byte / 4
|
||||
ref readValues);
|
||||
|
||||
if (cmsError.IsError())
|
||||
@@ -430,7 +431,7 @@ namespace CMS_CORE.Osai
|
||||
// Add alarm info into active alarms list
|
||||
alarms.Add(new PlcAlarmModel()
|
||||
{
|
||||
Id = (uint)i,
|
||||
Id = (uint)i + 1,
|
||||
IsWarning = statusBits[dataByteAddress + 7],
|
||||
RestorationIsActive = statusBits[dataByteAddress + 6],
|
||||
Process = processList
|
||||
@@ -446,34 +447,198 @@ namespace CMS_CORE.Osai
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_WRefreshMessage(uint id)
|
||||
public override CmsError PLC_WRestoreMessage(uint id)
|
||||
{
|
||||
// Call restore message
|
||||
CmsError cmsError = PLC_WStrobe(MEMORY_ADDRESS.ALARM_ACK, MEMORY_ADDRESS.ALARM_RESTORATION_STROBE, id);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_WRestoreMessage(uint id)
|
||||
public override CmsError PLC_WRefreshMessage(uint id)
|
||||
{
|
||||
// Call restore message
|
||||
CmsError cmsError = PLC_WStrobe(MEMORY_ADDRESS.ALARM_ACK, MEMORY_ADDRESS.ALARM_REFRESH_STROBE, id);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
public override CmsError PLC_WRefreshAllMessages()
|
||||
{
|
||||
int numberOfInteger = (ALARMS_NUMBER / 8) / 4; // Number of integers to write 1024 / 8 = byte number
|
||||
List<uint> defaultValue = Enumerable.Repeat(uint.MaxValue, numberOfInteger).ToList();
|
||||
|
||||
CmsError cmsError = MEM_RWDWordList(W, 0, MEMORY_ADDRESS.ALARM_REFRESH_STROBE.MemType, MEMORY_ADDRESS.ALARM_REFRESH_STROBE.Address, numberOfInteger, ref defaultValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
private CmsError PLC_WStrobe(MEMORY_CELL ackCell, MEMORY_CELL strobeCell, uint id)
|
||||
{
|
||||
// Check id range
|
||||
if (id > ALARMS_NUMBER)
|
||||
return INCORRECT_PARAMETERS_ERROR;
|
||||
|
||||
CmsError cmsError;
|
||||
bool readValue = false;
|
||||
bool writeValue = true;
|
||||
|
||||
SetupAckStrobeAddresses(ackCell.Address, strobeCell.Address, id, out int ackWord, out int strobeWord, out int alarmBitId);
|
||||
|
||||
// Check ACK
|
||||
cmsError = MEM_RWBoolean(R, 0, ackCell.MemType, ackWord, alarmBitId, ref readValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// If PLC it's performing another request then return
|
||||
if (readValue)
|
||||
return NO_ERROR;
|
||||
|
||||
// Write strobe into memory
|
||||
cmsError = MEM_RWBoolean(W, 0, strobeCell.MemType, strobeWord, alarmBitId, ref writeValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Reset wait ack = 1 and reset the strobe
|
||||
cmsError = ResetStrobe(alarmBitId, strobeWord, ackWord, ackCell.MemType);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
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 cmsError = MEM_RWInteger(R, 0, MEMORY_ADDRESS.PRE_POST_POWER_ON.MemType, MEMORY_ADDRESS.PRE_POST_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 = 1, Active = bits[0], Clickable = bits[16] }, // id = N, bits = N, Clickable = N + 8 (Second bit)
|
||||
AirPressure = new PowerOnDataModel() { Id = 2, Active = bits[1], Clickable = bits[17] },
|
||||
ProtectionStatus = new PowerOnDataModel() { Id = 3, Active = bits[2], Clickable = bits[18] },
|
||||
EmergencyButtons = new PowerOnDataModel() { Id = 4, Active = bits[3], Clickable = bits[19] },
|
||||
SettingMode = new PowerOnDataModel() { Id = 5, Active = bits[4], Clickable = bits[20] },
|
||||
StartingKey = new PowerOnDataModel() { Id = 6, Active = bits[5], Clickable = bits[21] }
|
||||
};
|
||||
// Create and set post power on object
|
||||
PostPowerOnModel postPowerOn = new PostPowerOnModel()
|
||||
{
|
||||
AxisReset = new PowerOnDataModel() { Id = 9, Active = bits[8], Clickable = bits[25] }, // id = N - 8, bits = N, Clickable = N + 8 (Second bit)
|
||||
WaterjetPump = new PowerOnDataModel() { Id = 10, Active = bits[9], Clickable = bits[26] }
|
||||
};
|
||||
|
||||
powerOnModel = new PreAndPostPowerOnModel()
|
||||
{
|
||||
PostPowerOn = postPowerOn,
|
||||
PrePowerOn = prePowerOn
|
||||
};
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_WPowerOnData(uint id, bool value)
|
||||
{
|
||||
// Check bit range
|
||||
if (id > 16)
|
||||
return INCORRECT_PARAMETERS_ERROR;
|
||||
|
||||
// Call restore message
|
||||
CmsError cmsError = PLC_WStrobe(MEMORY_ADDRESS.PRE_POST_POWER_ON_ACK, MEMORY_ADDRESS.PRE_POST_POWER_ON_CLICKED, id);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
return NO_ERROR;
|
||||
|
||||
//// Check bit range
|
||||
//if (id > 16)
|
||||
// return INCORRECT_PARAMETERS_ERROR;
|
||||
//bool readValue = false;
|
||||
|
||||
//// Check ACK
|
||||
//CmsError cmsError = MEM_RWBoolean(R, 0, MEMORY_ADDRESS.PRE_POST_POWER_ON_ACK.MemType, MEMORY_ADDRESS.PRE_POST_POWER_ON_ACK.Address, (int)id, ref readValue);
|
||||
//if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
|
||||
//// If PLC it's performing another request then return
|
||||
//if (readValue)
|
||||
// return NO_ERROR;
|
||||
|
||||
//// Bit = id
|
||||
//// Choose Pre-Power-On or Post-Power-Om
|
||||
//cmsError = MEM_RWBoolean(W, 0, MEMORY_ADDRESS.PRE_POST_POWER_ON_CLICKED.MemType, MEMORY_ADDRESS.PRE_POST_POWER_ON_CLICKED.Address, (int)id, ref value);
|
||||
//if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
|
||||
//// Reset till wait ack = 1 and reset the strobe
|
||||
//cmsError = ResetStrobe((int)id, MEMORY_ADDRESS.PRE_POST_POWER_ON_CLICKED.Address, MEMORY_ADDRESS.PRE_POST_POWER_ON_ACK.Address, MEMORY_ADDRESS.PRE_POST_POWER_ON_ACK.MemType);
|
||||
//if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
|
||||
//return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_RFunctionAccess(ref List<FunctionalityModel> functions)
|
||||
{
|
||||
List<int> readValues = new List<int>();
|
||||
int numberOfIntegers = MEMORY_ADDRESS.FUNCTION_ACCESS.Size / 4;
|
||||
// Read functions access data from memory
|
||||
CmsError cmsError = MEM_RWIntegerList(R, 0, MEMORY_ADDRESS.FUNCTION_ACCESS.MemType, MEMORY_ADDRESS.FUNCTION_ACCESS.Address, numberOfIntegers, ref readValues);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
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 + 1,
|
||||
IsActive = bits[i]
|
||||
});
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_RAxesResetData(ref AxisResetDataModel axisResetData)
|
||||
{
|
||||
byte value = 0;
|
||||
// Read byte from memory
|
||||
CmsError cmsError = MEM_RWByte(R, 0, MEMORY_ADDRESS.AXIS_RESET_PROCEDURE.MemType, MEMORY_ADDRESS.AXIS_RESET_PROCEDURE.Address, 0, ref value);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Check last bit if is active
|
||||
if ((value & 128) == 128)
|
||||
{
|
||||
// Set to 0 last bit( isActive bit x - 128 )
|
||||
// From 0 to 6 bit represents percentage
|
||||
// If higher than 100 then value = 100
|
||||
byte percentage = value - 128 > 100 ? (byte)100 : (byte)(value - 128);
|
||||
axisResetData = new AxisResetDataModel()
|
||||
{
|
||||
IsActive = true,
|
||||
Percentage = percentage
|
||||
};
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -482,36 +647,175 @@ namespace CMS_CORE.Osai
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_WNcSoftKey(uint id)
|
||||
{
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_RNcSoftKeys(ref List<SoftKeysModel> ncSoftKeys)
|
||||
{
|
||||
CmsError cmsError = PLC_RSoftKeys(MEMORY_ADDRESS.NC_SOFTKEYS_VALUE, MEMORY_ADDRESS.NC_SOFTKEYS_CLICKABLE, ref ncSoftKeys);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_RUserSoftKeys(ref List<SoftKeysModel> softKeys)
|
||||
{
|
||||
CmsError cmsError = PLC_RSoftKeys(MEMORY_ADDRESS.USER_SOFTKEYS_VALUE, MEMORY_ADDRESS.USER_SOFTKEYS_CLICKABLE, ref softKeys);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
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 clickable data
|
||||
int offset = softKeyStatusMemory.Size * 8;
|
||||
|
||||
// Read on data from memory
|
||||
CmsError cmsError = MEM_RWIntegerList(R, 0,
|
||||
softKeyStatusMemory.MemType,
|
||||
softKeyStatusMemory.Address,
|
||||
memorySizeToRead / 4,
|
||||
ref readValue);
|
||||
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
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_WNcSoftKey(uint id)
|
||||
{
|
||||
// Check id range
|
||||
if (id > NC_SOFTKEYS_NUMBER)
|
||||
return INCORRECT_PARAMETERS_ERROR;
|
||||
|
||||
// Write strobe into memory
|
||||
CmsError cmsError = PLC_WStrobe(MEMORY_ADDRESS.NC_SOFT_KEYS_ACK, MEMORY_ADDRESS.NC_SOFT_KEYS_CLICKED, id);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_WUserSoftKey(uint id)
|
||||
{
|
||||
// Check id range
|
||||
if (id > USER_SOFTKEYS_NUMBER)
|
||||
return INCORRECT_PARAMETERS_ERROR;
|
||||
|
||||
// Write strobe into memory
|
||||
CmsError cmsError = PLC_WStrobe(MEMORY_ADDRESS.USER_SOFT_KEYS_ACK, MEMORY_ADDRESS.USER_SOFT_KEYS_CLICKED, id);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_RHeadsData(List<HeadDataModel> heads, int number)
|
||||
{
|
||||
// Check parameters
|
||||
if (number > HEADS_NUMBER)
|
||||
return INCORRECT_PARAMETERS_ERROR;
|
||||
heads.Clear();
|
||||
|
||||
List<byte> readValues = new List<byte>();
|
||||
// Find the size of a single head
|
||||
int headsByte = (MEMORY_ADDRESS.HEADS_DATA.Size / HEADS_NUMBER);
|
||||
|
||||
// Read data for N heads
|
||||
CmsError cmsError = MEM_RWByteList(R, 0, MEMORY_ADDRESS.HEADS_DATA.MemType, MEMORY_ADDRESS.HEADS_DATA.Address, 0, headsByte * number, ref readValues);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Parse and format readed 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,
|
||||
Process = readValues[headOffset],
|
||||
Override = readValues[headOffset + 1],
|
||||
Load_Abrasive = BitConverter.ToUInt16(readValues.ToArray(), headOffset + 2), // Uint 16 = 2byte
|
||||
ActualSpeed_Pressure = BitConverter.ToInt32(readValues.ToArray(), headOffset + 4), // Int32 = 4byte
|
||||
MountedTool_Vacum = BitConverter.ToUInt16(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
|
||||
});
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_WHeadOverride(uint id, HEAD_OVERRIDE_SIGN sign)
|
||||
{
|
||||
if (id > HEADS_NUMBER)
|
||||
return INCORRECT_PARAMETERS_ERROR;
|
||||
|
||||
MEMORY_CELL currentStrobeCell = sign == HEAD_OVERRIDE_SIGN.PLUS ? MEMORY_ADDRESS.HEADS_STROBE_INCREMENT : MEMORY_ADDRESS.HEADS_STROBE_DECREMENT;
|
||||
|
||||
// Write strobe into memory
|
||||
CmsError cmsError = PLC_WStrobe(MEMORY_ADDRESS.HEADS_ACK, currentStrobeCell, id);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
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 cmsError;
|
||||
do
|
||||
{
|
||||
// Check ACK
|
||||
cmsError = MEM_RWBoolean(R, 0, memType, ackByte, bitId, ref readValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// If true reset strobe
|
||||
if (readValue == true)
|
||||
{
|
||||
// Reset strobe
|
||||
cmsError = MEM_RWBoolean(W, 0, memType, strobeByte, bitId, ref writeValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
// Exit from cycle
|
||||
n = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Decrement
|
||||
n--;
|
||||
// Wait befor next cycle
|
||||
Thread.Sleep(20);
|
||||
}
|
||||
} while (n > 0);
|
||||
|
||||
return cmsError;
|
||||
}
|
||||
|
||||
#endregion PLC High-level data
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -1058,8 +1362,8 @@ namespace CMS_CORE.Osai
|
||||
for (int i = 0; i < axesNumber; i++)
|
||||
{
|
||||
var charName = Convert.ToChar(axesName[i]);
|
||||
// Filter per master axes and process
|
||||
if((charName < 'a' || charName > 'z') && charName != 'S' && charName != '\0' && axesProcess[i] == process)
|
||||
// Filter per master axes and process
|
||||
if ((charName < 'a' || charName > 'z') && charName != 'S' && charName != '\0' && axesProcess[i] == process)
|
||||
{
|
||||
// Add to returned value
|
||||
axesData.Add(new AxisModel()
|
||||
@@ -1097,7 +1401,7 @@ namespace CMS_CORE.Osai
|
||||
public override CmsError MEM_RWBoolean(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, int MemBit, ref bool Value)
|
||||
{
|
||||
ushort WordValue = 0;
|
||||
byte pow = (byte)Math.Pow(2, MemBit);
|
||||
ushort pow = (ushort)Math.Pow(2, MemBit);
|
||||
|
||||
//Read the Byte where is the bit
|
||||
CmsError cmsError = MEM_RWWord(R, Process, MemType, MemIndex, ref WordValue);
|
||||
@@ -1113,9 +1417,9 @@ namespace CMS_CORE.Osai
|
||||
else
|
||||
{
|
||||
if (Value)
|
||||
WordValue = (byte)(WordValue | (1 << MemBit));
|
||||
WordValue = (ushort)(WordValue | (1 << MemBit));
|
||||
else
|
||||
WordValue = (byte)(WordValue & ~(1 << MemBit));
|
||||
WordValue = (ushort)(WordValue & ~(1 << MemBit));
|
||||
|
||||
cmsError = MEM_RWWord(W, Process, MemType, MemIndex, ref WordValue);
|
||||
if (cmsError.IsError())
|
||||
@@ -1329,7 +1633,7 @@ namespace CMS_CORE.Osai
|
||||
Values.Clear();
|
||||
for (int i = 0; i < Number; i++)
|
||||
{
|
||||
cmsError = MEM_RWByte(W, Process, MemType, MemIndexTemp, index, ref TempVal);
|
||||
cmsError = MEM_RWByte(R, Process, MemType, MemIndexTemp, index, ref TempVal);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
@@ -1339,6 +1643,8 @@ namespace CMS_CORE.Osai
|
||||
index = 0;
|
||||
MemIndexTemp++;
|
||||
}
|
||||
else
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1647,8 +1953,15 @@ namespace CMS_CORE.Osai
|
||||
|
||||
#region Subordinate Private Functions
|
||||
|
||||
private void SetupAckStrobeAddresses(int ackAddress, int strobeAddress, uint id, out int ackWord, out int strobeWord, out int bit)
|
||||
{
|
||||
ackWord = ackAddress + (((int)id - 1) / 16);
|
||||
strobeWord = strobeAddress + (((int)id - 1) / 16);
|
||||
bit = (((int)id - 1) % 16);
|
||||
}
|
||||
|
||||
//Setup the connection Binding
|
||||
private void setupConnection()
|
||||
private void SetupConnection()
|
||||
{
|
||||
HttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
|
||||
HttpBinding.Name = "OPENcontrol";
|
||||
@@ -1790,7 +2103,6 @@ namespace CMS_CORE.Osai
|
||||
//Read Plc Messages
|
||||
private CmsError ReadPlcMessages()
|
||||
{
|
||||
String[] SPlitted;
|
||||
String Path;
|
||||
try
|
||||
{
|
||||
@@ -2085,8 +2397,48 @@ namespace CMS_CORE.Osai
|
||||
|
||||
internal static class MEMORY_ADDRESS
|
||||
{
|
||||
internal static MEMORY_CELL ALARMS_STATUS = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12000, 128);
|
||||
internal static MEMORY_CELL ALARMS_DATA = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12064, 1024);
|
||||
internal const int STARTING_ADDRESS = 12000;
|
||||
|
||||
internal static MEMORY_CELL FUNCTION_ACCESS = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12003, 8);
|
||||
|
||||
internal static MEMORY_CELL PRE_POST_POWER_ON = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12775, 1);
|
||||
internal static MEMORY_CELL PRE_POST_POWER_ON_CLICKABLE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12776, 1);
|
||||
internal static MEMORY_CELL PRE_POST_POWER_ON_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12777, 1);
|
||||
internal static MEMORY_CELL PRE_POST_POWER_ON_CLICKED = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12778, 1);
|
||||
|
||||
internal static MEMORY_CELL AXIS_RESET_PROCEDURE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12792, 7, 1);
|
||||
|
||||
internal static MEMORY_CELL SELECTED_PROCESS = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 29, 1);
|
||||
internal static MEMORY_CELL SELECT_PROCESS = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 30, 1);
|
||||
internal static MEMORY_CELL PROCESS_STATUS = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 31, 0, 12);
|
||||
|
||||
internal static MEMORY_CELL COUNTERS = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 43, 0, 40);
|
||||
|
||||
internal static MEMORY_CELL SELECTED_AXIS = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 83, 0, 1);
|
||||
internal static MEMORY_CELL SELECT_AXIS = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 84, 0, 1);
|
||||
|
||||
internal static MEMORY_CELL NC_SOFTKEYS_VALUE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12793, 0, 4);
|
||||
internal static MEMORY_CELL NC_SOFTKEYS_CLICKABLE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12795, 0, 4);
|
||||
internal static MEMORY_CELL NC_SOFT_KEYS_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12797, 4);
|
||||
internal static MEMORY_CELL NC_SOFT_KEYS_CLICKED = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12799, 4);
|
||||
|
||||
internal static MEMORY_CELL USER_SOFTKEYS_VALUE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12802, 0, 16);
|
||||
internal static MEMORY_CELL USER_SOFTKEYS_CLICKABLE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12810, 0, 16);
|
||||
internal static MEMORY_CELL USER_SOFT_KEYS_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12818, 16);
|
||||
internal static MEMORY_CELL USER_SOFT_KEYS_CLICKED = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12825, 16);
|
||||
|
||||
internal static MEMORY_CELL ALARMS_STATUS = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12007, 128);
|
||||
internal static MEMORY_CELL ALARMS_DATA = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12071, 1024);
|
||||
|
||||
internal static MEMORY_CELL ALARM_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12583, 128);
|
||||
internal static MEMORY_CELL ALARM_RESTORATION_STROBE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12647, 128);
|
||||
internal static MEMORY_CELL ALARM_REFRESH_STROBE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12711, 128);
|
||||
|
||||
internal static MEMORY_CELL HEADS_DATA = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 12833, 240);
|
||||
|
||||
internal static MEMORY_CELL HEADS_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 449, 4);
|
||||
internal static MEMORY_CELL HEADS_STROBE_INCREMENT = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 453, 4);
|
||||
internal static MEMORY_CELL HEADS_STROBE_DECREMENT = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 457, 4);
|
||||
}
|
||||
|
||||
#endregion Memory addresses
|
||||
|
||||
@@ -303,6 +303,11 @@ namespace CMS_CORE.Siemens
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_WRefreshAllMessages()
|
||||
{
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_RFunctionAccess(ref List<FunctionalityModel> functions)
|
||||
{
|
||||
functions = new List<FunctionalityModel>();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SQLite;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Web;
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
using Nc_Demo_Application.Database;
|
||||
using Nc_Demo_Application.Database.Models;
|
||||
using System;
|
||||
using System.ServiceModel;
|
||||
using System.Collections.Generic;
|
||||
using static Nc_Demo_Application.Constants;
|
||||
using System.Linq;
|
||||
using System.ServiceModel.Web;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using Nc_Demo_Application.Server.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Web;
|
||||
using static Nc_Demo_Application.Constants;
|
||||
|
||||
namespace Nc_Demo_Application.Server.Service
|
||||
{
|
||||
[ServiceBehavior(MaxItemsInObjectGraph = int.MaxValue, InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
|
||||
class LibraryService : ILibraryService
|
||||
internal class LibraryService : ILibraryService
|
||||
{
|
||||
private NcDataModel ncDataData = new NcDataModel();
|
||||
|
||||
#region Nc Data API
|
||||
|
||||
public void Name(out string name)
|
||||
{
|
||||
ncDataData = DatabaseController.getInstance().GetNcData();
|
||||
@@ -59,9 +60,11 @@ namespace Nc_Demo_Application.Server.Service
|
||||
ncDataData = DatabaseController.getInstance().GetNcData();
|
||||
softwareVersion = ncDataData.softwareVersion;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion Nc Data API
|
||||
|
||||
#region Process API
|
||||
|
||||
public void ProcessNumber(out ushort processNumber)
|
||||
{
|
||||
List<NcProcessModel> ncProcessesData = DatabaseController.getInstance().GetNcProcesses();
|
||||
@@ -135,7 +138,7 @@ namespace Nc_Demo_Application.Server.Service
|
||||
axes = ncAxesModel.FindAll(i => i.processId == Convert.ToInt32(id));
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion Process API
|
||||
|
||||
#region Binary Memory
|
||||
|
||||
@@ -235,10 +238,10 @@ namespace Nc_Demo_Application.Server.Service
|
||||
DatabaseController.getInstance().PutDWordValue(Convert.ToInt32(index), body.dWord);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
#endregion Binary Memory
|
||||
|
||||
#region Binary Memory List
|
||||
|
||||
public void GetByteList(string index, string number, out List<byte> byteList)
|
||||
{
|
||||
int idx = Convert.ToInt32(index);
|
||||
@@ -342,6 +345,7 @@ namespace Nc_Demo_Application.Server.Service
|
||||
foreach (int item in body.shortList)
|
||||
{
|
||||
DatabaseController.getInstance().PutIntegerValue(idx, item);
|
||||
idx += 4;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,12 +357,14 @@ namespace Nc_Demo_Application.Server.Service
|
||||
}
|
||||
|
||||
int idx = Convert.ToInt32(index);
|
||||
foreach (int item in body.dWordList)
|
||||
foreach (uint item in body.dWordList.ToList())
|
||||
{
|
||||
DatabaseController.getInstance().PutIntegerValue(idx, item);
|
||||
DatabaseController.getInstance().PutDWordValue(idx, item);
|
||||
idx += 4;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion Binary Memory List
|
||||
|
||||
#region File Management
|
||||
|
||||
@@ -446,7 +452,6 @@ namespace Nc_Demo_Application.Server.Service
|
||||
.ToDictionary(y => i++, y => y[0]);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion File Management
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user