Commit e57b9fab 刘韬

增加取标贴标吹气

1 个父辈 d0fcb671
using log4net;
using ConfigHelper;
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
......@@ -13,9 +14,32 @@ using System.Windows.Forms.Layout;
namespace OnlineStore
{
public class CrcObject {
public string msg;
public string key;
public CrcObject(string key, string msg)
{
this.key = key;
this.msg = msg;
}
public override string ToString()
{
return msg.ToString();
}
public static implicit operator string(CrcObject m1)
{
if (m1 == null)
return null;
return m1.msg;
}
}
public class crc : CodeResourceControl
{
}
public class CodeResourceControl
{
......@@ -166,12 +190,12 @@ namespace OnlineStore
{
return GetString(id.ToString(), defaultStr);
}
public static string GetString(string id, string defaultStr)
public static CrcObject GetString(string id, string defaultStr)
{
string strCurLanguage = defaultStr;
var haslang = getLangRes(CurrLanguage);
if (!haslang) {
return strCurLanguage;
return new CrcObject(id, strCurLanguage);
}
try
{
......@@ -200,7 +224,7 @@ namespace OnlineStore
{
strCurLanguage = "";
}
return strCurLanguage;
return new CrcObject(id, strCurLanguage);
}
public static string GetString(string id, string defaultStr, params object[] param)
{
......@@ -314,7 +338,7 @@ namespace OnlineStore
var newStr = GetString(GetTextIdStr(className, con.Name), txt);
if (!newStr.Equals(""))
{
Con_SetTxt(con, newStr.Replace("\\n", "\n"));
Con_SetTxt(con, newStr.ToString().Replace("\\n", "\n"));
//haslang = true;
}
}
......
......@@ -35,6 +35,8 @@ namespace OnlineStore.Common
public static MyConfig<string> Device_DauxiKS107_Port = "COM3";
[MyConfigComment("RFID IP")]
public static MyConfig<string> Device_RFID_IP = "192.168.110.21";
[MyConfigComment("RFID IP2")]
public static MyConfig<string> Device_RFID_IP2 = "192.168.110.21";
[MyConfigComment("是否启用校准库位")]
public static MyConfig<bool> Device_Use_Fixpos = false;
[MyConfigComment("屏蔽日志窗口")]
......
......@@ -291,6 +291,8 @@ namespace OnlineStore.Common
public static string disable = "disable";
public static string queueTaskCount="queueTaskCount";
public static string selfAudit = "selfAudit";
public static string selfAuditException = "selfAuditException";
public static string inDoorStatus= "inDoorStatus";
public static string outDoorStatus= "outDoorStatus";
public static string open= "open";
......
......@@ -107,7 +107,7 @@
<Compile Include="theMachine\MainMachine _AutoInOutTest.cs" />
<Compile Include="theMachine\MainMachine_Labeling.cs" />
<Compile Include="theMachine\MainMachine_RFIDSelftest.cs" />
<Compile Include="theMachine\MainMachine_StoreDemo.cs" />
<Compile Include="theMachine\MainMachine_Store.cs" />
<Compile Include="theMachine\MainMachine _IOMonitor.cs" />
<Compile Include="theMachine\MainMachine _LedProcess.cs" />
<Compile Include="theMachine\MainMachine.cs" />
......
using OnlineStore.Common;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
......@@ -36,6 +37,9 @@ namespace DeviceLibrary
Msg = "";
string portName = Config.DeviceName;
short slvAddr = Config.GetAxisValue();
if (AxisManager.IsServeoOn(portName, slvAddr)) {
return true;
}
AxisManager.AlarmClear(portName, slvAddr);
Thread.Sleep(50);
AxisManager.ServoOn(portName, slvAddr);
......@@ -79,7 +83,7 @@ namespace DeviceLibrary
else
{
AxisManager.ServoOff(portName, slvAddr);
msg = "打开轴" + Config.Explain + "失败 ";
msg = crc.GetString("Res0158.2bf5c941","打开轴") + Config.Explain + crc.GetString("Res0159.33d2a704","失败 ");
LogUtil.info(AxisName + msg);
return false;
}
......@@ -128,7 +132,7 @@ namespace DeviceLibrary
if (ForceSafeCheck && !IsSafe(targetPosition,out string msg))
{
Msg.add(msg, MsgLevel.alarm);
Msg.add(Config.ProName,msg, MsgLevel.alarm);
RobotManage.UserPause(msg);
return;
}
......@@ -158,7 +162,7 @@ namespace DeviceLibrary
if (ForceSafeCheck && !IsSafe(targetPosition, out string msg))
{
Msg.add(msg, MsgLevel.alarm);
Msg.add(Config.ProName, msg, MsgLevel.alarm);
LogUtil.info(AxisName + $" 不在安全点无法运行:{msg}");
RobotManage.UserPause(msg);
return false;
......@@ -224,7 +228,7 @@ namespace DeviceLibrary
int isAlarm = AxisManager.GetAlarmStatus(deviceName, axisNo);
if (isAlarm.Equals(1))
{
clearMsg = "清理报警,";
clearMsg = crc.GetString("Res0160.cbd5d752","清理报警,");
AxisManager.AlarmClear(deviceName, axisNo);
Thread.Sleep(200);
AxisManager.ServoOn(deviceName, axisNo);
......@@ -273,7 +277,7 @@ namespace DeviceLibrary
}
else
{
msg = MoveInfo.Name + " " + MoveInfo.MoveStep + axis.DisplayStr + ",收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警";
msg = MoveInfo.Name + " " + MoveInfo.MoveStep + axis.DisplayStr + crc.GetString("Res0161.405c5a9e",",收到原点完成信号,当前位置[") + outCount + crc.GetString("Res0162.6658614e","],误差过大,需要报警");
LogUtil.error(msg);
}
}
......@@ -467,4 +471,4 @@ namespace DeviceLibrary
}
}
}
\ No newline at end of file
using OnlineStore.Common;
using OnlineStore;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Ports;
using System.Linq;
using System.Text;
......@@ -17,13 +19,12 @@ public class DauxiKS107Controller
private SerialPort _serialPort = null;
string comPortName;
System.Timers.Timer timer;
public bool IsAlarm;
public int Distance;
public DauxiKS107Controller()
{
timer = new System.Timers.Timer(5*60*1000);
timer = new System.Timers.Timer(5*1000);
timer.Elapsed += Timer_Elapsed;
timer.AutoReset = true;
IsAlarm = false;
}
~DauxiKS107Controller() {
LogUtil.info($"液位传感器退出");
......@@ -34,11 +35,29 @@ public class DauxiKS107Controller
}
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Quary(out int value, out string errmsg);
LogUtil.info($"读取到液位:{value}mm,err:{errmsg}");
if (value > 0)
bool readok = true;
for (int i = 0; i < 5; i++)
{
IsAlarm = value < 180;
if (Quary(out int value, out string errmsg))
{
Debug.WriteLine($"读取到液位:{value}mm,err:{errmsg}");
readok = true;
if (value > 0)
{
Distance = value;
return;
}
}
else {
readok = false;
}
}
if (!readok)
{
LogUtil.info($"液位传感器读取失败,重新打开");
if (!OpenPort(comPortName, out string errmsg)) {
LogUtil.info($"液位传感器打开失败:"+ errmsg);
}
}
}
......@@ -50,14 +69,19 @@ public class DauxiKS107Controller
{
comPortName = _comport;
_serialPort = new SerialPort(comPortName, baudRate, parity, dataBits, stopBits);
_serialPort.RtsEnable = true; //自动请求
_serialPort.ReadTimeout = 100;//超时
errmsg = "";
bool ok = false;
//如果串口是打开的,先关闭
if (_serialPort == null)
{
_serialPort = new SerialPort(comPortName, baudRate, parity, dataBits, stopBits);
_serialPort.RtsEnable = true; //自动请求
_serialPort.ReadTimeout = 100;//超时
}
if (_serialPort.IsOpen)
_serialPort.Close();
errmsg = "";
bool ok = false;
try
{
//打开串口
......@@ -84,7 +108,7 @@ public class DauxiKS107Controller
static byte[] quarycommand = new byte[] { 0xe8, 0x02, 0xb0 };
public bool Quary(out int value, out string errmsg) {
errmsg = "";
byte[] buf = new byte[50];
byte[] buf = new byte[8];
value = 0;
try
{
......@@ -98,6 +122,7 @@ public class DauxiKS107Controller
}
else
{
errmsg = crc.GetString("Res0170.6832e9a0","返回数据不正确:")+BitConverter.ToString(buf);
return false;
}
}
......@@ -108,4 +133,3 @@ public class DauxiKS107Controller
return true;
}
}
......@@ -32,6 +32,7 @@ namespace DeviceLibrary
upspeed = _upspeed;
StrokeLength = _StrokeLength;
SafetyDevice.AddDevice(this);
TurnWork = Task.Run(() => { });
}
public bool isAtTOP
{
......
......@@ -32,7 +32,8 @@ namespace DeviceLibrary
string WarnMsg = "";
private System.Timers.Timer serverConnectTimer = new System.Timers.Timer();
public bool selfAudit = false;
public bool selfAuditException = false;
object serverclock = new object();
public ServerCommunication()
{
......@@ -347,7 +348,20 @@ namespace DeviceLibrary
queueTaskCount = -1;
}
}
if (dataMap.ContainsKey(ParamDefine.selfAudit))
{
if (!string.IsNullOrEmpty(dataMap[ParamDefine.selfAudit].ToString()))
selfAudit = true;
}
else
selfAudit = false;
if (dataMap.ContainsKey(ParamDefine.selfAuditException))
{
if (dataMap[ParamDefine.selfAuditException].ToString()=="true")
selfAuditException = true;
}
else
selfAuditException = false;
if (dataMap.ContainsKey(ParamDefine.openInLock) && dataMap[ParamDefine.openInLock].Equals(ParamDefine.doit))
{
......@@ -359,11 +373,19 @@ namespace DeviceLibrary
{
LogUtil.info(StoreName + "收到服务器命令:closeInLock=doit");
IOManager.IOMove(IO_Type.Entry_Drawer_Lock, IO_VALUE.HIGH);
RobotManage.mainMachine.NGInfoList = new List<ReelParam>();
Setting_Init.Runtime_NGINFOLIST = JsonConvert.SerializeObject(RobotManage.mainMachine.NGInfoList);
RobotManage.mainMachine.StoreMoveInfo.NewMove(MoveStep.StoreIn01);
RobotManage.mainMachine.StoreMoveInfo.log(StoreName + " 服务器锁定抽屉,开始入库");
result = "";
if (!selfAuditException)
{
RobotManage.mainMachine.newDrawer = false;
RobotManage.mainMachine.NGInfoList = new List<ReelParam>();
Setting_Init.Runtime_NGINFOLIST = JsonConvert.SerializeObject(RobotManage.mainMachine.NGInfoList);
RobotManage.mainMachine.StoreMoveInfo.NewMove(MoveStep.StoreIn01);
RobotManage.mainMachine.StoreMoveInfo.log(StoreName + " 服务器锁定抽屉,开始入库");
}
else
{
RobotManage.mainMachine.StoreMoveInfo.log(StoreName + " 服务器锁定抽屉,有自检错误,不允许入库");
result = crc.GetString("Res0171.14f1eca7","有自检错误,仅锁入库抽屉");
}
}
if (dataMap.ContainsKey(ParamDefine.openOutLock) && dataMap[ParamDefine.openOutLock].Equals(ParamDefine.doit))
......@@ -412,7 +434,7 @@ namespace DeviceLibrary
&& RobotManage.mainMachine.StoreMoveInfo.MoveStep == MoveStep.Wait)
{
map[ParamDefine.inDoorStatus] = ParamDefine.close;
}else if (IOManager.IOValue(IO_Type.Entry_Drawer_Lock).Equals(IO_VALUE.LOW)
}else if ((RobotManage.mainMachine.newDrawer || IOManager.IOValue(IO_Type.Entry_Drawer_Lock).Equals(IO_VALUE.LOW))
&& RobotManage.mainMachine.StoreMoveInfo.MoveStep == MoveStep.Wait)
{
map[ParamDefine.inDoorStatus] = ParamDefine.open;
......@@ -554,7 +576,17 @@ namespace DeviceLibrary
}
else
{
RobotManage.mainMachine.AddOutStoreTask(code.ToString(), posId);
var ngReel = false;
object ngMsg = "";
if (data.ContainsKey("ngReel") && data["ngReel"].ToString().ToLower() == "true")
{
ngReel = true;
data.TryGetValue("ngMsg", out ngMsg);
}
RobotManage.mainMachine.AddOutStoreTask(code.ToString(), posId, ngReel, ngMsg.ToString());
}
}
TimeSpan span = DateTime.Now - time;
......@@ -633,6 +665,103 @@ namespace DeviceLibrary
}
return msg;
}
public JobInfo SelfAudit_getNetPos()
{
string msg = "";
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("cid", CID);
string server = GetAddr("/rest/device/selfAudit/getNetPos", paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.info("SelfAudit:" + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
ResultData data = JsonHelper.DeserializeJsonToObject<ResultData>(resultStr);
if (data == null)
{
return null;
}
else if (data.code.Equals(0).Equals(false))
{
return null;
}
try
{
//data 中包含:posName 库位号,barcode 条码,batchNo 盘点批次号
var d = JsonConvert.DeserializeObject<Dictionary<string, string>>(data.data.ToString());
var posName = d["posName"];
var barcode = d["barcode"];
var batchNo = d["batchNo"];
var j = new JobInfo(barcode, posName);
j.batchNo = batchNo;
return j;
}
catch (Exception ex) {
LogUtil.info("SelfAudit:" + data.data.ToString());
return null;
}
}
catch (Exception ex)
{
LogUtil.error("SelfAudit: " + ex.ToString());
}
return null;
}
public string SelfAudit_posOutEnd(string posName)
{
string msg = "";
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("posName", posName);
string server = GetAddr("/rest/device/selfAudit/posOutEnd", paramMap);
string resultStr = HttpHelper.Post(server, "");
ResultData data = JsonHelper.DeserializeJsonToObject<ResultData>(resultStr);
if (data == null)
return msg = " DisabledPos【 " + posName + "】 没有收到服务器反馈";
else if (data.code.Equals(0).Equals(false))
return msg = " DisabledPos【 " + posName + "】 :" + data.msg;
return "";
}
catch (Exception ex)
{
LogUtil.error("DisabledPos: " + ex.ToString());
}
return msg;
}
public string SelfAudit_posSelfAuditEnd(string posName,string barcode,string actualBarcode)
{
string msg = "";
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("posName", posName);
paramMap.Add("barcode", barcode);
paramMap.Add("actualBarcode", actualBarcode);
string server = GetAddr("/rest/device/selfAudit/posSelfAuditEnd", paramMap);
string resultStr = HttpHelper.Post(server, "");
ResultData data = JsonHelper.DeserializeJsonToObject<ResultData>(resultStr);
if (data == null)
return msg = " posSelfAuditEnd【 " + posName + "】没有收到服务器反馈";
else if (data.code.Equals(0).Equals(false))
return msg = " posSelfAuditEnd【 " + posName + "】:" + data.msg;
return resultStr;
}
catch (Exception ex)
{
LogUtil.error("DisabledPos: " + ex.ToString());
}
return msg;
}
private static string GetAddr(string addr, Dictionary<string, string> paramsMap)
{
if (server.EndsWith("/"))
......
......@@ -28,7 +28,7 @@ namespace DeviceLibrary
public event Action<string, StoreMoveType, bool> InOutEndProcessEvent;
public bool IsComplateOrFree { get => MoveInfo.MoveStep == MoveStep.Wait && !movelock; }
public bool IsTakedReel { get => MoveInfo.MoveStep >= MoveStep.StoreTS20; }
public bool IsTakedReel { get => MoveInfo.MoveStep >= MoveStep.StoreTS20 || MoveInfo.MoveStep == MoveStep.Wait; }
public bool IsPutOnOut {get=> MoveInfo.MoveStep >= MoveStep.StoreTS16; }
public ReelTransport(Robot_Config _Config, MainMachine _mainMachine)
......@@ -57,12 +57,15 @@ namespace DeviceLibrary
bool ignoreFixtureCheck = false;
int ToCheckOffset = 0;
int FromCheckOffset = 0;
public bool isSelfAudit = false;
public bool CheckHasMatetial = false;
public bool Start(BoxStorePosition from, BoxStorePosition to, StoreMoveType _storeMoveType, bool premove=false)
{
if (MoveInfo.MoveStep != MoveStep.Wait)
return false;
isSelfAudit = false;
CheckHasMatetial = false;
ignoreFixtureCheck = false;
storeMoveType = _storeMoveType;
PreMove = premove;
......@@ -113,6 +116,7 @@ namespace DeviceLibrary
IgnoreX09 = false;
MoveInfo.NextMoveStep(MoveStep.StoreTS02);
MoveInfo.log($"{storeMoveType}:开始");
CheckPosStatus(MoveInfo, From.posid, true);
break;
case MoveStep.StoreTS02:
MoveInfo.NextMoveStep(MoveStep.StoreTS03);
......@@ -138,25 +142,38 @@ namespace DeviceLibrary
if (CheckPosStatus(MoveInfo, From.posid))
{
MoveInfo.NextMoveStep(MoveStep.StoreTS05);
var zp2 = From.Z_Axis_P3 - 205000;
if (zp2 < 0)
zp2 = 0;
Z_Axis.AbsMove(MoveInfo, zp2, Config.Z_Axis_P1_speed);
MoveInfo.log($"{storeMoveType}:Z轴到达取料前点,{From.Z_Axis_P2}");
if (From.posid != MainMachine.LabelP)
{
var zp2 = From.Z_Axis_P3 - 205000;
if (zp2 < 0)
zp2 = 0;
Z_Axis.AbsMove(MoveInfo, zp2, Config.Z_Axis_P1_speed);
MoveInfo.log($"{storeMoveType}:Z轴到达取料前点,{From.Z_Axis_P2}");
}
RobotManage.mainMachine.CylinderMove(MoveInfo, IO_Type.Taking_Release, IO_Type.Taking_Clamp, IO_VALUE.LOW);
MoveInfo.log($"{storeMoveType}:松开夹爪");
IgnoreX09 = false;
}
break;
case MoveStep.StoreTS05:
if (!ignoreFixtureCheck && FromCheckOffset > 0 && !IgnoreX09 && IOManager.IOValue(FromCheckOffset > 0 ? IO_Type.Taking_Left_Check : IO_Type.Taking_Right_Check).Equals(IO_VALUE.LOW))
if (!ignoreFixtureCheck && FromCheckOffset != 0 && !IgnoreX09 && IOManager.IOValue(FromCheckOffset > 0 ? IO_Type.Taking_Left_Check : IO_Type.Taking_Right_Check).Equals(IO_VALUE.LOW))
{
Msg.add(crc.GetString("Res0062", "取料时没有检测到物料信号,请检查."), MsgLevel.alarm, ErrInfo.X09_BoxNotDetect);
MoveInfo.log($"取料时没有检测到物料信号,请检查.");
RobotManage.UserPause(crc.GetString("Res0063", "取料时没有检测到物料信号,请检查"));
if (isSelfAudit)
{
CheckHasMatetial = false;
MoveInfo.log($"{storeMoveType}:自检时没有检测到物料");
MoveInfo.NextMoveStep(MoveStep.StoreTS26);
}
else
{
Msg.add(crc.GetString("Res0062", "取料时没有检测到物料信号,请检查."), MsgLevel.alarm, ErrInfo.X09_BoxNotDetect);
MoveInfo.log($"取料时没有检测到物料信号,请检查.");
//RobotManage.UserPause(crc.GetString("Res0063", "取料时没有检测到物料信号,请检查"));
}
}
else
{
CheckHasMatetial = true;
Msg.add("", MsgLevel.info, ErrInfo.X09_Clear);
IgnoreX09 = false;
MoveInfo.NextMoveStep(MoveStep.StoreTS06);
......@@ -203,6 +220,7 @@ namespace DeviceLibrary
break;
case MoveStep.StoreTS20:
MoveInfo.NextMoveStep(MoveStep.StoreTS21);
CheckPosStatus(MoveInfo, To.posid,true);
Y_Axis.AbsMove(MoveInfo, To.Y_Axis_P2 + ToCheckOffset, Config.Y_Axis_P1_speed);
X_Axis.AbsMove(MoveInfo, To.X_Axis_P2, Config.X_Axis_P1_speed);
MoveInfo.log($"{storeMoveType}:XY轴到达目的地检测,X:{To.X_Axis_P2},Y:{To.Y_Axis_P2}+{ToCheckOffset}");
......@@ -235,20 +253,24 @@ namespace DeviceLibrary
zp2 = 0;
Z_Axis.AbsMove(MoveInfo, zp2, Config.Z_Axis_P1_speed);
}
else if (To.posid == MainMachine.LabelP)
{
RobotManage.mainMachine.FlipEquip.LiftUp(MoveInfo);
}
break;
case MoveStep.StoreTS23:
if (!ignoreFixtureCheck && ToCheckOffset > 0 && IOManager.IOValue(ToCheckOffset > 0 ? IO_Type.Taking_Left_Check : IO_Type.Taking_Right_Check).Equals(IO_VALUE.HIGH))
{
Msg.add(crc.GetString("Res0064", "放料时发现库位已经有料,请检查."), MsgLevel.alarm);
MoveInfo.log($"放料时发现库位已经有料,请检查.");
RobotManage.UserPause(crc.GetString("Res0065", "放料时发现库位已经有料,请检查"));
//RobotManage.UserPause(crc.GetString("Res0065", "放料时发现库位已经有料,请检查"));
}
else
{
Msg.add("", MsgLevel.info, ErrInfo.X09_Clear);
IgnoreX09 = false;
MoveInfo.NextMoveStep(MoveStep.StoreTS24);
MoveInfo.log($"{storeMoveType}:检测料");
MoveInfo.log($"{storeMoveType}:检测有无物料,有物料");
}
break;
......@@ -298,7 +320,7 @@ namespace DeviceLibrary
else
{
MoveInfo.log($"{storeMoveType}:XY返回待机点");
Y_Axis.AbsMove(MoveInfo, Config.Y_Axis_P1, Config.Y_Axis_P1_speed);
//Y_Axis.AbsMove(MoveInfo, Config.Y_Axis_P1, Config.Y_Axis_P1_speed);
X_Axis.AbsMove(MoveInfo, Config.X_Axis_P1, Config.X_Axis_P1_speed);
}
MoveInfo.log($"{storeMoveType}:完成放料");
......@@ -319,7 +341,7 @@ namespace DeviceLibrary
return false;
}
bool CheckPosStatus(MoveInfo moveInfo,string posid) {
bool CheckPosStatus(MoveInfo moveInfo,string posid,bool precheck=false) {
if (posid.StartsWith("L"))
{
if (IOManager.IOValue(IO_Type.Entry_Drawer).Equals(IO_VALUE.HIGH) &&
......@@ -372,7 +394,7 @@ namespace DeviceLibrary
return true;
else
{
RobotManage.mainMachine.TPMove.ToLow(moveInfo);
RobotManage.mainMachine.TPMove.ToLow(precheck?null:moveInfo);
moveInfo.log($"{posid},上层库位移至左侧");
return false;
}
......@@ -383,7 +405,7 @@ namespace DeviceLibrary
return true;
else
{
RobotManage.mainMachine.TPMove.ToHigh(moveInfo);
RobotManage.mainMachine.TPMove.ToHigh(precheck ? null : moveInfo);
moveInfo.log($"{posid},上层库位移至右侧");
return false;
}
......@@ -394,7 +416,7 @@ namespace DeviceLibrary
return true;
else
{
RobotManage.mainMachine.TPMove.ToLow(moveInfo);
RobotManage.mainMachine.TPMove.ToLow(precheck ? null : moveInfo);
moveInfo.log($"{posid},上层库位移至左侧");
return false;
}
......
......@@ -7,16 +7,19 @@ using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace DeviceLibrary
{
[Serializable]
public enum TestStorePointPort {
入口, 出口, 上层左侧, 上层右侧, 下层左侧, 下层右侧,贴标
入口, 出口, 上层左侧, 上层右侧, 下层左侧, 下层右侧,贴标,接标台
}
[Serializable]
public class tstoredata {
......@@ -69,7 +72,8 @@ namespace DeviceLibrary
Dictionary<int, string> ngmsglist = new Dictionary<int, string>();
RobotManage.mainMachine.NGInfoList.ForEach(ng=> {
var sindex = RobotManage.AllPositionMapNumList.IndexOf(ng.PosID)-startindex;
ngmsglist.Add(sindex, ng.NgMsg);
if (!ngmsglist.ContainsKey(sindex))
ngmsglist.Add(sindex, ng.NgMsg);
});
int index = 0;
for (int i = 0; i < 5; i++) {
......@@ -150,7 +154,7 @@ namespace DeviceLibrary
List<Point> points = CameraData[Name].ObjectPoint;
if (bmp == null)
return new List<int>(points.Count);
return Enumerable.Repeat(0, points.Count).ToList();
List<int> haslist = new List<int>();
BitmapData bd=null;
......@@ -217,6 +221,87 @@ namespace DeviceLibrary
TestStorePointEvent?.Invoke(tp, bmp);
return haslist;
}
public static TestStorePointPort GetTestStorePointPort(string posname) {
TestStorePointPort testStorePointPort;
if (Regex.IsMatch(posname, "^S[A-G]"))
testStorePointPort= TestStorePointPort.上层左侧;
else if (Regex.IsMatch(posname, "^S[H-N][1-6]$"))
testStorePointPort = TestStorePointPort.下层左侧;
else
testStorePointPort = TestStorePointPort.下层右侧;
LogUtil.info($"GetTestStorePointPort: {posname}={testStorePointPort}");
return testStorePointPort;
}
/// <summary>
/// 检测标签是否被取走
/// </summary>
/// <returns></returns>
public static bool TestHasLabelOnDock(bool checkstatus) {
var r = CameraPointTest.CameraData[TestStorePointPort.接标台.ToString()].PointList;
Point checkpoint = r[0];
var bmp = RobotManage.CameraA.GetImage(0);
if (bmp == null)
return true;
//bmp = new Bitmap("d:\\新建分组1_监控点1_106_20220818172856_3997146.bmp");
BitmapData bd = null;
try
{
bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat);
var p = checkpoint;
p.X = p.X - 8;
p.Y = p.Y - 8;
var cl = new List<ColorHSV>();
for (int j = 0; j < 16; j++)
{
for (int k = 0; k < 16; k++)
{
var x = p.X + j;
var y = p.Y + k;
var addr = y * bd.Stride + x * 4;
var cr = Marshal.ReadByte(bd.Scan0, addr + 2);
var cg = Marshal.ReadByte(bd.Scan0, addr + 1);
var cb = Marshal.ReadByte(bd.Scan0, addr);
var hh = ColorHelper.RgbToHsv(new ColorRGB(cr, cg, cb));
cl.Add(hh);
}
}
var h = cl.Average(cc => cc.H);
var s = cl.Average(cc => cc.S);
var v = cl.Average(cc => cc.V);
var has = (h>180 && h<260) || s<10;
has = s < 15;
LogUtil.info($"TestHasLabelOnDock checkstatus:{checkstatus}, h:{h},s:{s},v:{v},config_s:{CameraData[TestStorePointPort.接标台.ToString()].S}");
if (has != checkstatus)
{
Directory.CreateDirectory("\\image\\LabelDock");
bmp.Save("\\image\\LabelDock\\"+ checkstatus +"_"+ DateTime.Now.ToString("yyyyMMddHHmmss")+".jpg");
}
return has;
}
catch (AccessViolationException ex)
{
LogUtil.error("TestHasLabelOnDock AccessViolationException:" + ex.ToString());
}
catch (Exception ex)
{
LogUtil.error("TestHasLabelOnDock:" + ex.ToString());
}
finally
{
if (bd != null)
bmp.UnlockBits(bd);
}
return false;
}
/// <summary>
/// 按中心点扩展一个矩形区域
/// </summary>
......
using CodeLibrary;
using OnlineStore;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
......@@ -322,6 +323,7 @@ namespace DeviceLibrary
{
public static List<Msg> msg = new List<Msg>();
public string msgtxt;
public string msgkey;
public MsgLevel msgLevel;
public ErrInfo errInfo;
public DateTime datetime;
......@@ -335,13 +337,26 @@ namespace DeviceLibrary
List<Msg> mm = new List<Msg>(msg);
return mm;
}
public static void add(string m, MsgLevel ml, ErrInfo errInfo= ErrInfo.Empty)
public static void add(string m, MsgLevel ml, ErrInfo errInfo = ErrInfo.Empty)
{
lock (msg)
{
var fm = msg.Find((x) => x.msgtxt == m);
if (fm==null)
msg.Add(new Msg { msgtxt = m, msgLevel = ml, datetime = DateTime.Now, errInfo = errInfo });
if (fm == null)
msg.Add(new Msg { msgtxt = m, msgkey = "", msgLevel = ml, datetime = DateTime.Now, errInfo = errInfo });
}
}
public static void add(CrcObject m, MsgLevel ml, ErrInfo errInfo= ErrInfo.Empty)
{
add(m.key, m.msg, ml, errInfo);
}
public static void add(string key,string m, MsgLevel ml, ErrInfo errInfo = ErrInfo.Empty)
{
lock (msg)
{
var fm = msg.Find((x) => x.msgtxt == m);
if (fm == null)
msg.Add(new Msg { msgtxt = m, msgkey = key, msgLevel = ml, datetime = DateTime.Now, errInfo = errInfo });
}
}
static bool _setlogones = false;
......
......@@ -79,6 +79,10 @@ namespace DeviceLibrary
/// 料盘高
/// </summary>
public int plateH { get; set; }
public string batchNo { get; set; }
public bool isNG { get; set; }
public string NgMsg { get; set; }
public string ToStr()
{
......
......@@ -48,7 +48,7 @@ namespace DeviceLibrary
MoveInfo.WaitList.ForEach((w) => {
if (w.WaitType.Equals(WaitEnum.W014_Msg)) {
w.IsEnd = true;
Msg.add(w.ActionMsg, w.Data);
Msg.add("WaitType."+ w.WaitType, w.ActionMsg, w.Data);
}
});
foreach (WaitResultInfo wait in MoveInfo.WaitList)
......@@ -78,7 +78,7 @@ namespace DeviceLibrary
isOk = false;
WarnMsg = msg;
///Alarm(AlarmType.AxisMoveError, WarnMsg);
Msg.add(WarnMsg, MsgLevel.alarm);
Msg.add("WaitType."+wait.WaitType,WarnMsg, MsgLevel.alarm);
RobotManage.UserPause(WarnMsg);
break;
}
......@@ -118,7 +118,7 @@ namespace DeviceLibrary
else if (wait.WaitType.Equals(WaitEnum.W013_Action))
{
wait.IsEnd = wait.Action.Invoke(wait);
LogUtil.info($"{Name} 自定义等待 IsEnd={wait.IsEnd},Type={wait.Action.GetType()}");
LogUtil.info($"{Name} 自定义等待 IsEnd={wait.IsEnd},Msg={wait.ActionMsg}");
}
else if (wait.WaitType.Equals(WaitEnum.W008_BatchAxis))
{
......@@ -183,7 +183,7 @@ namespace DeviceLibrary
}
else if (span.TotalSeconds > MoveInfo.TimeOutSeconds)
{
WarnMsg = MoveInfo.Name + "[" + MoveInfo.MoveStep + "]" + "等待" + "}" + NotOkMsg + "超时" + "[" + Math.Round(span.TotalSeconds, 1) + "]" + "秒";
WarnMsg = MoveInfo.Name + "[" + MoveInfo.MoveStep + "]" + "等待" + "}" + NotOkMsg + "超时";
int second = (int)(MoveInfo.TimeOutSeconds / span.TotalSeconds) * 10;
if (second > 120)
......@@ -197,7 +197,7 @@ namespace DeviceLibrary
LogUtil.error(WarnMsg, logType + 100, second);
//MoveInfo.errlog(WarnMsg);
//Alarm(AlarmType.IoSingleTimeOut, WarnMsg);
Msg.add(WarnMsg, MsgLevel.alarm);
Msg.add("MoveStep.",WarnMsg, MsgLevel.alarm);
}
return true;
}
......@@ -259,8 +259,8 @@ namespace DeviceLibrary
// return;
(IoLowType, IoHighType) = (IoHighType, IoLowType);
}
//if (IOManager.DOValue(IoHighType).Equals(IO_VALUE.HIGH))
// return;
if (IOManager.IOValue(IoHighType).Equals(IO_VALUE.HIGH) && IOManager.IOValue(IoLowType).Equals(IO_VALUE.LOW))
return;
IOMove(IoLowType, IO_VALUE.LOW);
IOMove(IoHighType, IO_VALUE.HIGH);
if (moveInfo != null)
......@@ -270,7 +270,7 @@ namespace DeviceLibrary
}
}
public IO_VALUE IOValue(string ioType) => IOManager.IOValue(ioType);
void IOMove(string IoType, IO_VALUE value, bool isCheck = false, int msTime = 0)
public void IOMove(string IoType, IO_VALUE value, bool isCheck = false, int msTime = 0)
{
if (msTime <= 0)
{
......
......@@ -42,6 +42,12 @@ namespace DeviceLibrary
//{
// RightDoorOpen = false;
//}
if (RobotManage.dauxiKS107.Distance < 180) {
Msg.add(crc.GetString("Res0163.f6ad5099","冷凝液回收桶已满"), MsgLevel.warning);
}
if (IOValue(IO_Type.Airpressure_Check).Equals(IO_VALUE.LOW)) {
Msg.add(crc.GetString("Res0079","未检测到气压信号."), MsgLevel.warning);
}
......
......@@ -131,6 +131,7 @@ namespace DeviceLibrary
Labeling50,
Labeling51,
Labeling52,
Labeling52_2,
Labeling53,
Labeling54,
Labeling55,
......
......@@ -79,6 +79,7 @@ namespace DeviceLibrary
//public static HIKCamera CameraD=new HIKCamera();
public static DauxiKS107Controller dauxiKS107 = new DauxiKS107Controller();
public static PuYueRFID_FR540SP_C2S RFID = new PuYueRFID_FR540SP_C2S();
public static PuYueRFID_FR540SP_C2S RFID2 = new PuYueRFID_FR540SP_C2S();
public static PrinterHelper printerHelper = new PrinterHelper();
public static void Init() {
string msg = "";
......@@ -147,6 +148,14 @@ namespace DeviceLibrary
else
{
CameraA.Open();
for (int i = 0; i < 4;i++) {
if (CameraA.GetImage(i) == null)
{
msg += string.Format(crc.GetString("Res0176.7352b919","第{0}个相机打开失败"), i) + "\r\n";
IsLoadOk = false;
}
}
}
mainMachine = new MainMachine(RobotManage.Config);
if (!dauxiKS107.OpenPort(Setting_Init.Device_DauxiKS107_Port, out _)) {
......@@ -172,7 +181,17 @@ namespace DeviceLibrary
}
else
LogUtil.info("RFID连接成功,IP:"+ Setting_Init.Device_RFID_IP);
//RFID.Init();
RFID2.IP = Setting_Init.Device_RFID_IP2;
RFID2.Open(Setting_Init.Device_RFID_IP2);
if (!RFID2.IsConn)
{
IsLoadOk = false;
msg += crc.GetString("Res0142","RFID2连接失败,IP:") + $"{Setting_Init.Device_RFID_IP2}\n";
}
else
LogUtil.info("RFID2连接成功,IP:"+ Setting_Init.Device_RFID_IP2);
//RFID.AntennaPower = 4;
IOManager.IOMove(IO_Type.Camera_Led, IO_VALUE.HIGH);
......
......@@ -287,6 +287,11 @@ namespace DeviceLibrary
{
return;
}
if (!currentAxis.IsSafe(0, out string msg))
{
MessageBox.Show(msg);
return;
}
if (btnAddMove.BackColor.Equals(Color.White))
{
int speed = Convert.ToInt32(comjSpeed.Text);
......@@ -316,6 +321,11 @@ namespace DeviceLibrary
{
return;
}
if (!currentAxis.IsSafe(0, out string msg))
{
MessageBox.Show(msg);
return;
}
if (btnDelMove.BackColor.Equals(Color.White))
{
int speed = Convert.ToInt32(comjSpeed.Text);
......
......@@ -83,3 +83,5 @@ DO,0,锡膏旋转定位夹紧气缸夹紧,Tin_Dock_Rotate_Clamp,26,HC,Y26,,,,,,,,,,
DO,0,锡膏翻转机构前进,Tin_Dock_Right,27,HC,Y27,,,,,,,,,,
DO,0,锡膏翻转机构后退,Tin_Dock_Left,28,HC,Y28,,,,,,,,,,
DO,0,标签吸盘取料,Label_Vacuum,29,HC,Y29,,,,,,,,,,
DO,0,标签出标吹气,Label_TakeBlow,30,HC,Y30,,,,,,,,,,
DO,0,标签贴标吹气,Label_PasteBlow,31,HC,Y31,,,,,,,,,,
\ No newline at end of file
......@@ -213,6 +213,15 @@ namespace OnlineStore.LoadCSVLibrary
public static string Label_Vacuum = "Label_Vacuum";
/// <summary>
/// DO,0,标签出标吹气,Label_TakeBlow,30,HC,Y30,,,,,,,,,,
/// </summary>
public static string Label_TakeBlow = "Label_TakeBlow";
/// <summary>
/// DO,0,标签贴标吹气,Label_PasteBlow,31,HC,Y31,,,,,,,,,,
/// </summary>
public static string Label_PasteBlow = "Label_PasteBlow";
}
public enum IO_VALUE
{
......
......@@ -430,10 +430,11 @@ namespace TheMachine
}
else if (msg.errInfo == ErrInfo.LabelInPaste)
{
RobotManage.mainMachine.IOMove(IO_Type.PrinterDoor_Lock, IO_VALUE.LOW);
if (FrmAlarm.ShowAlarmDialog(crc.GetString("Res0143","贴标区内可能有物料未完成贴标,请手动取出")) == DialogResult.OK)
{
{
LogUtil.info("用户确认已处理");
Setting_Init.Runtime_Step = Runtime_StepE.None;
//Setting_Init.Runtime_Step = Runtime_StepE.None;
RobotManage.UserPause(false);
}
else {
......
......@@ -79,6 +79,7 @@ namespace TheMachine
this.Name = "FrmAlarm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "FrmAlarm";
this.Load += new System.EventHandler(this.FrmAlarm_Load);
this.ResumeLayout(false);
}
......
using System;
using OnlineStore;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
......@@ -34,5 +35,10 @@ namespace TheMachine
DialogResult = DialogResult.OK;
Close();
}
private void FrmAlarm_Load(object sender, EventArgs e)
{
crc.LanguageProcess(this);
}
}
}
......@@ -118,7 +118,6 @@ namespace TheMachine
this.button10.TabIndex = 6;
this.button10.Text = "写入RFID EPC";
this.button10.UseVisualStyleBackColor = false;
this.button10.Visible = false;
this.button10.Click += new System.EventHandler(this.button10_Click);
//
// button9
......
......@@ -88,12 +88,23 @@ namespace TheMachine
private void button9_Click(object sender, EventArgs e)
{
var r= RobotManage.RFID.ReOpen();
RobotManage.RFID2.ReOpen();
LogUtil.info("RFID.ReOpen:" + r);
for (int i = 0; i < 6;i++) {
Thread.Sleep(200);
if (RobotManage.RFID.ReadEPC(12,out byte[] data)) {
if (RobotManage.RFID.ReadEPC(16,out byte[] data)) {
if (data[0] != 0xFF)
{
MessageBox.Show(RobotManage.RFID.HexBuff(data) + "\r\n" + Encoding.ASCII.GetString(data).Trim());
MessageBox.Show("RFID:"+Encoding.ASCII.GetString(data).Trim());
return;
}
}
if (RobotManage.RFID2.ReadEPC(16, out data))
{
if (data[0] != 0xFF)
{
MessageBox.Show("RFID2:" + RobotManage.RFID2.HexBuff(data) + "\r\n" + Encoding.ASCII.GetString(data).Trim());
return;
}
}
......@@ -103,16 +114,82 @@ namespace TheMachine
private void button10_Click(object sender, EventArgs e)
{
var epc = InputBox("Write EPC, maximum 16 words.", "Please enter EPC data, maximum 16 words.", "");
var r = RobotManage.RFID.ReOpen();
RobotManage.RFID2.ReOpen();
LogUtil.info("RFID.ReOpen:" + r+",epc="+ epc);
epc = epc.PadRight(16);
RobotManage.RFID.WriteByte(550, new byte[] { 0x40, 0x00 });
Thread.Sleep(300);
var epc = "20418002Z-203";
epc = "20418002Z-20";
epc = epc.PadRight(12);
var result = RobotManage.RFID.WriteEPC(Encoding.ASCII.GetBytes(epc));
result = RobotManage.RFID2.WriteEPC(Encoding.ASCII.GetBytes(epc));
if (result)
{
MessageBox.Show(crc.GetString("Res0144","写入成功"));
return;
}
}
private string InputBox(string Caption, string Hint, string Default)
{
Form InputForm = new Form();
InputForm.MinimizeBox = false;
InputForm.MaximizeBox = false;
InputForm.StartPosition = FormStartPosition.CenterScreen;
InputForm.Width = 360;
InputForm.Height = 150;
//InputForm.Font.Name = "宋体";
//InputForm.Font.Size = 10;
InputForm.Text = Caption;
Label lbl = new Label();
lbl.Text = Hint;
lbl.Left = 10;
lbl.Top = 20;
lbl.Parent = InputForm;
lbl.AutoSize = true;
TextBox tb = new TextBox();
tb.Left = 30;
tb.Top = 45;
tb.Width = 300;
tb.Parent = InputForm;
tb.Text = Default;
tb.SelectAll();
Button btnok = new Button();
btnok.Left = 30;
btnok.Top = 80;
btnok.Parent = InputForm;
btnok.Text = "Ok";
InputForm.AcceptButton = btnok;//回车响应
btnok.DialogResult = DialogResult.OK;
Button btncancal = new Button();
btncancal.Left = 120;
btncancal.Top = 80;
btncancal.Parent = InputForm;
btncancal.Text = "Cancel";
btncancal.DialogResult = DialogResult.Cancel;
try
{
if (InputForm.ShowDialog() == DialogResult.OK)
{
return tb.Text;
}
else
{
return "";
}
}
finally
{
InputForm.Dispose();
}
}
}
}
\ No newline at end of file
using ConfigHelper;
using DeviceLibrary;
using log4net.Config;
using OnlineStore;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
......@@ -25,12 +26,13 @@ namespace TheMachine
static void Main()
{
CameraPointTest.Init();
CameraPointTest.TestHasLabelOnDock(true);
//CameraPointTest.ScanRectangle();
//var bmpfile = @"D:\rick\vs\SO20031_TinStorage\TheMachine\bin\Debug\test.bmp";
//var bmp = new Bitmap(bmpfile);
//var r = CameraPointTest.TestStorePoint(bmp, TestStorePointPort.入口);
_ = new Mutex(true, Application.ProductName, out bool ret);
if (!ret)
{
......
......@@ -133,6 +133,9 @@ namespace TheMachine
haslistStoreName = CameraPointTest.GetThingStoreName(TestStorePointPort.下层右侧);
LogUtil.info("下层右侧:" + string.Join(",", haslistStoreName));
}
var haslabel = CameraPointTest.TestHasLabelOnDock(true);
LogUtil.info("标签台:" + haslabel);
});
RobotManage.mainMachine.ScanCode();
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!