Commit d4b24431 刘韬

优化配置存储防止断电导致损坏

1 个父辈 733ba004
......@@ -52,6 +52,7 @@
<HintPath>..\..\..\增广夹爪\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.ServiceModel" />
......
......@@ -5,11 +5,14 @@ using OnlineStore.DeviceLibrary;
using OnlineStore.DUOStore;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
namespace OnlineStore.DUOStore
{
......@@ -58,12 +61,14 @@ namespace OnlineStore.DUOStore
//string path = @"http://localhost:4090/rest/api/v1/station/status";
//HttpHelper.PostOperation(path, new Operation());
List<InOutParam> aa = new List<InOutParam>();
aa.Add(new InOutParam(MoveType.InStore, "123", "123", 7, 8, 1));
var aaa = from a in aa where a.TargetPosition == 1 select a;
var xccsaf = aaa.Count();
//List<InOutParam> aa = new List<InOutParam>();
//aa.Add(new InOutParam(MoveType.InStore, "123", "123", 7, 8, 1));
//var aaa = from a in aa where a.TargetPosition == 1 select a;
//var xccsaf = aaa.Count();
//string a = "LZAUJN0208MAN;E20210105 0365;BQT001200261510792021010515000;R107920210118A1049";
//a = a.Replace("\u001a", "");
CheckConfigFile();
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
......@@ -112,6 +117,24 @@ namespace OnlineStore.DUOStore
Application.Run(new FrmStore());
}
}
private static void CheckConfigFile()
{
string configfile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
string backupfile = configfile + ".backup";
try
{
var c = new XmlDocument();
c.Load(configfile);
File.Copy(configfile, backupfile, true);
}
catch {
if (File.Exists(backupfile)) {
File.Copy(backupfile, configfile, true);
}
}
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
LogUnhandledException(e.ExceptionObject);
......
......@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary.IO
......@@ -27,7 +28,12 @@ namespace OnlineStore.DeviceLibrary.IO
HCBoardManager.InitConfig("", "", "HCBOARD");
if (!HCBoardManager.CardInitOk())
{
HCBoardManager.OpenCard();
if (!HCBoardManager.OpenCard()) {
LogUtil.info("伺服板卡打开失败,重新打开");
HCBoardManager.CloseCard();
Thread.Sleep(2000);
HCBoardManager.OpenCard();
}
}
}
}
......
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
......@@ -34,21 +35,53 @@ namespace OnlineStore.DeviceLibrary
}
void startCamera() {
var rtn = camera.Open(0);
if (!rtn)
LogUtil.error(Name + "打开监控相机失败");
if (!camera.IsOpen[0])
{
var rtn = camera.Open(0);
if (!rtn)
LogUtil.error(Name + "打开监控相机失败");
}
while (camera.IsOpen[0])
{
rtn = camera.GrabOne(0, out Bitmap bmp);
var rtn = camera.GrabOne(0, out Bitmap bmp);
if (rtn)
{
camera_event?.Invoke(this, bmp);
}
Thread.Sleep(1000/10);
Thread.Sleep(1000/7);
}
camera.Close(0);
camera.Dispose();
}
void CameraGrabOne(string filename) {
LogUtil.info(Name + "库位文件名:"+ filename);
return;
if (!camera.IsOpen[0]) {
camera.Open(0);
LogUtil.error(Name + "打开监控相机失败2");
}
var rtn = camera.GrabOne(0, out Bitmap bmp);
if (rtn)
{
bmp.Save(filename,ImageFormat.Jpeg);
bmp.Dispose();
}
}
string GetFixtureStateFilename(InOutParam inOutParam, FixtureState fixtureState) {
string dir = $"\\image\\Fixture\\{inOutParam.moveType}\\BOX{ID}\\{inOutParam.PosID}\\";
Directory.CreateDirectory(dir);
string filename = $"{inOutParam.WareCode}@@{StoreManager.LastVisualRfid}@@{fixtureState}.jpg";
foreach (var x in Path.GetInvalidFileNameChars())
{
filename = filename.Replace(x.ToString(), "");
}
return dir+filename;
}
enum FixtureState {
In,
Up,
Out
}
}
}
......@@ -178,6 +178,7 @@ namespace OnlineStore.DeviceLibrary
}
else if (MoveInfo.IsStep(StoreMoveStep.SI_03_InoutToP2))
{
CameraGrabOne(GetFixtureStateFilename(MoveInfo.MoveParam, FixtureState.In));
MoveInfo.NextMoveStep(StoreMoveStep.SI_04_GetReel);
InOutStoreLog(outType + "升降轴到入料口高点P2 [" + moveP.UpDown_P2 + "],压紧轴到P2 [" + moveP.ComPress_P2 + "] ");
ComAxis.AbsMove(MoveInfo, moveP.ComPress_P2, Config.CompAxis_P2_Speed);
......@@ -185,12 +186,14 @@ namespace OnlineStore.DeviceLibrary
}
else if (MoveInfo.IsStep(StoreMoveStep.SI_04_GetReel))
{
CameraGrabOne(GetFixtureStateFilename(MoveInfo.MoveParam, FixtureState.Up));
MoveInfo.NextMoveStep(StoreMoveStep.SI_05_InoutToP1);
InOutStoreLog(outType + "进出轴返回P1 [" + moveP.InOut_P1 + "] ");
InOutBackToP1(moveP.InOut_P1);
}
else if (MoveInfo.IsStep(StoreMoveStep.SI_05_InoutToP1))
{
CameraGrabOne(GetFixtureStateFilename(MoveInfo.MoveParam, FixtureState.Out));
MoveInfo.NextMoveStep(StoreMoveStep.SI_06_FixtureCheck);
InOutStoreLog(outType + "等待料叉检测信号 ");
if (Config.IsUse_Tray_Check.Equals(1))
......@@ -440,16 +443,20 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.NextMoveStep(StoreMoveStep.SO_03_InoutToP3);
InOutStoreLog(outType + " 进出轴至P3 [" + moveP.InOut_P3 + "] ");
InoutAxis.AbsMove(MoveInfo, moveP.InOut_P3, Config.InOutAxis_P3_Speed);
}
else if (MoveInfo.IsStep(StoreMoveStep.SO_03_InoutToP3))
{
CameraGrabOne(GetFixtureStateFilename(MoveInfo.MoveParam, FixtureState.In));
MoveInfo.NextMoveStep(StoreMoveStep.SO_04_GetReel);
InOutStoreLog(outType + "升降轴到P6[" + moveP.UpDown_P6 + "],压紧轴到P2[" + moveP.ComPress_P2 + "]");
ComAxis.AbsMove(MoveInfo, moveP.ComPress_P2, Config.CompAxis_P2_Speed);
UpdownAxis.AbsMove(MoveInfo, moveP.UpDown_P6, Config.UpDownAxis_P6_Speed);
}
else if (MoveInfo.IsStep(StoreMoveStep.SO_04_GetReel))
{
CameraGrabOne(GetFixtureStateFilename(MoveInfo.MoveParam, FixtureState.Up));
MoveInfo.NextMoveStep(StoreMoveStep.SO_05_InoutBack);
InOutStoreLog(outType + "进出轴返回P1[" + moveP.InOut_P1 + "]");
InOutBackToP1(moveP.InOut_P1);
......@@ -462,6 +469,7 @@ namespace OnlineStore.DeviceLibrary
}
else if (MoveInfo.IsStep(StoreMoveStep.SO_05_InoutBack))
{
CameraGrabOne(GetFixtureStateFilename(MoveInfo.MoveParam, FixtureState.Out));
if (MoveInfo.MoveParam.TargetPosition.Equals(0))
{
MoveInfo.NextMoveStep(StoreMoveStep.SO_06_ToDoor);
......
......@@ -134,7 +134,9 @@ namespace OnlineStore.DeviceLibrary
public override bool StartOutStoreMove(InOutParam param,bool shelfisready=false)
{
if (IOValue(IO_Type.RaiseStation_BackendCheck).Equals(IO_VALUE.HIGH)) {
if (IOValue(IO_Type.RaiseStation_BackendCheck).Equals(IO_VALUE.HIGH)
|| IOValue(IO_Type.RaiseStation_UpLocation1).Equals(IO_VALUE.HIGH)
) {
runStatus = StoreRunStatus.Busy;
storeStatus = StoreStatus.OutStoreExecute;
MoveInfo.NewMove(MoveType.OutStore, new InOutParam(MoveType.OutStore));
......@@ -212,8 +214,10 @@ namespace OnlineStore.DeviceLibrary
}
}
}
/// <summary>
/// 料串下降过度重新上升校准次数
/// </summary>
int TrayStringUpFix = 0;
protected override void OutStoreProcess()
{
if (MoveInfo.IsInWait)
......@@ -261,6 +265,7 @@ namespace OnlineStore.DeviceLibrary
{
MoveInfo.NextMoveStep(StoreMoveStep.LO_09_WaitOut);
InOutStoreLog("料架出库:料架准备完成,等待料盘出库");
TrayStringUpFix = 0;
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(5000));
T1_BatchAxis.AbsMove(MoveInfo, T1_BatchAxis.GetAclPosition() - Config.BatchAxis_ChangeValue * 40, Config.BatchAxis_P1Speed);
}
......@@ -369,12 +374,12 @@ namespace OnlineStore.DeviceLibrary
if (MoveInfo.MoveParam.TargetBox.Equals(1))
{
InOutStoreLog("取料:BOX1 升降轴上升到料门口高点P4 [" + Config.UpdownAxis_P4 + "]");
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P4, Config.UpdownAxis_P4Speed);
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P4, (int)(Config.UpdownAxis_P4Speed));
}
else
{
InOutStoreLog("取料:BOX2 升降轴上升到料门口高点P6 [" + Config.UpdownAxis_P6 + "]");
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P6, Config.UpdownAxis_P6Speed);
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P6, (int)(Config.UpdownAxis_P6Speed));
}
}
else if (MoveInfo.IsStep(StoreMoveStep.LO_15a_UpdownUp))
......@@ -418,7 +423,7 @@ namespace OnlineStore.DeviceLibrary
{
MoveInfo.NextMoveStep(StoreMoveStep.LO_18_UpdownDown);
InOutStoreLog("取料:升降轴到料串放料低点P1 [" + Config.UpdownAxis_P1 + "]");
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P1, Config.UpdownAxis_P1Speed);
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P1, (int)(Config.UpdownAxis_P1Speed*2));
}
else if (MoveInfo.IsStep(StoreMoveStep.LO_18_UpdownDown))
{
......@@ -437,12 +442,13 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.NextMoveStep(StoreMoveStep.LO_20_UpdownUp);
//只有提升轴位置过低时才需要到P3
int currPosition = T1_BatchAxis.GetAclPosition();
int reoppos = (Config.BatchAxis_P1 + Config.BatchAxis_ChangeValue * 120);
int reoppos = (Config.BatchAxis_P1 + Config.BatchAxis_ChangeValue * 100);
InOutStoreLog($"料盘移栽: 当前T1位置[{currPosition}],最低需要重新上升位置:[{reoppos}]");
if (currPosition <= reoppos)
if (currPosition <= reoppos && TrayStringUpFix<2)
{
MoveInfo.NextMoveStep(StoreMoveStep.LO_20_UpdownUp_wait);
InOutStoreLog("料盘移栽: 升降轴到料串高点[" + Config.UpdownAxis_P2 + "],提升轴[" + currPosition + $"]需要到P2");
TrayStringUpFix++;
InOutStoreLog($"料盘移栽: 第{TrayStringUpFix}次,升降轴到料串高点[" + Config.UpdownAxis_P2 + "],提升轴[" + currPosition + $"]需要到P2");
BatchAxisToP2();
}
else
......@@ -1060,12 +1066,12 @@ namespace OnlineStore.DeviceLibrary
if (LastPosParam.TargetBox.Equals(1))
{
InOutStoreLog($"料盘移栽: 升降轴到料门口低点P3[{Config.UpdownAxis_P3},补偿:{(LastHeight - 8) * Config.UpdownAxis_ChangeValue}],开始预扫码");
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P3 - (LastHeight - 8) * Config.UpdownAxis_ChangeValue, Config.UpdownAxis_P3Speed);
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P3 - (LastHeight - 8) * Config.UpdownAxis_ChangeValue, (int)(Config.UpdownAxis_P3Speed*2));
}
else
{
InOutStoreLog($"料盘移栽: 升降轴到料门口低点P5[{Config.UpdownAxis_P5},补偿:{(LastHeight - 8) * Config.UpdownAxis_ChangeValue}],开始预扫码");
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P5 - (LastHeight - 8) * Config.UpdownAxis_ChangeValue, Config.UpdownAxis_P5Speed);
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P5 - (LastHeight - 8) * Config.UpdownAxis_ChangeValue, (int)(Config.UpdownAxis_P5Speed*2));
}
}
else if (MoveInfo.IsStep(StoreMoveStep.LI_23_UpdownDown))
......@@ -1080,12 +1086,12 @@ namespace OnlineStore.DeviceLibrary
if (LastPosParam.TargetBox.Equals(1))
{
InOutStoreLog("料盘移栽: 升降轴到料门口高点P4[" + Config.UpdownAxis_P4 + "]");
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P4, Config.UpdownAxis_P4Speed);
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P4, (int)(Config.UpdownAxis_P4Speed));
}
else
{
InOutStoreLog("料盘移栽: 升降轴到料门口高点P6[" + Config.UpdownAxis_P6 + "]");
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P6, Config.UpdownAxis_P6Speed);
T3_UpdownAxis.AbsMove(MoveInfo, Config.UpdownAxis_P6, (int)(Config.UpdownAxis_P6Speed));
}
int storeId = LastPosParam.GetStoreId();
......@@ -1441,6 +1447,7 @@ namespace OnlineStore.DeviceLibrary
if (!StartOutStoreMove(new InOutParam(MoveType.OutStore), true))
{
InOutStoreLog("检测料架为空:转换出库失败.");
LI_31_BatchAxisToP1();
//MoveEndP();
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!