123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Event;
- using Aitex.Core.Util;
- using MECF.Framework.Common.Communications;
- using MECF.Framework.Common.Equipment;
- namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.CarrierIdReaders
- {
- public class CarrierIdReader : BaseDevice, IDevice
- {
- public event Action<ModuleName, string, string> OnCarrierIdRead;
- public event Action<ModuleName, string> OnCarrierIdReadFailed;
- public event Action<ModuleName, string/*Name*/, string/*Code*/> OnCarrierIdWrite;
- public event Action<ModuleName, string/*Name*/> OnCarrierIdWriteFailed;
- private string _loadPort;
- public CarrierIdReader(string module, string name, string display="", string deviceId="", string address="", string page="", string loadport="") :base(module, name, name, name)
- {
- Module = module;
- Name = name;
- _loadPort = loadport;
- }
- public virtual bool Initialize()
- {
- DEVICE.Register(String.Format("{0}.{1}", Name, "ReadRFID"), (out string reason, int time, object[] param) =>
- {
- bool ret = Read(out reason);
- if (ret)
- {
- reason = string.Format("{0}{1}", Name, "Reading ID");
- return true;
- }
- return false;
- });
- DEVICE.Register(String.Format("{0}.{1}", Name, "WriteRFID"), (out string reason, int time, object[] param) =>
- {
- string id = (string)param[0];
- bool ret = Write(id, out reason);
- if (ret)
- {
- reason = string.Format("{0}{1}", Name, "Writing ID");
- return true;
- }
- return false;
- });
- return true;
- }
-
- public virtual bool Read(out string reason)
- {
- reason = string.Empty;
- return true;
- }
- public virtual bool Write(string id, out string reason)
- {
- reason = string.Empty;
- return true;
- }
-
- public virtual void Monitor()
- {
-
- }
- public virtual void Terminate()
- {
-
- }
- public virtual void Reset()
- {
-
- }
- public virtual bool Connect()
- {
- return true;
- }
- public bool SetManualScanCode(string code)
- {
- ReadOk(code);
- EV.PostInfoLog("System", "Manually scan code");
- return true;
- }
- public void ReadOk(string code)
- {
- if (OnCarrierIdRead != null)
- {
- OnCarrierIdRead((ModuleName)Enum.Parse(typeof(ModuleName), string.IsNullOrEmpty(Module) ? _loadPort : Module), Name, code);
- }
- }
- public void ReadFailed()
- {
- if (OnCarrierIdReadFailed != null)
- {
- OnCarrierIdReadFailed((ModuleName)Enum.Parse(typeof(ModuleName), string.IsNullOrEmpty(Module) ? _loadPort : Module), Name);
- }
- }
- public void WriteOk(string code)
- {
- if (OnCarrierIdWrite != null)
- {
- OnCarrierIdWrite((ModuleName)Enum.Parse(typeof(ModuleName), string.IsNullOrEmpty(Module) ? _loadPort : Module), Name, code);
- }
- }
- public void WriteFailed()
- {
- if (OnCarrierIdWriteFailed != null)
- {
- OnCarrierIdWriteFailed((ModuleName)Enum.Parse(typeof(ModuleName), string.IsNullOrEmpty(Module) ? _loadPort : Module), Name);
- }
- }
- }
-
- }
|