|
|
@@ -28,8 +28,6 @@ namespace CCDCount.DLL
|
|
|
public string ThisCameraSN = string.Empty;
|
|
|
public string ThisCamerName = string.Empty;
|
|
|
public int ThisCamerNo = -1;
|
|
|
- //留给主界面的回调函数
|
|
|
- public event EventHandler<ActiveObjectEventArgsClass> WorkerToFrom;
|
|
|
|
|
|
public bool CameraStatic { get { return _CameraStatic; } }
|
|
|
private bool _CameraStatic = false;
|
|
|
@@ -63,10 +61,15 @@ namespace CCDCount.DLL
|
|
|
/// </summary>
|
|
|
private bool _ShuLiState = true;
|
|
|
public bool ShuLiState { get { return _ShuLiState; } }
|
|
|
+
|
|
|
+ private bool IsDebug = false;
|
|
|
#endregion
|
|
|
|
|
|
#region 公共方法
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// 设置ModbusTcpClient
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="modbusTcpClient"></param>
|
|
|
public void SetModbusClient(ModbusTcpClient modbusTcpClient)
|
|
|
{
|
|
|
this.modbusTcpClient = modbusTcpClient;
|
|
|
@@ -81,6 +84,11 @@ namespace CCDCount.DLL
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 初始化构造方法
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="configClass"></param>
|
|
|
+ /// <param name="CameraConfig"></param>
|
|
|
public MainThreadClass(ShuLiConfigClass configClass,CameraConfig CameraConfig)
|
|
|
{
|
|
|
// 数粒配置文件地址
|
|
|
@@ -101,6 +109,7 @@ namespace CCDCount.DLL
|
|
|
ThisCameraDevice = CameraConfig.DeviceName;
|
|
|
ThisCamerNo = CameraConfig.CamerNo;
|
|
|
}
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 开始主线程
|
|
|
/// </summary>
|
|
|
@@ -167,6 +176,7 @@ namespace CCDCount.DLL
|
|
|
result = true;
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 停止主线程
|
|
|
/// </summary>
|
|
|
@@ -182,6 +192,11 @@ namespace CCDCount.DLL
|
|
|
StopSendBottLogicMessageThread();
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 重加载相机
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="CameraSN"></param>
|
|
|
+ /// <returns></returns>
|
|
|
public bool ReLoadCamera(string CameraSN)
|
|
|
{
|
|
|
bool result = false;
|
|
|
@@ -197,6 +212,9 @@ namespace CCDCount.DLL
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 释放相机资源
|
|
|
+ /// </summary>
|
|
|
public void DisposeCamera()
|
|
|
{
|
|
|
cameraClass.StopCamera();
|
|
|
@@ -204,6 +222,7 @@ namespace CCDCount.DLL
|
|
|
ThisCamerName = string.Empty;
|
|
|
ThisCameraDevice = string.Empty;
|
|
|
}
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 获取显示用的图片数据
|
|
|
/// </summary>
|
|
|
@@ -222,18 +241,54 @@ namespace CCDCount.DLL
|
|
|
List<ActiveObjectClass> Data = shuLiClass.GetHistoryActive().Where(o => o.LastSeenLine > NewActive.LastSeenLine - ImageHeight).ToList();
|
|
|
Data.ForEach(o => o.RowsData.ForEach(p => RowsShowList.Add(p)));
|
|
|
Bitmap BitmapImage = new Bitmap(NewActive.ImageWidth, ImageHeight);
|
|
|
- Graphics g = Graphics.FromImage(BitmapImage);
|
|
|
- Pen redPen = new Pen(Color.Red, 1);
|
|
|
- List<RowStartEndCol> ShowList = RowsShowList.Where(o => o.RowsCol > NewActive.LastSeenLine - BitmapImage.Height).ToList();
|
|
|
- RowsShowList.Where(o => o.RowsCol < NewActive.LastSeenLine - BitmapImage.Height).ToList().ForEach(o => RowsShowList.Remove(o));
|
|
|
- RowsShowList.Clear();
|
|
|
- ShowList.ForEach(o => g.DrawLine(redPen, new Point(o.StartCol, (int)(NewActive.LastSeenLine - o.RowsCol)), new Point(o.EndCol, (int)(NewActive.LastSeenLine - o.RowsCol))));
|
|
|
- ShowList.Clear();
|
|
|
+ using (Graphics g = Graphics.FromImage(BitmapImage))
|
|
|
+ {
|
|
|
+ g.Clear(Color.White);
|
|
|
+ using (Pen BlackPan = new Pen(Color.Black, 4))
|
|
|
+ {
|
|
|
+ for (int i = 0; i < shuLiClass.ChannelsRoi.Count - 1; i++)
|
|
|
+ {
|
|
|
+ g.DrawLine(BlackPan, new Point(shuLiClass.ChannelsRoi[i], 0), new Point(shuLiClass.ChannelsRoi[i], BitmapImage.Height));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ using (Pen redPen = new Pen(Color.Red, 1))
|
|
|
+ {
|
|
|
+ List<RowStartEndCol> ShowList = RowsShowList.Where(o => o.RowsCol > NewActive.LastSeenLine - BitmapImage.Height).ToList();
|
|
|
+ RowsShowList.Where(o => o.RowsCol < NewActive.LastSeenLine - BitmapImage.Height).ToList().ForEach(o => RowsShowList.Remove(o));
|
|
|
+ RowsShowList.Clear();
|
|
|
+ ShowList.ForEach(o => g.DrawLine(redPen, new Point(o.StartCol, (int)(NewActive.LastSeenLine - o.RowsCol)), new Point(o.EndCol, (int)(NewActive.LastSeenLine - o.RowsCol))));
|
|
|
+ ShowList.Clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
ImageData = BitmapImage.Clone() as Bitmap;
|
|
|
BitmapImage.Dispose();
|
|
|
//GC.Collect();
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 获取无数据的图片
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="ImageWidth"></param>
|
|
|
+ /// <param name="ImageHeight"></param>
|
|
|
+ /// <param name="ImageData"></param>
|
|
|
+ public void GetNullShowImage(int ImageWidth, int ImageHeight, out Bitmap ImageData)
|
|
|
+ {
|
|
|
+ Bitmap BitmapImage = new Bitmap(ImageWidth, ImageHeight);
|
|
|
+ using (Graphics g = Graphics.FromImage(BitmapImage))
|
|
|
+ {
|
|
|
+ g.Clear(Color.White);
|
|
|
+ using (Pen BlackPan = new Pen(Color.Black, 4))
|
|
|
+ {
|
|
|
+ for (int i = 0; i < shuLiClass.ChannelsRoi.Count - 1; i++)
|
|
|
+ {
|
|
|
+ g.DrawLine(BlackPan, new Point(shuLiClass.ChannelsRoi[i], 0), new Point(shuLiClass.ChannelsRoi[i], BitmapImage.Height));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ImageData = BitmapImage.Clone() as Bitmap;
|
|
|
+ BitmapImage.Dispose();
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 获取此刻的Config数据
|
|
|
/// </summary>
|
|
|
@@ -265,6 +320,7 @@ namespace CCDCount.DLL
|
|
|
//新建一个相机配置
|
|
|
CameraConfig = new CameraConfig();
|
|
|
}
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 保存所有Config
|
|
|
/// </summary>
|
|
|
@@ -285,9 +341,28 @@ namespace CCDCount.DLL
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public void Dispose()
|
|
|
+ /// <summary>
|
|
|
+ /// 清除历史数据
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public bool ClearHistoryActive()
|
|
|
{
|
|
|
- //MechanicalControl.Dispose();
|
|
|
+ bool result = false;
|
|
|
+ if(shuLiClass != null)
|
|
|
+ result = shuLiClass.ClearHistoryActive();
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取过去一秒内颗粒数量
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public int GetOneSecondActiveNum()
|
|
|
+ {
|
|
|
+ int result = 0;
|
|
|
+ if(shuLiClass != null)
|
|
|
+ result = shuLiClass.GetHistoryActive().Where(o=>o.EndCheckTime>DateTime.Now-TimeSpan.FromSeconds(1)).Count();
|
|
|
+ return result;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
@@ -344,16 +419,6 @@ namespace CCDCount.DLL
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 对外通知事件
|
|
|
- /// </summary>
|
|
|
- private void OnOneGrain(List<ActiveObjectClass> activeObject)
|
|
|
- {
|
|
|
- ActiveObjectEventArgsClass activeObjectEventArgs = new ActiveObjectEventArgsClass(activeObject);
|
|
|
- // 触发事件
|
|
|
- WorkerToFrom?.Invoke(this, activeObjectEventArgs);
|
|
|
- }
|
|
|
#endregion
|
|
|
|
|
|
#region 线程方法
|
|
|
@@ -404,6 +469,11 @@ namespace CCDCount.DLL
|
|
|
GC.Collect();
|
|
|
stopwatch.Restart();
|
|
|
}
|
|
|
+ //Debug模式,不进行图像处理
|
|
|
+ if (IsDebug)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
//Thread.Sleep(5);
|
|
|
bool result = cameraClass.GetOnceImage(out IFramedata);
|
|
|
if (result)
|
|
|
@@ -471,7 +541,7 @@ namespace CCDCount.DLL
|
|
|
Stopwatch sw = Stopwatch.StartNew();
|
|
|
while (IsSend)
|
|
|
{
|
|
|
- LOG.log("进入线程", 6);
|
|
|
+ //LOG.log("进入线程", 6);
|
|
|
sw.Restart();
|
|
|
sendMessage = new ushort();
|
|
|
//读取装瓶状态
|
|
|
@@ -501,9 +571,9 @@ namespace CCDCount.DLL
|
|
|
modbusTcpClient.WriteSingleRegister(slaveId: 1, registerAddress: 100, value: sendMessage);
|
|
|
modbusTcpClient.WriteCoilsRegister(slaveId: 1, CoilsAddress: 11, values: true);
|
|
|
}
|
|
|
+ sw.Stop();
|
|
|
+ LOG.log(string.Format("sendMessage[1]:{0},此次写值耗时:{1}", sendMessage, sw.Elapsed), 6);
|
|
|
}
|
|
|
- sw.Stop();
|
|
|
- LOG.log(string.Format("离开线程写入值:sendMessage[1]:{0},此次写值耗时:{1}", sendMessage, sw.Elapsed), 6);
|
|
|
Thread.Sleep(1);
|
|
|
}
|
|
|
}
|