Commit 7373df5f LN

增加http扫码方式

1 个父辈 cdb831d5
此文件类型无法预览
此文件类型无法预览
<?xml version="1.0" encoding="UTF-8"?>
<config ver="10">
<item key="MaxMenory" ver="10" value="8000" />
</config>
\ No newline at end of file \ No newline at end of file
此文件类型无法预览
<?xml version="1.0"?>
<doc>
<assembly>
<name>ConfigHelper</name>
</assembly>
<members>
<member name="M:ConfigHelper.Config.Get``1(System.Object,``0)">
<summary>
读取配置
</summary>
<typeparam name="T">返回类型</typeparam>
<param name="key">传入一个枚举值</param>
<param name="defaultvalue">失败默认值</param>
<returns></returns>
</member>
</members>
</doc>
此文件类型无法预览
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs/ScanCodeServer.log"/>
<param name="Encoding" value="UTF-8"/>
<appendToFile value="true"/>
<rollingStyle value="Date"/>
<datePattern value="yyyy-MM-dd"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date][%t]%-5p %m%n"/>
</layout>
</appender>
<logger name="RollingLogFileAppender">
<level value="ALL"/>
<appender-ref ref="RollingLogFileAppender"/>
</logger>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding maxReceivedMessageSize="90000000" maxBufferPoolSize="90000000" maxBufferSize="90000000" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:01:00" sendTimeout="00:01:00">
<readerQuotas maxStringContentLength="90000000" maxArrayLength="90000000" maxBytesPerRead="90000000" />
<security mode="None"/>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
\ No newline at end of file \ No newline at end of file
此文件太大,无法显示。
此文件类型无法预览
此文件类型无法预览
此文件的差异太大,无法显示。
...@@ -86,6 +86,7 @@ ...@@ -86,6 +86,7 @@
<Compile Include="deviceLibrary\AXIS\AxisManager.cs" /> <Compile Include="deviceLibrary\AXIS\AxisManager.cs" />
<Compile Include="deviceLibrary\AXIS\HC\HCAxisManager.cs" /> <Compile Include="deviceLibrary\AXIS\HC\HCAxisManager.cs" />
<Compile Include="deviceLibrary\halcon\CodeManager.cs" /> <Compile Include="deviceLibrary\halcon\CodeManager.cs" />
<Compile Include="deviceLibrary\halcon\RemoteDecodeHelper.cs" />
<Compile Include="deviceLibrary\IO\AIOBOX\AIOBOX.cs" /> <Compile Include="deviceLibrary\IO\AIOBOX\AIOBOX.cs" />
<Compile Include="deviceLibrary\IO\AIOBOX\AIOBOXManager.cs" /> <Compile Include="deviceLibrary\IO\AIOBOX\AIOBOXManager.cs" />
<Compile Include="deviceLibrary\IO\HCIOManager.cs" /> <Compile Include="deviceLibrary\IO\HCIOManager.cs" />
......
...@@ -16,7 +16,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -16,7 +16,7 @@ namespace OnlineStore.DeviceLibrary
{ {
public class CodeManager public class CodeManager
{ {
public static List<string> codeTypeList = new List<string>(); public static List<string> allCodeTypeList = new List<string>();
public static List<string> balserNameList = new List<string>(); public static List<string> balserNameList = new List<string>();
public static List<string> hikNameList = new List<string>(); public static List<string> hikNameList = new List<string>();
...@@ -27,7 +27,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -27,7 +27,7 @@ namespace OnlineStore.DeviceLibrary
public static void LoadConfig() public static void LoadConfig()
{ {
string codeStr = ConfigAppSettings.GetValue(Setting_Init.CodeType); string codeStr = ConfigAppSettings.GetValue(Setting_Init.CodeType);
codeTypeList = new List<string>(); allCodeTypeList = new List<string>();
HDLogUtil.LogName = "RollingLogFileAppender"; HDLogUtil.LogName = "RollingLogFileAppender";
try try
{ {
...@@ -39,7 +39,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -39,7 +39,7 @@ namespace OnlineStore.DeviceLibrary
continue; continue;
} }
LogUtil.info("加载到配置二维码类型:" + str.Trim()); LogUtil.info("加载到配置二维码类型:" + str.Trim());
codeTypeList.Add(str.Trim()); allCodeTypeList.Add(str.Trim());
} }
LoadCamera(false); LoadCamera(false);
...@@ -168,37 +168,39 @@ namespace OnlineStore.DeviceLibrary ...@@ -168,37 +168,39 @@ namespace OnlineStore.DeviceLibrary
{ {
if (!findRightCode) if (!findRightCode)
{ {
List<CodeInfo> cc = new List<CodeInfo>(); try
eyemNoCode = true; {
foreach (string codeType in codeTypeList) List<CodeInfo> cc = new List<CodeInfo>();
{ eyemNoCode = true;
//判断是否是一维码
if (codeType.ToLower().Equals("barcode")) RemoteDecodeHelper.RemoteDecodeParam remoteDecodeParam = new RemoteDecodeHelper.RemoteDecodeParam
{ {
cc = HDCodeHelper.DecodeBarCode(ho_Image); codeTypeList = allCodeTypeList.ToArray(),
} codeCount = 3,
//else timeout = 3000
//{ };
// cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), codeCount, timeOut); cc = RemoteDecodeHelper.DecodeRequest(ho_Image, remoteDecodeParam);
//} if (cc != null)
foreach (CodeInfo c in cc)
{ {
string str = CodeManager.ReplaceCode(c.CodeStr); foreach (CodeInfo c in cc)
if (!codeList.Contains(str))
{ {
codeList.Add(str); string str = CodeManager.ReplaceCode(c.CodeStr);
r = r + "##halcon|" + codeType + "|" + str; if (!codeList.Contains(str))
if (!findRightCode)
{ {
findRightCode = HasRightCode(str); codeList.Add(str);
r = r + "##halcon|" + c.CodeType + "|" + str;
if (!findRightCode)
{
findRightCode = HasRightCode(str);
}
} }
} }
} }
if (findRightCodeBreak && findRightCode) }
{ catch (Exception ex)
break; {
} LogUtil.error(deviceName + " RemoteDecodeHelper扫码出错:" + ex.ToString());
} }
} }
//if (!findRightCode && SaveErrorImageToFile.Equals(1)) //if (!findRightCode && SaveErrorImageToFile.Equals(1))
......
using CodeLibrary;
using HalconDotNet;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
public class RemoteDecodeHelper
{
static int webclienttimeout = 30 * 1000;
static Process p = new Process();
private static string serverhost = ConfigAppSettings.GetValue("ScanCodeServer");
public static List<CodeInfo> DecodeRequest(HObject hoimg, RemoteDecodeParam remoteDecodeParam)
{
if (serverhost.Trim().Equals(""))
{
serverhost = "http://127.0.0.1:58137/";
}
byte[] requestdata;
lock (hoimg)
{
using (MemoryStream mStream = new MemoryStream())
{
hoimg.Serialize(mStream);
requestdata = mStream.ToArray();
mStream.Close();
}
}
return DecodeRequest(requestdata, remoteDecodeParam,true);
}
public static List<CodeInfo> DecodeRequest(Bitmap bitmap, RemoteDecodeParam remoteDecodeParam)
{
byte[] requestdata;
lock (bitmap)
{
using (MemoryStream mStream = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(mStream, bitmap);
requestdata = mStream.ToArray();
mStream.Close();
}
}
return DecodeRequest(requestdata, remoteDecodeParam);
}
static List<CodeInfo> DecodeRequest(byte[] requestdata, RemoteDecodeParam remoteDecodeParam,bool isHObject=false)
{
CheckAndRunServer();
string param;
using (MemoryStream mStreamparam = new MemoryStream())
{
XmlSerializer xf = new XmlSerializer(typeof(RemoteDecodeParam));
xf.Serialize(mStreamparam, remoteDecodeParam);
param = base64UrlEncode(mStreamparam.ToArray());
mStreamparam.Close();
}
string url = serverhost+"ProcessBitmap?param=";
if (isHObject)
url = serverhost+"Process?param=";
byte[] resp;
try
{
MyWebClient webClient = new MyWebClient(webclienttimeout);
resp = webClient.UploadData(url + param, requestdata);
webClient.Dispose();
}
catch(WebException we)
{
return null;
}
catch
{
return null;
}
var ss = Encoding.UTF8.GetString(resp).Trim().Trim('"');
var bb = Convert.FromBase64String(ss);
List<CodeInfo> codeInfos;
using (MemoryStream mStreamResult = new MemoryStream(bb))
{
XmlSerializer xff = new XmlSerializer(typeof(List<CodeInfo>));
codeInfos = (List<CodeInfo>)xff.Deserialize(mStreamResult);
}
return codeInfos;
}
/// <summary>
/// 在url中传递base64字符串需要替换加号等符号
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
static string base64UrlEncode(byte[] input)
{
return Convert.ToBase64String(input).Replace('+', '-').Replace('/', '_');
}
/// <summary>
/// 检查并自动启动服务器
/// </summary>
static void CheckAndRunServer()
{
lock (p)
{
var pss = Process.GetProcessesByName("ScanCodeServer");
if (pss.Length > 0)
return;
var f = "ScanCodeServer\\ScanCodeServer.exe";
if (!File.Exists(f))
throw new Exception("找不到扫码服务器文件");
p.StartInfo = new ProcessStartInfo(f);
p.Start();
int checkcount = 5;
while (checkcount > 0)
{
checkcount--;
Thread.Sleep(500);
MyWebClient webClient = new MyWebClient(webclienttimeout);
var s = webClient.DownloadString(serverhost + "alive");
if (s.Trim() == "\"1\"")
return;
}
throw new Exception("扫码服务器打开失败");
}
}
[Serializable]
public struct RemoteDecodeParam
{
public string[] codeTypeList;
public int codeCount;
public int timeout;
}
public class MyWebClient : WebClient
{
private int _timeout;
public MyWebClient(int timeout)
{
this._timeout = timeout;
}
protected override WebRequest GetWebRequest(Uri address)
{
var result = base.GetWebRequest(address);
result.Timeout = this._timeout;
return result;
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!