提交整体修改

This commit is contained in:
2025-03-27 11:37:48 +08:00
parent 1046978877
commit 2d98b2d8b8
22 changed files with 2560 additions and 2032 deletions

View File

@ -291,7 +291,7 @@ namespace DHSoftware
for (int i = 0; i < ConfigModel.PLCBaseList.Count; i++)
{
var plcBase = ConfigModel.PLCBaseList[i];
if (plcBase.PLCType == EnumPLCType.XC网口)
if (plcBase.PLCType == EnumPLCType.XC网口 || plcBase.PLCType == EnumPLCType.XD网口)
{
PLC.IP = plcBase.IP;
PLC.PLCType = plcBase.PLCType;
@ -577,19 +577,17 @@ namespace DHSoftware
StartProcess();
}
private static int currentRegister = 411; // 初始为 D411
private void StartProcess()
{
startTime= DateTime.Now;
//计数清零
PieceCount = 0;
//吹气点位归置
currentRegister = 411;
if (PLC?.Enable == true)
{
PLC.CountToZero();
PLC.OnNewPieces -= MainMotion_NewPieces;
PLC.OnNewPieces += MainMotion_NewPieces;
}
@ -692,414 +690,14 @@ namespace DHSoftware
}
//流程执行时PLC
StartPLCAction();
PLC.StartProcess();
// 转盘操作
// if (_PLC?.IIConfig?.IsEnabled == true)
// _PLC.TurntableOpen(XKRSPLCConfig.TurnSpeed, XKRSPLCConfig.TurnDirection);
PLCItem itemSpeed = PLC.PLCItemList.FirstOrDefault(u => u.Name == "转盘速度");
if (itemSpeed != null)
{
PLC.TurntableOpen();
}
Thread.Sleep(500);
//振动盘
//if (XKRSPLCConfig.IsEnableVibratory)
//{
// if (_PLC.IIConfig.IsEnabled)
// _PLC.Vibratory(true);
//}
//InitialOEEStatistic();
// MachineState = MachineState.Running;
}
/// <summary>
/// 流程开始执行PLC
/// </summary>
private void StartPLCAction()
{
if (PLC.PLCItemList?.Count > 0)
{
List<PLCItem> startPLCList= PLC.PLCItemList.Where(it=>it.StartExecute).ToList();
if (startPLCList?.Count > 0)
{
}
}
}
private void PrepareMLEngine()
{
//if (_visionEngine == null)
//{
// _visionEngine = DeviceCollection.FirstOrDefault(u => u is VisionEngineBase) as VisionEngineBase;
//}
//if (_visionEngine == null)
//{
// throw new ProcessException($"未能获取检测设备");
//}
//相机模组
//_cameraRelatedDetectionDict = new();
//detectionList.ForEach(detection =>
//{
// 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);
// }
// });
//});
//_visionEngine.OnDetectionWarningStop += VisionEngine_OnDetectionWarningStopAsync;
}
#if false
private void HandleStartButton2()
{
CurrentMachine = true;
//_visionEngine.Start();
//[Category("深度学习检测配置")]
//[DisplayName("检测标签定义集合")]
//[Description("定义检测标签的集合例如Seg/Detection模式断裂、油污、划伤...Class模式ok、ng、上面、下面、套环、正常...")]
//[TypeConverter(typeof(CollectionCountConvert))]
//[Editor(typeof(ComplexCollectionEditor<RecongnitionLabel>), typeof(UITypeEditor))]
RecongnitionLabel recongnition = new RecongnitionLabel
{
LabelName = "youwu",
LabelDescription = "油污",
LabelCategory = "A_NG"
};
RecongnitionLabel recongnition2 = new RecongnitionLabel
{
LabelName = "youwu",
LabelDescription = "油污",
LabelCategory = "A_NG"
};
RecongnitionLabel recongnition3 = new RecongnitionLabel
{
LabelName = "youwu",
LabelDescription = "油污",
LabelCategory = "A_NG"
};
RecongnitionLabelList.Add(recongnition);
RecongnitionLabelList.Add(recongnition2);
RecongnitionLabelList.Add(recongnition3);
var det1 = new DetectionConfig("相机1", ModelType., @"D:\PROJECTS\X015\Vision\Cam1.onnx", false, "Cam1");
var det2 = new DetectionConfig("相机2", ModelType., @"D:\PROJECTS\X015\Vision\Cam2.onnx", false, "Cam2");
var det3 = new DetectionConfig("相机3", ModelType., @"D:\PROJECTS\X015\Vision\Cam3.onnx", false, "Cam3");
var det4 = new DetectionConfig("相机4", ModelType., @"D:\PROJECTS\X015\Vision\Cam4.onnx", false, "Cam4");
var det5 = new DetectionConfig("相机5", ModelType., @"D:\PROJECTS\X015\Vision\Cam5.onnx", false, "Cam5");
var det6 = new DetectionConfig("相机6", ModelType., @"D:\PROJECTS\X015\Vision\Cam6.onnx", false, "Cam6");
var det7 = new DetectionConfig("相机7", ModelType., @"D:\PROJECTS\X015\Vision\Cam7.onnx", false, "Cam7");
var det8 = new DetectionConfig("相机8", ModelType., @"D:\PROJECTS\X015\Vision\Cam8.onnx", false, "Cam8");
List<RelatedCamera> CameraCollects = new List<RelatedCamera>();
CameraCollects.Add(new RelatedCamera("Cam1"));
List<RelatedCamera> CameraCollects2 = new List<RelatedCamera>();
CameraCollects2.Add(new RelatedCamera("Cam2"));
List<RelatedCamera> CameraCollects3 = new List<RelatedCamera>();
CameraCollects3.Add(new RelatedCamera("Cam3"));
List<RelatedCamera> CameraCollects4 = new List<RelatedCamera>();
CameraCollects4.Add(new RelatedCamera("Cam4"));
List<RelatedCamera> CameraCollects5 = new List<RelatedCamera>();
CameraCollects5.Add(new RelatedCamera("Cam5"));
List<RelatedCamera> CameraCollects6 = new List<RelatedCamera>();
CameraCollects6.Add(new RelatedCamera("Cam6"));
List<RelatedCamera> CameraCollects7 = new List<RelatedCamera>();
CameraCollects7.Add(new RelatedCamera("Cam7"));
List<RelatedCamera> CameraCollects8 = new List<RelatedCamera>();
CameraCollects8.Add(new RelatedCamera("Cam8"));
float Conf = 0.5f;
det1.CameraCollects = CameraCollects;
det1.ModelconfThreshold = Conf;
det1.ModelWidth = 640;
det1.ModelHeight = 640;
det1.In_lable_path = "D:\\PROJECTS\\X015\\Vision\\Cam1.txt";
det1.IsEnabled = true;
det1.ShowLocation.X = 1;
det1.ShowLocation.Y = 1;
det2.CameraCollects = CameraCollects2;
det2.ModelconfThreshold = Conf;
det2.ModelWidth = 640;
det2.ModelHeight = 640;
det2.In_lable_path = "D:\\PROJECTS\\X015\\Vision\\Cam2.txt";
det2.IsEnabled = true;
det2.ShowLocation.X = 2;
det2.ShowLocation.Y = 1;
det3.CameraCollects = CameraCollects3;
det3.ModelconfThreshold = Conf;
det3.ModelWidth = 640;
det3.ModelHeight = 640;
det3.In_lable_path = "D:\\PROJECTS\\X015\\Vision\\Cam3.txt";
det3.IsEnabled = true;
det3.ShowLocation.X = 3;
det3.ShowLocation.Y = 1;
det4.CameraCollects = CameraCollects4;
det4.ModelconfThreshold = Conf;
det4.ModelWidth = 640;
det4.ModelHeight = 640;
det4.In_lable_path = "D:\\PROJECTS\\X015\\Vision\\Cam4.txt";
det4.IsEnabled = true;
det4.ShowLocation.X = 4;
det4.ShowLocation.Y = 1;
det5.CameraCollects = CameraCollects5;
det5.ModelconfThreshold = Conf;
det5.ModelWidth = 640;
det5.ModelHeight = 640;
det5.In_lable_path = "D:\\PROJECTS\\X015\\Vision\\Cam5.txt";
det5.IsEnabled = true;
det5.ShowLocation.X = 1;
det5.ShowLocation.Y = 2;
det6.CameraCollects = CameraCollects6;
det6.ModelconfThreshold = Conf;
det6.ModelWidth = 640;
det6.ModelHeight = 640;
det6.In_lable_path = "D:\\PROJECTS\\X015\\Vision\\Cam6.txt";
det6.IsEnabled = true;
det6.ShowLocation.X = 2;
det6.ShowLocation.Y = 2;
det7.CameraCollects = CameraCollects7;
det7.ModelconfThreshold = Conf;
det7.ModelWidth = 640;
det7.ModelHeight = 640;
det7.In_lable_path = "D:\\PROJECTS\\X015\\Vision\\Cam7.txt";
det7.IsEnabled = true;
det7.ShowLocation.X = 3;
det7.ShowLocation.Y = 2;
det8.CameraCollects = CameraCollects8;
det8.ModelconfThreshold = Conf;
det8.ModelWidth = 640;
det8.ModelHeight = 640;
det8.In_lable_path = "D:\\PROJECTS\\X015\\Vision\\Cam8.txt";
det8.IsEnabled = true;
det8.ShowLocation.X = 4;
det8.ShowLocation.Y = 2;
DetectionConfigs.Add(det1);
DetectionConfigs.Add(det2);
DetectionConfigs.Add(det3);
DetectionConfigs.Add(det4);
DetectionConfigs.Add(det5);
DetectionConfigs.Add(det6);
DetectionConfigs.Add(det7);
DetectionConfigs.Add(det8);
Cameras.Clear();
HKCameras.Clear();
Dectection.Clear();
_cameraRelatedDetectionDict = new();
#if false
for (int i = 1; i <= 8; i++)
{
HikVisionCamera camera = new HikVisionCamera();
camera.CameraName = $"Cam{i}";
camera.CameraIP = $"192.168.{i}.1";
camera.ComputerIP = $"192.168.{i}.1";
camera.CameraConnect();
camera.OnHImageOutput += OnCameraHImageOutput;
HKCameras.Add(camera);
}
#else
//Do3ThinkCamera do3ThinkCamera1 = new Do3ThinkCamera();
//do3ThinkCamera1.dvpStreamFormat = dvpStreamFormat.S_RAW8;
//do3ThinkCamera1.CameraName = "Cam1";
//do3ThinkCamera1.CameraConnect();
//do3ThinkCamera1.OnHImageOutput += OnCameraHImageOutput;
// Cameras.Add(do3ThinkCamera1);
for (int i = 1; i <= 8; i++)
{
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
DetectionConfigs.ForEach(detection =>
{
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);
}
}
);
});
string inferenceDevice = "CPU";
_visionEngine = new SimboVisionDriver();
_visionEngine.DetectionConfigs = DetectionConfigs;
_visionEngine.Init();
CtrlVisionRunBase ctrlVisionRun = new CtrlVisionRunBase(_visionEngine);
tabImgDisplay.Controls.Add(ctrlVisionRun);
//Add the code for the "启动" button click here
////初始化Halcon工具
//InitialHalconTools();
////深度学习模型加载
//bool resultOK = InitialSimboMLEnginesAsync();
//if (resultOK)
//{
// //初始化失败
// // return;
//}
//位置比较卡
sLDMotion.AxisSettings = new List<AxisSetting>();
AxisSetting axis1 = new AxisSetting();
axis1.AxisIndex = 0;
axis1.AxisName = "转盘1";
axis1.IsAxisEnabled = true;
//axis1.AlarmLogic = AxisDirection.Positive;
sLDMotion.IODefinitionCollection = new List<IODefinition>();
Motion(sLDMotion.IODefinitionCollection);
sLDMotion.SnapshotSettings = new List<SnapshotSetting>();
int[] cameraPositions = { 24161, 33608, 39702, 45701 };
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
{
IsEnabled = true,
CameraIO = sLDMotion.IODefinitionCollection.FirstOrDefault(t => t.IOType == IOType.OUTPUT && t.IOIndex == i),
CameraPosition = cameraPositions[i],
StationNumber = 0
});
}
sLDMotion.BlowSettings = new List<BlowSetting>();
int[] BlowPositions = { 61353, 68566 };
sLDMotion.BlowSettings.Add(new BlowSetting
{
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;
//sna1.CameraIO= sLDMotion.IODefinitionCollection.FirstOrDefault(t => t.IOType == IOType.OUTPUT && t.IOIndex == 0);
//sna1.CameraPosition = 17000;
//sna1.StationNumber = 0;
// sLDMotion.SnapshotSettings.Add(sna1);
sLDMotion.AxisSettings.Add(axis1);
sLDMotion.Init();
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 = 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(14000, 100000);
startTime = DateTime.Now;
}
public void Motion(List<IODefinition> iODefinitions)
{
for (int i = 0; i < 16; i++)
{
iODefinitions.Add(new IODefinition
{
IOType = IOType.INPUT,
IOIndex = i,
IODesc = $"入料传感器{i + 1}"
});
}
for (int i = 0; i < 16; i++)
{
iODefinitions.Add(new IODefinition
{
IOType = IOType.OUTPUT,
IOIndex = i,
IODesc = $"入料传感器{i + 1}"
});
}
}
#endif
private uint PieceCount = 0;
private List<ConcurrentDictionary<uint, ProductData>> _productLists = new List<ConcurrentDictionary<uint, ProductData>>();
private int ProductListMulti = 2;
@ -1302,6 +900,14 @@ namespace DHSoftware
product.ProductResult = product.ResultCollection.Any(u => u.ResultState != ResultState.OK)
? ResultState.B_NG
: ResultState.OK;
if (product.ProductResult == ResultState.OK)
{
PLC.Blowing(productNumber, 1);
}
else
{
PLC.Blowing(productNumber, 2);
}
product.ProductLabelCategory = product.ProductResult.GetEnumDescription();
product.ProductLabel = product.ProductResult.GetEnumDescription();
@ -1402,9 +1008,9 @@ namespace DHSoftware
Cameras.Clear();
Dectection.Clear();
// Add the code for the "停止" button click here
PLC.TurntableStop();
PLC.TurnStart(false);
CurrentMachine = true;
sLDMotion.Stop();
//sLDMotion.Stop();
}
public int UPH = 0;