posted this on March 10, 2011 12:52 PM
I've been playing around with an iTach IP2IR device. In a wiring closet, I have a cable box connected to a PC. A video capture card in the PC is used to stream the video over our LAN to desktop users. Whenever we need to change the channel, someone must unlock the wiring closet, go in, point the remote at the cable box, and change the channel. Using the IP2IR device, we can now control the cable box from our desktop, sending remote control codes to the IP2IR using a Visual Basic application.
I'm posting the code in case anyone wants to know how to talk to the IP2IR device over IP. The only parameter passed is the code as captured by iLearn.
Private Function SendIRCommand(ByVal strCommand As String) As String Const Host = "192.168.1.1" Const HostPort = 4998 Dim tcpClient As New System.Net.Sockets.TcpClient() tcpClient.Connect(host, hostport) Dim networkStream As NetworkStream = tcpClient.GetStream() Dim strResponse As String strResponse = "No response" If networkStream.CanWrite Then Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(strCommand) networkStream.Write(sendBytes, 0, sendBytes.Length) Dim bytes(tcpClient.ReceiveBufferSize) As Byte networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize)) Dim returndata As String = Encoding.ASCII.GetString(bytes) strResponse = "Device responded: " & CStr(returndata) Else If Not networkStream.CanWrite Then strResponse = "Error: Cannot write data to the device" tcpClient.Close() End If End If Return strResponse End Function