终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

123 righe
3.8 KiB

  1. using BPASmartClient.MorkCL.Model.Control;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace BPASmartClient.MorkCL.Server
  8. {
  9. /// <summary>
  10. /// 机器人服务类
  11. /// </summary>
  12. internal class RobotServer : RobotSet, IModbus
  13. {
  14. public void Init(string IP = "", int Port = 502, string PortName = "")
  15. {
  16. MyModbus = new ModbusTcp();
  17. MyModbus.WithModbusTcp(IP, Port).UseConnected(() =>
  18. {
  19. ((ModbusTcp)MyModbus).master.Transport.ReadTimeout = 3000;
  20. ((ModbusTcp)MyModbus).master.Transport.WriteTimeout = 3000;
  21. TaskManage.GetInstance.StartLong(new Action(() =>
  22. {
  23. MyModbus.Read<bool[]>("GM600".ToModbusAdd(), 9).OnSuccess(s =>
  24. {
  25. for (byte i = 0; i < 3; i++)
  26. {
  27. MaterialPouringRequest[i] = s[i * 3];
  28. MaterialPouringComplete[i] = s[i * 3 + 1];
  29. DiningOutRequest[i] = s[i * 3 + 2];
  30. }
  31. });
  32. Thread.Sleep(20);
  33. MyModbus.Read<bool>("GM620".ToModbusAdd()).OnSuccess((b)=> { Home = b; });
  34. Thread.Sleep(20);
  35. MyModbus.Read<bool[]>("GM630".ToModbusAdd(), 12).OnSuccess(s =>
  36. {
  37. for (byte i = 0; i < s.Length; i++) WarehousingComplete[i] = s[i];
  38. });
  39. Thread.Sleep(20);
  40. MyModbus.Read<ushort>("GI5".ToModbusAdd(), 1).OnSuccess(s => { TaskFeedback = (RobotMainTask)s; });
  41. IsIdle = (TaskFeedback == RobotMainTask.无任务 && Home);
  42. Thread.Sleep(20);
  43. MyModbus.Read<bool>("GM130".ToModbusAdd(), 1).OnSuccess((b) => { RemoteMode = b; });
  44. Thread.Sleep(20);
  45. }), $"机器人服务-{IP}", true);
  46. });
  47. }
  48. public void WriteValue<T>(string address, T value)
  49. {
  50. throw new NotImplementedException();
  51. }
  52. private void RobotInit()
  53. {
  54. if (EnableState && ProgramRuning) return;
  55. //if (!CR_Data.Home)
  56. //{
  57. // Noticer.GetInstance().Show("煮面机器人初始化失败,机器人不在原点");
  58. // return;
  59. //}
  60. while (!EnableState || !ProgramRuning)
  61. {
  62. //复位
  63. RobotReset = true;
  64. Thread.Sleep(1000);
  65. RobotReset = false;
  66. Thread.Sleep(500);
  67. if (!EnableState)
  68. {
  69. //上使能
  70. RobotEnable = true;
  71. Thread.Sleep(1000);
  72. RobotEnable = false;
  73. Thread.Sleep(500);
  74. }
  75. //启动
  76. RobotStart = true;
  77. Thread.Sleep(1000);
  78. RobotStart = false;
  79. Thread.Sleep(1000);
  80. }
  81. }
  82. public bool InitVariable()
  83. {
  84. if (MyModbus is not null && MyModbus.IsConnected())
  85. {
  86. try
  87. {
  88. MyModbus.Write<ushort>("GI0".ToModbusAdd(), 0);
  89. MyModbus.Write<ushort>("GI1".ToModbusAdd(), 0);
  90. for (int i = 0; i <= 8; i++)
  91. {
  92. MyModbus.Write<bool>(("GM" + (500 + i).ToString()).ToModbusAdd(), false);
  93. }
  94. return true;
  95. }
  96. catch (Exception)
  97. {
  98. return false;
  99. }
  100. }
  101. else
  102. return false;
  103. }
  104. }
  105. }