FeederInfo.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Runtime.CompilerServices;
  7. using Newtonsoft.Json;
  8. using TeamAAS.Feeder.Enums;
  9. namespace TeamAAS.Feeder.Models
  10. {
  11. /// <summary>
  12. /// 单个电机参数(振幅 / 频率 / 相位 / 波形)
  13. /// </summary>
  14. public class VoiceMotorParam : INotifyPropertyChanged
  15. {
  16. private ushort _amplitude = 50;
  17. private ushort _frequency = 100;
  18. private ushort _phase = 0;
  19. private WaveShape _waveShape = WaveShape.SignWave;
  20. [Category("电机参数"), DisplayName("振幅(0-100%)")]
  21. public ushort Amplitude
  22. {
  23. get { return _amplitude; }
  24. set { SetProperty(ref _amplitude, value); }
  25. }
  26. [Category("电机参数"), DisplayName("频率(0-250Hz)")]
  27. public ushort Frequency
  28. {
  29. get { return _frequency; }
  30. set { SetProperty(ref _frequency, value); }
  31. }
  32. [Category("电机参数"), DisplayName("相位(0-359°)")]
  33. public ushort Phase
  34. {
  35. get { return _phase; }
  36. set { SetProperty(ref _phase, value); }
  37. }
  38. [Category("电机参数"), DisplayName("波形")]
  39. public WaveShape WaveShape
  40. {
  41. get { return _waveShape; }
  42. set
  43. {
  44. if (SetProperty(ref _waveShape, value))
  45. {
  46. OnPropertyChanged(nameof(IsWaveNone));
  47. OnPropertyChanged(nameof(IsWaveSin));
  48. OnPropertyChanged(nameof(IsWaveSaw));
  49. OnPropertyChanged(nameof(IsWaveTri));
  50. }
  51. }
  52. }
  53. [JsonIgnore, Category("电机参数")]
  54. public bool IsWaveNone
  55. {
  56. get { return _waveShape == WaveShape.None; }
  57. set { if (value) WaveShape = WaveShape.None; }
  58. }
  59. [JsonIgnore, Category("电机参数")]
  60. public bool IsWaveSin
  61. {
  62. get { return (_waveShape & WaveShape.SignWave) != 0; }
  63. set { WaveShape = value ? (_waveShape | WaveShape.SignWave) : (_waveShape & ~WaveShape.SignWave); }
  64. }
  65. [JsonIgnore, Category("电机参数")]
  66. public bool IsWaveSaw
  67. {
  68. get { return (_waveShape & WaveShape.SawToothWave) != 0; }
  69. set { WaveShape = value ? (_waveShape | WaveShape.SawToothWave) : (_waveShape & ~WaveShape.SawToothWave); }
  70. }
  71. [JsonIgnore, Category("电机参数")]
  72. public bool IsWaveTri
  73. {
  74. get { return (_waveShape & WaveShape.TriangleWave) != 0; }
  75. set { WaveShape = value ? (_waveShape | WaveShape.TriangleWave) : (_waveShape & ~WaveShape.TriangleWave); }
  76. }
  77. public VoiceMotorParam Clone()
  78. {
  79. return new VoiceMotorParam
  80. {
  81. Amplitude = Amplitude,
  82. Frequency = Frequency,
  83. Phase = Phase,
  84. WaveShape = WaveShape,
  85. };
  86. }
  87. public event PropertyChangedEventHandler PropertyChanged;
  88. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  89. {
  90. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  91. storage = value;
  92. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  93. return true;
  94. }
  95. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  96. {
  97. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  98. }
  99. }
  100. /// <summary>
  101. /// 单个振动动作参数 = 4 个电机 + 持续时间
  102. /// </summary>
  103. public class SingleActionParam : INotifyPropertyChanged
  104. {
  105. public VoiceMotorParam Motor1 { get; set; } = new VoiceMotorParam();
  106. public VoiceMotorParam Motor2 { get; set; } = new VoiceMotorParam();
  107. public VoiceMotorParam Motor3 { get; set; } = new VoiceMotorParam();
  108. public VoiceMotorParam Motor4 { get; set; } = new VoiceMotorParam();
  109. private int _durationValue = 500;
  110. [Category("动作参数"), DisplayName("持续时间(ms)")]
  111. public int DurationValue
  112. {
  113. get { return _durationValue; }
  114. set { SetProperty(ref _durationValue, value); }
  115. }
  116. public SingleActionParam Clone()
  117. {
  118. return new SingleActionParam
  119. {
  120. Motor1 = Motor1.Clone(),
  121. Motor2 = Motor2.Clone(),
  122. Motor3 = Motor3.Clone(),
  123. Motor4 = Motor4.Clone(),
  124. DurationValue = DurationValue,
  125. };
  126. }
  127. public event PropertyChangedEventHandler PropertyChanged;
  128. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  129. {
  130. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  131. storage = value;
  132. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  133. return true;
  134. }
  135. }
  136. /// <summary>
  137. /// 供料器配置信息(设备 + 完整振动参数)
  138. /// </summary>
  139. public class FeederInfo : INotifyPropertyChanged
  140. {
  141. private Guid _id = Guid.NewGuid();
  142. private int _feederNo;
  143. private string _feederName = "";
  144. private FeederBrand _feederBrand = FeederBrand.Team;
  145. private FeederConnectType _connectType = FeederConnectType.TCP;
  146. private string _ip = "192.168.31.200";
  147. private int _port = 5000;
  148. private string _serialPortName = "COM3";
  149. private int _baudRate = 115200;
  150. private bool _isConnected;
  151. private bool _isBacklightOn;
  152. [Browsable(false)]
  153. public Guid Id
  154. {
  155. get { return _id; }
  156. set { SetProperty(ref _id, value); }
  157. }
  158. [Category("基本"), DisplayName("编号")]
  159. public int FeederNo
  160. {
  161. get { return _feederNo; }
  162. set { SetProperty(ref _feederNo, value); }
  163. }
  164. [Category("基本"), DisplayName("名称")]
  165. public string FeederName
  166. {
  167. get { return _feederName; }
  168. set { SetProperty(ref _feederName, value); }
  169. }
  170. [Category("只读信息"), DisplayName("品牌"), ReadOnly(true)]
  171. public FeederBrand FeederBrand
  172. {
  173. get { return _feederBrand; }
  174. set
  175. {
  176. if (SetProperty(ref _feederBrand, value))
  177. {
  178. // Team 品牌只支持 TCP 连接,切品牌时自动纠正连接方式
  179. if (value == FeederBrand.Team && ConnectType != FeederConnectType.TCP)
  180. ConnectType = FeederConnectType.TCP;
  181. }
  182. }
  183. }
  184. [Category("通讯"), DisplayName("连接方式")]
  185. public FeederConnectType ConnectType
  186. {
  187. get { return _connectType; }
  188. set { SetProperty(ref _connectType, value); }
  189. }
  190. [Category("通讯"), DisplayName("IP地址")]
  191. public string IP
  192. {
  193. get { return _ip; }
  194. set { SetProperty(ref _ip, value); }
  195. }
  196. [Category("通讯"), DisplayName("端口")]
  197. public int Port
  198. {
  199. get { return _port; }
  200. set { SetProperty(ref _port, value); }
  201. }
  202. [Category("通讯"), DisplayName("串口号")]
  203. public string SerialPortName
  204. {
  205. get { return _serialPortName; }
  206. set { SetProperty(ref _serialPortName, value); }
  207. }
  208. [Category("通讯"), DisplayName("波特率")]
  209. public int BaudRate
  210. {
  211. get { return _baudRate; }
  212. set { SetProperty(ref _baudRate, value); }
  213. }
  214. [Browsable(false)]
  215. [JsonIgnore]
  216. public bool IsConnected
  217. {
  218. get { return _isConnected; }
  219. set { SetProperty(ref _isConnected, value); }
  220. }
  221. [Browsable(false)]
  222. [JsonIgnore]
  223. public bool IsBacklightOn
  224. {
  225. get { return _isBacklightOn; }
  226. set { SetProperty(ref _isBacklightOn, value); }
  227. }
  228. /// <summary>
  229. /// 11 个振动动作组(A~K,对应 FeederAction 0~10)
  230. /// </summary>
  231. public ObservableCollection<SingleActionParam> ActionGroups { get; set; }
  232. = new ObservableCollection<SingleActionParam>(
  233. Enumerable.Range(0, 11).Select(_ => new SingleActionParam()));
  234. /// <summary>
  235. /// 多个送料流程(序列集)
  236. /// </summary>
  237. public ObservableCollection<SequenceSet> Sequences { get; set; }
  238. = new ObservableCollection<SequenceSet>();
  239. public FeederInfo Clone()
  240. {
  241. var json = JsonConvert.SerializeObject(this);
  242. return JsonConvert.DeserializeObject<FeederInfo>(json);
  243. }
  244. public event PropertyChangedEventHandler PropertyChanged;
  245. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  246. {
  247. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  248. storage = value;
  249. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  250. return true;
  251. }
  252. }
  253. }