CmdSendService.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace IntelligentControlForsx.Service.WindturbineControl.IntPtrSvc
  8. {
  9. /// <summary>
  10. /// 控制命令发送接口,引用C++服务
  11. /// </summary>
  12. public static class CmdSendService
  13. {
  14. /// <summary>
  15. /// 遥信
  16. /// </summary>
  17. public static byte GYCP_TYPE_YX = 0;
  18. /// <summary>
  19. /// 遥测
  20. /// </summary>
  21. public static byte GYCP_TYPE_YC = 1;
  22. /// <summary>
  23. /// 遥控
  24. /// </summary>
  25. public static byte GYCP_TYPE_YK = 2;
  26. /// <summary>
  27. /// 遥调
  28. /// </summary>
  29. public static byte GYCP_TYPE_YT = 3;
  30. /// <summary>
  31. /// 遥视
  32. /// </summary>
  33. public static byte GYCP_TYPE_YS = 4;
  34. [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.Cdecl)]
  35. public delegate void GycpReceive(IntPtr types, IntPtr addrs, IntPtr errors, uint length, IntPtr arg);
  36. /// <summary>
  37. /// 创建句柄
  38. /// </summary>
  39. /// <param name="ip">服务地址</param>
  40. /// <param name="port">端口</param>
  41. /// <param name="t0">重连时间</param>
  42. /// <param name="t1">keepalive时间</param>
  43. /// <param name="t2">keepalive返回时间</param>
  44. /// <param name="receive">回调函数</param>
  45. /// <param name="arg">回调函数参数</param>
  46. /// <returns></returns>
  47. [DllImport("gycp.dll", CallingConvention = CallingConvention.Cdecl)]
  48. public static extern IntPtr gycp_create(string ip, ushort port, byte t0, byte t1, byte t2, GycpReceive receive, IntPtr arg);
  49. [DllImport("gycp.dll", CallingConvention = CallingConvention.Cdecl)]
  50. public static extern void gycp_destroy(IntPtr gycp);
  51. /// <summary>
  52. /// 发送命令
  53. /// </summary>
  54. /// <param name="gycp">句柄</param>
  55. /// <param name="types">控制类型</param>
  56. /// <param name="addrs">控制地址(控制点)</param>
  57. /// <param name="values">控制值</param>
  58. /// <param name="length">数组长度</param>
  59. /// <returns></returns>
  60. [DllImport("gycp.dll", CallingConvention = CallingConvention.Cdecl)]
  61. public static extern int gycp_control(IntPtr gycp, byte[] types, uint[] addrs, float[] values, uint length);
  62. }
  63. }