瀏覽代碼

gebruikt nu de discovery functie om ipaddress te zoeken als deze niet gegeven is. Functie ook van commentaar voorzien.

keep-around/c5216e76cad262723738e350daf9fd25abbc8ea7
Wouter Horlings 9 年之前
父節點
當前提交
c9b026c692
共有 1 個文件被更改,包括 29 次插入16 次删除
  1. +29
    -16
      Equipment/prologix_connect.m

+ 29
- 16
Equipment/prologix_connect.m 查看文件

@@ -1,19 +1,32 @@
function [ t,version ] = prologix_connect(ipAddress,port)
%PROLOGIX_CONNECT open TCP/IP connection with Prologix Ethernet GPIB
%converter
% Detailed explanation goes here
if nargin < 2
port = 1234;
if nargin < 1
ipAddress = '10.0.0.2';
end
function [ t,version ] = prologix_connect(ipAddress)
%PROLOGIX_CONNECT opens TCP/IP connection with Prologix device
% [t,version] = PROLOGIX_CONNECT() will automaticly find IP
% address and starts connection.
% [t,version] = PROLOGIX_CONNECT(ipAddress) starts connection
% with given IP address.
% IP address is autodiscovered. But can be used for a
% device on a different subnet.
% If you don't know the IP address leave it empty.
%% define variables
port = 1234;
% if no IP address is given start autodiscovery;
if nargin < 1
ipAddress = prologix_discovery();
elseif isempty(regexp(ipAddress,'([1-2]?[0-9]{1,2}\.){3}[1-2]?[0-9]{1,2}','match'))
error('Given IP address is not valid, leave empty to use autodiscovery of device');
end
echotcpip('on', port);
t = tcpip(ipAddress,port);
fopen(t);
fprintf(t, '++mode 1');
fprintf(t, '++auto 0');
fprintf(t, '++ver');
version = ['Firmware Version: ', fscanf(t)];
%% open connection.
echotcpip('on', port); % start listening for tcp packets on port
t = tcpip(ipAddress,port); % define tcpip connection
fopen(t); % open connection
%% configure prologix.
fprintf(t, '++mode 1'); %set device in controller mode
fprintf(t, '++auto 0'); %disable automatic datapull. this avoids errors on equipment.
fprintf(t, '++ver'); %ask firmware version of the prologix.
version = ['Firmware Version: ', fscanf(t)]; %pull firmware function from prologix.
end

Loading…
取消
儲存