diff --git a/Equipment/prologix_discovery.m b/Equipment/prologix_discovery.m index 33458d1..4502e3b 100644 --- a/Equipment/prologix_discovery.m +++ b/Equipment/prologix_discovery.m @@ -25,6 +25,7 @@ remote_port = 3040; %% setup dsp to send and recieve udp packets. udpconnection = udp('255.255.255.255',3040); + udpconnection.LocalHost = '130.89.143.33'; %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 diff --git a/OOequipment/debug/discovery.m b/OOequipment/debug/discovery.m new file mode 100644 index 0000000..7fba8b8 --- /dev/null +++ b/OOequipment/debug/discovery.m @@ -0,0 +1,17 @@ + +ipPrefix='10.0.0'; +ipPrefixRegex = '10\.0\.0'; +if ispc() + system(['for /L %a in (1,1,254) do @start /b ping ' ipPrefix '.%a -w 100 -n 2 >nul']); + [~,arptable] = system('arp -a'); + ipaddresses = regexp(arptable,[ipPrefixRegex '\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])(?=[-a-f0-9\s]*dynamic)'],'match'); +elseif isunix() + [~,ipaddresses] = system(['echo $(seq 254) | xargs -P255 -I% -d" " ping -W 1 -c 1 ' ipPrefix '.% | grep -P -o "[0-1].*?(?=:)"']); +elseif ismac() + +else + +end + + +%% find prologix \ No newline at end of file diff --git a/OOequipment/subfiles/EquipmentClass.m b/OOequipment/subfiles/EquipmentClass.m index add3c09..ed2d506 100644 --- a/OOequipment/subfiles/EquipmentClass.m +++ b/OOequipment/subfiles/EquipmentClass.m @@ -368,9 +368,42 @@ classdef EquipmentClass < handle structname = matlab.lang.makeValidName(['ip',cleanip,'_',num2str(port)]); end - function equipmentstruct = discover() - - + function ipaddress = getInterfaceIP() + if ispc + % Code to run on Windows plaform + [status,result]=system('ipconfig'); + if ~(status == 0) + error('Failed to find local IP address'); + end + ipaddress = regexp(result,'(?<=\n IPv4 Address[ \.]*: )([0-9]{1,3}\.?){4}','match'); + elseif ismac + % Code to run on Mac platform + [status,result]=system('ifconfig'); + if ~(status == 0) + error('Failed to find local IP address'); + end + ipaddress = regexp(result,'(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])(?=\/)','match'); + elseif isunix + % Code to run on Unix platform + [status,result]=system('ip addr show'); + if ~(status == 0) + error('Failed to find local IP address'); + end + ipaddress = regexp(result,'(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])(?=\/)','match'); + else + error('Platform not supported'); + end + end + + function prologixIP = discoverPrologix() + persistent stored_ipaddress; + if ~isempty(stored_ipaddress) + prologixIP = stored_ipaddress; + return + end + ipaddress = getInterfaceIP() + udpconnection = udp('255.255.255.255',3040); + udpconnection.LocalHost = localhost; end end end \ No newline at end of file