XYZU_Robot.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. using MahApps.Metro.Controls;
  2. using Opc.Ua;
  3. using Prism;
  4. using Prism.Ioc;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Diagnostics;
  9. using System.Linq;
  10. using System.Runtime.CompilerServices;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using TeamAAS_VP.Core.PLCs;
  15. using TeamAAS_VP.Enums;
  16. using TeamAAS_VP.Interfaces;
  17. using TeamAAS_VP.Models;
  18. using TouchSocket.Core;
  19. using TouchSocket.Sockets;
  20. using static System.Windows.Forms.AxHost;
  21. namespace TeamAAS_VP.Core.Robots
  22. {
  23. /// <summary>
  24. /// Generic multi-axis robot that composes axis objects and uses PLC nodes configured in RobotInfo.PlcRobotParameter
  25. /// to perform coordinated moves (Go/Move/CalibMotion) for 3 or 4 axes.
  26. /// This implementation maps X/Y/Z/(U) axes by name and writes their position nodes then triggers ExecuteMove node.
  27. /// </summary>
  28. public class XYZU_Robot : IRobot, INotifyPropertyChanged
  29. {
  30. public event Action<Guid, object, ConnectedEventArgs> ConnectedEvent;
  31. public event Action<Guid, object, ClosedEventArgs> DisconnectedEvent;
  32. public event Action<Guid, object, ReceivedDataEventArgs> ReceivedEvent;
  33. public event Action<Guid, object, string> SendEvent;
  34. public XYZU_Robot(RobotInfo robot, OpcUaClientPLC pLC)
  35. {
  36. RobotInfo = robot;
  37. Name = robot.RobotName;
  38. Id = robot.Id;
  39. RobotNo = robot.RobotNo;
  40. RobotIp = robot.IP;
  41. RobotPort = robot.Port;
  42. ConnectType = robot.ConnectType;
  43. Terminator = robot.Terminator;
  44. DataEncoding = robot.DataEncoding;
  45. Brand = RobotBrand.XYZ_Platform;
  46. Plc = pLC;
  47. Plc.ConnectChangedEvent += Plc_ConnectChangedEvent;
  48. // build axis list from known RobotInfo.PlcRobotParameter nodes (best-effort)
  49. Axes = new List<Axis>();
  50. // X
  51. var ax = new Axis();
  52. ax.Name = "X";
  53. ax.Index = 1;
  54. ax.Command = robot.PlcRobotParameter.AxixList[0].Command;
  55. ax.Parameter = robot.PlcRobotParameter.AxixList[0].Parameter;
  56. ax.State = robot.PlcRobotParameter.AxixList[0].State;
  57. Axes.Add(ax);
  58. // Y
  59. var ay = new Axis();
  60. ay.Name = "Y";
  61. ay.Index = 2;
  62. ay.Command = robot.PlcRobotParameter.AxixList[1].Command;
  63. ay.Parameter = robot.PlcRobotParameter.AxixList[1].Parameter;
  64. ay.State = robot.PlcRobotParameter.AxixList[1].State;
  65. Axes.Add(ay);
  66. // Z
  67. var az = new Axis();
  68. az.Name = "Z";
  69. az.Index = 3;
  70. az.Command = robot.PlcRobotParameter.AxixList[2].Command;
  71. az.Parameter = robot.PlcRobotParameter.AxixList[2].Parameter;
  72. az.State = robot.PlcRobotParameter.AxixList[2].State;
  73. Axes.Add(az);
  74. // U optional
  75. if (robot.PlcRobotParameter.AxixList.Count >= 4)
  76. {
  77. var au = new Axis();
  78. au.Name = "U";
  79. au.Index = 4;
  80. au.Command = robot.PlcRobotParameter.AxixList[3].Command;
  81. au.Parameter = robot.PlcRobotParameter.AxixList[3].Parameter;
  82. au.State = robot.PlcRobotParameter.AxixList[3].State;
  83. Axes.Add(au);
  84. Brand = RobotBrand.XYZU_Platform;
  85. }
  86. //所有轴的位置节点
  87. var nodeIds = Axes.Where(a => !string.IsNullOrWhiteSpace(a.State.ActPositionNode)).Select(a => a.State.ActPositionNode).ToArray();
  88. List<string> positionNodes = new List<string>(nodeIds);
  89. pLC.SubscribeNodes("AxisPosition",positionNodes, (res) =>
  90. {
  91. if (res.key!= "AxisPosition") return;
  92. for (int i = 0; i < Axes.Count; i++)
  93. {
  94. var axis = Axes[i];
  95. if (axis.State.ActPositionNode.Contains(res.nodeId))
  96. {
  97. float v = Convert.ToSingle(res.value);
  98. switch (axis.Name)
  99. {
  100. case "X": CurrentPosition.X = v; break;
  101. case "Y": CurrentPosition.Y = v; break;
  102. case "Z": CurrentPosition.Z = v; break;
  103. case "U": CurrentPosition.U = v; break;
  104. }
  105. }
  106. }
  107. });
  108. }
  109. private void Plc_ConnectChangedEvent(object arg1, bool arg2)
  110. {
  111. CanExecute = arg2;
  112. if (arg2)
  113. ConnectedEvent?.Invoke(Id, this, null);
  114. else
  115. DisconnectedEvent?.Invoke(Id, this, null);
  116. }
  117. #region 属性
  118. public TcpClient TcpClient { get; private set; }
  119. public TcpService TcpService { get; private set; }
  120. public Guid Id { get; set; }
  121. public string Name { get; set; }
  122. /// <summary>
  123. /// 机器人编号
  124. /// </summary>
  125. public int RobotNo { get; set; }
  126. public int RobotPort { get; private set; }
  127. public string RobotIp { get; private set; }
  128. public TCPConnectType ConnectType { get; private set; }
  129. public Terminator Terminator { get; private set; }
  130. public DataEncoding DataEncoding { get; private set; }
  131. public bool IsConnected
  132. {
  133. get
  134. {
  135. if (Plc != null)
  136. {
  137. return Plc.IsConnected;
  138. }
  139. else
  140. {
  141. return false;
  142. }
  143. }
  144. }
  145. public int Timeout { get; set; } = 120000;
  146. private bool _CanExecute = true;
  147. public bool CanExecute
  148. {
  149. get { return _CanExecute; }
  150. set { SetProperty(ref _CanExecute, value); }
  151. }
  152. public int SelectedTool { get; private set; } = 0;
  153. public RobotBrand Brand { get; private set; }
  154. public OpcUaClientPLC Plc { get; private set; }
  155. public RobotInfo RobotInfo { get; private set; }
  156. public List<Axis> Axes { get; private set; }
  157. /// <summary>
  158. /// 进入调试模式
  159. /// </summary>
  160. /// <returns></returns>
  161. public bool EnterDebugMode { get; set; }
  162. private RPoint _CurrentPosition = new RPoint();
  163. /// <summary>
  164. /// 当前位置
  165. /// </summary>
  166. public RPoint CurrentPosition
  167. {
  168. get { return _CurrentPosition; }
  169. set { SetProperty(ref _CurrentPosition, value); }
  170. }
  171. #endregion
  172. #region 连接
  173. public void Connect()
  174. {
  175. if (Plc.IsConnected)
  176. {
  177. ConnectedEvent?.Invoke(Id, this, null);
  178. }
  179. }
  180. public Task ConnectAsync()
  181. {
  182. if (Plc.IsConnected)
  183. {
  184. ConnectedEvent?.Invoke(Id, this, null);
  185. }
  186. return Task.CompletedTask;
  187. }
  188. public void Disconnect()
  189. {
  190. }
  191. public void Dispose()
  192. {
  193. }
  194. #endregion
  195. #region 控制
  196. public bool Reset() => true;
  197. public Task<bool> ResetAsync() { return Task.Run(() => Reset()); }
  198. public bool Motor(bool state)
  199. {
  200. //遍历所有轴,设置电机状态
  201. //获取所有轴的Poer节点,组成一个集合,一次性写入
  202. Dictionary<string, object> nodesToWrite = new Dictionary<string, object>();
  203. foreach (var axis in Axes)
  204. {
  205. if (!string.IsNullOrWhiteSpace(axis.Command.PowerNode))
  206. {
  207. nodesToWrite[axis.Command.PowerNode] = state;
  208. }
  209. }
  210. if (Plc == null || !Plc.IsConnected) return false;
  211. return Plc.WriteNodes(nodesToWrite);
  212. }
  213. public async Task<bool> MotorAsync(bool state)
  214. {
  215. //遍历所有轴,设置电机状态
  216. //获取所有轴的Poer节点,组成一个集合,一次性写入
  217. Dictionary<string, object> nodesToWrite = new Dictionary<string, object>();
  218. foreach (var axis in Axes)
  219. {
  220. if (!string.IsNullOrWhiteSpace(axis.Command.PowerNode))
  221. {
  222. nodesToWrite[axis.Command.PowerNode] = state;
  223. }
  224. }
  225. if (Plc == null || !Plc.IsConnected) return false;
  226. return await Plc.WriteNodesAsync(nodesToWrite);
  227. }
  228. public bool Power(bool state) => true;
  229. public Task<bool> PowerAsync(bool state) => Task.FromResult(true);
  230. public bool Speed(int value)
  231. {
  232. return true;
  233. }
  234. public Task<bool> SpeedAsync(int value) => Task.FromResult(true);
  235. public bool Speedfactor(int value) => true;
  236. public Task<bool> SpeedfactorAsync(int value) => Task.FromResult(true);
  237. public bool Speeds(double value)
  238. {
  239. //遍历所有轴,设置电机状态
  240. //获取所有轴的Poer节点,组成一个集合,一次性写入
  241. Dictionary<string, object> nodesToWrite = new Dictionary<string, object>();
  242. foreach (var axis in Axes)
  243. {
  244. if (!string.IsNullOrWhiteSpace(axis.Parameter.ManuVelocityNode))
  245. {
  246. nodesToWrite[axis.Command.PowerNode] = (float)value;
  247. }
  248. }
  249. if (Plc == null || !Plc.IsConnected) return false;
  250. return Plc.WriteNodes(nodesToWrite);
  251. }
  252. public async Task<bool> SpeedsAsync(double value)
  253. {
  254. //遍历所有轴,设置电机状态
  255. //获取所有轴的Poer节点,组成一个集合,一次性写入
  256. Dictionary<string, object> nodesToWrite = new Dictionary<string, object>();
  257. foreach (var axis in Axes)
  258. {
  259. if (!string.IsNullOrWhiteSpace(axis.Parameter.ManuVelocityNode))
  260. {
  261. nodesToWrite[axis.Command.PowerNode] = (float)value;
  262. }
  263. }
  264. if (Plc == null || !Plc.IsConnected) return false;
  265. return await Plc.WriteNodesAsync(nodesToWrite);
  266. }
  267. public bool Accel(int value) => true;
  268. public Task<bool> AccelAsync(int value) => Task.FromResult(true);
  269. public bool Accels(double value) => true;
  270. public Task<bool> AccelsAsync(double value) => Task.FromResult(true);
  271. public RPoint GetRobotPos()
  272. {
  273. if (Plc == null || !Plc.IsConnected) return null;
  274. try
  275. {
  276. var nodeIds = Axes.Where(a => !string.IsNullOrWhiteSpace(a.State.ActPositionNode)).Select(a => a.State.ActPositionNode).ToArray();
  277. var data = Plc.ReadNodes(nodeIds);
  278. if (data == null || data.Count == 0) return null;
  279. //获取所有的值
  280. var values = data.Values.ToArray();
  281. RPoint point = new RPoint();
  282. for (int i = 0; i < Axes.Count && i < values.Length; i++)
  283. {
  284. var val = values[i];
  285. float v = 0;
  286. if (val != null)
  287. {
  288. try { v = Convert.ToSingle(val); } catch { }
  289. }
  290. switch (Axes[i].Name)
  291. {
  292. case "X": point.X = v; break;
  293. case "Y": point.Y = v; break;
  294. case "Z": point.Z = v; break;
  295. case "U": point.U = v; break;
  296. default: break;
  297. }
  298. }
  299. return point;
  300. }
  301. catch (Exception ex)
  302. {
  303. LogHelper.WriteLogError("获取机器人位置出错", ex);
  304. throw;
  305. }
  306. }
  307. public Task<RPoint> GetRobotPosAsync()
  308. {
  309. return Task.Run(() => GetRobotPos());
  310. }
  311. public bool Go(RPoint position)
  312. {
  313. return WaitMoveFinished(position);
  314. }
  315. public Task<bool> GoAsync(RPoint position)
  316. {
  317. return Task.Run(() => Go(position));
  318. }
  319. public bool Move(RPoint position) => Go(position);
  320. public Task<bool> MoveAsync(RPoint position) => GoAsync(position);
  321. public bool Jump(RPoint position, double? LimZ) => Go(position);
  322. public Task<bool> JumpAsync(RPoint position, double? LimZ) => GoAsync(position);
  323. public bool Jog(string axis, double distance)
  324. {
  325. //获取当前机器人坐标
  326. var currentPos = GetRobotPos();
  327. if (currentPos == null) return false;
  328. switch (axis.ToUpper())
  329. {
  330. case "X":
  331. currentPos.X += (float)distance;
  332. break;
  333. case "Y":
  334. currentPos.Y += (float)distance;
  335. break;
  336. case "Z":
  337. currentPos.Z += (float)distance;
  338. break;
  339. case "U":
  340. currentPos.U += (float)distance;
  341. break;
  342. default:
  343. return false;
  344. }
  345. return Go(currentPos);
  346. }
  347. public Task<bool> JogAsync(string axis, double distance)
  348. {
  349. return Task.Run(() => Jog(axis, distance));
  350. }
  351. public bool Joint(int joint, double distance)
  352. {
  353. return false;
  354. }
  355. public Task<bool> JointAsync(int joint, double distance) => Task.FromResult(false);
  356. public bool SFree()
  357. {
  358. return Motor(false);
  359. }
  360. public Task<bool> SFreeAsync() => Task.Run(() => SFree());
  361. public bool SLock() => Motor(true);
  362. public Task<bool> SLockAsync() => Task.Run(() => SLock());
  363. public bool CalibMotion(RPoint position, double? LimZ)
  364. {
  365. //先Z轴到安全高度
  366. var currentPos = GetRobotPos();
  367. if (currentPos == null) return false;
  368. if (LimZ.HasValue)
  369. {
  370. currentPos.Z = (float)LimZ.Value;
  371. if (!Go(currentPos)) return false;
  372. }
  373. //再XYU轴到位
  374. currentPos.X = position.X;
  375. currentPos.Y = position.Y;
  376. currentPos.U = position.U;
  377. if (!Go(currentPos)) return false;
  378. //最后Z轴到目标高度
  379. currentPos.Z = position.Z;
  380. return Go(currentPos);
  381. }
  382. public Task<bool> CalibMotionAsync(RPoint position, double? LimZ) => Task.Run(() => CalibMotion(position, LimZ));
  383. public bool CalibOutIO(bool state) => false;
  384. public Task<bool> CalibOutIOAsync(bool state) => Task.FromResult(false);
  385. public bool CalibParame(PickInfo Pick, int Speed, int Accel, bool Power, int WaitSuction, int WaitBlow)
  386. {
  387. return false;
  388. }
  389. public async Task<bool> CalibParameAsync(PickInfo Pick, int Speed, int Accel, bool Power, int WaitSuction, int WaitBlow)
  390. {
  391. if (Plc == null || !Plc.IsConnected) return false;
  392. try
  393. {
  394. Dictionary<string, object> keyValues = new Dictionary<string, object>();
  395. foreach (var axis in Axes)
  396. {
  397. if (string.IsNullOrWhiteSpace(axis.Parameter.ManuVelocityNode)) continue;
  398. string nodeid = axis.Parameter.ManuVelocityNode;
  399. float value = Speed;
  400. keyValues.Add(nodeid, value);
  401. }
  402. // 2. 写入速度给所有轴
  403. if (!Plc.WriteNodes(keyValues))
  404. {
  405. return false;
  406. }
  407. return true;
  408. }
  409. catch (Exception ex)
  410. {
  411. LogHelper.WriteLogError("为XYZU平台设置速度时出错!", ex);
  412. return false;
  413. }
  414. }
  415. /// <summary>
  416. /// 阻塞式等待运动完成
  417. /// </summary>
  418. /// <param name="position"></param>
  419. /// <returns></returns>
  420. private bool WaitMoveFinished(RPoint position)
  421. {
  422. if (Plc == null || !Plc.IsConnected) return false;
  423. try
  424. {
  425. CanExecute = false;
  426. Dictionary<string, object> keyValues = new Dictionary<string, object>();
  427. // 1. 复位所有轴的开始移动命令
  428. //StopMove();
  429. keyValues = new Dictionary<string, object>();
  430. foreach (var axis in Axes)
  431. {
  432. if (string.IsNullOrWhiteSpace(axis.Parameter.ManuPositionNode)) continue;
  433. string nodeid = axis.Parameter.ManuPositionNode;
  434. float value = 0;
  435. switch (axis.Name)
  436. {
  437. case "X": value = position.X; break;
  438. case "Y": value = position.Y; break;
  439. case "Z": value = position.Z; break;
  440. case "U": value = position.U; break;
  441. default: value = 0; break;
  442. }
  443. keyValues.Add(nodeid, value);
  444. }
  445. // 2. 写入位置给所有轴
  446. if (!Plc.WriteNodes(keyValues))
  447. {
  448. return false;
  449. }
  450. // 3. 写入开始移动命令给所有轴
  451. if (!StartMove())
  452. {
  453. return false;
  454. }
  455. // 4. 等待移动完成
  456. Stopwatch sw = new Stopwatch();
  457. sw.Start();
  458. while (true)
  459. {
  460. //检查各轴是否到位和目标位置一致
  461. var (isFinished, isError) = CheckMoveFinished(position);
  462. if (isFinished)
  463. {
  464. StopMove();
  465. if (isError)
  466. {
  467. LogHelper.WriteLogInfo($"机器人执行移动时发生错误,位置:X={position.X},Y={position.Y},Z={position.Z},U={position.U}");
  468. return false;
  469. }
  470. return true;
  471. }
  472. if (sw.ElapsedMilliseconds > Timeout)
  473. {
  474. LogHelper.WriteLogInfo($"机器人执行移动超时,位置:X={position.X},Y={position.Y},Z={position.Z},U={position.U}");
  475. StopMove();
  476. return false;
  477. }
  478. Thread.Sleep(10);
  479. }
  480. }
  481. catch (Exception ex)
  482. {
  483. LogHelper.WriteLogError("执行XYZU平台,阻塞式等待运动完成时出错!", ex);
  484. CanExecute = true;
  485. return false;
  486. }
  487. finally
  488. {
  489. CanExecute = true;
  490. }
  491. }
  492. /// <summary>
  493. /// 开始运动
  494. /// </summary>
  495. /// <returns></returns>
  496. private bool StartMove()
  497. {
  498. Dictionary<string, object> keyValues = new Dictionary<string, object>();
  499. // 1. 复位所有轴的开始移动命令
  500. foreach (var axis in Axes)
  501. {
  502. if (!string.IsNullOrWhiteSpace(axis.Command.ManuPositionNode))
  503. {
  504. keyValues.Add(axis.Command.ManuPositionNode, true);
  505. }
  506. }
  507. return Plc.WriteNodes(keyValues);
  508. }
  509. /// <summary>
  510. /// 停止运动
  511. /// </summary>
  512. /// <returns></returns>
  513. private bool StopMove()
  514. {
  515. Dictionary<string, object> keyValues = new Dictionary<string, object>();
  516. // 1. 复位所有轴的开始移动命令
  517. foreach (var axis in Axes)
  518. {
  519. if (!string.IsNullOrWhiteSpace(axis.Command.ManuPositionNode))
  520. {
  521. keyValues.Add(axis.Command.ManuPositionNode, false);
  522. }
  523. if (!string.IsNullOrWhiteSpace(axis.Command.StopNode))
  524. {
  525. keyValues.Add(axis.Command.StopNode, true);
  526. }
  527. }
  528. bool result = Plc.WriteNodes(keyValues);
  529. // 异步等待100ms后复位停止命令
  530. //Task.Run(async () =>
  531. //{
  532. // await Task.Delay(100);
  533. Thread.Sleep(50);
  534. Dictionary<string, object> resetValues = new Dictionary<string, object>();
  535. foreach (var axis in Axes)
  536. {
  537. if (!string.IsNullOrWhiteSpace(axis.Command.StopNode))
  538. {
  539. resetValues.Add(axis.Command.StopNode, false);
  540. }
  541. }
  542. Plc.WriteNodes(resetValues);
  543. //});
  544. return result;
  545. }
  546. /// <summary>
  547. /// 检查运动是否结束,返回是否停止、是否有错误
  548. /// </summary>
  549. /// <param name="position"></param>
  550. /// <returns></returns>
  551. private (bool isFinished, bool isError) CheckMoveFinished(RPoint position)
  552. {
  553. //检查各轴是否到位和目标位置一致
  554. //批量获取所有轴的定位状态和位置、是否错误
  555. var nodeIds = new List<string>();
  556. foreach (var axis in Axes)
  557. {
  558. if (!string.IsNullOrWhiteSpace(axis.State.PosOKNode))
  559. {
  560. nodeIds.Add(axis.State.PosOKNode);
  561. }
  562. if (!string.IsNullOrWhiteSpace(axis.State.ActPositionNode))
  563. {
  564. nodeIds.Add(axis.State.ActPositionNode);
  565. }
  566. if (!string.IsNullOrWhiteSpace(axis.State.ErrorNode))
  567. {
  568. nodeIds.Add(axis.State.ErrorNode);
  569. }
  570. }
  571. var res = Plc.ReadNodes(nodeIds.ToArray());
  572. bool allOk = true;
  573. bool isAnyError = false;
  574. foreach (var axis in Axes)
  575. {
  576. bool posOk = false;
  577. float actualPos = 0;
  578. bool isError = false;
  579. //获取此轴的定位状态、实际位置、错误状态
  580. if (res.ContainsKey(axis.State.PosOKNode))
  581. {
  582. posOk = (bool)res[axis.State.PosOKNode];
  583. }
  584. if (res.ContainsKey(axis.State.ActPositionNode))
  585. {
  586. try { actualPos = Convert.ToSingle(res[axis.State.ActPositionNode]); } catch { }
  587. }
  588. if (res.ContainsKey(axis.State.ErrorNode))
  589. {
  590. isError = (bool)res[axis.State.ErrorNode];
  591. }
  592. //检查是否到位和位置一致
  593. float targetPos = 0;
  594. switch (axis.Name)
  595. {
  596. case "X": targetPos = position.X; break;
  597. case "Y": targetPos = position.Y; break;
  598. case "Z": targetPos = position.Z; break;
  599. case "U": targetPos = position.U; break;
  600. default: targetPos = 0; break;
  601. }
  602. //如果定位完成且位置一致,则此轴完成,如果有错误则失败
  603. if (!(posOk && Math.Abs(actualPos - targetPos) < 0.02))
  604. {
  605. if (isError)
  606. {
  607. isAnyError = true;
  608. break;
  609. }
  610. allOk = false;
  611. break;
  612. }
  613. }
  614. return (allOk, isAnyError);
  615. }
  616. #endregion
  617. #region 收发数据
  618. public string SendAndReceive(string send) => string.Empty;
  619. public Task<string> SendAndReceiveAsync(string send) => Task.FromResult(string.Empty);
  620. public string SendAndReceive(ITcpSessionClient client, string send) => string.Empty;
  621. public Task<string> SendAndReceiveAsync(ITcpSessionClient client, string send) => Task.FromResult(string.Empty);
  622. public void Send(string send) { }
  623. public Task SendAsync(string send) => Task.CompletedTask;
  624. public void Send(ITcpSessionClient client, string send) { }
  625. public Task SendAsync(ITcpSessionClient client, string send) => Task.CompletedTask;
  626. public Encoding GetEncoding() => Encoding.Default;
  627. #endregion
  628. #region 属性通知
  629. public event PropertyChangedEventHandler PropertyChanged;
  630. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  631. {
  632. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  633. storage = value;
  634. OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
  635. return true;
  636. }
  637. protected void OnPropertyChanged(PropertyChangedEventArgs args) => PropertyChanged?.Invoke(this, args);
  638. #endregion
  639. #region IRobot SetTool/SelectTool stubs
  640. public bool SetTool(int index, double x, double y) => true;
  641. public Task<bool> SetToolAsync(int index, double x, double y) => Task.FromResult(true);
  642. public bool SelectTool(int index) => true;
  643. public Task<bool> SelectToolAsync(int index) => Task.FromResult(true);
  644. #endregion
  645. }
  646. }