SimulatorFinsDataDevice.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.RT.PLC;
  8. using Aitex.Jet.RT.Simulator;
  9. using Aitex.Triton160.RT.Module;
  10. using Aitex.Triton160.RT.PLC;
  11. namespace Aitex.Triton160.RT.Simulator
  12. {
  13. public class SimulatorFinsDataDevice : IDataDevice
  14. {
  15. private ISimulatorManager _simulator;
  16. private bool _isOpened = true;
  17. public bool IsOpened { get { return _isOpened; } }
  18. private List<string> _types = new List<string> {"local", "remote"};
  19. public bool Open()
  20. {
  21. //if (SystemConfigManager.Instance.GetSystemType().ToLower() == "patronmax")
  22. //{
  23. // _simulator = new SimulatorPatronMax();
  24. // _types = new List<string> {"local"};
  25. //}
  26. //else if (SystemConfigManager.Instance.GetSystemType().ToLower() == "patron")
  27. //{
  28. // _simulator = new SimulatorPatron();
  29. //}
  30. //else
  31. //if (SystemConfigManager.Instance.GetSystemType().ToLower() == "hz")
  32. {
  33. _simulator = new SimulatorTriton160();
  34. _types = new List<string> {"local"};
  35. }
  36. //else
  37. //{
  38. // _simulator = new SimulatorTriton();
  39. //}
  40. return true;
  41. }
  42. public void Close()
  43. {
  44. ;
  45. }
  46. public object Read<T>(string type)
  47. {
  48. try
  49. {
  50. return _simulator.Read(type);
  51. }
  52. catch (Exception ex)
  53. {
  54. LOG.Write(ex);
  55. }
  56. return null;
  57. }
  58. public bool Write<T>(string type, T buffer)
  59. {
  60. try
  61. {
  62. _simulator.Write(type, (PLC_OUTPUT_DATA)(object)buffer);
  63. }
  64. catch (Exception ex)
  65. {
  66. LOG.Write(ex);
  67. }
  68. return true;
  69. }
  70. public List<string> GetTypes()
  71. {
  72. return _types;
  73. }
  74. public bool IsOpen(string type)
  75. {
  76. return IsOpened;
  77. }
  78. public bool Open(string type)
  79. {
  80. return Open();
  81. }
  82. public void Close(string type)
  83. {
  84. Close();
  85. }
  86. }
  87. }