Commit fe2dd3b3 几米阳光

使用balser相机扫码

1 个父辈 4d9b62ca
......@@ -36,6 +36,9 @@
<ApplicationIcon>box.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="halcondotnet">
<HintPath>..\..\dll\halcondotnet.dll</HintPath>
</Reference>
<Reference Include="log4net">
<HintPath>..\..\dll\log4net.dll</HintPath>
</Reference>
......@@ -65,6 +68,18 @@
<Compile Include="FrmBase.Designer.cs">
<DependentUpon>FrmBase.cs</DependentUpon>
</Compile>
<Compile Include="FrmCamera.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FrmCamera.Designer.cs">
<DependentUpon>FrmCamera.cs</DependentUpon>
</Compile>
<Compile Include="FrmCodeLearn.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FrmCodeLearn.Designer.cs">
<DependentUpon>FrmCodeLearn.cs</DependentUpon>
</Compile>
<Compile Include="FrmIOStatus.cs">
<SubType>Form</SubType>
</Compile>
......@@ -93,6 +108,12 @@
<EmbeddedResource Include="FrmBase.resx">
<DependentUpon>FrmBase.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FrmCamera.resx">
<DependentUpon>FrmCamera.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FrmCodeLearn.resx">
<DependentUpon>FrmCodeLearn.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FrmIOStatus.resx">
<DependentUpon>FrmIOStatus.cs</DependentUpon>
</EmbeddedResource>
......
......@@ -36,9 +36,9 @@
<add key="KTK_MOVE_AxisNo" value="1"/>
<!--摄像机名称列表配置,用#分割-->
<add key ="CameraName" value ="192168024#192168025"/>
<add key ="CameraName" value ="codeCamera"/>
<!--二维码类型列表配置,用#分割-->
<add key ="CodeType" value ="QR Code#Data Matrix ECC 200"/>
<add key ="CodeType" value ="Data Matrix ECC 200"/>
<!--二维码参数文件所在路径,文件名与二维码类型名一样-->
<add key ="CodeParamPath" value ="\StoreConfig\AC\"/>
</appSettings>
......
namespace OnlineStore.ACSingleStore
{
partial class FrmCamera
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.btnCloseCamera = new System.Windows.Forms.Button();
this.btnGetImage = new System.Windows.Forms.Button();
this.btnOpen = new System.Windows.Forms.Button();
this.hWindowControl1 = new HalconDotNet.HWindowControl();
this.btnExit = new System.Windows.Forms.Button();
this.btnLearn = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// timer1
//
this.timer1.Interval = 5000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// richTextBox1
//
this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.richTextBox1.Location = new System.Drawing.Point(496, 216);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(165, 167);
this.richTextBox1.TabIndex = 4;
this.richTextBox1.Text = "";
//
// btnCloseCamera
//
this.btnCloseCamera.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnCloseCamera.Location = new System.Drawing.Point(523, 90);
this.btnCloseCamera.Name = "btnCloseCamera";
this.btnCloseCamera.Size = new System.Drawing.Size(135, 35);
this.btnCloseCamera.TabIndex = 3;
this.btnCloseCamera.Text = "关闭 ";
this.btnCloseCamera.UseVisualStyleBackColor = true;
this.btnCloseCamera.Click += new System.EventHandler(this.btnCloseCamera_Click);
//
// btnGetImage
//
this.btnGetImage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnGetImage.Location = new System.Drawing.Point(523, 51);
this.btnGetImage.Name = "btnGetImage";
this.btnGetImage.Size = new System.Drawing.Size(135, 35);
this.btnGetImage.TabIndex = 2;
this.btnGetImage.Text = "扫码测试";
this.btnGetImage.UseVisualStyleBackColor = true;
this.btnGetImage.Click += new System.EventHandler(this.btnGetImage_Click);
//
// btnOpen
//
this.btnOpen.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnOpen.Location = new System.Drawing.Point(523, 12);
this.btnOpen.Name = "btnOpen";
this.btnOpen.Size = new System.Drawing.Size(135, 35);
this.btnOpen.TabIndex = 1;
this.btnOpen.Text = "打开 ";
this.btnOpen.UseVisualStyleBackColor = true;
this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);
//
// hWindowControl1
//
this.hWindowControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.hWindowControl1.BackColor = System.Drawing.Color.Black;
this.hWindowControl1.BorderColor = System.Drawing.Color.Black;
this.hWindowControl1.ImagePart = new System.Drawing.Rectangle(0, 0, 640, 480);
this.hWindowControl1.Location = new System.Drawing.Point(12, 12);
this.hWindowControl1.Name = "hWindowControl1";
this.hWindowControl1.Size = new System.Drawing.Size(478, 371);
this.hWindowControl1.TabIndex = 5;
this.hWindowControl1.WindowSize = new System.Drawing.Size(478, 371);
//
// btnExit
//
this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnExit.Location = new System.Drawing.Point(523, 168);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(135, 35);
this.btnExit.TabIndex = 6;
this.btnExit.Text = "返回(&B)";
this.btnExit.UseVisualStyleBackColor = true;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// btnLearn
//
this.btnLearn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnLearn.Location = new System.Drawing.Point(523, 129);
this.btnLearn.Name = "btnLearn";
this.btnLearn.Size = new System.Drawing.Size(135, 35);
this.btnLearn.TabIndex = 7;
this.btnLearn.Text = "学习二维码";
this.btnLearn.UseVisualStyleBackColor = true;
this.btnLearn.Click += new System.EventHandler(this.btnLearn_Click);
//
// FrmCamera
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(670, 395);
this.Controls.Add(this.btnLearn);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.hWindowControl1);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.btnCloseCamera);
this.Controls.Add(this.btnGetImage);
this.Controls.Add(this.btnOpen);
this.Name = "FrmCamera";
this.Text = "二维码识别测试";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FrmCamera_FormClosed);
this.Load += new System.EventHandler(this.FrmCamera_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btnOpen;
private System.Windows.Forms.Button btnGetImage;
private System.Windows.Forms.Button btnCloseCamera;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Timer timer1;
private HalconDotNet.HWindowControl hWindowControl1;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Button btnLearn;
}
}
\ No newline at end of file

