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.
 
 

60 lines
1.6 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Lebai.SDK;
  7. using Lebai.SDK.Dtos;
  8. using Robotc;
  9. namespace HBLConsole.Communication
  10. {
  11. public class LebaiHelper
  12. {
  13. private volatile static LebaiHelper _Instance;
  14. public static LebaiHelper GetInstance => _Instance ?? (_Instance = new LebaiHelper());
  15. private LebaiHelper() { }
  16. private LebaiRobotClient client;
  17. public void Connect(string ip)
  18. {
  19. client = new LebaiRobotClient(ip);
  20. }
  21. /// <summary>
  22. /// 获取信号量
  23. /// </summary>
  24. /// <param name="index"></param>
  25. /// <returns></returns>
  26. public SignalResult GetValueAsync(int index = 0)
  27. {
  28. SignalValue signalValue = new SignalValue();
  29. signalValue.Index = index;
  30. return client?.GetSignal(signalValue).Result;
  31. }
  32. /// <summary>
  33. /// 设置信号量
  34. /// </summary>
  35. /// <param name="index"></param>
  36. /// <param name="value"></param>
  37. /// <returns></returns>
  38. public SignalResult SetValue(int value, int index = 0)
  39. {
  40. SignalValue signalValue = new SignalValue();
  41. signalValue.Index = index;
  42. signalValue.Value = value;
  43. return client.SetSignal(signalValue).Result;
  44. }
  45. /// <summary>
  46. /// 运行指定的场景
  47. /// </summary>
  48. /// <param name="id"></param>
  49. public void Scene(int id)
  50. {
  51. client?.RunScene(id);
  52. }
  53. }
  54. }