Selaa lähdekoodia

2e commit ofzo

keep-around/c5216e76cad262723738e350daf9fd25abbc8ea7
Wouter Horlings 8 vuotta sitten
vanhempi
commit
711d2ecfca
8 muutettua tiedostoa jossa 217 lisäystä ja 23 poistoa
  1. +14
    -0
      Equipment/bodeplot.m
  2. +15
    -0
      Equipment/getLocalIP.m
  3. +11
    -0
      Equipment/keysight_connect.m
  4. +10
    -0
      Equipment/keysight_disconnect.m
  5. +22
    -0
      Equipment/keysight_measure_vpp.m
  6. +36
    -23
      Equipment/prologix_discovery.m
  7. +97
    -0
      OOequipment/Equipment.m
  8. +12
    -0
      OOequipment/function_generator.m

+ 14
- 0
Equipment/bodeplot.m Näytä tiedosto

@@ -0,0 +1,14 @@
fStart = 2.7;
fStop = 4;
fStep = 25;
frequency = logspace(fStart,fStop,fStep);
amplitude = 10;
scopeIP = '10.0.0.7';
outputarray = NaN(fStep,1);

for i = 1:fStep
prologix_function_generator_waveform(1,frequency(i),amplitude);
outputarray(i) = keysight_measure_vpp(1,scopeIP);
end
semilogx(frequency,outputarray)
grid on

+ 15
- 0
Equipment/getLocalIP.m Näytä tiedosto

@@ -0,0 +1,15 @@
function [ ipaddress ] = getLocalIP()
%GETLOCALIP returns the ipaddress of the current windows machine
[status,result]=system('ipconfig');
if ~(status == 0)
error('Failed to find local IP address');
end
[startIndex,endIndex] = regexp(result,'(?<=\n IPv4 Address[ \.]*: )([0-9]{1,3}\.?){4}');
if isempty(startIndex)
error('Failed to find local IP address');
end
for i = 1:length(startIndex)
ipaddress{i} = result(startIndex(i):endIndex(i));
end
end


+ 11
- 0
Equipment/keysight_connect.m Näytä tiedosto

@@ -0,0 +1,11 @@
function [ t ] = keysight_connect( ipaddress )
%KEYSIGHT_CONNECT Summary of this function goes here
% Detailed explanation goes here
if nargin < 1
ipaddress = [hostname '.local.'];
end
t = tcpip(ipaddress,5025);
fopen(t);

end


+ 10
- 0
Equipment/keysight_disconnect.m Näytä tiedosto

@@ -0,0 +1,10 @@
function keysight_disconnect(t)
%KEYSIGHT_DISCONNECT Summary of this function goes here
% Detailed explanation goes here


fclose(t);
delete(t);
clear t
end


+ 22
- 0
Equipment/keysight_measure_vpp.m Näytä tiedosto

@@ -0,0 +1,22 @@
function [ msg ] = keysight_measure_vpp(channel,ipaddress)
%KEYSIGHT_MEASURE_VPP Summary of this function goes here
% Detailed explanation goes here
if nargin < 2
t = keysight_connect();
else
t = keysight_connect(ipaddress);
if nargin < 1
channel = 1;
end
end
fprintf(t,':autoscale');
fprintf(t,'*OPC?');
fscanf(t);
fprintf(t,[':meas:vamp? chan' num2str(channel)]);
msg = str2double(fscanf(t));
if msg > 9e+37
msg = NaN;
end
keysight_disconnect(t);
end


+ 36
- 23
Equipment/prologix_discovery.m Näytä tiedosto

@@ -1,4 +1,4 @@
function ipaddress = prologix_discovery()
function ipaddress = prologix_discovery(localhost)
%% PROLOGIX_DISCOVERY Find your prologix GPIB device.
% ipaddress = PROLOGIX_DISCOVERY() finds prologix on your
% local network. When your prologix device is detected
@@ -10,6 +10,11 @@ function ipaddress = prologix_discovery()

%% setup correct variables.
% if location of prologix is known: just return stored ip address
if nargin < 1
localhostcellarray = getLocalIP();
else
localhostcellarray{1} = localhost;
end
persistent stored_ipaddress;
if ~isempty(stored_ipaddress)
ipaddress = stored_ipaddress;
@@ -19,26 +24,37 @@ local_port = randi([49152 65535]);
remote_port = 3040;

%% setup dsp to send and recieve udp packets.
hudpr = dsp.UDPReceiver('LocalIPPort',local_port);
hudps = dsp.UDPSender('RemoteIPAddress','255.255.255.255','RemoteIPPort',remote_port,'LocalIPPortSource','Property','LocalIPPort',local_port);
% start recieving udp packets
setup(hudpr);
for ipIndex = 1:length(localhostcellarray)
udpconnection = udp('10.255.255.255',3040);
%hudpr = dsp.UDPReceiver('LocalIPPort',local_port);
% hudps = dsp.UDPSender('RemoteIPAddress','255.255.255.255','RemoteIPPort',remote_port,'LocalIPPortSource','Property','LocalIPPort',local_port);
% start recieving udp packets
% setup(hudpr);
fopen(udpconnection);


