|
- using BPASmartClient.MorkCL.Model.Control;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.MorkCL.Server
- {
- /// <summary>
- /// 机器人服务类
- /// </summary>
- internal class RobotServer : RobotSet, IModbus
- {
- public void Init(string IP = "", int Port = 502, string PortName = "")
- {
- MyModbus = new ModbusTcp();
- MyModbus.WithModbusTcp(IP, Port).UseConnected(() =>
- {
- TaskManage.GetInstance.StartLong(new Action(() =>
- {
- MyModbus.Read<bool[]>("M600".ToModbusAdd(), 9).OnSuccess(s =>
- {
- for (byte i = 0; i < 3; i++)
- {
- MaterialPouringRequest[i] = s[i * 3];
- MaterialPouringComplete[i] = s[i * 3 + 1];
- DiningOutRequest[i] = s[i * 3 + 2];
- }
- });
-
- MyModbus.Read<bool[]>("M630".ToModbusAdd(), 12).OnSuccess(s =>
- {
- for (byte i = 0; i < s.Length; i++) WarehousingComplete[i] = s[i];
- });
-
- MyModbus.Read<ushort>("GI5".ToModbusAdd(), 1).OnSuccess(s => { TaskFeedback = (RobotMainTask)s; });
-
- Thread.Sleep(10);
- }), $"机器人服务-{IP}", true);
- });
- }
-
- private void RobotInit()
- {
- if (EnableState && ProgramRuning) return;
- //if (!CR_Data.Home)
- //{
- // Noticer.GetInstance().Show("煮面机器人初始化失败,机器人不在原点");
- // return;
- //}
-
- while (!EnableState || !ProgramRuning)
- {
- //复位
- RobotReset = true;
- Thread.Sleep(1000);
- RobotReset = false;
- Thread.Sleep(500);
-
- if (!EnableState)
- {
- //上使能
- RobotEnable = true;
- Thread.Sleep(1000);
- RobotEnable = false;
- Thread.Sleep(500);
- }
-
- //启动
- RobotStart = true;
- Thread.Sleep(1000);
- RobotStart = false;
-
- Thread.Sleep(1000);
- }
- }
- }
- }
|