Commit da61a318 张东亮

添加扫码小程序、等待报警问题处理

1 个父辈 87ff0457
...@@ -11,6 +11,7 @@ using System.Threading.Tasks; ...@@ -11,6 +11,7 @@ using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using OnlineStore.DeviceLibrary; using OnlineStore.DeviceLibrary;
using log4net.Repository.Hierarchy; using log4net.Repository.Hierarchy;
using System.IO;
namespace OnlineStore.ACPackingStore namespace OnlineStore.ACPackingStore
{ {
...@@ -99,6 +100,22 @@ namespace OnlineStore.ACPackingStore ...@@ -99,6 +100,22 @@ namespace OnlineStore.ACPackingStore
XmlConfigurator.Configure(); XmlConfigurator.Configure();
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
try
{
var pss = Process.GetProcessesByName("ScanCodeServer");
if (pss.Length > 0)
return;
var f = "ScanCodeServer\\ScanCodeServer.exe";
if (File.Exists(f))
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo(f);
p.Start();
}
}catch (Exception ex) { }
Application.Run(new FrmStore()); Application.Run(new FrmStore());
} }
} }
......
...@@ -91,6 +91,8 @@ namespace OnlineStore.Common ...@@ -91,6 +91,8 @@ namespace OnlineStore.Common
public static MyConfig<string> AgvServerIp = "172.16.77.76"; public static MyConfig<string> AgvServerIp = "172.16.77.76";
[MyConfigComment("条码数量")] [MyConfigComment("条码数量")]
public static MyConfig<int> CodeCount = 3; public static MyConfig<int> CodeCount = 3;
[MyConfigComment("扫码超时")]
public static MyConfig<int> ScanCodeTimeout = 3000;
[MyConfigComment("是否检测到料架自动入库")] [MyConfigComment("是否检测到料架自动入库")]
public static MyConfig<bool> AutoShelfInstore = true; public static MyConfig<bool> AutoShelfInstore = true;
[MyConfigComment("是否启用入料口移门")] [MyConfigComment("是否启用入料口移门")]
......
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="device\halcon\RemoteDecodeHelper.cs" />
<Compile Include="PackingStore\AC_BOX_Bean_AutoInOutTest.cs" /> <Compile Include="PackingStore\AC_BOX_Bean_AutoInOutTest.cs" />
<Compile Include="PackingStore\AC_BOX_Bean_server_connect.cs" /> <Compile Include="PackingStore\AC_BOX_Bean_server_connect.cs" />
<Compile Include="PackingStore\AC_BOX_Bean.cs" /> <Compile Include="PackingStore\AC_BOX_Bean.cs" />
......
...@@ -201,11 +201,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -201,11 +201,11 @@ namespace OnlineStore.DeviceLibrary
if (MoveInfo.MoveStep.Equals(StoreMoveStep.BS_08_WaitLineIn) || if (MoveInfo.MoveStep.Equals(StoreMoveStep.BS_08_WaitLineIn) ||
MoveInfo.MoveStep.Equals(StoreMoveStep.BI_04_WaitTakeSingle)) MoveInfo.MoveStep.Equals(StoreMoveStep.BI_04_WaitTakeSingle))
{ {
timeOutMs = 30000; timeOutMs = int.MaxValue;
} }
else if (MoveInfo.MoveStep.Equals(StoreMoveStep.BI_03_LineRun)) else if (MoveInfo.MoveStep.Equals(StoreMoveStep.BI_03_LineRun))
{ {
timeOutMs = 40000; timeOutMs = int.MaxValue;
} }
if ((!wait.IsEnd) && span.TotalMilliseconds > timeOutMs && NoAlarm()) if ((!wait.IsEnd) && span.TotalMilliseconds > timeOutMs && NoAlarm())
{ {
......
...@@ -378,7 +378,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -378,7 +378,7 @@ namespace OnlineStore.DeviceLibrary
else if (MoveInfo.MoveStep.Equals(StoreMoveStep.BS_09_WaitTime)) else if (MoveInfo.MoveStep.Equals(StoreMoveStep.BS_09_WaitTime))
{ {
MoveInfo.NextMoveStep(StoreMoveStep.BS_10_WaitAGVLeave); MoveInfo.NextMoveStep(StoreMoveStep.BS_10_WaitAGVLeave);
MoveInfo.TimeOutSeconds = 180; MoveInfo.TimeOutSeconds = 1800;
LogRunStepInfo(moveName + "等待DoorClose事件,最多等待180000 "); LogRunStepInfo(moveName + "等待DoorClose事件,最多等待180000 ");
MoveInfo.OneWaitCanEndStep = true; MoveInfo.OneWaitCanEndStep = true;
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(180000)); MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(180000));
......
...@@ -99,6 +99,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -99,6 +99,7 @@ namespace OnlineStore.DeviceLibrary
private static int ScanCount = 0; private static int ScanCount = 0;
private static int codeCount = Setting_Init.CodeCount; private static int codeCount = Setting_Init.CodeCount;
private static int codeTimeout = Setting_Init.ScanCodeTimeout;
[HandleProcessCorruptedStateExceptions] [HandleProcessCorruptedStateExceptions]
public static List<string> CameraScan(List<string> cameraList, string deviceName, int timeOut = 1500) public static List<string> CameraScan(List<string> cameraList, string deviceName, int timeOut = 1500)
{ {
...@@ -139,24 +140,22 @@ namespace OnlineStore.DeviceLibrary ...@@ -139,24 +140,22 @@ namespace OnlineStore.DeviceLibrary
LogUtil.debug(deviceName + " 【" + cameraName + "】取图片完成,开始扫码"); LogUtil.debug(deviceName + " 【" + cameraName + "】取图片完成,开始扫码");
List<CodeInfo> cc = new List<CodeInfo>(); List<CodeInfo> cc = new List<CodeInfo>();
string r = ""; string r = "";
foreach (string codeType in codeTypeList) RemoteDecodeHelper.RemoteDecodeParam remoteDecodeParam = new RemoteDecodeHelper.RemoteDecodeParam
{ {
//判断是否是一维码 codeTypeList = codeTypeList.ToArray(),
if (codeType.ToLower().Equals("barcode")) codeCount = codeCount,
timeout = codeTimeout
};
cc = RemoteDecodeHelper.DecodeRequest(ho_Image, remoteDecodeParam);
if (cc != null)
{ {
cc = HDCodeHelper.DecodeBarCode(ho_Image);
}
else
{
cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), codeCount, timeOut);
}
foreach (CodeInfo c in cc) foreach (CodeInfo c in cc)
{ {
string str = CodeManager.ReplaceCode(c.CodeStr); string str = CodeManager.ReplaceCode(c.CodeStr);
if (!codeList.Contains(str)) if (!codeList.Contains(str))
{ {
codeList.Add(str); codeList.Add(str);
r = r + "##" + str; r = r + "##remote|" + c.CodeType + "|" + str;
if (!findRightCode) if (!findRightCode)
{ {
findRightCode = HasRightCode(str); findRightCode = HasRightCode(str);
...@@ -164,6 +163,31 @@ namespace OnlineStore.DeviceLibrary ...@@ -164,6 +163,31 @@ namespace OnlineStore.DeviceLibrary
} }
} }
} }
//foreach (string codeType in codeTypeList)
//{
// //判断是否是一维码
// if (codeType.ToLower().Equals("barcode"))
// {
// cc = HDCodeHelper.DecodeBarCode(ho_Image);
// }
// else
// {
// cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), codeCount, timeOut);
// }
// foreach (CodeInfo c in cc)
// {
// string str = CodeManager.ReplaceCode(c.CodeStr);
// if (!codeList.Contains(str))
// {
// codeList.Add(str);
// r = r + "##" + str;
// if (!findRightCode)
// {
// findRightCode = HasRightCode(str);
// }
// }
// }
//}
if (!findRightCode) if (!findRightCode)
{ {
SaveImageToFile(deviceName, cameraName, ho_Image); SaveImageToFile(deviceName, cameraName, ho_Image);
......
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!