Added virtual class for reading lsit of double values
This commit is contained in:
@@ -1293,6 +1293,47 @@ namespace CMS_CORE_Library
|
||||
|
||||
public abstract CmsError MEM_RWIntegerList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List<int> Value);
|
||||
|
||||
/**
|
||||
* <summary>Read/Write List of signed 4 Byte (NC: DWord:, .NET: int) from/into NC Memory Area
|
||||
* <para>
|
||||
* Compatibility: Fanuc | Osai | Demo
|
||||
* </para>
|
||||
* </summary>
|
||||
* <returns cref="CmsError">Returns an error when an internal or a library error occours</returns>
|
||||
* <param name="bWrite">Set True to Write-operation (Also Allowed <see cref="Nc.W"/>/<see cref="Nc.R"/>)</param>
|
||||
* <param name="Process">Process to perform operation (If the area is process-indipendent use 0 or Nc.<see cref="Nc.UNDEF_PROC"/>)</param>
|
||||
* <param name="MemType">Nc Memory Area. See <see cref="Nc.MEMORY_TYPE"/></param>
|
||||
* <param name="MemIndex">Starting Index of Memory Area</param>
|
||||
* <param name="Number">Number of sequential data Read/Write. (Used only in Reading Operation)</param>
|
||||
* <param name="Value">List of values to read/Write</param>
|
||||
* */
|
||||
|
||||
public virtual CmsError MEM_RWDoubleList(bool bWrite, int process, MEMORY_TYPE memType, int memIndex, int Number, ref List<double> value)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* <summary>Read/Write List of signed 4 Byte (NC: DWord:, .NET: int) from/into NC Memory Area (including Siemens Nc)
|
||||
* <para>
|
||||
* Compatibility: Fanuc | Osai | Demo | Siemens
|
||||
* </para>
|
||||
* </summary>
|
||||
* <returns cref="CmsError">Returns an error when an internal or a library error occours</returns>
|
||||
* <param name="bWrite">Set True to Write-operation (Also Allowed <see cref="Nc.W"/>/<see cref="Nc.R"/>)</param>
|
||||
* <param name="Process">Process to perform operation (If the area is process-indipendent use 0 or Nc.<see cref="Nc.UNDEF_PROC"/>)</param>
|
||||
* <param name="MemType">Nc Memory Area. See <see cref="Nc.MEMORY_TYPE"/></param>
|
||||
* <param name="MemTable">Siemens Memory Table (Used only in Siemens-Nc)</param>
|
||||
* <param name="MemIndex">Starting Index of Memory Area</param>
|
||||
* <param name="Number">Number of sequential data Read/Write. (Used only in Reading Operation)</param>
|
||||
* <param name="Value">List of values to read/Write</param>
|
||||
* */
|
||||
|
||||
public virtual CmsError MEM_RWDoubleList(bool bWrite, int process, MEMORY_TYPE memType, int memTable, int memIndex, int Number, ref List<double> value)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
|
||||
#endregion NC Low-level function: variables List in memory (to override)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -2504,6 +2504,8 @@ namespace CMS_CORE_Library.S7Net
|
||||
|
||||
public override CmsError AXES_RInterpPosition(ushort channel, ref Dictionary<string, double> axes)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
#if false
|
||||
try
|
||||
{
|
||||
axes = new Dictionary<string, double>();
|
||||
@@ -2523,11 +2525,14 @@ namespace CMS_CORE_Library.S7Net
|
||||
return ManageException(ex);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
return NO_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
public override CmsError AXES_RMachinePosition(ushort channel, ref Dictionary<string, double> axes)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
#if false
|
||||
try
|
||||
{
|
||||
axes = new Dictionary<string, double>();
|
||||
@@ -2547,11 +2552,14 @@ namespace CMS_CORE_Library.S7Net
|
||||
return ManageException(ex);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
return NO_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
public override CmsError AXES_RProgrPosition(ushort channel, ref Dictionary<string, double> axes)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
#if false
|
||||
try
|
||||
{
|
||||
axes = new Dictionary<string, double>();
|
||||
@@ -2570,11 +2578,14 @@ namespace CMS_CORE_Library.S7Net
|
||||
return ManageException(ex);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
return NO_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
public override CmsError AXES_RFollowingError(ushort channel, ref Dictionary<string, double> axes)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
#if false
|
||||
try
|
||||
{
|
||||
axes = new Dictionary<string, double>();
|
||||
@@ -2593,11 +2604,14 @@ namespace CMS_CORE_Library.S7Net
|
||||
return ManageException(ex);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
return NO_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
public override CmsError AXES_RDistanceToGo(ushort channel, ref Dictionary<string, double> axes)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
#if false
|
||||
try
|
||||
{
|
||||
axes = new Dictionary<string, double>();
|
||||
@@ -2615,12 +2629,14 @@ namespace CMS_CORE_Library.S7Net
|
||||
{
|
||||
return ManageException(ex);
|
||||
}
|
||||
return NO_ERROR;
|
||||
return NO_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
private Dictionary<string, double> AXES_RAxesPos(ushort channel, string positionType)
|
||||
{
|
||||
Dictionary<string, double> axes = new Dictionary<string, double>();
|
||||
#if false
|
||||
List<AxisModel> axesConf = new List<AxisModel>();
|
||||
|
||||
CmsError cmsError = AXES_RAxesNames(channel, ref axesConf);
|
||||
@@ -2641,13 +2657,16 @@ namespace CMS_CORE_Library.S7Net
|
||||
{
|
||||
axes.Add(conf.Id.ToString(), Convert.ToDouble(items[i].Value));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return axes;
|
||||
}
|
||||
|
||||
public override CmsError AXES_RAxesNames(ushort channel, ref List<AxisModel> axesData)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
#if false
|
||||
if (!File.Exists(AXES_FILE_PATH))
|
||||
return CmsError.InternalError("File" + AXES_FILE_PATH + " not found", new Exception("File" + AXES_FILE_PATH + " not found"));
|
||||
|
||||
@@ -2738,31 +2757,40 @@ namespace CMS_CORE_Library.S7Net
|
||||
return ManageException(ex);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
return NO_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
public override CmsError AXES_RSelectedAxis(ref byte axisId)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
#if false
|
||||
// Read byte from memory
|
||||
CmsError cmsError = MEM_RWByte(R, 0, SELECTED_AXIS.MemType, SELECTED_AXIS.Address, SELECTED_AXIS.SubAddress, 1, ref axisId);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
return NO_ERROR;
|
||||
return NO_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
public override CmsError AXES_WSelectAxis(byte axisId)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
#if false
|
||||
// Write byte from memory
|
||||
CmsError cmsError = MEM_RWByte(W, 0, SELECT_AXIS.MemType, SELECT_AXIS.Address, SELECT_AXIS.SubAddress, 1, ref axisId);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
return NO_ERROR;
|
||||
return NO_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
public override CmsError AXES_ROrigin(int numberOfAxes)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
#if false
|
||||
DataSvc dataSvc = new DataSvc();
|
||||
List<Item> ncAxes = new List<Item>();
|
||||
|
||||
@@ -2784,7 +2812,8 @@ namespace CMS_CORE_Library.S7Net
|
||||
|
||||
dataSvc.Read(ncAxes.ToArray());
|
||||
|
||||
return NO_ERROR;
|
||||
return NO_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion PROCESS-AXES (PATH) High-level data
|
||||
@@ -2806,34 +2835,32 @@ namespace CMS_CORE_Library.S7Net
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
//Try to get information
|
||||
try
|
||||
{
|
||||
//Setup variables
|
||||
DataSvc Data = HighPriorityDataSvc();
|
||||
byte bValue = 0;
|
||||
ushort pow = (ushort)Math.Pow(2, MemBit);
|
||||
|
||||
cmsError = ConvertMemToPath(MemType, MemTable, MemIndex, MemBit, 1, 'X', out string itemString);
|
||||
//Read the Byte where is the bit
|
||||
cmsError = MEM_RWByte(R, Process, MemType, MemTable, MemIndex, ref bValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
//If i have to Write -> Write the Bit
|
||||
if (bWrite)
|
||||
{
|
||||
if (Value)
|
||||
bValue = (byte)(bValue | (1 << MemBit));
|
||||
else
|
||||
bValue = (byte)(bValue & ~(1 << MemBit));
|
||||
|
||||
cmsError = MEM_RWByte(W, Process, MemType, MemTable, MemIndex, ref bValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
Item item = new Item(itemString);
|
||||
|
||||
//Read-Write Data
|
||||
if (bWrite)
|
||||
{
|
||||
item.Value = Value;
|
||||
Data.Write(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
Data.Read(item);
|
||||
Value = (bool)item.Value;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
//If i have to read -> Read the Bit
|
||||
else
|
||||
{
|
||||
return ManageException(ex);
|
||||
Value = (bValue & pow) == pow;
|
||||
}
|
||||
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -2896,49 +2923,16 @@ namespace CMS_CORE_Library.S7Net
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError MEM_RWDouble(bool bWrite, int process, MEMORY_TYPE memType, int memTable, int memIndex, ref double value)
|
||||
public override CmsError MEM_RWDouble(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref double Value)
|
||||
{
|
||||
// Check if the NC is Connected
|
||||
CmsError cmsError = CheckConnection();
|
||||
List<double> ListValue = new List<double>() { Value };
|
||||
|
||||
//uses the List method with one-element list
|
||||
CmsError cmsError = MEM_RWDoubleList(bWrite, Process, MemType, MemTable, MemIndex, 1, ref ListValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Try to get information
|
||||
try
|
||||
{
|
||||
// Setup variables
|
||||
DataSvc Data = new DataSvc
|
||||
{
|
||||
Timeout = TimeoutConn,
|
||||
PriorityFlag = SlPriority.highPriority
|
||||
};
|
||||
|
||||
cmsError = ConvertMemToPath(memType, memTable, memIndex, 0, 1, 'D', out string itemString);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
Item item = new Item(itemString);
|
||||
|
||||
|
||||
byte[] byteVal;
|
||||
|
||||
// Read-Write Data
|
||||
if (bWrite)
|
||||
{
|
||||
byteVal = BitConverter.GetBytes((Single)value);
|
||||
item.Value = BitConverter.ToUInt32(byteVal, 0);
|
||||
Data.Write(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
Data.Read(item);
|
||||
byteVal = BitConverter.GetBytes((uint)item.Value);
|
||||
value = unchecked(Convert.ToDouble(BitConverter.ToSingle(byteVal, 0)));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ManageException(ex);
|
||||
}
|
||||
Value = ListValue.First();
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
@@ -3275,6 +3269,58 @@ namespace CMS_CORE_Library.S7Net
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError MEM_RWDoubleList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int Number, ref List<double> Values)
|
||||
{
|
||||
//Check if the NC is Connected
|
||||
CmsError cmsError = CheckConnection();
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
if (MemType != MEMORY_TYPE.Siemens_DB)
|
||||
{
|
||||
return INCORRECT_PARAMETERS_ERROR;
|
||||
}
|
||||
|
||||
cmsError = null;
|
||||
|
||||
if (bWrite)
|
||||
{
|
||||
//Prevent some exceptions
|
||||
if (Values.Count == 0)
|
||||
return NO_ERROR;
|
||||
|
||||
byte[] singleItem = new byte[4];
|
||||
List<Byte> memByteList = new List<byte>();
|
||||
|
||||
foreach (var Item in Values)
|
||||
{
|
||||
singleItem = S7.Net.Types.Double.ToByteArray(Item);
|
||||
memByteList.AddRange(singleItem);
|
||||
}
|
||||
|
||||
currPLC.WriteBytes(DataType.DataBlock, MemTable, MemIndex, memByteList.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Prevent some exceptions
|
||||
if (Number == 0)
|
||||
return NO_ERROR;
|
||||
|
||||
Values.Clear();
|
||||
|
||||
byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, MemTable, MemIndex, Number);
|
||||
// converto a word!
|
||||
double shortVal = 0;
|
||||
for (int i = 0; i < memByteRead.Length / 4; i++)
|
||||
{
|
||||
shortVal = S7.Net.Types.Double.FromByteArray(memByteRead.Skip(4 * i).Take(4).ToArray());
|
||||
Values.Add(shortVal);
|
||||
}
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
#endregion Low level methods
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user