Commit 2a28891c 刘韬

添加相机日志, 优化设备报警

1 个父辈 27272119
......@@ -5,12 +5,12 @@ using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("自动扫码贴标机")]
[assembly: AssemblyTitle("NS200")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("上海挚锦科技有限公司")]
[assembly: AssemblyProduct("自动扫码贴标机")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyCompany("Neotel")]
[assembly: AssemblyProduct("NS200")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
......
......@@ -943,7 +943,8 @@ namespace DeviceLibrary
public enum MsgLevel
{
warning,
info
info,
alarm
}
public class IdWorker
{
......
......@@ -43,24 +43,36 @@ namespace DeviceLibrary
break;
case MoveStep.Lbl_WaitPrint:
string version = ConfigHelper.Config.Get("Hardwareversion", "V2");
bool detectLabel = false;
if (version == "V2")
{
Thread.Sleep(1000);
if (IOValue(IO_Type.HasPrinter).Equals(IO_VALUE.HIGH))
{
LabelMoveInfo.NextMoveStep(MoveStep.Lbl_Printted);
Thread.Sleep(500);
}
detectLabel = true;
}
else
{
var isPrinted = RobotManage.printerHelper.IsLabelOnPeeler();
isPrinted.Wait();
if (isPrinted.Result.Item1)
{
LabelMoveInfo.NextMoveStep(MoveStep.Lbl_Printted);
Thread.Sleep(500);
}
detectLabel = true;
}
if (detectLabel)
{
LabelMoveInfo.errlog("标签打印完成");
LabelMoveInfo.NextMoveStep(MoveStep.Lbl_Printted);
Thread.Sleep(500);
}
//else if (LabelMoveInfo.IsTimeOut(15))
//{
// Msg.add("标签打印超时,请检查,取走标签后复位", MsgLevel.warning);
// LabelMoveInfo.errlog("标签打印超时");
// RobotManage.UserPause();
//}
else
{
Msg.add("等待标签打印", MsgLevel.info);
LabelMoveInfo.log("等待标签打印");
}
break;
case MoveStep.Lbl_Printted:
......@@ -82,31 +94,26 @@ namespace DeviceLibrary
break;
case MoveStep.Lbl05:
string versions = ConfigHelper.Config.Get("Hardwareversion", "V2");
bool IsLabelLeave;
if (versions == "V2")
{
Thread.Sleep(1000);
if (IOValue(IO_Type.HasPrinter).Equals(IO_VALUE.LOW))
{
LabelMoveInfo.NextMoveStep(MoveStep.Lbl06);
}
else
{
Msg.add(crc.GetString("Res0122.62c858d3", "标签取起失败!"), MsgLevel.warning);
}
IsLabelLeave = IOValue(IO_Type.HasPrinter).Equals(IO_VALUE.LOW);
}
else
{
var ip = RobotManage.printerHelper.IsLabelOnPeeler();
ip.Wait();
var r = ip.Result;
if (r.Item1)
{
Msg.add(crc.GetString("Res0122.62c858d3", "标签取起失败!"), MsgLevel.warning);
}
else
{
LabelMoveInfo.NextMoveStep(MoveStep.Lbl06);
}
IsLabelLeave = !ip.Result.Item1;
}
if (IsLabelLeave)
{
LabelMoveInfo.NextMoveStep(MoveStep.Lbl06);
LabelMoveInfo.log("标签已经被取走");
}
else
{
Msg.add(crc.GetString("Res0122.62c858d3", "标签取起失败!"), MsgLevel.alarm);
}
break;
case MoveStep.Lbl06:
......@@ -264,7 +271,7 @@ namespace DeviceLibrary
{
state += crc.GetString("Res0072", "标签已打印,当前ReelID:") + LabelMoveInfo.MoveParam.WareCode;
}
if (LabelMoveInfo.MoveStep == MoveStep.Lbl01)
if (LabelMoveInfo.MoveStep == MoveStep.Lbl_WaitPrint)
{
state += crc.GetString("Res0073", "等待标签打印");
}
......
......@@ -42,7 +42,7 @@ namespace DeviceLibrary
// RunningLed.LedState = LedState.on;
//}
if (alarmType != AlarmType.None)
if (alarmType != AlarmType.None || IsAlarm)
{
AlarmLed.LedState = LedState.on;
AlarmBuzzer.ON();
......
......@@ -71,11 +71,11 @@ namespace DeviceLibrary
{
if (MiddleMoveInfo.MoveParam.IsNg)
{
Msg.add(crc.GetString("Res0096","抓料失败请手动处理,请将料盘放入:NG箱,按右侧按钮继续"), MsgLevel.warning);
Msg.add(crc.GetString("Res0096","抓料失败请手动处理,请将料盘放入:NG箱,按右侧按钮继续"), MsgLevel.alarm);
}
else
{
Msg.add(crc.GetString("Res0097","抓料失败请手动处理,请将料盘放入: 左侧料串,按右侧按钮继续"), MsgLevel.warning);
Msg.add(crc.GetString("Res0097","抓料失败请手动处理,请将料盘放入: 左侧料串,按右侧按钮继续"), MsgLevel.alarm);
}
if (IOValue(IO_Type.Right_BTN).Equals(IO_VALUE.HIGH))
......@@ -186,7 +186,7 @@ namespace DeviceLibrary
MiddleMoveInfo.NextMoveStep(MoveStep.M09);
MiddleMoveInfo.log("等待夹爪放松");
}
Msg.add(crc.GetString("Res0050","等待夹爪放松"), MsgLevel.warning);
Msg.add(crc.GetString("Res0050","等待夹爪放松"), MsgLevel.info);
break;
case MoveStep.M10:
MiddleMoveInfo.NextMoveStep(MoveStep.M_ReturnToP1);
......@@ -220,7 +220,7 @@ namespace DeviceLibrary
MiddleMoveInfo.NextMoveStep(MoveStep.M22);
MiddleMoveInfo.log("等待夹爪放松");
}
Msg.add(crc.GetString("Res0050","等待夹爪放松"), MsgLevel.warning);
Msg.add(crc.GetString("Res0050","等待夹爪放松"), MsgLevel.info);
break;
case MoveStep.M23:
MiddleMoveInfo.NextMoveStep(MoveStep.M_ReturnToP1);
......
......@@ -8,6 +8,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace DeviceLibrary
{
......@@ -67,6 +68,7 @@ namespace DeviceLibrary
/// 是否在急停中
/// </summary>
public bool isInSuddenDown = false;
public bool IsAlarm = false;
public ServerCommunication ServerCM;
......@@ -197,8 +199,18 @@ namespace DeviceLibrary
}
finally
{
ProcessMsgEvent?.Invoke(Msg.get());
var m = Msg.get();
ProcessMsgEvent?.Invoke(m);
ServerCM.ProcessMsg(m);
//ProcessMoveinfoEvent?.Invoke(MoveInfo.List);
if (m.Find((aa) => aa.msgLevel == MsgLevel.alarm) == null)
{
IsAlarm = false;
}
else
{
IsAlarm = true;
}
Msg.clear();
}
}
......@@ -354,7 +366,7 @@ namespace DeviceLibrary
}
if (IOValue(IO_Type.HasNgBox).Equals(IO_VALUE.LOW))
{
Msg.add(crc.GetString("Res0062", "没有检测到NG料箱"), MsgLevel.warning);
Msg.add(crc.GetString("Res0062", "没有检测到NG料箱"), MsgLevel.alarm);
ok = false;
}
//if (IOValue(IO_Type.HasPrinter).Equals(IO_VALUE.LOW))
......@@ -440,7 +452,7 @@ namespace DeviceLibrary
if (span.TotalSeconds > RobotManage.Config.AirCheckSeconds)
{
ok = false;
Msg.add(crc.GetString("Res0068", "气压不足"), MsgLevel.warning);
Msg.add(crc.GetString("Res0068", "气压不足"), MsgLevel.alarm);
}
}
else
......@@ -457,7 +469,7 @@ namespace DeviceLibrary
{
if (AxisManager.GetAlarmStatus(configMoveAxis.DeviceName, configMoveAxis.GetAxisValue()) == 1)
{
Msg.add($"{configMoveAxis.Explain}:运动报警", MsgLevel.warning);
Msg.add($"{configMoveAxis.Explain}:运动报警", MsgLevel.alarm);
ok = false;
}
}
......
......@@ -38,6 +38,8 @@ namespace DeviceLibrary
Config = (Robot_Config)CSVConfigReader.LoadConfig(Config);
CodeManager.LoadConfig();
IDHIKCamera.LibLogUtil.LogEvent += LibLogUtil_LogEvent;
clampTool = new ClampTool();
if (!clampTool.Open())
{
......@@ -70,6 +72,19 @@ namespace DeviceLibrary
LoadFinishEvent?.Invoke(false, ex.Message);
}
}
private static void LibLogUtil_LogEvent(IDHIKCamera.LibLogEventArg libLogEventArg)
{
if (libLogEventArg.Level <= IDHIKCamera.LibLogLevel.Warning)
{
LogUtil.info(libLogEventArg.Msg);
}
else
{
LogUtil.error(libLogEventArg.Msg);
}
}
public static void LoadDebug()
{
LoadFinishEvent?.Invoke(true, crc.GetString("Res0190", "打开配置模式"));
......
......@@ -49,6 +49,10 @@
<Reference Include="HuichuanLibrary">
<HintPath>..\dll\HuichuanLibrary.dll</HintPath>
</Reference>
<Reference Include="IDHIKCamera, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dll\IDHIKCamera.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
</Reference>
......
......@@ -168,13 +168,19 @@ namespace DeviceLibrary
Bitmap bmp = null;
try
{
int retry = 0;
bool nohalcon = true;
retry:
_ = Camera._cam.CaptureOnImage(cameraName, out bmp, out List<CodeInfo> codes, nohalcon);
if (bmp == null)
{
LogUtil.error(" 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
LoadCamera(true);
continue;
LogUtil.error(" 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机,重试:"+ retry);
Camera._cam.CloseAll();
//LoadCamera(true);
retry++;
if (retry>2)
continue;
goto retry;
}
bitmapfilename = SaveImageToFile("Ns200", cameraName, bmp);
WebResultCode webResult = null;
......
......@@ -58,6 +58,36 @@ namespace DeviceLibrary
return;
SendLineStatus();
}
public void ProcessMsg(List<Msg> msg)
{
if (msg == null)
return;
WarnMsg = string.Join("\r\n", msg.Select(x =>
{
if (x.msgLevel == MsgLevel.warning || x.msgLevel == MsgLevel.alarm)
{
return GetMsgPrefix(x.msgLevel) + x.msgtxt;
}
return null;
}
).Where(x => !string.IsNullOrEmpty(x)));
}
string GetMsgPrefix(MsgLevel msgLevel)
{
switch (msgLevel)
{
case MsgLevel.info:
return "I=";
case MsgLevel.warning:
return "W=";
case MsgLevel.alarm:
return "A=";
}
return "";
}
public void StartConnectServer()
{
serverConnectTimer.Enabled = true;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!