namespace Measure
{
public delegate void DelegateTrigger();
public class HMeasureSYS : System.IDisposable
{
public static string sConfigPath = @"MeasureSys.cfg"; /// <summary>
/// U000单元 全局变量
/// </summary>
public const int U000 = ;
/// <summary>
/// USys单元 系统变量
/// </summary>
public const int USys = -; /// <summary>
/// 当前项目
/// </summary>
public static CProject Cur_Project = null; //当前项目 /// <summary>
/// 工程列表
/// </summary>
public static List<CProject> g_ProjectList = new List<CProject>(); /// <summary>
/// 系统变量列表和常量
/// </summary>
public static List<F_DATA_CELL> g_VariableList = new List<F_DATA_CELL>(); /// <summary>
/// 采集设备列表
/// </summary>
public static List<AcqDeviceBase> g_AcqDeviceList = new List<AcqDeviceBase>();
/// <summary>
/// tcp服务器
/// </summary>
public static TCPServer2 g_TcpServer = new TCPServer2(); /// <summary>
/// 系统运行状态
/// </summary>
public static Sys_Status g_SysStatus = new Sys_Status(); /// <summary>
/// 相机触发源,定义为EVENT是为了满足一个信号触发多个相机
/// </summary>
public static event DelegateTrigger g_TR1 = null;
public static event DelegateTrigger g_TR2 = null;
public static event DelegateTrigger g_TR3 = null;
public static event DelegateTrigger g_TR4 = null; /// <summary>
/// 镭射终止采集触发源,定义为EVENT是为了满足一个信号触发多个相机
/// </summary>
public static event DelegateTrigger g_EndTR1 = null;
public static event DelegateTrigger g_EndTR2 = null;
public static event DelegateTrigger g_EndTR3 = null;
public static event DelegateTrigger g_EndTR4 = null; /// <summary>
/// 初始化视觉工程项目
/// </summary>
/// <param name="filepath">初始化文件所在路径</param>
/// <returns></returns>
public static bool InitialVisionProgram(string filepath = @"MeasureSys.cfg")
{
try
{
string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
if (filepath.Contains(@":\") == false)
{
filepath = System.IO.Path.Combine(ThePath, filepath);
} if (filepath.Trim() == "" || System.IO.File.Exists(filepath) == false)
{
System.Windows.Forms.MessageBox.Show("输入文件名错误!");
throw new Exception("视觉测量模块报错:" + filepath + "不存在!");
}
else
{
HMeasureSYS.sConfigPath = filepath;
}
//设备也要同步先关闭 yoga 2018-8-30 15:34:29
HMeasureSYS.DisposeDev();
//由于可能之前已经打开了 此处要先将tcp服务器关闭
HMeasureSYS.g_TcpServer.tcp.Stop(); HMeasureSYS.ReadConfig(HMeasureSYS.sConfigPath);
//HMeasureSYS.ReadSpaceInfo(out HMeasureSYS.g_ProjectList, out HMeasureSYS.g_VariableList, out HMeasureSYS.g_AcqDeviceList, out HMeasureSYS.g_TcpServer, Application.StartupPath + sProject_Path); HMeasureSYS.g_TcpServer.tcp.Start();
//没次读取新的配置文件时重新检测VB代码状态和设备连接状态
HMeasureSYS.InitDevStatus();
return true;
}
catch (Exception ex)
{
MessageBox.Show("Measure.HMeasureSYS.InitialVisionProgram:" + ex.ToString());
return false;
}
} public static void DisposeVisionProgram()
{
Sys_Stop();
HMeasureSYS.g_TcpServer.Stop();
HMeasureSYS.DisposeDev();
} /// <summary>
///系统检测启动
/// </summary>
public static void Sys_Start()
{
for (int i = ; i < HMeasureSYS.g_ProjectList.Count; i++)
{
Sys_Start(i);
}
} /// <summary>
///系统检测启动
/// </summary>
public static void Sys_Start(int index)
{
HMeasureSYS.g_SysStatus.m_RunMode = RunMode.循环运行;
Sys_ThreadStart(index);
} public static void Sys_ThreadStart(int index)
{
if (index > HMeasureSYS.g_ProjectList.Count - )
{
return;
}
CMeasureCell cell = HMeasureSYS.g_ProjectList[index].m_CellList.First(c => c.m_CellCatagory == CellCatagory.线阵图像单元 || c.m_CellCatagory == CellCatagory.面阵图像单元);
if (cell.m_CellCatagory == CellCatagory.面阵图像单元)
{
((CImageReg_Area)cell).m_AcqDevice.eventWait.Reset();
((CImageReg_Area)cell).m_AcqDevice.SignalWait.Reset();
}
else if (cell.m_CellCatagory == CellCatagory.线阵图像单元)
{
((CImageReg_Line)cell).m_AcqDevice.eventWait.Reset();
} HMeasureSYS.g_ProjectList[index].Thread_Start();
}
public static void Sys_StartTest(int index)
{
HMeasureSYS.g_SysStatus.m_RunMode = RunMode.执行一次;
Sys_ThreadStart(index);
} /// <summary>
///系统检测停止
/// </summary>
public static void Sys_Stop(int index)
{
try
{
if (index > HMeasureSYS.g_ProjectList.Count - )
{
return;
}
HMeasureSYS.g_ProjectList[index].Thread_Stop();
int cellIndex = HMeasureSYS.g_ProjectList[index].m_CellList.FindIndex(c => c.m_CellID == HMeasureSYS.g_ProjectList[index].CurCellID);
if (cellIndex >= )
{
CMeasureCell cell = HMeasureSYS.g_ProjectList[index].m_CellList[cellIndex];
if (cell.m_CellCatagory == CellCatagory.面阵图像单元)
{
((CImageReg_Area)cell).m_AcqDevice.SignalWait.Set();
((CImageReg_Area)cell).m_AcqDevice.eventWait.Set();
}
else if (cell.m_CellCatagory == CellCatagory.线阵图像单元)
{
((CImageReg_Line)cell).m_AcqDevice.eventWait.Set();
}
else if (cell.m_CellCatagory== CellCatagory.延时单元)
{
((CDelay)cell).Stop();
}
}
}
catch (Exception ex)
{
MessageBox.Show("Measure.HMeasureSYS.Sys_Stop:" + ex.ToString());
}
} /// <summary>
///系统检测停止
/// </summary>
public static void Sys_Stop()
{
try
{
for (int i = ; i < HMeasureSYS.g_ProjectList.Count; i++)
{
Sys_Stop(i);
}
}
catch (System.Exception ex)
{
MessageBox.Show("Measure.HMeasureSYS.Sys_Stop:" + ex.ToString());
Helper.LogHandler.Instance.VTLogWarning(ex.ToString());
}
} /// <summary>
/// 相机触发事件/镭射开始终止采集触发事件
/// </summary>
/// <param name="str">字符串</param>
public static void setTrigger(string str)
{
switch (str)
{
case "TR1":
if (HMeasureSYS.g_TR1 != null)
{
HMeasureSYS.g_TR1();
}
break;
case "TR2":
if (HMeasureSYS.g_TR2 != null)
{
HMeasureSYS.g_TR2();
}
break;
case "TR3":
if (HMeasureSYS.g_TR3 != null)
{
HMeasureSYS.g_TR3();
}
break;
case "TR4":
if (HMeasureSYS.g_TR4 != null)
{
HMeasureSYS.g_TR4();
}
break;
case "EndTR1":
if (HMeasureSYS.g_EndTR1 != null)
{
HMeasureSYS.g_EndTR1();
}
break;
case "EndTR2":
if (HMeasureSYS.g_EndTR2 != null)
{
HMeasureSYS.g_EndTR2();
}
break;
case "EndTR3":
if (HMeasureSYS.g_EndTR3 != null)
{
HMeasureSYS.g_EndTR3();
}
break;
case "EndTR4":
if (HMeasureSYS.g_EndTR4 != null)
{
HMeasureSYS.g_EndTR4();
}
break;
}
} #region 配置文件
public static void ReadConfig(string filePath)
{
try
{// Deserialize.
using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
fs.Seek(, SeekOrigin.Begin);
BinaryFormatter binaryFmt = new BinaryFormatter();
HMeasureSYS.g_VariableList = (List<F_DATA_CELL>)binaryFmt.Deserialize(fs);
HMeasureSYS.g_AcqDeviceList = (List<AcqDeviceBase>)binaryFmt.Deserialize(fs);
AcqDeviceBase.m_LastDeviceID = (int)binaryFmt.Deserialize(fs);
HMeasureSYS.g_TcpServer = (TCPServer2)binaryFmt.Deserialize(fs);
HMeasureSYS.g_ProjectList = (List<CProject>)binaryFmt.Deserialize(fs);
CProject.m_LastProjectID = (int)binaryFmt.Deserialize(fs);
CProject.m_IsMangerGTCard=(bool)binaryFmt.Deserialize(fs);
//fs.Close();
//GT_MotionControl.Helper.InitMotionControl();
}
}
catch (System.Exception ex)
{
MessageBox.Show("Measure.HMeasureSYS.ReadConfig:" + ex.ToString());
LogHandler.Instance.VTLogError(ex.ToString());
}
} public static void SaveConfig(string filePath)
{
//添加相对路径判断 如果是相对路径 必须指定到exe目录 否则可能因为打开文件等对话框影响存储路径 yoga 2018-8-30 11:06:48
string ThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
string tempFile = "tempMeasureSys.cfg";
tempFile=System.IO.Path.Combine(ThePath, tempFile);
try
{
System.GC.Collect();
using (FileStream fs = new FileStream(tempFile, FileMode.Create))
{
BinaryFormatter binaryFmt = new BinaryFormatter();
fs.Seek(, SeekOrigin.Begin);
binaryFmt.Serialize(fs, HMeasureSYS.g_VariableList);
binaryFmt.Serialize(fs, HMeasureSYS.g_AcqDeviceList);
binaryFmt.Serialize(fs, AcqDeviceBase.m_LastDeviceID);
binaryFmt.Serialize(fs, HMeasureSYS.g_TcpServer);
binaryFmt.Serialize(fs, HMeasureSYS.g_ProjectList);
binaryFmt.Serialize(fs, CProject.m_LastProjectID);
binaryFmt.Serialize(fs, CProject.m_IsMangerGTCard);
//fs.Close();
}
string outPath = filePath;
if (filePath.Contains(@":\") == false)
{
outPath = System.IO.Path.Combine(ThePath, filePath);
}
Helper.FileHelper.FileCoppy(tempFile, outPath);
}
catch (System.Exception ex)
{
MessageBox.Show("保存配置文件失败" + ex.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
LogHandler.Instance.VTLogError(ex.ToString());
}
}
#endregion
/// <summary>
/// 检查所有相机是否在线
/// </summary>
/// <returns>全部在线为true</returns>
public static bool CheckDevStatus()
{
foreach (AcqDeviceBase dev in HMeasureSYS.g_AcqDeviceList)
{
if (dev.m_bConnected==false)
{
return false;
}
}
return true;
}
/// <summary>
/// 初始化设备连接状态
/// </summary>
public static void InitDevStatus()
{
foreach (AcqDeviceBase dev in HMeasureSYS.g_AcqDeviceList)
{
if (dev.m_bConnected)
{
dev.m_bConnected = false;
dev.ConnectDev();
dev.setSetting();
}
else
{
dev.DisConnectDev();
}
}
} /// <summary>
/// 释放设备
/// </summary>
public static void DisposeDev()
{
foreach (AcqDeviceBase dev in HMeasureSYS.g_AcqDeviceList)
{
if (dev.m_bConnected)
{
dev.DisConnectDev();
}
}
} public void Dispose()
{
} #region "图像离线保存"
/// <summary>
/// 保存图片
/// </summary>
/// <param name="filePath">文件存储路径</param>
/// <param name="projectId">项目ID</param>
/// <param name="imgName">保存图片的变量名称</param>
public static void SaveImage(string filePath, int projectId, string imgName)
{
if (HMeasureSYS.g_ProjectList.Count > projectId)
{
RegisterIMG_Info tempImg = new RegisterIMG_Info();
F_DATA_CELL datacell = HMeasureSYS.g_ProjectList[projectId].m_VariableList.FirstOrDefault(c => c.m_Data_CellID == HMeasureSYS.U000 && c.m_Data_Name == imgName);
tempImg.m_Image = ((List<HImageExt>)datacell.m_Data_Value)[].Clone();
tempImg.m_ImageID = filePath;
ThreadPool.QueueUserWorkItem(o =>
{
try
{
RegisterIMG_Info imgInfo = (RegisterIMG_Info)tempImg;
string type = imgInfo.m_Image.GetImageType().ToString();
if (type.Contains("real"))
{
imgInfo.m_Image.WriteImage("tiff", , imgInfo.m_ImageID);
}
else if (type.Contains("byte"))
{
imgInfo.m_Image.WriteImage("tiff lzw alpha", , imgInfo.m_ImageID);
}
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
});
}
} /// <summary>
/// 保存图像
/// </summary>
/// <param name="filepath">图像保存路径,不包括文件后缀如 .png</param>
/// <param name="scaleSize">放缩比例,建议为1.0,不能小于0</param>
/// <param name="isSaveSrcImage">是否保存原图,true表示保存原图,false表示保存效果图</param>
/// <param name="imageName">图像名称 为空保存图像序列中的全部</param>
public static void SaveImage(string filepath, double scaleSize, bool isSaveSrcImage, string imageName)
{
if (filepath == "")
{
System.Windows.Forms.MessageBox.Show("SaveBoardImage:输出路径为空!");
return;
} if (scaleSize <= )
{
System.Windows.Forms.MessageBox.Show("SaveBoardImage:scaleSize必须大于0!");
return;
} List<F_DATA_CELL> datalist = HMeasureSYS.Cur_Project.m_VariableList.FindAll(c => c.m_Data_CellID == HMeasureSYS.U000
&& c.m_Data_Type == DataType.图像);
foreach (F_DATA_CELL item in datalist)
{
if (imageName == "")
{
SaveImage(filepath + "_" + HMeasureSYS.Cur_Project.m_ProjectName + "_" + item.m_Data_Name,
scaleSize,
isSaveSrcImage,
((List<HImageExt>)item.m_Data_Value)[].Clone());
}
else
{
if (item.m_Data_Name == imageName)
{
SaveImage(filepath + "_" + HMeasureSYS.Cur_Project.m_ProjectName + "_" + item.m_Data_Name,
scaleSize,
isSaveSrcImage,
((List<HImageExt>)item.m_Data_Value)[].Clone());
return;
}
}
}
} /// <summary>
/// 保存单一图像
/// </summary>
/// <param name="filepath">图像保存路径,不包括文件后缀如 .png</param>
/// <param name="scaleSize">放缩比例,建议为1.0,不能小于0</param>
/// <param name="isSaveSrcImage">是否保存原图,true表示保存原图,false表示保存效果图</param>
/// <param name="srcImage">需要保存的图像</param>
public static void SaveImage(string filepath, double scaleSize, bool isSaveSrcImage, HImageExt srcImage)
{
if (filepath == "")
{
System.Windows.Forms.MessageBox.Show("SaveBoardImage:输出路径为空!");
return;
} if (scaleSize <= )
{
System.Windows.Forms.MessageBox.Show("SaveBoardImage:scaleSize必须大于0!");
return;
} if (srcImage.IsInitialized() == false && srcImage != null)
{
System.Windows.Forms.MessageBox.Show("SaveBoardImage:图像未初始化!");
return;
} if (isSaveSrcImage)
{
ThreadPool.QueueUserWorkItem(o =>
{
try
{
HImageExt image = srcImage.Clone();
string type = image.GetImageType().ToString();
if (type.Contains("real"))
{
image.WriteImage("tiff", , filepath);
}
else
{
image.WriteImage("tiff lzw alpha", , filepath);
} image.Dispose();
GC.Collect();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
});
}
else
{
ThreadPool.QueueUserWorkItem(o =>
{
try
{
HImageExt image = srcImage.Clone();
int width, height;
image.GetImageSize(out width, out height);
ChoiceTech.Halcon.Control.HWindow_HE tempHWindow_HE = new ChoiceTech.Halcon.Control.HWindow_HE();
tempHWindow_HE.Size = new Size((int)(width * scaleSize), (int)(height * scaleSize));
tempHWindow_HE.showHE(image);
HImage img = tempHWindow_HE.hWindowControl.HalconWindow.DumpWindowImage();
img.WriteImage("tiff lzw alpha", , filepath);
tempHWindow_HE.Dispose();
image.Dispose();
GC.Collect();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.ToString());
}
});
}
}
#endregion
}
}

namespace Measure的更多相关文章

  1. 重新想象 Windows 8 Store Apps (17) - 控件基础: Measure, Arrange, GeneralTransform, VisualTree

    原文:重新想象 Windows 8 Store Apps (17) - 控件基础: Measure, Arrange, GeneralTransform, VisualTree [源码下载] 重新想象 ...

  2. Microsoft.Office.Workflow.Actions Namespace

    Microsoft.Office.Workflow.Actions Namespace SharePoint 2010   Contains the workflow activities that ...

  3. 理解Docker(3):Docker 使用 Linux namespace 隔离容器的运行环境

    本系列文章将介绍Docker的有关知识: (1)Docker 安装及基本用法 (2)Docker 镜像 (3)Docker 容器的隔离性 - 使用 Linux namespace 隔离容器的运行环境 ...

  4. C++ namespace

    namespace, 命名空间, 用于解决命名冲突的问题. Python中的package/module, Javascript中的object, Java中的package都具有这样的功能. 如何使 ...

  5. C++ 之namespace常见用法

    一.背景 需要使用Visual studio的C++,此篇对namespace的常用用法做个记录. 二.正文 namespace通常用来给类或者函数做个区间定义,以使编译器能准确定位到适合的类或者函数 ...

  6. using namespace std 和 using std::cin

    相较using std::cin使用using namespace std不会使得程序的效率变低,或者稳定性降低,只是这样作会将很多的名字引入程序,使得程序员使用的名字集合变小,容易引起命名冲突. 在 ...

  7. Why Namespace? - 每天5分钟玩转 OpenStack(102)

    上一节我们讨论了 Neutron 将虚拟 router 放置到 namespace 中实现了不同 subnet 之间的路由.今天探讨为什么要用 namespace 封装 router? 回顾一下前面的 ...

  8. struts2中错误There is no Action mapped for namespace [/] and action name [] associated with context path

    1 There is no Action mapped for namespace [/] and action name [] associated with context path [/Stru ...

  9. PHP 命名空间(namespace)

    PHP 命名空间(namespace) PHP 命名空间(namespace)是在PHP 5.3中加入的,如果你学过C#和Java,那命名空间就不算什么新事物. 不过在PHP当中还是有着相当重要的意义 ...

随机推荐

  1. CentOS7.5安装SVN和可视化管理工具iF.SVNAdmin

    一.安装Apache和PHP 由于iF.SVNAdmin使用php写的,因此我们需要安装php yum install httpd php 二.安装SVN服务器(其中,mod_dav_svn是Apac ...

  2. 《BUG创造队》第九次团队作业:Beta冲刺与验收准备

    项目 内容 这个作业属于哪个课程 2016级软件工程 这个作业的要求在哪里 实验十三 团队作业9:Beta冲刺与团队项目验收 团队名称 BUG创造队 作业学习目标 (1)掌握软件黑盒测试技术:(2)学 ...

  3. docker-compose更新image命令

    docker-compose stop docker-compose up -d --build

  4. css 的弱化与 js 的强化(转)

    web 的三要素 html, css, js 在前端组件化的过程中,比如 react.vue 等组件化框架的运用,使 html 的弱化与 js 的强化 成为了一种趋势,而在这个过程中,其实还有另一种趋 ...

  5. npm中的学习课程

    我也不知道叫什么名字好 进入 https://nodeschool.io/zh-cn/,你能够看到许多课程. 这些课程大多面向零基础的,非常有趣(类似于许多关卡的小游戏). 快速开始 首先,确定你的电 ...

  6. 域权限维持:Ptk(Pass The Ticket)

    Kerberos协议传送门:https://www.cnblogs.com/zpchcbd/p/11707302.html 1.黄金票据 2.白银票据

  7. Optimal Marks SPOJ - OPTM(最小割)

    传送门 论文<最小割模型在信息学竞赛中的应用>原题 二进制不同位上互不影响,那么就按位跑网络流 每一位上,确定的点值为1的与S连一条容量为INF的有向边.为0的与T连一条容量为INF的有向 ...

  8. ROM

    ROM 是 read only memory的简称,表示只读存储器,是一种半导体存储器.只读存储器(ROM)是一种在正常工作时其存储的数据固定不变,其中的数据只能读出,不能写入,即使断电也能够保留数据 ...

  9. 【JZOJ6227】【20190621】ichi

    题目 $n , m ,d,x\le 10^5 , $强制在线 题解 对原树做dfs,得到原树的dfs序 对kruksal重构树做dfs,得到重构树的dfs序 那么就是一个三维数点问题 强制在线并且卡空 ...

  10. QML学习(三)——<QML命名规范>

    QML对象声明 QML对象特性一般使用下面的顺序进行构造: id 属性声明 信号声明 JavaScript函数 对象属性 子对象 状态 状态切换 为了获取更好的可读性,建议在不同部分之间添加一个空行. ...