Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

108 Zeilen
2.7KB

  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.write(strcat('FUNCtion:SHAPe ', FunctionGenerator.getWave(w)));
  36. end
  37. function fg = set.frequency(fg,f)
  38. Equipment.forceNum(f);
  39. fg.write(strcat('FREQuency ', num2str(f)));
  40. end
  41. function fg = set.voltage(fg,v)
  42. Equipment.forceNum(v);
  43. fg.write(strcat('VOLTage ', num2str(v)));
  44. end
  45. function fg = set.unit(fg,u)
  46. fg.write(strcat('VOLTage:UNIT ', FunctionGenerator.getUnit(u)));
  47. end
  48. function fg = set.offset(fg,o)
  49. Equipment.forceNum(o);
  50. fg.write(strcat('VOLTage:OFFSet ', num2str(o)));
  51. end
  52. function fg = set.load(fg,l)
  53. fg.write(strcat('OUTPut:LOAD ', FunctionGenerator.getLoad(l)));
  54. end
  55. end
  56. methods (Static)
  57. function w = getWave(win)
  58. w = regexp(num2str(win), '(si|sq|mi|ma|[trndu1-7]|s)', 'match', 'once', 'ignorecase');
  59. if isempty(w)
  60. error(strcat('Invalid waveform: ', win));
  61. end
  62. w = regexprep(w, {'^(1|si|(?-i)s)$', '^(2|sq|(?-i)S)$', '^[3t]$', '^[4r]$', '^[5n]$', '^[6d]$', '^[7u]$', '^mi$', '^ma$'}, ...
  63. {'sinusoid', 'square', 'triangle', 'ramp', 'noise', 'dc', 'user', 'minimum', 'maximum'}, 'ignorecase');
  64. end
  65. function u = getUnit(uin)
  66. u = regexp(num2str(uin), '([1-4]|vp|vr|db|de)', 'match', 'once', 'ignorecase');
  67. if isempty(u)
  68. error(strcat('Invalid voltage unit: ', uin));
  69. end
  70. u = regexprep(u, {'^(1|vp)$', '^(2|vr)$', '^(3|db)$', '^(4|de)$'}, ...
  71. {'Vpp', 'Vrms', 'dBm', 'default'}, 'ignorecase');
  72. end
  73. function l = getLoad(lin)
  74. l = regexp(num2str(lin), '([12]|50|in|mi|ma)', 'match', 'once', 'ignorecase');
  75. if isempty(l)
  76. error(strcat('Invalid load: ', lin));
  77. end
  78. u = regexprep(l, {'^(1|50)$', '^(2|in)$', '^mi$', '^ma$'}, ...
  79. {'50', 'infinity', 'minimum', 'maximum'}, 'ignorecase');
  80. end
  81. end
  82. end