カメラ (Scopia XT5000 - Radvision) などのデバイスをリモートで制御できるアプリケーションを作成しています。デバイスを制御する AT コマンドを送信できるようにするには、デバイスに初期化コマンドを送信する必要があります。
初期化コマンドを送信すると、サーバーは次のように応答する必要があります:
In String
??\0\0\0 AT[<IP400C9XT5000-03.01.00.0028\r??\0\0\0OK\r
バイト単位
170 170 0 0 0 32 65 84 91 60 73 80 52 48 48 67 57 88 84 53 48 48 48 45 48 51 46 48 49 46 48 48 46 48 48 50 56 13 170 170 3 0 39
ここにブレークを入れると、デバッグを試みてそれらの値を取得しました
serverStream.Read(inStream, 0, inStream.Length);
しかし、デバッグや中断をせずにプログラムを実行するたびに、異なる文字列とバイトが返されます。このよう
に文字列で
??\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0
バイト単位
170 170 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
何が問題なのですか?
それは:
- Null バイトですか?
-キャリッジリターン?"\r"?
-複数の行?
コード全体:
{
TcpClient clientSocket = new System.Net.Sockets.TcpClient();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
msg("Client Started");
}
public void openSocket()
{
if (clientSocket.Connected)
{
clientSocket.Close();
}
clientSocket = new System.Net.Sockets.TcpClient();
clientSocket.Connect("10.0.3.202", 55003);
label1.Text = "Client Socket Program - Server Connected ...";
}
private void btnSend_Click(object sender, EventArgs e)
{
openSocket();
//header bytes and initAT bytes are the initialization command for me to send AT commands
msg("Init: ");
NetworkStream serverStream = clientSocket.GetStream();
//header bytes to enable AT command
byte[] header = {170,170,0,0,0,8 };
serverStream.Write(header, 0, header.Length);
serverStream.Flush();
//Initialize the Interface
byte[] initAT = System.Text.Encoding.ASCII.GetBytes("AT[&IPV\r");
serverStream.Write(initAT,0, initAT.Length);
serverStream.Flush();
byte[] inStream = new byte[10025];
serverStream.Read(inStream, 0, inStream.Length);
string returndata = System.Text.Encoding.ASCII.GetString(inStream);
msg("Data from Server : " + returndata);
}
private void btnRight_Click(object sender, EventArgs e)
{
msg("Right : ");
NetworkStream serverStream = clientSocket.GetStream();
//AT Command to move the main camera to right
byte[] outStream3 = System.Text.Encoding.ASCII.GetBytes("AT[&SY011R\r");
serverStream.Write(outStream3, 0, outStream3.Length);
byte[] inStream2 = new byte[48];
serverStream.Read(inStream2, 0,inStream2.Length);
string returndata = System.Text.Encoding.ASCII.GetString(inStream2);
msg(returndata);
}
public void msg(string mesg)
{
textBox1.Text = textBox1.Text + Environment.NewLine + " >> " + mesg;
}
}