소스 검색

discovery functie van persistent IP (i know statefull)+commentaar en nu wel gitignore toegevoegd.

keep-around/c5216e76cad262723738e350daf9fd25abbc8ea7
Wouter Horlings 9 년 전
부모
커밋
7c8153361d
2개의 변경된 파일72개의 추가작업 그리고 0개의 파일을 삭제
  1. +19
    -0
      .gitignore
  2. +53
    -0
      Equipment/prologix_discovery.m

+ 19
- 0
.gitignore 파일 보기

@@ -0,0 +1,19 @@
##---------------------------------------------------
## Remove autosaves generated by the Matlab editor
## We have git for backups!
##---------------------------------------------------

# Windows default autosave extension
*.asv

# OSX / *nix default autosave extension
*.m~

# Compiled MEX binaries (all platforms)
*.mex*

# Simulink Code Generation
slprj/

# Session info
octave-workspace

+ 53
- 0
Equipment/prologix_discovery.m 파일 보기

@@ -0,0 +1,53 @@
function ipaddress = prologix_discovery()
%% PROLOGIX_DISCOVERY Find your prologix GPIB device.
% ipaddress = PROLOGIX_DISCOVERY() finds prologix on your
% local network. When your prologix device is detected
% string with ip address is returned.
%
% Function uses persistent ipaddress: when ipaddress is
% changed use CLEAR ALL to find the current ipaddress.
% See also CLEAR

%% setup correct variables.
% if location of prologix is known: just return stored ip address
persistent stored_ipaddress;
if ~isempty(stored_ipaddress)
ipaddress = stored_ipaddress;
return
end
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);

%% 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
break;
elseif mod(i,10) == 0
%waiting dot and resending of string
fprintf('.')
step(hudps,magic_msg);
end
end
if isempty(msg)
error('No prologix found on network');
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);

불러오는 중...
취소
저장