Commit 4eb33448 LN

负载率功能修改

1 个父辈 11c81d5d
...@@ -38,7 +38,7 @@ namespace HuichuanLibrary ...@@ -38,7 +38,7 @@ namespace HuichuanLibrary
DILabelList.Add(lblDI13); DILabelList.Add(lblDI13);
DILabelList.Add(lblDI14); DILabelList.Add(lblDI14);
DILabelList.Add(lblDI15); DILabelList.Add(lblDI15);
for(int i = 0; i < DILabelList.Count; i++) for (int i = 0; i < DILabelList.Count; i++)
{ {
DILabelList[i].Text = "DI_" + i; DILabelList[i].Text = "DI_" + i;
} }
...@@ -87,9 +87,9 @@ namespace HuichuanLibrary ...@@ -87,9 +87,9 @@ namespace HuichuanLibrary
FormStatus(false); FormStatus(false);
timerIO.Start(); timerIO.Start();
timerMain.Start(); timerMain.Start();
lblAdSts.Text ="状态说明:\r\n"+ lblAdSts.Text = "状态说明:\r\n" +
"Bit0 ,负载电压故障,0:正常,1:未接入外部电源\r\n" + "Bit0 ,负载电压故障,0:正常,1:未接入外部电源\r\n" +
"Bit1 ,模拟芯片连接错误,0:正常,1:数字版与模拟板通讯错误\r\n" + "Bit1 ,模拟芯片连接错误,0:正常,1:数字版与模拟板通讯错误\r\n" +
"Bit2:通道故障\r\n" + "Bit2:通道故障\r\n" +
"Bit3:通道上溢\r\n" + "Bit3:通道上溢\r\n" +
"Bit4:通道下溢\r\n" + "Bit4:通道下溢\r\n" +
...@@ -98,8 +98,78 @@ namespace HuichuanLibrary ...@@ -98,8 +98,78 @@ namespace HuichuanLibrary
"Bit7:通道断线\r\n"; "Bit7:通道断线\r\n";
HCLogUtil.logBox = richTextBox1; HCLogUtil.logBox = richTextBox1;
axisTimer = new System.Timers.Timer();
axisTimer.Interval = 200;
axisTimer.AutoReset = true;
axisTimer.Enabled = false;
axisTimer.Elapsed += AxisTimer_Elapsed;
txtMaxFuzai.Text = MaxFuZai.ToString();
groupBox12.Text = "最大负载率=" + MaxFuZai;
}
private void AxisTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//200毫秒检测一次运动轴,如果负载率超过指定值,直接停止
//如果停止运动,从集合移除;
List<short> axiss = new List<short>(moveAxisNoList);
foreach (short axisNo in axiss)
{
AxisSts sts = HCBoardManager.GetAxisSts(axisNo);
if (sts.ServoOn <= 0)
{
HCLogUtil.error($"AxisTimer_Elapsed 轴号{axisNo} 伺服已关闭,removeMoveAxis");
removeMoveAxis(axisNo);
}
//判断是否再运动中
if (sts.BUSY <= 0)
{
HCLogUtil.error($"AxisTimer_Elapsed 轴号{axisNo} 已停止运动,removeMoveAxis");
removeMoveAxis(axisNo);
}
float currFuzai = HCBoardManager.GetAxisLoadRate(axisNo);
if (currFuzai > MaxFuZai)
{
HCLogUtil.error($"AxisTimer_Elapsed 轴号{axisNo} 当前负载率{currFuzai}大于最大负载率{MaxFuZai},停止运动,removeMoveAxis");
HCBoardManager.AxisStop(axisNo);
removeMoveAxis(axisNo);
}
}
}
private void removeMoveAxis(short axisNo)
{
try
{
HCLogUtil.info($"removeMoveAxis{axisNo}");
moveAxisNoList.Remove(axisNo);
}
catch(Exception ex)
{
}
}
private void addMoveAxis(short axisNo)
{
try
{
if (!moveAxisNoList.Contains(axisNo))
{
HCLogUtil.info($"addMoveAxis{axisNo}");
moveAxisNoList.Add(axisNo);
}
}
catch (Exception ex)
{
}
} }
private List<short> moveAxisNoList = new List<short>();
private System.Timers.Timer axisTimer;
private float MaxFuZai = 10;
private void btnInitBoard_Click(object sender, EventArgs e) private void btnInitBoard_Click(object sender, EventArgs e)
{ {
bool result = HCBoardManager.OpenCard(1); bool result = HCBoardManager.OpenCard(1);
...@@ -242,6 +312,12 @@ namespace HuichuanLibrary ...@@ -242,6 +312,12 @@ namespace HuichuanLibrary
double ptpPos = Convert.ToDouble(txtPtpPos.Text); double ptpPos = Convert.ToDouble(txtPtpPos.Text);
HCBoardManager.AbsMove(axisNo, ptpPos, ptpVel, ptpAcc, ptpDec); HCBoardManager.AbsMove(axisNo, ptpPos, ptpVel, ptpAcc, ptpDec);
addMoveAxis(axisNo);
if (!axisTimer.Enabled)
{
HCLogUtil.info("启动axisTimer");
axisTimer.Start();
}
} }
private void btnRelMove_Click(object sender, EventArgs e) private void btnRelMove_Click(object sender, EventArgs e)
...@@ -255,6 +331,12 @@ namespace HuichuanLibrary ...@@ -255,6 +331,12 @@ namespace HuichuanLibrary
double ptpPos = Convert.ToDouble(txtPtpPos.Text); double ptpPos = Convert.ToDouble(txtPtpPos.Text);
HCBoardManager.RelMove(axisNo, ptpPos, ptpVel, ptpAcc, ptpDec); HCBoardManager.RelMove(axisNo, ptpPos, ptpVel, ptpAcc, ptpDec);
addMoveAxis(axisNo);
if (!axisTimer.Enabled)
{
HCLogUtil.info("启动axisTimer");
axisTimer.Start();
}
} }
private void btnAxisStop_Click(object sender, EventArgs e) private void btnAxisStop_Click(object sender, EventArgs e)
{ {
...@@ -298,7 +380,14 @@ namespace HuichuanLibrary ...@@ -298,7 +380,14 @@ namespace HuichuanLibrary
{ {
if (value.Equals(1)) if (value.Equals(1))
{ {
lbl.BackColor = Color.Lime; if (lbl.Text.Equals("ALM"))
{
lbl.BackColor = Color.Red;
}
else
{
lbl.BackColor = Color.Lime;
}
} }
else if (value.Equals(0)) else if (value.Equals(0))
{ {
...@@ -674,7 +763,7 @@ namespace HuichuanLibrary ...@@ -674,7 +763,7 @@ namespace HuichuanLibrary
private void btnSearch_Click(object sender, EventArgs e) private void btnSearch_Click(object sender, EventArgs e)
{ {
short axisNo = GetAxisNo(); short axisNo = GetAxisNo();
//txtFuzai.Text = HCBoardManager.GetAxisLoadRate(axisNo).ToString(); txtFuzai.Text = HCBoardManager.GetAxisLoadRate(axisNo).ToString();
} }
private void btnSearchNj_Click(object sender, EventArgs e) private void btnSearchNj_Click(object sender, EventArgs e)
...@@ -682,5 +771,30 @@ namespace HuichuanLibrary ...@@ -682,5 +771,30 @@ namespace HuichuanLibrary
short axisNo = GetAxisNo(); short axisNo = GetAxisNo();
txtNuiju.Text = HCBoardManager.GetAxActTorq(axisNo).ToString(); txtNuiju.Text = HCBoardManager.GetAxActTorq(axisNo).ToString();
} }
private void btnSaveMaxFuzai_Click(object sender, EventArgs e)
{
float v = 0;
try
{
v = (float)Convert.ToDecimal(txtMaxFuzai.Text);
}
catch (Exception ex)
{
}
if (v > 0)
{
MaxFuZai = v;
MessageBox.Show("已设置最大负载率=" + MaxFuZai);
}
else
{
MessageBox.Show("设置失败");
}
groupBox12.Text = "最大负载率=" + MaxFuZai;
}
} }
} }
...@@ -905,7 +905,7 @@ namespace HuichuanLibrary ...@@ -905,7 +905,7 @@ namespace HuichuanLibrary
/// </summary> /// </summary>
/// <param name="axisNo"></param> /// <param name="axisNo"></param>
/// <returns></returns> /// <returns></returns>
public static string GetAxisLoadRate(short axisNo) public static float GetAxisLoadRate(short axisNo)
{ {
short pPhyStation_Id = 0; short pPhyStation_Id = 0;
short pPhySlot_id = 0; short pPhySlot_id = 0;
...@@ -913,6 +913,7 @@ namespace HuichuanLibrary ...@@ -913,6 +913,7 @@ namespace HuichuanLibrary
ushort index = 0x200b; ushort index = 0x200b;
ushort subindex = 13; ushort subindex = 13;
//扭矩 3;
uint targetsize = 2; uint targetsize = 2;
int datasize = 2; int datasize = 2;
uint resultSize = 0; uint resultSize = 0;
...@@ -931,14 +932,15 @@ namespace HuichuanLibrary ...@@ -931,14 +932,15 @@ namespace HuichuanLibrary
} }
int value = Convert.ToInt32(str.Trim().Replace(" ", ""), 16); int value = Convert.ToInt32(str.Trim().Replace(" ", ""), 16);
HCLogUtil.info($"axisNo={axisNo},pPhyStation_Id={pPhyStation_Id},index={index},subindex= {subindex},abortCode ={abortCode},resultSize={resultSize}, str={str},value={value}" ); float v = (float)value / 2560;
return value.ToString(); HCLogUtil.info($"axisNo={axisNo},pPhyStation_Id={pPhyStation_Id},index={index},subindex= {subindex},abortCode ={abortCode},resultSize={resultSize}, str={str},value={value},v={v}" );
return v;
} }
else else
{ {
HCLogUtil.info($"axisNo={axisNo},pPhyStation_Id={pPhyStation_Id},index={index},subindex= {subindex},abortCode ={abortCode},resultSize={resultSize},"); HCLogUtil.info($"axisNo={axisNo},pPhyStation_Id={pPhyStation_Id},index={index},subindex= {subindex},abortCode ={abortCode},resultSize={resultSize},");
} }
return ""; return 0;
} }
/// <summary> /// <summary>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!