Commit 8566b42c LN

增加模拟量查询代码

1 个父辈 1c0fb29d
...@@ -37,12 +37,13 @@ ...@@ -37,12 +37,13 @@
<ApplicationIcon>DfIcon.ico</ApplicationIcon> <ApplicationIcon>DfIcon.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="log4net"> <Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\dll\log4net.dll</HintPath> <HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" /> <Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
...@@ -66,6 +67,7 @@ ...@@ -66,6 +67,7 @@
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.12" targetFramework="net461" />
</packages>
\ No newline at end of file \ No newline at end of file
...@@ -87,7 +87,18 @@ namespace HuichuanLibrary ...@@ -87,7 +87,18 @@ namespace HuichuanLibrary
FormStatus(false); FormStatus(false);
timerIO.Start(); timerIO.Start();
timerMain.Start(); timerMain.Start();
HCLogUtil.logBox = richTextBox1; lblAdSts.Text ="状态说明:\r\n"+
"Bit0 ,负载电压故障,0:正常,1:未接入外部电源\r\n" +
"Bit1 ,模拟芯片连接错误,0:正常,1:数字版与模拟板通讯错误\r\n" +
"Bit2:通道故障\r\n" +
"Bit3:通道上溢\r\n" +
"Bit4:通道下溢\r\n" +
"Bit5:通道超上限\r\n" +
"Bit6:通道超下限\r\n" +
"Bit7:通道断线\r\n";
HCLogUtil.logBox = richTextBox1;
} }
private void btnInitBoard_Click(object sender, EventArgs e) private void btnInitBoard_Click(object sender, EventArgs e)
{ {
...@@ -611,6 +622,31 @@ namespace HuichuanLibrary ...@@ -611,6 +622,31 @@ namespace HuichuanLibrary
timerIO.Enabled = isOk; timerIO.Enabled = isOk;
axStsMonitor_timer.Enabled = isOk; axStsMonitor_timer.Enabled = isOk;
groupBox5.Enabled = isOk;
}
private void btnAdGet_Click(object sender, EventArgs e)
{
if (!HCBoardManager.CardInitOk())
{
MessageBox.Show("板卡未初始化完成!");
return;
}
txtAd1.Text = HCBoardManager.GetAdVal(0).ToString();
txtAd2.Text = HCBoardManager.GetAdVal(1).ToString();
txtAd3.Text = HCBoardManager.GetAdVal(2).ToString();
txtAd4.Text = HCBoardManager.GetAdVal(3).ToString();
txtAdSts1.Text = ConSts(HCBoardManager.GetAdSts(0));
txtAdSts2.Text = ConSts(HCBoardManager.GetAdSts(1));
txtAdSts3.Text = ConSts(HCBoardManager.GetAdSts(2));
txtAdSts4.Text = ConSts(HCBoardManager.GetAdSts(3));
}
private string ConSts(short input)
{
string output = Convert.ToString(input, 2).ToString().PadLeft(8, '0');
return output;
} }
} }
} }
...@@ -544,6 +544,65 @@ namespace HuichuanLibrary ...@@ -544,6 +544,65 @@ namespace HuichuanLibrary
#endregion #endregion
#region AD/DA控制
/// <summary>
/// 获取EtherCAT 第 adNo号的ad值
/// </summary>
/// <param name="adNo">ad的通道:0~配置个数</param>
/// <returns>获取AD的输入值</returns>
public static short GetAdVal(short adNo)
{
if (!CardInitOk())
{
return 0;
}
Int16 adVal = 0;
UInt32 ret = ImcApi.IMC_GetEcatAdVal(nCardHandle, adNo, ref adVal);
if (ret != 0)
{
ShowErrorLog(" adNo[" + adNo + "] IMC_GetEcatAdVal FAIL, ErrorCode=0x" + ret.ToString("x8"));
return 0;
}
return adVal;
}
/// <summary>
/// 获取EtherCAT 第 adNo号的状态
/// </summary>
/// <param name="adNo">ad的通道:0~配置个数</param>
/// <returns>获取AD的状态值</returns>
public static short GetAdSts(short adNo)
{
if (!CardInitOk())
{
return 0;
}
Int16 adSts = 0;
UInt32 ret = ImcApi.IMC_GetEcatAdSts(nCardHandle, adNo, ref adSts);
if (ret != 0)
{
ShowErrorLog(" adNo[" + adNo + "] IMC_GetEcatAdSts FAIL, ErrorCode=0x" + ret.ToString("x8"));
return 0;
}
return adSts;
}
public static AdStsInfo GetAdStsInfo(short sts)
{
//【3】更新界面显示
AdStsInfo stsInfo = new AdStsInfo();
stsInfo.VoltageSts = ((sts & 0x01) == 0x01) ? 1 : 0; //负载电压故障
stsInfo.ConnectSts = ((sts & 0x02) == 0x02) ? 1 : 0; //模拟芯片连接错误
stsInfo.NoSts = ((sts & 0x04) == 0x04) ? 1 : 0; //通道故障
stsInfo.Overflow = ((sts & 0x08) == 0x08) ? 1 : 0; //通道上溢
stsInfo.Underflow = ((sts & 0x10) == 0x10) ? 1 : 0; //通道下溢
stsInfo.PEL = ((sts & 0x20) == 0x20) ? 1 : 0; //通道超上限
stsInfo.NEL = ((sts & 0x40) == 0x40) ? 1 : 0;//通道超下限
stsInfo.OffLine = ((sts & 0x80) == 0x80) ? 1 : 0;//通道断线
return stsInfo;
}
#endregion
private static void ShowErrorLog(string msg) private static void ShowErrorLog(string msg)
{ {
CardMsg = BoardName() + msg; CardMsg = BoardName() + msg;
...@@ -562,6 +621,48 @@ namespace HuichuanLibrary ...@@ -562,6 +621,48 @@ namespace HuichuanLibrary
HCLogUtil.debug(BoardName() + msg); HCLogUtil.debug(BoardName() + msg);
} }
} }
public class AdStsInfo
{
/// <summary>
/// Bit0 ,负载电压故障,0:接入外部电源,1:未接入外部电源
/// </summary>
public int VoltageSts= -1;
/// <summary>
/// Bit1 ,模拟芯片连接错误,0:数字版与模拟板通讯正常,1:数字版与模拟板通讯错误
/// </summary>
public int ConnectSts = -1;
/// <summary>
/// Bit2:通道故障
/// </summary>
public int NoSts = -1;
/// <summary>
/// Bit3:通道上溢
/// </summary>
public int Overflow = -1;
/// <summary>
/// Bit4:通道下溢
/// </summary>
public int Underflow = -1;
/// <summary>
/// Bit5:通道超上限
/// </summary>
public int PEL = -1;
/// <summary>
/// Bit6:通道超下限
/// </summary>
public int NEL = -1;
/// <summary>
/// Bit7:通道断线
/// </summary>
public int OffLine = -1;
public string ToStr()
{
return "VoltageSts=" + VoltageSts + ",ConnectSts=" + ConnectSts + ",NoSts=" + NoSts + ",Overflow=" + Overflow + ",Underflow=" + Underflow
+ ",PEL=" + PEL + ",NEL=" + NEL + ",OffLine=" + OffLine;
}
}
public class AxisSts public class AxisSts
{ {
/// <summary> /// <summary>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!