Exemple #1
0
 void StopRecording(int channelIndex)
 {
     //Detach ourselves from the sample read event queue
     if (IsRecordingCh1)
     {
         HardwareManager.DaqBoard.ReadDone -= RecordSamples;
         //add end of recording to signal to our queue
         ChannelReadDataChunk end_chunk = new ChannelReadDataChunk();
         end_chunk.StartIndex = 0;
         end_chunk.Data       = null;
         _record_dataQueue.Produce(end_chunk);
         //wait for our file writing to finish
         if (_recordTask != null && !_recordTask.IsCompleted)
         {
             if (!_recordTask.Wait(1000))
             {
                 System.Diagnostics.Debug.WriteLine("Timed out waiting on record task to end");
             }
         }
         _recordTask = null;
     }
     if (channelIndex == 1)
     {
         IsRecordingCh1 = false;
     }
 }
Exemple #2
0
        /// <summary>
        /// Event to receive and distribute analog in samples received
        /// </summary>
        /// <param name="args">Sample payload</param>
        void RecordSamples(ReadDoneEventArgs args)
        {
            ChannelReadDataChunk chunk = new ChannelReadDataChunk();

            chunk.StartIndex = args.StartIndex;
            chunk.Data       = args.Data.Clone() as double[, ];
            _record_dataQueue.Produce(chunk);
        }
Exemple #3
0
 void StartRecording(int channelIndex, Dictionary <string, string> exp_info = null)
 {
     //Attach ourselves to the sample read event queue
     if (!IsRecordingCh1)
     {
         HardwareManager.DaqBoard.ReadDone += RecordSamples;
     }
     if (channelIndex == 1)
     {
         _recordTask = new Task(() =>
         {
             string data_file_name = CreateFilename(1) + ".data";
             //Write info file
             if (exp_info == null)
             {
                 exp_info = new Dictionary <string, string>();
                 exp_info["Experiment type"] = "Free run";
             }
             exp_info["datafile"]  = Path.GetFileName(data_file_name);
             exp_info["daq_rate"]  = HardwareSettings.DAQ.Rate.ToString();
             exp_info["channel"]   = channelIndex.ToString();
             exp_info["mV_per_V"]  = mV_per_V.ToString();
             exp_info["pA_per_V"]  = pA_per_V.ToString();
             TextWriter infoWriter = new StreamWriter(CreateFilename(1) + ".info");
             WriteExperimentInfo(BaseFNameCh1, exp_info, infoWriter);
             infoWriter.Dispose();
             BinaryWriter ch1File = new BinaryWriter(File.OpenWrite(data_file_name));
             while (true)
             {
                 ChannelReadDataChunk chnk = _record_dataQueue.Consume();
                 if (chnk.StartIndex == 0 && chnk.Data == null)
                 {
                     break;
                 }
                 for (int i = 0; i < chnk.Data.GetLength(1); i++)
                 {
                     WriteChannel1Sample(ch1File, chnk.StartIndex + i, chnk.Data[2, i] > 2, (float)chnk.Data[4, i], (float)chnk.Data[0, i],
                                         (float)chnk.Data[6, i]);
                 }
             }
             ch1File.Dispose();
         });
         _recordTask.Start();
         IsRecordingCh1 = true;
     }
     else
     {
         throw new NotImplementedException();
     }
 }