FrmCamera.cs
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using HalconDotNet;
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OnlineStore.KTKSingleStore
{
public partial class FrmCamera : FrmBase
{
public FrmCamera()
{
InitializeComponent();
}
private void btnOpen_Click(object sender, EventArgs e)
{
string text = cmbCamera.Text;
HDevelopExport.CloseAllCamera();
if (SAStoreManager.store != null)
{
SAStoreManager.store.KNDIOMove(Store_IO_Type.CameraLight_Power, IO_VALUE.HIGH);
}
HDevelopExport.OpenAllCamera();
FormStatus(true);
}
private void FormStatus(bool open)
{
btnOpen.Enabled = !open;
btnCloseCamera.Enabled = open;
btnGetImage.Enabled = open;
timer1.Enabled = open;
}
private void btnGetImage_Click(object sender, EventArgs e)
{
//HObject ho_Image = HDevelopExport.GrabImage();
//if (ho_Image != null)
//{
// HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);
// string[] codeList = HDevelopExport.GetQrCode(ho_Image);
// if (codeList != null)
// {
// this.richTextBox1.Clear();
// foreach (string str in codeList)
// {
// this.richTextBox1.AppendText(str);
// }
// }
//}
}
private void btnCloseCamera_Click(object sender, EventArgs e)
{
if (SAStoreManager.store != null)
{
SAStoreManager.store.KNDIOMove(Store_IO_Type.CameraLight_Power, IO_VALUE.LOW);
}
HDevelopExport.CloseAllCamera();
FormStatus(false);
}
private void FrmCamera_Load(object sender, EventArgs e)
{
foreach (string name in HDevelopExport.cameraNameList)
{
this.cmbCamera.Items.Add(name);
}
this.cmbCamera.SelectedIndex = 0;
FormStatus(false);
}
private void FrmCamera_FormClosed(object sender, FormClosedEventArgs e)
{
if (btnCloseCamera.Enabled.Equals(true))
{
if (SAStoreManager.store != null)
{
SAStoreManager.store.KNDIOMove(Store_IO_Type.CameraLight_Power, IO_VALUE.LOW);
}
HDevelopExport.CloseAllCamera();
FormStatus(false);
}
}
private int preIndex = 0;
int dWidth = 0; int dHeight = 0;
private void timer1_Tick(object sender, EventArgs e)
{
preIndex++;
HObject ho_Image = null;
int index = preIndex % HDevelopExport.cameraNameList.Count;
ho_Image = HDevelopExport.GrabImage(HDevelopExport.cameraNameList[index]);
if (ho_Image != null)
{
if (dWidth <= 0)
{
HTuple width, height;
//int dWidth = 0; int dHeight = 0;
HOperatorSet.GetImageSize(ho_Image, out width, out height);
dWidth = (int)width.D;
dHeight = (int)height.D;
hWindowControl1.HalconWindow.SetPart(0, 0, dHeight, dWidth);
}
HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);
List<string> codeList = HDevelopExport.GetCode(ho_Image);
if (codeList != null)
{
this.richTextBox1.Clear();
this.richTextBox1.AppendText("读取到的二维码列表:" + "\r\n");
Console.Write("读取到的二维码列表" + "\r\n");
foreach (string str in codeList)
{
this.richTextBox1.AppendText(str+"\r\n");
Console.Write(str + "\r\n");
}
}
//pictureBox1.Handle,获取pictureBox1的句柄
// HOperatorSet.OpenWindow(0, 0, width, height, pictureBox1.Handle, "visible", "", out hWindowControl1);
}
}
}
}