CommunicationBase.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Services
  6. {
  7. /// <summary>
  8. /// 接收事件类
  9. /// </summary>
  10. public class ReceivedEventArgs:EventArgs
  11. {
  12. public byte[] buffer;
  13. public string type;
  14. }
  15. /// <summary>
  16. /// 通讯基类
  17. /// </summary>
  18. public abstract class CommunicationBase:IDisposable
  19. {
  20. public abstract void SendData(byte[] buffer,object o);
  21. public delegate void ReceivedEventHandler(object o, ReceivedEventArgs e);
  22. public event ReceivedEventHandler ReceivedEvent;
  23. public abstract void Open();
  24. public abstract void Close();
  25. private bool isOpen;
  26. public virtual object GetTag()
  27. {
  28. return null;
  29. }
  30. public bool IsOpen
  31. {
  32. get { return isOpen; }
  33. set { isOpen = value; }
  34. }
  35. protected virtual void OnReceivedEvent(object o, ReceivedEventArgs e)
  36. {
  37. if (ReceivedEvent != null)
  38. {
  39. ReceivedEvent(o, e);
  40. }
  41. }
  42. public virtual void Dispose()
  43. {
  44. }
  45. }
  46. }