123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
-
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- using Automation.BDaq;
- using System;
- namespace athosRT.Devices.IO
- {
- public class IOCard
- {
- private int _portCount;
- private byte[] _buff = (byte[]) null;
- private R_TRIG _trigError = new R_TRIG();
- private InstantDoCtrl _doCtrl = new InstantDoCtrl();
- private InstantDiCtrl _diCtrl = new InstantDiCtrl();
- private bool init = false;
- private string cardName = "N/A";
- public IOCard(string deviceNum, int port)
- {
- try
- {
- this._diCtrl.SelectedDevice = new DeviceInformation(deviceNum);
- this._doCtrl.SelectedDevice = new DeviceInformation(deviceNum);
- this.init = true;
- LOG.Write("IO Card selected", file: "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Devices\\AdvantecIoCard.cs", member: ".ctor", line: 361);
- }
- catch (Exception ex)
- {
- this.init = false;
- }
- this.cardName = this._diCtrl.SelectedDevice.Description;
- this._portCount = port;
- this._buff = new byte[this._portCount * 8];
- }
- public string Name { get; set; }
- public bool Init => this.init;
- public string CardName => this.cardName;
- public bool Write(byte[] buffer)
- {
- if (!this._doCtrl.Initialized)
- return false;
- ErrorCode errorCode = ErrorCode.Success;
- for (int port = 0; port < this._portCount; ++port)
- {
- for (int bit = 0; bit < 8; ++bit)
- {
- if (port * 8 + bit < buffer.Length)
- errorCode = this._doCtrl.WriteBit(port, bit, buffer[port * 8 + bit]);
- this._trigError.CLK = errorCode != 0;
- if (this._trigError.Q)
- {
- LOG.Write(string.Format("{0} : write error: {1}", (object) this.Name, (object) errorCode), file: "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Devices\\AdvantecIoCard.cs", member: nameof (Write), line: 448);
- break;
- }
- }
- }
- this._trigError.CLK = errorCode != 0;
- if (this._trigError.Q)
- LOG.Write("Write DO failed.", file: "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Devices\\AdvantecIoCard.cs", member: nameof (Write), line: 458);
- return errorCode == 0;
- }
- public bool Read(out byte[] buffer)
- {
- if (!this._diCtrl.Initialized)
- {
- LOG.Write(this.Name + " : not initialized", file: "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Devices\\AdvantecIoCard.cs", member: nameof (Read), line: 474);
- buffer = (byte[]) null;
- return false;
- }
- for (int port = 0; port < this._portCount; ++port)
- {
- for (int bit = 0; bit < 8; ++bit)
- {
- byte data;
- ErrorCode errorCode = this._diCtrl.ReadBit(port, bit, out data);
- this._buff[port * 8 + bit] = data;
- this._trigError.CLK = errorCode != 0;
- if (this._trigError.Q)
- {
- LOG.Write(string.Format("{0} : read error: {1}", (object) this.Name, (object) errorCode), file: "D:\\sorter\\trunk\\Efem\\Jet\\Jet_001_2P_Jet\\EfemRT\\Devices\\AdvantecIoCard.cs", member: nameof (Read), line: 490);
- break;
- }
- }
- }
- if (this._trigError.M)
- {
- buffer = (byte[]) null;
- return false;
- }
- buffer = this._buff;
- return true;
- }
- public void Disp()
- {
- this._doCtrl.Cleanup();
- this._diCtrl.Cleanup();
- this._doCtrl.Dispose();
- this._diCtrl.Dispose();
- }
- }
- }
|