25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

66 satır
2.1KB

  1. function ipaddress = prologix_discovery(localhost)
  2. %% PROLOGIX_DISCOVERY Find your prologix GPIB device.
  3. % ipaddress = PROLOGIX_DISCOVERY() finds prologix on your
  4. % local network. When your prologix device is detected
  5. % string with ip address is returned.
  6. %
  7. % Function uses persistent ipaddress: when ipaddress is
  8. % changed use CLEAR ALL to find the current ipaddress.
  9. % See also CLEAR
  10. %% setup correct variables.
  11. % if location of prologix is known: just return stored ip address
  12. if nargin < 1
  13. localhostcellarray = getLocalIP();
  14. else
  15. localhostcellarray{1} = localhost;
  16. end
  17. persistent stored_ipaddress;
  18. if ~isempty(stored_ipaddress)
  19. ipaddress = stored_ipaddress;
  20. return
  21. end
  22. local_port = randi([49152 65535]);
  23. remote_port = 3040;
  24. %% setup dsp to send and recieve udp packets.
  25. for ipIndex = 1:length(localhostcellarray)
  26. udpconnection = udp('10.255.255.255',3040);
  27. %hudpr = dsp.UDPReceiver('LocalIPPort',local_port);
  28. % hudps = dsp.UDPSender('RemoteIPAddress','255.255.255.255','RemoteIPPort',remote_port,'LocalIPPortSource','Property','LocalIPPort',local_port);
  29. % start recieving udp packets
  30. % setup(hudpr);
  31. fopen(udpconnection);
  32. %% Discover prologix.
  33. % magic string to request ipaddress from prologix: ['5a' '00' '5b' 'db' 'ff' 'ff' 'ff' 'ff' 'ff' 'ff' '00' '00']
  34. magic_msg = uint8([90 0 91 219 255 255 255 255 255 255 00 00]);
  35. % Sending packet.
  36. % hudps(magic_msg);
  37. fwrite(udpconnection,magic_msg);
  38. % Recieving packet or resend.
  39. for i = 1:100
  40. pause(0.1);
  41. msg = fread(udpconnection);
  42. if numel(msg)>0
  43. break;
  44. elseif mod(i,10) == 0
  45. %waiting dot and resending of string
  46. fprintf('.')
  47. fwrite(udpconnection,magic_msg);
  48. % step(hudps,magic_msg);
  49. end
  50. end
  51. fclose(udpconnection);
  52. if ~isempty(msg)
  53. break;
  54. end
  55. end
  56. if isempty(msg)
  57. error('No prologix found on network');
  58. end
  59. %ipaddress string is extracted from recieved UDP message. array position 21
  60. %till 24.
  61. ipaddress = num2str(msg(21:24)','%d.%d.%d.%d');
  62. stored_ipaddress = ipaddress;