diff --git a/Equipment/bodeplot.m b/Equipment/bodeplot.m new file mode 100644 index 0000000..3c1ee72 --- /dev/null +++ b/Equipment/bodeplot.m @@ -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 \ No newline at end of file diff --git a/Equipment/getLocalIP.m b/Equipment/getLocalIP.m new file mode 100644 index 0000000..4813b8d --- /dev/null +++ b/Equipment/getLocalIP.m @@ -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 + diff --git a/Equipment/keysight_connect.m b/Equipment/keysight_connect.m new file mode 100644 index 0000000..0679176 --- /dev/null +++ b/Equipment/keysight_connect.m @@ -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 + diff --git a/Equipment/keysight_disconnect.m b/Equipment/keysight_disconnect.m new file mode 100644 index 0000000..0a567fa --- /dev/null +++ b/Equipment/keysight_disconnect.m @@ -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 + diff --git a/Equipment/keysight_measure_vpp.m b/Equipment/keysight_measure_vpp.m new file mode 100644 index 0000000..98fd54f --- /dev/null +++ b/Equipment/keysight_measure_vpp.m @@ -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 + diff --git a/Equipment/prologix_discovery.m b/Equipment/prologix_discovery.m index 62e34db..10425c5 100644 --- a/Equipment/prologix_discovery.m +++ b/Equipment/prologix_discovery.m @@ -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); \ No newline at end of file +stored_ipaddress = ipaddress; \ No newline at end of file diff --git a/OOequipment/Equipment.m b/OOequipment/Equipment.m new file mode 100644 index 0000000..f9ca1d2 --- /dev/null +++ b/OOequipment/Equipment.m @@ -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 diff --git a/OOequipment/function_generator.m b/OOequipment/function_generator.m new file mode 100644 index 0000000..c443fca --- /dev/null +++ b/OOequipment/function_generator.m @@ -0,0 +1,12 @@ +classdef function_generator + %FUNCTION_GENERATOR Summary of this class goes here + % Detailed explanation goes here + + properties + end + + methods + end + +end +