Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

69 lines
2.1KB

  1. function ipaddress = prologix_discovery()
  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. %%Magic
  25. udpmagic = udp('10.255.255.255',12345);
  26. fopen(udpmagic);
  27. fwrite(udpmagic,'windows moet dood');
  28. fclose(udpmagic);
  29. delete udpmagic
  30. %% setup dsp to send and recieve udp packets.
  31. udpconnection = udp('255.255.255.255',3040);
  32. %hudpr = dsp.UDPReceiver('LocalIPPort',local_port);
  33. % hudps = dsp.UDPSender('RemoteIPAddress','255.255.255.255','RemoteIPPort',remote_port,'LocalIPPortSource','Property','LocalIPPort',local_port);
  34. % start recieving udp packets
  35. % setup(hudpr);
  36. fopen(udpconnection);
  37. %% Discover prologix.
  38. % magic string to request ipaddress from prologix: ['5a' '00' '5b' 'db' 'ff' 'ff' 'ff' 'ff' 'ff' 'ff' '00' '00']
  39. magic_msg = uint8([90 0 91 219 255 255 255 255 255 255 00 00]);
  40. % Sending packet.
  41. % hudps(magic_msg);
  42. fwrite(udpconnection,magic_msg);
  43. % Recieving packet or resend.
  44. for i = 1:100
  45. pause(0.1);
  46. msg = fread(udpconnection);
  47. if numel(msg)>0
  48. break;
  49. elseif mod(i,10) == 0
  50. %waiting dot and resending of string
  51. fprintf('.')
  52. fwrite(udpconnection,magic_msg);
  53. % step(hudps,magic_msg);
  54. end
  55. end
  56. fclose(udpconnection);
  57. if isempty(msg)
  58. error('No prologix found on network');
  59. end
  60. %ipaddress string is extracted from recieved UDP message. array position 21
  61. %till 24.
  62. ipaddress = num2str(msg(21:24)','%d.%d.%d.%d');
  63. stored_ipaddress = ipaddress;