25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.4KB

  1. function [ t,version ] = prologix_connect(ipAddress)
  2. %PROLOGIX_CONNECT opens TCP/IP connection with Prologix device
  3. % [t,version] = PROLOGIX_CONNECT() will automaticly find IP
  4. % address and starts connection.
  5. % [t,version] = PROLOGIX_CONNECT(ipAddress) starts connection
  6. % with given IP address.
  7. % IP address is autodiscovered. But can be used for a
  8. % device on a different subnet.
  9. % If you don't know the IP address leave it empty.
  10. %% define variables
  11. port = 1234;
  12. % if no IP address is given start autodiscovery;
  13. if nargin < 1
  14. ipAddress = prologix_discovery();
  15. elseif isempty(regexp(ipAddress,'([1-2]?[0-9]{1,2}\.){3}[1-2]?[0-9]{1,2}','match'))
  16. error('Given IP address is not valid, leave empty to use autodiscovery of device');
  17. end
  18. %% open connection.
  19. echotcpip('on', port); % start listening for tcp packets on port
  20. t = tcpip(ipAddress,port); % define tcpip connection
  21. fopen(t); % open connection
  22. %% configure prologix.
  23. fprintf(t, '++mode 1'); %set device in controller mode
  24. fprintf(t, '++auto 0'); %disable automatic datapull. this avoids errors on equipment.
  25. fprintf(t, '++ver'); %ask firmware version of the prologix.
  26. version = ['Firmware Version: ', fscanf(t)]; %pull firmware function from prologix.
  27. end