终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MCUMachine.cs 2.0 KiB

2 vuotta sitten
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using BPASmartClient.EventBus;
  2. using BPASmartClient.Model.PLC;
  3. using BPASmartClient.Model.单片机;
  4. using BPASmartClient.Peripheral;
  5. using BPASmartClient.SerialPort;
  6. using static BPASmartClient.EventBus.EventBus;
  7. namespace BPASmartClient.MCU
  8. {
  9. public class MCUMachine : BasePeripheral
  10. {
  11. MCUSerialHelper mCUSerialHelper = new MCUSerialHelper();
  12. public override void Init()
  13. {
  14. mCUSerialHelper.Open(communicationPar.SerialPort, communicationPar.BaudRate);
  15. EventBus.EventBus.GetInstance().Subscribe<ReadMcu>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  16. {
  17. if (@event == null) return;
  18. var par = @event as ReadMcu;
  19. if (status != null)
  20. {
  21. SetStatus(par?.TagName, mCUSerialHelper.GetInputStatus(Convert.ToByte(par?.ReadPar)));
  22. }
  23. });
  24. EventBus.EventBus.GetInstance().Subscribe<WriteMcu>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  25. {
  26. if (@event == null) return;
  27. var par = @event as WriteMcu;
  28. switch (par?.TagName)
  29. {
  30. case "OutputControl":
  31. mCUSerialHelper.OutputControl(Convert.ToByte(par?.Address), Convert.ToBoolean(par?.Value));
  32. break;
  33. case "ServoControl":
  34. mCUSerialHelper.ServoControl(Convert.ToByte(par?.Address), Convert.ToByte(par?.Value));
  35. break;
  36. default:
  37. break;
  38. }
  39. });
  40. }
  41. //public override void ReadData(string address)
  42. //{
  43. //}
  44. public override void Start()
  45. {
  46. }
  47. public override void Stop()
  48. {
  49. }
  50. public override void WriteData(string address, object value)
  51. {
  52. }
  53. protected override void InitStatus()
  54. {
  55. }
  56. }
  57. }