修改界面

This commit is contained in:
xhm\HP 2025-03-12 17:18:39 +08:00
parent b8c83e459d
commit a9d02a5a9d
14 changed files with 2425 additions and 636 deletions

View File

@ -12,7 +12,7 @@ namespace DH.Devices.Camera
public class Do3ThinkCamera : CameraBase
{
private dvpCameraInfo stDevInfo = new dvpCameraInfo();
private dvpStatus nRet = dvpStatus.DVP_STATUS_OK;
private DVPCamera.dvpEventCallback pCallBackFunc;
@ -24,7 +24,7 @@ namespace DH.Devices.Camera
public Double m_dfDisplayCount = 0;
public Do3ThinkCamera()
{
}
@ -66,7 +66,7 @@ namespace DH.Devices.Camera
dvpCameraInfo camerainfo = new dvpCameraInfo();
nRet = DVPCamera.dvpGetCameraInfo(m_handle, ref camerainfo);
SerialNumber= camerainfo.SerialNumber;
SerialNumber = camerainfo.SerialNumber;
// ch:注册异常回调函数 | en:Register Exception Callback
//nRet = DVPCamera.dvpRegisterEventCallback(m_handle, pCallBackFunc, dvpEvent.EVENT_DISCONNECTED, IntPtr.Zero);
//if (nRet != dvpStatus.DVP_STATUS_OK)
@ -87,82 +87,82 @@ namespace DH.Devices.Camera
//}
//else
//{
// ch:设置触发模式为on || en:set trigger mode as on
nRet = DVPCamera.dvpSetTriggerState(m_handle, true);
if (dvpStatus.DVP_STATUS_OK != nRet)
{
throw new Exception("Set TriggerMode failed!");
}
// ch:设置触发模式为on || en:set trigger mode as on
nRet = DVPCamera.dvpSetTriggerState(m_handle, true);
if (dvpStatus.DVP_STATUS_OK != nRet)
{
throw new Exception("Set TriggerMode failed!");
}
// 硬触发
//if (IIConfig.IsHardwareTrigger)
//{
// ch:触发源选择:1 - Line1; | en:Trigger source select:1 - Line1;
nRet = DVPCamera.dvpSetTriggerSource(m_handle, dvpTriggerSource.TRIGGER_SOURCE_LINE1);
if (dvpStatus.DVP_STATUS_OK != nRet)
{
throw new Exception("Set Line1 Trigger failed!");
}
// 硬触发
//if (IIConfig.IsHardwareTrigger)
//{
// ch:触发源选择:1 - Line1; | en:Trigger source select:1 - Line1;
nRet = DVPCamera.dvpSetTriggerSource(m_handle, dvpTriggerSource.TRIGGER_SOURCE_LINE1);
if (dvpStatus.DVP_STATUS_OK != nRet)
{
throw new Exception("Set Line1 Trigger failed!");
}
// ch:注册回调函数 | en:Register image callback
ImageCallback = new DVPCamera.dvpStreamCallback(ImageCallbackFunc);
nRet = DVPCamera.dvpRegisterStreamCallback(m_handle, ImageCallback, dvpStreamEvent.STREAM_EVENT_PROCESSED, IntPtr.Zero);
if (dvpStatus.DVP_STATUS_OK != nRet)
{
throw new Exception("Register image callback failed!");
}
//}
//else // 软触发
//{
// nRet = DVPCamera.dvpSetTriggerSource(m_handle, dvpTriggerSource.TRIGGER_SOURCE_SOFTWARE);
// if (dvpStatus.DVP_STATUS_OK != nRet)
// {
// throw new Exception("Set Software Trigger failed!");
// }
//}
// ch:注册回调函数 | en:Register image callback
ImageCallback = new DVPCamera.dvpStreamCallback(ImageCallbackFunc);
nRet = DVPCamera.dvpRegisterStreamCallback(m_handle, ImageCallback, dvpStreamEvent.STREAM_EVENT_PROCESSED, IntPtr.Zero);
if (dvpStatus.DVP_STATUS_OK != nRet)
{
throw new Exception("Register image callback failed!");
}
//}
//else // 软触发
//{
// nRet = DVPCamera.dvpSetTriggerSource(m_handle, dvpTriggerSource.TRIGGER_SOURCE_SOFTWARE);
// if (dvpStatus.DVP_STATUS_OK != nRet)
// {
// throw new Exception("Set Software Trigger failed!");
// }
//}
// ch:开启抓图 || en: start grab image
nRet = DVPCamera.dvpStart(m_handle);
if (dvpStatus.DVP_STATUS_OK != nRet)
{
throw new Exception($"Start grabbing failed:{nRet:x8}");
}
//// 曝光
//if (IIConfig.DefaultExposure != 0)
//{
// SetExposure(IIConfig.DefaultExposure);
//}
//// 增益
//if (IIConfig.Gain >= 0)
//{
// SetGain(IIConfig.Gain);
//}
//SetPictureRoi(IIConfig.VelocityPara.A_Pic_X, IIConfig.VelocityPara.A_Pic_Y, IIConfig.VelocityPara.Width, IIConfig.VelocityPara.Hight);
// ch:开启抓图 || en: start grab image
nRet = DVPCamera.dvpStart(m_handle);
if (dvpStatus.DVP_STATUS_OK != nRet)
{
throw new Exception($"Start grabbing failed:{nRet:x8}");
}
//// 曝光
//if (IIConfig.DefaultExposure != 0)
//{
// SetExposure(IIConfig.DefaultExposure);
//}
//// 增益
//if (IIConfig.Gain >= 0)
//{
// SetGain(IIConfig.Gain);
//}
//SetPictureRoi(IIConfig.VelocityPara.A_Pic_X, IIConfig.VelocityPara.A_Pic_Y, IIConfig.VelocityPara.Width, IIConfig.VelocityPara.Hight);
//// 设置 触发延迟
//if (IIConfig.TriggerDelay > 0)
//{
// nRet = DVPCamera.dvpSetTriggerDelay(m_handle, IIConfig.TriggerDelay);
// if (nRet != dvpStatus.DVP_STATUS_OK)
// {
// throw new Exception("Set TriggerDelay failed!");
// }
//}
//// 设置 触发延迟
//if (IIConfig.TriggerDelay > 0)
//{
// nRet = DVPCamera.dvpSetTriggerDelay(m_handle, IIConfig.TriggerDelay);
// if (nRet != dvpStatus.DVP_STATUS_OK)
// {
// throw new Exception("Set TriggerDelay failed!");
// }
//}
//// 信号消抖
//if (IIConfig.LineDebouncerTime > 0)
//{
// nRet = DVPCamera.dvpSetTriggerJitterFilter(m_handle, IIConfig.LineDebouncerTime);
// if (nRet != dvpStatus.DVP_STATUS_OK)
// {
// throw new Exception($"LineDebouncerTime set failed:{nRet}");
// }
//}
//// 信号消抖
//if (IIConfig.LineDebouncerTime > 0)
//{
// nRet = DVPCamera.dvpSetTriggerJitterFilter(m_handle, IIConfig.LineDebouncerTime);
// if (nRet != dvpStatus.DVP_STATUS_OK)
// {
// throw new Exception($"LineDebouncerTime set failed:{nRet}");
// }
//}
//IIConfig.PropertyChanged -= IIConfig_PropertyChanged;
//IIConfig.PropertyChanged += IIConfig_PropertyChanged;
//IIConfig.PropertyChanged -= IIConfig_PropertyChanged;
//IIConfig.PropertyChanged += IIConfig_PropertyChanged;
return true;
return true;
}
catch
{
@ -258,20 +258,20 @@ namespace DH.Devices.Camera
/// <exception cref="Exception"></exception>
private void SetExposure(double exposure)
{
// 关闭自动曝光
nRet = DVPCamera.dvpSetAeOperation(m_handle, dvpAeOperation.AE_OP_OFF);
if (nRet != dvpStatus.DVP_STATUS_OK)
{
throw new Exception($"Exposure set failed:{nRet}");
}
// 设置曝光值
nRet = DVPCamera.dvpSetExposure(m_handle, exposure);
if (nRet != dvpStatus.DVP_STATUS_OK)
{
throw new Exception($"Exposure set failed:{nRet}");
}
}
// 关闭自动曝光
nRet = DVPCamera.dvpSetAeOperation(m_handle, dvpAeOperation.AE_OP_OFF);
if (nRet != dvpStatus.DVP_STATUS_OK)
{
throw new Exception($"Exposure set failed:{nRet}");
}
// 设置曝光值
nRet = DVPCamera.dvpSetExposure(m_handle, exposure);
if (nRet != dvpStatus.DVP_STATUS_OK)
{
throw new Exception($"Exposure set failed:{nRet}");
}
}
/// <summary>
@ -309,16 +309,23 @@ namespace DH.Devices.Camera
public int ImageCallbackFunc(uint handle, dvpStreamEvent _event, IntPtr pContext, ref dvpFrame refFrame, IntPtr pBuffer)
{
Mat cvImage = new Mat();
if (this.CameraName.Equals("Cam1"))
{
Console.WriteLine( );
}
if (this.CameraName.Equals("Cam2"))
{
Console.WriteLine();
}
try
{
Interlocked.Increment(ref SnapshotCount);
int nWidth = refFrame.iWidth;
int nHeight = refFrame.iHeight;
// 根据图像格式创建Mat
switch (refFrame.format)
{
@ -336,7 +343,8 @@ namespace DH.Devices.Camera
break;
default:
throw new NotSupportedException($"Unsupported format: {refFrame.format}");
cvImage = Mat.FromPixelData(nHeight, nWidth, MatType.CV_8UC1, pBuffer);
break;
}
Mat smat = cvImage.Clone();
OnHImageOutput?.Invoke(DateTime.Now, this, smat);
@ -349,7 +357,7 @@ namespace DH.Devices.Camera
}
catch (Exception ex)
{
}
finally
{

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
using DH.Commons.Enums;
using DH.Devices.Motion;
using MCDLL_NET;
using OpenCvSharp;
using System.Diagnostics;
using static System.Collections.Specialized.BitVector32;
@ -287,53 +288,56 @@ namespace DH.Devices.Motion
for (ushort station = 0; station < BoardCount; station++)
{
// 关闭调试测试后的位置比较
//关闭调试测试后的位置比较
for (int i = 0; i < 16; i++)
{
rtn = CMCDLL_NET.MCF_Set_Compare_Config_Net((ushort)i, 0, 0, station);
Console.WriteLine($"MCF_Set_Compare_Config_Net {i}::{rtn}");
}
// 2.配置物件设置
rtn = CMCDLL_NET_Sorting.MCF_Sorting_Set_Piece_Size_Net(PieceMaxSize, PieceMinSize, station);
//2.配置物件设置
rtn = CMCDLL_NET.MCF_Sorting_Set_Piece_Size_Net(PieceMaxSize, PieceMinSize, station);
Console.WriteLine($"MCF_Sorting_Set_Piece_Size_Net::{rtn}");
rtn = CMCDLL_NET_Sorting.MCF_Sorting_Set_Piece_Place_Net(MinDistance, MinTimeInterval, station);
rtn = CMCDLL_NET.MCF_Sorting_Set_Piece_Place_Net(MinDistance, MinTimeInterval, station);
Console.WriteLine($"MCF_Sorting_Set_Piece_Place_Net::{rtn}");
}
if (BoardCount < 2)
{
// rtn = CMCDLL_NET_Sorting.MCF_Sorting_Camera_Blow_Config_Net(10, 6, 0);
// 3.配置相机设置
rtn = CMCDLL_NET_Sorting.MCF_Sorting_Camera_Blow_Config_Net(10, 6, 0);
//设置来料使能 0 是默认 1是开始
//
rtn = CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Enable_Net((ushort)SortingInputSetting.BitInputNumber, 1);
//设置物件检测有效电平 0是低电平 1是高电平
rtn = CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Logic_Net((ushort)SortingInputSetting.BitInputNumber, 0);
//设置来料检测编码器 双转盘要设置两个轴
/*Bit_Input_Number
Bit_Input_0, Bit_Input_1
Axis:
Source
0
1()
StationNumber: */
// rtn = CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Source_Net((ushort)IIConfig.SortingInputSetting.BitInputNumber, 0, 1);
rtn = CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Source_Net((ushort)SortingInputSetting.BitInputNumber, 1, 1);
//if (BoardCount < 2)
//{
// // rtn = CMCDLL_NET_Sorting.MCF_Sorting_Camera_Blow_Config_Net(10, 6, 0);
// // 3.配置相机设置
// rtn = CMCDLL_NET_Sorting.MCF_Sorting_Camera_Blow_Config_Net(10, 6, 0);
// //设置来料使能 0 是默认 1是开始
// //
// rtn = CMCDLL_NET.MCF_Sorting_Set_Input_Enable_Net((ushort)SortingInputSetting.BitInputNumber, 1);
// //设置物件检测有效电平 0是低电平 1是高电平
// rtn = CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Logic_Net((ushort)SortingInputSetting.BitInputNumber, 0);
// //设置来料检测编码器 双转盘要设置两个轴
// /*Bit_Input_Number设置位号。
// 取值: Bit_Input_0, Bit_Input_1。
// Axis: 轴号。
// Source跟随方式
// 取值0命令
// 1编码器(默认)
// StationNumber: 站点号;*/
// // rtn = CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Source_Net((ushort)IIConfig.SortingInputSetting.BitInputNumber, 0, 1);
// rtn = CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Source_Net((ushort)SortingInputSetting.BitInputNumber, 1, 1);
//rtn = CMCDLL_NET_Sorting.MCF_Sorting_Camera_Blow_Config_Net(
// (ushort)IIConfig.SnapshotSettings.Count,
// (ushort)IIConfig.BlowSettings.Count,
// 0);
// rtn = CMCDLL_NET_Sorting.MCF_Set_Config_Camera_Net();
//为防止转盘第二个盘不触发拍照 设置一键取反功能
}
// //rtn = CMCDLL_NET_Sorting.MCF_Sorting_Camera_Blow_Config_Net(
// // (ushort)IIConfig.SnapshotSettings.Count,
// // (ushort)IIConfig.BlowSettings.Count,
// // 0);
// // rtn = CMCDLL_NET_Sorting.MCF_Set_Config_Camera_Net();
// //为防止转盘第二个盘不触发拍照 设置一键取反功能
//}
// 3.配置相机设置
ConfigCamera();
// 4.配置气阀
ConfigBlow();
// ConfigBlow();
@ -345,54 +349,33 @@ namespace DH.Devices.Motion
for (ushort card = 0; card < cardCount; card++)
{
//IIConfig.SortingInputSettings.ForEach(sortingInputSetting =>
//5.开启筛选
rtn = CMCDLL_NET.MCF_Sorting_Start_Net(0, card);
if (rtn != (short)0)
{
// LogAsync(DateTime.Now, LogLevel.Warning, $"卡{station}开启筛选异常ret{rtn}");
}
//if (cardCount < 2)
//{
// var camStart = 0;
// if (sortingInputSetting.EnableBindCamera)
// {
// camStart = sortingInputSetting.CameraStartNumber;
// }
// var blowStart = 0;
// if (sortingInputSetting.EnableBindBlow)
// {
// blowStart = sortingInputSetting.BlowStartNumber;
// }
// var b = (ushort)sortingInputSetting.BitInputNumber;
// //var ret = CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Bind_Net(b,
// // (ushort)camStart,
// // (ushort)blowStart,
// // card);
// var ret = CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Bind_Net(1,
// 1,
// 2,
// // 最小值 1 2 2
// var ret = CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Bind_Net(
// (ushort)SortingInputSetting.BitInputNumber, // 1
// SortingInputSetting.CameraStartNumber, // 7,
// SortingInputSetting.BlowStartNumber, // 2,
// card);
//});
// CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Source_Net();
if (cardCount < 2)
{
// 最小值 1 2 2
var ret = CMCDLL_NET_Sorting.MCF_Sorting_Set_Input_Bind_Net(
(ushort)SortingInputSetting.BitInputNumber, // 1
SortingInputSetting.CameraStartNumber, // 7,
SortingInputSetting.BlowStartNumber, // 2,
card);
//}
}
for (ushort station = 0; station < cardCount; station++)
{
// 5.开启筛选
//开启自动筛选功能
rtn = CMCDLL_NET_Sorting.MCF_Sorting_Start_Net(0, station);
if (rtn != (short)FuncRet.Function_Success)
{
//LogAsync(DateTime.Now, LogLevel.Warning, $"卡{card}开启筛选异常ret{rtn}");
}
}
//for (ushort station = 0; station < cardCount; station++)
//{
// // 5.开启筛选
// //开启自动筛选功能
// rtn = CMCDLL_NET_Sorting.MCF_Sorting_Start_Net(0, station);
// if (rtn != (short)FuncRet.Function_Success)
// {
// //LogAsync(DateTime.Now, LogLevel.Warning, $"卡{card}开启筛选异常ret{rtn}");
// }
//}
}
}
@ -419,6 +402,7 @@ namespace DH.Devices.Motion
public override void Stop()
{
isconnected = false;
//base.Stop();
AxisStop();
int ret = CMCDLL_NET.MCF_Set_Servo_Enable_Net(0, (ushort)ServoLogic.Servo_Open, 0);
@ -636,7 +620,7 @@ namespace DH.Devices.Motion
// 初始化
for (ushort station = 0; station < BoardCount; station++)
{
ret = CMCDLL_NET_Sorting.MCF_Sorting_Init_Net(station);
ret = CMCDLL_NET.MCF_Sorting_Init_Net(station);
stations.Add(station);
cardTypes.Add(2);
}
@ -658,8 +642,8 @@ namespace DH.Devices.Motion
{
}
MCF_Screen_Set_Trigger1();
MCF_Screen_Set_Trigger1(1);
//MCF_Screen_Set_Trigger1();
// MCF_Screen_Set_Trigger1(1);
}
@ -1859,7 +1843,7 @@ namespace DH.Devices.Motion
continue;
}
var rtn = CMCDLL_NET_Sorting.MCF_Sorting_Set_Trig_Camera_Delay_Count_Net(i,
var rtn = CMCDLL_NET.MCF_Sorting_Set_Trig_Camera_Delay_Count_Net(i,
camSetting.CameraDelayCountMS, camSetting.StationNumber);
@ -1894,7 +1878,7 @@ namespace DH.Devices.Motion
}
else
{
rtn = CMCDLL_NET_Sorting.MCF_Sorting_Set_Camera_Net(
rtn = CMCDLL_NET.MCF_Sorting_Set_Camera_Net(
i, // CCD0
CameraPositionReal,
RotationDirectionReal,
@ -2004,23 +1988,31 @@ namespace DH.Devices.Motion
switch (blowSetting.BlowType)
{
case BlowType.OK:
CMCDLL_NET_Sorting.MCF_Sorting_Set_Blow_OK_Net(CameraPositionReal, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)ioIndex, blowSetting.StationNumber);
CMCDLL_NET.MCF_Sorting_Set_Blow_OK_Net(CameraPositionReal, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)ioIndex, blowSetting.StationNumber);
break;
case BlowType.NG:
CMCDLL_NET_Sorting.MCF_Sorting_Set_Blow_NG_Net(CameraPositionReal, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)ioIndex, blowSetting.StationNumber);
CMCDLL_NET.MCF_Sorting_Set_Blow_NG_Net(CameraPositionReal, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)ioIndex, blowSetting.StationNumber);
break;
case BlowType.Blow1:
CMCDLL_NET_Sorting.MCF_Sorting_Set_Blow_Net(1, CameraPositionReal, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)ioIndex, blowSetting.StationNumber);
CMCDLL_NET.MCF_Sorting_Set_Blow_1_Net(blowSetting.BlowPosition, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)blowSetting.BlowIO.IOIndex, blowSetting.StationNumber);
break;
///第一路绑定OK NG 吹起口1
case BlowType.Blow2:
CMCDLL_NET_Sorting.MCF_Sorting_Set_Blow_Net(2, CameraPositionReal, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)ioIndex, blowSetting.StationNumber);
CMCDLL_NET.MCF_Sorting_Set_Blow_2_Net(blowSetting.BlowPosition, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)blowSetting.BlowIO.IOIndex, blowSetting.StationNumber);
break;
case BlowType.Blow3:
CMCDLL_NET_Sorting.MCF_Sorting_Set_Blow_Net(3, CameraPositionReal, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)ioIndex, blowSetting.StationNumber);
CMCDLL_NET.MCF_Sorting_Set_Blow_3_Net(blowSetting.BlowPosition, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)blowSetting.BlowIO.IOIndex, blowSetting.StationNumber);
break;
case BlowType.Blow4:
CMCDLL_NET_Sorting.MCF_Sorting_Set_Blow_Net(4, CameraPositionReal, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)ioIndex, blowSetting.StationNumber);
CMCDLL_NET.MCF_Sorting_Set_Blow_4_Net(blowSetting.BlowPosition, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)blowSetting.BlowIO.IOIndex, blowSetting.StationNumber);
break;
case BlowType.Blow5:
CMCDLL_NET.MCF_Sorting_Set_Blow_5_Net(blowSetting.BlowPosition, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)blowSetting.BlowIO.IOIndex, blowSetting.StationNumber);
break;
case BlowType.Blow6:
CMCDLL_NET.MCF_Sorting_Set_Blow_6_Net(blowSetting.BlowPosition, (ushort)rotationDirectionEnum, (ushort)blowSetting.ActionMode, (ushort)blowSetting.BlowIO.IOIndex, blowSetting.StationNumber);
break;
default:
break;
//case BlowType.OK:
// CMCDLL_NET_Sorting.MCF_Sorting_Set_Blow_OK_Net(setting.BlowPosition, (ushort)IIConfig.MotionDir, (ushort)setting.ActionMode, (ushort)setting.BlowIO.IOIndex, setting.StationNumber);
@ -2047,8 +2039,7 @@ namespace DH.Devices.Motion
//case BlowType.Blow6:
// CMCDLL_NET_Sorting.MCF_Sorting_Set_Blow_6_Net(setting.BlowPosition, (ushort)IIConfig.MotionDir, (ushort)setting.ActionMode, (ushort)setting.BlowIO.IOIndex, setting.StationNumber);
// break;
default:
break;
}
}

