Commit 1f8a322e 几米阳光

IO模块增加重连

1 个父辈 d49e19f7
......@@ -296,7 +296,22 @@ namespace OnlineStore.AutoInOutStore
{
StoreOpenStatus(true);
}
lblThisSta.Text = store.GetRunStr(store.storeRunStatus, true);
StoreRunStatus s = store.storeRunStatus;
if (s.Equals(StoreRunStatus.Runing))
{
if (AutomaticBaiting.StoreMove.MoveType.Equals(StoreMoveType.InStore) ||
AutomaticBaiting.AutoBaitingStatus.Equals(StoreRunStatus.Busy))
{
s = StoreRunStatus.Busy;
}
else if (AutomaticBaiting.StoreMove.MoveType.Equals(StoreMoveType.StoreReset) ||
AutomaticBaiting.AutoBaitingStatus.Equals(StoreRunStatus.Reset))
{
s = StoreRunStatus.Reset;
}
}
lblThisSta.Text = store.GetRunStr(s, true);
//复位按钮状态显示
if (复位ToolStripMenuItem.Enabled == false)
{
......@@ -334,7 +349,10 @@ namespace OnlineStore.AutoInOutStore
{
lblWarnMsg.Text = lblWarnMsg.Text + " 温湿度报警[" + store.TempAlarmTime.ToLongTimeString() + "]";
}
if (ShuoKeControls.CheckErrorCount > 10)
{
lblWarnMsg.Text = lblWarnMsg.Text + " 压紧轴通信异常[" + ShuoKeControls.CheckErrorCount + "]";
}
if (store.autoNext)
{
string msg = store.autoMsg;
......
......@@ -161,11 +161,14 @@ PRO,最后一盘料需要补充的高度,LastTrayAddHeight,10,,,,,,,,,
20190508
复位完成后,增加清料功能。
批量模块在复位过程中,设备不能显示联机状态。
压紧轴需要运动一段时间自动回原点。
复位时自动出入库会清理
IO模块增加重连功能。
......
......@@ -69,13 +69,13 @@ namespace OnlineStore.DeviceLibrary
aioBox.DI_Changed_Event += AioBox_DI_Changed_Event; ;
aioBox.DO_Changed_Event += AioBox_DO_Changed_Event;
aioBox.Log_Out_Event += AioBox_Log_Out_Event;
AIOMap.Add(ioIp, aioBox);
LogUtil.info("开始连接IO模块【" + ioIp + "】,尝试重连三次");
for (int i = 1; i <= 3; i++)
{
bool result = aioBox.Connect();
if (result)
{
AIOMap.Add(ioIp, aioBox);
LogUtil.info("第【"+i+"】次连接IO模块【" + ioIp + "】成功:" + aioBox.ErrInfo);
Thread.Sleep(10);
//读取所有的DO
......@@ -88,7 +88,14 @@ namespace OnlineStore.DeviceLibrary
}
Thread.Sleep(10);
}
if (timer == null)
{
timer = new System.Timers.Timer();
timer.Interval = 5000;
timer.AutoReset = true;
timer.Elapsed += timer_Elapsed;
timer.Enabled = true;
}
}
catch (Exception error)
{
......@@ -210,10 +217,19 @@ namespace OnlineStore.DeviceLibrary
foreach (string io in list)
{
//判断是否连接,如果没有连接自动重连
AIOBOX clinet = AIOMap[io];
if (!clinet.IsConn)
{
LogUtil.error(LOGGER, io + "当前没有连上:" + clinet.ErrInfo);
AIOBOX client = AIOMap[io];
if (!client.IsConn)
{
//重连
bool result = client.Connect();
if (result)
{
LogUtil.info("重连O模块【" + client.IP + "】成功:" + client.ErrInfo);
}
else
{
LogUtil.error("重连O模块【" + client.IP + "】失败:" + client.ErrInfo);
}
}
}
}
......@@ -243,13 +259,7 @@ namespace OnlineStore.DeviceLibrary
ushort u =(ushort)( i + length);
Box_Addr addr = GetAddr(u);
aio.WriteDO(addr, Box_Sta.Off);
}
//Box_Sta[] Box_Staes = new Box_Sta[16];
//for(int i = 0; i < 16; i++)
//{
// Box_Staes[i] = Box_Sta.Off;
//}
// aio.WriteDO( Box_Addr.DI_1, Box_Staes);
}
}
}
......@@ -260,6 +270,8 @@ namespace OnlineStore.DeviceLibrary
aio.Close();
}
AIOMap.Clear();
timer.Stop();
timer = null;
}
public override void WriteSingleDO(string ioIp, byte slaveId, ushort StartAddress, IO_VALUE onOff)
{
......
......@@ -257,8 +257,9 @@ namespace OnlineStore.DeviceLibrary
tcp.disconnect();
}
mastMap.Clear();
mastMap.Clear();
timer.Stop();
timer = null;
}
public static void CloseAllDO(string ioIp, byte slaveId)
{
......
......@@ -40,7 +40,8 @@ namespace OnlineStore.DeviceLibrary
}
try
{
PortName = comPortName;
ShuoKeControls.CheckErrorCount = 0;
PortName = comPortName;
Parity parity = (Parity)tparity;
bean = new AcSerialBean(comPortName, baudRate, parity, 8, stopBits);
bool result = bean.openPort();
......@@ -61,7 +62,8 @@ namespace OnlineStore.DeviceLibrary
}
public static void ClosePort()
{
isRun = false;
ShuoKeControls.CheckErrorCount = 0;
isRun = false;
if (bean == null)
{
return;
......@@ -115,6 +117,7 @@ namespace OnlineStore.DeviceLibrary
else
{
bean.SendCommand(data, ref returnData, outTime, reviceLength);
Thread.Sleep(2);
}
}
catch (Exception ex)
......@@ -124,56 +127,7 @@ namespace OnlineStore.DeviceLibrary
return returnData;
}
private static void DataReceived(string portName, object sender, SerialDataReceivedEventArgs e, byte[] bits)
{
string strSend = "";
for (int i = 0; i < bits.Length; i++)
{
strSend += string.Format("{0:X2} ", bits[i]);
}
if (strSend.Equals(""))
{
return;
}
//校验
ushort pChecksum = 0;
AcSerialBean.CalculateCRC(bits, bits.Length - 2, out pChecksum);
string checkStr = Convert.ToString(pChecksum, 16);
byte[] checkByte = AcSerialBean.StringToByte(checkStr);
if (checkByte.Length == 1)
{
if (!bits[bits.Length - 2].Equals(checkByte[0]))
{
bean.clearInBuffer();
LogUtil.info(LOGGER, " 【" + portName + "】 收到数据【" + strSend + "】,校验错误");
return;
}
}
else
{
if (!bits[bits.Length - 1].Equals(checkByte[0]) || (!bits[bits.Length - 2].Equals(checkByte[1])))
{
bean.clearInBuffer();
LogUtil.info(LOGGER, " 【" + portName + "】 收到数据【" + strSend + "】,校验错误");
return;
}
}
LogUtil.debug(LOGGER, " 【" + portName + "】 收到数据【" + strSend + "】");
int slvAddr = (int)bits[0];
byte cmd = bits[1];
//查询状态
if (cmd.Equals(ShuoKeCMD.SearchMoveStatus))
{
ShuoKeInfo info = DataToStatus(bits);
}
else if (cmd.Equals(ShuoKeCMD.GetAbsPosition))
{
int position = DataToPosition(bits);
}
}
public static int CheckErrorCount = 0;
private static bool CheckByte(byte[] bits)
{
if (bits == null)
......@@ -190,24 +144,32 @@ namespace OnlineStore.DeviceLibrary
AcSerialBean.CalculateCRC(bits, bits.Length - 2, out pChecksum);
string checkStr = Convert.ToString(pChecksum, 16);
byte[] checkByte = AcSerialBean.StringToByte(checkStr);
if (checkByte.Length == 1)
bool isError = false;
if ((checkByte.Length == 1) && (!bits[bits.Length - 2].Equals(checkByte[0])))
{
if (!bits[bits.Length - 2].Equals(checkByte[0]))
isError = true;
}
else if (!bits[bits.Length - 1].Equals(checkByte[0]) || (!bits[bits.Length - 2].Equals(checkByte[1])))
{
isError = true;
}
if (isError)
{
bean.clearInBuffer();
CheckErrorCount++;
if (CheckErrorCount > 10)
{
bean.clearInBuffer();
LogUtil.info(LOGGER, "【" + PortName + "】收到数据【" + strSend + "】校验错误");
return false ;
LogUtil.error( "【" + PortName + "】收到数据后已累计【"+CheckErrorCount+"】次校验错误,通信异常",201);
}
}
else
{
if (!bits[bits.Length - 1].Equals(checkByte[0]) || (!bits[bits.Length - 2].Equals(checkByte[1])))
else
{
bean.clearInBuffer();
LogUtil.info(LOGGER, "【" + PortName + "】收到数据【" + strSend + "】校验错误");
return false ;
LogUtil.error( "【" + PortName + "】收到数据【" + strSend + "】校验错误");
}
}return true;
return false;
}
CheckErrorCount = 0;
return true;
}
private static int DataToPosition(byte[] bits)
{
......
......@@ -106,33 +106,39 @@ namespace OnlineStore.DeviceLibrary
private void IoCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//判断急停
if (storeRunStatus >= StoreRunStatus.HomeMoving)
try
{
if (IOManager.IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
//判断急停
if (storeRunStatus >= StoreRunStatus.HomeMoving)
{
if (isInSuddenDown.Equals(false))
if (IOManager.IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
//LogUtil.error(LOGGER, StoreName + "收到急停信号,等待200后再次判断");
//Thread.Sleep(200);
//if (IOManager.IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
//{
if (isInSuddenDown.Equals(false))
{
//LogUtil.error(LOGGER, StoreName + "收到急停信号,等待200后再次判断");
//Thread.Sleep(200);
//if (IOManager.IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
//{
isInSuddenDown = true;
LogUtil.error(LOGGER, StoreName + "收到急停信号,报警急停");
WarnMsg = StoreName + ResourceControl.GetString(ResourceControl.inSuddenStop, "Receive emergency stop signal, alarm to stop");
//报警时会关闭所有轴
Alarm(StoreAlarmType.SuddenStop, "1", WarnMsg, StoreMoveType.None);
//}
//}
}
}
else
{
//气压检测,如果气压持续3秒没有信号,报气压报警
AirCheckProcess();
//光栅处理
//SafetyLightProcess();
}
}
else
{
//气压检测,如果气压持续3秒没有信号,报气压报警
AirCheckProcess();
//光栅处理
//SafetyLightProcess();
}
}catch(Exception ex)
{
LogUtil.error("IoCheckTimer_Elapsed出错:" + ex.ToString());
}
}
private void AirCheckProcess()
......@@ -900,28 +906,27 @@ namespace OnlineStore.DeviceLibrary
}
private bool InProcess = false;
private bool IsChongfu = false;
private Stopwatch stopwatch = new Stopwatch();
private Stopwatch stopwatch = new Stopwatch();
protected override void timersTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (InProcess)
try
{
if (stopwatch.Elapsed.TotalMinutes < 2.5)
if (InProcess)
{
return;
}
else
{
LogUtil.error("主定时器:InProcess已等待" + stopwatch.Elapsed.ToString() + "重新处理");
IsChongfu = true;
if (stopwatch.Elapsed.TotalMinutes < 2.5)
{
return;
}
else
{
LogUtil.error("主定时器:InProcess已等待" + stopwatch.Elapsed.ToString() + "重新处理");
IsChongfu = true;
}
}
}
InProcess = true;
stopwatch.Restart();
InProcess = true;
stopwatch.Restart();
try
{
IoCheckProcess();
ShowTimeLog("IoCheckProcess");
TimerProcess();
......@@ -1228,7 +1233,7 @@ namespace OnlineStore.DeviceLibrary
else
{
LogUtil.info(LOGGER, StoreName + "已经累计出入库" + CurrInOutACount + "次,需要复位一下");
Reset();
Reset(false);
}
}
//else if (CurrInOutCount >= this.Config.Box_ResetMCount)
......@@ -1261,10 +1266,10 @@ namespace OnlineStore.DeviceLibrary
{
LogUtil.info(LOGGER, StoreName + " 执行排队中的出库【" + currInOutFixture.ToStr() + "】失败,重新加入等待队列");
AddWaitOutInfo(currInOutFixture);
}
}
}
}
else if (autoNext && CanStarInOut() )
else if (autoNext && CanStarInOut())
{
//获取出库的库位号
string readId = "";
......@@ -1282,7 +1287,7 @@ namespace OnlineStore.DeviceLibrary
if (rId.Length > 7)
{
readId = rId.Substring(6, rId.Length - 7);
LogUtil.debug("自动出入库:查找到:RI: " + readId );
LogUtil.debug("自动出入库:查找到:RI: " + readId);
break;
}
}
......@@ -1297,8 +1302,8 @@ namespace OnlineStore.DeviceLibrary
else
{
autoMsg = "自动出库:RI:" + readId;
result = HttpHelper.Post(StoreManager.GetAPI("", StoreManager.api_stackOut)+ "?RIS=" + readId);
LogUtil.info("自动出入库:自动出库:RI: " + readId + " ," + result);
result = HttpHelper.Post(StoreManager.GetAPI("", StoreManager.api_stackOut) + "?RIS=" + readId);
LogUtil.info("自动出入库:自动出库:RI: " + readId + " ," + result);
}
}
}
......@@ -1616,8 +1621,7 @@ namespace OnlineStore.DeviceLibrary
BoxStatus boxStatus = new BoxStatus();
boxStatus.boxId = StoreID;
//状态
boxStatus.status = GetStoreStatus();
boxStatus.msg = WarnMsg;
lineOperation.msg = WarnMsg;
......@@ -1644,8 +1648,8 @@ namespace OnlineStore.DeviceLibrary
}
CodeOrInoutMsg = "";
//WarnMsg = "";
//状态
boxStatus.status = (int)storeStatus;
//状态
boxStatus.status = GetStoreStatus();
if (IsDebug)
{
boxStatus.status = (int)StoreStatus.Debugging;
......@@ -1729,7 +1733,7 @@ namespace OnlineStore.DeviceLibrary
return lineOperation;
}
private int GetStoreStatus()
public int GetStoreStatus()
{
int status = (int)storeStatus;
......@@ -1740,11 +1744,13 @@ namespace OnlineStore.DeviceLibrary
//如果料仓没有出入库,但是自动上下料机构在上料中
if (storeStatus.Equals(StoreStatus.StoreOnline))
{
if (AutomaticBaiting.StoreMove.MoveType.Equals(StoreMoveType.InStore))
if (AutomaticBaiting.StoreMove.MoveType.Equals(StoreMoveType.InStore)||
AutomaticBaiting.AutoBaitingStatus.Equals(StoreRunStatus.Busy))
{
status = (int)StoreStatus.BatchInStore;
}
else if (AutomaticBaiting.StoreMove.MoveType.Equals(StoreMoveType.StoreReset))
else if (AutomaticBaiting.StoreMove.MoveType.Equals(StoreMoveType.StoreReset)||
AutomaticBaiting.AutoBaitingStatus.Equals(StoreRunStatus.Reset))
{
status = (int)StoreStatus.BatchReset;
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!