Camera.cs
4.3 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 CodeLibrary;
using DeviceLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
public class HIKCamera
{
public string Name = "";
public event EventHandler<Bitmap> camera_event;
public string DeviceName = "monitor1";
public PictureBox picture = new PictureBox();
//public bool LoadCameraConfig(out string msg, object preview = null)
//{
// msg = "";
// if (!enableCamera) return true;
// string path = $".\\Config\\IPCamera.json";
// if (!File.Exists(path))
// {
// msg = crc.GetString(L.monitor_config_not_exist, "找不到监控相机配置文件");
// LogUtil.error("找不到监控相机配置文件" + path);
// return false;
// }
// try
// {
// if (!VideoManager.LoadCamera(path, out string loadmsg))
// {
// msg = loadmsg;
// }
// }
// catch (Exception e)
// {
// msg = crc.GetString(L.monitor_config_load_fail, "加载监控相机配置文件失败:") + e.ToString();
// LogUtil.error("加载监控相机配置文件失败:" + e.ToString());
// return false;
// }
// if (VideoManager.CamNames != null && VideoManager.CamNames.Count > 0)
// {
// Name = VideoManager.CamNames[0];
// if (preview == null)
// {
// VideoManager.Open(new Dictionary<string, IntPtr> { { Name, picture.Handle } });
// }
// else
// {
// VideoManager.Open(new Dictionary<string, IntPtr> { { Name, (IntPtr)preview } });
// }
// VideoManager.GrabOneImg(Name, out Bitmap bmp);
// if (bmp == null)
// {
// msg = Name + crc.GetString(L.monitor_open_fail, "监控相机打开失败");
// LogUtil.error(Name + $"监控相机打开失败");
// return false;
// }
// VideoManager.StartRecord(Name, "Auto1");
// camera_event?.Invoke(this, bmp);
// return true;
// }
// return false;
//}
int errortimes = 0;
bool camerathreadrun = true;
public void startCamera()
{
//if(!VideoManager.IsRecording(Name))
//{
// VideoManager.StartRecord(Name, "Auto2");
//}
}
public void stopCamera()
{
//VideoManager.StopRecord(Name);
//VideoManager.Close();
camerathreadrun = false;
}
public void CameraGrabOne(string filename)
{
//try
//{
// LogUtil.info(Name + "库位文件名:" + filename);
// VideoManager.GrabOneImg(Name, out Bitmap bmp);
// if (bmp != null)
// {
// if (File.Exists(filename))
// File.Delete(filename);
// bmp.Save(filename, ImageFormat.Jpeg);
// bmp.Dispose();
// }
//}
//catch (Exception e)
//{
// LogUtil.error(Name + e.ToString());
//}
}
public string GetFixtureStateFilename(string PositionNum, string WareNumber, StoreMoveType storeMoveType, FixtureState fixtureState)
{
Path.GetInvalidFileNameChars().ToList().ForEach((ix) => { WareNumber = WareNumber.Replace(ix.ToString(), ""); });
if (WareNumber.Length > 150)
{
WareNumber = "";
}
if (string.IsNullOrEmpty(WareNumber))
WareNumber = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
string dir = $"\\image\\Fixture\\{storeMoveType}\\{PositionNum}\\";
Directory.CreateDirectory(dir);
string filename = $"{WareNumber}@@{fixtureState}.jpg";
foreach (var x in Path.GetInvalidFileNameChars())
{
filename = filename.Replace(x.ToString(), "");
}
return dir + filename;
}
}
public enum FixtureState
{
FromIn,
FromOut,
FromInSide,
FromOutSide,
ToIn,
ToOut,
ToInSide,
ToOutSide,
ToFix,
}