View File

@ -12,6 +12,18 @@
<OutputType>WinExe</OutputType>
</PropertyGroup>
<ItemGroup>
<Compile Include="Views\CamConfigFrm.cs" />
<Compile Include="Views\CamConfigFrm.Designer.cs" />
<Compile Include="Views\UserConfigFrm.cs" />
<Compile Include="Views\UserConfigFrm.Designer.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Views\CamConfigFrm.resx" />
<EmbeddedResource Include="Views\UserConfigFrm.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AntdUI" Version="1.8.9" />
<PackageReference Include="System.IO.Ports" Version="9.0.2" />

View File

@ -41,6 +41,7 @@
button_color = new AntdUI.Button();
buttonSZ = new AntdUI.Button();
pageHeader1 = new AntdUI.PageHeader();
label1 = new Label();
divider2 = new AntdUI.Divider();
panelmain = new AntdUI.Panel();
panel2 = new AntdUI.Panel();
@ -56,11 +57,9 @@
panel3 = new AntdUI.Panel();
tabs2 = new AntdUI.Tabs();
tabPage2 = new AntdUI.TabPage();
pictureBox1 = new PictureBox();
divider1 = new AntdUI.Divider();
panel1 = new AntdUI.Panel();
segmented1 = new AntdUI.Segmented();
label1 = new Label();
titlebar.SuspendLayout();
pageHeader1.SuspendLayout();
panelmain.SuspendLayout();
@ -73,8 +72,6 @@
tabPage3.SuspendLayout();
panel3.SuspendLayout();
tabs2.SuspendLayout();
tabPage2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
panel1.SuspendLayout();
SuspendLayout();
//
@ -139,6 +136,15 @@
pageHeader1.TabIndex = 7;
pageHeader1.Text = "UPH";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(61, 10);
label1.Name = "label1";
label1.Size = new Size(64, 21);
label1.TabIndex = 1;
label1.Text = "100000";
//
// divider2
//
divider2.Dock = DockStyle.Top;
@ -285,22 +291,11 @@
//
// tabPage2
//
tabPage2.Controls.Add(pictureBox1);
tabPage2.Location = new Point(3, 28);
tabPage2.Name = "tabPage2";
tabPage2.Size = new Size(347, 469);
tabPage2.TabIndex = 0;
tabPage2.Text = "统计";
//
// pictureBox1
//
pictureBox1.Dock = DockStyle.Fill;
pictureBox1.Location = new Point(0, 0);
pictureBox1.Name = "pictureBox1";
pictureBox1.Size = new Size(347, 469);
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox1.TabIndex = 0;
pictureBox1.TabStop = false;
tabPage2.Text = "配置";
//
// divider1
//
@ -401,15 +396,6 @@
segmented1.Text = "segmented1";
segmented1.SelectIndexChanged += segmented1_SelectIndexChanged;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(61, 10);
label1.Name = "label1";
label1.Size = new Size(64, 21);
label1.TabIndex = 1;
label1.Text = "100000";
//
// MainWindow
//
ClientSize = new Size(1024, 648);
@ -438,8 +424,6 @@
tabPage3.ResumeLayout(false);
panel3.ResumeLayout(false);
tabs2.ResumeLayout(false);
tabPage2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
panel1.ResumeLayout(false);
ResumeLayout(false);
}
@ -468,7 +452,6 @@
private AntdUI.TabPage tabPage2;
private AntdUI.Divider divider1;
private RichTextBox richTextBox1;
private PictureBox pictureBox1;
private Label label1;
}
}

