Commit 968f3309 LN

增加http扫码方式

1 个父辈 c921060c
此文件类型无法预览
此文件类型无法预览
<?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
此文件太大,无法显示。
此文件类型无法预览
此文件类型无法预览
此文件的差异太大,无法显示。
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
<Compile Include="baan\AxisBean.cs" /> <Compile Include="baan\AxisBean.cs" />
<Compile Include="baan\WaitUtil.cs" /> <Compile Include="baan\WaitUtil.cs" />
<Compile Include="deviceLibrary\halcon\CodeManager.cs" /> <Compile Include="deviceLibrary\halcon\CodeManager.cs" />
<Compile Include="deviceLibrary\halcon\RemoteDecodeHelper.cs" />
<Compile Include="deviceLibrary\IO\AIOBOX\AIOAutoConSetting.cs" /> <Compile Include="deviceLibrary\IO\AIOBOX\AIOAutoConSetting.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" />
......
...@@ -14,7 +14,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -14,7 +14,7 @@ namespace OnlineStore.DeviceLibrary
/// </summary> /// </summary>
public class OutTrayLineBean public class OutTrayLineBean
{ {
private bool NgInReverseSide = true ; private bool NgInReverseSide = true;
public int MaxPosition = 5; public int MaxPosition = 5;
private int equipBeanId = 301; private int equipBeanId = 301;
private string Line3_TrayCheck = ""; private string Line3_TrayCheck = "";
...@@ -75,14 +75,15 @@ namespace OnlineStore.DeviceLibrary ...@@ -75,14 +75,15 @@ namespace OnlineStore.DeviceLibrary
return false; return false;
} }
//MoveInfo.MoveParam = moveParam; //MoveInfo.MoveParam = moveParam;
MoveInfo.NewMove(LineMoveType.OutStore, moveParam); MoveInfo.NewMove(LineMoveType.OutStore, moveParam);
posId = "[" + moveParam.PosId + "][" + moveParam.WareCode + "][" + moveParam.rfid + "]"; posId = "[" + moveParam.PosId + "][" + moveParam.WareCode + "][" + moveParam.rfid + "]";
if (moveParam.InStoreNg) if (moveParam.InStoreNg)
{ {
posId = moveParam.rfid + "NG料" + "[" + moveParam.WareCode + "]"; posId = moveParam.rfid + "NG料" + "[" + moveParam.WareCode + "]";
}else if(moveParam.urgentReel) }
{ else if (moveParam.urgentReel)
posId = "[" + moveParam.PosId + "]紧急出料" + "[" + moveParam.WareCode + "]"; {
posId = "[" + moveParam.PosId + "]紧急出料" + "[" + moveParam.WareCode + "]";
} }
MoveInfo.NextMoveStep(LineMoveStep.DLO_01_NGBack); MoveInfo.NextMoveStep(LineMoveStep.DLO_01_NGBack);
LogUtil.info(Name + "开始送料【" + moveParam.ToStr() + "】:" + MoveInfo.SLog + "NG气缸后退"); LogUtil.info(Name + "开始送料【" + moveParam.ToStr() + "】:" + MoveInfo.SLog + "NG气缸后退");
...@@ -100,15 +101,15 @@ namespace OnlineStore.DeviceLibrary ...@@ -100,15 +101,15 @@ namespace OnlineStore.DeviceLibrary
} }
} }
else else
{ {
if (LastTrayPosition > needEmptyP) if (LastTrayPosition > needEmptyP)
{ {
WaitReviceTray(); WaitReviceTray();
} }
else else
{ {
MoveInfo.NextMoveStep(LineMoveStep.DLO_02_WaitEnteryNoTray); MoveInfo.NextMoveStep(LineMoveStep.DLO_02_WaitEnteryNoTray);
LogUtil.info(Name + "送料【" + posId + "】:" + MoveInfo.SLog + "--- 等待入口 "+ needEmptyP + " 无料-- "); LogUtil.info(Name + "送料【" + posId + "】:" + MoveInfo.SLog + "--- 等待入口 " + needEmptyP + " 无料-- ");
} }
} }
return true; return true;
...@@ -160,7 +161,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -160,7 +161,7 @@ namespace OnlineStore.DeviceLibrary
} }
else if (MoveInfo.IsTimeOut(180)) else if (MoveInfo.IsTimeOut(180))
{ {
LogUtil.error(Name + "等待入口"+ needEmptyP + "无料超时" + FormUtil.GetSpanStr(MoveInfo.StepSpan()), Id * 1000 + 33); LogUtil.error(Name + "等待入口" + needEmptyP + "无料超时" + FormUtil.GetSpanStr(MoveInfo.StepSpan()), Id * 1000 + 33);
} }
} }
...@@ -230,7 +231,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -230,7 +231,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000)); MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
} }
else if (MoveInfo.MoveParam.urgentReel|| MoveInfo.MoveParam.InStoreNg) else if (MoveInfo.MoveParam.urgentReel || MoveInfo.MoveParam.InStoreNg)
{ {
MoveInfo.NextMoveStep(LineMoveStep.DLO_08_NGBefore); MoveInfo.NextMoveStep(LineMoveStep.DLO_08_NGBefore);
LogUtil.info(Name + "送料【" + posId + "】:" + MoveInfo.SLog + "NG气缸前进"); LogUtil.info(Name + "送料【" + posId + "】:" + MoveInfo.SLog + "NG气缸前进");
...@@ -349,7 +350,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -349,7 +350,8 @@ namespace OnlineStore.DeviceLibrary
} }
} }
if (DateTime.Now <= BrushStopTime || equipBean.IOValue(LineRun_Do).Equals(IO_VALUE.HIGH)) if (DateTime.Now <= BrushStopTime)
//if (DateTime.Now <= BrushStopTime || equipBean.IOValue(LineRun_Do).Equals(IO_VALUE.HIGH))
{ {
equipBean.CheckAndMove(DLine_Brush_Do, IO_VALUE.HIGH); equipBean.CheckAndMove(DLine_Brush_Do, IO_VALUE.HIGH);
} }
......
...@@ -17,7 +17,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -17,7 +17,7 @@ namespace OnlineStore.DeviceLibrary
public class CodeManager public class CodeManager
{ {
public static bool SaveImage = false; public static bool SaveImage = false;
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>();
...@@ -28,7 +28,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -28,7 +28,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
{ {
...@@ -40,7 +40,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -40,7 +40,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);
...@@ -169,38 +169,39 @@ namespace OnlineStore.DeviceLibrary ...@@ -169,38 +169,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>();
if (codeType.ToLower().Equals("barcode")) eyemNoCode = true;
{
cc = HDCodeHelper.DecodeBarCode(ho_Image); RemoteDecodeHelper.RemoteDecodeParam remoteDecodeParam = new RemoteDecodeHelper.RemoteDecodeParam
}
else
{ {
//去掉halcon补充扫码 codeTypeList = allCodeTypeList.ToArray(),
//cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), codeCount, timeOut); codeCount = 3,
} timeout = 3000
foreach (CodeInfo c in cc) };
cc = RemoteDecodeHelper.DecodeRequest(ho_Image, remoteDecodeParam);
if (cc != null)
{ {
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!