mirror of
https://github.com/d-moco/panSight3DForm.git
synced 2025-01-10 04:27:16 -05:00
增加开始彩图 停止彩图 软件触发一次
This commit is contained in:
parent
aad93c08e7
commit
f5cdcae39c
@ -30,6 +30,8 @@ namespace PanSight3DForm
|
|||||||
enum TEST_TYPE { TEST_TYPE_GRAB_PNTS_CLOUD, TEST_TYPE_LOOP_GRAB, TEST_TYPE_PROFILES };
|
enum TEST_TYPE { TEST_TYPE_GRAB_PNTS_CLOUD, TEST_TYPE_LOOP_GRAB, TEST_TYPE_PROFILES };
|
||||||
|
|
||||||
TEST_TYPE m_testType = TEST_TYPE.TEST_TYPE_GRAB_PNTS_CLOUD;
|
TEST_TYPE m_testType = TEST_TYPE.TEST_TYPE_GRAB_PNTS_CLOUD;
|
||||||
|
|
||||||
|
TcpServer server;
|
||||||
#endregion
|
#endregion
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
@ -37,6 +39,10 @@ namespace PanSight3DForm
|
|||||||
m_camera.DepthEvent += onDepth;
|
m_camera.DepthEvent += onDepth;
|
||||||
|
|
||||||
m_camera.prepare();
|
m_camera.prepare();
|
||||||
|
server = new TcpServer(3000);
|
||||||
|
server.CommandReceived += Server_CommandReceived;
|
||||||
|
server.ClientConnected += Server_ClientConnected;
|
||||||
|
server.ClientDisconnected += Server_ClientDisconnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void M_camera_ImageEvent(IntPtr arg1, CameraWrapper.SG_IMGDATA_PARAM arg2, IntPtr arg3)
|
private void M_camera_ImageEvent(IntPtr arg1, CameraWrapper.SG_IMGDATA_PARAM arg2, IntPtr arg3)
|
||||||
@ -597,5 +603,33 @@ namespace PanSight3DForm
|
|||||||
|
|
||||||
CameraSyn.LibRelease();
|
CameraSyn.LibRelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Server_ClientDisconnected(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("有客户端断开");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Server_ClientConnected(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("有客户端连接");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Server_CommandReceived(object sender, string command)
|
||||||
|
{
|
||||||
|
switch (command)
|
||||||
|
{
|
||||||
|
case "start":
|
||||||
|
buttonStart_Click(sender,null);
|
||||||
|
break;
|
||||||
|
case "softOnce":
|
||||||
|
buttonCapture_Click(sender, null);
|
||||||
|
break;
|
||||||
|
case "stop":
|
||||||
|
buttonStop_Click(sender, null);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,6 +108,7 @@
|
|||||||
<Compile Include="GzLinearDetection.cs" />
|
<Compile Include="GzLinearDetection.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="TcpServer.cs" />
|
||||||
<EmbeddedResource Include="DetectForm1.resx">
|
<EmbeddedResource Include="DetectForm1.resx">
|
||||||
<DependentUpon>DetectForm1.cs</DependentUpon>
|
<DependentUpon>DetectForm1.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
95
PanSight3DForm/TcpServer.cs
Normal file
95
PanSight3DForm/TcpServer.cs
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PanSight3DForm
|
||||||
|
{
|
||||||
|
|
||||||
|
public class TcpServer
|
||||||
|
{
|
||||||
|
public event EventHandler<string> CommandReceived; // 事件,当收到命令时触发
|
||||||
|
public event EventHandler ClientConnected; // 事件,当有客户端连接时触发
|
||||||
|
public event EventHandler ClientDisconnected; // 事件,当客户端断开连接时触发
|
||||||
|
|
||||||
|
private TcpListener tcpListener;
|
||||||
|
private Thread listenThread;
|
||||||
|
|
||||||
|
public TcpServer(int port)
|
||||||
|
{
|
||||||
|
this.tcpListener = new TcpListener(IPAddress.Any, port);
|
||||||
|
this.listenThread = new Thread(new ThreadStart(ListenForClients));
|
||||||
|
this.listenThread.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void ListenForClients()
|
||||||
|
{
|
||||||
|
this.tcpListener.Start();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
TcpClient client = this.tcpListener.AcceptTcpClient();
|
||||||
|
OnClientConnected(EventArgs.Empty); // 触发客户端连接事件
|
||||||
|
|
||||||
|
Thread clientThread = new Thread(new ParameterizedThreadStart(HandleClientComm));
|
||||||
|
clientThread.Start(client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleClientComm(object client)
|
||||||
|
{
|
||||||
|
TcpClient tcpClient = (TcpClient)client;
|
||||||
|
NetworkStream clientStream = tcpClient.GetStream();
|
||||||
|
byte[] message = new byte[4096];
|
||||||
|
int bytesRead;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
bytesRead = 0;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bytesRead = clientStream.Read(message, 0, 4096);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// 发生错误,可能是连接中断
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bytesRead == 0)
|
||||||
|
{
|
||||||
|
// 客户端已断开连接
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASCIIEncoding encoder = new ASCIIEncoding();
|
||||||
|
string command = encoder.GetString(message, 0, bytesRead).Trim();
|
||||||
|
OnCommandReceived(command); // 触发命令接收事件
|
||||||
|
}
|
||||||
|
|
||||||
|
tcpClient.Close();
|
||||||
|
OnClientDisconnected(EventArgs.Empty); // 触发客户端断开连接事件
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnCommandReceived(string command)
|
||||||
|
{
|
||||||
|
CommandReceived?.Invoke(this, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnClientConnected(EventArgs e)
|
||||||
|
{
|
||||||
|
ClientConnected?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnClientDisconnected(EventArgs e)
|
||||||
|
{
|
||||||
|
ClientDisconnected?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user