Commit b3049428 LN

candll调用时增加异常捕获。退出调宽页面时自动停止调宽。

1 个父辈 dc0d39bb
......@@ -600,12 +600,12 @@ namespace TSA_V.LoadCSVLibrary
Dictionary<string, ComponetInfo> comMap = new Dictionary<string, ComponetInfo>();
foreach (ComponetInfo obj in comList)
{
string key = obj.PN + "-" + obj.PositionNum;
string key = obj.PN + "-" + obj.PositionNum;
if (comMap.ContainsKey(key))
{
continue;
}
obj.TagNo = "";
//obj.TagNo = "";
comMap.Add(key, obj);
}
List<ComponetInfo> list = new List<ComponetInfo>(comMap.Values);
......
......@@ -67,7 +67,12 @@ namespace TSA_V.DeviceLibrary
public static void StopChangeWidth()
{
IsStop = true;
if (!IsStop)
{
IsStop = true;
PUSICANControl.StopMove(LWidthManager.Line_NodeAddr);
LogUtil.info("StopChangeWidth ,停止调宽电机运动");
}
}
public static string StartChangeWidth(int targetWidth, int targetPosition, int timeOutSeconds = 600)
{
......
......@@ -50,7 +50,7 @@ namespace PUSICANLibrary
public static extern PUSIResult PUSICO_SetNodeState(uint nodeid, SLAVE_MANAGEMENT slaveManagement);
#endregion
#endregion
private static Dictionary<uint, Dictionary<uint, int>> sdoLastData = new Dictionary<uint, Dictionary<uint, int>>();
......@@ -87,6 +87,7 @@ namespace PUSICANLibrary
}
return -1;
}
[HandleProcessCorruptedStateExceptions]
public static PUSIResult WriteSDO(uint nodeId, uint sdoAddr, int value)
{
PUSIResult result = PUSIResult.RET_READSDO_FAIL;
......@@ -112,6 +113,10 @@ namespace PUSICANLibrary
UpdateSDOData(nodeId, sdoAddr, value);
}
}
catch (AccessViolationException e)
{
LogUtil.error("write " + nodeId + " CAN_Address." + sdoAddr + " AccessViolationException 异常 ." + e.ToString());
}
catch (Exception ex)
{
LogUtil.error("write "+ nodeId + " CAN_Address." + sdoAddr + " error ." + ex.ToString());
......@@ -119,6 +124,7 @@ namespace PUSICANLibrary
return result;
}
[HandleProcessCorruptedStateExceptions]
public static PUSIResult ReadSDO(uint nodeId, uint sdoAddr, out int outValue)
{
outValue = 0;
......@@ -145,6 +151,10 @@ namespace PUSICANLibrary
Console.WriteLine("read " + addr.sdoAddr + " sdo ok." + outValue);
}
}
catch (AccessViolationException e)
{
LogUtil.error("read " + nodeId + " CAN_Address." + sdoAddr + " AccessViolationException 异常 ." + e.ToString());
}
catch (Exception ex)
{
LogUtil.error("read " + nodeId + " CAN_Address." + sdoAddr + " error ." + ex.ToString());
......@@ -174,6 +184,7 @@ namespace PUSICANLibrary
return Open(adapterIndex, baudIndex, Ip, port);
}
[HandleProcessCorruptedStateExceptions]
public static void Close()
{
try
......@@ -185,11 +196,17 @@ namespace PUSICANLibrary
ISOpen = false;
}
}
catch (AccessViolationException e)
{
LogUtil.error("Close出错 AccessViolationException 异常 ." + e.ToString());
}
catch (Exception ex)
{
LogUtil.error("Close出错:" + ex.ToString());
}
}
[HandleProcessCorruptedStateExceptions]
public static string Open(int adapterIndex, int baudIndex, string Ip, int port)
{
try
......@@ -254,6 +271,10 @@ namespace PUSICANLibrary
return "打开端口失败!";
}
}
catch (AccessViolationException e)
{
LogUtil.error("Open出错 AccessViolationException 异常 ." + e.ToString());
}
catch (Exception ex)
{
LogUtil.error("Open出错:" + ex.ToString());
......@@ -263,20 +284,48 @@ namespace PUSICANLibrary
/// <summary>
/// 初始化节点
/// </summary>
[HandleProcessCorruptedStateExceptions]
public static bool InitNode(uint nodeid)
{
//添加节点
PUSIResult result = PUSICANControl.PUSICO_AddNode(Convert.ToUInt32(nodeid));
//启动节点
result = PUSICANControl.PUSICO_SetNodeState(nodeid, SLAVE_MANAGEMENT.SLAVE_START);
return SetOutStopType(nodeid);
try
{
//添加节点
PUSIResult result = PUSICANControl.PUSICO_AddNode(Convert.ToUInt32(nodeid));
//启动节点
result = PUSICANControl.PUSICO_SetNodeState(nodeid, SLAVE_MANAGEMENT.SLAVE_START);
return SetOutStopType(nodeid);
}
catch (AccessViolationException e)
{
LogUtil.error("InitNode 出错 AccessViolationException 异常 ." + e.ToString());
}
catch (Exception ex)
{
LogUtil.error("InitNode 出错:" + ex.ToString());
}
return false;
}
[HandleProcessCorruptedStateExceptions]
public static bool RemoveNode(uint nodeid)
{
LogUtil.info("RemoveNode " + nodeid);
//删除节点
PUSIResult result = PUSICANControl.PUSICO_RemoveNode(Convert.ToUInt32(nodeid));
return true;
try
{
LogUtil.info("RemoveNode " + nodeid);
//删除节点
PUSIResult result = PUSICANControl.PUSICO_RemoveNode(Convert.ToUInt32(nodeid));
return true;
}
catch (AccessViolationException e)
{
LogUtil.error("RemoveNode 出错 AccessViolationException 异常 ." + e.ToString());
}
catch (Exception ex)
{
LogUtil.error("RemoveNode 出错:" + ex.ToString());
}
return false;
}
public static bool InitRNodeConfig(uint nodeId, bool isLineSlv = false)
......
......@@ -107,7 +107,8 @@ namespace TSA_V
private void FrmPutCom_FormClosing(object sender, FormClosingEventArgs e)
{
//停止调宽
LWidthManager.StopChangeWidth();
}
private void timer1_Tick(object sender, EventArgs e)
......
......@@ -190,6 +190,7 @@
this.Controls.Add(this.chbOffLine);
this.Name = "FrmBoardSelect";
this.Text = "请选择程序";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmBoardSelect_FormClosing);
this.Load += new System.EventHandler(this.FrmBoardSelect_Load);
this.Shown += new System.EventHandler(this.FrmBoardSelect_Shown);
this.ResumeLayout(false);
......
......@@ -370,5 +370,11 @@ namespace TSA_V
}
}
private void FrmBoardSelect_FormClosing(object sender, FormClosingEventArgs e)
{
//停止调宽
LWidthManager.StopChangeWidth();
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!