You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.7KB

  1. classdef Channel
  2. %CHANNEL Summary of this class goes here
  3. % Detailed explanation goes here
  4. properties (Hidden, Access = private)
  5. scope
  6. channelnumber
  7. end
  8. properties (Dependent)
  9. state
  10. coupling
  11. bandwidth
  12. scale
  13. offset
  14. probe
  15. label
  16. end
  17. methods
  18. function ch = Channel(scope,channelnumber)
  19. ch.channelnumber = channelnumber;
  20. ch.scope = scope;
  21. end
  22. function s = get.state(ch)
  23. s = ch.CHAN('state?');
  24. end
  25. function out = get.coupling(ch)
  26. out = ch.CHAN('coup?');
  27. end
  28. function out = get.bandwidth(ch)
  29. out = ch.CHAN('band?');
  30. end
  31. function out = get.offset(ch)
  32. out = ch.CHAN('offs?');
  33. end
  34. function out = get.scale(ch)
  35. out = ch.CHAN('scal?');
  36. end
  37. function out = get.label(ch)
  38. out = ch.CHAN('lab?');
  39. end
  40. function ch = set.state(ch,in)
  41. ch.CHAN('state',in);
  42. end
  43. function ch = set.coupling(ch,in)
  44. ch.CHAN('coup',in);
  45. end
  46. function ch = set.bandwidth(ch,in)
  47. ch.CHAN('band',in);
  48. end
  49. function ch = set.offset(ch,in)
  50. ch.CHAN('offs',in);
  51. end
  52. function ch = set.scale(ch,in)
  53. ch.CHAN('scal',in);
  54. end
  55. function ch = set.label(ch,in)
  56. ch.CHAN('lab',in);
  57. end
  58. function out = frequency(ch)
  59. out = str2double(ch.MEAS('freq'));
  60. end
  61. function out = peak2peak(ch)
  62. out = str2double(ch.MEAS('peak'));
  63. end
  64. function out = period(ch)
  65. out = str2double(ch.MEAS('per'));
  66. end
  67. function out = amplitude(ch)
  68. out = str2double(ch.MEAS('ampl'));
  69. end
  70. function out = mean(ch)
  71. out = str2double(ch.MEAS('mean'));
  72. end
  73. function out = rms(ch)
  74. out = str2double(ch.MEAS('rms'));
  75. end
  76. function out = phase(ch)
  77. out = str2double(ch.MEAS('phas'));
  78. end
  79. function data = waveform(ch)
  80. ch.scope.clear;
  81. ch.CHAN('TYPE HRES');
  82. ch.scope.write('FORM REAL');
  83. ch.scope.write('FORM:BORD MSBF');
  84. ch.CHAN('DATA:POIN DEF');
  85. ch.scope.write('SING');
  86. header = str2num(ch.CHAN('DATA:HEAD?'));
  87. ch.scope.opc;
  88. ch.scope.write_unsafe('CHAN1:DATA?');
  89. prefixstring = fscanf(ch.scope.tcp,'%c',2);
  90. prefixlength = str2double(prefixstring(2));
  91. datalength = fscanf(ch.scope.tcp,'%c',prefixlength);
  92. data = fread(ch.scope.tcp,header(3),'float');
  93. flushinput(ch.scope.tcp);
  94. end
  95. end
  96. methods (Hidden, Access = private)
  97. function c = CHAN(ch,string,in)
  98. if nargin == 2
  99. if strcmp(string(end),'?')
  100. c = ch.scope.query(['CHAN',num2str(ch.channelnumber),':',string]);
  101. else
  102. ch.scope.write(['CHAN',num2str(ch.channelnumber),':',string]);
  103. end
  104. else
  105. ch.scope.write(['CHAN',num2str(ch.channelnumber),':',string,' ',in]);
  106. end
  107. end
  108. function c = MEAS(ch,string)
  109. c = ch.scope.query(['MEAS',num2str(ch.channelnumber),':RES:ACT?',string]);
  110. end
  111. % function c = CHANsend(ch,string,in)
  112. % c = ['CHAN',num2str(ch.channelnumber),':',string,' ',in];
  113. % end
  114. end
  115. end