I am attempting to write a .net script to communicate commands to the iTach. I am new to vb.net and get the Warning message below. I have also posted the script. Any help would be appreciated. BTW I took the code from another post and hope to make it work for me with the appropriate modifications.
VB.Net script exception(0), re-starting: Object reference not set to an instance of an object
VB.Net script exception(0), re-starting: Object reference not set to an instance of an object
Code:
' import required modules Imports System.Net Imports System.Net.Sockets Imports System.Text Public Sub TVControl() Const Host = "192.168.1.250" Const HostPort = 4998 Const LGTVPWRCode = "sendir,1:1,1,56561,1,1,19,75,10,4,1,79,8,3,1,179" &vbCR 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(LGTVPWRCode) 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) hs.WriteLog (strResponse) Else If Not networkStream.CanWrite Then strResponse = "Error: Cannot write data to the device" tcpClient.Close() hs.WriteLog (strResponse) End If End If End Sub
Comment