Commit 0bc3a2d7 LN

增加异常处理

1 个父辈 d91c34b0
...@@ -115,7 +115,13 @@ namespace DeviceLibrary ...@@ -115,7 +115,13 @@ namespace DeviceLibrary
{ {
if (RobotManage.InoutDebugMode) if (RobotManage.InoutDebugMode)
{
return; return;
}
if (RobotManage.mainMachine.runStatus!=RunStatus.Running)
{
return;
}
lock (serverclock) lock (serverclock)
{ {
var code = ProcessCode(codelist, reel.PlateW, reel.PlateH); var code = ProcessCode(codelist, reel.PlateW, reel.PlateH);
...@@ -133,7 +139,7 @@ namespace DeviceLibrary ...@@ -133,7 +139,7 @@ namespace DeviceLibrary
operation.data.Add("singleIn", "false"); operation.data.Add("singleIn", "false");
} }
Operation resultOperation = HttpHelper.Post(GetPostApi(), operation, 5000, printlog); Operation resultOperation = HttpHelper.Post(GetPostApi(), operation, 5000, printlog);
if (operation.seq != resultOperation?.seq) if (resultOperation != null && resultOperation.seq > 0 && operation.seq != resultOperation?.seq)
{ {
Thread.Sleep(1000); Thread.Sleep(1000);
SendInStoreRequest(codelist, reel, printlog); SendInStoreRequest(codelist, reel, printlog);
......
...@@ -220,14 +220,16 @@ namespace DeviceLibrary ...@@ -220,14 +220,16 @@ namespace DeviceLibrary
} }
byte[] SendAndReceive(byte[] buff, string cmdname = "") byte[] SendAndReceive(byte[] buff, string cmdname = "")
{ {
try
{
lock (port) lock (port)
{ {
byte[] restr = new byte[0]; byte[] restr = new byte[0];
if (port == null || !port.IsOpen) if (port == null || !port.IsOpen)
{ {
if (!Open(PortName,out string msg)) if (!Open(PortName, out string msg))
{ {
log(PortName+"未初始化,或已断开连接"); log(PortName + "未初始化,或已断开连接");
return restr; return restr;
} }
} }
...@@ -267,6 +269,13 @@ namespace DeviceLibrary ...@@ -267,6 +269,13 @@ namespace DeviceLibrary
else else
return new byte[0]; return new byte[0];
} }
}
catch (Exception ex)
{
error("SendAndReceive , " + cmdname + ", error :" + ex.ToString());
}
return new byte[0];
} }
/// <summary> /// <summary>
/// 初始化设置 /// 初始化设置
......
...@@ -276,6 +276,8 @@ namespace DeviceLibrary ...@@ -276,6 +276,8 @@ namespace DeviceLibrary
public void Run() public void Run()
{ {
mstart = true; mstart = true;
try
{
while (mstart) while (mstart)
{ {
try try
...@@ -353,6 +355,11 @@ namespace DeviceLibrary ...@@ -353,6 +355,11 @@ namespace DeviceLibrary
ServerCM.storeStatus = currnetstoreStatus; ServerCM.storeStatus = currnetstoreStatus;
} }
} }
}
catch (Exception ex)
{
LogUtil.error("Run error :" + ex.ToString());
}
RobotManage.isRunning = false; RobotManage.isRunning = false;
RobotManage.UserPause($"isRunning = false", false); RobotManage.UserPause($"isRunning = false", false);
LogUtil.info("主线程已退出."); LogUtil.info("主线程已退出.");
...@@ -364,6 +371,8 @@ namespace DeviceLibrary ...@@ -364,6 +371,8 @@ namespace DeviceLibrary
} }
public void Stop() public void Stop()
{ {
try
{
LogUtil.info("开始停止系统2."); LogUtil.info("开始停止系统2.");
mstart = false; mstart = false;
AutoInOutTest = false; AutoInOutTest = false;
...@@ -377,7 +386,15 @@ namespace DeviceLibrary ...@@ -377,7 +386,15 @@ namespace DeviceLibrary
LedProcess(null); LedProcess(null);
CloseRgbLed(); CloseRgbLed();
SoundsController.StopPlay(); SoundsController.StopPlay();
runStatus = RunStatus.Stop;
mstart = false;
LogUtil.info("开始停止系统3."); LogUtil.info("开始停止系统3.");
}
catch (Exception ex)
{
LogUtil.error("停止系统 Stop error :" + ex.ToString());
}
} }
public void BeginHomeReset(bool firstRun = false) public void BeginHomeReset(bool firstRun = false)
{ {
......
...@@ -605,15 +605,6 @@ namespace TheMachine ...@@ -605,15 +605,6 @@ namespace TheMachine
if (RobotManage.isRunning) if (RobotManage.isRunning)
{ {
btn_stop.Enabled = true; btn_stop.Enabled = true;
}
else
{
btn_stop.Enabled = false;
btn_run.Text = crc.GetString(L.start, "启动");
btn_run.BackColor = Color.Transparent;
cb_IgnoreSafecheck.Enabled = true;
return;
}
if (e) if (e)
{ {
(btn_run as Button).Text = crc.GetString(L.device_resume, "恢复运行"); (btn_run as Button).Text = crc.GetString(L.device_resume, "恢复运行");
...@@ -626,6 +617,15 @@ namespace TheMachine ...@@ -626,6 +617,15 @@ namespace TheMachine
(btn_run as Button).BackColor = Color.Yellow; (btn_run as Button).BackColor = Color.Yellow;
cb_IgnoreSafecheck.Enabled = false; cb_IgnoreSafecheck.Enabled = false;
} }
}
else
{
btn_stop.Enabled = false;
btn_run.Text = crc.GetString(L.start, "启动");
btn_run.BackColor = Color.Transparent;
cb_IgnoreSafecheck.Enabled = true;
return;
}
} }
private void btn_stop_Click(object sender, EventArgs e) private void btn_stop_Click(object sender, EventArgs e)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!