Form1.cs
2.0 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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConsoleTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "*.PNG|*.PNG";
openFileDialog.Multiselect = false;
openFileDialog.ShowDialog();
if (File.Exists(openFileDialog.FileName))
{
var srcfile = openFileDialog.FileName;
string resultfile = Path.GetDirectoryName(srcfile) + "\\" + Path.GetFileNameWithoutExtension(srcfile) + "_Mark.png";
callcounter(srcfile, resultfile);
}
}
Result callcounter(string srcfile, string resultfile) {
var p = new Process();
p.StartInfo = new ProcessStartInfo(Application.StartupPath + "\\wafer_die_counter\\wafer_die_counter.exe");
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = $"\"{srcfile}\" \"{resultfile}\"";
p.Start();
p.WaitForExit(45 * 1000);//最长等待45秒
var x = p.StandardOutput.ReadToEndAsync();
if (x.Wait(1000))
return JsonConvert.DeserializeObject<Result>(x.Result);
else
{
p.Kill();
return new Result() { msg = "外部点料算法调用失败" };
}
}
}
[Serializable]
public class Result
{
public bool success = false;
public int qty = 0;
public string msg = "";//错误消息
}
}