MainWindow.xaml.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace MotorTest
  17. {
  18. /// <summary>
  19. /// Interaction logic for MainWindow.xaml
  20. /// </summary>
  21. public partial class MainWindow : Window
  22. {
  23. public MainWindow()
  24. {
  25. InitializeComponent();
  26. IntPtr actuator = EAIWrapper.BodyActuator_new();
  27. Console.WriteLine(actuator.ToString());
  28. EAIWrapper.BodyActuator_init(actuator, ActuatorType.EAI, "COM5" , 16);
  29. EAIWrapper.BodyActuator_startActuation(actuator, 0 , (float)0.3);
  30. System.Threading.Thread.Sleep(1000);
  31. EAIWrapper.BodyActuator_stopActuation(actuator, 0);
  32. }
  33. }
  34. class EAIWrapper
  35. {
  36. [DllImport("BodyActuator.dll", CallingConvention = CallingConvention.Cdecl)]
  37. public static extern IntPtr BodyActuator_new();
  38. [DllImport("BodyActuator.dll", CallingConvention = CallingConvention.Cdecl)]
  39. public static extern void BodyActuator_init(IntPtr self, ActuatorType type, [MarshalAs(UnmanagedType.LPStr)]string port, int actuatorCount);
  40. [DllImport("BodyActuator.dll", CallingConvention = CallingConvention.Cdecl)]
  41. public static extern void BodyActuator_startActuation(IntPtr self, int tactor, float intensity);
  42. [DllImport("BodyActuator.dll", CallingConvention = CallingConvention.Cdecl)]
  43. public static extern void BodyActuator_actuate(IntPtr self, int tactor, float intensity, int duration);
  44. [DllImport("BodyActuator.dll", CallingConvention = CallingConvention.Cdecl)]
  45. public static extern void BodyActuator_stopActuation(IntPtr self, int tactor);
  46. [DllImport("BodyActuator.dll", CallingConvention = CallingConvention.Cdecl)]
  47. public static extern void BodyActuator_setFrequency(IntPtr self, int tactor, int frequency);
  48. }
  49. enum ActuatorType
  50. {
  51. NONE = 0,
  52. EAI,
  53. PIEZO,
  54. ERM,
  55. EMS
  56. }
  57. }