Commit 7f9ed739 刘韬

1

1 个父辈 7b9ae5e4
......@@ -17,6 +17,7 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Description = 美光环形线
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{064BEBF5-8FAA-4EA2-A5F3-A06E6E7D9251}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
......
......@@ -50,9 +50,6 @@
<Reference Include="Fleck, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Fleck.1.2.0\lib\net45\Fleck.dll</HintPath>
</Reference>
<Reference Include="halcondotnet">
<HintPath>..\..\RC1271-DUOStore\dll\halcondotnet.dll</HintPath>
</Reference>
<Reference Include="HuichuanLibrary">
<HintPath>..\..\HuichuanLibrary\HuichuanLibrary\bin\Debug\HuichuanLibrary.dll</HintPath>
</Reference>
......
......@@ -181,136 +181,6 @@ namespace DeviceLibrary
}
[HandleProcessCorruptedStateExceptions]
public static List<CodeInfo> CameraScan(List<string> cameraNameList)
{
HashSet<string> codestr = new HashSet<string>();
List<CodeInfo> codeList = new List<CodeInfo>();
string bitmapfilename = "";
if (cameraNameList == null || cameraNameList.Count <= 0)
{
throw new Exception("CameraScan方法没有传入相机名称.");
}
try
{
Task[] cameraTask = new Task[cameraNameList.Count()];
for (int ii = 0; ii < cameraNameList.Count(); ii++)
{
var cameraName = cameraNameList[ii];
var idx = ii;
cameraTask[ii] = Task.Run(new Action(() =>
{
int retrytime = 0;
retry:
LogUtil.info($"【" + cameraName + "】开始取图片");
if (cameraName.Trim().Equals(""))
{
return;
}
DateTime startTime = DateTime.Now;
HalconDotNet.HObject ho_Image = null;
Bitmap bmp = null;
try
{
bool nohalcon = true;
ho_Image = Camera._cam.CaptureOnImage(cameraName, out bmp, nohalcon);
if (bmp == null)
{
if (retrytime > 2)
return;
retrytime++;
CloseCamera(cameraName);
LogUtil.info($"bitmap为空重试第{retrytime}次");
Task.Delay(1500).Wait();
goto retry;
}
//HalconDotNet.HOperatorSet.RotateImage()
if (ho_Image == null && !nohalcon)
{
LogUtil.error(" 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
CloseCamera(cameraName);
return;
}
if (idx==0)
camera_event?.Invoke(null, bmp);
LogUtil.info(" 【" + cameraName + "】取图片完成,开始扫码");
string r = "";
RemoteDecodeHelper.RemoteDecodeParam remoteDecodeParam = new RemoteDecodeHelper.RemoteDecodeParam
{
codeTypeList = codeTypeList.ToArray(),
codeCount = QRCodeCount,
timeout = CodeTimeOut
};
List<CodeInfo> cc = new List<CodeInfo>();
cc = RemoteDecodeHelper.DecodeRequest(bmp, remoteDecodeParam);
if (cc != null)
{
lock (codeList)
{
cc.ForEach((c) =>
{
c.CodeStr = CodeManager.ReplaceCode(c.CodeStr);
if (!codestr.Contains(c.CodeStr))
{
codeList.Add(c);
codestr.Add(c.CodeStr);
r += "##" + c.CodeStr;
}
});
}
}
else
{
bitmapfilename = SaveImageToFile("mimo", cameraName, bmp);
}
LogUtil.info(" 【" + cameraName + "】" + " 扫码完成【" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "】 :" + r);
}
catch (AccessViolationException e)
{
LogUtil.error(" 扫码出现AccessViolationException异常,关闭相机【" + cameraName + "】:" + e.ToString());
Camera._cam.Close(cameraName);
// GC.Collect();
}
catch (Exception ex)
{
LogUtil.error(" 扫码出错:" + ex.ToString());
}
finally
{
if (ho_Image != null)
{
ho_Image.Dispose();
}
if (bmp != null)
bmp.Dispose();
}
}));
Task.Delay(ii * 700).Wait();
}
while (!cameraTask[0].IsCompleted || !cameraTask[1].IsCompleted)
{
Application.DoEvents();
Thread.Sleep(100);
}
}
catch (AccessViolationException e)
{
LogUtil.error( " 扫码出现AccessViolationException异常:" + e.ToString());
//throw new Exception("扫码出现AccessViolationException异常");
// GC.Collect();
}
catch (Exception ex)
{
LogUtil.error( " 扫码出错:" + ex.ToString());
//throw new Exception("扫码出错");
}
return codeList;
}
/// <summary>
///
/// </summary>
......
using HalconDotNet;
using OnlineStore.Common;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.IO;
......
......@@ -595,6 +595,10 @@ namespace DeviceLibrary
/// 存储MyCronic料仓的剩余容量 7X8=1000;7X12=345;13X32=100;
/// </summary>
internal string capacity;
/// <summary>
/// 与mycrnoic通讯错误
/// </summary>
public bool communicationError = false;
public bool SendCommand(string command, bool needlog, out string msg, params string[] arg)
{
......@@ -621,20 +625,22 @@ namespace DeviceLibrary
{
var re = towerAppWSClient.XmlAction(command);
msg = re.ToString();
//communicationError = false;
return true;
//errmsg = "Request sent successfully.";
}
catch (Exception ex)
{
errmsg = "Failed to send request." + command+ ex;
errmsg = "Failed to send request." + command + ex;
msg = errmsg;
communicationError= true;
return false;
}
}
catch (Exception ex)
{
errmsg = "Error: " + ex.ToString();
errmsg = "Error: " + command + ex.ToString();
msg = errmsg;
}
return false;
......
......@@ -2,13 +2,6 @@ using OnlineStore;
using RemoteSheardObject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
namespace DeviceLibrary
{
......@@ -29,27 +22,28 @@ namespace DeviceLibrary
public string CID;
public string TowerName;
public TowerInfo TowerInfo;
public VStore(TowerInfo towerInfo, VStoreCollection storeCollection) {
public VStore(TowerInfo towerInfo, VStoreCollection storeCollection)
{
vc = storeCollection;
CID = towerInfo.TowerID;
TowerName = towerInfo.TowerName;
TowerInfo= towerInfo;
TowerInfo = towerInfo;
VLog = new VLog(CID, CID);
ServerCM = new VServerComm(CID,VLog);
ServerCM = new VServerComm(CID, VLog);
ServerCM.OutStoreEvent += ServerCM_OutStoreEvent;
ServerCM.storeStatus = StoreStatus.None;
Msg = new MsgService("RT-" + CID);
OutStoreJobList = new StoreJobList(crc.GetString("Res0050","出库任务"));
OutStoreJobList = new StoreJobList(crc.GetString("Res0050", "出库任务"));
}
public void ServerCM_OutStoreEvent(object sender, JobInfo e)
{
VLog.Info(sender+"出库指令信息:" + e.ToStr());
VLog.Info(sender + "出库指令信息:" + e.ToStr());
OutStoreJobList.Enqueue(e.Clone());
//MI.DeviceList[TowerList.List[CurrentOutJobInfo.CID].DeviceGroupName].EnqueueOutStore(CurrentOutJobInfo);
}
public string CurrentTowerStatusText="";
public string CurrentTowerStatusText = "";
public RTStoreStatus RTStoreStatus = RTStoreStatus.Offline;
public volatile bool TerminalError = false;
DateTime LastStatusTime = DateTime.Now;
......@@ -59,19 +53,28 @@ namespace DeviceLibrary
/// </summary>
public DateTime LastProcessErrorTime = DateTime.Now;
public int LastProcessErrorTimes = 0;
internal void VTowerProcess() {
if (!TowerInfo.Enable) {
internal void VTowerProcess()
{
if (!TowerInfo.Enable)
{
ServerCM.storeStatus = StoreStatus.None;
CurrentTowerStatusText = "Disable";
RTStoreStatus = RTStoreStatus.Offline;
TerminalError=false;
TerminalError = false;
return;
}
try
{
ServerCM.communicationError = false;
var ti = ServerCM.GetTowerDetailInformation(CID);
if (ti != null)
if (ti == null)
{
ServerCM.storeStatus = StoreStatus.None;
RTStoreStatus = RTStoreStatus.Offline;
VLog.Error("GetTowerDetailInformation=null");
}
else
{
if (LastStatusCode != ti.StatusCode)
{
......@@ -83,7 +86,7 @@ namespace DeviceLibrary
ServerCM.Humidity = ti.Humidity;
if (ServerCM.Humidity > ServerCM.Max_Humidity || ServerCM.Temperature > ServerCM.Max_Temperature)
{
Msg.add(crc.GetString("Res0098.70dccffd","温湿度超限"), MsgLevel.alarm);
Msg.add(crc.GetString("Res0098.70dccffd", "温湿度超限"), MsgLevel.alarm);
}
if (ti.StatusCode == 26 && ti.StatusText == "Ready")
......@@ -158,13 +161,13 @@ namespace DeviceLibrary
else if (RTStoreStatus == RTStoreStatus.LockToOutStore)
{
VLog.Error($"出库超时出错,没有检测到出库信息,RTStoreStatus={RTStoreStatus}:" + CurrentTerminalReelID);
CurrentTowerStatusText = crc.GetString("Res0112.e6c4624b","出库错误,没有执行出库过程");
Msg.add($"TerminalError:" + crc.GetString("Res0113.71e5a53a","出库超时"), MsgLevel.alarm);
CurrentTowerStatusText = crc.GetString("Res0112.e6c4624b", "出库错误,没有执行出库过程");
Msg.add($"TerminalError:" + crc.GetString("Res0113.71e5a53a", "出库超时"), MsgLevel.alarm);
}
else
{
VLog.Error($"未知状态超时,RTStoreStatus={RTStoreStatus}:" + InStoreJobInfo?.ToStr());
Msg.add($"TerminalError:" + crc.GetString("Res0114.d3023f35","料仓状态异常"), MsgLevel.warning);
Msg.add($"TerminalError:" + crc.GetString("Res0114.d3023f35", "料仓状态异常"), MsgLevel.warning);
}
}
......@@ -275,12 +278,7 @@ namespace DeviceLibrary
//CurrentTowerStatusText = $"{ti.StatusText}-{ti.OnlineStatus}";
}
}
else
{
ServerCM.storeStatus = StoreStatus.None;
RTStoreStatus = RTStoreStatus.Offline;
}
/*
18 offline
26 Ready/Idle
......@@ -335,8 +333,13 @@ namespace DeviceLibrary
}
finally
{
if (ServerCM.communicationError)
{
Msg.add($"Communication with tower {CID} failed.", MsgLevel.warning);
VLog.Error($"Communication with tower {CID} failed.");
}
ServerCM.ProcessMsg(Msg.msg);
Msg.clear();
//Msg.clear();
}
}
public Dictionary<string, string> SlotsInfo = new Dictionary<string, string>();
......@@ -353,13 +356,13 @@ namespace DeviceLibrary
return crc.GetString("Res0067", "等待入库信息");
if (RTStoreStatus == RTStoreStatus.LockToOutStore)
return crc.GetString("Res0115.44b81dd3","等待出库");
return crc.GetString("Res0115.44b81dd3", "等待出库");
if (RTStoreStatus == RTStoreStatus.InStoreExecute || RTStoreStatus == RTStoreStatus.InStoreReady)
return crc.GetString("Res0068", "入库中") + " Barcode:" + InStoreJobInfo?.WareNum;
if (RTStoreStatus == RTStoreStatus.InStoreError)
return crc.GetString("Res0069", "入库出错,物料NG") +"LT:"+ LastProcessErrorTimes + ", Barcode:" + InStoreJobInfo?.WareNum;
return crc.GetString("Res0069", "入库出错,物料NG") + "LT:" + LastProcessErrorTimes + ", Barcode:" + InStoreJobInfo?.WareNum;
if (RTStoreStatus == RTStoreStatus.Error)
return CurrentTowerStatusText;
......@@ -371,14 +374,16 @@ namespace DeviceLibrary
/// </summary>
public volatile JobInfo InStoreJobInfo;
StoreJobList OutStoreJobList;
public void RequestInStore(JobInfo jobInfo) {
LastStatusTime=DateTime.Now;
public void RequestInStore(JobInfo jobInfo)
{
LastStatusTime = DateTime.Now;
TerminalError = false;
InStoreJobInfo = jobInfo.Clone();
//return vc.BeginInStore(CID, jobInfo);
}
public bool OutStoreEnd(string reelid,string towerid) {
public bool OutStoreEnd(string reelid, string towerid)
{
CurrentTerminalReelID = reelid;
TheLine.UpdateLocInfo("", CurrentTerminalReelID, TheLine.LineStatusE.BOXDOOR, towerid);
return ServerCM.SendStoreState("", reelid, StoreStatus.OutStoreEnd);
......@@ -393,7 +398,8 @@ namespace DeviceLibrary
VLog.Info(v);
}
}
public enum RTStoreStatus {
public enum RTStoreStatus
{
Offline,
Ready,
InStoreReady,
......
using log4net;
using MydataWcfServiceTest.ServiceReference2;
using Newtonsoft.Json;
using Newtonsoft.Json;
using OnlineStore.Common;
using RemoteSheardObject;
using RtTower.WebService.ComTowerApp.Contract;
using RtTower.WebService.SharedService;
using System;
using System.Collections.Generic;
......@@ -11,7 +8,6 @@ using System.IO;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
......@@ -28,13 +24,14 @@ namespace DeviceLibrary
public VLog VLog = new VLog();
public string StoreServerURL;
public static Dictionary<string, VStore> VStoreList = new Dictionary<string, VStore>();
public VStoreCollection() {
public VStoreCollection()
{
StoreServerURL = Setting_Init.Device_StoreServerURL;
service.OnCommand += Service_OnCommand;
StartService();
if(!string.IsNullOrEmpty(Setting_Init.Runtime_OutStoreReelInfo))
if (!string.IsNullOrEmpty(Setting_Init.Runtime_OutStoreReelInfo))
OutStoreReelInfo = JsonConvert.DeserializeObject<Dictionary<string, JobInfo>>(Setting_Init.Runtime_OutStoreReelInfo);
//TowerList.List.Add("123132", new TowerInfo() { TowerID = "13123", TowerName = "asdasd" });
......@@ -42,15 +39,16 @@ namespace DeviceLibrary
TowerList.List.Values.ToList().ForEach(s =>
{
VLog.Info("加载RT料仓:" + s.TowerID);
VStore vStore = new VStore(s,this);
VStore vStore = new VStore(s, this);
VStoreList[s.TowerID] = vStore;
});
}
private void Service_OnCommand(object sender, string xmlString)
{
var cmd= XmlCommandSerializer.DeserializeCommand(xmlString);
switch (cmd.Command) {
var cmd = XmlCommandSerializer.DeserializeCommand(xmlString);
switch (cmd.Command)
{
case "NotifyCarrierLoad":
// put in your code here
var r = XElement.Parse(cmd.Parameter);
......@@ -61,7 +59,8 @@ namespace DeviceLibrary
if (!VStoreList.ContainsKey(towerid))
{
VLog.Error("收到入库信息,但没有找到该料仓id");
}else
}
else
VStoreList[towerid].InStoreEnd(reelid);
break;
case "NotifyCarrierUnload":
......@@ -71,7 +70,8 @@ namespace DeviceLibrary
towerid = r.Descendants("TowerId").FirstOrDefault().Value;
VLog.Info("收到出库完成通知:" + $"ReelID:{reelid},TowerID:{towerid}");
VStoreList[towerid].log("收到出库完成通知:" + $"ReelID:{reelid},TowerID:{towerid}");
if (!VStoreList.ContainsKey(towerid)) {
if (!VStoreList.ContainsKey(towerid))
{
VLog.Error("收到出库信息,但没有找到该料仓id");
}
else
......@@ -82,18 +82,21 @@ namespace DeviceLibrary
}
}
Thread td;
public void Start() {
public void Start()
{
td = new Thread(new ThreadStart(Run));
td.Start();
}
bool mstate = false;
DateTime LastQueryCarrierListTime = DateTime.MinValue;
void Run() {
void Run()
{
mstate = true;
while (mstate) {
while (mstate)
{
Thread.Sleep(1000);
VStoreList.Values.ToList().ForEach(vs=>
VStoreList.Values.ToList().ForEach(vs =>
{
try
{
......@@ -102,7 +105,7 @@ namespace DeviceLibrary
}
catch (Exception ex)
{
VLog.Error("VTowerProcess error:"+ex);
VLog.Error("VTowerProcess error:" + ex);
}
finally
{
......@@ -119,7 +122,7 @@ namespace DeviceLibrary
VLog.Info("RT料仓退出主循环");
}
public static Dictionary<string, JobInfo> OutStoreReelInfo = new Dictionary<string,JobInfo>();
public static Dictionary<string, JobInfo> OutStoreReelInfo = new Dictionary<string, JobInfo>();
RtTowerClientService.Service service = new RtTowerClientService.Service();
void StartService()
......@@ -201,7 +204,7 @@ namespace DeviceLibrary
VLog.Info("stop service success");
}
public void GetCarrierList()
public async void GetCarrierList()
{
try
{
......@@ -218,7 +221,7 @@ namespace DeviceLibrary
EndpointAddress endpointAddress = new EndpointAddress(baseAddress.ToString());
var towerAppWSClient = new MydataWcfServiceTest.ServiceReference2.TowerAppWSClient(binding, endpointAddress);
VLog.Info("开始查询 CarrierList");
var result = towerAppWSClient.XmlAction(VCmd.GetCarrierList);
var result = await towerAppWSClient.XmlActionAsync(VCmd.GetCarrierList);
VLog.Info("结束查询 CarrierList");
File.WriteAllText("logs\\CarrierList.xml", result.ToString());
towerAppWSClient.Close();
......@@ -227,7 +230,7 @@ namespace DeviceLibrary
}
catch (Exception ex)
{
VLog.Error(ex.ToString());
VLog.Error("GetCarrierList:" + ex.ToString());
}
}
......@@ -265,7 +268,8 @@ namespace DeviceLibrary
}
TheLine.UploadCarrierInformation(cril);
VLog.Info("上传库位信息:" + cril.Count);
}catch (Exception ex)
}
catch (Exception ex)
{
VLog.Error("上传库位信息失败:" + ex);
}
......
......@@ -31,6 +31,6 @@ using System.Runtime.InteropServices;
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.6")]
//[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyFileVersion("1.0.0.0")]
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!