Hi Bo,
sorry for the delay.
If I execute “Item item=Configuration.Instance.GetItem(fqid);” I get the Camera Item, so it works.
Here is an example in the ConfigDump sample. This example starts an TcpListener which listens to a TcpClient (code for the client is attached aswell) and starts/stops recording on a camera in my system.
The code is part of the “BackgroundDump.cs”-Class:
=================================================================================
private void Run()
{
Thread.Sleep(30000);
Task.Run(() => StartListener());
while (!\_stop)
{
//Do some work here
Thread.Sleep(15000);
}
}
private void StartListener()
{
TcpListener server = null;
try
{
Int32 port = 13001;
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
server = new TcpListener(localAddr, port);
server.Start();
Byte\[\] bytes = new Byte\[256\];
String data = null;
while (true)
{
try
{
Console.Write("Waiting for a connection... ");
using (TcpClient client = server.AcceptTcpClient())
{
Console.WriteLine("Connected!");
data = null;
NetworkStream stream = client.GetStream();
int i;
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
if (data == "startRecording")
{
//Replace Guid with CameraObjectId of existing camera in your system
Item cameraItem = Configuration.Instance.GetItem(new Guid("66911d2d-eaf5-4768-827c-c4dfcfefa928"), Kind.Camera);
EnvironmentManager.Instance.SendMessage(new Message(MessageId.Control.StartRecordingCommand), cameraItem.FQID);
}
if (data == "stopRecording")
{
//Replace Guid with CameraObjectId of existing camera in your system
Item cameraItem = Configuration.Instance.GetItem(new Guid("66911d2d-eaf5-4768-827c-c4dfcfefa928"), Kind.Camera);
EnvironmentManager.Instance.SendMessage(new Message(MessageId.Control.StopRecordingCommand), cameraItem.FQID);
}
}
}
}catch(Exception ex) { }
Thread.Sleep(100);
}
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
}
finally
{
server.Stop();
}
}
=================================================================================
And here is the code i use for the TcpClient (.Net 6, Console Application) which sends “startRecording” or “stopRecording” commands to the TcpListener running in the Background Plugin of the DonfigDump sample:
=================================================================================
using System.Net.Sockets;
Console.WriteLine(“Tcp Client started!”);
var stop = false;
do
{
var command = Console.ReadLine();
if (command! != null)
{
if (command == "stop")
{
stop = true;
}
else
{
Connect("127.0.0.1", command);
}
}
}while(!stop);
static void Connect(String server, String message)
{
try
{
Int32 port = 13001;
using TcpClient client = new TcpClient(server, port);
Byte\[\] data = System.Text.Encoding.ASCII.GetBytes(message);
NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
Console.WriteLine("Sent: {0}", message);
}
catch (ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException: {0}", e);
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
}
}
=================================================================================
Best regards
Simon