SchneiderRobot.cs 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using TeamAAS.Robot.Core.Robots;
  9. using TeamAAS.Robot.Enums;
  10. using TeamAAS.Robot.Interfaces;
  11. using TeamAAS.Robot.Models;
  12. using TeamAAS.Robot.Attributes;
  13. using TeamAAS.Communication.Enums;
  14. using static TeamAAS.Robot.Core.CoordinateTransformer;
  15. namespace TeamAAS.Robot.Core.Robots
  16. {
  17. [Robot("Schneider", RobotBrand.Schneider)]
  18. public class SchneiderRobot : IRobot, INotifyPropertyChanged
  19. {
  20. private RobotTcpClient _tcp;
  21. public event Action<Guid, object, byte[]> ConnectedEvent;
  22. public event Action<Guid, object, byte[]> DisconnectedEvent;
  23. public event Action<Guid, object, byte[]> ReceivedEvent;
  24. public event Action<Guid, object, string> SendEvent;
  25. public SchneiderRobot(RobotInfo robot)
  26. {
  27. Id = robot.Id;
  28. Name = robot.RobotName;
  29. RobotNo = robot.RobotNo;
  30. RobotIp = robot.IP;
  31. RobotPort = robot.Port;
  32. ConnectType = robot.ConnectType;
  33. Terminator = robot.Terminator;
  34. DataEncoding = robot.DataEncoding;
  35. Brand = robot.RobotBrand;
  36. _tcp = new RobotTcpClient(RobotIp, RobotPort, ConnectType, Terminator, DataEncoding);
  37. _tcp.OnConnected += Tcp_OnConnected;
  38. _tcp.OnDisconnected += Tcp_OnDisconnected;
  39. _tcp.OnReceived += Tcp_OnReceived;
  40. _tcp.OnSent += Tcp_OnSent;
  41. }
  42. #region 属性
  43. public RobotTcpClient Tcp => _tcp;
  44. public Guid Id { get; set; }
  45. public string Name { get; set; }
  46. /// <summary>
  47. /// 机器人编号
  48. /// </summary>
  49. public int RobotNo { get; set; }
  50. public int RobotPort { get; private set; }
  51. public string RobotIp { get; private set; }
  52. public TCPConnectType ConnectType { get; private set; }
  53. public Terminator Terminator { get; private set; }
  54. public DataEncoding DataEncoding { get; private set; }
  55. public bool IsConnected { get { return _tcp.IsConnected; } }
  56. public int Timeout { get; set; } = 5000;
  57. private bool _CanExecute = false;
  58. public bool CanExecute
  59. {
  60. get { return _CanExecute; }
  61. set { SetProperty(ref _CanExecute, value); }
  62. }
  63. public int SelectedTool { get; private set; } = 0;
  64. public RobotBrand Brand { get; private set; }
  65. /// <summary>
  66. /// 进入调试模式
  67. /// </summary>
  68. /// <returns></returns>
  69. public bool EnterDebugMode { get; set; }
  70. #endregion
  71. #region 事件接收
  72. private void Tcp_OnConnected(byte[] data)
  73. {
  74. CanExecute = true;
  75. ConnectedEvent?.Invoke(this.Id, _tcp, data);
  76. }
  77. private void Tcp_OnDisconnected(byte[] data)
  78. {
  79. CanExecute = false;
  80. DisconnectedEvent?.Invoke(this.Id, _tcp, data);
  81. }
  82. private void Tcp_OnReceived(byte[] data)
  83. {
  84. ReceivedEvent?.Invoke(this.Id, _tcp, data);
  85. }
  86. private void Tcp_OnSent(string data)
  87. {
  88. SendEvent?.Invoke(this.Id, _tcp, data);
  89. }
  90. #endregion
  91. #region 连接
  92. public void Connect()
  93. {
  94. _tcp.Connect();
  95. }
  96. public async Task ConnectAsync()
  97. {
  98. await _tcp.ConnectAsync();
  99. }
  100. public void Disconnect()
  101. {
  102. _tcp.Disconnect();
  103. }
  104. public void Dispose()
  105. {
  106. _tcp?.Dispose();
  107. }
  108. #endregion
  109. #region 控制
  110. public bool Reset()
  111. {
  112. try
  113. {
  114. CanExecute = false;
  115. string rev = SendAndReceive($"Reset");
  116. if (rev.Contains("Reset"))
  117. return true;
  118. else
  119. return false;
  120. }
  121. catch (Exception ex)
  122. {
  123. // LogHelper removed
  124. CanExecute = true;
  125. throw ex;
  126. }
  127. finally
  128. {
  129. CanExecute = true;
  130. }
  131. }
  132. public async Task<bool> ResetAsync()
  133. {
  134. try
  135. {
  136. CanExecute = false;
  137. string rev = await SendAndReceiveAsync($"Reset");
  138. if (rev.Contains("Reset"))
  139. return true;
  140. else
  141. return false;
  142. }
  143. catch (Exception ex)
  144. {
  145. // LogHelper removed
  146. CanExecute = true;
  147. throw ex;
  148. }
  149. finally
  150. {
  151. CanExecute = true;
  152. }
  153. }
  154. public bool Motor(bool state)
  155. {
  156. try
  157. {
  158. CanExecute = false;
  159. int v = state ? 1 : 0;
  160. string rev = SendAndReceive($"Motor,{v}");
  161. if (rev.Contains("Motor"))
  162. return true;
  163. else
  164. return false;
  165. }
  166. catch (Exception ex)
  167. {
  168. // LogHelper removed
  169. CanExecute = true;
  170. throw ex;
  171. }
  172. finally
  173. {
  174. CanExecute = true;
  175. }
  176. }
  177. public async Task<bool> MotorAsync(bool state)
  178. {
  179. try
  180. {
  181. CanExecute = false;
  182. int v = state ? 1 : 0;
  183. string rev = await SendAndReceiveAsync($"Motor,{v}");
  184. if (rev.Contains("Motor"))
  185. return true;
  186. else
  187. return false;
  188. }
  189. catch (Exception ex)
  190. {
  191. // LogHelper removed
  192. CanExecute = true;
  193. throw ex;
  194. }
  195. finally
  196. {
  197. CanExecute = true;
  198. }
  199. }
  200. public bool Power(bool state)
  201. {
  202. try
  203. {
  204. CanExecute = false;
  205. int v = state ? 1 : 0;
  206. string rev = SendAndReceive($"Power,{v}");
  207. if (rev.Contains("Power"))
  208. return true;
  209. else
  210. return false;
  211. }
  212. catch (Exception ex)
  213. {
  214. // LogHelper removed
  215. CanExecute = true;
  216. throw ex;
  217. }
  218. finally
  219. {
  220. CanExecute = true;
  221. }
  222. }
  223. public async Task<bool> PowerAsync(bool state)
  224. {
  225. try
  226. {
  227. CanExecute = false;
  228. int v = state ? 1 : 0;
  229. string rev = await SendAndReceiveAsync($"Power,{v}");
  230. if (rev.Contains("Power"))
  231. return true;
  232. else
  233. return false;
  234. }
  235. catch (Exception ex)
  236. {
  237. // LogHelper removed
  238. CanExecute = true;
  239. throw ex;
  240. }
  241. finally
  242. {
  243. CanExecute = true;
  244. }
  245. }
  246. public bool Speed(int value)
  247. {
  248. try
  249. {
  250. CanExecute = false;
  251. string rev = SendAndReceive($"Speed,{value}");
  252. if (rev.Contains("Speed"))
  253. return true;
  254. else
  255. return false;
  256. }
  257. catch (Exception ex)
  258. {
  259. // LogHelper removed
  260. CanExecute = true;
  261. throw ex;
  262. }
  263. finally
  264. {
  265. CanExecute = true;
  266. }
  267. }
  268. public async Task<bool> SpeedAsync(int value)
  269. {
  270. try
  271. {
  272. CanExecute = false;
  273. string rev = await SendAndReceiveAsync($"Speed,{value}");
  274. if (rev.Contains("Speed"))
  275. return true;
  276. else
  277. return false;
  278. }
  279. catch (Exception ex)
  280. {
  281. // LogHelper removed
  282. CanExecute = true;
  283. throw ex;
  284. }
  285. finally
  286. {
  287. CanExecute = true;
  288. }
  289. }
  290. public bool Speedfactor(int value)
  291. {
  292. try
  293. {
  294. CanExecute = false;
  295. string rev = SendAndReceive($"Speedfactor,{value}");
  296. if (rev.Contains("Speedfactor"))
  297. return true;
  298. else
  299. return false;
  300. }
  301. catch (Exception ex)
  302. {
  303. // LogHelper removed
  304. CanExecute = true;
  305. throw ex;
  306. }
  307. finally
  308. {
  309. CanExecute = true;
  310. }
  311. }
  312. public async Task<bool> SpeedfactorAsync(int value)
  313. {
  314. try
  315. {
  316. CanExecute = false;
  317. string rev = await SendAndReceiveAsync($"Speedfactor,{value}");
  318. if (rev.Contains("Speedfactor"))
  319. return true;
  320. else
  321. return false;
  322. }
  323. catch (Exception ex)
  324. {
  325. // LogHelper removed
  326. CanExecute = true;
  327. throw ex;
  328. }
  329. finally
  330. {
  331. CanExecute = true;
  332. }
  333. }
  334. public bool Speeds(double value)
  335. {
  336. try
  337. {
  338. CanExecute = false;
  339. string rev = SendAndReceive($"Speeds,{value}");
  340. if (rev.Contains("Speeds"))
  341. return true;
  342. else
  343. return false;
  344. }
  345. catch (Exception ex)
  346. {
  347. // LogHelper removed
  348. CanExecute = true;
  349. throw ex;
  350. }
  351. finally
  352. {
  353. CanExecute = true;
  354. }
  355. }
  356. public async Task<bool> SpeedsAsync(double value)
  357. {
  358. try
  359. {
  360. CanExecute = false;
  361. string rev = await SendAndReceiveAsync($"Speeds,{value}");
  362. if (rev.Contains("Speeds"))
  363. return true;
  364. else
  365. return false;
  366. }
  367. catch (Exception ex)
  368. {
  369. // LogHelper removed
  370. CanExecute = true;
  371. throw ex;
  372. }
  373. finally
  374. {
  375. CanExecute = true;
  376. }
  377. }
  378. public bool Accel(int value)
  379. {
  380. try
  381. {
  382. CanExecute = false;
  383. string rev = SendAndReceive($"Accel,{value},{value}");
  384. if (rev.Contains("Accel"))
  385. return true;
  386. else
  387. return false;
  388. }
  389. catch (Exception ex)
  390. {
  391. // LogHelper removed
  392. CanExecute = true;
  393. throw ex;
  394. }
  395. finally
  396. {
  397. CanExecute = true;
  398. }
  399. }
  400. public async Task<bool> AccelAsync(int value)
  401. {
  402. try
  403. {
  404. CanExecute = false;
  405. string rev = await SendAndReceiveAsync($"Accel,{value},{value}");
  406. if (rev.Contains("Accel"))
  407. return true;
  408. else
  409. return false;
  410. }
  411. catch (Exception ex)
  412. {
  413. // LogHelper removed
  414. CanExecute = true;
  415. throw ex;
  416. }
  417. finally
  418. {
  419. CanExecute = true;
  420. }
  421. }
  422. public bool Accels(double value)
  423. {
  424. try
  425. {
  426. CanExecute = false;
  427. string rev = SendAndReceive($"Accels,{value},{value}");
  428. if (rev.Contains("Accels"))
  429. return true;
  430. else
  431. return false;
  432. }
  433. catch (Exception ex)
  434. {
  435. // LogHelper removed
  436. CanExecute = true;
  437. throw ex;
  438. }
  439. finally
  440. {
  441. CanExecute = true;
  442. }
  443. }
  444. public async Task<bool> AccelsAsync(double value)
  445. {
  446. try
  447. {
  448. CanExecute = false;
  449. string rev = await SendAndReceiveAsync($"Accels,{value},{value}");
  450. if (rev.Contains("Accels"))
  451. return true;
  452. else
  453. return false;
  454. }
  455. catch (Exception ex)
  456. {
  457. // LogHelper removed
  458. CanExecute = true;
  459. throw ex;
  460. }
  461. finally
  462. {
  463. CanExecute = true;
  464. }
  465. }
  466. public RPoint GetRobotPos()
  467. {
  468. try
  469. {
  470. CanExecute = false;
  471. string rev = SendAndReceive($"GetRobotPos");
  472. if (rev.Contains("GetRobotPos"))
  473. {
  474. RPoint point = new RPoint();
  475. var items = rev.Split(',');
  476. point.X = Convert.ToSingle(items[1]);
  477. point.Y = Convert.ToSingle(items[2]);
  478. point.Z = Convert.ToSingle(items[3]);
  479. point.U = Convert.ToSingle(items[4]);
  480. point.V = Convert.ToSingle(items[5]);
  481. point.W = Convert.ToSingle(items[6]);
  482. point.Hand = (RobotHand)Convert.ToInt32(items[7]);
  483. point.Local = Convert.ToInt32(items[8]);
  484. point.Tool = Convert.ToInt32(items[9]);
  485. return point;
  486. }
  487. else
  488. return null;
  489. }
  490. catch (Exception ex)
  491. {
  492. // LogHelper removed
  493. CanExecute = true;
  494. throw ex;
  495. }
  496. finally
  497. {
  498. CanExecute = true;
  499. }
  500. }
  501. public async Task<RPoint> GetRobotPosAsync()
  502. {
  503. try
  504. {
  505. CanExecute = false;
  506. string rev = await SendAndReceiveAsync($"GetRobotPos");
  507. if (rev.Contains("GetRobotPos"))
  508. {
  509. RPoint point = new RPoint();
  510. var items = rev.Split(',');
  511. point.X = Convert.ToSingle(items[1]);
  512. point.Y = Convert.ToSingle(items[2]);
  513. point.Z = Convert.ToSingle(items[3]);
  514. point.U = Convert.ToSingle(items[4]);
  515. point.V = Convert.ToSingle(items[5]);
  516. point.W = Convert.ToSingle(items[6]);
  517. point.Hand = (RobotHand)Convert.ToInt32(items[7]);
  518. point.Local = Convert.ToInt32(items[8]);
  519. point.Tool = Convert.ToInt32(items[9]);
  520. return point;
  521. }
  522. else
  523. return null;
  524. }
  525. catch (Exception ex)
  526. {
  527. // LogHelper removed
  528. CanExecute = true;
  529. throw ex;
  530. }
  531. finally
  532. {
  533. CanExecute = true;
  534. }
  535. }
  536. public bool Jog(string axis, double distance)
  537. {
  538. try
  539. {
  540. CanExecute = false;
  541. string rev = SendAndReceive($"Jog,{axis},{distance}");
  542. if (rev.Contains("Jog"))
  543. return true;
  544. else
  545. return false;
  546. }
  547. catch (Exception ex)
  548. {
  549. // LogHelper removed
  550. CanExecute = true;
  551. throw ex;
  552. }
  553. finally
  554. {
  555. CanExecute = true;
  556. }
  557. }
  558. public async Task<bool> JogAsync(string axis, double distance)
  559. {
  560. try
  561. {
  562. CanExecute = false;
  563. string rev = await SendAndReceiveAsync($"Jog,{axis},{distance}");
  564. if (rev.Contains("Jog"))
  565. return true;
  566. else
  567. return false;
  568. }
  569. catch (Exception ex)
  570. {
  571. // LogHelper removed
  572. CanExecute = true;
  573. throw ex;
  574. }
  575. finally
  576. {
  577. CanExecute = true;
  578. }
  579. }
  580. public bool Joint(int joint, double distance)
  581. {
  582. try
  583. {
  584. CanExecute = false;
  585. string rev = SendAndReceive($"Joint,{joint},{distance}");
  586. if (rev.Contains("Joint"))
  587. return true;
  588. else
  589. return false;
  590. }
  591. catch (Exception ex)
  592. {
  593. // LogHelper removed
  594. CanExecute = true;
  595. throw ex;
  596. }
  597. finally
  598. {
  599. CanExecute = true;
  600. }
  601. }
  602. public async Task<bool> JointAsync(int joint, double distance)
  603. {
  604. try
  605. {
  606. CanExecute = false;
  607. string rev = await SendAndReceiveAsync($"Joint,{joint},{distance}");
  608. if (rev.Contains("Joint"))
  609. return true;
  610. else
  611. return false;
  612. }
  613. catch (Exception ex)
  614. {
  615. // LogHelper removed
  616. CanExecute = true;
  617. throw ex;
  618. }
  619. finally
  620. {
  621. CanExecute = true;
  622. }
  623. }
  624. public bool Go(RPoint position)
  625. {
  626. try
  627. {
  628. CanExecute = false;
  629. string rev = SendAndReceive($"Go,{position.X},{position.Y},{position.Z},{position.U},{position.V},{position.W},{(int)position.Hand},{position.Local},{position.Tool}");
  630. if (rev.Contains("Go"))
  631. return true;
  632. else
  633. return false;
  634. }
  635. catch (Exception ex)
  636. {
  637. // LogHelper removed
  638. CanExecute = true;
  639. throw ex;
  640. }
  641. finally
  642. {
  643. CanExecute = true;
  644. }
  645. }
  646. public async Task<bool> GoAsync(RPoint position)
  647. {
  648. try
  649. {
  650. CanExecute = false;
  651. string rev = await SendAndReceiveAsync($"Go,{Math.Round(position.X, 3)},{Math.Round(position.Y, 3)},{Math.Round(position.Z, 3)},{Math.Round(position.U, 3)},{Math.Round(position.V, 3)},{Math.Round(position.W, 3)},{(int)position.Hand},{position.Local},{position.Tool}");
  652. if (rev.Contains("Go"))
  653. return true;
  654. else
  655. return false;
  656. }
  657. catch (Exception ex)
  658. {
  659. // LogHelper removed
  660. CanExecute = true;
  661. throw ex;
  662. }
  663. finally
  664. {
  665. CanExecute = true;
  666. }
  667. }
  668. public bool Jump(RPoint position, double? LimZ)
  669. {
  670. try
  671. {
  672. CanExecute = false;
  673. double limz = LimZ == null ? 0 : (double)LimZ;
  674. string rev = SendAndReceive($"Jump,{Math.Round(position.X, 3)},{Math.Round(position.Y, 3)},{Math.Round(position.Z, 3)},{Math.Round(position.U, 3)},{Math.Round(position.V, 3)},{Math.Round(position.W, 3)},{(int)position.Hand},{position.Local},{position.Tool},{Math.Round(limz, 3)}");
  675. if (rev.Contains("Jump"))
  676. return true;
  677. else
  678. return false;
  679. }
  680. catch (Exception ex)
  681. {
  682. // LogHelper removed
  683. CanExecute = true;
  684. throw ex;
  685. }
  686. finally
  687. {
  688. CanExecute = true;
  689. }
  690. }
  691. public async Task<bool> JumpAsync(RPoint position, double? LimZ)
  692. {
  693. try
  694. {
  695. CanExecute = false;
  696. double limz = LimZ == null ? 0 : (double)LimZ;
  697. string rev = await SendAndReceiveAsync($"Jump,{Math.Round(position.X, 3)},{Math.Round(position.Y, 3)},{Math.Round(position.Z, 3)},{Math.Round(position.U, 3)},{Math.Round(position.V, 3)},{Math.Round(position.W, 3)},{(int)position.Hand},{position.Local},{position.Tool},{Math.Round(limz, 3)}");
  698. if (rev.Contains("Jump"))
  699. return true;
  700. else
  701. return false;
  702. }
  703. catch (Exception ex)
  704. {
  705. // LogHelper removed
  706. CanExecute = true;
  707. throw ex;
  708. }
  709. finally
  710. {
  711. CanExecute = true;
  712. }
  713. }
  714. public bool Move(RPoint position)
  715. {
  716. try
  717. {
  718. CanExecute = false;
  719. string rev = SendAndReceive($"Move,{position.X},{position.Y},{position.Z},{position.U},{position.V},{position.W},{(int)position.Hand},{position.Local},{position.Tool}");
  720. if (rev.Contains("Move"))
  721. return true;
  722. else
  723. return false;
  724. }
  725. catch (Exception ex)
  726. {
  727. // LogHelper removed
  728. CanExecute = true;
  729. throw ex;
  730. }
  731. finally
  732. {
  733. CanExecute = true;
  734. }
  735. }
  736. public async Task<bool> MoveAsync(RPoint position)
  737. {
  738. try
  739. {
  740. CanExecute = false;
  741. string rev = await SendAndReceiveAsync($"Move,{Math.Round(position.X, 3)},{Math.Round(position.Y, 3)},{Math.Round(position.Z, 3)},{Math.Round(position.U, 3)},{Math.Round(position.V, 3)},{Math.Round(position.W, 3)},{(int)position.Hand},{position.Local},{position.Tool}");
  742. if (rev.Contains("Move"))
  743. return true;
  744. else
  745. return false;
  746. }
  747. catch (Exception ex)
  748. {
  749. // LogHelper removed
  750. CanExecute = true;
  751. throw ex;
  752. }
  753. finally
  754. {
  755. CanExecute = true;
  756. }
  757. }
  758. public bool SFree()
  759. {
  760. try
  761. {
  762. CanExecute = false;
  763. string rev = SendAndReceive($"SFree");
  764. if (rev.Contains("SFree"))
  765. return true;
  766. else
  767. return false;
  768. }
  769. catch (Exception ex)
  770. {
  771. // LogHelper removed
  772. CanExecute = true;
  773. throw ex;
  774. }
  775. finally
  776. {
  777. CanExecute = true;
  778. }
  779. }
  780. public async Task<bool> SFreeAsync()
  781. {
  782. try
  783. {
  784. CanExecute = false;
  785. string rev = await SendAndReceiveAsync($"SFree");
  786. if (rev.Contains("SFree"))
  787. return true;
  788. else
  789. return false;
  790. }
  791. catch (Exception ex)
  792. {
  793. // LogHelper removed
  794. CanExecute = true;
  795. throw ex;
  796. }
  797. finally
  798. {
  799. CanExecute = true;
  800. }
  801. }
  802. public bool SLock()
  803. {
  804. try
  805. {
  806. CanExecute = false;
  807. string rev = SendAndReceive($"SLock");
  808. if (rev.Contains("SLock"))
  809. return true;
  810. else
  811. return false;
  812. }
  813. catch (Exception ex)
  814. {
  815. // LogHelper removed
  816. CanExecute = true;
  817. throw ex;
  818. }
  819. finally
  820. {
  821. CanExecute = true;
  822. }
  823. }
  824. public async Task<bool> SLockAsync()
  825. {
  826. try
  827. {
  828. CanExecute = false;
  829. string rev = await SendAndReceiveAsync($"SLock");
  830. if (rev.Contains("SLock"))
  831. return true;
  832. else
  833. return false;
  834. }
  835. catch (Exception ex)
  836. {
  837. // LogHelper removed
  838. CanExecute = true;
  839. throw ex;
  840. }
  841. finally
  842. {
  843. CanExecute = true;
  844. }
  845. }
  846. public bool CalibMotion(RPoint position, double? LimZ)
  847. {
  848. try
  849. {
  850. CanExecute = false;
  851. double limz = LimZ == null ? 0 : (double)LimZ;
  852. string rev = SendAndReceive($"CalibMotion,{position.X},{position.Y},{position.Z},{position.U},{position.V},{position.W},{(int)position.Hand},{position.Local},{position.Tool},{limz}");
  853. if (rev.Contains("CalibMotion"))
  854. return true;
  855. else
  856. return false;
  857. }
  858. catch (Exception ex)
  859. {
  860. // LogHelper removed
  861. CanExecute = true;
  862. throw ex;
  863. }
  864. finally
  865. {
  866. CanExecute = true;
  867. }
  868. }
  869. public async Task<bool> CalibMotionAsync(RPoint position, double? LimZ)
  870. {
  871. try
  872. {
  873. CanExecute = false;
  874. double limz = LimZ == null ? 0 : (double)LimZ;
  875. string rev = await SendAndReceiveAsync($"CalibMotion,{Math.Round(position.X, 3)},{Math.Round(position.Y, 3)},{Math.Round(position.Z, 3)},{Math.Round(position.U, 3)},{Math.Round(position.V, 3)},{Math.Round(position.W, 3)},{(int)position.Hand},{position.Local},{position.Tool},{Math.Round(limz, 2)}");
  876. if (rev.Contains("CalibMotion"))
  877. return true;
  878. else
  879. return false;
  880. }
  881. catch (Exception ex)
  882. {
  883. // LogHelper removed
  884. CanExecute = true;
  885. throw ex;
  886. }
  887. finally
  888. {
  889. CanExecute = true;
  890. }
  891. }
  892. public bool CalibOutIO(bool state)
  893. {
  894. try
  895. {
  896. CanExecute = false;
  897. int va = state ? 1 : 0;
  898. string rev = SendAndReceive($"CalibOutIO,{va}");
  899. if (rev.Contains("CalibOutIO"))
  900. return true;
  901. else
  902. return false;
  903. }
  904. catch (Exception ex)
  905. {
  906. // LogHelper removed
  907. CanExecute = true;
  908. throw ex;
  909. }
  910. finally
  911. {
  912. CanExecute = true;
  913. }
  914. }
  915. public async Task<bool> CalibOutIOAsync(bool state)
  916. {
  917. try
  918. {
  919. CanExecute = false;
  920. int va = state ? 1 : 0;
  921. string rev = await SendAndReceiveAsync($"CalibOutIO,{va}");
  922. if (rev.Contains("CalibOutIO"))
  923. return true;
  924. else
  925. return false;
  926. }
  927. catch (Exception ex)
  928. {
  929. // LogHelper removed
  930. CanExecute = true;
  931. throw ex;
  932. }
  933. finally
  934. {
  935. CanExecute = true;
  936. }
  937. }
  938. public bool CalibParame(PickInfo Pick, int Speed, int Accel, bool Power, int WaitSuction, int WaitBlow)
  939. {
  940. try
  941. {
  942. CanExecute = false;
  943. int va = Power ? 1 : 0;
  944. string rev = SendAndReceive($"CalibParame,{(int)Pick.PickPlaceModel},{Pick.Inhal},{Pick.Blow},{Speed},{Accel},{va},{WaitSuction},{WaitBlow}");
  945. if (rev.Contains("CalibParame"))
  946. return true;
  947. else
  948. return false;
  949. }
  950. catch (Exception ex)
  951. {
  952. // LogHelper removed
  953. CanExecute = true;
  954. throw ex;
  955. }
  956. finally
  957. {
  958. CanExecute = true;
  959. }
  960. }
  961. public async Task<bool> CalibParameAsync(PickInfo Pick, int Speed, int Accel, bool Power, int WaitSuction, int WaitBlow)
  962. {
  963. try
  964. {
  965. CanExecute = false;
  966. int va = Power ? 1 : 0;
  967. string rev = await SendAndReceiveAsync($"CalibParame,{(int)Pick.PickPlaceModel},{Pick.Inhal},{Pick.Blow},{Speed},{Accel},{va},{WaitSuction},{WaitBlow}");
  968. if (rev.Contains("CalibParame"))
  969. return true;
  970. else
  971. return false;
  972. }
  973. catch (Exception ex)
  974. {
  975. // LogHelper removed
  976. CanExecute = true;
  977. throw ex;
  978. }
  979. finally
  980. {
  981. CanExecute = true;
  982. }
  983. }
  984. /// <summary>
  985. /// 设置工具坐标
  986. /// </summary>
  987. /// <param name="index"></param>
  988. /// <param name="x"></param>
  989. /// <param name="y"></param>
  990. /// <returns></returns>
  991. public bool SetTool(int index, double x, double y)
  992. {
  993. try
  994. {
  995. CanExecute = false;
  996. string rev = SendAndReceive($"SetTool,{index},{x},{y}");
  997. if (rev.Contains("SetTool"))
  998. return true;
  999. else
  1000. return false;
  1001. }
  1002. catch (Exception ex)
  1003. {
  1004. // LogHelper removed
  1005. CanExecute = true;
  1006. throw ex;
  1007. }
  1008. finally
  1009. {
  1010. CanExecute = true;
  1011. }
  1012. }
  1013. /// <summary>
  1014. /// 设置工具坐标
  1015. /// </summary>
  1016. /// <param name="index"></param>
  1017. /// <param name="x"></param>
  1018. /// <param name="y"></param>
  1019. /// <returns></returns>
  1020. public async Task<bool> SetToolAsync(int index, double x, double y)
  1021. {
  1022. try
  1023. {
  1024. CanExecute = false;
  1025. string rev = await SendAndReceiveAsync($"SetTool,{index},{Math.Round(x, 3)},{Math.Round(y, 3)}");
  1026. if (rev.Contains("SetTool"))
  1027. return true;
  1028. else
  1029. return false;
  1030. }
  1031. catch (Exception ex)
  1032. {
  1033. // LogHelper removed
  1034. CanExecute = true;
  1035. throw ex;
  1036. }
  1037. finally
  1038. {
  1039. CanExecute = true;
  1040. }
  1041. }
  1042. /// <summary>
  1043. /// 选择工具坐标
  1044. /// </summary>
  1045. /// <param name="index"></param>
  1046. /// <returns></returns>
  1047. public bool SelectTool(int index)
  1048. {
  1049. try
  1050. {
  1051. SelectedTool = index;
  1052. CanExecute = false;
  1053. string rev = SendAndReceive($"SelectTool,{index}");
  1054. if (rev.Contains("SetTool"))
  1055. return true;
  1056. else
  1057. return false;
  1058. }
  1059. catch (Exception ex)
  1060. {
  1061. // LogHelper removed
  1062. CanExecute = true;
  1063. throw ex;
  1064. }
  1065. finally
  1066. {
  1067. CanExecute = true;
  1068. }
  1069. }
  1070. /// <summary>
  1071. /// 选择工具坐标
  1072. /// </summary>
  1073. /// <param name="index"></param>
  1074. /// <returns></returns>
  1075. public async Task<bool> SelectToolAsync(int index)
  1076. {
  1077. {
  1078. try
  1079. {
  1080. SelectedTool = index;
  1081. CanExecute = false;
  1082. string rev = await SendAndReceiveAsync($"SelectTool,{index}");
  1083. if (rev.Contains("SetTool"))
  1084. return true;
  1085. else
  1086. return false;
  1087. }
  1088. catch (Exception ex)
  1089. {
  1090. // LogHelper removed
  1091. CanExecute = true;
  1092. throw ex;
  1093. }
  1094. finally
  1095. {
  1096. CanExecute = true;
  1097. }
  1098. }
  1099. }
  1100. #endregion
  1101. #region 收发数据
  1102. public string SendAndReceive(string send)
  1103. {
  1104. return _tcp.SendAndReceive(send, Timeout);
  1105. }
  1106. public async Task<string> SendAndReceiveAsync(string send)
  1107. {
  1108. return await _tcp.SendAndReceiveAsync(send, Timeout);
  1109. }
  1110. public void Send(string send)
  1111. {
  1112. _tcp.Send(send);
  1113. }
  1114. public async Task SendAsync(string send)
  1115. {
  1116. await _tcp.SendAsync(send);
  1117. }
  1118. public Encoding GetEncoding()
  1119. {
  1120. return _tcp.GetEncoding();
  1121. }
  1122. #endregion
  1123. #region 属性通知
  1124. /// <summary>
  1125. /// Occurs when a property value changes.
  1126. /// </summary>
  1127. public event PropertyChangedEventHandler PropertyChanged;
  1128. /// <summary>
  1129. /// Checks if a property already matches a desired value. Sets the property and
  1130. /// notifies listeners only when necessary.
  1131. /// </summary>
  1132. /// <typeparam name="T">Type of the property.</typeparam>
  1133. /// <param name="storage">Reference to a property with both getter and setter.</param>
  1134. /// <param name="value">Desired value for the property.</param>
  1135. /// <param name="propertyName">Name of the property used to notify listeners. This
  1136. /// value is optional and can be provided automatically when invoked from compilers that
  1137. /// support CallerMemberName.</param>
  1138. /// <returns>True if the value was changed, false if the existing value matched the
  1139. /// desired value.</returns>
  1140. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  1141. {
  1142. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  1143. storage = value;
  1144. RaisePropertyChanged(propertyName);
  1145. return true;
  1146. }
  1147. /// <summary>
  1148. /// Checks if a property already matches a desired value. Sets the property and
  1149. /// notifies listeners only when necessary.
  1150. /// </summary>
  1151. /// <typeparam name="T">Type of the property.</typeparam>
  1152. /// <param name="storage">Reference to a property with both getter and setter.</param>
  1153. /// <param name="value">Desired value for the property.</param>
  1154. /// <param name="propertyName">Name of the property used to notify listeners. This
  1155. /// value is optional and can be provided automatically when invoked from compilers that
  1156. /// support CallerMemberName.</param>
  1157. /// <param name="onChanged">Action that is called after the property value has been changed.</param>
  1158. /// <returns>True if the value was changed, false if the existing value matched the
  1159. /// desired value.</returns>
  1160. protected virtual bool SetProperty<T>(ref T storage, T value, Action onChanged, [CallerMemberName] string propertyName = null)
  1161. {
  1162. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  1163. storage = value;
  1164. onChanged?.Invoke();
  1165. RaisePropertyChanged(propertyName);
  1166. return true;
  1167. }
  1168. /// <summary>
  1169. /// Raises this object's PropertyChanged event.
  1170. /// </summary>
  1171. /// <param name="propertyName">Name of the property used to notify listeners. This
  1172. /// value is optional and can be provided automatically when invoked from compilers that
  1173. /// support <see cref="CallerMemberNameAttribute"/>.</param>
  1174. protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
  1175. {
  1176. OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
  1177. }
  1178. /// <summary>
  1179. /// Raises this object's PropertyChanged event.
  1180. /// </summary>
  1181. /// <param name="args">The PropertyChangedEventArgs</param>
  1182. protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
  1183. {
  1184. PropertyChanged?.Invoke(this, args);
  1185. }
  1186. public List<object> GetNodesValue()
  1187. {
  1188. throw new NotImplementedException();
  1189. }
  1190. #endregion
  1191. }
  1192. }