I am helping my church to develop a simple C# Projector control desktop application. (without pay)
The targeted projector is Hitachi Projector - CP-WX3014N supporting sending RS-232 command via network.
The main function of the application include power on/off and changing the input source.
From the operation manual, I have found the following information: "content.etilize.com/user-manual/1020465953.pdf"
While I am new in this area, I would like to ask whether there are any good examples or tutorials I can
look at or take as reference before starting my work. (I have done a search from google but can't find good tutorial or source code related to this area)
Thanks very much and any help is appreciate.
=================================================
I have tried to develop the C# code as below, please kindly advise whether the code is appropriate.
public static byte[] StringToByteArray(String hex) { int NumberChars = hex.Length / 2; byte[] bytes = new byte[NumberChars]; using (var sr = new StringReader(hex)) { for (int i = 0; i < NumberChars; i++) bytes[i] = Convert.ToByte(new string(new char[2] { (char)sr.Read(), (char)sr.Read() }), 16); } return bytes; } static string SendCommand(String value) { Int32 port = 23; String hostname = "192.168.0.254"; String responseData = String.Empty; try { TcpClient client = new TcpClient(hostname, port); Byte[] data = StringToByteArray(value); NetworkStream stream = client.GetStream(); stream.Write(data, 0, data.Length); data = new Byte[8]; Int32 bytes = stream.Read(data, 0, data.Length); responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes); stream.Close(); client.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return responseData ; }
Code for powering on the projector
String value = "BE EF 03 06 00 2A D3 01 00 00 60 01 00"; SendCommand(value);