Commit 047cd333 张东亮

存储机构出入库一定次数复位,监控相机图片转视频

1 个父辈 ea4fd53a
......@@ -12,6 +12,7 @@ AXIS,0,B面移栽压紧轴,ComAxis_B,9,HC,,20000,150000,150000,2000,10000,20000,
,,,,,,,,,,,,,,,,
PRO,0,设备是否处于调试状态(1=调试,0=正常),IsDebug,0,,,,,,,,,,,,
PRO,0,温湿度端口号,Humiture_Port,0,,,,,,,,,,,,
PRO,0,设备出入库次数多少次时,会自动重置操作,Box_ResetCount,200,,,,,,,,,,,,
PRO,0,A面抽屉对位Mark_X坐标,FindPos_Drawer_A_X,930.03,,,,,,,,,,,,
PRO,0,A面抽屉对位Mark_Y坐标,FindPos_Drawer_A_Y,897.49,,,,,,,,,,,,
PRO,0,A面抽屉验证Mark_X坐标,Validate_Drawer_A_X,932.59,,,,,,,,,,,,
......
......@@ -23,7 +23,7 @@ namespace OnlineStore.DeviceLibrary
public int LastPosition = 0;
public string AxisName;
public AxisBean(ConfigMoveAxis axisConfig, string deviceName, bool needHome = false)
public AxisBean(ConfigMoveAxis axisConfig, string deviceName, bool needHome = true)
{
this.IsNeedHome = needHome;
this.Config = axisConfig;
......
......@@ -26,7 +26,6 @@ namespace OnlineStore.DeviceLibrary
/// 当前出入库的次数,超过配置的数量时,需要自动重置一下,再进行出入库
/// </summary>
internal int CurrInOutCount = 0;
internal int CurrInOutACount = 0;
#endregion
......@@ -47,6 +46,12 @@ namespace OnlineStore.DeviceLibrary
{
try
{
CurrInOutCount++;
if (CurrInOutCount >= boxBean.Config.Box_ResetCount)
{
boxBean.LogInfo($"存储机构出入库达到{CurrInOutCount}次数,需要复位");
boxBean.Reset();
}
//是否自动进入出库状态
if (!autoNext)
{
......@@ -139,7 +144,6 @@ namespace OnlineStore.DeviceLibrary
internal void ClearCount()
{
CurrInOutACount = 0;
CurrInOutCount = 0;
}
}
......
......@@ -262,6 +262,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.NewMove(MoveType.Reset);
LogInfo("开始重置: ");
AutoInout.ClearCount();
StartReset();
mainTimer.Enabled = true;
return true;
......@@ -304,7 +305,8 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.NextMoveStep(StepEnum.BOX_H001_Wait);
AutoInout.StopAuto();
LogInfo($"复位 {MoveInfo.SLog} :存储机构轴开始复位");
//停止记录
StopRecord();
isInPro = false;
}
......@@ -431,7 +433,7 @@ namespace OnlineStore.DeviceLibrary
{
MoveInfo.NextMoveStep(StepEnum.BOX_H03_PullAxis_InoutHome);
LogInfo($"复位 {MoveInfo.SLog}:视觉检测确认抽屉不在轴上,抽屉拉取进出轴回原点");
PullAxis_Inout.HomeMove(MoveInfo);
//PullAxis_Inout.HomeMove(MoveInfo);
}
}
break;
......@@ -602,27 +604,27 @@ namespace OnlineStore.DeviceLibrary
{
MoveInfo.NextMoveStep(StepEnum.BOX_H03_PullAxis_InoutHome);
LogInfo($"复位 {MoveInfo.SLog}:料屉拉取进出轴回原点");
PullAxis_Inout.HomeMove(MoveInfo);
//PullAxis_Inout.HomeMove(MoveInfo);
}
break;
case StepEnum.BOX_H02_PullAxis_UpDownToP1:
MoveInfo.NextMoveStep(StepEnum.BOX_H03_PullAxis_InoutHome);
LogInfo($"复位 {MoveInfo.SLog}:料屉拉取进出轴回原点");
PullAxis_Inout.HomeMove(MoveInfo);
//PullAxis_Inout.HomeMove(MoveInfo);
break;
case StepEnum.BOX_H03_PullAxis_InoutHome:
MoveInfo.NextMoveStep(StepEnum.BOX_H04_PullAxis_Updown_ABComAxis_Home);
LogInfo($"复位 {MoveInfo.SLog}:料屉拉取升降轴、AB面压紧轴回原点");
if (!IsMoveAxisInSafePos())
MoveAxis.AbsMove(MoveInfo, Config.MoveAxis_SafePos, Config.MoveAxis_P1_Speed);
PullAxis_Inout.HomeMove(MoveInfo);
ComAxis_A.HomeMove(MoveInfo);
ComAxis_B.HomeMove(MoveInfo);
PullAxis_Updown.HomeMove(MoveInfo);
//ComAxis_A.HomeMove(MoveInfo);
//ComAxis_B.HomeMove(MoveInfo);
break;
case StepEnum.BOX_H04_PullAxis_Updown_ABComAxis_Home:
MoveInfo.NextMoveStep(StepEnum.BOX_H05_XAxis_AB_UpDown_Home);
LogInfo($"复位 {MoveInfo.SLog}:AB面移栽X轴回原点、移栽升降轴");
PullAxis_Inout.HomeMove(MoveInfo);
// PullAxis_Inout.HomeMove(MoveInfo);
XAxis_A.HomeMove(MoveInfo);
XAxis_B.HomeMove(MoveInfo);
UpdownAxis.HomeMove(MoveInfo);
......
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
......@@ -62,23 +63,20 @@ namespace OnlineStore.DeviceLibrary
Bitmap bmp = AcqImage(name);
if (bmp != null)
{
if (IsRecord)
{
cnt++;
Task.Factory.StartNew(delegate
{
SaveImage("box_A", cnt);
});
Task.Factory.StartNew(delegate
{
SaveImage("box_B", cnt);
});
}
camera_event?.Invoke(new CameraArgs(name, bmp));
}
//if (MoveInfo != null)
//{
// if (MoveInfo.MoveType.Equals(MoveType.InStore) || MoveInfo.MoveType.Equals(MoveType.OutStore))
// {
// if (CheckASide() && name.Equals("box_A"))
// {
// SaveImage(name);
// }
// else
// {
// SaveImage("box_B");
// }
// }
//}
Thread.Sleep(300);
}
}
......@@ -173,6 +171,66 @@ namespace OnlineStore.DeviceLibrary
}
}
#region 监控保存
void SaveImage(string camName, int count)
{
try
{
if (inOutPosInfo != null)
{
string path = Application.StartupPath + imgPath + camName + "\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId;
if (!System.IO.Directory.Exists(path))
Directory.CreateDirectory(path);
Task.Factory.StartNew(() =>
{
camera.SaveImage(camName, path, $"{count.ToString().PadLeft(4, '0')}", System.Drawing.Imaging.ImageFormat.Bmp);
});
}
}
catch (Exception ex)
{
LogUtil.error($"保存{camName}图片失败", ex);
}
}
FFMPEG ffmpegA = new FFMPEG();
FFMPEG ffmpegB = new FFMPEG();
bool IsRecord = false;
int cnt = 0;
InOutPosInfo inOutPosInfo = null;
/// <summary>
/// 开始记录
/// </summary>
public void StartRecord(bool isTest=false)
{
if(isTest)
{
inOutPosInfo = new InOutPosInfo("code"+DateTime.Now.ToString("mmssfff"), DateTime.Now.ToString("yyyyMMddhh"));
}
else
{
inOutPosInfo = MoveInfo.MoveParam.PosInfo;
}
cnt = 0;
string inputfolderA = Application.StartupPath + imgPath + "box_A\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId;
string inputfolderB = Application.StartupPath + imgPath + "box_B\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId;
string outputfolderA = Application.StartupPath + "\\Videos\\box_A\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId;
string outputfolderB = Application.StartupPath + "\\Videos\\box_B\\" + DateTime.Now.ToString("yyyyMMdd") + "\\" + inOutPosInfo.PosId;
ffmpegA.SetParam(inputfolderA, outputfolderA,$"{DateTime.Now.ToString("hhmmss")}_{inOutPosInfo.barcode}.mp4");
ffmpegB.SetParam(inputfolderB, outputfolderB, $"{DateTime.Now.ToString("hhmmss")}_{inOutPosInfo.barcode}.mp4");
IsRecord = true;
}
/// <summary>
/// 停止记录
/// </summary>
public void StopRecord()
{
IsRecord = false;
ffmpegA.ConvertImgsToMp4();
ffmpegB.ConvertImgsToMp4();
}
#endregion
}
public class CameraArgs : EventArgs
{
......@@ -190,4 +248,88 @@ namespace OnlineStore.DeviceLibrary
Image = img;
}
}
public class FFMPEG
{
public static string appFolderPath = Application.StartupPath;
static string imgPath = ConfigAppSettings.GetValue(Setting_Init.ImagePath);
/// <summary>
/// 帧频
/// </summary>
public int FrameRate { get; set; } = 2;
/// <summary>
/// 画面宽
/// </summary>
public int Width { get; set; } = 1920;
/// <summary>
/// 画面高
/// </summary>
public int Height { get; set; } = 1080;
/// <summary>
/// 输入文件夹
/// </summary>
public string InputFolder { get; set; } = appFolderPath + imgPath;
public string InputFileNamePrefix { get; set; } = "";
/// <summary>
/// 输出文件夹
/// </summary>
public string OutputFolder { get; set; } = appFolderPath + "Videos\\";
/// <summary>
/// 输出文件名带后缀
/// </summary>
public string OutputFileName { get; set; } = "test.mp4";
public string Cmd { get { return ExportCmd(); } }
public void SetParam(string inputfolder, string outputfolder, string outputfilename)
{
InputFolder = inputfolder;
OutputFolder = outputfolder;
OutputFileName = outputfilename;
if (!Directory.Exists(outputfolder))
Directory.CreateDirectory(outputfolder);
}
string ExportCmd()
{
StringBuilder sb = new StringBuilder();
sb.Append(appFolderPath + "\\ffmpeg ");
sb.Append($" -y -r {FrameRate} -f image2 -s {Width}*{Height} -i {InputFolder}\\{InputFileNamePrefix}%04d.Bmp -vcodec libx264 -pix_fmt yuv420p ");
sb.Append(OutputFolder + "\\" + OutputFileName);
return sb.ToString();
}
public void ConvertImgsToMp4()
{
Task task = Task.Factory.StartNew(delegate
{
using (Process p = new Process())
{
//(1)设置要启动的应用程序
p.StartInfo.FileName = "cmd.exe";
//p.StartInfo.FileName = appFolderPath + "\\ffmpeg.exe";
//p.StartInfo.Arguments = Cmd +" & exit /b";
//(2)是否使用操作系统shell启动
p.StartInfo.UseShellExecute = false;
//(3)接受来自调用程序的输入信息
p.StartInfo.RedirectStandardInput = true;
//(4)输出信息
p.StartInfo.RedirectStandardOutput = true;
//(5)输出错误
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(Cmd + "&exit");
p.StandardInput.AutoFlush = true;
p.StandardInput.Close();
p.StandardError.ReadToEnd();
p.WaitForExit();
try
{
System.IO.Directory.Delete(InputFolder, true);
}
catch { }
}
});
task.Wait(120000);
}
}
}
......@@ -155,7 +155,7 @@ namespace OnlineStore.DeviceLibrary
}
return lineOperation;
}
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
public void SendLineStatus()
{
DateTime time = DateTime.Now;
......@@ -167,7 +167,6 @@ namespace OnlineStore.DeviceLibrary
lineOperation.op = 5;
LogUtil.error(Name + "没有湿度预警范围,需要从服务器获取,发送OP=" + lineOperation.op, DeviceID + 105);
}
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
Operation resultOperation = HttpHelper.PostOperation(SServerManager.GetPostApi(server), lineOperation);
//LogUtil.info("resultOperation="+ JsonHelper.SerializeObject(resultOperation));
//发送状态信息到服务器
......
......@@ -393,6 +393,8 @@ namespace OnlineStore.DeviceLibrary
SetBoxStatus(DeviceStatus.StoreOnline, RunStatus.Runing);
LogInfo($"入库 {MoveInfo.SLog}:入库结束[{MoveInfo.MoveParam.PosInfo.PosId}][耗时:{(DateTime.Now - startTime).TotalSeconds.ToString("f2")}秒][{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
MoveInfo.EndMove();
//停止记录
StopRecord();
AutoInout.InOutEndProcess(this, MoveType.InStore);
}
......@@ -412,6 +414,8 @@ namespace OnlineStore.DeviceLibrary
SetBoxStatus(DeviceStatus.StoreOnline, RunStatus.Runing);
LogInfo($"入库 {MoveInfo.SLog}:入库结束[{MoveInfo.MoveParam.PosInfo.PosId}][耗时:{(DateTime.Now - startTime).TotalSeconds.ToString("f2")}秒][{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
MoveInfo.EndMove();
//停止记录
StopRecord();
AutoInout.InOutEndProcess(this, MoveType.InStore);
break;
}
......
......@@ -296,6 +296,8 @@ namespace OnlineStore.DeviceLibrary
case StepEnum.SO_20_Finish:
SetBoxStatus(DeviceStatus.StoreOnline, RunStatus.Runing);
MoveInfo.EndMove();
//停止记录
StopRecord();
AutoInout.InOutEndProcess(this, MoveType.OutStore);
break;
}
......
......@@ -936,8 +936,10 @@ namespace OnlineStore.DeviceLibrary
startInStoreTime = DateTime.Now;
LogInfo(" 启动入库【" + param.PosInfo.ToStr() + "】 ");
param.MoveP = new LineMoveP(Config, param.PosInfo.PosId);
LogInfo("LoadInoutParam:" + JsonHelper.SerializeObject(param.MoveP));
// LogInfo("LoadInoutParam:" + JsonHelper.SerializeObject(param.MoveP));
MoveInfo.NewMove(MoveType.InStore, param);
///开始记录
StartRecord();
IgnoreCamDect = false;
SetBoxStatus(DeviceStatus.InStoreExecute, RunStatus.Busy, param.PosInfo.PosId, param.PosInfo.barcode);
MoveInfo.NextMoveStep(StepEnum.SI_00_StartInstore);
......@@ -1142,7 +1144,9 @@ namespace OnlineStore.DeviceLibrary
SetBoxStatus(DeviceStatus.OutStoreExecute, RunStatus.Busy, param.PosInfo.PosId, param.PosInfo.barcode);
MoveInfo.NewMove(MoveType.OutStore, param);
LogInfo("启动出库【" + param.PosInfo.ToStr() + "】 ");
LogInfo("LoadInoutParam:" + JsonHelper.SerializeObject(param.MoveP));
///开始记录
StartRecord();
//LogInfo("LoadInoutParam:" + JsonHelper.SerializeObject(param.MoveP));
IgnoreCamDect = false;
MoveInfo.NextMoveStep(StepEnum.SO_00_StartOutstore);
AxisAlarmFlag = false;
......@@ -1163,8 +1167,10 @@ namespace OnlineStore.DeviceLibrary
OutstoreExecute();
}
#endregion
private void SaveSpecifiedImage()
private void SaveSpecifiedImage(bool open=false)
{
if (!open)
return;
SaveImage("box_A");
SaveImage("box_B");
//if (CheckASide())
......
......@@ -223,7 +223,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.NextMoveStep(StepEnum.SP_13_PutReel);
LogInfo($"库位调试 {MoveInfo.SLog}:进入库位中,移栽升降轴到料屉取放点P7/P13[{MoveInfo.MoveParam.PosInfo.GetPosSide()}面]");
UpdownAxisToP7_P13(true);
SaveSpecifiedImage();
SaveSpecifiedImage(true);
break;
case StepEnum.SP_13_PutReel:
......
......@@ -19,6 +19,11 @@ namespace OnlineStore.LoadCSVLibrary
: base(id, cid, LoadCSVLibrary.DeviceType.BoxEquip, filepath)
{
}
/// <summary>
/// 出入库一定次数后复位
/// </summary>
[ConfigProAttribute("Box_ResetCount")]
public int Box_ResetCount { get; set; }
#region
/// <summary>
/// AXIS,0,行走机构,MoveAxis,0,HC,,35000,60000,60000,1000,5000,20000,10,100,0,0
......
......@@ -530,6 +530,16 @@ namespace OnlineStore.XLRStore
{
boxBean.IgnoreCamDect = true;
}
private void button1_Click(object sender, EventArgs e)
{
boxBean.StartRecord(true);
}
private void button2_Click(object sender, EventArgs e)
{
boxBean.StopRecord();
}
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!