Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

111 строки
2.8KB

  1. classdef FunctionGenerator < Equipment
  2. %FUNCTION_GENERATOR Summary of this class goes here
  3. % Detailed explanation goes here
  4. properties (Dependent)
  5. waveform
  6. frequency
  7. voltage
  8. unit
  9. offset
  10. load
  11. end
  12. methods
  13. function fg = FunctionGenerator(ipAddress,port,channel)
  14. fg@Equipment(ipAddress,port,channel);
  15. end
  16. function w = get.waveform(fg)
  17. w = FunctionGenerator.getWave(fg.query('FUNCtion:SHAPe?'));
  18. end
  19. function f = get.frequency(fg)
  20. f = str2num(fg.query('FREQuency?'));
  21. end
  22. function v = get.voltage(fg)
  23. v = str2num(fg.query('VOLTage?'));
  24. end
  25. function u = get.unit(fg)
  26. u = FunctionGenerator.getUnit(fg.query('VOLTage:UNIT?'));
  27. end
  28. function o = get.offset(fg)
  29. o = str2num(fg.query('VOLTage:OFFSet?'));
  30. end
  31. function l = get.load(fg)
  32. o = FunctionGenerator.getLoad(fg.query('OUTPut:LOAD?'));
  33. end
  34. function fg = set.waveform(fg,w)
  35. fg.waveform = FunctionGenerator.getWave(w);
  36. fg.write(strcat('FUNCtion:SHAPe ', fg.waveform));
  37. end
  38. function fg = set.frequency(fg,f)
  39. fg.frequency = Equipment.forceNum(f);
  40. fg.write(strcat('FREQuency ', num2str(fg.frequency)));
  41. end
  42. function fg = set.voltage(fg,v)
  43. fg.voltage = Equipment.forceNum(v);
  44. fg.write(strcat('VOLTage ', num2str(fg.voltage)));
  45. end
  46. function fg = set.unit(fg,u)
  47. fg.unit = FunctionGenerator.getUnit(u);
  48. fg.write(strcat('VOLTage:UNIT ', fg.unit));
  49. end
  50. function fg = set.offset(fg,o)
  51. fg.offset = Equipment.forceNum(o);
  52. fg.write(strcat('VOLTage:OFFSet ', num2str(fg.offset)));
  53. end
  54. function fg = set.load(fg,l)
  55. fg.load = FunctionGenerator.getLoad(l);
  56. fg.write(strcat('OUTPut:LOAD ', fg.load));
  57. end
  58. end
  59. methods (Static)
  60. function w = getWave(win)
  61. w = regexp(num2str(win), '(si|sq|mi|ma[trndu1-7]|s)', 'match', 'once', 'ignorecase');
  62. if isempty(w)
  63. error(strcat('Invalid waveform: ', win));
  64. end
  65. w = regexprep(w, {'^(1|si|(?-i)s)$', '^(2|sq|(?-i)S)$', '^[3t]$', '^[4r]$', '^[5n]$', '^[6d]$', '^[7u]$', '^mi$', '^ma$'}, ...
  66. {'sinusoid', 'square', 'triangle', 'ramp', 'noise', 'dc', 'user', 'minimum', 'maximum'}, 'ignorecase');
  67. end
  68. function u = getUnit(uin)
  69. u = regexp(num2str(uin), '([1-4]|vp|vr|db|de)', 'match', 'once', 'ignorecase');
  70. if isempty(u)
  71. error(strcat('Invalid voltage unit: ', uin));
  72. end
  73. u = regexprep(u, {'^(1|vp)$', '^(2|vr)$', '^(3|db)$', '^(4|de)$'}, ...
  74. {'Vpp', 'Vrms', 'dBm', 'default'}, 'ignorecase');
  75. end
  76. function l = getLoad(lin)
  77. l = regexp(num2str(lin), '([12]|50|in|mi|ma)', 'match', 'once', 'ignorecase');
  78. if isempty(u)
  79. error(strcat('Invalid load: ', lin));
  80. end
  81. u = regexprep(l, {'^(1|50)$', '^(2|in)$', '^mi$', '^ma$'}, ...
  82. {'50', 'infinity', 'minimum', 'maximum'}, 'ignorecase');
  83. end
  84. end
  85. end