%% Discover prologix.
% magic string to request ipaddress from prologix: ['5a' '00' '5b' 'db' 'ff' 'ff' 'ff' 'ff' 'ff' 'ff' '00' '00']
magic_msg = uint8([90 0 91 219 255 255 255 255 255 255 00 00]);
% Sending packet.
step(hudps,magic_msg);
% Recieving packet or resend.
for i = 1:100
pause(0.1);
msg = step(hudpr);
if numel(msg)>0
%% Discover prologix.
% magic string to request ipaddress from prologix: ['5a' '00' '5b' 'db' 'ff' 'ff' 'ff' 'ff' 'ff' 'ff' '00' '00']
magic_msg = uint8([90 0 91 219 255 255 255 255 255 255 00 00]);
% Sending packet.
% hudps(magic_msg);
fwrite(udpconnection,magic_msg);
% Recieving packet or resend.
for i = 1:100
pause(0.1);
msg = fread(udpconnection);
if numel(msg)>0
break;
elseif mod(i,10) == 0
%waiting dot and resending of string
fprintf('.')
fwrite(udpconnection,magic_msg);
% step(hudps,magic_msg);
end
end
fclose(udpconnection);
if ~isempty(msg)
break;
elseif mod(i,10) == 0
%waiting dot and resending of string
fprintf('.')
step(hudps,magic_msg);
end
end
if isempty(msg)
@@ -47,7 +63,4 @@ end
%ipaddress string is extracted from recieved UDP message. array position 21
%till 24.
ipaddress = num2str(msg(21:24)','%d.%d.%d.%d');
stored_ipaddress = ipaddress;
%% releasing connection.
release(hudps);
release(hudpr);
stored_ipaddress = ipaddress;

+ 97
- 0
OOequipment/Equipment.m Näytä tiedosto

@@ -0,0 +1,97 @@
classdef Equipment < handle
%EQUIPMENT Summary of this class goes here
% Detailed explanation goes here
properties (SetAccess=private)
name
tcp
channel
end
methods
function DMM = equipment(name,connection,channel)
DMM.name = name;
DMM.tcp = tcpip(connection,1234);
DMM.channel = channel;
end
function idn(DMM)
fprintf(DMM.tcp,['++addr ',num2str(DMM.channel)]);
fprintf(DMM.tcp,'*idn?');
fprintf(DMM.tcp,'++read');
fprintf(fscanf(DMM.tcp));
end
function starttcp(DMM)
fopen(DMM.tcp);
end
end
methods (Static)
function getTCP(ipAddress)
persistent stored_ipaddress;
if ~isempty(stored_ipaddress)
ipaddress = stored_ipaddress;
return
end
end
end
end

% classdef BankAccount < handle
% properties (Access = ?AccountManager)
% AccountStatus = 'open'
% end
% properties (SetAccess = private)
% AccountNumber
% AccountBalance
% end
% properties (Transient)
% AccountListener
% end
% events
% InsufficientFunds
% end
% methods
% function BA = BankAccount(accNum,initBal)
% BA.AccountNumber = accNum;
% BA.AccountBalance = initBal;
% BA.AccountListener = AccountManager.addAccount(BA);
% end
% function deposit(BA,amt)
% BA.AccountBalance = BA.AccountBalance + amt;
% if BA.AccountBalance > 0
% BA.AccountStatus = 'open';
% end
% end
% function withdraw(BA,amt)
% if (strcmp(BA.AccountStatus,'closed')&& BA.AccountBalance <= 0)
% disp(['Account ',num2str(BA.AccountNumber),' has been closed.'])
% return
% end
% newbal = BA.AccountBalance - amt;
% BA.AccountBalance = newbal;
% if newbal < 0
% notify(BA,'InsufficientFunds')
% end
% end
% function getStatement(BA)
% disp('-------------------------')
% disp(['Account: ',num2str(BA.AccountNumber)])
% ab = sprintf('%0.2f',BA.AccountBalance);
% disp(['CurrentBalance: ',ab])
% disp(['Account Status: ',BA.AccountStatus])
% disp('-------------------------')
% end
% end
% methods (Static)
% function obj = loadobj(s)
% if isstruct(s)
% accNum = s.AccountNumber;
% initBal = s.AccountBalance;
% obj = BankAccount(accNum,initBal);
% else
% obj.AccountListener = AccountManager.addAccount(s);
% end
% end
% end
% end

+ 12
- 0
OOequipment/function_generator.m Näytä tiedosto

@@ -0,0 +1,12 @@
classdef function_generator
%FUNCTION_GENERATOR Summary of this class goes here
% Detailed explanation goes here
properties
end
methods
end
end


Loading…
Peruuta
Tallenna