Commit 70114bfb 几米阳光

调试修改

1 个父辈 941dda78
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
this.txtParamPath = new System.Windows.Forms.TextBox(); this.txtParamPath = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label();
this.btnLight = new System.Windows.Forms.Button(); this.btnLight = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
...@@ -353,11 +354,24 @@ ...@@ -353,11 +354,24 @@
this.btnLight.Visible = false; this.btnLight.Visible = false;
this.btnLight.Click += new System.EventHandler(this.btnLigth_Click); this.btnLight.Click += new System.EventHandler(this.btnLigth_Click);
// //
// button1
//
this.button1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button1.Location = new System.Drawing.Point(723, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(167, 33);
this.button1.TabIndex = 29;
this.button1.Text = "循环测试";
this.button1.UseVisualStyleBackColor = true;
this.button1.Visible = false;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// FrmCodeDecode // FrmCodeDecode
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1192, 729); this.ClientSize = new System.Drawing.Size(1192, 729);
this.Controls.Add(this.button1);
this.Controls.Add(this.txtParamPath); this.Controls.Add(this.txtParamPath);
this.Controls.Add(this.label4); this.Controls.Add(this.label4);
this.Controls.Add(this.chbUseParam); this.Controls.Add(this.chbUseParam);
...@@ -422,6 +436,7 @@ ...@@ -422,6 +436,7 @@
private System.Windows.Forms.TextBox txtParamPath; private System.Windows.Forms.TextBox txtParamPath;
private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button btnLight; private System.Windows.Forms.Button btnLight;
private System.Windows.Forms.Button button1;
} }
} }
...@@ -34,7 +34,7 @@ namespace CodeLibrary ...@@ -34,7 +34,7 @@ namespace CodeLibrary
private string sureDelete = CodeResourceControl.GetString(CodeResourceControl.sureDelete, "确定删除文件:"); private string sureDelete = CodeResourceControl.GetString(CodeResourceControl.sureDelete, "确定删除文件:");
private void FrmMain_Load(object sender, EventArgs e) private void FrmMain_Load(object sender, EventArgs e)
{ {
Control.CheckForIllegalCrossThreadCalls = false;
cmbCount.SelectedIndex = 0; cmbCount.SelectedIndex = 0;
LoadCamera(); LoadCamera();
...@@ -134,7 +134,7 @@ namespace CodeLibrary ...@@ -134,7 +134,7 @@ namespace CodeLibrary
} }
private void btnbarCode_Click(object sender, EventArgs e) private void btnbarCode_Click(object sender, EventArgs e)
{ {
if (pictureBox1.Image == null ) if (pictureBox1.Image == null )
{ {
MessageBox.Show(selImage ,title, MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(selImage ,title, MessageBoxButtons.OK, MessageBoxIcon.Error);
...@@ -284,5 +284,69 @@ namespace CodeLibrary ...@@ -284,5 +284,69 @@ namespace CodeLibrary
txtParamPath.Text = HDCodeHelper.GetCodeParamFilePath(cmbCodeType.Text); txtParamPath.Text = HDCodeHelper.GetCodeParamFilePath(cmbCodeType.Text);
} }
} }
private System.Timers.Timer testTimer = new System.Timers.Timer();
private int testCount = 0;
private void button1_Click(object sender, EventArgs e)
{
if (testTimer.Enabled)
{
HDLogUtil.info("停止扫码测试");
testTimer.Stop();
}
else
{
HDLogUtil.info("开始扫码测试");
testCount = 0;
testTimer.Interval = 1000;
testTimer.Elapsed += TestTimer_Elapsed;
testTimer.AutoReset = true;
testTimer.Start();
}
}
private void TestTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try {
if (pictureBox1.Image == null)
{
return;
}
int count = cmbCount.SelectedIndex + 1;
txtResult.Text = "";
stopwatch.Restart();
testCount++;
Bitmap map = new Bitmap(pictureBox1.Image);
HObject ho_image = HDCodeHelper.Bitmap2HObjectBpp24(map);
txtResult.Text += "\r\n elapsed time:" + stopwatch.Elapsed.ToString();
hWindowControl1.HalconWindow.SetPart(0, 0, map.Height, map.Width);
HOperatorSet.DispObj(ho_image, hWindowControl1.HalconWindow);
ShowImage(ho_image);
HDCodeHelper.HalconWindow = this.hWindowControl1.HalconWindow;
string codeParamPath = HDCodeHelper.GetCodeParamFilePath(cmbCodeType.Text);
if (chbUseParam.Checked.Equals(false))
{
codeParamPath = "";
}
List<CodeInfo> codeList = new List<CodeInfo>();
if (cmbCodeType.Text.ToLower().Equals("barcode"))
{
codeList = HDCodeHelper.DecodeBarCode(ho_image);
}
else
{
codeList = HDCodeHelper.DecodeCode(ho_image, count, codeParamPath, cmbCodeType.Text);
}
ShowCode(codeList);
txtResult.Text += "\r\n elapsed time:" + stopwatch.Elapsed.ToString();
HDLogUtil.info("第【"+testCount+"】次扫码测试结束");
}
catch(Exception ex)
{
HDLogUtil.error(ex.ToString());
}
}
} }
} }
...@@ -9,13 +9,13 @@ ...@@ -9,13 +9,13 @@
<!--是否开机自动启动料仓--> <!--是否开机自动启动料仓-->
<add key="App_AutoRun" value="0"/> <add key="App_AutoRun" value="0"/>
<!--摄像机名称列表配置,用#分割--> <!--摄像机名称列表配置,用#分割-->
<add key ="CameraName" value ="[0] Integrated Camera"/> <add key="CameraName" value="[0] Integrated Camera"/>
<!--<add key ="CameraName" value ="tsavCamera"/>--> <!--<add key ="CameraName" value ="tsavCamera"/>-->
<!--<add key ="CameraName" value ="codeCamera"/>--> <!--<add key ="CameraName" value ="codeCamera"/>-->
<!--二维码类型列表配置,用#分割--> <!--二维码类型列表配置,用#分割-->
<add key ="CodeType" value ="Data Matrix ECC 200#QR Code"/> <add key="CodeType" value="Data Matrix ECC 200#QR Code"/>
<!--二维码参数文件所在路径,文件名与二维码类型名一样--> <!--二维码参数文件所在路径,文件名与二维码类型名一样-->
<add key ="CodeParamPath" value ="\Conifg\"/> <add key="CodeParamPath" value="\Conifg\"/>
</appSettings> </appSettings>
<log4net> <log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
</root> </root>
</log4net> </log4net>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup> </startup>
</configuration> </configuration>
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using ZXing;
using ZXing.Common;
namespace CodeTest
{
public class CodeCreater
{
public static void CreateCode(int count)
{
DateTime now = DateTime.Now;
string data = now.Year.ToString() + now.Month.ToString().PadLeft(2, '0') + now.Day.ToString().PadLeft(2, '0') + now.Hour.ToString().PadLeft(2, '0');
string targetFilePath = @"D:\Code\" + data + @"\";
if (!File.Exists(targetFilePath))
{
Directory.CreateDirectory(targetFilePath);
}
for (int i = 1; i <= count; i++)
{
string name = "pn;" + i.ToString().PadLeft(6, '0') + ";1000";
Bitmap map = GetQRCodeByZXingNet(name, 200, 200);
if (map != null)
{
map.Save(targetFilePath + name + ".bmp");
}
}
}
/// <summary>
/// 生成二维码图片
/// </summary>
/// <param name="strMessage">要生成二维码的字符串</param>
/// <param name="width">二维码图片宽度</param>
/// <param name="height">二维码图片高度</param>
/// <returns></returns>
private static Bitmap GetQRCodeByZXingNet(String strMessage, Int32 width, Int32 height)
{
Bitmap result = null;
try
{
BarcodeWriter barCodeWriter = new BarcodeWriter();
barCodeWriter.Format = BarcodeFormat.QR_CODE;
barCodeWriter.Options.Hints.Add(EncodeHintType.CHARACTER_SET, "UTF-8");
barCodeWriter.Options.Hints.Add(EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H);
barCodeWriter.Options.Height = height;
barCodeWriter.Options.Width = width;
barCodeWriter.Options.Margin = 0;
ZXing.Common.BitMatrix bm = barCodeWriter.Encode(strMessage);
result = barCodeWriter.Write(bm);
}
catch (Exception ex)
{
//异常输出
}
return result;
}
//public bool DecodeQRCode(Bitmap bmp, out string text)
//{
// DecodingOptions option = new DecodingOptions();
// //option.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE, BarcodeFormat.All_1D };
// option.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE };
// BarcodeReader br = new BarcodeReader();
// br.Options = option;
// Result rs = br.Decode(bmp);
// if (rs == null)
// {
// text = "";
// return false;
// }
// else
// {
// text = rs.Text;
// return true;
// }
//}
///// <summary>
///// DataMatrix矩阵二维码
///// </summary>
///// <param name="text"></param>
///// <param name="size"></param>
///// <returns></returns>
//public static Bitmap DataMatrix(string text, int size)
//{
// if (size < 10) size = 10;
// DataMatrix.net.DmtxImageEncoderOptions opt = new DataMatrix.net.DmtxImageEncoderOptions();
// opt.ModuleSize = size;
// opt.MarginSize = 5;
// DataMatrix.net.DmtxImageEncoder encoder = new DataMatrix.net.DmtxImageEncoder();
// Bitmap bm = encoder.EncodeImage(text, opt);
// return bm;
//}
}
}
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<RootNamespace>CodeTest</RootNamespace> <RootNamespace>CodeTest</RootNamespace>
<AssemblyName>CodeTest</AssemblyName> <AssemblyName>CodeTest</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
...@@ -40,6 +40,9 @@ ...@@ -40,6 +40,9 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\dll\Basler.Pylon.dll</HintPath> <HintPath>..\dll\Basler.Pylon.dll</HintPath>
</Reference> </Reference>
<Reference Include="DataMatrix.net">
<HintPath>..\dll\DataMatrix.net.dll</HintPath>
</Reference>
<Reference Include="halcondotnet"> <Reference Include="halcondotnet">
<HintPath>..\dll\halcondotnet.dll</HintPath> <HintPath>..\dll\halcondotnet.dll</HintPath>
</Reference> </Reference>
...@@ -58,11 +61,13 @@ ...@@ -58,11 +61,13 @@
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="zxing"> <Reference Include="zxing, Version=0.14.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dll\zxing.dll</HintPath> <HintPath>..\dll\zxing.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CodeCreater.cs" />
<Compile Include="CompressHelper.cs" /> <Compile Include="CompressHelper.cs" />
<Compile Include="FrmTest.cs"> <Compile Include="FrmTest.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
......
...@@ -3,6 +3,7 @@ using Common; ...@@ -3,6 +3,7 @@ using Common;
using log4net.Config; using log4net.Config;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
...@@ -17,12 +18,13 @@ namespace CodeTest ...@@ -17,12 +18,13 @@ namespace CodeTest
[STAThread] [STAThread]
static void Main() static void Main()
{ {
CodeCreater.CreateCode(30);
Application.EnableVisualStyles(); //Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); //Application.SetCompatibleTextRenderingDefault(false);
HDCodeLearnHelper.LoadConfig(ConfigAppSettings.GetValue(Setting_Init.CameraName),ConfigAppSettings.GetValue(Setting_Init.CodeType)); //HDCodeLearnHelper.LoadConfig(ConfigAppSettings.GetValue(Setting_Init.CameraName),ConfigAppSettings.GetValue(Setting_Init.CodeType));
Application.Run(new FrmCodeDecode()); //Application.Run(new FrmCodeDecode());
//Application.Run(new FrmTest()); //Application.Run(new FrmTest());
} }
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!