Commit dcc082d6 张东亮

1

1 个父辈 47e5bd0f
......@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OnlineStore.Common</RootNamespace>
<AssemblyName>MyCommon</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
......
此文件类型无法预览
此文件类型无法预览
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file
此文件类型无法预览
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Drawing.Common" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup></configuration>
......@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DeviceLibrary</RootNamespace>
<AssemblyName>DeviceLibrary</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
......@@ -32,10 +32,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Asa.Camera.VisionLib, Version=1.3.8482.30580, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\DLL\Asa.Camera.VisionLib.dll</HintPath>
</Reference>
<Reference Include="CodeLibrary, Version=1.0.8384.25672, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\DLL\CodeLibrary.dll</HintPath>
......@@ -70,6 +66,9 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Vision.Video">
<HintPath>..\DLL\Vision.Video.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DeviceLibrary\AcSerialBean.cs" />
......@@ -77,7 +76,6 @@
<Compile Include="DeviceLibrary\CameraTest.cs" />
<Compile Include="DeviceLibrary\CylinderManger.cs" />
<Compile Include="DeviceLibrary\IOMonitor.cs" />
<Compile Include="DeviceLibrary\IPCameraHelper.cs" />
<Compile Include="DeviceLibrary\I_SafetyDevice.cs" />
<Compile Include="DeviceLibrary\LiftMonitor.cs" />
<Compile Include="DeviceLibrary\LineRunMonitor.cs" />
......
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
{
Thread camerathread;
//static HIKCamera _camera;
//Asa.Camera.VisionLib camera;
//public static HIKCamera Current
//{
// get
// {
// if (_camera == null)
// _camera = new HIKCamera();
// return _camera;
// }
//}
public string Name = "";
public event EventHandler<Bitmap> camera_event;
public string DeviceName = "monitor1";
public PictureBox picture = new PictureBox();
bool enableCamera = ConfigHelper.Config.Get("Func_EnableCam", true);
public bool LoadCameraConfig(string CameraID, out string msg, object preview = null)
{
Name = CameraID;
msg = "";
if (!enableCamera) return true;
string path = $".\\Config\\{CameraID}.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 VisionLib(path, true, "HIK.IPCamera");
}
catch (Exception e)
{
msg = Name + crc.GetString(L.monitor_config_load_fail, "加载监控相机配置文件失败:") + e.ToString();
LogUtil.error(Name + "加载监控相机配置文件失败:" + e.ToString());
return false;
}
PictureBox p1 = new PictureBox();
camera.PreviewImage(DeviceName, p1.Handle);
//if (preview == null)
//{
// camera.PreviewImage(DeviceName, picture.Handle);
//}
//else
//{
// camera.PreviewImage(DeviceName, (IntPtr)preview);
//}
camera.Open(DeviceName);
Bitmap bmp = camera.GetImage(DeviceName);
if (bmp == null)
{
msg = Name + crc.GetString(L.monitor_open_fail, "监控相机打开失败");
LogUtil.error(Name + $"监控相机打开失败");
return false;
}
camera_event?.Invoke(this, bmp);
camerathread = new Thread(new ThreadStart(startCamera));
camerathread.Start();
GC.KeepAlive(camerathread);
return true;
}
int errortimes = 0;
bool camerathreadrun = true;
public void stopCamera()
{
camerathreadrun = false;
}
void startCamera()
{
int errorsleeptime = 5000;
camerathreadrun = true;
while (camerathreadrun)
{
try
{
Bitmap bmp = camera.GetImage(DeviceName);
if (bmp != null)
{
errortimes = 0;
errorsleeptime = 5000;
//saveTest(bmp);
camera_event?.Invoke(this, bmp);
}
else if (bmp == null && errortimes < 5)
{
errortimes++;
LogUtil.error(Name + $"相机获取图像出错,{errortimes}");
Thread.Sleep(errorsleeptime);
}
else if (errortimes == 5)
{
camera.Close(DeviceName);
Thread.Sleep(1000);
camera.Open(DeviceName);
errortimes = 0;
errorsleeptime = errorsleeptime * 2;
LogUtil.error(Name + $"相机错误次数过多,重新打开,{errortimes}");
}
else if (errortimes == 6)
{
LogUtil.error(Name + $"相机连接失败, 相机线程退出,{errortimes}");
break;
}
Thread.Sleep(1000 / 5);
}
catch
{
errortimes++;
}
}
try
{
camera.Close(DeviceName);
}
catch { }
camera.Dispose();
}
void saveTest(Bitmap bitmap)
{
if (!Directory.Exists(".\\TestImg"))
{
Directory.CreateDirectory(".\\TestImg");
}
bitmap.Save(Path.Combine(".\\TestImg\\", $"{DateTime.Now.ToString("yyyyMMddhhmmssfff")}.bmp"));
}
public void CameraGrabOne(string filename)
{
try
{
LogUtil.info(Name + "库位文件名:" + filename);
Bitmap bmp = camera.GetImage(DeviceName);
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,
}
using Asa.Camera;
using CodeLibrary;
using DeviceLibrary;
using OnlineStore;
using OnlineStore.Common;
......@@ -14,152 +14,82 @@ using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
public class HIKCamera
{
Thread camerathread;
//static HIKCamera _camera;
Asa.Camera.VisionLib camera;
//public static HIKCamera Current
//{
// get
// {
// if (_camera == null)
// _camera = new HIKCamera();
// return _camera;
// }
//}
public string Name = "";
public event EventHandler<Bitmap> camera_event;
public string DeviceName = "monitor1";
public PictureBox picture = new PictureBox();
bool enableCamera = ConfigHelper.Config.Get("Func_EnableCam", true);
public bool LoadCameraConfig(string CameraID, out string msg, object preview = null)
public bool LoadCameraConfig(out string msg, object preview = null)
{
Name = CameraID;
msg = "";
if (!enableCamera) return true;
string path = $".\\Config\\{CameraID}.json";
string path = $".\\Config\\IPCamera.json";
if (!File.Exists(path))
{
msg = Name + crc.GetString(L.monitor_config_not_exist, "找不到监控相机配置文件");
LogUtil.error(Name + "找不到监控相机配置文件" + path);
msg = crc.GetString(L.monitor_config_not_exist, "找不到监控相机配置文件");
LogUtil.error("找不到监控相机配置文件" + path);
return false;
}
try
{
var configtxt = File.ReadAllText(path);
if (configtxt.IndexOf("Pwd") > 0)
if (!VideoManager.LoadCamera(path, out string loadmsg))
{
configtxt = configtxt.Replace("Pwd", "Password");
configtxt = configtxt.Replace("\"8000\"", "8000");
File.WriteAllText(path, configtxt);
msg = loadmsg;
}
var m = Regex.Match(configtxt, "name\".*?\"(.+)\"", RegexOptions.IgnoreCase);
DeviceName = m.Groups[1].Value;
camera = new VisionLib(path, true, "HIK.IPCamera");
}
catch (Exception e)
{
msg = Name + crc.GetString(L.monitor_config_load_fail, "加载监控相机配置文件失败:") + e.ToString();
LogUtil.error(Name + "加载监控相机配置文件失败:" + e.ToString());
return false;
}
PictureBox p1 = new PictureBox();
camera.PreviewImage(DeviceName, p1.Handle);
//if (preview == null)
//{
// camera.PreviewImage(DeviceName, picture.Handle);
//}
//else
//{
// camera.PreviewImage(DeviceName, (IntPtr)preview);
//}
camera.Open(DeviceName);
Bitmap bmp = camera.GetImage(DeviceName);
if (bmp == null)
{
msg = Name + crc.GetString(L.monitor_open_fail, "监控相机打开失败");
LogUtil.error(Name + $"监控相机打开失败");
msg = crc.GetString(L.monitor_config_load_fail, "加载监控相机配置文件失败:") + e.ToString();
LogUtil.error("加载监控相机配置文件失败:" + e.ToString());
return false;
}
camera_event?.Invoke(this, bmp);
camerathread = new Thread(new ThreadStart(startCamera));
camerathread.Start();
GC.KeepAlive(camerathread);
return true;
}
int errortimes = 0;
bool camerathreadrun = true;
public void stopCamera()
{
camerathreadrun = false;
}
void startCamera()
{
int errorsleeptime = 5000;
camerathreadrun = true;
while (camerathreadrun)
if (VideoManager.CamNames != null && VideoManager.CamNames.Count > 0)
{
try
Name = VideoManager.CamNames[0];
if (preview == null)
{
Bitmap bmp = camera.GetImage(DeviceName);
if (bmp != null)
{
errortimes = 0;
errorsleeptime = 5000;
//saveTest(bmp);
camera_event?.Invoke(this, bmp);
}
else if (bmp == null && errortimes < 5)
{
errortimes++;
LogUtil.error(Name + $"相机获取图像出错,{errortimes}");
Thread.Sleep(errorsleeptime);
}
else if (errortimes == 5)
{
camera.Close(DeviceName);
Thread.Sleep(1000);
camera.Open(DeviceName);
errortimes = 0;
errorsleeptime = errorsleeptime * 2;
LogUtil.error(Name + $"相机错误次数过多,重新打开,{errortimes}");
}
else if (errortimes == 6)
{
LogUtil.error(Name + $"相机连接失败, 相机线程退出,{errortimes}");
break;
}
Thread.Sleep(1000 / 5);
VideoManager.Open(new Dictionary<string, IntPtr> { { Name, picture.Handle } });
}
catch
else
{
errortimes++;
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;
}
try
{
camera.Close(DeviceName);
}
catch { }
camera.Dispose();
return false;
}
void saveTest(Bitmap bitmap)
int errortimes = 0;
bool camerathreadrun = true;
public void startCamera()
{
if (!Directory.Exists(".\\TestImg"))
if(!VideoManager.IsRecording(Name))
{
Directory.CreateDirectory(".\\TestImg");
VideoManager.StartRecord(Name, "Auto2");
}
bitmap.Save(Path.Combine(".\\TestImg\\", $"{DateTime.Now.ToString("yyyyMMddhhmmssfff")}.bmp"));
}
public void stopCamera()
{
VideoManager.StopRecord(Name);
VideoManager.Close();
camerathreadrun = false;
}
public void CameraGrabOne(string filename)
{
try
{
LogUtil.info(Name + "库位文件名:" + filename);
Bitmap bmp = camera.GetImage(DeviceName);
VideoManager.GrabOneImg(Name, out Bitmap bmp);
if (bmp != null)
{
if (File.Exists(filename))
......
using OnlineStore.Common;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration.Install;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class IPCameraHelper
{
static bool Func_EnableTriggerIPCam = ConfigHelper.Config.Get("Func_EnableTriggerIPCam", false);
static string baseDir = ConfigHelper.Config.Get("IPCameraService_HttpServer", "http://localhost:8088");
static string cameName = ConfigHelper.Config.Get("IPCameraService_CamName", "cam1");
public static void StartRecord(string fileName = "")
{
if (!Func_EnableTriggerIPCam) return;
Task.Factory.StartNew(delegate
{
string url = $"{baseDir}/cam/startRecord?camName={cameName}&filename={fileName}";
string res = HttpHelper.Get(url);
LogUtil.info($"开始记录视频:{fileName},{res}");
});
}
public static void StopRecord()
{
if (!Func_EnableTriggerIPCam) return;
Task.Factory.StartNew(delegate
{
string url = $"{baseDir}/cam/stopRecord?camName={cameName}";
string res = HttpHelper.Get(url);
LogUtil.info($"停止记录视频:{res}");
});
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" requireReinstallation="true" />
</packages>
\ No newline at end of file
......@@ -87,7 +87,6 @@ namespace DeviceLibrary
Fix = BoxStorePosition.GetFixPos(Config, To.Reel);
}
MoveInfo.MoveParam.WareCode = WareCode;
IPCameraHelper.StartRecord($"{WareCode}-{From?.posid}-{To?.posid}");
ErrMsgTxt = "";
return true;
//thread = new Thread(new ThreadStart(Run));
......@@ -315,7 +314,6 @@ namespace DeviceLibrary
ErrMsgTxt = "";
InOutEndProcess(StoreMoveType.InStore, To.posid);
storeMoveType = StoreMoveType.None;
IPCameraHelper.StopRecord();
break;
default:
MoveInfo.log($"{storeMoveType}:未找到对应步骤:{MoveInfo.MoveStep}");
......
......@@ -326,7 +326,6 @@ namespace DeviceLibrary
ServerCM.storeStatus = currnetstoreStatus;
}
}
IPCameraHelper.StopRecord();
LogUtil.info("主线程已退出.");
}
public void Start()
......
......@@ -80,7 +80,7 @@ namespace DeviceLibrary
msg += crc.GetString(L.iocard_init_fail, "IO板卡初始化失败")+ "\n";
}
// IOManager.CloseAllConnection();
if (!CameraA.LoadCameraConfig("CameraA", out string errmsg, param[0]))
if (!CameraA.LoadCameraConfig(out string errmsg, param[0]))
{
IsLoadOk = false;
msg += errmsg + "\r\n";
......@@ -127,6 +127,7 @@ namespace DeviceLibrary
isRunning = true;
mainThread = new Thread(new ThreadStart(mainMachine.Start));
mainThread.Start();
CameraA.startCamera();
}
GC.KeepAlive(mainThread);
......
......@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OnlineStore.LoadCSVLibrary</RootNamespace>
<AssemblyName>LoadCSVLibrary</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
......
......@@ -71,7 +71,7 @@
</root>-->
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
......
......@@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<RootNamespace>TheMachine</RootNamespace>
<AssemblyName>MIMO_G2</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>false</Deterministic>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!