06-24-2020 08:41 AM
Hello dear community,
I want to add to my data aquisition software in .NET the feature to calculate and display the avarege value for every x second. For that purpose i have implemented in my reading loop a loop that stores the data in an array, calculates the avarage every x seconds and transfers the data to an dataobject, that is beeing read in the Plotframe. Unfortunately i get Error -200279. I tried different thing, raising buffer size, reading more samples, but nothing worked.
I think it must be said that i have two channel groups. The aquisition begins by starting the Programm:
Private Sub butStartProgramm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butStartProgramm.Click
Me.butStartProgramm.Enabled = False
Me.ButStartMessung.Enabled = True
Me.butEndeProgramm.Enabled = True
setFenster() ' here i call the Frameplots
objScan_Teil2.Start() 'here is beeing started the aquisition of the second channel group, executed throug a separate class
iniKanaele() ' here the channels of group 1 are beeing initialisated
'starting the aquisition of channel group 1
If taskRunning = False Then
Try
taskRunning = True
analogInReader = New AnalogMultiChannelReader(myTask.Stream)
analogInReader.SynchronizeCallbacks = True
analogCallback = New AsyncCallback(AddressOf AnalogInCallback)
analogInReader.BeginReadMultiSample(objKanalinfo_Teil1.m_ScansProKanal, _
analogCallback, Nothing)
Catch exception As DaqException
MessageBox.Show(exception.Message)
taskRunning = False
Me.butStartProgramm.Enabled = True
Me.butStopMessung.Enabled = False
myTask.Dispose()
End Try
End If
End Sub
the async.callback looks as follows:
Private Sub AnalogInCallback(ByVal ar As IAsyncResult)
Dim Messdaten_Teil1 As Double(,) 'Aquisition array
Dim MittelwMessdaten_Teil1 As Double() 'Array for loop avareged values
Dim PeriodenmittelwertOsz As Double() 'Array for over time period avareged values
Dim DatenArray_proScanOszillationen As Double(,) ' Array in which aquisition data are stored in one loop
Static Dim n_Osz As Integer = 0 ' Period counter
Dim zeile_Osz As Integer
Dim spalte_Osz As Integer
Dim zeilen_Osz As Integer
Dim spalten_Osz As Integer
Dim deltaTime As Double
deltaTime = 1.0 / objKanalinfo_Teil1.m_Frequenz * objKanalinfo_Teil1.m_ScansProKanal 'here i define the time of the loop( Scans=1)
zeilen_Osz = CInt(5 / (deltaTime)) ' here i define the first dimension of the storage array as Period/looptime
spalten_Osz = 19 'number of channels
Static Dim Oszillation_Array(zeilen_Osz, spalten_Osz) As Double 'the storage array
Try
If taskRunning = True Then
Messdaten_Teil1 = analogInReader.EndReadMultiSample(ar)
analogInReader.BeginReadMultiSample(objKanalinfo_Teil1.m_ScansProKanal, _
analogCallback, Nothing)
SyncLock Me
Messdaten_Teil1 = Daten_berechnen(Messdaten_Teil1) 'calculating data from signals
DatenArray_proScanOszillationen = Daten_Array_Oszillation(Messdaten_Teil2) 'storing the data from the loop
For zeile_Osz = DatenArray_proScanOszillationen.GetLowerBound(0) To DatenArray_proScanOszillationen.GetUpperBound(0)
For spalte_Osz = DatenArray_proScanOszillationen.GetLowerBound(1) To DatenArray_proScanOszillationen.GetUpperBound(1)
Oszillation_Array(n_Osz, spalte_Osz) = DatenArray_proScanOszillationen(zeile_Osz, spalte_Osz) 'storing the data in the array containig data over one period
Next spalte_Osz
n_Osz = n_Osz + 1
If n_Osz = zeilen_Osz Then
PeriodenmittelwertOsz = Periodenmittelwert(Oszillation_Array) 'calculation the averaged data
objPeriodengemittelteMessdatenUebergabe = ZuweisungPeriodengemittelterMessdaten(PeriodenmittelwertOsz, objPeriodengemittelteMessdatenUebergabe) 'trasfering the Data to the object read in the Plot frame
n_Osz = 0
End If
Next zeile_Osz
'Calculating the avarage over loop and transfering the data to the plots
MittelwMessdaten_Teil1 = mitt(Messdaten_Teil1)
MittelwMessdaten_Teil2 = mitt(Messdaten_Teil2)
objMessdaten = ZuweisungMessdaten(MittelwMessdaten_Teil1, MittelwMessdaten_Teil2, objMessdaten)
objMessdatenUebergabe = ZuweisungMessdaten(MittelwMessdaten_Teil1, MittelwMessdaten_Teil2, objMessdatenUebergabe)
Thread.Sleep(0)
End SyncLock
End If
Catch ex As DaqException
MessageBox.Show(ex.Message)
taskRunning = False
Me.butStartProgramm.Enabled = True
Me.butStopMessung.Enabled = False
myTask.Dispose()
End Try
End Sub
#End Region
an here is the Plotframe:
Private Sub frmTemperaturen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
objDatenPlotTemp = New classPeriodengemittelteMessdaten ' defining the data object
'Starting the thra
Dim Start1 As New ThreadStart(AddressOf threadPlotTemperaturen)
myThread1 = New Thread(Start1)
myThread1.Start()
End Sub
#End Region
#Region "thread: Plot der Kurven"
Private Sub threadPlotTemperaturen()Dim wert_plot2(19, 0) As Double
xyPloTymin = 0.0
xyPloTymax = 100.0
xyPloTxmin = 0.0
xyPloTxmax = 100.0
xyPloDymin = 0.0
xyPloDymax = 10.0
xyPloDxmin = 0.0
xyPloDxmax = 100.0
iniPlots()
'transfering the data from aquisition loop
objDatenPlotTemp = frmMessStart.objPeriodengemittelteMessdatenUebergabe
While True
If objDatenPlotTemp Is Nothing Then
Else
SyncLock objDatenPlotTemp
'giving the transfered Data to the plot
wert_plot2(0, 0) = objDatenPlotTemp.T12PM
wert_plot2(1, 0) = objDatenPlotTemp.T13PM
wert_plot2(2, 0) = objDatenPlotTemp.T14PM
wert_plot2(3, 0) = objDatenPlotTemp.T15PM
wert_plot2(4, 0) = objDatenPlotTemp.T16PM
wert_plot2(5, 0) = objDatenPlotTemp.T17PM
wert_plot2(6, 0) = objDatenPlotTemp.T18PM
wert_plot2(7, 0) = objDatenPlotTemp.T19PM
wert_plot2(8, 0) = objDatenPlotTemp.T20PM
wert_plot2(9, 0) = objDatenPlotTemp.T21PM
wert_plot2(10, 0) = objDatenPlotTemp.T24PM
wert_plot2(11, 0) = objDatenPlotTemp.T25PM
wert_plot2(12, 0) = objDatenPlotTemp.T29PM
wert_plot2(13, 0) = objDatenPlotTemp.T30PM
wert_plot2(14, 0) = objDatenPlotTemp.T31PM
wert_plot2(15, 0) = objDatenPlotTemp.T32PM
wert_plot2(16, 0) = objDatenPlotTemp.T33PM
wert_plot2(17, 0) = objDatenPlotTemp.T34PM
wert_plot2(18, 0) = objDatenPlotTemp.T35PM
wert_plot2(19, 0) = objDatenPlotTemp.T36PM
Thread.Sleep(1500)
End SyncLock
Setslider1y(Me.slTymin1)
Setslider2y(Me.slTymax1)
Setslider1x(Me.slTxmin1)
Setslider2x(Me.slTxmax1)
SetArray(Me.grfTempKreislauf, wert_plot1) 'Plot Temperaturen Kreislauf
Setslider1dy(Me.slDmin1)
Setslider2dy(Me.slDmax1)
Setslider1dx(Me.slDxmin2)
Setslider2dx(Me.slDxmax2)SetArray1(Me.grfTempMesstrecke1, wert_plot2) ' Plot Temperaturen Versuchsrohr
End If
Thread.Sleep(6)
End While
End Sub
I would be very thankfull for any help!