Commit b3049428 LN

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

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