Commit 1f8a322e 几米阳光

IO模块增加重连

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