View File

@ -282,11 +282,11 @@ namespace DHSoftware
//[Description("定义检测标签的集合例如Seg/Detection模式断裂、油污、划伤...Class模式ok、ng、上面、下面、套环、正常...")]
//[TypeConverter(typeof(CollectionCountConvert))]
//[Editor(typeof(ComplexCollectionEditor<RecongnitionLabel>), typeof(UITypeEditor))]
RecongnitionLabel recongnition=new RecongnitionLabel
RecongnitionLabel recongnition = new RecongnitionLabel
{
LabelName="youwu",
LabelDescription="油污",
LabelCategory="A_NG"
LabelName = "youwu",
LabelDescription = "油污",
LabelCategory = "A_NG"
};
RecongnitionLabel recongnition2 = new RecongnitionLabel
{
@ -314,7 +314,7 @@ namespace DHSoftware
var det6 = new DetectionConfig("相机6", MLModelType.ObjectDetection, @"D:\PROJECTS\X015\Vision\Cam6.onnx", false, "Cam6");
var det7 = new DetectionConfig("相机7", MLModelType.ObjectDetection, @"D:\PROJECTS\X015\Vision\Cam7.onnx", false, "Cam7");
var det8 = new DetectionConfig("相机8", MLModelType.ObjectDetection, @"D:\PROJECTS\X015\Vision\Cam8.onnx", false, "Cam8");
List<RelatedCamera> CameraCollects=new List<RelatedCamera>();
List<RelatedCamera> CameraCollects = new List<RelatedCamera>();
CameraCollects.Add(new RelatedCamera("Cam1"));
List<RelatedCamera> CameraCollects2 = new List<RelatedCamera>();
CameraCollects2.Add(new RelatedCamera("Cam2"));
@ -420,24 +420,32 @@ namespace DHSoftware
}
#else
Do3ThinkCamera do3ThinkCamera1 = new Do3ThinkCamera();
//Do3ThinkCamera do3ThinkCamera1 = new Do3ThinkCamera();
do3ThinkCamera1.dvpStreamFormat = dvpStreamFormat.S_RAW8;
do3ThinkCamera1.CameraName = "Cam1";
do3ThinkCamera1.CameraConnect();
do3ThinkCamera1.OnHImageOutput += OnCameraHImageOutput;
Cameras.Add(do3ThinkCamera1);
for (int i=2;i<=8;i++)
//do3ThinkCamera1.dvpStreamFormat = dvpStreamFormat.S_RAW8;
//do3ThinkCamera1.CameraName = "Cam1";
//do3ThinkCamera1.CameraConnect();
//do3ThinkCamera1.OnHImageOutput += OnCameraHImageOutput;
// Cameras.Add(do3ThinkCamera1);
for (int i = 1; i <= 8; i++)
{
Do3ThinkCamera do3ThinkCamera2 = new Do3ThinkCamera();
do3ThinkCamera2.dvpStreamFormat = dvpStreamFormat.S_RGB24;
do3ThinkCamera2.CameraName = $"Cam{i}";
Cameras.Add(do3ThinkCamera2);
do3ThinkCamera2.CameraConnect();
do3ThinkCamera2.OnHImageOutput += OnCameraHImageOutput;
Do3ThinkCamera cam = new Do3ThinkCamera();
if (i == 1)
{
cam.dvpStreamFormat = dvpStreamFormat.S_RAW8;
}
else
{
cam.dvpStreamFormat = dvpStreamFormat.S_RGB24;
}
cam.CameraName = $"Cam{i}";
Cameras.Add(cam);
cam.CameraConnect();
cam.OnHImageOutput += OnCameraHImageOutput;
}
#endif
@ -445,24 +453,24 @@ namespace DHSoftware
DetectionConfigs.ForEach(detection =>
{
detection.CameraCollects.ForEach(cam =>
{
List<string> Dets = new List<string>
{
detection.CameraCollects.ForEach(cam =>
{
List<string> Dets = new List<string>
{
detection.Id
};
if (!_cameraRelatedDetectionDict.ContainsKey(cam.CameraSourceId))
{
_cameraRelatedDetectionDict.Add(cam.CameraSourceId, Dets);
}
else
{
_cameraRelatedDetectionDict[cam.CameraSourceId].Add(detection.Id);
}
};
if (!_cameraRelatedDetectionDict.ContainsKey(cam.CameraSourceId))
{
_cameraRelatedDetectionDict.Add(cam.CameraSourceId, Dets);
}
else
{
_cameraRelatedDetectionDict[cam.CameraSourceId].Add(detection.Id);
}
}
);
}
);
});
string inferenceDevice = "CPU";
@ -474,31 +482,39 @@ namespace DHSoftware
//初始化Halcon工具
InitialHalconTools();
//深度学习模型加载
bool resultOK =InitialSimboMLEnginesAsync();
bool resultOK = InitialSimboMLEnginesAsync();
if (resultOK)
{
//初始化失败
// return;
// return;
}
//位置比较卡
sLDMotion.AxisSettings = new List<AxisSetting>();
AxisSetting axis1=new AxisSetting();
AxisSetting axis1 = new AxisSetting();
axis1.AxisIndex = 0;
axis1.AxisName = "转盘1";
axis1.IsAxisEnabled = true;
//axis1.AlarmLogic = AxisDirection.Positive;
sLDMotion.IODefinitionCollection=new List<IODefinition>();
sLDMotion.IODefinitionCollection = new List<IODefinition>();
Motion(sLDMotion.IODefinitionCollection);
sLDMotion.SnapshotSettings = new List<SnapshotSetting>();
int[] cameraPositions = { 7613, 24161, 33608, 39702, 45701 };
int[] cameraPositions = { 24161, 33608, 39702, 45701 };
for (int i = 0; i < 5; i++)
sLDMotion.SnapshotSettings.Add(new SnapshotSetting
{
IsEnabled = true,
CameraIO = sLDMotion.IODefinitionCollection.FirstOrDefault(t => t.IOType == IOType.OUTPUT && t.IOIndex == 13),
CameraPosition = 7613,
StationNumber = 0
});
for (int i = 0; i < 4; i++)
{
sLDMotion.SnapshotSettings.Add(new SnapshotSetting
{
@ -513,17 +529,20 @@ namespace DHSoftware
sLDMotion.BlowSettings = new List<BlowSetting>();
int[] BlowPositions = { 61353, 68566 };
for (int i = 0; i < 2; i++)
sLDMotion.BlowSettings.Add(new BlowSetting
{
sLDMotion.BlowSettings.Add(new BlowSetting
{
IsEnabled = true,
BlowIO = sLDMotion.IODefinitionCollection.FirstOrDefault(t => t.IOType == IOType.OUTPUT && t.IOIndex == i),
BlowPosition = BlowPositions[i],
StationNumber = 0
});
}
IsEnabled = true,
BlowIO = sLDMotion.IODefinitionCollection.FirstOrDefault(t => t.IOType == IOType.OUTPUT && t.IOIndex == 5),
BlowPosition = BlowPositions[0],
StationNumber = 0
});
sLDMotion.BlowSettings.Add(new BlowSetting
{
IsEnabled = true,
BlowIO = sLDMotion.IODefinitionCollection.FirstOrDefault(t => t.IOType == IOType.OUTPUT && t.IOIndex == 6),
BlowPosition = BlowPositions[1],
StationNumber = 0
});
//SnapshotSetting sna1 = new SnapshotSetting();
//sna1.IsEnabled = true;
@ -536,23 +555,26 @@ namespace DHSoftware
// sLDMotion.SnapshotSettings.Add(sna1);
sLDMotion.AxisSettings.Add(axis1);
sLDMotion.Init();
// sLDMotion.Start();
sLDMotion.OnNewPieces -= MainMotion_NewPieces;
sLDMotion.OnNewPieces += MainMotion_NewPieces;
// sLDMotion.Start();
//PLC.IP = "192.168.6.6";
//PLC.Port = 502;
//PLC.PLCConnect();
//PLC.OnNewPieces -= MainMotion_NewPieces;
//PLC.OnNewPieces += MainMotion_NewPieces;
ProductBaseCount = 2;
ProductBaseCount = 8;
for (int i = 0; i < ProductBaseCount * ProductListMulti; i++)
{
ConcurrentDictionary<uint, ProductData> products = new ConcurrentDictionary<uint, ProductData>();
_productLists.Add(products);
}
sLDMotion.AxisStop();
bool e=sLDMotion.CArdReset();
sLDMotion.JOGRun(10000, 100000);
startTime =DateTime.Now;
sLDMotion.AxisStop();
bool e = sLDMotion.CArdReset();
//转盘速度
sLDMotion.JOGRun(14000, 100000);
startTime = DateTime.Now;
}
public void Motion(List<IODefinition> iODefinitions)
{
@ -583,7 +605,7 @@ namespace DHSoftware
private int PieceNumberToIndex(uint pn)
{
// 物料编号,取余 集合数量
int ret = (int)(pn % (ProductBaseCount * ProductListMulti));
return ret;
}
@ -598,7 +620,7 @@ namespace DHSoftware
PieceCount++;
int index = PieceNumberToIndex(pieceNumber);
// productDatas.Add(pData);
//转盘2 的物料是不是重新覆盖之前的pDta
@ -607,8 +629,9 @@ namespace DHSoftware
ProductData pData = new ProductData("", pieceNumber, ProductBaseCount);
_productLists[index][pieceNumber] = pData;
}
string logStr = $"时间:{DateTime.Now} 轴{axisIndex}新产品{pieceNumber}加入队列{index}----入料计数{PieceCount}\n";
Task.Run(() => {
string logStr = $"时间:{DateTime.Now} 轴{axisIndex}新产品{pieceNumber}加入队列{index}----入料计数{PieceCount}\n";
Task.Run(() =>
{
this.BeginInvoke(new MethodInvoker(delegate () { richTextBox1.AppendText(logStr); }));
});
@ -622,7 +645,7 @@ namespace DHSoftware
{
await Task.Run(() =>
{
//OnUpdateCT?.Invoke(objData, ctTime);
//OnUpdateCT?.Invoke(objData, ctTime);
});
}
/// <summary>
@ -632,7 +655,7 @@ namespace DHSoftware
{
//深度学习 模型加载
var resultOK = MLLoadModel();
return resultOK;
return resultOK;
}
/// <summary>
/// 深度学习 模型加载
@ -645,56 +668,56 @@ namespace DHSoftware
{
SimboStationMLEngineList = new List<SimboStationMLEngineSet>();
// _cameraRelatedDetectionDict = IConfig.DetectionConfigs.Select(t => t.ModelPath).Distinct().ToList();
DetectionConfigs.ForEach(dc =>
DetectionConfigs.ForEach(dc =>
//_cameraRelatedDetectionDict.ForEach(dc =>
{
if (dc.IsEnabled && !string.IsNullOrWhiteSpace(dc.ModelPath))
{
if (dc.IsEnableGPU)
{
//if (IIConfig.IsLockGPU)
//{
//foreach (var validGPU in ValidGPUList2)
//{
// if (validGPU.DetectionIds.Contains(dc.Id))
// {
var engine = SingleMLLoadModel(dc, true, 0);
SimboStationMLEngineList.Add(engine);
// }
//}
//}
//else
//{
// foreach (var validGPU in ValidGPUList)
// {
// //var validGPU = ValidGPUList.FirstOrDefault(u => u.DetectionIds.Contains(dc.Id));
// if (validGPU.DetectionId == dc.Id)
// {
// var engine = SingleMLLoadModel(dc, true, validGPU.GPUNo);
// SimboStationMLEngineList.Add(engine);
// }
// }
//}
{
}
else
{
//for (int i = 0; i < IConfig.CPUNums; i++)
for (int i = 0; i <1; i++)
{
//var engine = SingleMLLoadModel(dc, false, i);
var engine = SingleMLLoadModel(dc, false, i);
SimboStationMLEngineList.Add(engine);
}
}
}
});
if (dc.IsEnabled && !string.IsNullOrWhiteSpace(dc.ModelPath))
{
if (dc.IsEnableGPU)
{
//if (IIConfig.IsLockGPU)
//{
//foreach (var validGPU in ValidGPUList2)
//{
// if (validGPU.DetectionIds.Contains(dc.Id))
// {
var engine = SingleMLLoadModel(dc, true, 0);
SimboStationMLEngineList.Add(engine);
// }
//}
//}
//else
//{
// foreach (var validGPU in ValidGPUList)
// {
// //var validGPU = ValidGPUList.FirstOrDefault(u => u.DetectionIds.Contains(dc.Id));
// if (validGPU.DetectionId == dc.Id)
// {
// var engine = SingleMLLoadModel(dc, true, validGPU.GPUNo);
// SimboStationMLEngineList.Add(engine);
// }
// }
//}
}
else
{
//for (int i = 0; i < IConfig.CPUNums; i++)
for (int i = 0; i < 1; i++)
{
//var engine = SingleMLLoadModel(dc, false, i);
var engine = SingleMLLoadModel(dc, false, i);
SimboStationMLEngineList.Add(engine);
}
}
}
});
resultOK = true;
}
catch (Exception ex)
{
// LogAsync(DateTime.Now, LogLevel.Exception, $"异常:模型并发加载异常:{ex.GetExceptionMessage()}");
// LogAsync(DateTime.Now, LogLevel.Exception, $"异常:模型并发加载异常:{ex.GetExceptionMessage()}");
resultOK = false;
}
@ -761,7 +784,7 @@ namespace DHSoftware
bool isSuccess = mLEngineSet.StationMLEngine.Load(mLInit);
if (!isSuccess)
{
// throw new ProcessException("异常:模型加载异常", null);
// throw new ProcessException("异常:模型加载异常", null);
}
//LogAsync(DateTime.Now, LogLevel.Information, $"模型加载成功是否GPU:{isGPU} CoreInx:{coreInx} - {dc.Name}" + $" {dc.ModelType.GetEnumDescription()}:{dc.ModelPath}");
}
@ -785,9 +808,9 @@ namespace DHSoftware
if (!c.IsEnabled)
return;
if(c.HalconAlgorithemPath_Pre!=null)
if (c.HalconAlgorithemPath_Pre != null)
LoadHalconTool(c.HalconAlgorithemPath_Pre);
});
}
@ -795,7 +818,7 @@ namespace DHSoftware
{
if (!HalconToolDict.ContainsKey(path))
{
string algorithemPath = path;
@ -817,7 +840,7 @@ namespace DHSoftware
/// </summary>
/// <param name="detectConfig"></param>
/// <param name="detectResult"></param>
public void PreTreated(DetectionConfig detectConfig, DetectStationResult detectResult,Mat MhImage)
public void PreTreated(DetectionConfig detectConfig, DetectStationResult detectResult, Mat MhImage)
{
try
{
@ -828,10 +851,10 @@ namespace DHSoftware
{
HObject obj = OpenCVHelper.MatToHImage(MhImage);
HImage hImage = HalconHelper.ConvertHObjectToHImage(obj);
string toolKey = detectConfig.HalconAlgorithemPath_Pre;
string toolKey = detectConfig.HalconAlgorithemPath_Pre;
if (!HalconToolDict.ContainsKey(toolKey))
{
// LogAsync(DateTime.Now, LogLevel.Exception, $"{detectConfig.Name}未获取预处理算法");
// LogAsync(DateTime.Now, LogLevel.Exception, $"{detectConfig.Name}未获取预处理算法");
return;
}
//Mean_Thre Deviation_Thre Mean_standard Deviation_standard
@ -851,11 +874,11 @@ namespace DHSoftware
if (!tool.RunProcedure(out string errorMsg, out _))
{
// detectResult.PreTreatedFlag = false;
// detectResult.PreTreatedFlag = false;
detectResult.IsPreTreatDone = false;
return;
}
@ -883,37 +906,37 @@ namespace DHSoftware
detectResult.ResultState = ResultState.DetectNG;
detectResult.IsPreTreatNG = true;
// if (detectResult.VisionImageSet.PreTreatedFlag)
{
//detectResult.VisionImageSet.MLImage = tool.GetResultObject("OUTPUT_PreTreatedImage");
//DetectionResultImage
// detectResult.VisionImageSet.DetectionResultImage = detectResult.VisionImageSet.MLImage.ConvertHImageToBitmap();
// detectResult.VisionImageSet.DetectionResultImage = detectResult.VisionImageSet.MLImage.ConvertHImageToBitmap();
}
}
else
{
// detectResult.VisionImageSet.DetectionResultImage = detectResult.VisionImageSet.MLImage.ConvertHImageToBitmap();
// detectResult.VisionImageSet.DetectionResultImage = detectResult.VisionImageSet.MLImage.ConvertHImageToBitmap();
}
}
}
catch (Exception ex)
{
}
finally
{
//detectResult.VisionImageSet.HImage?.Dispose();
//detectResult.VisionImageSet.HImage = null;
// MhImage?.Dispose();
// MhImage?.Dispose();
//MhImage = null;
}
}
/// <summary>
/// 相机回调
@ -923,6 +946,16 @@ namespace DHSoftware
/// <param name="imageSet"></param>
private void OnCameraHImageOutput(DateTime dt, CameraBase camera, Mat imageSet)
{
//if (camera.CameraName.Equals("cam1", StringComparison.OrdinalIgnoreCase))
//{
// Console.WriteLine();
//}
//if (camera.CameraName.Equals("cam2", StringComparison.OrdinalIgnoreCase))
//{
// Console.WriteLine();
//}
// 获取该相机的拍照计数
uint productNumber = (uint)camera.SnapshotCount;
@ -930,7 +963,7 @@ namespace DHSoftware
{
using (Mat localImageSet = imageSet.Clone()) // 复制 Mat 避免并发问题
{
// imageSet?.Dispose();
// imageSet?.Dispose();
// 拍照计数与物件编号一致,查找对应的产品
ProductData product = null;
//内外壁模组多个相机的处理方法
@ -939,52 +972,87 @@ namespace DHSoftware
// 找到产品存放在哪个队列里
ConcurrentDictionary<uint, ProductData> tmpDic = _productLists[index];
try
{
int retryTimes = 100;
while (product == null && retryTimes > 0)
try
{
if (tmpDic.ContainsKey(productNumber))
int retryTimes = 100;
while (product == null && retryTimes > 0)
{
product = tmpDic[productNumber];
if (tmpDic.ContainsKey(productNumber))
{
product = tmpDic[productNumber];
}
else
{
// Thread.Sleep(20);
await Task.Delay(20);
}
retryTimes--;
}
else
// 如果产品为空,则销毁图片,提示错误
if (null == product)
{
Thread.Sleep(20);
}
retryTimes--;
}
// 如果产品为空,则销毁图片,提示错误
if (null == product)
{
List<uint> pnList = tmpDic.Keys.ToList();
List<uint> pnList = tmpDic.Keys.ToList();
string pnStr = "";
if (pnList != null && pnList.Count > 0)
{
pnStr = string.Join(",", pnList);
string pnStr = "";
if (pnList != null && pnList.Count > 0)
{
pnStr = string.Join(",", pnList);
}
//LogAsync(DateTime.Now, LogLevel.Error, $"{camera.Name} 未找到产品,编号:{productNumber},队列{index}数量:{tmpDic.Count},列表:{pnStr}");
localImageSet.Dispose();
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText(productNumber + "提前推出" + camera.CameraName);
// 设置回原来的滚动位置
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
//重新生成实例 销毁之前的实例
using (StreamWriter sw = new StreamWriter("D://123log.txt", true, Encoding.UTF8))
{
sw.WriteLine(productNumber + "提前推出" + camera.CameraName);
}
return;
}
//LogAsync(DateTime.Now, LogLevel.Error, $"{camera.Name} 未找到产品,编号:{productNumber},队列{index}数量:{tmpDic.Count},列表:{pnStr}");
localImageSet.Dispose();
return;
}
// LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 找到产品{productNumber},队列{index}数量:{tmpDic.Count}");
// LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 找到产品{productNumber},队列{index}数量:{tmpDic.Count}");
if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName))
{
if (!_cameraRelatedDetectionDict.ContainsKey(camera.CameraName))
{
localImageSet.Dispose();
this.BeginInvoke(new MethodInvoker(delegate ()
{
localImageSet.Dispose();
// LogAsync(DateTime.Now, LogLevel.Warning, $"{camera.Name} 找到产品{productNumber}但是没有推理1");
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
return;
}
richTextBox1.AppendText(productNumber+"提前推出" + camera.CameraName);
// 设置回原来的滚动位置
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
//重新生成实例 销毁之前的实例
using (StreamWriter sw = new StreamWriter("D://123log.txt", true, Encoding.UTF8))
{
sw.WriteLine(productNumber+"提前推出" + camera.CameraName);
}
// LogAsync(DateTime.Now, LogLevel.Warning, $"{camera.Name} 找到产品{productNumber}但是没有推理1");
return;
}
double totalTime = 0.0;
List<ResultState> resultStates = new List<ResultState>();
List<string>? detectionDict = _cameraRelatedDetectionDict[camera.CameraName];
double totalTime = 0.0;
List<ResultState> resultStates = new List<ResultState>();
List<string>? detectionDict = _cameraRelatedDetectionDict[camera.CameraName];
for (int i = 0; i < detectionDict.Count; i++)
@ -1062,14 +1130,14 @@ namespace DHSoftware
req.ResizeHeight = (int)detectConfig.ModelHeight;
// req.LabelNames = detectConfig.GetLabelNames();
// req.Score = IIConfig.Score;
req.mImage = inferenceImage.Clone();
req.in_lable_path = detectConfig.in_lable_path;
req.confThreshold = detectConfig.ModelconfThreshold;
req.iouThreshold = 0.3f;
req.segmentWidth = 320;
req.out_node_name = "output0";
switch (detectConfig.ModelType)
{
case MLModelType.ImageClassification:
@ -1117,14 +1185,14 @@ namespace DHSoftware
//var result = Dectection[detectionId].RunInference(req);
//sw.Stop();
//LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 推理进度1.1,产品{productNumber},耗时{sw.ElapsedMilliseconds}ms");
this.BeginInvoke(new MethodInvoker(delegate ()
{
pictureBox1.Image?.Dispose(); // 释放旧图像
pictureBox1.Image = result.ResultMap;
richTextBox1.AppendText($"推理成功 {productNumber}, {result.IsSuccess} 耗时 {mlWatch.ElapsedMilliseconds}ms\n");
richTextBox1.AppendText($"推理成功 {productNumber}, {result.IsSuccess}相机名字{camera.CameraName} 耗时 {mlWatch.ElapsedMilliseconds}ms\n");
}));
req.mImage.Dispose();
req.mImage?.Dispose();
@ -1247,67 +1315,80 @@ namespace DHSoftware
}
product.InferenceOne(() =>
{
;
}, () =>
{
;
});
product.InferenceOne();
// LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 推理完成,产品{productNumber}");
// LogAsync(DateTime.Now, LogLevel.Information, $"{camera.Name} 推理完成,产品{productNumber}");
if (!product.InferenceFinished())
if (!product.InferenceFinished())
{
return;
}
ProductNum_Total++;
CalculateOEE();
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText($"统计结果成功,{productNumber} 吹气!\n");
// 设置回原来的滚动位置
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
#region 6.
product.ProductResult = product.ResultCollection.Any(u => u.ResultState != ResultState.OK)
? ResultState.B_NG
: ResultState.OK;
product.ProductLabelCategory = product.ProductResult.GetEnumDescription();
product.ProductLabel = product.ProductResult.GetEnumDescription();
#endregion
#region 7.
#endregion
// 出列
ProductData temp = null;
int tryTimes = 10;
while (temp == null && tryTimes > 0)
{
if (tmpDic.TryRemove(productNumber, out temp))
{
return;
break;
}
ProductNum_Total++;
CalculateOEE();
tryTimes--;
Thread.Sleep(5);
}
if (temp == null)
{
string logStr = $"{DateTime.Now}产品{productNumber}出列失败true" +
$"当前队列产品数量:{tmpDic.Count}";
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText($"统计结果成功,{productNumber} 吹气!\n");
richTextBox1.AppendText(logStr);
// 设置回原来的滚动位置
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
#region 6.
product.ProductResult = product.ResultCollection.Any(u => u.ResultState != ResultState.OK)
? ResultState.B_NG
: ResultState.OK;
product.ProductLabelCategory = product.ProductResult.GetEnumDescription();
product.ProductLabel = product.ProductResult.GetEnumDescription();
#endregion
#region 7.
#endregion
// 出列
ProductData temp = null;
int tryTimes = 10;
while (temp == null && tryTimes > 0)
}
else
{
try
{
if (tmpDic.TryRemove(productNumber, out temp))
{
break;
}
tryTimes--;
Thread.Sleep(5);
}
if (temp == null)
{
string logStr = $"{DateTime.Now}产品{productNumber}出列失败true" +
$"当前队列产品数量:{tmpDic.Count}";
string logStr = $"{DateTime.Now}产品{productNumber}出列成功true" +
$"产品结果:{temp.ProductResult.GetEnumDescription()}" +
$"当前队列产品数量:{tmpDic.Count}";
this.BeginInvoke(new MethodInvoker(delegate ()
{
@ -1319,61 +1400,42 @@ namespace DHSoftware
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
//重新生成实例 销毁之前的实例
var saveData = temp.GetProductData();
using (StreamWriter sw = new StreamWriter("D://123log.txt", true, Encoding.UTF8))
{
sw.WriteLine(logStr);
}
}
else
catch (Exception) { }
finally
{
try
{
string logStr = $"{DateTime.Now}产品{productNumber}出列成功true" +
$"产品结果:{temp.ProductResult.GetEnumDescription()}" +
$"当前队列产品数量:{tmpDic.Count}";
this.BeginInvoke(new MethodInvoker(delegate ()
{
int currentScrollPosition = richTextBox1.GetPositionFromCharIndex(richTextBox1.TextLength).Y;
richTextBox1.AppendText(logStr);
// 设置回原来的滚动位置
richTextBox1.SelectionStart = richTextBox1.TextLength;
richTextBox1.ScrollToCaret();
}));
//重新生成实例 销毁之前的实例
var saveData = temp.GetProductData();
using (StreamWriter sw = new StreamWriter("D://123log.txt", true, Encoding.UTF8))
{
sw.WriteLine(logStr);
}
}
catch (Exception) { }
finally
{
// temp.Dispose();
temp = null;
}
// temp.Dispose();
temp = null;
}
// UpdateCT((float)(dtNow - _ctTime).TotalSeconds);
//_ctTime = dtNow;
// });
}
catch (Exception ex)
{
//LogAsync(DateTime.Now, LogLevel.Error, $"流程检测未捕获的异常:{ex.GetExceptionMessage()}");
product?.Dispose();
}
// UpdateCT((float)(dtNow - _ctTime).TotalSeconds);
//_ctTime = dtNow;
// });
}
catch (Exception ex)
{
//LogAsync(DateTime.Now, LogLevel.Error, $"流程检测未捕获的异常:{ex.GetExceptionMessage()}");
product?.Dispose();
}
}
});
});
}
public void SetResult()
{
//// detectResult.IsPreTreatDone = detectResult.VisionImageSet.PreTreatedFlag
@ -1397,19 +1459,20 @@ namespace DHSoftware
Cameras.Clear();
Dectection.Clear();
// Add the code for the "停止" button click here
PLC.TurntableStop();
// PLC.TurntableStop();
CurrentMachine = true;
sLDMotion.Stop();
}
public int UPH=0;
public int UPH = 0;
public void CalculateOEE()
{
TimeSpan timeSpan = DateTime.Now - startTime;
UPH = (int)(ProductNum_Total / timeSpan.TotalHours) + 100;
UPH = (int)(ProductNum_Total / timeSpan.TotalHours) + 100;
//UPM = (int)UPH / 60;
this.BeginInvoke(new MethodInvoker(delegate () {
label1.Text = UPH.ToString();
this.BeginInvoke(new MethodInvoker(delegate ()
{
label1.Text = UPH.ToString();
}));

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter

View File

@ -0,0 +1,44 @@
namespace DHSoftware.Views
{
partial class CamConfigFrm
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
SuspendLayout();
//
// CamConfigFrm
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
Name = "CamConfigFrm";
Size = new Size(869, 521);
ResumeLayout(false);
}
#endregion
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DHSoftware.Views
{
public partial class CamConfigFrm : UserControl
{
public CamConfigFrm()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,44 @@
namespace DHSoftware.Views
{
partial class UserConfigFrm
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
SuspendLayout();
//
// UserConfigFrm
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
Name = "UserConfigFrm";
Size = new Size(749, 536);
ResumeLayout(false);
}
#endregion
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DHSoftware.Views
{
public partial class UserConfigFrm : UserControl
{
public UserConfigFrm()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -78,16 +78,16 @@ namespace DHSoftware
}
public void InferenceOne(Action preAction = null, Action postAction = null)
public void InferenceOne()
{
//lock (_inferenceLock)
//{
// Interlocked.Decrement(ref InferenceLeft);
//}
preAction?.Invoke();
_countdownEvent.Signal();
postAction?.Invoke();
}
public bool InferenceFinished()