Example: Control video projector via PJLINK protocol from LogicMachine

Task

How to turn ON and OFF video projector using PJLINK protocol? Use LogicMachine with the following event-based script.

Event-based script

Add this script for the grp address which will control ON/OFF from visualization. In this example video projector’s IP is 192.168.1.5, port 4352.

Source code    
  1. require('socket')
  2.  
  3. value = event.getvalue()
  4.  
  5. ip = '192.168.1.5'
  6. port = 4352
  7.  
  8. if value == 1 then
  9. cmd = '%1POWR 1\r\n'
  10. else
  11. cmd = '%1POWR 0\r\n'
  12. end
  13.  
  14. sock = socket.tcp()
  15. sock:settimeout(1)
  16.  
  17. res, err = sock:connect(ip, port)
  18.  
  19. if res then
  20. res, err = sock:send(cmd)
  21.  
  22. if res then
  23. alert('Send OK')
  24. else
  25. alert('Send failed: %s', tostring(err))
  26. end
  27. else
  28. alert('Connect failed: %s', tostring(err))
  29. end