Code:
' import required modules Imports System.Net Imports System.Net.Sockets Imports System.Text Sub Main(ByVal parms as Object) Dim strCommand as string Dim Yammy_Mute = "sendir,1:1,1,38000,1,69,341,170,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,1517,341,85,21,3655" &vbCR Dim Yammy_UnMute = "sendir,1:1,1,38000,1,69,341,170,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,1517,341,85,21,3655" &vbCR Dim DTV_Pause = "sendir,1:3,1,38000,1,21,229,45,45,45,22,22,22,22,45,45,22,22,45,22,22,22,22,45,22,1143,114,45,45,45,22,22,22,22,45,45,22,22,45,22,22,22,22,45,22,1143" &vbCR Dim Yammy_Power_On = "sendir,1:1,1,38000,1,69,341,170,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,1517,341,85,21,3655" &vbCR Dim Yammy_Power_Off = "sendir,1:1,1,38000,1,69,341,170,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,1517,341,85,21,3655" &vbCR Dim DTV_Power_On = "sendir,1:3,1,39000,1,1,232,46,46,46,23,23,46,23,23,23,23,23,23,23,46,46,46,23,23,1155,116,46,46,46,23,23,46,23,23,23,23,23,23,23,46,46,46,23,23,1155,116,46,46,46,23,23,46,23,23,23,23,23,23,23,46,46,46,23,23,46" &vbCR Dim DTV_Power_Off = "sendir,1:3,1,39000,1,1,232,46,46,46,23,23,46,23,23,23,23,23,23,46,46,46,46,46,23,1155,116,46,46,46,23,23,46,23,23,23,23,23,23,46,46,46,46,46,23,1155,116,46,46,46,23,23,46,23,23,23,23,23,23,46,46,46,46,46,23,46" &vbCR Dim NEC_Power_On = "sendir,1:2,1,38109,1,1,343,171,22,21,21,21,22,21,22,63,22,63,22,21,22,21,21,21,22,63,22,63,22,63,22,21,22,21,21,64,21,64,21,64,21,21,22,21,22,21,22,63,22,21,21,21,22,21,22,21,21,64,21,64,21,64,21,21,22,63,22,63,22,63,22,63,22,1533,343,85,22,3661,342,85,22,3661,342,85,22,3800" &vbCR Dim NEC_Power_Off = "sendir,1:2,1,38000,1,69,342,171,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,21,21,21,21,1702,342,85,21,3663" &vbCR Dim DTV_Digit_9 = "sendir,1:3,1,38000,1,21,229,45,45,45,22,22,22,22,22,22,45,22,22,45,22,45,45,45,22,1143,114,45,45,45,22,22,22,22,22,22,45,22,22,45,22,45,45,45,22,1143" &vbCR Dim Yammy_DTV = "sendir,1:1,1,38000,1,69,341,170,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,64,21,21,21,64,21,21,21,64,21,1517,341,85,21,3655" &vbCR Dim Yammy_CD = "sendir,1:1,1,38000,1,69,341,170,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,64,21,1517,341,85,21,3655" &vbCR If Instr(parms,"pause") then Call IRSend(DTV_Pause) hs.setdevicestring(2393, "I have paused the TV", true) End If If Instr(parms,"mute") then Call IRSend(Yammy_Mute) hs.setdevicestring(2393, "I have muted the TV", true) End If If Instr(parms,"unmute") then Call IRSend(Yammy_UnMute) hs.setdevicestring(2393, "I have unmuted the TV", true) End If If Instr(parms,"news") then Call IRSend(Yammy_Power_On) hs.waitsecs(1) Call IRSend(Yammy_DTV) hs.waitsecs(1) Call IRSend(DTV_Power_On) hs.waitsecs(1) Call IRSend(NEC_Power_On) hs.waitsecs(1) Call IRSend(DTV_Digit_9) hs.setdevicestring(2393, "I have turned on the news", true) End If If InStr(parms,"television on") orElse InStr(parms,"tv on") then hs.setdevicestring(2393, "I have turned the TV On", true) Dim TV_Watts as integer = hs.devicevalue(824) If TV_Watts = 0 then hs.CAPIControlHandler(hs.CAPIGetSingleControl(824,true ,"on",false,true)) hs.waitsecs(2) Else 'Do Nothing End If Call IRSend(Yammy_Power_On) hs.waitsecs(1) Call IRSend(Yammy_DTV) hs.waitsecs(1) Call IRSend(DTV_Power_On) hs.waitsecs(1) Call IRSend(NEC_Power_On) End If If InStr(parms,"television off") orElse InStr(parms,"tv off") then hs.setdevicestring(2393, "I have turned the TV Off", true) Dim TV_Watts as integer = hs.devicevalueEX(822) If TV_Watts > 50 then Call IRSend(Yammy_Power_Off) hs.waitsecs(1) Call IRSend(DTV_Power_Off) hs.waitsecs(1) Call IRSend(NEC_Power_Off) Else 'Do Nothing hs.setdevicestring(2393, "TV is already Off", true) End If End If If InStr(parms,"russound") then Dim Stereo_Power as integer = hs.devicevalue(833) Dim TV_Power as integer = hs.devicevalue(822) Dim Russound_Zone as integer = hs.devicevalue(1336) If Stereo_Power < 30 then 'Stereo Off Call IRSend(Yammy_Power_On) hs.waitsecs(1) Call IRSend(Yammy_CD) Else Call IRSend(Yammy_CD) hs.waitsecs(1) Call IRSend(NEC_Power_Off) End If If Russound_Zone = 0 then Call IRSend(Yammy_Power_Off) End If End If End Sub Sub IRSend(ByVal strCommand as object) Dim tcpClient As New System.Net.Sockets.TcpClient() tcpClient.Connect("10.0.254.19", "4998") 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 hs.writelog("iTach Script", strResponse) tcpClient.Close() End Sub
Leave a comment: