DICard.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.Util;
  3. using Automation.BDaq;
  4. namespace athosRT.Devices
  5. {
  6. public class DICard
  7. {
  8. private int _portCount;
  9. private byte[] _buff = (byte[]) null;
  10. private InstantDiCtrl _ctrl = (InstantDiCtrl) null;
  11. private int _deviceNumber = -1;
  12. private R_TRIG _trigError = new R_TRIG();
  13. public string Name { get; set; }
  14. public byte[] DI => this._buff;
  15. public DICard(string name, int deviceID)
  16. {
  17. this.Name = name;
  18. this._deviceNumber = deviceID;
  19. this._ctrl = new InstantDiCtrl();
  20. this._ctrl.SelectedDevice = new DeviceInformation(deviceID);
  21. }
  22. public bool Open()
  23. {
  24. if (!this._ctrl.Initialized)
  25. {
  26. LOG.Write(string.Format("{0} : {1} initialize failed", (object) this.Name, (object) this._deviceNumber), file: "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Devices\\AdvantecIoCard.cs", member: nameof (Open), line: 196);
  27. return false;
  28. }
  29. this._portCount = this._ctrl.PortCount;
  30. this._buff = new byte[this._portCount * 8];
  31. return true;
  32. }
  33. public bool Read()
  34. {
  35. if (!this._ctrl.Initialized)
  36. return false;
  37. for (int port = 0; port < this._portCount; ++port)
  38. {
  39. for (int bit = 0; bit < 8; ++bit)
  40. {
  41. byte data;
  42. ErrorCode errorCode = this._ctrl.ReadBit(port, bit, out data);
  43. this._buff[port * 8 + bit] = data;
  44. this._trigError.CLK = errorCode != 0;
  45. if (this._trigError.Q)
  46. {
  47. LOG.Write(string.Format("{0} : {1} read error: {2}", (object) this.Name, (object) this._deviceNumber, (object) errorCode), file: "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Devices\\AdvantecIoCard.cs", member: nameof (Read), line: 225);
  48. break;
  49. }
  50. }
  51. }
  52. return !this._trigError.M;
  53. }
  54. public bool Write(byte[] buffer) => true;
  55. public bool Reset() => true;
  56. public bool Close() => true;
  57. }
  58. }