diff --git a/CMS_CORE_Library/Nc.cs b/CMS_CORE_Library/Nc.cs index 4ffcd4f..2d2abb9 100644 --- a/CMS_CORE_Library/Nc.cs +++ b/CMS_CORE_Library/Nc.cs @@ -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 Value); + /** + * Read/Write List of signed 4 Byte (NC: DWord:, .NET: int) from/into NC Memory Area + * + * Compatibility: Fanuc | Osai | Demo + * + * + * Returns an error when an internal or a library error occours + * Set True to Write-operation (Also Allowed /) + * Process to perform operation (If the area is process-indipendent use 0 or Nc.) + * Nc Memory Area. See + * Starting Index of Memory Area + * Number of sequential data Read/Write. (Used only in Reading Operation) + * List of values to read/Write + * */ + + public virtual CmsError MEM_RWDoubleList(bool bWrite, int process, MEMORY_TYPE memType, int memIndex, int Number, ref List value) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + + /** + * Read/Write List of signed 4 Byte (NC: DWord:, .NET: int) from/into NC Memory Area (including Siemens Nc) + * + * Compatibility: Fanuc | Osai | Demo | Siemens + * + * + * Returns an error when an internal or a library error occours + * Set True to Write-operation (Also Allowed /) + * Process to perform operation (If the area is process-indipendent use 0 or Nc.) + * Nc Memory Area. See + * Siemens Memory Table (Used only in Siemens-Nc) + * Starting Index of Memory Area + * Number of sequential data Read/Write. (Used only in Reading Operation) + * List of values to read/Write + * */ + + public virtual CmsError MEM_RWDoubleList(bool bWrite, int process, MEMORY_TYPE memType, int memTable, int memIndex, int Number, ref List value) + { + return FUNCTION_NOT_ALLOWED_ERROR; + } + #endregion NC Low-level function: variables List in memory (to override) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 43f936d..0a7b25c 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -2504,6 +2504,8 @@ namespace CMS_CORE_Library.S7Net public override CmsError AXES_RInterpPosition(ushort channel, ref Dictionary axes) { + return FUNCTION_NOT_ALLOWED_ERROR; +#if false try { axes = new Dictionary(); @@ -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 axes) { + return FUNCTION_NOT_ALLOWED_ERROR; +#if false try { axes = new Dictionary(); @@ -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 axes) { + return FUNCTION_NOT_ALLOWED_ERROR; +#if false try { axes = new Dictionary(); @@ -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 axes) { + return FUNCTION_NOT_ALLOWED_ERROR; +#if false try { axes = new Dictionary(); @@ -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 axes) { + return FUNCTION_NOT_ALLOWED_ERROR; +#if false try { axes = new Dictionary(); @@ -2615,12 +2629,14 @@ namespace CMS_CORE_Library.S7Net { return ManageException(ex); } - return NO_ERROR; + return NO_ERROR; +#endif } private Dictionary AXES_RAxesPos(ushort channel, string positionType) { Dictionary axes = new Dictionary(); +#if false List axesConf = new List(); 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 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 ncAxes = new List(); @@ -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 ListValue = new List() { 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 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 memByteList = new List(); + + 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 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////