using System; using System.Runtime.InteropServices; using Aitex.Core.RT.IOCore; using Aitex.Core.RT.PLC; namespace Aitex.Triton160.RT.PLC { public class CPLCBuffer : IDataBuffer { private PLC_INPUT_DATA input; private PLC_OUTPUT_DATA output; public PLC_INPUT_DATA Input { get { return input; } set { input = value; } } public PLC_OUTPUT_DATA Output { get { return output; } set { output = value; } } public void UpdateDI(bool[] values) { for (int i = 0; i < input.DI.Length && i < values.Length; i++) { values[i] = input.DI[i] != 0 ? true : false;; } } public void UpdateAI(float[] values) { for (int i = 0; i < input.AI.Length && i < values.Length; i++) { values[i] = input.AI[i]; } } public void UpdateDO(bool[] values) { for (int i = 0; i < output.DO.Length && i < values.Length; i++) { output.DO[i] = values[i] ? (byte)1 : (byte)0; //System.Diagnostics.Debug.Assert(!values[i]); } } public void UpdateAO(float[] values) { for (int i = 0; i < output.AO.Length && i < values.Length; i++) { output.AO[i] = values[i]; } } public CPLCBuffer() { input = new PLC_INPUT_DATA(); input.DI = new Byte[IOGroupManager.DioBlockLength]; input.AI = new float[IOGroupManager.AioBlockLength]; output = new PLC_OUTPUT_DATA(); output.DO = new Byte[IOGroupManager.DioBlockLength]; output.AO = new float[IOGroupManager.AioBlockLength]; } } }