Commit 0bc3a2d7 LN

增加异常处理

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