You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Cigarette/WindowsFormsApp2/singleCam.cs

233 lines
6.3 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Imaging;
namespace WindowsFormsApp2
{
public partial class singleCam : UserControl
{
static singleCam()
{
}
Client client = new Client();
public singleCam()
{
InitializeComponent();
}
public void closeSocket()
{
client.DisConnection();
}
private void updateUIID(int id)
{
if (InvokeRequired) { Invoke(new Action<int>(updateUIID), id); return; }
else
{
label1.Text = id + 1 + "#检测数";
label2.Text = id + 1 + "#OK数";
label3.Text = id + 1 + "#NG数";
label4.Text = id + 1 + "#剔除数";
groupBox1.Text = id + 1 + "#分析结果";
}
}
public void setCamId(int id)
{
try
{
thisId = id;
updateUIID(id);
client.bindCamId(id);
//client.InitLicenseData(updateTime, updateJd, updateOK, updateNG, updateSpeed, updatekick, updateTotal);
client.InitLicenseData(_update);
client.InitLicenseImage(updateImage);
}
catch (Exception)
{
return;
}
}
private void _update(string data)
{
string info_frame = "1";
string speed_frame = "2";
string kick_frame = "3";
string ok_frame = "4";
string ng_frame = "5";
string total_frame = "7";
if (InvokeRequired) { Invoke(new Action<string>(_update), data); return; }
else{
string[] lis = data.Split('_');
if (lis[0] == info_frame)
{
if(lis.Length == 3)
{
textBox6.Text = lis[1] + "个";
textBox7.Text = lis[2] + "ms";
}
}
else if(lis[0] == speed_frame)
{
textBox5.Text = lis[1] + "个/秒";
}
else if(lis[0] == kick_frame)
{
textBox4.Text = lis[1];
}
else if(lis[0] == ok_frame)
{
updateOK(lis[1]);
}
else if(lis[0] == ng_frame)
{
updateNG(lis[1]);
}
else if (lis[0] == total_frame)
{
textBox1.Text = lis[1];
}
}
}
Bitmap bmp0 = null;
private void updateImage(int Num,Bitmap data)
{
if (pictureBox1.InvokeRequired) {
if(Num==0)
pictureBox1.Invoke(new Action<int, Bitmap>(updateImage), Num, data);
return;
}
else
{
if(Num==0)
{
if(bmp0 != null)
{
bmp0.Dispose();
bmp0 = null;
}
bmp0 = new Bitmap(data);
pictureBox1.Image = bmp0;
}
}
}
private void updateSpeed(string data)
{
if (textBox5.InvokeRequired) { textBox5.Invoke(new Action<string>(updateSpeed), data); return; }
else
{
textBox5.Text = data + "个/秒";
}
}
private void updateTime(string data)
{
if (textBox7.InvokeRequired) { textBox7.Invoke(new Action<string>(updateTime), data); return; }
else
{
textBox7.Text = data + "ms";
}
}
private void updateJd(string data)
{
if (textBox6.InvokeRequired) { textBox6.Invoke(new Action<string>(updateJd), data); return; }
else
{
textBox6.Text = data + "个";
}
}
private void updateTotal(string data)
{
if (textBox1.InvokeRequired) { textBox1.Invoke(new Action<string>(updateTotal), data); return; }
else
{
textBox1.Text = data;
}
}
private void updateOK(string data)
{
if (textBox2.InvokeRequired) { textBox2.Invoke(new Action<string>(updateOK), data); return; }
else
{
textBox2.Text = data;
updateLabel(true);
}
}
private void updateNG(string data)
{
if (textBox3.InvokeRequired) { textBox3.Invoke(new Action<string>(updateNG), data); return; }
else
{
textBox3.Text = data;
updateLabel(false);
}
}
private void updatekick(string data)
{
if (textBox4.InvokeRequired) { textBox4.Invoke(new Action<string>(updatekick), data); return; }
else
{
textBox4.Text = data;
}
}
private void updateLabel(bool ok)
{
if (label8.InvokeRequired) { label8.Invoke(new Action<bool>(updateLabel), ok); return; }
else
{
if (UserControl1.Stop)
{
label8.Visible = false;
}
else
{
label8.Visible = true;
if (ok)
{
label8.Text = "OK";
label8.BackColor = Color.Lime;
}
else
{
label8.Text = "NG";
label8.BackColor = Color.Red;
}
}
}
}
public Action<int> callback = null;
private int thisId = -1;
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
callback?.Invoke(thisId);
}
}
}