From c9b026c692760350776272fa50409e797005d352 Mon Sep 17 00:00:00 2001 From: Wouter Horlings Date: Mon, 10 Oct 2016 16:48:18 +0200 Subject: [PATCH] gebruikt nu de discovery functie om ipaddress te zoeken als deze niet gegeven is. Functie ook van commentaar voorzien. --- Equipment/prologix_connect.m | 45 +++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/Equipment/prologix_connect.m b/Equipment/prologix_connect.m index eb47c0e..b3080ff 100644 --- a/Equipment/prologix_connect.m +++ b/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