using HalconDotNet;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OnlineStore.ACSingleStore
{
public partial class FrmCamera : FrmBase
{
private AC_SA_BoxBean store = null;
public FrmCamera(AC_SA_BoxBean store)
{
this.store = store;
InitializeComponent();
}
private void btnOpen_Click(object sender, EventArgs e)
{
HDevelopExport.CloseAllCamera();
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
HDevelopExport.OpenAllCamera();
FormStatus(true);
}
private void FormStatus(bool open)
{
btnOpen.Enabled = !open;
btnCloseCamera.Enabled = open;
btnGetImage.Enabled = open;
timer1.Enabled = open;
btnLearn.Enabled = !open;
}
private void btnGetImage_Click(object sender, EventArgs e)
{
List<string> allCodeList = new List<string>();
foreach (string cameraName in HDevelopExport.cameraNameList)
{
HObject ho_Image = HDevelopExport.GrabImage(cameraName);
List<string> codeList = HDevelopExport.GetCode(ho_Image);
allCodeList.AddRange(codeList);
}
if (allCodeList != null)
{
this.richTextBox1.Clear();
foreach (string str in allCodeList)
{
this.richTextBox1.AppendText(str);
}
}
}
private void btnCloseCamera_Click(object sender, EventArgs e)
{
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
HDevelopExport.CloseAllCamera();
FormStatus(false);
}
private void FrmCamera_Load(object sender, EventArgs e)
{
FormStatus(false);
}
private void FrmCamera_FormClosed(object sender, FormClosedEventArgs e)
{
if (btnCloseCamera.Enabled.Equals(true))
{
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
HDevelopExport.CloseAllCamera();
FormStatus(false);
}
}
private int preIndex = 0;
int dWidth = 0; int dHeight = 0;
private void timer1_Tick(object sender, EventArgs e)
{
preIndex++;
HObject ho_Image = null;
int index = preIndex % HDevelopExport.cameraNameList.Count;
ho_Image = HDevelopExport.GrabImage(HDevelopExport.cameraNameList[index]);
if (ho_Image != null)
{
if (dWidth <= 0)
{
HTuple width, height;
//int dWidth = 0; int dHeight = 0;
HOperatorSet.GetImageSize(ho_Image, out width, out height);
dWidth = (int)width.D;
dHeight = (int)height.D;
hWindowControl1.HalconWindow.SetPart(0, 0, dHeight, dWidth);
}
HOperatorSet.DispObj(ho_Image, hWindowControl1.HalconWindow);
List<string> codeList = HDevelopExport.GetCode(ho_Image);
if (codeList != null)
{
this.richTextBox1.Clear();
this.richTextBox1.AppendText(DateTime.Now.ToString()+ "读到二维码:" + "\r\n");
LogUtil.info("读取到的二维码列表" + "\r\n");
foreach (string str in codeList)
{
this.richTextBox1.AppendText(str + "\r\n");
LogUtil.info(str + "\r\n");
}
}
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnLearn_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
FrmCodeLearn learn = new FrmCodeLearn();
learn.ShowDialog();
timer1.Enabled = true;
}
}
}
<?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>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
\ No newline at end of file
using HalconDotNet;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OnlineStore.ACSingleStore
{
public partial class FrmCodeLearn : FrmBase
{
private static string appPath = Application.StartupPath;
private static string path = appPath + ConfigAppSettings.GetValue(Setting_Init.CodeParamPath);
public FrmCodeLearn()
{
InitializeComponent();
}
private void btnOpen_Click(object sender, EventArgs e)
{
string filePath = txtParamPath.Text.Trim();
if (File.Exists(filePath))
{
}
else
{
try
{
File.Create(filePath);
}
catch (Exception ex)
{
LogUtil.error("创建文件:" + filePath + " 失败");
MessageBox.Show("创建文件失败!");
txtParamPath.SelectAll();
txtParamPath.Focus();
return;
}
}
//File.Delete(filePath);
string cameraName = cmbCameraList.Text;
string codeType = this.cmbCodeType.Text;
int count = cmbCount.SelectedIndex + 1;
Task.Factory.StartNew(delegate ()
{
HDevelopCodeLearn.RunHalcon(this.hWindowControl1.HalconWindow, cameraName, codeType, filePath, count);
});
FormStatus(true);
}
private void FormStatus(bool open)
{
btnOpen.Enabled = !open;
btnStop.Enabled = open;
//timer1.Enabled = open;
//cmbCount.Enabled = !open;
//cmbCodeType.Enabled = !open;
//cmbCameraList.Enabled = !open;
}
private void btnStop_Click(object sender, EventArgs e)
{
HDevelopCodeLearn.StopLearn();
FormStatus(false);
}
private void FrmCamera_Load(object sender, EventArgs e)
{
LogUtil.logBox = this.richTextBox2;
HDevelopExport.LoadConfig(ConfigAppSettings.GetValue(Setting_Init.CameraName),ConfigAppSettings.GetValue(Setting_Init.CodeType));
FormStatus(false);
cmbCameraList.DataSource = HDevelopExport.cameraNameList;
if (HDevelopExport.cameraNameList.Count > 0)
{
cmbCameraList.SelectedIndex = 0;
}
cmbCodeType.DataSource = HDevelopExport.codeTypeList;
if (HDevelopExport.codeTypeList.Count > 0)
{
cmbCodeType.SelectedIndex = 0;
}
else
{
cmbCodeType.Items.Add("QR Code");
cmbCodeType.SelectedIndex = 0;
}
string filePath = path + cmbCodeType.Text + ".dcm";
txtParamPath.Text = filePath;
cmbCount.SelectedIndex = 0;
timer1.Start();
}
private void FrmCamera_FormClosed(object sender, FormClosedEventArgs e)
{
if (btnStop.Enabled.Equals(true))
{
btnStop_Click(null, null);
LogUtil.logBox = null;
FormStatus(false);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (HDevelopCodeLearn.IsRun)
{
if (btnOpen.Enabled)
{
btnOpen.Enabled = false ;
}
}
else
{
if (btnOpen.Enabled.Equals(false))
{
btnOpen.Enabled = true;
}
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void cmbCodeType_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbCodeType.SelectedIndex >= 0)
{
string filePath = path + cmbCodeType.Text + ".dcm";
txtParamPath.Text = filePath;
}
}
private void btnClearLog_Click(object sender, EventArgs e)
{
LogUtil.ClearLog();
}
}
}
<?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>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
</root>
\ No newline at end of file
......@@ -136,6 +136,7 @@
this.停止ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.复位ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.回待机点ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.退出ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.iO状态查看ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.查看IOToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.料仓运转ONToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
......@@ -160,7 +161,7 @@
this.显示ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.退出ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.摄像机调试ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.groupBox5.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
......@@ -1608,31 +1609,38 @@
// 启动ToolStripMenuItem
//
this.启动ToolStripMenuItem.Name = "启动ToolStripMenuItem";
this.启动ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.启动ToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
this.启动ToolStripMenuItem.Text = "启动";
this.启动ToolStripMenuItem.Click += new System.EventHandler(this.启动ToolStripMenuItem_Click);
//
// 停止ToolStripMenuItem
//
this.停止ToolStripMenuItem.Name = "停止ToolStripMenuItem";
this.停止ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.停止ToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
this.停止ToolStripMenuItem.Text = "停止";
this.停止ToolStripMenuItem.Click += new System.EventHandler(this.停止ToolStripMenuItem_Click);
//
// 复位ToolStripMenuItem
//
this.复位ToolStripMenuItem.Name = "复位ToolStripMenuItem";
this.复位ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.复位ToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
this.复位ToolStripMenuItem.Text = "复位";
this.复位ToolStripMenuItem.Click += new System.EventHandler(this.复位ToolStripMenuItem_Click);
//
// 回待机点ToolStripMenuItem
//
this.回待机点ToolStripMenuItem.Name = "回待机点ToolStripMenuItem";
this.回待机点ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.回待机点ToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
this.回待机点ToolStripMenuItem.Text = "回待机点";
this.回待机点ToolStripMenuItem.Click += new System.EventHandler(this.回待机点ToolStripMenuItem_Click);
//
// 退出ToolStripMenuItem
//
this.退出ToolStripMenuItem.Name = "退出ToolStripMenuItem";
this.退出ToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
this.退出ToolStripMenuItem.Text = "退出系统";
this.退出ToolStripMenuItem.Click += new System.EventHandler(this.退出ToolStripMenuItem_Click);
//
// iO状态查看ToolStripMenuItem
//
this.iO状态查看ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
......@@ -1648,35 +1656,35 @@
// 查看IOToolStripMenuItem
//
this.查看IOToolStripMenuItem.Name = "查看IOToolStripMenuItem";
this.查看IOToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
this.查看IOToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.查看IOToolStripMenuItem.Text = "查看IO";
this.查看IOToolStripMenuItem.Click += new System.EventHandler(this.查看IOToolStripMenuItem_Click);
//
// 料仓运转ONToolStripMenuItem
//
this.料仓运转ONToolStripMenuItem.Name = "料仓运转ONToolStripMenuItem";
this.料仓运转ONToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
this.料仓运转ONToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.料仓运转ONToolStripMenuItem.Text = "料仓运转ON";
this.料仓运转ONToolStripMenuItem.Click += new System.EventHandler(this.料仓运转ONToolStripMenuItem_Click);
//
// 料仓运转OFFToolStripMenuItem
//
this.料仓运转OFFToolStripMenuItem.Name = "料仓运转OFFToolStripMenuItem";
this.料仓运转OFFToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
this.料仓运转OFFToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.料仓运转OFFToolStripMenuItem.Text = "料仓运转OFF";
this.料仓运转OFFToolStripMenuItem.Click += new System.EventHandler(this.料仓运转OFFToolStripMenuItem_Click);
//
// 打开舱门ToolStripMenuItem
//
this.打开舱门ToolStripMenuItem.Name = "打开舱门ToolStripMenuItem";
this.打开舱门ToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
this.打开舱门ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.打开舱门ToolStripMenuItem.Text = "打开仓门";
this.打开舱门ToolStripMenuItem.Click += new System.EventHandler(this.打开舱门ToolStripMenuItem_Click);
//
// 关闭仓门ToolStripMenuItem
//
this.关闭仓门ToolStripMenuItem.Name = "关闭仓门ToolStripMenuItem";
this.关闭仓门ToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
this.关闭仓门ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.关闭仓门ToolStripMenuItem.Text = "关闭仓门";
this.关闭仓门ToolStripMenuItem.Click += new System.EventHandler(this.关闭仓门ToolStripMenuItem_Click);
//
......@@ -1684,7 +1692,8 @@
//
this.设备调试ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.轴卡点动ToolStripMenuItem,
this.扫码测试ToolStripMenuItem});
this.扫码测试ToolStripMenuItem,
this.摄像机调试ToolStripMenuItem});
this.设备调试ToolStripMenuItem.Name = "设备调试ToolStripMenuItem";
this.设备调试ToolStripMenuItem.Size = new System.Drawing.Size(68, 21);
this.设备调试ToolStripMenuItem.Text = "设备调试";
......@@ -1692,14 +1701,14 @@
// 轴卡点动ToolStripMenuItem
//
this.轴卡点动ToolStripMenuItem.Name = "轴卡点动ToolStripMenuItem";
this.轴卡点动ToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
this.轴卡点动ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.轴卡点动ToolStripMenuItem.Text = "轴卡点动";
this.轴卡点动ToolStripMenuItem.Click += new System.EventHandler(this.轴卡点动ToolStripMenuItem_Click);
//
// 扫码测试ToolStripMenuItem
//
this.扫码测试ToolStripMenuItem.Name = "扫码测试ToolStripMenuItem";
this.扫码测试ToolStripMenuItem.Size = new System.Drawing.Size(124, 22);
this.扫码测试ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.扫码测试ToolStripMenuItem.Text = "扫码测试";
this.扫码测试ToolStripMenuItem.Click += new System.EventHandler(this.扫码测试ToolStripMenuItem_Click);
//
......@@ -1715,7 +1724,7 @@
// 轴运动配置ToolStripMenuItem
//
this.轴运动配置ToolStripMenuItem.Name = "轴运动配置ToolStripMenuItem";
this.轴运动配置ToolStripMenuItem.Size = new System.Drawing.Size(136, 22);
this.轴运动配置ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.轴运动配置ToolStripMenuItem.Text = "轴运动配置";
this.轴运动配置ToolStripMenuItem.Click += new System.EventHandler(this.轴运动配置ToolStripMenuItem_Click);
//
......@@ -1841,12 +1850,12 @@
this.notifyIcon1.Text = "料仓客户端";
this.notifyIcon1.Visible = true;
//
// 退出ToolStripMenuItem
// 摄像机调试ToolStripMenuItem
//
this.退出ToolStripMenuItem.Name = "退出ToolStripMenuItem";
this.退出ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.退出ToolStripMenuItem.Text = "退出系统";
this.退出ToolStripMenuItem.Click += new System.EventHandler(this.退出ToolStripMenuItem_Click);
this.摄像机调试ToolStripMenuItem.Name = "摄像机调试ToolStripMenuItem";
this.摄像机调试ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.摄像机调试ToolStripMenuItem.Text = "摄像机调试";
this.摄像机调试ToolStripMenuItem.Click += new System.EventHandler(this.摄像机调试ToolStripMenuItem_Click);
//
// FrmStoreBox
//
......@@ -2026,6 +2035,7 @@
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ToolStripMenuItem 退出ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem 摄像机调试ToolStripMenuItem;
}
}
......@@ -150,6 +150,7 @@ namespace OnlineStore.ACSingleStore
private DateTime preReadModblsTime = DateTime.Now;
private void timer1_Tick(object sender, EventArgs e)
{
//HumitureServer.RandomData(store.Config.GetTempAddrList());
lblTemp.Text = store.currTempStr;
//验证运动是否完成
//CheckWait();
......@@ -862,7 +863,7 @@ namespace OnlineStore.ACSingleStore
private void btnClearLog_Click(object sender, EventArgs e)
{
//this.richTextBox1.Text = "";
LogUtil.ClearLogBoxText();
LogUtil.ClearLog();
}
private void btnRelMove_Click(object sender, EventArgs e)
......@@ -881,11 +882,16 @@ namespace OnlineStore.ACSingleStore
private void 扫码测试ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!store.scanSocket.isScannerRun)
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
string message = "";
List<string> codeList = HDevelopExport.CameraScan();
foreach (string str in codeList)
{
store.scanSocket.ConnectScanner(store.Config.Scanner_Ip,store.Config.Scanner_Port);
string code = HDevelopExport.SubStrCode(str);
message = message + code + "##";
}
store.scanSocket.BeginScannering();
LogUtil.info("扫码测试收到二维码:" + message);
store.KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
}
private void 打开舱门ToolStripMenuItem_Click(object sender, EventArgs e)
......@@ -1164,5 +1170,11 @@ namespace OnlineStore.ACSingleStore
ExitApp();
}
}
private void 摄像机调试ToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmCamera frm = new FrmCamera(store);
frm.ShowDialog();
}
}
}
1.出库到入料口后,出库之后等待10秒钟如果不拿走,自动扫码
2.添加开机自动启动的功能
20180815
修改内容:1.改为balser相机扫码,去掉datalogic扫码
2.增加摄像机调试界面
3.温湿度改为随机数据,温度24.5-25.5,湿度5.6-9.8
4.修改checkwait方法,判断轴是否运动到位时,如果位置到达 不管状态是否忙碌直接认为已到达
\ No newline at end of file
......@@ -77,5 +77,19 @@ namespace OnlineStore.Common
}
return wStr;
}
public static string GetSpanStr(TimeSpan span)
{
//return Convert.ToDateTime(span.ToString()).ToString("HH:mm:ss");
string seconds = Math.Round(span.TotalSeconds % 60, 1).ToString();
if (seconds.IndexOf(".") >= 0)
{
seconds = seconds.ToString().PadLeft(4, '0');
}
else
{
seconds = seconds.ToString().PadLeft(2, '0');
}
return span.Hours.ToString().PadLeft(2, '0') + ":" + span.Minutes.ToString().PadLeft(2, '0') + ":" + seconds;
}
}
}
......@@ -171,6 +171,7 @@ namespace OnlineStore.Common
TemperateParamMap.Remove(IP);
}
TemperateParamMap.Add(IP, ast);
//LogUtil.info(LOGGER, "address=" + IP + ",收到:温度=" + newWenDu + ",湿度=" + newShiDu + " ");
}
}catch(Exception ex)
{
......@@ -179,24 +180,32 @@ namespace OnlineStore.Common
}
public static double GetRandomWD()
{
Random rd = new Random((int)DateTime.Now.Ticks+99);
Random rd = new Random((int)DateTime.Now.Ticks + 99);
int num = rd.Next(-20, 20);
double newWendu = PreWenDu + (double)num / 1000F;
double newWendu = Math.Round(PreWenDu + (double)num / 1000F, 3);
if (newWendu > 25.5 || newWendu < 24.5)
{
newWendu = PreWenDu;
}
else
{
PreWenDu = newWendu;
}
return newWendu;
}
public static double GetRandomSD()
{
Random rd = new Random((int)DateTime.Now.Ticks);
int num = rd.Next(-20, 20);
double newShiDu = PreShiDu + (double)num / 1000F;
if (newShiDu > 9|| newShiDu < 6)
int num = rd.Next(-100, 100);
double newShiDu = Math.Round(PreShiDu + (double)num / 1000F, 3);
if (newShiDu > 9.8 || newShiDu < 5.6)
{
newShiDu = PreShiDu;
}
else
{
PreShiDu = newShiDu;
}
return newShiDu;
}
}
......
......@@ -157,12 +157,7 @@ namespace OnlineStore.Common
error( LOGGER,errorMsg);
}
public static void info(string msg)
{
info(LOGGER,msg );
}
public static void ClearLogBoxText()
public static void ClearLog()
{
if (logBox != null)
{
......@@ -170,5 +165,11 @@ namespace OnlineStore.Common
count = 0;
}
}
public static void info(string msg)
{
info(LOGGER,msg );
}
}
}
......@@ -56,6 +56,7 @@
<Compile Include="acSingleStore\AC_SA_BoxBean.cs" />
<Compile Include="acSingleStore\AC_SA_BoxBean_Partial.cs" />
<Compile Include="acSingleStore\ACStoreManager.cs" />
<Compile Include="halcon\HDevelopCodeLearn.cs" />
<Compile Include="halcon\HDevelopExport.cs" />
<Compile Include="KangNaiDe\KNDManager.cs" />
<Compile Include="KangNaiDe\MasterTcpClient.cs" />
......
......@@ -238,11 +238,14 @@ namespace OnlineStore.DeviceLibrary
#endregion
#region 入库
private DateTime startInStoreTime = DateTime.Now;
/// <summary>
/// 开始入库移动移动
/// </summary>
public void StartInStoreMove(InOutStoreParam param, bool isNeedCheckIO)
{
startInStoreTime = DateTime.Now;
string posId = param != null ? param.PositionNum : "";
if (storeRunStatus == StoreRunStatus.Runing)
{
......@@ -380,7 +383,7 @@ namespace OnlineStore.DeviceLibrary
{
//ShuoKeControls.AbsMove(Config.CompressAxis_Slv, moveP.ComPress_P2);
//StoreMove.WaitList.Add(WaitResultInfo.WaitShuoKe(Config.CompressAxis_Slv, moveP.ComPress_P2, false));
System.Threading.Thread.Sleep(600);
//System.Threading.Thread.Sleep(600);
}
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P7, Config.UpDownAxis_P7_Speed);
......@@ -486,8 +489,9 @@ namespace OnlineStore.DeviceLibrary
}
else if (StoreMove.MoveStep == StoreMoveStep.SI_14_GoBack)
{
TimeSpan span = DateTime.Now - startInStoreTime;
string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
LogUtil.info(LOGGER, StoreName + " 【" + posId + "】 整个入库流程结束!", storeMoveColor);
LogUtil.info(LOGGER, StoreName + " 【" + posId + "】 整个入库流程结束,耗时【" + FormUtil.GetSpanStr(span) + "】!", storeMoveColor);
StoreMove.EndMove();
storeRunStatus = StoreRunStatus.Runing;
//设备连接,入库后,BOX恢复原始状态
......@@ -506,11 +510,13 @@ namespace OnlineStore.DeviceLibrary
#region 出库
private DateTime startOutStoreTime = DateTime.Now;
/// <summary>
/// 开始出库运动
/// </summary>
public override void StartOutStoreMove(InOutStoreParam param)
{
startOutStoreTime = DateTime.Now;
string posId = param != null ? param.PositionNum : "";
if (storeRunStatus == StoreRunStatus.Runing)
{
......@@ -686,16 +692,17 @@ namespace OnlineStore.DeviceLibrary
{
StoreMove.NextMoveStep(StoreMoveStep.SO_14_WaitTake);
OutStoreLog("出库:SO_14_WaitTake 等待拿走物品,最多等待10秒");
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Door,IO_VALUE.LOW ));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Door, IO_VALUE.LOW));
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(10000));
StoreMove.OneWaitCanEndStep = true;
}
else if (StoreMove.MoveStep == StoreMoveStep.SO_14_WaitTake)
{
TimeSpan span = DateTime.Now - startOutStoreTime;
string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
storeStatus = StoreStatus.StoreOnline;
LogUtil.info(LOGGER, StoreName + " 【" + posId + "】 整个出库流程结束!", storeMoveColor);
LogUtil.info(LOGGER, StoreName + " 【" + posId + "】 整个出库流程结束,耗时【" + FormUtil.GetSpanStr(span) + "】!", storeMoveColor);
StoreMove.EndMove();
storeRunStatus = StoreRunStatus.Runing;
InOutEndProcess(StoreMoveType.OutStore);
......
using HalconDotNet;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace OnlineStore.DeviceLibrary
{
public class HDevelopCodeLearn
{
public static HWindow hv_ExpDefaultWinHandle;
public static HTuple hv_AcqHandle = null;
public static void HDevelopStop()
{
//MessageBox.Show("Press button to continue", "Program stop");
}
public static void InitHalcon()
{
// Default settings used in HDevelop
HOperatorSet.SetSystem("width", 512);
HOperatorSet.SetSystem("height", 512);
}
public static void RunHalcon(HWindow Window, string camerName, string codeType, string paramPath, int codeCount)
{
InitHalcon();
hv_ExpDefaultWinHandle = Window;
action(camerName, codeType, paramPath, codeCount);
}
private static bool OpenCamera(string cameraName)
{
try
{ //[1] HD USB Camera
//HOperatorSet.OpenFramegrabber("GigEVision", 0, 0, 0, 0, 0, 0, "default", -1,
// "default", -1, "false", "default", cameraName, 0, -1, out hv_AcqHandle);
HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb",
-1, "false", "default", "[1] HD USB Camera", 0, -1, out hv_AcqHandle);
return true;
}
catch (Exception ex)
{
LogUtil.error("打开摄像机失败:" + ex.ToString() + ",调用关闭摄像头");
CloseCamera(cameraName);
return false;
}
}
private static void CloseCamera(string cameraName)
{
try
{
HOperatorSet.CloseFramegrabber(hv_AcqHandle);
hv_AcqHandle = null;
}
catch (Exception ex)
{
LogUtil.error("关闭摄像机失败:" + ex.ToString());
}
}
public static bool IsRun = false;
// Main procedure
private static bool action(string cameraName, string codeType, string paramPath, int codeCount)
{
IsRun = true;
IsLearnEnd = false;
IsTestEnd = false;
try
{
HTuple hv_code_type = codeType;
HTuple hv_model_path = paramPath;
HObject ho_Image = null, ho_SymbolXLDs = null;
HTuple hv_train_first = null, /*hv_AcqHandle = null,*/ hv_DataCodeHandle = null;
HTuple hv_ResultHandles = new HTuple(), hv_DecodedDataStrings = new HTuple();
HTuple hv_GenParamNames = new HTuple(), hv_ModelBeforeTraining = new HTuple();
// Initialize local and output iconic variables
HOperatorSet.GenEmptyObj(out ho_Image);
HOperatorSet.GenEmptyObj(out ho_SymbolXLDs);
//Image Acquisition 04: Code generated by Image Acquisition 04
//Image Acquisition 01: Code generated by Image Acquisition 01
//hv_code_type = "Data Matrix ECC 200";
//hv_model_path = ("E:/BaiduNetdiskDownload/" + hv_code_type) + ".dcm";
hv_train_first = 1;
if (!OpenCamera(cameraName))
{
return false ;
}
//HOperatorSet.GrabImageStart(hv_AcqHandle, -1);
HOperatorSet.CreateDataCode2dModel(hv_code_type, new HTuple(), new HTuple(),
out hv_DataCodeHandle);
//set_data_code_2d_param (DataCodeHandle, 'strict_model', 'yes')
//set_data_code_2d_param (DataCodeHandle, 'persistence', 0)
//set_data_code_2d_param (DataCodeHandle, 'polarity', 'light_on_dark')
List<string> findCode = new List<string>();
if ((int)(hv_train_first) != 0)
{
while (findCode.Count < codeCount&&IsLearnEnd.Equals(false ))
{
ho_Image.Dispose();
HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);
//Image Acquisition 04: Do something
//write_image (Image, 'jpeg', 0, 'E:/BaiduNetdiskDownload/fuba2.jpg')
if (ho_Image != null)
{
ho_SymbolXLDs.Dispose();
HOperatorSet.FindDataCode2d(ho_Image, out ho_SymbolXLDs, hv_DataCodeHandle,
"train", "all", out hv_ResultHandles, out hv_DecodedDataStrings);
if ((int)(new HTuple((new HTuple(hv_DecodedDataStrings.TupleLength())).TupleNotEqual(
0))) != 0)
{
HOperatorSet.QueryDataCode2dParams(hv_DataCodeHandle, "get_model_params",
out hv_GenParamNames);
HOperatorSet.GetDataCode2dParam(hv_DataCodeHandle, hv_GenParamNames, out hv_ModelBeforeTraining);
HDevelopStop();
string[] resultList = hv_DecodedDataStrings.SArr;
foreach (string str in resultList)
{
if (!findCode.Contains(str))
{
LogUtil.info("["+cameraName + "][" + codeType + "]学习【" + str+"】");
findCode.Add(str);
}
}
}
ShowImage(ho_Image,ho_SymbolXLDs);
}
Thread.Sleep(500);
}
//*参数写入文件
LogUtil.info("["+cameraName + "][" + codeType + "]保存参数到文件【" + paramPath+"】");
HOperatorSet.WriteDataCode2dModel(hv_DataCodeHandle, hv_model_path);
HOperatorSet.ClearDataCode2dModel(hv_DataCodeHandle);
}
//Read the previously saved data code model
findCode = new List<string>();
HOperatorSet.ReadDataCode2dModel(hv_model_path, out hv_DataCodeHandle);
while (findCode.Count < codeCount&&IsTestEnd.Equals(false ))
{
ho_Image.Dispose();
HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);
//Image Acquisition 04: Do something
//write_image (Image, 'jpeg', 0, 'E:/BaiduNetdiskDownload/fuba2.jpg')
if (ho_Image != null)
{
ho_SymbolXLDs.Dispose();
HOperatorSet.FindDataCode2d(ho_Image, out ho_SymbolXLDs, hv_DataCodeHandle,
"stop_after_result_num", 5, out hv_ResultHandles, out hv_DecodedDataStrings);
ShowImage(ho_Image,ho_SymbolXLDs);
if ((int)(new HTuple((new HTuple(hv_DecodedDataStrings.TupleLength())).TupleNotEqual(
0))) != 0)
{
string[] resultList = hv_DecodedDataStrings.SArr;
foreach (string str in resultList)
{
if (!findCode.Contains(str))
{
findCode.Add(str);
LogUtil.info("[" + cameraName + "][" + codeType + "]检测到【" + str + "】");
}
}
}
}
Thread.Sleep(500);
}
HOperatorSet.ClearDataCode2dModel(hv_DataCodeHandle);
CloseCamera(cameraName);
ho_Image.Dispose();
ho_SymbolXLDs.Dispose();
IsRun = false;
return true;
}catch(Exception ex)
{
LogUtil.error("出错了:" + ex.ToString());
CloseCamera(cameraName);
IsRun = false;
return false;
}
}
public static bool IsTestEnd = false;
public static bool IsLearnEnd = false;
public static void StopLearn()
{
IsTestEnd = true;
IsLearnEnd = true;
}
private static int dWidth = 0;
private static int dHeight = 0;
private static void ShowImage(HObject ho_Image,HObject ho_SymbolXLDs)
{
if (dWidth <= 0)
{
HTuple width, height;
//int dWidth = 0; int dHeight = 0;
HOperatorSet.GetImageSize(ho_Image, out width, out height);
dWidth = (int)width.D;
dHeight = (int)height.D;
hv_ExpDefaultWinHandle.SetPart(0, 0, dHeight, dWidth);
}
HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);
HOperatorSet.DispObj(ho_SymbolXLDs, hv_ExpDefaultWinHandle);
}
}
}
......@@ -10,6 +10,7 @@ using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary
{
public class HDevelopExport
{
/// <summary>
......@@ -20,20 +21,24 @@ namespace OnlineStore.DeviceLibrary
public static List<string> codeTypeList = new List<string>();
private static char spiltChar = '#';
public static void LoadConfig()
/// <summary>
/// 初始化摄像机名称和二维码类型
/// </summary>
/// <param name="nameStr">摄像机名称,多个用#分割</param>
/// <param name="codeStr">二维码类型,多个用#分割</param>
public static void LoadConfig(string nameStr, string codeStr)
{
cameraNameList = new List<string>();
codeTypeList = new List<string>();
try
{
string nameStr = ConfigAppSettings.GetValue(Setting_Init.CameraName);
string[] nameArray = nameStr.Split(spiltChar);
foreach (string str in nameArray)
{
LogUtil.info("加载到摄像机名称:" + str.Trim());
cameraNameList.Add(str.Trim());
}
string codeStr = ConfigAppSettings.GetValue(Setting_Init.CodeType);
string[] codeArray = codeStr.Split(spiltChar);
foreach (string str in codeArray)
{
......@@ -47,44 +52,55 @@ namespace OnlineStore.DeviceLibrary
LogUtil.error("解析摄像机配置出错:" + ex.ToString());
}
}
public static List<string> GetCode(HObject ho_Image)
/// <summary>
/// 扫取二维码,会打开摄像机,正常情况下不关闭摄像机
/// </summary>
/// <returns></returns>
public static List<string> CameraScan()
{
return GetCode(ho_Image, 0);
}
public static List<string> GetCode(HObject ho_Image, string symbolType, int cameraIndex)
List<string> allCodeList = new List<string>();
try
{
List<string> list = new List<string>();
string[] array = GetQrCode(ho_Image, symbolType, cameraIndex);
if (array != null)
//HDevelopExport.CloseAllCamera();
//打开所有摄像机
HDevelopExport.OpenAllCamera();
foreach (string cameraName in HDevelopExport.cameraNameList)
{
list.AddRange(array);
HObject ho_Image = HDevelopExport.GrabImage(cameraName);
List<string> codeList = HDevelopExport.GetCode(ho_Image);
allCodeList.AddRange(codeList);
}
return list;
}
public static void GetCode(object param)
{
IList<object> paramList = (IList<object>)param;
if (paramList.Count == 3)
catch (Exception ex)
{
HObject ho_Image = (HObject)paramList[0];
int cameraIndex = (int)paramList[1];
string camerName = (string)paramList[2];
List<string> codeArray = HDevelopExport.GetCode(ho_Image, cameraIndex);
LogUtil.debug("扫码中:结束摄像机[" + camerName + "] 的识别 ");
AC_SA_BoxBean.codeMap.Add(camerName, codeArray);
LogUtil.error("从摄像机获取二维码出错:" + ex.ToString());
LogUtil.error("关闭摄像机");
HDevelopExport.CloseAllCamera();
}
else
return allCodeList;
}
public static List<string> GetCode(HObject ho_Image, string symbolType)
{
List<string> list = new List<string>();
string[] array = GetQrCode(ho_Image, symbolType);
if (array != null)
{
LogUtil.error("GetCode参数错误:" + param);
list.AddRange(array);
}
return list;
}
public static List<string> GetCode(HObject ho_Image, int cameraIndex)
public static List<string> GetCode(HObject ho_Image)
{
List<string> list = new List<string>();
foreach (string codeType in codeTypeList)
{
string[] array = GetQrCode(ho_Image, codeType, cameraIndex);
string[] array = GetQrCode(ho_Image, codeType);
if (array != null)
{
list.AddRange(array);
......@@ -96,8 +112,8 @@ namespace OnlineStore.DeviceLibrary
public static string GetCodeParamFilePath(string codePath)
{
string appPath = Application.StartupPath;
string path = appPath+ ConfigAppSettings.GetValue(Setting_Init.CodeParamPath);
string filePath= path + codePath + ".dcm";
string path = appPath + ConfigAppSettings.GetValue(Setting_Init.CodeParamPath);
string filePath = path + codePath + ".dcm";
if (File.Exists(filePath))
{
return filePath;
......@@ -109,7 +125,7 @@ namespace OnlineStore.DeviceLibrary
}
// Procedures
//private static HTuple hv_DataCodeHandle = null;
private static string[] GetQrCode(HObject ho_Image, string symbolType, int cameraIndex)
private static string[] GetQrCode(HObject ho_Image, string symbolType)
{
try
{
......@@ -180,7 +196,7 @@ namespace OnlineStore.DeviceLibrary
{
int x = (int)Math.Round(hv_Column.DArr[i]);
int y = (int)Math.Round(hv_Row1.DArr[i]);
string str = "=" + cameraIndex + "+" + x + "x" + y + "=" + hv_DecodedDataStrings.SArr[i];
string str = "=" + x + "x" + y + "=" + hv_DecodedDataStrings.SArr[i];
hv_DecodedDataStrings[i] = str;
}
catch (Exception ex)
......@@ -212,6 +228,19 @@ namespace OnlineStore.DeviceLibrary
CloseCamera(camera);
}
}
/// <summary>
/// 截取二维码,不需要位置
/// </summary>
public static string SubStrCode(string str)
{
string[] array = str.Split('=');
if (array.Length >= 3)
{
return array[2];
}
return "";
}
public static void OpenCamera(string cameraAddr)
{
try
......@@ -220,7 +249,8 @@ namespace OnlineStore.DeviceLibrary
HTuple hv_AcqHandle = null;
if (cameraHtuple.ContainsKey(cameraAddr))
{
CloseCamera(cameraAddr);
return;
//CloseCamera(cameraAddr);
}
// HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb",
//-1, "false", "default", "[0] Integrated Camera", 0, -1, out hv_AcqHandle);
......@@ -230,15 +260,14 @@ namespace OnlineStore.DeviceLibrary
-1, out hv_AcqHandle);
//003053242c50_Basler_acA250014gm
HOperatorSet.GrabImageStart(hv_AcqHandle, -1);
//HOperatorSet.GrabImageStart(hv_AcqHandle, -1);
cameraHtuple.Add(cameraAddr, hv_AcqHandle);
// IsOpen = true;
}
catch (Exception ex)
{
LogUtil.error("打开摄像机失败:" + ex.ToString()+",调用关闭摄像头");
LogUtil.error("打开摄像机失败:" + ex.ToString() + ",调用关闭摄像头");
CloseCamera(cameraAddr);
}
}
......@@ -268,13 +297,21 @@ namespace OnlineStore.DeviceLibrary
public static HObject GrabImage(string cameraStr)
{
HObject ho_Image = null;
try
{
if (cameraHtuple.ContainsKey(cameraStr))
{
HTuple hv_AcqHandle = cameraHtuple[cameraStr];
HOperatorSet.GenEmptyObj(out ho_Image);
ho_Image.Dispose();
// HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle,-1);
HOperatorSet.GrabImage(out ho_Image, hv_AcqHandle);
}
}
catch (Exception ex)
{
LogUtil.error("获取摄像机【" + cameraStr + "】的图片出错:" + ex.ToString());
}
return ho_Image;
}
......
......@@ -278,10 +278,10 @@ namespace OnlineStore.DeviceLibrary
bool isOk = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0);
if (isOk)
{
int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo);
int errorCount = Math.Abs(outCount - targetPosition);
if (isOk)
{
if (errorCount > moveAxis.CanErrorCountMax)
{
//判断是否需要重新运动
......@@ -307,12 +307,12 @@ namespace OnlineStore.DeviceLibrary
return true;
}
}
//else if (errorCount < moveAxis.CanErrorCountMin)
//{
// LogUtil.info(LOGGER, " storeMoveStep=" + StoreMove.MoveStep + moveAxis.DisplayStr + ",targetPosition=" + targetPosition + ",当前outCount=" + outCount +
// ",误差值小于最小误差【" + moveAxis.CanErrorCountMin + "】,默认轴已经停止运动");
// return true;
//}
else if (errorCount < moveAxis.CanErrorCountMin)
{
LogUtil.info(LOGGER, " storeMoveStep=" + StoreMove.MoveStep + moveAxis.DisplayStr + ",targetPosition=" + targetPosition + ",当前outCount=" + outCount +
",误差值小于最小误差【" + moveAxis.CanErrorCountMin + "】,默认轴已经停止运动");
return true;
}
return false;
}
protected bool ACHomeMoveIsEnd(ConfigMoveAxis moveAxis,out string msg)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!