|
@@ -1,4 +1,5 @@
|
|
|
using NPOI.XSSF.UserModel;
|
|
|
+using SCADA;
|
|
|
using SCADA.CommonCtrl;
|
|
|
using SCADA.CommonCtrl.AnimationHelper;
|
|
|
using SCADA.CommonCtrl.WpfControl;
|
|
@@ -6,11 +7,15 @@ using SCADA.CommonLib.Data.DIL;
|
|
|
using SCADA.CommonLib.Data.DIL.MSSql;
|
|
|
using SCADA.CommonLib.Data.DIL.MySql;
|
|
|
using SCADA.CommonLib.Data.DIL.Oracle;
|
|
|
+using SCADA.CommonLib.Helper;
|
|
|
using SCADA_DAQ.Customer.ART;
|
|
|
+using SCADA_DAQ.Customer.Service;
|
|
|
using System;
|
|
|
+using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
+using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Media.Animation;
|
|
@@ -24,15 +29,305 @@ namespace SCADA_DAQ.Customer
|
|
|
[UctMenu("主页", Icon = "主页")]
|
|
|
public partial class UctFrmMain : BaseUctFrm
|
|
|
{
|
|
|
+ /// <summary>
|
|
|
+ /// 连接句柄
|
|
|
+ /// </summary>
|
|
|
+ private IntPtr hDevice;
|
|
|
+
|
|
|
+ public static USB5621AE_AI_PARAM AIParam;
|
|
|
+
|
|
|
+ private bool IsRunning { get; set; }
|
|
|
+
|
|
|
+ UInt16[] nBinArray = new UInt16[32768];
|
|
|
+ UInt32 nReadSampsPerChan = 1024;
|
|
|
+ UInt32 nSampsPerChanRead = 0;
|
|
|
+ UInt32 nReadableSamps = 0;
|
|
|
+ double fTimeout = 10.0;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// /
|
|
|
/// </summary>
|
|
|
public UctFrmMain()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
- var ptr = USB5621AE.USB5621AE_DEV_CreateA("192.168.1.4", 5, 5);
|
|
|
- var info = new DEVICE_NET_INFO_A();
|
|
|
- var res = USB5621AE.USB5621AE_GetNetCfgA(ptr, ref info);
|
|
|
+ ToolBar.Visibility = Visibility.Collapsed;
|
|
|
+ SetAIParams();
|
|
|
+ //for (int i = 0; i < 50; i++)
|
|
|
+ //{
|
|
|
+ // DataChart.mainChart.Series[0].Points.Add(RandomHelper.Next(0, 100));
|
|
|
+ //}
|
|
|
+ }
|
|
|
+
|
|
|
+ private void IconButton_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ hDevice = USB5621AE_DEV_CreateA("192.168.1.4", 10, 10);
|
|
|
+ if (hDevice == (IntPtr)(-1))
|
|
|
+ {
|
|
|
+ //Console.WriteLine("USB5621AE_DEV_Create Error");
|
|
|
+ Log.Error("创建设备链接失败!");
|
|
|
+ return; // 如果创建设备对象失败,则返回
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!USB5621AE_AI_VerifyParam(hDevice, ref AIParam))
|
|
|
+ {
|
|
|
+ Log.Info("参数有误,已被调整为合法值");
|
|
|
+ }
|
|
|
+ StartBtn.IsEnabled = true;
|
|
|
+ StopBtn.IsEnabled = true;
|
|
|
+ }
|
|
|
+ //var info = new DEVICE_NET_INFO_A();
|
|
|
+ //var res = USB5621AE_GetNetCfgA(hDevice, ref info);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void CloseThis()
|
|
|
+ {
|
|
|
+ StopTask();
|
|
|
+ if (hDevice != (IntPtr)0)
|
|
|
+ {
|
|
|
+ USB5621AE_DEV_Release(hDevice);
|
|
|
+
|
|
|
+ }
|
|
|
+ base.CloseThis();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SetAIParams()
|
|
|
+ {
|
|
|
+ // 通道参数
|
|
|
+ AIParam.nSampChanCount = 4;
|
|
|
+
|
|
|
+ AIParam.CHParam0.nChannel = 0;
|
|
|
+ AIParam.CHParam0.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam0.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam0.nReserved0 = 0;
|
|
|
+ AIParam.CHParam0.nReserved1 = 0;
|
|
|
+ AIParam.CHParam0.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam1.nChannel = 1;
|
|
|
+ AIParam.CHParam1.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam1.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam1.nReserved0 = 0;
|
|
|
+ AIParam.CHParam1.nReserved1 = 0;
|
|
|
+ AIParam.CHParam1.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam2.nChannel = 2;
|
|
|
+ AIParam.CHParam2.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam2.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam2.nReserved0 = 0;
|
|
|
+ AIParam.CHParam2.nReserved1 = 0;
|
|
|
+ AIParam.CHParam2.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam3.nChannel = 3;
|
|
|
+ AIParam.CHParam3.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam3.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam3.nReserved0 = 0;
|
|
|
+ AIParam.CHParam3.nReserved1 = 0;
|
|
|
+ AIParam.CHParam3.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam4.nChannel = 4;
|
|
|
+ AIParam.CHParam4.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam4.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam4.nReserved0 = 0;
|
|
|
+ AIParam.CHParam4.nReserved1 = 0;
|
|
|
+ AIParam.CHParam4.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam5.nChannel = 5;
|
|
|
+ AIParam.CHParam5.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam5.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam5.nReserved0 = 0;
|
|
|
+ AIParam.CHParam5.nReserved1 = 0;
|
|
|
+ AIParam.CHParam5.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam6.nChannel = 6;
|
|
|
+ AIParam.CHParam6.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam6.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam6.nReserved0 = 0;
|
|
|
+ AIParam.CHParam6.nReserved1 = 0;
|
|
|
+ AIParam.CHParam6.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam7.nChannel = 7;
|
|
|
+ AIParam.CHParam7.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam7.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam7.nReserved0 = 0;
|
|
|
+ AIParam.CHParam7.nReserved1 = 0;
|
|
|
+ AIParam.CHParam7.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam8.nChannel = 8;
|
|
|
+ AIParam.CHParam8.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam8.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam8.nReserved0 = 0;
|
|
|
+ AIParam.CHParam8.nReserved1 = 0;
|
|
|
+ AIParam.CHParam8.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam9.nChannel = 9;
|
|
|
+ AIParam.CHParam9.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam9.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam9.nReserved0 = 0;
|
|
|
+ AIParam.CHParam9.nReserved1 = 0;
|
|
|
+ AIParam.CHParam9.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam10.nChannel = 10;
|
|
|
+ AIParam.CHParam10.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam10.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam10.nReserved0 = 0;
|
|
|
+ AIParam.CHParam10.nReserved1 = 0;
|
|
|
+ AIParam.CHParam10.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam11.nChannel = 11;
|
|
|
+ AIParam.CHParam11.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam11.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam11.nReserved0 = 0;
|
|
|
+ AIParam.CHParam11.nReserved1 = 0;
|
|
|
+ AIParam.CHParam11.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam12.nChannel = 12;
|
|
|
+ AIParam.CHParam12.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam12.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam12.nReserved0 = 0;
|
|
|
+ AIParam.CHParam12.nReserved1 = 0;
|
|
|
+ AIParam.CHParam12.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam13.nChannel = 13;
|
|
|
+ AIParam.CHParam13.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam13.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam13.nReserved0 = 0;
|
|
|
+ AIParam.CHParam13.nReserved1 = 0;
|
|
|
+ AIParam.CHParam13.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam14.nChannel = 14;
|
|
|
+ AIParam.CHParam14.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam14.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam14.nReserved0 = 0;
|
|
|
+ AIParam.CHParam14.nReserved1 = 0;
|
|
|
+ AIParam.CHParam14.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.CHParam15.nChannel = 15;
|
|
|
+ AIParam.CHParam15.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
|
|
|
+ AIParam.CHParam15.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
|
|
|
+ AIParam.CHParam15.nReserved0 = 0;
|
|
|
+ AIParam.CHParam15.nReserved1 = 0;
|
|
|
+ AIParam.CHParam15.nReserved2 = 0;
|
|
|
+
|
|
|
+ AIParam.nReserved0 = 0;
|
|
|
+ AIParam.nReserved1 = 0;
|
|
|
+
|
|
|
+ AIParam.nChanScanMode = USB5621AE.USB5621AE_AI_CHAN_SCANMODE_CONTINUOUS;
|
|
|
+ AIParam.nGroupLoops = 1;
|
|
|
+ AIParam.nGroupInterval = 1;
|
|
|
+ AIParam.nSampleSignal = USB5621AE.USB5621AE_AI_SAMPSIGNAL_AI;
|
|
|
+ AIParam.nSampleRange = USB5621AE.USB5621AE_AI_SAMPRANGE_0_P10V;
|
|
|
+
|
|
|
+ // 时钟参数
|
|
|
+ AIParam.nSampleMode = USB5621AE.USB5621AE_AI_SAMPMODE_CONTINUOUS;
|
|
|
+ //缓存点数
|
|
|
+ AIParam.nSampsPerChan = 1024;
|
|
|
+ //采集间隔
|
|
|
+ AIParam.fSampleRate = 10000.0;
|
|
|
+ AIParam.nClockSource = USB5621AE.USB5621AE_AI_CLKSRC_LOCAL;
|
|
|
+ AIParam.bClockOutput = 0;
|
|
|
+
|
|
|
+
|
|
|
+ // 开始触发参数
|
|
|
+ AIParam.bDTriggerEn = 1;
|
|
|
+ AIParam.nDTriggerDir = USB5621AE.USB5621AE_AI_TRIGDIR_FALLING;
|
|
|
+ AIParam.bATriggerEn = 1;
|
|
|
+ AIParam.nATriggerDir = USB5621AE.USB5621AE_AI_TRIGDIR_FALLING;
|
|
|
+ AIParam.fTriggerLevel = 0;
|
|
|
+ AIParam.nTriggerSens = 5;
|
|
|
+
|
|
|
+
|
|
|
+ // 其他参数
|
|
|
+ AIParam.nReserved1 = 0;
|
|
|
+ AIParam.nReserved2 = 0;
|
|
|
+ AIParam.nReserved3 = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void StopTask()
|
|
|
+ {
|
|
|
+ IsRunning = false;
|
|
|
+ // 第六步 停止AI采集任务
|
|
|
+ if (!USB5621AE_AI_StopTask(hDevice))
|
|
|
+ {
|
|
|
+ Log.Error("停止采集任务失败!\n");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第七步 释放AI采集任务
|
|
|
+ if (!USB5621AE_AI_ReleaseTask(hDevice))
|
|
|
+ {
|
|
|
+ Log.Error("释放采集任务失败!\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void IconButton_Click_1(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ foreach (var item in DataChart.mainChart.Series)
|
|
|
+ {
|
|
|
+ item.Points.Clear();
|
|
|
+ }
|
|
|
+ // 第二步 初始化AI采集任务
|
|
|
+ if (!USB5621AE_AI_InitTask(hDevice, ref AIParam, (IntPtr)null))
|
|
|
+ {
|
|
|
+ Log.Error("初始化采集任务失败!\n");
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第三步 开始AI采集任务
|
|
|
+ if (!USB5621AE_AI_StartTask(hDevice))
|
|
|
+ {
|
|
|
+ Log.Error("开始采集任务失败!\n");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第四步 发送软件触发事件(硬件外触发时不需要)
|
|
|
+ if (!USB5621AE_AI_SendSoftTrig(hDevice))
|
|
|
+ {
|
|
|
+ Console.WriteLine("发送软件触发事件失败!\n");
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
+ IsRunning = true;
|
|
|
+
|
|
|
+ Task.Run(() =>
|
|
|
+ {
|
|
|
+ // 第五步 循环读取AI数据
|
|
|
+ while (IsRunning)
|
|
|
+ {
|
|
|
+ if (USB5621AE.USB5621AE_AI_ReadBinary(hDevice, nBinArray, nReadSampsPerChan, ref nSampsPerChanRead, ref nReadableSamps, fTimeout) == false)
|
|
|
+ {
|
|
|
+ Log.Error("读取数据失败!");
|
|
|
+ IsRunning = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var data = nBinArray.TakeWhile(t=>t != 0).ToList();
|
|
|
+ //AIParam设置了获取4个通道的数据
|
|
|
+ for (int nIndex = 0; nIndex < (data.Count / 4); nIndex++)
|
|
|
+ {
|
|
|
+ for (int nChannel = 0; nChannel < 4; nChannel++)
|
|
|
+ {
|
|
|
+ Dispatcher.Invoke(new Action(() =>
|
|
|
+ {
|
|
|
+ DataChart.mainChart.Series[nChannel].Points.Add(data[nChannel + nIndex * 4]);
|
|
|
+
|
|
|
+ DataChart.mainChart.ChartAreas[0].AxisX.ScaleView.Position = DataChart.mainChart.Series[0].Points.Count - DataChart.mainChart.ChartAreas[0].AxisX.ScaleView.Size;
|
|
|
+
|
|
|
+ }));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Thread.Sleep(50);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void IconButton_Click_2(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ StopTask();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|