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
138
using DeviceLibrary;
using OnlineStore;
using OnlineStore.Common;
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
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();
//Asa.Camera.VisionLib camera;
//public bool LoadCameraConfig(string CameraID, out string msg)
//{
// Name = CameraID;
// msg = "";
// //string path = $"D\\X800\\Config\\{CameraID}.json";
// string path = CommonLib.GetPath(@"Config\CameraA.json");
// if (!File.Exists(path))
// {
// msg = Name + crc.GetString(L.monitor_config_not_exist, "找不到监控相机配置文件");
// LogUtil.error(Name + "找不到监控相机配置文件" + path);
// return false;
// }
// try
// {
// var configtxt = File.ReadAllText(path);
// if (configtxt.IndexOf("Pwd") > 0)
// {
// configtxt = configtxt.Replace("Pwd", "Password");
// configtxt = configtxt.Replace("\"8000\"", "8000");
// File.WriteAllText(path, configtxt);
// }
// var m = Regex.Match(configtxt, "name\".*?\"(.+)\"", RegexOptions.IgnoreCase);
// DeviceName = m.Groups[1].Value;
// camera = new Asa.Camera.VisionLib(path, true, "HIKIPCamera");
// }
// catch (Exception e)
// {
// msg = Name + crc.GetString(L.monitor_config_load_fail, "加载监控相机配置文件失败:") + e.ToString();
// LogUtil.error(Name + "加载监控相机配置文件失败:" + e.ToString());
// return false;
// }
// camera.Open(DeviceName);
// //Bitmap bmp = camera.GetImage(DeviceName);
// //if (bmp == null)
// //{
// // msg = Name + crc.GetString(L.monitor_open_fail,"监控相机打开失败");
// // LogUtil.error(Name + $"监控相机打开失败");
// // return false;
// //}
// //camerathread = new Thread(new ThreadStart(startCamera));
// //camerathread.Start();
// //GC.KeepAlive(camerathread);
// return true;
//}
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 Bitmap GetImage(int index)
{
return null;
//if (camera == null)
// return null;
//return camera.GetImage(index);
}
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,
}