public static void MyCallback(int bd, MccDaq.EventType et, uint sampleCount, IntPtr pUserData) { //MyCallback is a static member function. So, we must do some work to get the reference // to this object. Recall that we passed in a pointer to a struct that wrapped the // class reference as UserData. TUserData userStruct = (TUserData)Marshal.PtrToStructure(pUserData, typeof(TUserData)); frmEventDisplay ThisObj = (frmEventDisplay)userStruct.ThisObj; //Calculate the index of the latest sample in the buffer. int sampleIdx = ((int)sampleCount - 1) % ThisObj.TotalCount; ushort[] rawData = new ushort[1]; uint[] rawData32 = new uint[1]; float voltData; double highResVoltData; ThisObj.lblSampleCount.Text = sampleCount.ToString(); //Retrieve the latest sample and convert it to engineering units. if (ThisObj.ADResolution > 16) { MccDaq.MccService.WinBufToArray32(ThisObj.MemHandle, rawData32, (int)sampleIdx, 1); ThisObj.DaqBoard.ToEngUnits32(ThisObj.Range, rawData32[0], out highResVoltData); ThisObj.lblLatestSample.Text = highResVoltData.ToString("F5") + " V"; } else { MccDaq.MccService.WinBufToArray(ThisObj.MemHandle, rawData, (int)sampleIdx, 1); ThisObj.DaqBoard.ToEngUnits(ThisObj.Range, rawData[0], out voltData); ThisObj.lblLatestSample.Text = voltData.ToString("F4") + " V"; } if (et == MccDaq.EventType.OnEndOfAiScan) { // If the event is the end of acquisition, release the // resources in preparation for the next scan. ThisObj.DaqBoard.StopBackground(MccDaq.FunctionType.AiFunction); if (ThisObj.chkAutoRestart.Checked) { int rate = ThisObj.DesiredRate; ThisObj.DaqBoard.AInScan(0, 0, ThisObj.TotalCount, ref rate, ThisObj.Range, ThisObj.MemHandle, ThisObj.Options); } else { ThisObj.lblStatus.Text = "IDLE"; ThisObj.cmdStart.Enabled = true; } } }
public static void OnScanError(int bd, MccDaq.EventType et, uint scanError, IntPtr pdata) { //OnScanError is a static member function. So, we must do some work to get the reference // to this object. Recall that we passed in a pointer to a struct that wrapped the // class reference as UserData... TUserData thisStruct = (TUserData)Marshal.PtrToStructure(pdata, typeof(TUserData)); frmEventDisplay ThisObj = (frmEventDisplay)thisStruct.ThisObj; ThisObj.DaqBoard.StopBackground(MccDaq.FunctionType.AiFunction); // Reset the chkAutoRestart such that the 'OnEndOfAiScan' event does //not automatically start a new scan ThisObj.chkAutoRestart.Checked = false; }