DOCard.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Core.Util;
  3. using Automation.BDaq;
  4. namespace athosRT.Devices
  5. {
  6. public class DOCard
  7. {
  8. private int _portCount;
  9. private byte[] _buff = (byte[]) null;
  10. private R_TRIG _trigError = new R_TRIG();
  11. private InstantDoCtrl _ctrl = (InstantDoCtrl) null;
  12. public string Name { get; set; }
  13. public DOCard(string name, int deviceID)
  14. {
  15. this.Name = name;
  16. this._ctrl = new InstantDoCtrl();
  17. this._ctrl.SelectedDevice = new DeviceInformation(deviceID);
  18. }
  19. public bool Open()
  20. {
  21. if (!this._ctrl.Initialized)
  22. {
  23. LOG.Write("Open DO card failed.", file: "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Devices\\AdvantecIoCard.cs", member: nameof (Open), line: 285);
  24. return false;
  25. }
  26. this._portCount = this._ctrl.PortCount;
  27. this._buff = new byte[this._portCount * 8];
  28. return true;
  29. }
  30. public bool Read() => true;
  31. public bool Write(byte[] buffer)
  32. {
  33. if (!this._ctrl.Initialized)
  34. return false;
  35. for (int index = 0; index < this._portCount * 8 && index < buffer.Length; ++index)
  36. this._buff[index] = buffer[index];
  37. ErrorCode errorCode = this._ctrl.Write(0, this._portCount, this._buff);
  38. this._trigError.CLK = errorCode != 0;
  39. if (this._trigError.Q)
  40. LOG.Write("Write DO failed.", file: "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Devices\\AdvantecIoCard.cs", member: nameof (Write), line: 317);
  41. return errorCode == 0;
  42. }
  43. public bool Reset() => true;
  44. public bool Close() => true;
  45. }
  46. }