SoDaRadio-5.0.3-master:8901fb5
n200serport.py
Go to the documentation of this file.
1 #!/bin/python
2 
3 import socket
4 import sys
5 import time
6 
7 try:
8  sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
9 except socket.error:
10  print 'Failed to create socket'
11  sys.exit()
12 
13 host = '192.168.10.2'
14 port = 49172
15 
16 #sock.setblocking(0)
17 msg = ("ON00NO\r", "ST00TS\r")
18 sel = 0
19 while(1):
20 
21  try :
22  print 'About to send [' + msg[sel] + ']'
23  sock.sendto(msg[sel], (host, port))
24  print 'Sent'
25 
26  time.sleep(1)
27 
28  time.sleep(5)
29  (reply, rport) = sock.recvfrom(1024)
30  print 'Got reply : ' + reply
31  print 'On port ' + str(rport)
32  #(reply, rport) = sock.recvfrom(1024)
33  except socket.error, erm:
34  print 'Error Code : ' + str(erm[0]) + ' Message ' + erm[1]
35  sys.exit()
36 
37  if sel == 0:
38  sel = 1
39  else:
40  sel = 0
41