我有一台巴可投影机,我想远程控制自己。
Barco有自己的tool来做这件事,但完全是用java编写的。
当我通过wireshark捕获发送到swith的数据时,我得到以下信息:
0000 00 0d 0a 01 2a bc d8 d3 85 95 91 57 08 00 45 00 ....*......W..E.
0010 00 31 51 72 40 00 80 06 00 00 0a 00 00 0d 0a 00 .1Qr@...........
0020 00 3e ef e1 04 01 c2 67 14 b8 9e da c6 b2 50 18 .>.....g......P.
0030 01 00 14 6e 00 00 3a 49 48 44 4d 20 31 20 0d ...n..:IHDM 1 .
0000 00 0d 0a 01 2a bc d8 d3 85 95 91 57 08 00 45 00 ....*......W..E.
0010 00 28 51 73 40 00 80 06 00 00 0a 00 00 0d 0a 00 .(Qs@...........
0020 00 3e ef e1 04 01 c2 67 14 c1 9e da c6 c4 50 10 .>.....g......P.
0030 01 00 14 65 00 00 ...e..
要切换回DVI,我得到:
0000 00 0d 0a 01 2a bc d8 d3 85 95 91 57 08 00 45 00 ....*......W..E.
0010 00 31 53 1e 40 00 80 06 00 00 0a 00 00 0d 0a 00 .1S.@...........
0020 00 3e ef e1 04 01 c2 67 14 c1 9e da c6 c4 50 18 .>.....g......P.
0030 01 00 14 6e 00 00 3a 49 44 56 49 20 31 20 0d ...n..:IDVI 1 .
0000 00 0d 0a 01 2a bc d8 d3 85 95 91 57 08 00 45 00 ....*......W..E.
0010 00 28 53 20 40 00 80 06 00 00 0a 00 00 0d 0a 00 .(S @...........
0020 00 3e ef e1 04 01 c2 67 14 ca 9e da c6 d6 50 10 .>.....g......P.
0030 00 ff 14 65 00 00 ...e..
我在c#中尝试了一些事情,但收效甚微:
IPAddress beamerIP = new IPAddress(IpToBin("!!Beamer IP!!"));
IPEndPoint ip = new IPEndPoint(beamerIP, 1025);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(ip);
Console.WriteLine("Socket connected to " + socket.RemoteEndPoint.ToString());
byte[] msg = Encoding.ASCII.GetBytes(":IDVI 1 .");
byte[] dvi = new byte[] { 0x3a, 0x49, 0x44, 0x56, 0x49, 0x20, 0x31, 0x20, 0x0d };
byte[] hdmi = new byte[] { 0x3a, 0x49, 0x48, 0x44, 0x4d, 0x20, 0x31, 0x20, 0x0d };
int bytesSent = socket.Send(dvi);
Console.WriteLine("Sent {0} bytes.", bytesSent);
socket.Shutdown(SocketShutdown.Both);
socket.Close();
我也试过像这样thread发送PCAP.NET,但收效甚微。
我做错了什么还是有其他方法吗?
答案 0 :(得分:0)
原来我几乎就在那里。这是对我有用的代码:
// Data buffer for incoming data.
byte[] bytes = new byte[1024];
// Establish the remote endpoint for the socket.
IPAddress beamerIP = new IPAddress(IpToBin("!!Beamer IP!!"));
IPEndPoint ip = new IPEndPoint(beamerIP, 1025);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
socket.Connect(ip);
// Send the data through the socket.
int bytesSent = socket.Send(message); //message => DVI = Encoding.ASCII.GetBytes(":IDVI 1 \r") || HDMI = Encoding.ASCII.GetBytes(":IHDM 1 \r")
// Receive the response from the remote device.
int bytesRec = socket.Receive(bytes);
// Release the socket.
socket.Shutdown(SocketShutdown.Both);
socket.Close();