123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.RT.PLC;
- using Aitex.Core.RT.Simulator;
- using Aitex.Core.Util;
- using Aitex.Triton160.RT.PLC;
- namespace Aitex.Triton160.RT.Simulator
- {
- public class SimulatorBuffer : IDataBuffer<PLC_INPUT_DATA, PLC_OUTPUT_DATA>
- {
- 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;
- }
- }
- List<Tuple<int, int, string>> _diMap;
- List<Tuple<int, int, string>> _doMap;
- List<Tuple<int, int, string>> _aiMap;
- List<Tuple<int, int, string>> _aoMap;
- public SimulatorBuffer()
- {
- _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];
- }
- public void Initialize(List<Tuple<int, int, string>> diMap, List<Tuple<int, int, string>> doMap, List<Tuple<int, int, string>> aiMap, List<Tuple<int, int, string>> aoMap)
- {
- _diMap = diMap;
- _doMap = doMap;
- _aiMap = aiMap;
- _aoMap = aoMap;
- }
- public Tuple<int, int, string> FindAI(string name)
- {
- return _aiMap.Find(item => item.Item3 == name);
- }
- public Tuple<int, int, string> FindAI(int iodefineIndex)
- {
- return _aiMap.Find(item => item.Item1 == iodefineIndex);
- }
- public Tuple<int, int, string> FindAO(string name)
- {
- return _aoMap.Find(item => item.Item3 == name);
- }
- public Tuple<int, int, string> FindAO(int iodefineIndex)
- {
- return _aoMap.Find(item => item.Item1 == iodefineIndex);
- }
- public Tuple<int, int, string> FindDI(string name)
- {
- return _diMap.Find(item => item.Item3 == name);
- }
- public Tuple<int, int, string> FindDI(int iodefineIndex)
- {
- return _diMap.Find(item => item.Item1 == iodefineIndex);
- }
- public Tuple<int, int, string> FindDO(int iodefineIndex)
- {
- return _doMap.Find(item => item.Item1 == iodefineIndex);
- }
- public Tuple<int, int, string> FindDO(string name)
- {
- return _doMap.Find(item => item.Item3 == name);
- }
- public void UpdateDI(bool[] values)
- {
- }
- public void SetDI(string name, bool value)
- {
- SetDI(name, value ? (byte)1 : (byte)0);
- }
- public void SetDI(string name, byte value)
- {
- Thread.Sleep(200);
- if (DiForce.Instance.ForceValues.ContainsKey(name))
- value = DiForce.Instance.ForceValues[name] ? (byte)1 : (byte)0;
- var item = FindDI(name);
- if (item != null)
- {
- _input.DI[item.Item2] = value;
- }
- }
- public void SetDI(string diName, string doName)
- {
- var item = FindDO(doName);
- if (item == null)
- return;
- SetDI(diName, _output.DO[item.Item2]);
- }
- public void SetAI(string aiName, float value)
- {
- if (AiForce.Instance.ForceValues.ContainsKey(aiName))
- value = AiForce.Instance.ForceValues[aiName];
- var item = FindAI(aiName);
- if (item != null)
- {
- _input.AI[item.Item2] = value;
- }
- }
- public float GetAI(string aiName)
- {
- var item = FindAI(aiName);
- if (item != null)
- {
- return _input.AI[item.Item2];
- }
- return 0;
- }
- public float GetAO(string aoName)
- {
- var item = FindAO(aoName);
- if (item != null)
- {
- return _output.AO[item.Item2];
- }
- return 0;
- }
- public byte GetDI(string diName)
- {
- var item = FindDI(diName);
- if (item != null)
- {
- return _input.DI[item.Item2];
- }
- return 0;
- }
- public byte GetDO(string doName)
- {
- var item = FindDO(doName);
- if (item != null)
- {
- return _output.DO[item.Item2];
- }
- return 0;
- }
- public void UpdateAI(float[] values)
- {
- }
- //仿真不输出output
- public void UpdateDO(bool[] values)
- {
- }
- //仿真不输出output
- public void UpdateAO(float[] values)
- {
- }
- //写入的IO,INDEX做了映射,需要映射回去
- public bool Write(PLC_OUTPUT_DATA data)
- {
- Array.Copy(data.DO, _output.DO, data.DO.Length);
- Array.Copy(data.AO, _output.AO, data.AO.Length);
- return true;
- }
- }
- }
|