iTach python example

I thought I'd contribute this to the community since it took me a little while to figure out how to get this right. It shows how to send a command to an iTach CC and how to handle the return values using sockets in python. It can get tighter/cleaner, but I left it very basic so it's easier for people to play with.


import socket

HOST2 = ''

PORT2 = 4998

s = socket.socket( socket.AF_INET, socket.SOCK_STREAM)

s.connect((HOST2, PORT2))


response = s.recv(24) #This is the echo back from iTach

print "Response from send():", response


state = s.recv(24)

if ( int(state[10:11]) == 1 ):

  print "Current state is ON"

elif ( int(state[10:11]) == 0 ):

  print "Current state is OFF"


  print "Unknown. Got:", state


Please sign in to leave a comment.