Jump to content

Recommended Posts

Posted

our new projector has a web interface as well as telnet (for some reason) I'm not sure if the web interface has an API

 

Anyway thought it would be nice of me, instead of using a remote - to develop a small application thatll turn the projector on and off.

 

I've wrote the program but it doesnt seem to work as intended (probably to do with my lack of coding fu) doesn't help the fact i've no idea what the program is doing when its running (would be handy to see a telnet window as its doing its stuff)

 

here's the code im trying to use well the sub that i pass a value to anyway

 

    Public Sub projectorcontrol(ByVal onoroff)

       Dim client As Net.Sockets.TcpClient
       Dim sr As IO.StreamReader
       Dim sw As IO.StreamWriter
       Dim ns As Net.Sockets.NetworkStream
       Dim response As String

       'connecting to a server
       client = New Net.Sockets.TcpClient
       Try
           client.Connect(projectorip, 10000) ' 10000 is the port number
       Catch e As Exception
           MessageBox.Show("Failed to connect: " & e.ToString, "Error")
           Return
       End Try

       ns = client.GetStream
       sr = New IO.StreamReader(ns, System.Text.Encoding.ASCII, True) ' this sends our commands to the server
       sw = New IO.StreamWriter(ns)  ' and this will read server's response

       sw.WriteLine("****" & ControlChars.CrLf) ' send pin number

       sw.Flush()

       sw.WriteLine(onoroff & ControlChars.CrLf) ' on or off is c00 on, c02 off

       response = sr.ReadLine()

   End Sub

 

The form is just two huge buttons saying ON OFF respectively

  • 1 month later...
Posted

I seem to remember that the telnet protocol isn't as straight forward as just sending data over tcp.

You need to 1st send some configuration data (something about if you are accepting echo, and go ahead signals)

You have to send a 2 byte commands (255 ) the 255 states that the next byte is an instruction and not a character.

 

It's been a long time since I programmed a telnet client, but there should be plenty of info out on the googlesphere if you search telnet protocol.

 

Hope this points you in the right direction.

Pete.

Posted

Thanks pete,

 

Been pretty much on hold as it's hard to test (i'm building then running to the hall to test, fails then repeat!) , some kind of output window would be beneficial then I can see if it's sending the right information.

Not a critical piece of code just one to help out

 

mark

Posted

Don't know if this Telnet class is any good (a glance suggests it will do), but I would find a free dotNet telnet class.

 

 

Failing that, I happily did cert authenticated SSH sessions to modify large amounts of config on some network gadgets a few years ago by simply calling the puTTY command line util from my dotNet code (puTTY does telnet too).

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...